keyword-tags exported-imported fixes, prefilling more mapping
This commit is contained in:
parent
70d37cead1
commit
125a97baed
|
@ -1054,14 +1054,10 @@ public class DatasetManager {
|
|||
if (!value.toString().equals("\"\"")) {
|
||||
String stringValue = value.toString().replaceAll("=", ":");
|
||||
JSONArray values = new JSONArray(stringValue);
|
||||
if (values != null) {
|
||||
values.iterator().forEachRemaining(element -> {
|
||||
Map<String, Object> data = ((JSONObject) element).toMap();
|
||||
this.addTag(tags, wizardModel.getTags(), data.get("id").toString(), data.get("name").toString());
|
||||
});
|
||||
} else {
|
||||
this.addTag(tags, wizardModel.getTags(), "", value.asText());
|
||||
}
|
||||
values.iterator().forEachRemaining(element -> {
|
||||
Map<String, Object> data = ((JSONObject) element).toMap();
|
||||
this.addTag(tags, wizardModel.getTags(), data.get("id").toString(), data.get("name").toString());
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -20,9 +20,13 @@ import eu.eudat.models.data.dmp.DataManagementPlan;
|
|||
import eu.eudat.models.data.externaldataset.ExternalDatasetListingModel;
|
||||
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||
import net.minidev.json.JSONValue;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -346,7 +350,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
Class<?>[] params = setterMethod.getParameterTypes();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
//GK: Tags Special logic
|
||||
if (prefillingMapping.getTarget().equals("tags")) {
|
||||
if (!value.equals("null") && prefillingMapping.getTarget().equals("tags")) {
|
||||
List<Object> rawTags = (List<Object>) mapper.readValue(value, params[0]);
|
||||
if (rawTags.get(0) instanceof String) {
|
||||
List<Tag> parsedTags = rawTags.stream().map(rawTag -> new Tag((String) rawTag, (String) rawTag)).collect(Collectors.toList());
|
||||
|
@ -359,9 +363,44 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
}
|
||||
} else {
|
||||
List<JsonNode> nodes = JsonSearcher.findNodes(parentNode, "rdaProperty", prefillingMapping.getMaDmpTarget());
|
||||
if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.available_until") && !value.equals("null")){
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd");
|
||||
LocalDate date = LocalDate.parse(value.replace("\"", ""), formatter);
|
||||
date = date.plusYears(20);
|
||||
value = date.toString();
|
||||
}
|
||||
for (JsonNode node: nodes) {
|
||||
String id = node.get(0) != null ? node.get(0).get("id").asText() : node.get("id").asText();
|
||||
properties.put(id, value);
|
||||
if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.format")){
|
||||
JSONArray jsonArr = new JSONArray(value);
|
||||
List<String> formats = new ArrayList<>();
|
||||
String extension;
|
||||
for (int i = 0; i < jsonArr.length(); i++){
|
||||
JSONObject jsonObj = jsonArr.getJSONObject(i);
|
||||
String filename = (String) jsonObj.get("filename");
|
||||
int index = filename.lastIndexOf('.');
|
||||
extension = (index > 0) ? filename.substring(index+1) : filename;
|
||||
formats.add(extension);
|
||||
}
|
||||
formats = formats.stream().distinct().collect(Collectors.toList());
|
||||
String format = String.join(", ", formats);
|
||||
properties.put(id, format);
|
||||
}
|
||||
else if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.data_access")){
|
||||
value = value.replace("\"", "");
|
||||
if(value.equals("open")){
|
||||
properties.put(id, value);
|
||||
}
|
||||
else if(value.equals("restricted")){
|
||||
properties.put(id, "shared");
|
||||
}
|
||||
else{
|
||||
properties.put(id, "closed");
|
||||
}
|
||||
}
|
||||
else{
|
||||
properties.put(id, value.replace("\"", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package eu.eudat.models.rda.mapper;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.data.entities.DatasetProfile;
|
||||
import eu.eudat.elastic.criteria.DatasetCriteria;
|
||||
import eu.eudat.elastic.entities.Tag;
|
||||
import eu.eudat.logic.managers.DatasetManager;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.utilities.json.JavaToJson;
|
||||
import eu.eudat.logic.utilities.helpers.StreamDistinctBy;
|
||||
import eu.eudat.logic.utilities.json.JsonSearcher;
|
||||
import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel;
|
||||
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
||||
|
@ -19,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
import java.net.URI;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
@ -131,7 +130,7 @@ public class DatasetRDAMapper {
|
|||
rda.setKeyword(keywordNodes.stream().map(keywordNode -> {
|
||||
JsonNode value = keywordNode.get("value");
|
||||
if (value.isArray()) {
|
||||
return StreamSupport.stream(value.spliterator(), false).map(node -> KeywordRDAMapper.toRDA(node.asText())).flatMap(Collection::stream).collect(Collectors.toList());
|
||||
return StreamSupport.stream(value.spliterator(), false).map(node -> KeywordRDAMapper.toRDA(node.toString())).flatMap(Collection::stream).collect(Collectors.toList());
|
||||
} else {
|
||||
return KeywordRDAMapper.toRDA(keywordNode.get("value").asText());
|
||||
}
|
||||
|
@ -331,9 +330,14 @@ public class DatasetRDAMapper {
|
|||
// if (keywordIds.size() < rda.getKeyword().size()) {
|
||||
// takeAll = true;
|
||||
// }
|
||||
DatasetCriteria criteria = new DatasetCriteria();
|
||||
criteria.setHasTags(true);
|
||||
List<Tag> tags = this.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());
|
||||
if(!rda.getKeyword().isEmpty()){
|
||||
for (int i = 0; i < keywordIds.size(); i++) {
|
||||
// if (takeAll) {
|
||||
List<Tag> templateTags = tags.stream().filter(tag -> rda.getKeyword().contains(tag.getName())).collect(Collectors.toList());
|
||||
properties.put(keywordIds.get(0), mapper.writeValueAsString(templateTags));
|
||||
// for (int i = 0; i < keywordIds.size(); i++) {
|
||||
// //if (takeAll) {
|
||||
// List<String> tags = new ArrayList<>();
|
||||
// for (String keyword : rda.getKeyword()) {
|
||||
// tags.add(mapper.writeValueAsString(toTagEntity(keyword)));
|
||||
|
@ -342,8 +346,8 @@ public class DatasetRDAMapper {
|
|||
// } else {
|
||||
// properties.put(keywordIds.get(i), mapper.writeValueAsString(toTagEntity(rda.getKeyword().get(i))));
|
||||
// }
|
||||
properties.put(keywordIds.get(i), rda.getKeyword().get(i));
|
||||
}
|
||||
// properties.put(keywordIds.get(i), rda.getKeyword().get(i));
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,9 @@ package eu.eudat.models.rda.mapper;
|
|||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.elastic.entities.Dataset;
|
||||
import eu.eudat.elastic.entities.Tag;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.utilities.json.JavaToJson;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -15,15 +17,15 @@ public class KeywordRDAMapper {
|
|||
private static final Logger logger = LoggerFactory.getLogger(KeywordRDAMapper.class);
|
||||
|
||||
public static List<String> toRDA(String value) {
|
||||
if (!value.isEmpty()) {
|
||||
if (!value.isEmpty() && !value.equals("null")) {
|
||||
try {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String valueJson = JavaToJson.objectStringToJson(value);
|
||||
List<Tag> tags = Arrays.asList(mapper.readValue(valueJson, Tag[].class));
|
||||
return tags.stream().map(Tag::getName).collect(Collectors.toList());
|
||||
Tag tag = mapper.readValue(valueJson, Tag.class);
|
||||
return new ArrayList<>(Collections.singletonList(tag.getName()));
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.warn(e.getMessage() + ". Attempting to parse it as a String list.");
|
||||
return new ArrayList<>(Arrays.asList(value.replace(" ", "").split(",")));
|
||||
logger.warn(e.getMessage() + ". Attempting to parse it as a String since its a new tag.");
|
||||
return new ArrayList<>(Collections.singletonList(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1039,11 +1039,19 @@
|
|||
<mapping source="metadata.dates.valid" maDmpTarget="dataset.distribution.available_until"/>
|
||||
<mapping source="metadata.access_right" maDmpTarget="dataset.distribution.data_access"/>
|
||||
<mapping source="metadata.publication_date" maDmpTarget="dataset.issued"/>
|
||||
<mapping source="metadata.license.id" maDmpTarget="dataset.distribution.license.license_ref"/>
|
||||
<mapping source="metadata.license.created" maDmpTarget="dataset.distribution.license.start_date"/>
|
||||
<mapping source="files" maDmpTarget="dataset.distribution.format"/>
|
||||
</mappings>
|
||||
<fixedMappings>
|
||||
<fixedMapping maDmpTarget="dataset.distribution.host.title" value="Zenodo" />
|
||||
<fixedMapping maDmpTarget="dataset.metadata.metadata_standard_id.identifier" value="https://schema.datacite.org/meta/kernel-4.4/" />
|
||||
<fixedMapping maDmpTarget="dataset.metadata.metadata_standard_id.type" value="url" />
|
||||
<fixedMapping maDmpTarget="dataset.distribution.host.description" value="Repository hosted by Zenodo" />
|
||||
<fixedMapping maDmpTarget="dataset.distribution.host.url" value="https://zenodo.org" />
|
||||
<fixedMapping maDmpTarget="dataset.distribution.host.pid_system" value="doi" />
|
||||
<fixedMapping maDmpTarget="dataset.security_and_privacy.title" value="TBD" />
|
||||
<fixedMapping maDmpTarget="dataset.security_and_privacy.description" value="TBD" />
|
||||
<fixedMapping maDmpTarget="dataset.preservation_statement" value="TBD" />
|
||||
</fixedMappings>
|
||||
</prefillingGet>
|
||||
</config>
|
||||
|
|
Loading…
Reference in New Issue