Add get All Versions Endpoint to the Backend

This commit is contained in:
George Kalampokis 2020-07-09 13:11:43 +03:00
parent a1963602df
commit 4e249e4b8b
4 changed files with 95 additions and 4 deletions

View File

@ -38,7 +38,12 @@ import java.util.stream.Collectors;
@NamedSubgraph(name = "users", attributeNodes = {@NamedAttributeNode("user")}),
@NamedSubgraph(name = "dataset", attributeNodes = {@NamedAttributeNode("id"), @NamedAttributeNode("label")})
}
),
@NamedEntityGraph(
name = "versionListingModel",
attributeNodes = {@NamedAttributeNode("id"), @NamedAttributeNode("groupId"), @NamedAttributeNode("version")}
)
})
public class DMP implements DataEntity<DMP, UUID> {

View File

@ -29,6 +29,7 @@ import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel;
import eu.eudat.models.data.listingmodels.DataManagementPlanOverviewModel;
import eu.eudat.models.data.listingmodels.UserInfoListingModel;
import eu.eudat.models.data.listingmodels.VersionListingModel;
import eu.eudat.models.data.security.Principal;
import eu.eudat.query.DMPQuery;
import eu.eudat.types.ApiMessageCode;
@ -159,6 +160,14 @@ public class DMPs extends BaseController {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Tuple<String, String>>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
}
@RequestMapping(method = RequestMethod.GET, value = {"/versions/{id}"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<List<VersionListingModel>>> getVersions(@PathVariable String groupId,
@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception {
List<VersionListingModel> versions = this.dataManagementPlanManager.getAllVersions(groupId, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<VersionListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(versions));
}
/*
* Data Export
* */

View File

@ -50,10 +50,7 @@ import eu.eudat.models.data.funder.FunderDMPEditorModel;
import eu.eudat.models.data.grant.GrantDMPEditorModel;
import eu.eudat.models.data.helpermodels.Tuple;
import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel;
import eu.eudat.models.data.listingmodels.DataManagementPlanOverviewModel;
import eu.eudat.models.data.listingmodels.DatasetListingModel;
import eu.eudat.models.data.listingmodels.UserInfoListingModel;
import eu.eudat.models.data.listingmodels.*;
import eu.eudat.models.data.project.ProjectDMPEditorModel;
import eu.eudat.models.data.security.Principal;
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
@ -301,6 +298,33 @@ public class DataManagementPlanManager {
return data;
}
public List<VersionListingModel> getAllVersions(String groupId, Principal principal) {
UUID principalId = principal.getId();
List<VersionListingModel> versions = new ArrayList<>();
QueryableList<DMP> items = null;
QueryableList<DMP> authItems = null;
List<Integer> roles = new LinkedList<>();
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria();
criteria.setGroupIds(Collections.singletonList(UUID.fromString(groupId)));
criteria.setAllVersions(true);
criteria.setIsPublic(principalId == null);
criteria.setOnlyPublic(principalId == null);
items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria);
if (principalId != null) {
authItems = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(items, principalId, roles);
} else {
authItems = items;
}
CompletableFuture<List<VersionListingModel>> versionFuture = authItems.withHint(HintedModelFactory.getHint(VersionListingModel.class))
.orderBy(((builder, root) -> builder.asc(root.get("version"))))
.selectAsync(item -> new VersionListingModel().fromDataModel(item))
.whenComplete(((versionListingModels, throwable) -> versions.addAll(versionListingModels)));
CompletableFuture.allOf(versionFuture).join();
return versions;
}
/*
* Data Management
* */

View File

@ -0,0 +1,53 @@
package eu.eudat.models.data.listingmodels;
import eu.eudat.data.entities.DMP;
import eu.eudat.models.DataModel;
public class VersionListingModel implements DataModel<DMP, VersionListingModel> {
private String id;
private String groupId;
private Integer version;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
@Override
public VersionListingModel fromDataModel(DMP entity) {
this.id = entity.getId().toString();
this.groupId = entity.getGroupId().toString();
this.version = entity.getVersion();
return this;
}
@Override
public DMP toDataModel() throws Exception {
return null;
}
@Override
public String getHint() {
return "versionListingModel";
}
}