Merge branch 'public_api_update' into Development

This commit is contained in:
Diamantis Tziotzios 2023-03-03 10:23:52 +02:00
commit 9ebefa8369
3 changed files with 82 additions and 10 deletions

View File

@ -94,13 +94,16 @@ public class PublicDmpsDocumentation extends BaseController {
" 1. periodStart: date, dmps created date greater than periodStart\n" +
" 2. periodEnd: date, dmps created date less than periodEnd\n" +
" 3. grants: list of uuids, dmps with the corresponding grants\n" +
" 4. funders: list of uuids, dmps with the corresponding funders\n" +
" 5. datasetTemplates: list of uuids, dataset templates which are described in the dmps\n" +
" 6. dmpOrganisations: list of strings, dmps belonging to these organisations\n" +
" 7. collaborators: list of uuids, user who collaborated on the creation/modification of dmps\n" +
" 8. allVersions: boolean, if dmps should be fetched with all their versions\n" +
" 9. groupIds: list of uuids, in which groups the dmps are\n" +
"10. like: string, dmps fetched have this string matched in their label or description\n";
" 4. grantsLike: list of strings, dmps fetched having their grant matching any of the strings provided\n" +
" 5. funders: list of uuids, dmps with the corresponding funders\n" +
" 6. fundersLike: list of strings, dmps fetched having their funders matching any of the strings provided\n" +
" 7. datasetTemplates: list of uuids, dataset templates which are described in the dmps\n" +
" 8. dmpOrganisations: list of strings, dmps belonging to these organisations\n" +
" 9. collaborators: list of uuids, user who collaborated on the creation/modification of dmps\n" +
"10. collaboratorsLike: list of strings, dmps fetched having their collaborators matching any of the strings provided\n" +
"11. allVersions: boolean, if dmps should be fetched with all their versions\n" +
"12. groupIds: list of uuids, in which groups the dmps are\n" +
"13. like: string, dmps fetched have this string matched in their label or description\n";
private static final String getPagedRequestParamDescription = "The fieldsGroup is a string which indicates if the returned objects would have all their properties\n" +
"There are two available values: 1) listing and 2) autocomplete\n" +
"**listing**: returns objects with all their properties completed\n" +

View File

@ -15,14 +15,20 @@ public class DataManagementPlanPublicCriteria extends Criteria<DMP> {
private Date periodEnd;
@ApiModelProperty(value = "grants", name = "grants", dataType = "List<UUID>", example = "[]")
private List<UUID> grants;
@ApiModelProperty(value = "grantsLike", name = "grantsLike", dataType = "List<String>", example = "[]")
private List<String> grantsLike;
@ApiModelProperty(value = "funders", name = "funders", dataType = "List<UUID>", example = "[]")
private List<UUID> funders;
@ApiModelProperty(value = "fundersLike", name = "fundersLike", dataType = "List<String>", example = "[]")
private List<String> fundersLike;
@ApiModelProperty(value = "datasetTemplates", name = "datasetTemplates", dataType = "List<UUID>", example = "[]")
private List<UUID> datasetTemplates;
@ApiModelProperty(value = "dmpOrganisations", name = "dmpOrganisations", dataType = "List<String>", example = "[]")
private List<String> dmpOrganisations;
@ApiModelProperty(value = "collaborators", name = "collaborators", dataType = "List<UUID>", example = "[]")
private List<UUID> collaborators;
@ApiModelProperty(value = "collaboratorsLike", name = "collaboratorsLike", dataType = "List<String>", example = "[]")
private List<String> collaboratorsLike;
@ApiModelProperty(value = "allVersions", name = "allVersions", dataType = "Boolean", example = "false")
private boolean allVersions;
@ApiModelProperty(value = "groupIds", name = "groupIds", dataType = "List<UUID>", example = "[]")
@ -49,6 +55,13 @@ public class DataManagementPlanPublicCriteria extends Criteria<DMP> {
this.grants = grants;
}
public List<String> getGrantsLike() {
return grantsLike;
}
public void setGrantsLike(List<String> grantsLike) {
this.grantsLike = grantsLike;
}
public List<UUID> getFunders() {
return funders;
}
@ -56,6 +69,13 @@ public class DataManagementPlanPublicCriteria extends Criteria<DMP> {
this.funders = funders;
}
public List<String> getFundersLike() {
return fundersLike;
}
public void setFundersLike(List<String> fundersLike) {
this.fundersLike = fundersLike;
}
public List<UUID> getDatasetTemplates() {
return datasetTemplates;
}
@ -77,6 +97,13 @@ public class DataManagementPlanPublicCriteria extends Criteria<DMP> {
this.collaborators = collaborators;
}
public List<String> getCollaboratorsLike() {
return collaboratorsLike;
}
public void setCollaboratorsLike(List<String> collaboratorsLike) {
this.collaboratorsLike = collaboratorsLike;
}
public boolean getAllVersions() {
return allVersions;
}

View File

@ -8,9 +8,9 @@ import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.types.FieldSelectionType;
import eu.eudat.queryable.types.SelectionField;
import java.util.Arrays;
import java.util.Date;
import java.util.UUID;
import javax.persistence.criteria.Predicate;
import java.util.*;
import java.util.stream.Collectors;
public class DataManagmentPlanPublicTableRequest extends TableQuery<DataManagementPlanPublicCriteria, DMP, UUID> {
@ -27,8 +27,36 @@ public class DataManagmentPlanPublicTableRequest extends TableQuery<DataManageme
query.where((builder, root) -> builder.lessThan(root.get("created"), this.getCriteria().getPeriodEnd()));
if (this.getCriteria().getGrants() != null && !this.getCriteria().getGrants().isEmpty())
query.where(((builder, root) -> root.get("grant").get("id").in(this.getCriteria().getGrants())));
if (this.getCriteria().getGrantsLike() != null && !this.getCriteria().getGrantsLike().isEmpty()) {
query.where(((builder, root) -> {
List<Predicate> predicates = new ArrayList<>();
for(String grantLike: this.getCriteria().getGrantsLike()){
String pattern = "%" + grantLike.toUpperCase() + "%";
predicates.add(builder.like(builder.upper(root.get("grant").get("label")), pattern));
predicates.add(builder.like(builder.upper(root.get("grant").get("abbreviation")), pattern));
predicates.add(builder.like(builder.upper(root.get("grant").get("reference")), pattern));
predicates.add(builder.like(builder.upper(root.get("grant").get("definition")), pattern));
predicates.add(builder.like(builder.upper(root.get("grant").get("description")), pattern));
}
return builder.or(predicates.toArray(new Predicate[0]));
}
));
}
if (this.getCriteria().getFunders() != null && !this.getCriteria().getFunders().isEmpty())
query.where(((builder, root) -> root.get("grant").get("funder").get("id").in(this.getCriteria().getFunders())));
if (this.getCriteria().getFundersLike() != null && !this.getCriteria().getFundersLike().isEmpty()) {
query.where(((builder, root) -> {
List<Predicate> predicates = new ArrayList<>();
for(String funderLike: this.getCriteria().getFundersLike()){
String pattern = "%" + funderLike.toUpperCase() + "%";
predicates.add(builder.like(builder.upper(root.get("grant").get("funder").get("label")), pattern));
predicates.add(builder.like(builder.upper(root.get("grant").get("funder").get("reference")), pattern));
predicates.add(builder.like(builder.upper(root.get("grant").get("funder").get("definition")), pattern));
}
return builder.or(predicates.toArray(new Predicate[0]));
}
));
}
//query.where((builder, root) -> builder.lessThan(root.get("grant").get("enddate"), new Date())); // GrantStateType.FINISHED
query.where((builder, root) ->
@ -41,6 +69,19 @@ public class DataManagmentPlanPublicTableRequest extends TableQuery<DataManageme
query.where(((builder, root) -> root.join("organisations").get("reference").in(this.getCriteria().getDmpOrganisations())));
if (this.getCriteria().getCollaborators() != null && !this.getCriteria().getCollaborators().isEmpty())
query.where(((builder, root) -> root.join("researchers").get("id").in(this.getCriteria().getCollaborators())));
if (this.getCriteria().getCollaboratorsLike() != null && !this.getCriteria().getCollaboratorsLike().isEmpty()) {
query.where(((builder, root) -> {
List<Predicate> predicates = new ArrayList<>();
for(String collaboratorLike: this.getCriteria().getCollaboratorsLike()){
String pattern = "%" + collaboratorLike.toUpperCase() + "%";
predicates.add(builder.like(builder.upper(root.join("researchers").get("label")), pattern));
predicates.add(builder.like(builder.upper(root.join("researchers").get("uri")), pattern));
predicates.add(builder.like(builder.upper(root.join("researchers").get("primaryEmail")), pattern));
}
return builder.or(predicates.toArray(new Predicate[0]));
}
));
}
if (!this.getCriteria().getAllVersions()) {
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("version"),
query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(builder1.equal(externalRoot.get("groupId"),
@ -49,6 +90,7 @@ public class DataManagmentPlanPublicTableRequest extends TableQuery<DataManageme
if (this.getCriteria().getGroupIds() != null && !this.getCriteria().getGroupIds().isEmpty()) {
query.where((builder, root) -> root.get("groupId").in(this.getCriteria().getGroupIds()));
}
query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()));
return query;
}