no message

This commit is contained in:
annabakouli 2017-12-22 10:31:05 +02:00
parent bd1bc36085
commit 62a7c1fad3
18 changed files with 126 additions and 136 deletions

View File

@ -100,7 +100,7 @@ public class DMPs {
@RequestMapping(method = RequestMethod.POST, value = { "/dmps/createOrUpdate" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseItem<DMP> createOrUpdate(@RequestBody eu.eudat.models.dmp.DataManagementPlan dataManagementPlan, Principal principal) {
try{
DataManagementPlanManager.createOrUpdate(dMPDao,researcherDao,userInfoDao,organisationDao,dataManagementPlan,principal);
DataManagementPlanManager.createOrUpdate(dMPDao,projectDao,researcherDao,userInfoDao,organisationDao,dataManagementPlan,principal);
return new ResponseItem<DMP>().status(HttpStatus.CREATED);
}catch (Exception ex){
ex.printStackTrace();

View File

@ -9,6 +9,7 @@ import java.util.UUID;
import javax.transaction.Transactional;
import eu.eudat.models.criteria.ProjectCriteria;
import eu.eudat.models.external.OrganisationsExternalSourcesModel;
import eu.eudat.models.external.ProjectsExternalSourcesModel;
import eu.eudat.models.external.RegistriesExternalSourcesModel;
import eu.eudat.models.helpers.responses.*;
@ -128,7 +129,7 @@ public class Projects {
@RequestMapping(method = RequestMethod.POST, value = { "/projects/get" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseItem<List<eu.eudat.models.project.Project>> getPaged(@RequestBody ProjectCriteriaRequest projectCriteria) {
try {
List<eu.eudat.models.project.Project> dataTable = new ProjectManager().getCriteria(projectDao, projectCriteria);
List<eu.eudat.models.project.Project> dataTable = new ProjectManager().getCriteria(projectDao, projectCriteria,remoteFetcher);
return new ResponseItem<List<eu.eudat.models.project.Project>>().payload(dataTable).status(HttpStatus.OK);
} catch (Exception ex) {
ex.printStackTrace();

View File

@ -33,7 +33,7 @@ public class DatasetProfileDaoImpl implements DatasetProfileDao {
@Override
public DatasetProfile createOrUpdate(DatasetProfile item) {
return null;
return this.databaseService.createOrUpdate(item,DatasetProfile.class);
}
@Override

View File

@ -3,13 +3,13 @@ package eu.eudat.managers;
import java.util.List;
import java.util.UUID;
import eu.eudat.dao.entities.DMPDao;
import eu.eudat.dao.entities.OrganisationDao;
import eu.eudat.dao.entities.ResearcherDao;
import eu.eudat.dao.entities.UserInfoDao;
import eu.eudat.dao.entities.*;
import eu.eudat.entities.DMP;
import eu.eudat.entities.Project;
import eu.eudat.entities.UserInfo;
import eu.eudat.models.criteria.DataManagementPlanCriteria;
import eu.eudat.models.criteria.OrganisationCriteria;
import eu.eudat.models.criteria.ProjectCriteria;
import eu.eudat.models.criteria.ResearcherCriteria;
import eu.eudat.models.dmp.DataManagementPlan;
import eu.eudat.models.dmp.DataManagementPlanCriteriaRequest;
@ -44,11 +44,13 @@ public class DataManagementPlanManager {
return datamanagementPlans;
}
public static void createOrUpdate(DMPDao dmpsRepository, ResearcherDao researcherRepository, UserInfoDao userInfoDao, OrganisationDao organisationRepository, DataManagementPlan dataManagementPlan, Principal principal){
public static void createOrUpdate(DMPDao dmpsRepository, ProjectDao projectDao,ResearcherDao researcherRepository, UserInfoDao userInfoDao, OrganisationDao organisationRepository, DataManagementPlan dataManagementPlan, Principal principal){
DMP newDmp = dataManagementPlan.toDataModel();
createOrganisationsIfTheyDontExist(newDmp,organisationRepository);
createResearchersIfTheyDontExist(newDmp,researcherRepository);
newDmp.setCreator(userInfoDao.read(principal.getId()));
UserInfo user = userInfoDao.read(principal.getId());
createProjectIfItDoesntExist(newDmp,projectDao,user);
newDmp.setCreator(user);
dmpsRepository.createOrUpdate(newDmp);
}
@ -76,4 +78,18 @@ public class DataManagementPlanManager {
}
}
}
private static void createProjectIfItDoesntExist(DMP newDmp,ProjectDao projectDao,UserInfo userInfo){
if(newDmp.getProject()!=null){
Project project = newDmp.getProject();
ProjectCriteria criteria = new ProjectCriteria();
criteria.setLike(project.getReference());
List<eu.eudat.entities.Project> entries = projectDao.getWithCriteria(criteria).toList();
if(entries!=null&&!entries.isEmpty())project.setId(entries.get(0).getId());
else{
project.setCreationUser(userInfo);
projectDao.createOrUpdate(project);
}
}
}
}

View File

@ -36,10 +36,10 @@ public class DatasetWizardManager {
public static List<AssociatedProfile> getAvailableProfiles(DMPDao dmpRepository, DatasetProfileWizardAutocompleteRequest datasetProfileWizardAutocompleteRequest) throws InstantiationException, IllegalAccessException {
DataManagementPlan dataManagementPlan = new DomainModelConverter<eu.eudat.entities.DMP,DataManagementPlan>().fromDataModel(new LinkedList<DMP>(Arrays.asList(dmpRepository.find(datasetProfileWizardAutocompleteRequest.getCriteria().getId()))),DataManagementPlan.class).get(0);
if(dataManagementPlan.getAssociatedProfile()==null||dataManagementPlan.getAssociatedProfile().getAssociatedProfiles()==null||dataManagementPlan.getAssociatedProfile().getAssociatedProfiles().isEmpty()){
if(dataManagementPlan.getProfiles()==null||dataManagementPlan.getProfiles().isEmpty()){
return new LinkedList<>();
}
List<AssociatedProfile> profiles = dataManagementPlan.getAssociatedProfile().getAssociatedProfiles();
List<AssociatedProfile> profiles = dataManagementPlan.getProfiles();
return profiles.stream().filter(item->item.getLabel().contains(datasetProfileWizardAutocompleteRequest.getCriteria().getLike())).collect(Collectors.toList());
}
}

View File

@ -1,16 +1,23 @@
package eu.eudat.managers;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import eu.eudat.dao.entities.ProjectDao;
import eu.eudat.dao.entities.UserInfoDao;
import eu.eudat.models.criteria.ProjectCriteria;
import eu.eudat.models.external.ExternalListingItem;
import eu.eudat.models.external.ExternalSourcesItemModel;
import eu.eudat.models.external.ProjectsExternalSourcesModel;
import eu.eudat.models.helpers.DataTableData;
import eu.eudat.models.project.Project;
import eu.eudat.models.project.ProjectCriteriaRequest;
import eu.eudat.models.project.ProjectTableRequest;
import eu.eudat.models.security.Principal;
import eu.eudat.proxy.config.exceptions.HugeResultSet;
import eu.eudat.proxy.config.exceptions.NoURLFound;
import eu.eudat.proxy.fetching.RemoteFetcher;
import eu.eudat.queryable.QueryableList;
import eu.eudat.utilities.builders.DomainModelConverter;
@ -39,9 +46,21 @@ public class ProjectManager {
return project;
}
public List<eu.eudat.models.project.Project> getCriteria(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria) throws IllegalAccessException, InstantiationException{
public List<eu.eudat.models.project.Project> getCriteria(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria,RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound {
QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectCriteria.getCriteria());
List<eu.eudat.models.project.Project> projects = new DomainModelConverter<eu.eudat.entities.Project, Project>().fromDataModel(items.toList(), eu.eudat.models.project.Project.class);
List<Map<String,String>> remoteRepos = remoteFetcher.getProjects(projectCriteria.getCriteria().getLike());
ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos);
for(ExternalSourcesItemModel externalListingItem:projectsExternalSourcesModel){
eu.eudat.models.project.Project project = new eu.eudat.models.project.Project();
project.setReference(externalListingItem.getRemoteId());
project.setLabel(externalListingItem.getName());
project.setDescription(externalListingItem.getDescription());
project.setUri(externalListingItem.getUri());
project.setAbbreviation(externalListingItem.getAbbreviation());
project.setStatus((short)0);
projects.add(project);
}
return projects;
}

View File

@ -2,7 +2,6 @@ package eu.eudat.models.dataset;
import eu.eudat.models.DataModel;
import eu.eudat.models.datasetprofile.DatasetProfileListingModel;
import eu.eudat.models.dmp.AssociatedProfiles;
import eu.eudat.models.dmp.DataManagementPlan;
import eu.eudat.utilities.builders.DomainModelConverter;

View File

@ -10,15 +10,15 @@ import java.util.UUID;
* Created by ikalyvas on 12/20/2017.
*/
public class AssociatedProfile implements XmlSerializable<AssociatedProfile>{
private UUID profileId;
private UUID id;
private String label;
public UUID getProfileId() {
return profileId;
public UUID getId() {
return id;
}
public void setProfileId(UUID profileId) {
this.profileId = profileId;
public void setId(UUID id) {
this.id = id;
}
public String getLabel() {
@ -32,14 +32,14 @@ public class AssociatedProfile implements XmlSerializable<AssociatedProfile>{
@Override
public Element toXml(Document doc) {
Element profile = doc.createElement("profile");
profile.setAttribute("profileId",this.profileId.toString());
profile.setAttribute("profileId",this.id.toString());
profile.setAttribute("label",this.label);
return profile;
}
@Override
public AssociatedProfile fromXml(Element item) {
this.profileId = UUID.fromString(item.getAttribute("profileId"));
this.id = UUID.fromString(item.getAttribute("profileId"));
this.label = item.getAttribute("label");
return this;
}

View File

@ -1,49 +0,0 @@
package eu.eudat.models.dmp;
import eu.eudat.utilities.XmlSerializable;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.LinkedList;
import java.util.List;
/**
* Created by ikalyvas on 12/20/2017.
*/
public class AssociatedProfiles implements XmlSerializable<AssociatedProfiles>{
List<AssociatedProfile> associatedProfiles;
public List<AssociatedProfile> getAssociatedProfiles() {
return associatedProfiles;
}
public void setAssociatedProfiles(List<AssociatedProfile> associatedProfiles) {
this.associatedProfiles = associatedProfiles;
}
@Override
public Element toXml(Document doc) {
Element associatedProfilesElement = doc.createElement("profiles");
for(AssociatedProfile associatedProfile:associatedProfiles){
associatedProfilesElement.appendChild(associatedProfile.toXml(doc));
}
return associatedProfilesElement;
}
@Override
public AssociatedProfiles fromXml(Element item) {
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;
}
}

View File

@ -2,10 +2,14 @@ package eu.eudat.models.dmp;
import eu.eudat.entities.*;
import eu.eudat.models.DataModel;
import eu.eudat.models.project.*;
import eu.eudat.models.project.Project;
import eu.eudat.utilities.builders.DomainModelConverter;
import eu.eudat.utilities.builders.XmlBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.*;
import java.util.stream.Collector;
@ -18,8 +22,8 @@ public class DataManagementPlan implements DataModel<DMP>{
private int version;
private int status;
private String description;
private AssociatedProfiles associatedProfile;
private eu.eudat.models.dmp.Project project;
private List<AssociatedProfile> profiles;
private eu.eudat.models.project.Project project;
private List<Organisation> organisations;
private List<Researcher> researchers;
private UserInfo creator;
@ -80,11 +84,11 @@ public class DataManagementPlan implements DataModel<DMP>{
this.status = status;
}
public eu.eudat.models.dmp.Project getProject() {
public Project getProject() {
return project;
}
public void setProject(eu.eudat.models.dmp.Project project) {
public void setProject(Project project) {
this.project = project;
}
@ -96,12 +100,12 @@ public class DataManagementPlan implements DataModel<DMP>{
this.creator = creator;
}
public AssociatedProfiles getAssociatedProfile() {
return associatedProfile;
public List<AssociatedProfile> getProfiles() {
return profiles;
}
public void setAssociatedProfile(AssociatedProfiles associatedProfile) {
this.associatedProfile = associatedProfile;
public void setProfiles(List<AssociatedProfile> profiles) {
this.profiles = profiles;
}
public Date getCreated() {
@ -128,15 +132,24 @@ public class DataManagementPlan implements DataModel<DMP>{
this.version = entity.getVersion();
this.previous = entity.getPrevious();
this.label = entity.getLabel();
this.project = new eu.eudat.models.dmp.Project();
this.project = new Project();
this.project.fromDataModel(entity.getProject());
this.creator = new eu.eudat.models.dmp.UserInfo();
if(entity.getCreator()!=null)this.creator.fromDataModel(entity.getCreator());
if(entity.getAssociatedDmps()!=null&&!entity.getAssociatedDmps().isEmpty()){
Document viewStyleDoc = XmlBuilder.fromXml(entity.getAssociatedDmps());
Element root = (Element)viewStyleDoc.getDocumentElement();
this.associatedProfile = new AssociatedProfiles().fromXml(root);
Element item = (Element) viewStyleDoc.getElementsByTagName("profiles").item(0);
this.profiles = 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.profiles.add(new AssociatedProfile().fromXml((Element)associatedProfileElement));
}
}
}
}
this.created = entity.getCreated();
this.description = entity.getDescription();
@ -154,10 +167,13 @@ public class DataManagementPlan implements DataModel<DMP>{
dataManagementPlanEntity.setProject(this.project.toDataModel());
dataManagementPlanEntity.setStatus((short)this.status);
dataManagementPlanEntity.setDescription(this.description);
if(this.associatedProfile!=null) {
if(this.profiles!=null) {
Document associatedProfileDoc = XmlBuilder.getDocument();
Element associatedProfileElement = this.associatedProfile.toXml(associatedProfileDoc);
associatedProfileDoc.appendChild(associatedProfileElement);
Element associatedProfilesElement = associatedProfileDoc.createElement("profiles");
for(AssociatedProfile associatedProfile:this.profiles){
associatedProfilesElement.appendChild(associatedProfile.toXml(associatedProfileDoc));
}
associatedProfileDoc.appendChild(associatedProfilesElement);
dataManagementPlanEntity.setAssociatedDmps(XmlBuilder.generateXml(associatedProfileDoc));
}
dataManagementPlanEntity.setCreated(this.created!=null?this.created:new Date());

View File

@ -1,39 +0,0 @@
package eu.eudat.models.dmp;
import eu.eudat.models.DataModel;
import java.util.UUID;
public class Project implements DataModel<eu.eudat.entities.Project>{
private UUID id;
private String label;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
@Override
public void fromDataModel(eu.eudat.entities.Project entity) {
this.id = entity.getId();
this.label = entity.getLabel();
}
@Override
public eu.eudat.entities.Project toDataModel() {
eu.eudat.entities.Project project = new eu.eudat.entities.Project();
project.setId(this.id);
return project;
}
}

View File

@ -6,8 +6,10 @@ package eu.eudat.models.external;
public class ExternalSourcesItemModel{
private String id;
private String name;
private String label;
private String description;
private String uri;
private String remoteId;
private String abbreviation;
public String getId() {
return id;
}
@ -24,11 +26,35 @@ public class ExternalSourcesItemModel{
this.name = name;
}
public String getLabel() {
return label;
public String getDescription() {
return description;
}
public void setLabel(String label) {
this.label = label;
public void setDescription(String description) {
this.description = description;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getRemoteId() {
return remoteId;
}
public void setRemoteId(String remoteId) {
this.remoteId = remoteId;
}
public String getAbbreviation() {
return abbreviation;
}
public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation;
}
}

View File

@ -13,7 +13,7 @@ public class OrganisationsExternalSourcesModel extends ExternalListingItem<Organ
for(Map<String,String> item : values){
ExternalSourcesItemModel model = new ExternalSourcesItemModel();
model.setId(item.get("pid"));
model.setLabel(item.get("uri"));
model.setUri(item.get("uri"));
model.setName(item.get("name"));
this.add(model);
}

View File

@ -12,9 +12,10 @@ public class ProjectsExternalSourcesModel extends ExternalListingItem<ProjectsEx
public ProjectsExternalSourcesModel fromExternalItem(List<Map<String,String>> values) {
for(Map<String,String> item : values){
ExternalSourcesItemModel model = new ExternalSourcesItemModel();
model.setId(item.get("pid"));
model.setLabel(item.get("uri"));
model.setRemoteId(item.get("pid"));
model.setUri(item.get("uri"));
model.setName(item.get("name"));
model.setDescription(item.get("description"));
this.add(model);
}
return this;

View File

@ -13,7 +13,7 @@ public class RegistriesExternalSourcesModel extends ExternalListingItem<Registri
for(Map<String,String> item : values){
ExternalSourcesItemModel model = new ExternalSourcesItemModel();
model.setId(item.get("pid"));
model.setLabel(item.get("uri"));
model.setUri(item.get("uri"));
model.setName(item.get("name"));
this.add(model);
}

View File

@ -13,7 +13,7 @@ public class ResearchersExternalSourcesModel extends ExternalListingItem<Researc
for(Map<String,String> item : values){
ExternalSourcesItemModel model = new ExternalSourcesItemModel();
model.setId(item.get("pid"));
model.setLabel(item.get("uri"));
model.setUri(item.get("uri"));
model.setName(item.get("name"));
this.add(model);
}

View File

@ -13,7 +13,7 @@ public class ServiceExternalSourcesModel extends ExternalListingItem<ServiceExte
for(Map<String,String> item : values){
ExternalSourcesItemModel model = new ExternalSourcesItemModel();
model.setId(item.get("pid"));
model.setLabel(item.get("label"));
model.setUri(item.get("label"));
model.setName(item.get("name"));
this.add(model);
}

View File

@ -3,13 +3,13 @@ import { Serializable } from "../Serializable";
export class ProfileModel implements Serializable<ProfileModel> {
public id: String;
public name: String;
public label: String;
public description: String;
public reference: String;
fromJSONObject(item: any): ProfileModel {
this.id = item.id;
this.name = item.name;
this.label = item.label;
this.description = item.abbreviation;
this.reference = item.reference;