|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
package eu.eudat.logic.managers;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import eu.eudat.data.dao.criteria.*;
|
|
|
|
|
import eu.eudat.data.dao.entities.DataRepositoryDao;
|
|
|
|
|
import eu.eudat.data.dao.entities.DatasetDao;
|
|
|
|
@ -49,22 +49,22 @@ import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
|
|
|
|
import eu.eudat.queryable.QueryableList;
|
|
|
|
|
import eu.eudat.types.Authorities;
|
|
|
|
|
import eu.eudat.types.MetricNames;
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
|
import jakarta.xml.bind.JAXBContext;
|
|
|
|
|
import jakarta.xml.bind.JAXBException;
|
|
|
|
|
import jakarta.xml.bind.Unmarshaller;
|
|
|
|
|
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
|
|
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.core.io.FileSystemResource;
|
|
|
|
|
import org.springframework.http.*;
|
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import org.w3c.dom.Document;
|
|
|
|
|
import org.w3c.dom.Element;
|
|
|
|
@ -75,9 +75,6 @@ import javax.activation.MimetypesFileTypeMap;
|
|
|
|
|
import javax.persistence.criteria.Join;
|
|
|
|
|
import javax.persistence.criteria.JoinType;
|
|
|
|
|
import javax.transaction.Transactional;
|
|
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
|
|
import javax.xml.bind.JAXBException;
|
|
|
|
|
import javax.xml.bind.Unmarshaller;
|
|
|
|
|
import javax.xml.parsers.DocumentBuilder;
|
|
|
|
|
import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
|
|
import javax.xml.xpath.XPath;
|
|
|
|
@ -91,8 +88,6 @@ import java.time.temporal.ChronoUnit;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
|
import java.util.zip.ZipInputStream;
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
|
public class DatasetManager {
|
|
|
|
@ -279,7 +274,7 @@ public class DatasetManager {
|
|
|
|
|
return dataTable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DatasetWizardModel getSingle(String id, Principal principal) {
|
|
|
|
|
public DatasetWizardModel getSingle(String id, Principal principal) throws JsonProcessingException {
|
|
|
|
|
DatasetWizardModel dataset = new DatasetWizardModel();
|
|
|
|
|
eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
|
|
|
|
|
if (datasetEntity.getDmp().getUsers()
|
|
|
|
@ -380,12 +375,11 @@ public class DatasetManager {
|
|
|
|
|
return databaseRepository.getDatasetDao().find(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PagedDatasetProfile getPagedProfile(DatasetWizardModel dataset, eu.eudat.data.entities.Dataset datasetEntity) {
|
|
|
|
|
public PagedDatasetProfile getPagedProfile(DatasetWizardModel dataset, eu.eudat.data.entities.Dataset datasetEntity) throws JsonProcessingException {
|
|
|
|
|
eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(datasetEntity.getProfile());
|
|
|
|
|
datasetprofile.setStatus(dataset.getStatus());
|
|
|
|
|
if (datasetEntity.getProperties() != null) {
|
|
|
|
|
JSONObject jObject = new JSONObject(datasetEntity.getProperties());
|
|
|
|
|
Map<String, Object> properties = jObject.toMap();
|
|
|
|
|
Map<String, Object> properties = apiContext.getObjectMapper().readValue(datasetEntity.getProperties(), HashMap.class);
|
|
|
|
|
datasetprofile.fromJsonObject(properties);
|
|
|
|
|
}
|
|
|
|
|
PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile();
|
|
|
|
@ -451,8 +445,7 @@ public class DatasetManager {
|
|
|
|
|
|
|
|
|
|
Map<String, Object> properties = new HashMap<>();
|
|
|
|
|
if (datasetEntity.getProperties() != null) {
|
|
|
|
|
JSONObject jObject = new JSONObject(datasetEntity.getProperties());
|
|
|
|
|
properties = jObject.toMap();
|
|
|
|
|
properties = apiContext.getObjectMapper().readValue(datasetEntity.getProperties(), HashMap.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
|
|
|
@ -484,8 +477,7 @@ public class DatasetManager {
|
|
|
|
|
|
|
|
|
|
Map<String, Object> properties = new HashMap<>();
|
|
|
|
|
if (dataset.getDatasetProfileDefinition() != null) {
|
|
|
|
|
JSONObject jObject = new JSONObject(propertiesModelToString(dataset.getDatasetProfileDefinition()));
|
|
|
|
|
properties = jObject.toMap();
|
|
|
|
|
properties = apiContext.getObjectMapper().readValue(propertiesModelToString(dataset.getDatasetProfileDefinition()), HashMap.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
|
|
|
@ -542,8 +534,7 @@ public class DatasetManager {
|
|
|
|
|
throw new UnauthorisedException();
|
|
|
|
|
Map<String, Object> properties = new HashMap<>();
|
|
|
|
|
if (datasetEntity.getProperties() != null) {
|
|
|
|
|
JSONObject jobject = new JSONObject(datasetEntity.getProperties());
|
|
|
|
|
properties = jobject.toMap();
|
|
|
|
|
properties = apiContext.getObjectMapper().readValue(datasetEntity.getProperties(), HashMap.class);
|
|
|
|
|
}
|
|
|
|
|
PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, datasetEntity);
|
|
|
|
|
visibilityRuleService.setProperties(properties);
|
|
|
|
@ -656,9 +647,9 @@ public class DatasetManager {
|
|
|
|
|
nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject obj = new JSONObject(dataset.getProperties());
|
|
|
|
|
Map<String, Object> obj = apiContext.getObjectMapper().readValue(dataset.getProperties(), HashMap.class);
|
|
|
|
|
VisibilityRuleService visibilityRuleService = this.apiContext.getUtilitiesService().getVisibilityRuleService();
|
|
|
|
|
visibilityRuleService.setProperties(obj.toMap());
|
|
|
|
|
visibilityRuleService.setProperties(obj);
|
|
|
|
|
|
|
|
|
|
dataset.setProfile(profile);
|
|
|
|
|
PagedDatasetProfile pagedDatasetProfile = this.getPagedProfile(new DatasetWizardModel(), dataset);
|
|
|
|
@ -666,7 +657,7 @@ public class DatasetManager {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (String validator : datasetProfileValidators) {
|
|
|
|
|
if ((obj.has(validator) && (obj.getString(validator) == null || obj.getString(validator).trim().isEmpty())) && isElementVisible(nodeList, validator, visibilityRuleService)) {
|
|
|
|
|
if ((obj.containsKey(validator) && (obj.get(validator) == null || obj.get(validator).toString().trim().isEmpty())) && isElementVisible(nodeList, validator, visibilityRuleService)) {
|
|
|
|
|
throw new Exception("Field value of " + validator + " must be filled.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -695,11 +686,10 @@ public class DatasetManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String propertiesModelToString(PagedDatasetProfile pagedDatasetProfile) {
|
|
|
|
|
private String propertiesModelToString(PagedDatasetProfile pagedDatasetProfile) throws JsonProcessingException {
|
|
|
|
|
Map<String, Object> values = new LinkedHashMap<>();
|
|
|
|
|
pagedDatasetProfile.toMap(values);
|
|
|
|
|
JSONObject jobject = new JSONObject(values);
|
|
|
|
|
return jobject.toString();
|
|
|
|
|
return apiContext.getObjectMapper().writeValueAsString(values);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void updateTags(Dataset datasetEntity, List<Tag> tags) throws Exception {
|
|
|
|
@ -908,12 +898,9 @@ public class DatasetManager {
|
|
|
|
|
)))))
|
|
|
|
|
.collect(Collectors.toMap(DatasetImportField::getId, DatasetImportField::getValue));
|
|
|
|
|
|
|
|
|
|
// Transforms map into json file.
|
|
|
|
|
JSONObject jsonDatasetProperties = new JSONObject(importMap);
|
|
|
|
|
|
|
|
|
|
// Creates the entity data set to save.
|
|
|
|
|
eu.eudat.data.entities.Dataset entity = new Dataset();
|
|
|
|
|
entity.setProperties(jsonDatasetProperties.toString());
|
|
|
|
|
entity.setProperties(apiContext.getObjectMapper().writeValueAsString(importMap));
|
|
|
|
|
entity.setLabel(importFile.getOriginalFilename());
|
|
|
|
|
DMP dmp = new DMP();
|
|
|
|
|
dmp.setId(UUID.fromString(dmpId));
|
|
|
|
@ -942,7 +929,7 @@ public class DatasetManager {
|
|
|
|
|
// TODO: When tags functionality return.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DatasetWizardModel datasetUpdateProfile(String id) {
|
|
|
|
|
public DatasetWizardModel datasetUpdateProfile(String id) throws JsonProcessingException {
|
|
|
|
|
DatasetWizardModel dataset = new DatasetWizardModel();
|
|
|
|
|
eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
|
|
|
|
|
eu.eudat.elastic.entities.Dataset datasetElastic;
|
|
|
|
@ -982,12 +969,11 @@ public class DatasetManager {
|
|
|
|
|
return dataset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PagedDatasetProfile getLatestDatasetProfile(Dataset datasetEntity, DatasetProfile profile) {
|
|
|
|
|
public PagedDatasetProfile getLatestDatasetProfile(Dataset datasetEntity, DatasetProfile profile) throws JsonProcessingException {
|
|
|
|
|
eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(profile);
|
|
|
|
|
datasetprofile.setStatus(datasetEntity.getStatus());
|
|
|
|
|
if (datasetEntity.getProperties() != null) {
|
|
|
|
|
JSONObject jobject = new JSONObject(datasetEntity.getProperties());
|
|
|
|
|
Map<String, Object> properties = jobject.toMap();
|
|
|
|
|
Map<String, Object> properties = apiContext.getObjectMapper().readValue(datasetEntity.getProperties(), HashMap.class);
|
|
|
|
|
datasetprofile.fromJsonObject(properties);
|
|
|
|
|
}
|
|
|
|
|
PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile();
|
|
|
|
@ -1039,9 +1025,8 @@ public class DatasetManager {
|
|
|
|
|
public void getTagsFromProfile(DatasetWizardModel wizardModel, Dataset dataset) throws IOException {
|
|
|
|
|
dataset.setProfile(apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(dataset.getProfile().getId()));
|
|
|
|
|
wizardModel.setDatasetProfileDefinition(this.getPagedProfile(wizardModel, dataset));
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
String json = mapper.writeValueAsString(wizardModel.getDatasetProfileDefinition());
|
|
|
|
|
JsonNode propertiesJson = mapper.readTree(json);
|
|
|
|
|
String json = apiContext.getObjectMapper().writeValueAsString(wizardModel.getDatasetProfileDefinition());
|
|
|
|
|
JsonNode propertiesJson = apiContext.getObjectMapper().readTree(json);
|
|
|
|
|
DatasetCriteria criteria = new DatasetCriteria();
|
|
|
|
|
criteria.setHasTags(true);
|
|
|
|
|
List<Tag> tags = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().query(criteria).stream().map(eu.eudat.elastic.entities.Dataset::getTags).flatMap(Collection::stream).filter(StreamDistinctBy.distinctByKey(Tag::getId)).collect(Collectors.toList());
|
|
|
|
@ -1053,11 +1038,20 @@ public class DatasetManager {
|
|
|
|
|
JsonNode value = node.get("value");
|
|
|
|
|
if (!value.toString().equals("\"\"")) {
|
|
|
|
|
String stringValue = value.toString().replaceAll("=", ":");
|
|
|
|
|
JSONArray values = new JSONArray(stringValue);
|
|
|
|
|
values.iterator().forEachRemaining(element -> {
|
|
|
|
|
Map<String, Object> data = ((JSONObject) element).toMap();
|
|
|
|
|
this.addTag(tags, wizardModel.getTags(), data.get("id").toString(), data.get("name").toString());
|
|
|
|
|
});
|
|
|
|
|
List<Map<String, Object>> values = null;
|
|
|
|
|
try {
|
|
|
|
|
values = apiContext.getObjectMapper().readValue(stringValue, LinkedList.class);
|
|
|
|
|
} catch (JsonProcessingException e) {
|
|
|
|
|
logger.error(e.getLocalizedMessage(), e);
|
|
|
|
|
}
|
|
|
|
|
if (values != null) {
|
|
|
|
|
values.iterator().forEachRemaining(element -> {
|
|
|
|
|
Map<String, Object> data = element;
|
|
|
|
|
this.addTag(tags, wizardModel.getTags(), data.get("id").toString(), data.get("name").toString());
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.addTag(tags, wizardModel.getTags(), "", value.asText());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|