Adds endpoint for the new model DataManagmentPlanOverview.

This commit is contained in:
gkolokythas 2019-05-17 18:21:56 +03:00
parent 682bebfc60
commit dd973d4b78
4 changed files with 243 additions and 1 deletions

View File

@ -24,6 +24,7 @@ import eu.eudat.models.data.helpermodels.Tuple;
import eu.eudat.models.data.helpers.common.DataTableData;
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.security.Principal;
import eu.eudat.types.ApiMessageCode;
import eu.eudat.types.Authorities;
@ -98,6 +99,13 @@ public class DMPs extends BaseController {
}
}
@RequestMapping(method = RequestMethod.GET, value = {"/overview/{id}"})
public @ResponseBody
ResponseEntity getOverviewSingle(@PathVariable String id, Principal principal) throws IllegalAccessException,InterruptedException, InstantiationException, IOException {
DataManagementPlanOverviewModel dataManagementPlan = this.dataManagementPlanManager.getOverviewSingle(id, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanOverviewModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
}
@RequestMapping(method = RequestMethod.GET, value = {"/public/{id}"})
public @ResponseBody
ResponseEntity getSinglePublic(@PathVariable String id) throws IllegalAccessException,InterruptedException, InstantiationException, IOException {

View File

@ -32,6 +32,7 @@ import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.Field;
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.security.Principal;
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
@ -152,7 +153,6 @@ public class DataManagementPlanManager {
return dataTable;
}
public void unlock(UUID uuid) throws Exception {
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao()
.asQueryable().where((builder, root) -> builder.equal(root.get("id"), uuid))
@ -253,6 +253,35 @@ public class DataManagementPlanManager {
return datamanagementPlan;
}
public DataManagementPlanOverviewModel getOverviewSingle(String id, Principal principal) throws InstantiationException, IllegalAccessException {
DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
if (dataManagementPlanEntity.getCreator().getId() != principal.getId() && dataManagementPlanEntity.getUsers()
.stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId())
.collect(Collectors.toList()).size() == 0)
throw new UnauthorisedException();
DataManagementPlanOverviewModel datamanagementPlan = new DataManagementPlanOverviewModel();
datamanagementPlan.fromDataModelDatasets(dataManagementPlanEntity);
/*Map dmpProperties = dataManagementPlanEntity.getDmpProperties() != null ? new org.json.JSONObject(dataManagementPlanEntity.getDmpProperties()).toMap() : null;
datamanagementPlan.setDynamicFields(dynamicProjectConfiguration.getFields().stream().map(item -> {
DynamicFieldWithValue fieldWithValue = new DynamicFieldWithValue();
fieldWithValue.setId(item.getId());
fieldWithValue.setDependencies(item.getDependencies());
fieldWithValue.setName(item.getName());
fieldWithValue.setQueryProperty(item.getQueryProperty());
fieldWithValue.setRequired(item.getRequired());
return fieldWithValue;
}).collect(Collectors.toList()));*/
/*if (dmpProperties != null && datamanagementPlan.getDynamicFields() != null)
datamanagementPlan.getDynamicFields().forEach(item -> {
Map<String, String> properties = (Map<String, String>) dmpProperties.get(item.getId());
if (properties != null)
item.setValue(new Tuple<>(properties.get("id"), properties.get("label")));
});*/
return datamanagementPlan;
}
public eu.eudat.models.data.dmp.DataManagementPlan getSinglePublic(String id, DynamicProjectConfiguration dynamicProjectConfiguration) throws Exception {
DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));

View File

@ -0,0 +1,201 @@
package eu.eudat.models.data.listingmodels;
import eu.eudat.data.entities.DMP;
import eu.eudat.logic.utilities.builders.XmlBuilder;
import eu.eudat.models.DataModel;
import eu.eudat.models.data.dmp.AssociatedProfile;
import eu.eudat.models.data.dmp.Organisation;
import eu.eudat.models.data.urls.DatasetUrlListing;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
public class DataManagementPlanOverviewModel implements DataModel<DMP, DataManagementPlanOverviewModel> {
private String id;
private String label;
private String project;
private String profile;
private Date creationTime;
private Date modifiedTime;
private List<Organisation> organisations;
private int version;
private int status;
private UUID groupId;
private List<DatasetUrlListing> datasets;
private List<AssociatedProfile> associatedProfiles;
private List<UserInfoListingModel> users;
private String description;
private String projectAbbreviation;
private String projectId;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getProject() {
return project;
}
public void setProject(String project) {
this.project = project;
}
public String getProfile() {
return profile;
}
public void setProfile(String profile) {
this.profile = profile;
}
public Date getCreationTime() {
return creationTime;
}
public void setCreationTime(Date creationTime) {
this.creationTime = creationTime;
}
public Date getModifiedTime() {
return modifiedTime;
}
public void setModifiedTime(Date modifiedTime) {
this.modifiedTime = modifiedTime;
}
public List<Organisation> getOrganisations() {
return organisations;
}
public void setOrganisations(List<Organisation> organizations) {
this.organisations = organizations;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public UUID getGroupId() {
return groupId;
}
public void setGroupId(UUID groupId) {
this.groupId = groupId;
}
public List<DatasetUrlListing> getDatasets() {
return datasets;
}
public void setDatasets(List<DatasetUrlListing> datasets) {
this.datasets = datasets;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public List<AssociatedProfile> getAssociatedProfiles() {
return associatedProfiles;
}
public void setAssociatedProfiles(List<AssociatedProfile> associatedProfiles) {
this.associatedProfiles = associatedProfiles;
}
public List<UserInfoListingModel> getUsers() {
return users;
}
public void setUsers(List<UserInfoListingModel> users) {
this.users = users;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getProjectAbbreviation() {
return projectAbbreviation;
}
public void setProjectAbbreviation(String projectAbbreviation) {
this.projectAbbreviation = projectAbbreviation;
}
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
@Override
public DataManagementPlanOverviewModel fromDataModel(DMP entity) {
this.id = entity.getId().toString();
this.label = entity.getLabel();
this.groupId = entity.getGroupId();
return this;
}
public DataManagementPlanOverviewModel fromDataModelDatasets(DMP entity) {
this.fromDataModel(entity);
this.status = entity.getStatus();
this.version = entity.getVersion();
this.project = entity.getProject().getLabel();
if (entity.getProfile() != null) this.profile = entity.getProfile().getLabel();
this.creationTime = entity.getCreated();
this.modifiedTime = entity.getModified();
this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList());
this.datasets = entity.getDataset().stream().map(x-> new DatasetUrlListing().fromDataModel(x)).collect(Collectors.toList());
this.users = entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList());
this.description = entity.getDescription();
this.projectAbbreviation = entity.getProject().getAbbreviation();
this.projectId = entity.getProject().getId().toString();
if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) {
Document viewStyleDoc = XmlBuilder.fromXml(entity.getAssociatedDmps());
Element item = (Element) viewStyleDoc.getElementsByTagName("profiles").item(0);
this.associatedProfiles = new LinkedList<>();
if (item != null) {
NodeList associatedProfilesElement = item.getChildNodes();
for (int temp = 0; temp < associatedProfilesElement.getLength(); temp++) {
Node associatedProfileElement = associatedProfilesElement.item(temp);
if (associatedProfileElement.getNodeType() == Node.ELEMENT_NODE) {
this.associatedProfiles.add(new AssociatedProfile().fromXml((Element) associatedProfileElement));
}
}
}
}
return this;
}
@Override
public DMP toDataModel() {
return null;
}
@Override
public String getHint() {
return "dataManagementPlanOverviewModel";
}
}

View File

@ -45,6 +45,10 @@ export class DmpService {
return this.http.get<DmpModel>(this.actionUrl + 'public/' + id, { headers: this.headers });
}
getOverviewSingle(id: string): Observable<any> {
return this.http.get<any>(this.actionUrl + 'overview/' + id, { headers: this.headers });
}
unlock(id: String): Observable<DmpModel> {
return this.http.get<DmpModel>(this.actionUrl + id + '/unlock', { headers: this.headers });
}