argos/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java

874 lines
49 KiB
Java
Raw Normal View History

2018-06-27 12:29:21 +02:00
package eu.eudat.logic.managers;
2017-12-15 00:01:26 +01:00
import com.fasterxml.jackson.databind.ObjectMapper;
2018-07-23 15:09:19 +02:00
import eu.eudat.configurations.dynamicproject.DynamicProjectConfiguration;
import eu.eudat.configurations.dynamicproject.entities.Property;
2019-02-15 16:11:38 +01:00
import eu.eudat.data.dao.criteria.*;
2018-03-21 11:57:56 +01:00
import eu.eudat.data.dao.entities.*;
2019-03-05 12:59:34 +01:00
import eu.eudat.data.entities.Organisation;
import eu.eudat.data.entities.Researcher;
import eu.eudat.data.entities.*;
2018-03-28 15:24:47 +02:00
import eu.eudat.data.query.items.item.dmp.DataManagementPlanCriteriaRequest;
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
2019-04-26 16:05:15 +02:00
import eu.eudat.data.query.items.table.dmp.DataManagmentPlanPublicTableRequest;
import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException;
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
2018-02-07 10:56:30 +01:00
import eu.eudat.exceptions.security.UnauthorisedException;
2018-07-23 15:09:19 +02:00
import eu.eudat.logic.builders.entity.UserInfoBuilder;
import eu.eudat.logic.services.ApiContext;
2018-10-08 17:14:27 +02:00
import eu.eudat.logic.services.forms.VisibilityRuleService;
import eu.eudat.logic.services.operations.DatabaseRepository;
import eu.eudat.logic.services.utilities.UtilitiesService;
2018-10-08 17:14:27 +02:00
import eu.eudat.logic.utilities.builders.XmlBuilder;
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
import eu.eudat.logic.utilities.documents.types.ParagraphStyle;
import eu.eudat.logic.utilities.documents.word.WordBuilder;
2018-10-08 17:14:27 +02:00
import eu.eudat.logic.utilities.documents.xml.ExportXmlBuilder;
2018-01-19 10:31:05 +01:00
import eu.eudat.models.HintedModelFactory;
2018-10-08 17:14:27 +02:00
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
2019-03-05 12:59:34 +01:00
import eu.eudat.models.data.dmp.*;
2018-06-27 12:29:21 +02:00
import eu.eudat.models.data.dynamicfields.DynamicFieldWithValue;
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.DataManagementPlanProfile;
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.Field;
2018-06-27 12:29:21 +02:00
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;
2018-06-27 12:29:21 +02:00
import eu.eudat.models.data.listingmodels.DatasetListingModel;
import eu.eudat.models.data.listingmodels.UserInfoListingModel;
2018-06-27 12:29:21 +02:00
import eu.eudat.models.data.security.Principal;
2018-10-08 17:14:27 +02:00
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import eu.eudat.models.data.userinfo.UserListingModel;
import eu.eudat.queryable.QueryableList;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
2018-10-08 17:14:27 +02:00
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
2018-03-28 15:24:47 +02:00
import org.springframework.http.*;
import org.springframework.stereotype.Component;
2018-03-28 15:24:47 +02:00
import org.springframework.web.client.RestTemplate;
2019-03-05 12:59:34 +01:00
import org.springframework.web.multipart.MultipartFile;
2018-10-08 17:14:27 +02:00
import org.w3c.dom.Document;
import org.w3c.dom.Element;
2017-12-15 00:01:26 +01:00
2019-03-05 12:59:34 +01:00
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.*;
import java.math.BigInteger;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
2018-03-28 15:24:47 +02:00
import java.util.*;
2018-02-16 11:34:02 +01:00
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@Component
2017-12-15 00:01:26 +01:00
public class DataManagementPlanManager {
private ApiContext apiContext;
private DatasetManager datasetManager;
private UtilitiesService utilitiesService;
private DatabaseRepository databaseRepository;
private Environment environment;
@Autowired
public DataManagementPlanManager(ApiContext apiContext, DatasetManager datasetManager, Environment environment) {
this.apiContext = apiContext;
this.datasetManager = datasetManager;
this.utilitiesService = apiContext.getUtilitiesService();
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
this.environment = environment;
}
public DataTableData<DataManagementPlanListingModel> getPaged(DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal, String fieldsGroup) throws Exception {
UUID principalID = principal.getId();
2019-05-31 13:07:12 +02:00
QueryableList<DMP> items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dataManagementPlanTableRequest.getCriteria());
QueryableList<DMP> authItems = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(items, principalID);
2018-01-11 17:19:15 +01:00
QueryableList<DMP> pagedItems = PaginationManager.applyPaging(authItems, dataManagementPlanTableRequest);
2018-01-08 15:57:21 +01:00
2018-07-23 15:09:19 +02:00
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<>();
2018-02-07 10:56:30 +01:00
CompletableFuture itemsFuture;
if(fieldsGroup.equals("listing")){
itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
.selectAsync(item -> {
item.setDataset(
item.getDataset().stream()
.filter(ds -> !ds.getStatus().equals(Dataset.Status.DELETED.getValue())).collect(Collectors.toList()).stream()
.filter(dataset -> dataset.getDmp().getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getId().equals(principalID)
|| dataset.isPublic()
|| dataset.getDmp().getUsers().stream()
.filter(x -> x.getUser().getId().equals(principalID))
.collect(Collectors.toList()).size() > 0)
.collect(Collectors.toSet()));
return new DataManagementPlanListingModel().fromDataModelDatasets(item);
})
.whenComplete((resultList, throwable) -> dataTable.setData(resultList));
}
else{
itemsFuture = pagedItems
.selectAsync(item -> new DataManagementPlanListingModel().fromDataModel(item))
.whenComplete((resultList, throwable) -> dataTable.setData(resultList));
}
2018-02-07 10:56:30 +01:00
2018-03-19 13:40:04 +01:00
CompletableFuture countFuture = authItems.countAsync().whenComplete((count, throwable) -> {
2018-02-07 10:56:30 +01:00
dataTable.setTotalCount(count);
});
CompletableFuture.allOf(itemsFuture, countFuture).join();
2018-01-11 17:19:15 +01:00
return dataTable;
}
2017-12-19 09:38:47 +01:00
2019-04-26 16:05:15 +02:00
public DataTableData<DataManagementPlanListingModel> getPaged(DataManagmentPlanPublicTableRequest dataManagementPlanPublicTableRequest, String fieldsGroup) throws Exception {
dataManagementPlanPublicTableRequest.setQuery(databaseRepository.getDmpDao().asQueryable().withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)));
QueryableList<DMP> items = dataManagementPlanPublicTableRequest.applyCriteria();
QueryableList<DMP> pagedItems = PaginationManager.applyPaging(items, dataManagementPlanPublicTableRequest);
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<>();
CompletableFuture itemsFuture;
if(fieldsGroup.equals("listing")){
itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
.selectAsync(item -> {
item.setDataset(
item.getDataset().stream()
.filter(dataset -> dataset.getStatus().equals(Dataset.Status.FINALISED.getValue())).collect(Collectors.toSet()));
2019-04-26 16:05:15 +02:00
return new DataManagementPlanListingModel().fromDataModelDatasets(item);
})
.whenComplete((resultList, throwable) -> dataTable.setData(resultList));
}
else{
itemsFuture = pagedItems
.selectAsync(item -> new DataManagementPlanListingModel().fromDataModel(item))
2019-04-26 16:05:15 +02:00
.whenComplete((resultList, throwable) -> dataTable.setData(resultList));
}
CompletableFuture countFuture = items.countAsync().whenComplete((count, throwable) -> {
dataTable.setTotalCount(count);
});
CompletableFuture.allOf(itemsFuture, countFuture).join();
return dataTable;
}
public void unlock(UUID uuid) throws Exception {
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao()
.asQueryable().where((builder, root) -> builder.equal(root.get("id"), uuid))
.update(root -> root.get("status"), DMP.DMPStatus.ACTIVE.getValue());
return;
}
public File getWordDocument(String id) throws InstantiationException, IllegalAccessException, IOException {
WordBuilder wordBuilder = new WordBuilder();
VisibilityRuleService visibilityRuleService = this.utilitiesService.getVisibilityRuleService();
DatasetWizardModel dataset = new DatasetWizardModel();
String fileUrl = environment.getProperty("configuration.h2020template");
InputStream is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream();
2018-10-22 12:34:39 +02:00
XWPFDocument document = new XWPFDocument(is);
eu.eudat.data.entities.DMP dmpEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
// Space above DMP title.
XWPFParagraph parAboveDmpTitle = document.createParagraph();
XWPFParagraph parAboveDmpTitle1 = document.createParagraph();
XWPFParagraph parAboveDmpTitle2 = document.createParagraph();
XWPFParagraph parAboveDmpTitle3 = document.createParagraph();
// DMP title custom style.
//wordBuilder.addParagraphContent(dmpEntity.getLabel(), document, ParagraphStyle.TITLE, BigInteger.ZERO);
XWPFParagraph dmpLabelParagraph = document.createParagraph();
XWPFRun run = dmpLabelParagraph.createRun();
run.setText(dmpEntity.getLabel());
run.setBold(true);
run.setFontSize(20);
// Space below DMP title.
XWPFParagraph parBelowDmpTitle = document.createParagraph();
wordBuilder.addParagraphContent(dmpEntity.getDescription(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
wordBuilder.addParagraphContent("Organisations", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
2019-03-05 12:59:34 +01:00
if (dmpEntity.getOrganisations().size() > 0) {
wordBuilder.addParagraphContent(dmpEntity.getOrganisations().stream().map(x -> x.getLabel()).collect(Collectors.joining(", "))
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
}
wordBuilder.addParagraphContent("Researchers", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
2019-03-05 12:59:34 +01:00
if (dmpEntity.getResearchers().size() > 0) {
wordBuilder.addParagraphContent(dmpEntity.getResearchers().stream().map(x -> x.getLabel()).collect(Collectors.joining(", "))
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
}
/*wordBuilder.addParagraphContent("DMP Profile", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
if (dmpEntity.getProfile() != null){
wordBuilder.addParagraphContent(dmpEntity.getProfile().getLabel(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
}*/
// Page break at the end of the DMP title.
XWPFParagraph parBreakDMP = document.createParagraph();
parBreakDMP.setPageBreak(true);
wordBuilder.addParagraphContent("Datasets", document, ParagraphStyle.TITLE, BigInteger.ZERO);
dmpEntity.getDataset().stream().forEach(datasetEntity -> {
Map<String, Object> properties = new HashMap<>();
if (datasetEntity.getProperties() != null) {
JSONObject jobject = new JSONObject(datasetEntity.getProperties());
properties = jobject.toMap();
}
// Custom style for the Dataset title.
//wordBuilder.addParagraphContent("Title: " + datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
XWPFParagraph datasetLabelParagraph = document.createParagraph();
XWPFRun runDatasetTitle1 = datasetLabelParagraph.createRun();
runDatasetTitle1.setText("Title: ");
runDatasetTitle1.setBold(true);
runDatasetTitle1.setFontSize(12);
XWPFRun runDatasetTitle = datasetLabelParagraph.createRun();
runDatasetTitle.setText(datasetEntity.getLabel());
runDatasetTitle.setColor("2E75B6");
runDatasetTitle.setBold(true);
runDatasetTitle.setFontSize(12);
wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER1, BigInteger.ZERO);
PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(dataset, datasetEntity);
visibilityRuleService.setProperties(properties);
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
try {
wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService);
} catch (IOException e) {
e.printStackTrace();
}
// Page break at the end of the Dataset.
XWPFParagraph parBreakDataset = document.createParagraph();
});
2019-03-05 12:59:34 +01:00
String fileName = dmpEntity.getLabel();
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
2019-04-05 11:20:06 +02:00
File exportFile = new File(environment.getProperty("configuration.exportUrl") + fileName + ".docx");
FileOutputStream out = new FileOutputStream(exportFile);
document.write(out);
out.close();
2019-04-05 11:20:06 +02:00
return exportFile;
}
2019-04-05 11:20:06 +02:00
/*public File getPdfDocument(String id) throws InstantiationException, IllegalAccessException, InterruptedException, IOException {
File file = this.getWordDocument(id);
String fileName = file.getName();
if (fileName.endsWith(".docx")){
fileName = fileName.substring(0, fileName.length() - 5);
}
return this.datasetManager.convertToPDF(file, environment, fileName);
}*/
public eu.eudat.models.data.dmp.DataManagementPlan getSingle(String id, Principal principal, DynamicProjectConfiguration dynamicProjectConfiguration) throws InstantiationException, IllegalAccessException {
DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
if (dataManagementPlanEntity.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0)
2018-01-11 17:19:15 +01:00
throw new UnauthorisedException();
2018-06-27 12:29:21 +02:00
eu.eudat.models.data.dmp.DataManagementPlan datamanagementPlan = new eu.eudat.models.data.dmp.DataManagementPlan();
2018-01-11 17:19:15 +01:00
datamanagementPlan.fromDataModel(dataManagementPlanEntity);
2018-03-28 15:24:47 +02:00
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")));
2018-03-28 15:24:47 +02:00
});
2018-01-11 17:19:15 +01:00
return datamanagementPlan;
}
2017-12-20 15:52:09 +01:00
public DataManagementPlanOverviewModel getOverviewSingle(String id, Principal principal) throws InstantiationException, IllegalAccessException {
DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
if (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;
}
2019-04-26 16:05:15 +02:00
public eu.eudat.models.data.dmp.DataManagementPlan getSinglePublic(String id, DynamicProjectConfiguration dynamicProjectConfiguration) throws Exception {
DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
if (dataManagementPlanEntity != null && dataManagementPlanEntity.getStatus() == 1){
eu.eudat.models.data.dmp.DataManagementPlan datamanagementPlan = new eu.eudat.models.data.dmp.DataManagementPlan();
datamanagementPlan.fromDataModel(dataManagementPlanEntity);
datamanagementPlan.setDatasets(datamanagementPlan.getDatasets().stream().filter(dataset -> dataset.getStatus() == Dataset.Status.FINALISED.getValue()).collect(Collectors.toList()));
2019-04-26 16:05:15 +02:00
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;
}
else {
throw new Exception("Selected DMP is not public");
}
}
2018-08-24 17:21:02 +02:00
public List<DataManagementPlan> getWithCriteria(DMPDao dmpsRepository, DataManagementPlanCriteriaRequest dataManagementPlanCriteria, Principal principal) throws IllegalAccessException, InstantiationException {
UUID principalID = principal.getId();
2018-08-24 17:21:02 +02:00
QueryableList<DMP> items = dmpsRepository.getWithCriteria(dataManagementPlanCriteria.getCriteria()).withHint(HintedModelFactory.getHint(DataManagementPlan.class));
QueryableList<DMP> authenticatedItems = dmpsRepository.getAuthenticated(items, principalID);
2018-08-24 17:21:02 +02:00
List<eu.eudat.models.data.dmp.DataManagementPlan> datamanagementPlans = authenticatedItems.select(item -> new DataManagementPlan().fromDataModel(item));
2018-01-11 17:19:15 +01:00
return datamanagementPlans;
}
2017-12-20 15:52:09 +01:00
2018-03-28 15:24:47 +02:00
public List<Tuple<String, String>> getDynamicFields(String id, DynamicProjectConfiguration dynamicProjectConfiguration, DynamicFieldsCriteria criteria) throws IllegalAccessException, InstantiationException {
List<Tuple<String, String>> result = new LinkedList<>();
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> entity = new HttpEntity<>("parameters", headers);
Property property = dynamicProjectConfiguration.getConfiguration().getConfigurationProperties().stream()
.filter(item -> item.getId().equals(id)).findFirst().orElse(null);
StringBuilder stringBuilder = new StringBuilder();
if (criteria.getLike() != null) stringBuilder.append("?search=" + criteria.getLike());
if (property.getDependencies() != null && !property.getDependencies().isEmpty() && criteria.getDynamicFields() != null && !criteria.getDynamicFields().isEmpty()) {
property.getDependencies().stream().forEach(item -> {
DynamicFieldsCriteria.DynamicFieldDependencyCriteria dependencyCriteria = criteria.getDynamicFields().stream().filter(dfield -> dfield.getProperty().equals(item.getId()))
.findFirst().orElse(null);
if (dependencyCriteria != null) {
if (criteria.getLike() != null || property.getDependencies().indexOf(item) > 0)
stringBuilder.append("&");
stringBuilder.append(item.getQueryProperty() + "=" + dependencyCriteria.getValue());
}
});
ResponseEntity<ArrayList> response = restTemplate.exchange(property.getSourceUrl() + stringBuilder.toString(), HttpMethod.GET, entity, ArrayList.class);
response.getBody().forEach(item -> {
Tuple<String, String> tuple = new Tuple<>();
tuple.setId((String) (((Map<String, Object>) item).get(property.getExternalFieldId())));
tuple.setLabel((String) (((Map<String, Object>) item).get(property.getExternalFieldLabel())));
result.add(tuple);
});
} else {
ResponseEntity<ArrayList> response = restTemplate.exchange(property.getSourceUrl() + stringBuilder.toString(), HttpMethod.GET, entity, ArrayList.class);
response.getBody().forEach(item -> {
Tuple<String, String> tuple = new Tuple<>();
tuple.setId((String) (((Map<String, Object>) item).get(property.getExternalFieldId())));
tuple.setLabel((String) (((Map<String, Object>) item).get(property.getExternalFieldLabel())));
result.add(tuple);
});
}
return result;
}
public void createOrUpdate(ApiContext apiContext, DataManagementPlan dataManagementPlan, Principal principal) throws Exception {
2018-01-11 17:19:15 +01:00
DMP newDmp = dataManagementPlan.toDataModel();
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
//newDmp.setCreator(user);
2018-03-05 17:18:45 +01:00
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao(), user);
try {
DMP dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId());
newDmp.setCreated(dmp.getCreated());
if (dmp.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId())
.collect(Collectors.toList()).size() == 0) {
List<UserDMP> userDMPList = dmp.getUsers().stream().collect(Collectors.toList());
for (UserInfoListingModel userInfoListingModel : dataManagementPlan.getUsers()) {
for(UserDMP userDMP : userDMPList) {
if (!(userDMP.getUser().getId().equals(userInfoListingModel.getId()))) {
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().delete(userDMP);
}
}
}
}
} catch (Exception e) {
newDmp.setCreated(new Date());
}
2018-03-05 17:18:45 +01:00
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
if (dataManagementPlan.getStatus() == DMP.DMPStatus.FINALISED.getValue()) {
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()
.asQueryable().where((builder, root) -> root.get("id").in(dataManagementPlan.getDatasets()
.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList())))
.update(root -> root.<Integer>get("status"), Dataset.Status.FINALISED.getValue());
}
if (dataManagementPlan.getAssociatedUsers().size() == 0)
2018-02-09 16:54:41 +01:00
assignUser(newDmp, user, apiContext);
2018-02-08 16:54:31 +01:00
}
2017-12-20 15:52:09 +01:00
public void assignUser(DMP dmp, UserInfo userInfo, ApiContext apiContext) {
2018-02-08 16:54:31 +01:00
UserDMP userDMP = new UserDMP();
userDMP.setDmp(dmp);
userDMP.setUser(userInfo);
userDMP.setRole(UserDMP.UserDMPRoles.OWNER.getValue());
2018-03-05 17:18:45 +01:00
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
2018-01-11 17:19:15 +01:00
}
2017-12-20 15:52:09 +01:00
public void newVersion(UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
2018-03-05 17:18:45 +01:00
DMP oldDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(uuid);
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria();
LinkedList<UUID> list = new LinkedList<>();
list.push(oldDmp.getGroupId());
criteria.setGroupIds(list);
criteria.setAllVersions(false);
QueryableList<DMP> dataManagementPlanQueryableList = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria);
List<DMP> latestVersionDMP = dataManagementPlanQueryableList.toList();
if(latestVersionDMP.get(0).getVersion().equals(oldDmp.getVersion())){
DMP newDmp = dataManagementPlan.toDataModel();
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao(), user);
newDmp.setGroupId(oldDmp.getGroupId());
newDmp.setVersion(oldDmp.getVersion() + 1);
newDmp.setId(null);
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
// Assign creator.
UserDMP userDMP = new UserDMP();
userDMP.setDmp(newDmp);
userDMP.setUser(user);
userDMP.setRole((UserDMP.UserDMPRoles.OWNER.getValue()));
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao());
} else {
throw new DMPNewVersionException("Version to update not the latest.");
}
2018-02-08 09:42:02 +01:00
}
2018-02-07 10:56:30 +01:00
public void clone(UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
2018-02-08 16:54:31 +01:00
DMP newDmp = dataManagementPlan.toDataModel();
2018-03-05 17:18:45 +01:00
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao(), user);
2018-02-08 09:42:02 +01:00
newDmp.setGroupId(UUID.randomUUID());
newDmp.setVersion(0);
newDmp.setId(null);
2018-03-05 17:18:45 +01:00
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
// Assign creator.
UserDMP userDMP = new UserDMP();
userDMP.setDmp(newDmp);
userDMP.setUser(user);
userDMP.setRole((UserDMP.UserDMPRoles.OWNER.getValue()));
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
2018-03-05 17:18:45 +01:00
copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao());
2018-02-07 10:56:30 +01:00
}
public void delete(UUID uuid) throws DMPWithDatasetsDeleteException {
2019-02-15 16:11:38 +01:00
DatasetCriteria criteria = new DatasetCriteria();
List<UUID> dmpIds = Collections.singletonList(uuid);
criteria.setDmpIds(dmpIds);
if (apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).toList().size()>0)
throw new DMPWithDatasetsDeleteException("You cannot Remove Datamanagement Plan with Datasets");
2019-02-15 16:11:38 +01:00
DMP oldDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(uuid);
2018-02-07 10:56:30 +01:00
oldDmp.setStatus(DMP.DMPStatus.DELETED.getValue());
2018-03-05 17:18:45 +01:00
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(oldDmp);
2018-01-23 16:21:38 +01:00
}
private void createResearchersIfTheyDontExist(DMP newDmp, ResearcherDao researcherRepository) {
2018-01-11 17:19:15 +01:00
if (newDmp.getResearchers() != null && !newDmp.getResearchers().isEmpty()) {
2018-03-21 11:57:56 +01:00
for (eu.eudat.data.entities.Researcher researcher : newDmp.getResearchers()) {
2018-01-11 17:19:15 +01:00
ResearcherCriteria criteria = new ResearcherCriteria();
criteria.setLike(researcher.getReference());
2018-03-21 11:57:56 +01:00
List<eu.eudat.data.entities.Researcher> entries = researcherRepository.getWithCriteria(criteria).toList();
2018-03-28 15:24:47 +02:00
if (entries != null && !entries.isEmpty()) researcher.setId(entries.get(0).getId());
2018-01-25 16:24:21 +01:00
else researcher = researcherRepository.createOrUpdate(researcher);
2018-01-11 17:19:15 +01:00
}
}
}
2017-12-22 09:31:05 +01:00
private void createOrganisationsIfTheyDontExist(DMP newDmp, OrganisationDao organisationRepository) {
2018-01-11 17:19:15 +01:00
if (newDmp.getOrganisations() != null && !newDmp.getOrganisations().isEmpty()) {
2018-03-21 11:57:56 +01:00
for (eu.eudat.data.entities.Organisation organisation : newDmp.getOrganisations()) {
2018-01-11 17:19:15 +01:00
OrganisationCriteria criteria = new OrganisationCriteria();
criteria.setLike(organisation.getReference());
2018-03-21 11:57:56 +01:00
List<eu.eudat.data.entities.Organisation> entries = organisationRepository.getWithCriteria(criteria).toList();
2018-01-11 17:19:15 +01:00
if (entries != null && !entries.isEmpty()) organisation.setId(entries.get(0).getId());
2018-01-25 16:24:21 +01:00
else organisation = organisationRepository.createOrUpdate(organisation);
2018-01-11 17:19:15 +01:00
}
}
}
private void createProjectIfItDoesntExist(DMP newDmp, ProjectDao projectDao, UserInfo userInfo) {
2018-01-11 17:19:15 +01:00
if (newDmp.getProject() != null) {
Project project = newDmp.getProject();
ProjectCriteria criteria = new ProjectCriteria();
2018-02-02 17:21:46 +01:00
criteria.setReference(project.getReference());
2018-03-21 11:57:56 +01:00
eu.eudat.data.entities.Project projectEntity = projectDao.getWithCriteria(criteria).getSingleOrDefault();
2018-02-02 17:21:46 +01:00
if (projectEntity != null) project.setId(projectEntity.getId());
2018-01-11 17:19:15 +01:00
else {
2018-03-19 13:40:04 +01:00
project.setType(Project.ProjectType.EXTERNAL.getValue());
2018-01-11 17:19:15 +01:00
projectDao.createOrUpdate(project);
}
}
}
2018-02-07 10:56:30 +01:00
private void copyDatasets(DMP newDmp, DatasetDao datasetDao) {
2018-02-07 10:56:30 +01:00
List<CompletableFuture<Dataset>> futures = new LinkedList<>();
for (Dataset dataset : newDmp.getDataset()) {
2018-02-09 16:54:41 +01:00
datasetDao.asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class)).where((builder, root) -> builder.equal(root.get("id"), dataset.getId())).getSingleAsync()
.thenApplyAsync(entityDataset -> {
Dataset newDataset = new Dataset();
newDataset.update(entityDataset);
newDataset.setDmp(newDmp);
newDataset.setStatus(Dataset.Status.SAVED.getValue());
2018-05-28 11:50:42 +02:00
if (newDataset.getDatasetDataRepositories() != null) {
newDataset.setDatasetDataRepositories(newDataset.getDatasetDataRepositories().stream().map(item -> {
2018-02-09 16:54:41 +01:00
DataRepository dataRepository = new DataRepository();
dataRepository.setId(item.getId());
2018-05-28 11:50:42 +02:00
DatasetDataRepository datasetDataRepository = new DatasetDataRepository();
datasetDataRepository.setDataRepository(dataRepository);
datasetDataRepository.setDataset(newDataset);
return datasetDataRepository;
2018-02-09 16:54:41 +01:00
}).collect(Collectors.toSet()));
}
2018-05-28 11:50:42 +02:00
if (newDataset.getDatasetExternalDatasets() != null) {
newDataset.setDatasetExternalDatasets(newDataset.getDatasetExternalDatasets().stream().map(item -> {
2018-02-09 16:54:41 +01:00
ExternalDataset externalDataset = new ExternalDataset();
externalDataset.setId(item.getId());
2018-05-28 11:50:42 +02:00
DatasetExternalDataset datasetExternalDataset = new DatasetExternalDataset();
datasetExternalDataset.setExternalDataset(externalDataset);
datasetExternalDataset.setDataset(newDataset);
return datasetExternalDataset;
2018-02-09 16:54:41 +01:00
}).collect(Collectors.toSet()));
}
if (newDataset.getRegistries() != null) {
newDataset.setRegistries(newDataset.getRegistries().stream().map(item -> {
Registry registry = new Registry();
registry.setId(item.getId());
return registry;
}).collect(Collectors.toSet()));
}
if (newDataset.getServices() != null) {
newDataset.setServices(newDataset.getServices().stream().map(item -> {
Service service = new Service();
service.setId(item.getId());
2018-05-28 11:50:42 +02:00
DatasetService datasetService = new DatasetService();
datasetService.setService(service);
datasetService.setDataset(newDataset);
return datasetService;
2018-02-09 16:54:41 +01:00
}).collect(Collectors.toSet()));
}
newDataset.setCreated(new Date());
return newDataset;
}).thenApplyAsync(item -> {
2018-02-07 10:56:30 +01:00
futures.add(datasetDao.createOrUpdateAsync(item));
return futures;
}).join();
}
}
2018-10-08 17:14:27 +02:00
public FileEnvelope getXmlDocument(String id) throws InstantiationException, IllegalAccessException, IOException {
2018-10-08 17:14:27 +02:00
ExportXmlBuilder xmlBuilder = new ExportXmlBuilder();
VisibilityRuleService visibilityRuleService = utilitiesService.getVisibilityRuleService();
eu.eudat.data.entities.DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id));
2018-10-08 17:14:27 +02:00
List<Dataset> datasets = dmp.getDataset().stream().collect(Collectors.toList());
2019-03-05 12:59:34 +01:00
String fileName = dmp.getLabel();
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
File xmlFile = new File(fileName + ".xml");
2018-10-08 17:14:27 +02:00
BufferedWriter writer = new BufferedWriter(new FileWriter(xmlFile, true));
Document xmlDoc = XmlBuilder.getDocument();
Element dmpElement = xmlDoc.createElement("dmp");
2019-03-05 12:59:34 +01:00
Element dmpDescription = xmlDoc.createElement("description");
dmpDescription.setTextContent(dmp.getDescription());
dmpElement.appendChild(dmpDescription);
Element dmpName = xmlDoc.createElement("dmpName");
dmpName.setTextContent(dmp.getLabel());
dmpElement.appendChild(dmpName);
2019-03-05 12:59:34 +01:00
DMPProfile dmpProfile = dmp.getProfile();
Element dmpProfileElement = xmlDoc.createElement("dmpProfile");
Element dmpProfileName = xmlDoc.createElement("dmpProfileName");
if (!(dmpProfile == null)){
dmpProfileName.setTextContent(dmpProfile.getLabel());
dmpProfileElement.appendChild(dmpProfileName);
Element dmpProfileId = xmlDoc.createElement("dmpProfileId");
dmpProfileId.setTextContent(dmpProfile.getId().toString());
dmpProfileElement.appendChild(dmpProfileId);
Element values = xmlDoc.createElement("values");
values.setTextContent(dmpProfile.getDefinition());
dmpProfileElement.appendChild(values);
2019-03-05 12:59:34 +01:00
}
dmpElement.appendChild(dmpProfileElement);
Element project = xmlDoc.createElement("project");
Element label = xmlDoc.createElement("label");
label.setTextContent(dmp.getProject().getLabel());
project.appendChild(label);
Element projectId = xmlDoc.createElement("id");
projectId.setTextContent(dmp.getProject().getId().toString());
project.appendChild(projectId);
dmpElement.appendChild(project);
Element organisationsElement = xmlDoc.createElement("organisations");
for (Organisation organisation : dmp.getOrganisations()) {
Element organisationElement = xmlDoc.createElement("organisation");
2019-03-05 12:59:34 +01:00
Element organisationNameElement = xmlDoc.createElement("name");
organisationNameElement.setTextContent(organisation.getLabel());
Element organisationReferenceElement = xmlDoc.createElement("reference");
organisationReferenceElement.setTextContent(organisation.getReference());
organisationElement.appendChild(organisationNameElement);
organisationElement.appendChild(organisationReferenceElement);
organisationsElement.appendChild(organisationElement);
}
dmpElement.appendChild(organisationsElement);
Element researchersElement = xmlDoc.createElement("researchers");
for (Researcher researcher : dmp.getResearchers()) {
2019-03-05 12:59:34 +01:00
Element researcherElement = xmlDoc.createElement("researcher");
Element researcherNameElement = xmlDoc.createElement("name");
researcherNameElement.setTextContent(researcher.getLabel());
Element researcherReferenceElement = xmlDoc.createElement("reference");
researcherReferenceElement.setTextContent(researcher.getReference());
researcherElement.appendChild(researcherNameElement);
researcherElement.appendChild(researcherReferenceElement);
researchersElement.appendChild(researcherElement);
}
dmpElement.appendChild(researchersElement);
2018-10-08 17:14:27 +02:00
Element datasetsElement = xmlDoc.createElement("datasets");
for (Dataset dataset : datasets) {
Element datasetElement = xmlDoc.createElement("dataset");
DatasetWizardModel datasetWizardModel = new DatasetWizardModel();
Map<String, Object> properties = new HashMap<>();
if (dataset.getProperties() != null) {
JSONObject jobject = new JSONObject(dataset.getProperties());
properties = jobject.toMap();
}
PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(datasetWizardModel, dataset);
2018-10-08 17:14:27 +02:00
visibilityRuleService.setProperties(properties);
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
datasetElement.appendChild(xmlBuilder.createPages(pagedDatasetProfile.getPages(), visibilityRuleService, xmlDoc));
datasetsElement.appendChild(datasetElement);
}
2019-03-05 12:59:34 +01:00
Element profiles = xmlDoc.createElement("profiles");
// Get DatasetProfiles from DMP to add to XML.
for (DatasetProfile datasetProfile : dmp.getAssociatedDmps()) {
Element profile = xmlDoc.createElement("profile");
Element profileLabel = xmlDoc.createElement("profilelabel");
profileLabel.setTextContent(datasetProfile.getLabel());
profile.appendChild(profileLabel);
Element profileId = xmlDoc.createElement("profileId");
profileId.setTextContent(datasetProfile.getId().toString());
profile.appendChild(profileId);
profiles.appendChild(profile);
2019-03-05 12:59:34 +01:00
}
dmpElement.appendChild(profiles);
2018-10-08 17:14:27 +02:00
dmpElement.appendChild(datasetsElement);
2019-03-05 12:59:34 +01:00
xmlDoc.appendChild(dmpElement);
2018-10-08 17:14:27 +02:00
String xml = XmlBuilder.generateXml(xmlDoc);
writer.write(xml);
writer.close();
FileEnvelope fileEnvelope = new FileEnvelope();
fileEnvelope.setFile(xmlFile);
fileEnvelope.setFilename(dmp.getLabel());
2018-10-08 17:14:27 +02:00
return fileEnvelope;
}
public ResponseEntity<byte[]> getRDAJsonDocument(String id) throws IOException {
eu.eudat.data.entities.DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id));
DmpRDAExportModel dmpExport = new DmpRDAExportModel().fromDataModel(dmp);
RDAExportModel rdaExportModel = new RDAExportModel();
rdaExportModel.setDmp(dmpExport);
ObjectMapper mapper = new ObjectMapper();
String fileName = dmp.getLabel();
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
File file = new File(fileName);
try {
mapper.writeValue(file, rdaExportModel);
}
catch (IOException e) {
e.printStackTrace();
}
InputStream resource = new FileInputStream(file);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(file.length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.set("Content-Disposition", "attachment;filename=" + file.getName());
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
byte[] content = org.apache.poi.util.IOUtils.toByteArray(resource);
resource.close();
Files.deleteIfExists(file.toPath());
return new ResponseEntity<>(content, responseHeaders, HttpStatus.OK);
}
public ResponseEntity<byte[]> getDocument(String id, String contentType) throws InstantiationException, IllegalAccessException, IOException {
File file;
switch (contentType){
case "application/xml":
file = getXmlDocument(id).getFile();
break;
case "application/msword":
file = getWordDocument(id);
break;
2019-04-05 11:20:06 +02:00
/*case "application/pdf":
file = getPdfDocument(id);
break;*/
default:
file = getXmlDocument(id).getFile();
}
InputStream resource = new FileInputStream(file);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(file.length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.set("Content-Disposition", "attachment;filename=" + file.getName());
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
byte[] content = org.apache.poi.util.IOUtils.toByteArray(resource);
resource.close();
Files.deleteIfExists(file.toPath());
return new ResponseEntity<>(content,
responseHeaders,
HttpStatus.OK);
}
2019-03-05 12:59:34 +01:00
public List<DmpImportModel> createDmpFromXml( ApiContext apiContext, MultipartFile[] files, Principal principal) throws IOException, JAXBException, Exception {
List<DmpImportModel> dataManagementPlans = new ArrayList<>();
// Jaxb approach.
JAXBContext jaxbContext;
for (MultipartFile multipartFile : Arrays.asList(files)){ // Gets one item from the array.
try{
InputStream in = multipartFile.getInputStream(); // Transforms item to InputStream.
jaxbContext = JAXBContext.newInstance(DmpImportModel.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
DmpImportModel dmpImportModel = (DmpImportModel)jaxbUnmarshaller.unmarshal(in);
dataManagementPlans.add(dmpImportModel);
}
catch (IOException | JAXBException ex){
ex.printStackTrace();
}
// TODO Iterate through the list of dataManagmentPlans.
// Creates new dataManagmentPlan to fill it with the data model that was parsed from the xml.
// Creates properties.
DataManagementPlan dm = new DataManagementPlan();
DataManagementPlanProfile dmpProfile = new DataManagementPlanProfile();
List<Field> fieldList = new LinkedList<>();
Field field = new Field();
field.setLabel(dataManagementPlans.get(0).getDmpProfile().getDmpProfileName());
field.setId(dataManagementPlans.get(0).getDmpProfile().getDmpProfileId());
fieldList.add(field);
dmpProfile.setFields(fieldList);
/*Tuple tuple = new Tuple();
2019-03-05 12:59:34 +01:00
tuple.setId(dataManagementPlans.get(0).getDmpProfile().getDmpProfileId());
tuple.setLabel(dataManagementPlans.get(0).getDmpProfile().getDmpProfileName());*/
2019-03-05 12:59:34 +01:00
eu.eudat.models.data.project.Project project = new eu.eudat.models.data.project.Project();
ProjectImportModels projectImport = dataManagementPlans.get(0).getProjectImport();
project.setId(projectImport.getId());
project.setLabel(projectImport.getLabel());
project.setAbbreviation(projectImport.getAbbreviation());
project.setDescription(projectImport.getDescription());
List<eu.eudat.models.data.dmp.AssociatedProfile> associatedProfiles = new LinkedList<>();
for(AssociatedProfileImportModels a : dataManagementPlans.get(0).getProfilesImportModels()) {
AssociatedProfile associatedProfile = new AssociatedProfile();
associatedProfile.setId(a.getId());
associatedProfile.setLabel(a.getLabel());
associatedProfiles.add(associatedProfile);
}
List< eu.eudat.models.data.dmp.Organisation > organisations = new ArrayList<>();
2019-03-06 16:35:56 +01:00
for(OrganisationImportModel org : dataManagementPlans.get(0).getOrganisationImportModels()) {
eu.eudat.models.data.dmp.Organisation organisation = new eu.eudat.models.data.dmp.Organisation();
organisation.setLabel(org.getOrganaisationNameImport());
organisation.setId(org.getOrganaisationReferenceImport());
organisations.add(organisation);
}
2019-03-05 12:59:34 +01:00
List<eu.eudat.models.data.dmp.Researcher> researchers = new LinkedList<>();
2019-03-06 16:35:56 +01:00
for(ResearcherImportModels res : dataManagementPlans.get(0).getResearchersImportModels()) {
eu.eudat.models.data.dmp.Researcher researcher = new eu.eudat.models.data.dmp.Researcher();
researcher.setLabel(res.getResearcherImportName());
researcher.setId(res.getResearcherImportReference());
researchers.add(researcher);
}
List<UserListingModel> associatedUsers = new LinkedList<>();
2019-03-05 12:59:34 +01:00
List<DynamicFieldWithValue> dynamicFields = new LinkedList<>();
// Sets properties.
dm.setLabel(files[0].getOriginalFilename()); // Sets label.
dm.setProject(project); //Sets project property.
dm.setDescription(dataManagementPlans.get(0).getDescriptionImport()); // Sets description property.
dm.setProfiles(associatedProfiles);
dm.setOrganisations(organisations); // Sets organisations property.
dm.setResearchers(researchers); // Sets researchers property.
dm.setAssociatedUsers(associatedUsers); // Sets associatedUsers property.
dm.setDynamicFields(dynamicFields); // Sets dynamicFields property.
dm.setDefinition(dmpProfile);
2019-03-05 12:59:34 +01:00
createOrUpdate(apiContext, dm, principal);
System.out.println(dm);
}
return dataManagementPlans;
}
2017-12-15 00:01:26 +01:00
}