rda export changes

This commit is contained in:
Efstratios Giannopoulos 2024-05-29 13:45:42 +03:00
parent 525a690d98
commit 9b44da2aea
17 changed files with 763 additions and 50 deletions

View File

@ -23,7 +23,7 @@ public class CostRDAMapper{
Map<String, Cost> rdaMap = new HashMap<>();
for(Map.Entry<String, List<FieldModel>> entry: nodes.entrySet()){
for(FieldModel node: entry.getValue()) {
String rdaProperty = node.getSchematics().stream().filter(schematic -> schematic.startsWith("rda.dmp.cost")).findFirst().orElse("");
String rdaProperty = node.getSemantics().stream().filter(schematic -> schematic.startsWith("rda.dmp.cost")).findFirst().orElse("");
org.opencdmp.commonmodels.models.description.FieldModel rdaValue = valueFields.stream().filter(x -> x.getId().equals(node.getId())).findFirst().orElse(null);
if (rdaValue == null || rdaValue.getTextValue() == null || rdaValue.getTextValue().isBlank()) {
continue;

View File

@ -21,7 +21,7 @@ public class DatasetIdRDAMapper{
DatasetId data = new DatasetId();
for (Map.Entry<String, List<FieldModel>> entry: nodes.entrySet()) {
for (FieldModel node: entry.getValue()) {
String rdaProperty = node.getSchematics().stream().filter(schematic -> schematic.startsWith("rda.dataset.dataset_id")).findFirst().orElse("");
String rdaProperty = node.getSemantics().stream().filter(schematic -> schematic.startsWith("rda.dataset.dataset_id")).findFirst().orElse("");
if (node.getData() == null) {
continue;
}

View File

@ -292,7 +292,7 @@ public class DatasetRDAMapper {
for (FieldModel node : entry.getValue()) {
List<org.opencdmp.commonmodels.models.description.FieldModel> fieldValues = this.findValueField(node, descriptionEntity.getProperties());
org.opencdmp.commonmodels.models.description.FieldModel fieldValue = fieldValues.getFirst();
String rdaProperty = node.getSchematics().stream().filter(schematic -> schematic.startsWith("rda.dmp.ethical_issues")).findFirst().orElse("");
String rdaProperty = node.getSemantics().stream().filter(schematic -> schematic.startsWith("rda.dmp.ethical_issues")).findFirst().orElse("");
if (fieldValue == null) {
continue;
}

View File

@ -88,7 +88,7 @@ public class DistributionRDAMapper {
break;
case LICENSE:
List<FieldModel> licenseNodes = nodes.values().stream().flatMap(Collection::stream).filter(lnode -> {
for (String schematic : lnode.getSchematics()) {
for (String schematic : lnode.getSemantics()) {
if (schematic.startsWith("rda.dataset.distribution.license")) {
return true;
}
@ -151,7 +151,7 @@ public class DistributionRDAMapper {
}
private static String getRdaDistributionProperty(FieldModel node) {
return node.getSchematics().stream().filter(schematic -> schematic.startsWith("rda.dataset.distribution")).findFirst().orElse("");
return node.getSemantics().stream().filter(schematic -> schematic.startsWith("rda.dataset.distribution")).findFirst().orElse("");
}
private enum ExportPropertyName {

View File

@ -18,24 +18,13 @@ public class DmpContactModelContactRDAMapper {
public Contact toRDA(DmpContactModel model) {
if (model == null) return null;
Contact rda = new Contact();
if (model.getUser() != null){
rda = this.contactRDAMapper.toRDA(model.getUser());
} else {
if (model.getLastName() == null) throw new MyApplicationException("Last Name is missing");
if (model.getEmail() == null) throw new MyApplicationException("Email is missing");
if (model.getLastName() == null) throw new MyApplicationException("Last Name is missing");
if (model.getEmail() == null) throw new MyApplicationException("Email is missing");
rda.setName(model.getLastName() + " " + model.getFirstName());
rda.setName(model.getLastName() + " " + model.getFirstName());
rda.setMbox(model.getEmail());
}
rda.setMbox(model.getEmail());
return rda;
}
public DmpContactModel toEntity(Contact rda) {
if (rda == null) return null;
DmpContactModel entity = new DmpContactModel();
entity.setUser(this.contactRDAMapper.toEntity(rda));
return entity;
}
}

View File

@ -103,12 +103,7 @@ public class DmpRDAMapper{
if (dmp.getProperties().getContacts() != null && !dmp.getProperties().getContacts().isEmpty()){
UserModel userContact = dmp.getProperties().getContacts().stream().filter(x-> x.getUser() != null).map(DmpContactModel::getUser).findFirst().orElse(null);
if (userContact != null) {
rda.setContact(contactRDAMapper.toRDA(userContact));
} else {
rda.setContact(dmpContactModelContactRDAMapper.toRDA(dmp.getProperties().getContacts().getFirst()));
}
rda.setContact(dmpContactModelContactRDAMapper.toRDA(dmp.getProperties().getContacts().getFirst()));
}
}

View File

@ -22,7 +22,7 @@ public class HostRDAMapper {
for (Map.Entry<String, List<FieldModel>> entry: nodes.entrySet()) {
for (FieldModel node: entry.getValue()) {
String rdaProperty = node.getSchematics().stream().filter(schematic -> schematic.startsWith("rda.dataset.distribution.host")).findFirst().orElse("");
String rdaProperty = node.getSemantics().stream().filter(schematic -> schematic.startsWith("rda.dataset.distribution.host")).findFirst().orElse("");
if (rdaProperty.contains("host")) {
int firstDiff = MyStringUtils.getFirstDifference(numbering, entry.getKey());
if (firstDiff == -1 || firstDiff >= 2) {

View File

@ -21,7 +21,7 @@ public class LicenseRDAMapper {
License rda = new License();
for (FieldModel node: nodes) {
String rdaProperty = node.getSchematics().stream().filter(schematic -> schematic.startsWith("rda.dataset.distribution.license")).findFirst().orElse("");
String rdaProperty = node.getSemantics().stream().filter(schematic -> schematic.startsWith("rda.dataset.distribution.license")).findFirst().orElse("");
org.opencdmp.commonmodels.models.description.FieldModel valueField = valueFields.stream().filter(x-> x.getId().equals(node.getId())).findFirst().orElse(null);
if(valueField == null || valueField.getTextValue() == null || valueField.getTextValue().isBlank()){
continue;

View File

@ -31,7 +31,7 @@ public class MetadataRDAMapper{
List<Metadatum> rdas = new ArrayList<>();
for (Map.Entry<String, List<FieldModel>> entry : nodes.entrySet()) {
for (FieldModel node : entry.getValue()) {
String rdaProperty = node.getSchematics().stream().filter(schematic -> schematic.startsWith("rda.dataset.metadata")).findFirst().orElse("");
String rdaProperty = node.getSemantics().stream().filter(schematic -> schematic.startsWith("rda.dataset.metadata")).findFirst().orElse("");
org.opencdmp.commonmodels.models.description.FieldModel rdaValue = valueFields.stream().filter(x -> x.getId().equals(node.getId())).findFirst().orElse(null);
for (PropertyName propertyName : PropertyName.values()) {

View File

@ -19,7 +19,7 @@ public class SecurityAndPrivacyRDAMapper {
for (Map.Entry<String, List<FieldModel>> entry: nodes.entrySet()) {
for (FieldModel node : entry.getValue()) {
String rdaProperty = node.getSchematics().stream().filter(schematic -> schematic.startsWith("rda.dataset.security_and_privacy")).findFirst().orElse("");
String rdaProperty = node.getSemantics().stream().filter(schematic -> schematic.startsWith("rda.dataset.security_and_privacy")).findFirst().orElse("");
if (node.getData() == null) {
continue;
}

View File

@ -19,7 +19,7 @@ public class TechnicalResourceRDAMapper {
for (Map.Entry<String, List<FieldModel>> entry: nodes.entrySet()) {
for (FieldModel node : entry.getValue()) {
String rdaProperty = node.getSchematics().stream().filter(schematic -> schematic.startsWith("rda.dataset.technical_resource")).findFirst().orElse("");
String rdaProperty = node.getSemantics().stream().filter(schematic -> schematic.startsWith("rda.dataset.technical_resource")).findFirst().orElse("");
if (node.getData() == null) {
continue;
}

View File

@ -2,11 +2,16 @@ package org.opencdmp.filetransformer.rda.service.descriptiontemplatesearcher;
import org.opencdmp.commonmodels.models.descriptiotemplate.DescriptionTemplateModel;
import org.opencdmp.commonmodels.models.descriptiotemplate.FieldModel;
import org.opencdmp.commonmodels.models.descriptiotemplate.FieldSetModel;
import java.util.List;
import java.util.Map;
public interface TemplateFieldSearcherService {
FieldModel findFieldBySemantic(FieldSetModel fieldSetModel, String semantic);
List<FieldSetModel> searchFieldSetsBySemantics(DescriptionTemplateModel template, List<String> Semantics);
Map<String, List<FieldModel>> searchFieldsById(DescriptionTemplateModel template, String value);
Map<String, List<FieldModel>> searchFieldsBySemantics(DescriptionTemplateModel template, String value);

View File

@ -4,11 +4,77 @@ import org.opencdmp.commonmodels.models.descriptiotemplate.*;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.stream.Collectors;
@Component
public class TemplateFieldSearcherServiceImpl implements TemplateFieldSearcherService {
@Override
public FieldModel findFieldBySemantic(FieldSetModel fieldSetModel, String semantic){
if (fieldSetModel == null || fieldSetModel.getFields() == null) return null;
List<FieldModel> fieldModels = fieldSetModel.getAllField();
if (fieldModels == null) return null;
return fieldModels.stream().filter(x-> x.getSemantics() != null && x.getSemantics().contains(semantic)).findFirst().orElse(null);
}
@Override
public List<FieldSetModel> searchFieldSetsBySemantics(DescriptionTemplateModel template, List<String> Semantics){
if (template == null || template.getDefinition() == null) return new ArrayList<>();
List<FieldModel> fieldModels = template.getDefinition().getAllField();
if (fieldModels == null) return new ArrayList<>();
fieldModels = fieldModels.stream().filter(x-> x.getSemantics() != null && x.getSemantics().stream().anyMatch(Semantics::contains)).toList();
List<FieldSetModel> response = new ArrayList<>();
HashSet<String> fieldSetIds = new HashSet<>();
for (FieldModel fieldModel : fieldModels){
FieldSetModel fieldSetModel = this.findFieldSet(template, fieldModel);
if (fieldSetIds.contains(fieldSetModel.getId())) continue;
fieldSetIds.add(fieldSetModel.getId());
response.add(fieldSetModel);
}
return response;
}
private FieldSetModel findFieldSet(DescriptionTemplateModel template, FieldModel fieldModel){
if (template == null || template.getDefinition() == null || template.getDefinition().getPages() == null) return null;
for (PageModel pageModel : template.getDefinition().getPages().stream().sorted(Comparator.comparing(PageModel::getOrdinal)).toList()){
FieldSetModel fieldSet = this.findFieldSet(pageModel, fieldModel);
if (fieldSet != null) return fieldSet;
}
return null;
}
private FieldSetModel findFieldSet(PageModel pageModel, FieldModel fieldModel){
if (pageModel == null || pageModel.getSections() == null) return null;
for (SectionModel sectionModel : pageModel.getSections().stream().sorted(Comparator.comparing(SectionModel::getOrdinal)).toList()){
FieldSetModel fieldSet = this.findFieldSet(sectionModel, fieldModel);
if (fieldSet != null) return fieldSet;
}
return null;
}
private FieldSetModel findFieldSet(SectionModel sectionModel, FieldModel fieldModel){
if (sectionModel == null) return null;
if (sectionModel.getSections() != null) {
for (SectionModel innerSectionModel : sectionModel.getSections().stream().sorted(Comparator.comparing(SectionModel::getOrdinal)).toList()) {
FieldSetModel fieldSet = this.findFieldSet(innerSectionModel, fieldModel);
if (fieldSet != null) return fieldSet;
}
}
if (sectionModel.getFieldSets() != null) {
for (FieldSetModel fieldSetModel : sectionModel.getFieldSets().stream().sorted(Comparator.comparing(FieldSetModel::getOrdinal)).toList()) {
FieldSetModel fieldSet = this.findFieldSet(fieldSetModel, fieldModel);
if (fieldSet != null) return fieldSet;
}
}
return null;
}
private FieldSetModel findFieldSet(FieldSetModel fieldSetModel, FieldModel fieldModel){
if (fieldSetModel == null || fieldSetModel.getFields() == null) return null;
for (FieldModel currentFieldModel : fieldSetModel.getFields().stream().sorted(Comparator.comparing(FieldModel::getOrdinal)).toList()){
if (currentFieldModel.getId().equals(fieldModel.getId())) return fieldSetModel;
}
return null;
}
@Override
public Map<String, List<FieldModel>> searchFieldsById(DescriptionTemplateModel template, String value) {
if (template == null || template.getDefinition() == null) return new HashMap<>();
@ -27,7 +93,7 @@ public class TemplateFieldSearcherServiceImpl implements TemplateFieldSearcherSe
if (template == null || template.getDefinition() == null) return new HashMap<>();
List<FieldModel> fieldModels = template.getDefinition().getAllField();
if (fieldModels == null) return new HashMap<>();
fieldModels = fieldModels.stream().filter(x-> x.getSchematics() != null && x.getSchematics().contains(value)).toList();
fieldModels = fieldModels.stream().filter(x-> x.getSemantics() != null && x.getSemantics().contains(value)).toList();
Map<String, List<FieldModel>> response = new HashMap<>();
for (FieldModel fieldModel : fieldModels){
String key = this.buildFieldKey(template, fieldModel);

View File

@ -10,6 +10,7 @@ import org.opencdmp.commonmodels.models.description.PropertyDefinitionFieldSetIt
import org.opencdmp.commonmodels.models.description.PropertyDefinitionFieldSetModel;
import org.opencdmp.commonmodels.models.description.PropertyDefinitionModel;
import org.opencdmp.commonmodels.models.descriptiotemplate.FieldModel;
import org.opencdmp.commonmodels.models.descriptiotemplate.FieldSetModel;
import org.opencdmp.commonmodels.models.dmp.DmpBlueprintValueModel;
import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.commonmodels.models.dmpblueprint.SectionModel;
@ -56,7 +57,7 @@ public class RdaFileTransformerService implements FileTransformerClient {
private static final String SEMANTIC_ETHICAL_ISSUES = "ethicalIssues";
private static final String SEMANTIC_ETHICAL_ISSUES_DESCRIPTION = "ethicalIssuesDescription";
private static final String SEMANTIC_ETHICAL_ISSUES_REPORT = "ethicalIssuesReport";
private static final String SEMANTIC_COST_CURRENCY_CODE = "rda.dmp.cost.currencycode";
private static final String SEMANTIC_COST_CURRENCY_CODE = "rda.dmp.cost.currency_code";
private static final String SEMANTIC_COST_DESCRIPTION = "rda.dmp.cost.description";
private static final String SEMANTIC_COST_TITLE = "rda.dmp.cost.title";
private static final String SEMANTIC_COST_VALUE = "rda.dmp.cost.value";
@ -68,6 +69,37 @@ public class RdaFileTransformerService implements FileTransformerClient {
private static final String SEMANTIC_DATASET_SENSITIVE_DATA = "rda.dataset.sensitive_data";
private static final String SEMANTIC_DATASET_PRESERVATION_STATEMENT = "rda.dataset.preservation_statement";
private static final String SEMANTIC_DATASET_DATA_QUALITY_ASSURANCE = "rda.dataset.data_quality_assurance";
private static final String SEMANTIC_DATASET_TECHNICAL_RESOURCE_DESCRIPTION = "rda.dataset.technical_resource.description";
private static final String SEMANTIC_DATASET_TECHNICAL_RESOURCE_NAME = "rda.dataset.technical_resource.name";
private static final String SEMANTIC_DATASET_SECURITY_AND_PRIVACY_DESCRIPTION = "rda.dataset.security_and_privacy.description";
private static final String SEMANTIC_DATASET_SECURITY_AND_PRIVACY_TITLE = "rda.dataset.security_and_privacy.title";
private static final String SEMANTIC_DATASET_METADATA_LANGUAGE = "rda.dataset.metadata.language";
private static final String SEMANTIC_DATASET_METADATA_DESCRIPTION = "rda.dataset.metadata.description";
private static final String SEMANTIC_DATASET_METADATA_STANDARD_ID = "rda.dataset.metadata.standard_id";
private static final String SEMANTIC_DATASET_DATASET_ID = "rda.dataset.metadata.dataset_id";
private static final String SEMANTIC_DATASET_DATASET_ID_ID = "rda.dataset.metadata.dataset_id.id";
private static final String SEMANTIC_DATASET_DATASET_ID_TYPE = "rda.dataset.metadata.dataset_id.type";
private static final String SEMANTIC_DATASET_DISTRIBUTION_ACCESS_URL = "rda.dataset.distribution.access_url";
private static final String SEMANTIC_DATASET_DISTRIBUTION_AVAILABLE_UTIL = "rda.dataset.distribution.available_until";
private static final String SEMANTIC_DATASET_DISTRIBUTION_BYTE_SIZE = "rda.dataset.distribution.byte_size";
private static final String SEMANTIC_DATASET_DISTRIBUTION_DATA_ACCESS = "rda.dataset.distribution.data_access";
private static final String SEMANTIC_DATASET_DISTRIBUTION_DESCRIPTION = "rda.dataset.distribution.description";
private static final String SEMANTIC_DATASET_DISTRIBUTION_DOWNLOAD_URL = "rda.dataset.distribution.download_url";
private static final String SEMANTIC_DATASET_DISTRIBUTION_FORMAT = "rda.dataset.distribution.format";
private static final String SEMANTIC_DATASET_DISTRIBUTION_TITLE = "rda.dataset.distribution.title";
private static final String SEMANTIC_DATASET_DISTRIBUTION_LICENCE = "rda.dataset.distribution.license";
private static final String SEMANTIC_DATASET_DISTRIBUTION_HOST_AVAILABILITY = "rda.dataset.distribution.host.availability";
private static final String SEMANTIC_DATASET_DISTRIBUTION_HOST_BACKUP_FREQUENCY = "rda.dataset.distribution.host.backup_frequency";
private static final String SEMANTIC_DATASET_DISTRIBUTION_HOST_BACKUP_TYPE = "rda.dataset.distribution.host.backup_type";
private static final String SEMANTIC_DATASET_DISTRIBUTION_HOST_CERTIFIED_WITH = "rda.dataset.distribution.host.certified_with";
private static final String SEMANTIC_DATASET_DISTRIBUTION_HOST_DESCRIPTION = "rda.dataset.distribution.host.description";
private static final String SEMANTIC_DATASET_DISTRIBUTION_HOST_GEO_LOCATION = "rda.dataset.distribution.host.geo_location";
private static final String SEMANTIC_DATASET_DISTRIBUTION_HOST_PID_SYSTEM = "rda.dataset.distribution.host.pid_system";
private static final String SEMANTIC_DATASET_DISTRIBUTION_HOST_STORAGE_TYPE = "rda.dataset.distribution.host.storage_type";
private static final String SEMANTIC_DATASET_DISTRIBUTION_HOST_SUPPORT_VERSIONING = "rda.dataset.distribution.host.support_versioning";
private static final String SEMANTIC_DATASET_DISTRIBUTION_HOST_TITLE = "rda.dataset.distribution.host.title";
private static final String SEMANTIC_DATASET_DISTRIBUTION_HOST_URL = "rda.dataset.distribution.host.url";
private static final String SEMANTIC_DATASET_CONTRIBUTOR = "rda.dmp.contributor";
@Autowired
public RdaFileTransformerService(DmpRDAMapper dmpRDAMapper, DatasetRDAMapper descriptionRDAMapper, FileStorageService storageService, JsonHandlingService jsonHandlingService, RdaFileTransformerServiceConfiguration configuration, TemplateFieldSearcherService templateFieldSearcherService) {
@ -147,7 +179,13 @@ public class RdaFileTransformerService implements FileTransformerClient {
rda.setEthicalIssuesExist(buildRdaEthicalIssuesExist(dmp));
rda.setEthicalIssuesDescription(buildRdaEthicalIssuesDescription(dmp));
rda.setEthicalIssuesReport(buildRdaEthicalIssueReport(dmp));
rda.setProject(buildRdaProjects(projects, grants, funders));
if (projects.size() == 1 && grants.size() == 1 && funders.size() == 1) { //TODO: Project hierarchy not implemented should rewrite this logic
rda.setProject(buildRdaProjects(projects, grants, funders));
} else if (!projects.isEmpty()){
rda.setProject(buildRdaProjects(projects, new ArrayList<>(), new ArrayList<>()));
} else if (grants.size() == 1 && funders.size() == 1) {
rda.setProject(buildRdaProjects(grants, grants, funders));
}
Cost cost = buildRdaCost(dmp);
rda.setCost(new ArrayList<>());
if (cost != null) rda.getCost().add(cost);
@ -214,7 +252,7 @@ public class RdaFileTransformerService implements FileTransformerClient {
project.getDefinition().getFields().stream().filter(field -> this.configuration.getRdaFileTransformerServiceProperties().getProjectStartDateCode().equalsIgnoreCase(field.getCode()) && field.getValue() != null && !field.getValue().isBlank()).map(ReferenceFieldModel::getValue).findFirst().ifPresent(rda::setStart);
project.getDefinition().getFields().stream().filter(field -> this.configuration.getRdaFileTransformerServiceProperties().getProjectEndDateCode().equalsIgnoreCase(field.getCode()) && field.getValue() != null && !field.getValue().isBlank()).map(ReferenceFieldModel::getValue).findFirst().ifPresent(rda::setEnd);
}
rda.setFunding(List.of(this.buildRRdaFunding(grants.getFirst(), funders.getFirst()))); //TODO
if (!funders.isEmpty()) rda.setFunding(List.of(this.buildRRdaFunding(funders.getFirst(), grants.isEmpty() ? null : grants.getFirst())));
return rda;
}
@ -228,7 +266,7 @@ public class RdaFileTransformerService implements FileTransformerClient {
return rdaModels;
}
public Funding buildRRdaFunding(ReferenceModel grant, ReferenceModel funder) {
public Funding buildRRdaFunding(ReferenceModel funder, ReferenceModel grant) {
if (grant == null && funder == null) return null;
Funding rda = new Funding();
String referencePrefix;
@ -445,6 +483,7 @@ public class RdaFileTransformerService implements FileTransformerClient {
if (model.getLabel() == null) throw new MyApplicationException("Dataset Label is missing");
Dataset rda = new Dataset();
rda.setDatasetId(this.buildRdaDatasetId(model));
rda.setTitle(model.getLabel());
rda.setDescription(model.getDescription());
rda.setLanguage(this.buildRdaDatasetLanguage(model));
@ -454,24 +493,623 @@ public class RdaFileTransformerService implements FileTransformerClient {
rda.setPersonalData(this.buildRdaDatasetPersonalData(model));
rda.setSensitiveData(this.buildRdaDatasetSensitiveData(model));
rda.setPreservationStatement(this.buildRdaDatasetPreservationStatement(model));
rda.setTechnicalResource(this.buildRdaDatasetTechnicalResources(model));
rda.setSecurityAndPrivacy(this.buildRdaDatasetSecurityAndPrivacy(model));
rda.setMetadata(this.buildRdaDatasetMetadata(model));
rda.setDataQualityAssurance(this.buildDataQualityAssurances(model));
rda.setDistribution(this.buildRdaDistribution(model));
dmpRda.getCost().addAll(this.buildRdaCosts(model));
dmpRda.getContributor().addAll(this.buildContributor(model));
this.mergeEthicalIssues(model, dmpRda);
if (model.getDescriptionTemplate() != null) rda.setAdditionalProperty("template", model.getDescriptionTemplate().getId());
rda.setAdditionalProperty("dmpSectionIndex", model.getSectionId());
if (model.getProperties() != null) rda.setAdditionalProperty("properties", jsonHandlingService.toJsonSafe(model.getProperties()));
if (rda.getKeyword() != null){
int i = 0 ;
for (String keyword : rda.getKeyword()) {
rda.setAdditionalProperty("keyword" + (i + 1), keyword);
i++;
int i = 1;
for (String keyword : rda.getKeyword()) rda.setAdditionalProperty("keyword" + (i++), keyword);
} //TODO Old logic not moved
return rda;
}
private List<Contributor> buildContributor(DescriptionModel model){
List<Contributor> values = new ArrayList<>();
for (FieldModel field : this.templateFieldSearcherService.searchFieldsBySemanticsFlat(model.getDescriptionTemplate(), SEMANTIC_DATASET_CONTRIBUTOR)) {
List<org.opencdmp.commonmodels.models.description.FieldModel> fieldValues = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : fieldValues) {
if (fieldValue.getReferences() != null && !fieldValue.getReferences().isEmpty()) {
for (ReferenceModel referenceModel : fieldValue.getReferences()){
values.add(this.buildRdaContributor(referenceModel));
}
}
}
}
return rda;
return values;
}
private void mergeEthicalIssues(DescriptionModel model, Dmp dmpRda){
for (FieldModel field : this.templateFieldSearcherService.searchFieldsBySemanticsFlat(model.getDescriptionTemplate(), SEMANTIC_ETHICAL_ISSUES)) {
List<org.opencdmp.commonmodels.models.description.FieldModel> fieldValues = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : fieldValues) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
try {
Dmp.EthicalIssuesExist value = Dmp.EthicalIssuesExist.fromValue(fieldValue.getTextValue());
if (!Dmp.EthicalIssuesExist.UNKNOWN.equals(value)) dmpRda.setEthicalIssuesExist(value);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
}
}
for (FieldSetModel fieldSet : this.templateFieldSearcherService.searchFieldSetsBySemantics(model.getDescriptionTemplate(), List.of(SEMANTIC_ETHICAL_ISSUES, SEMANTIC_ETHICAL_ISSUES_DESCRIPTION, SEMANTIC_ETHICAL_ISSUES_REPORT))) {
FieldModel field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_ETHICAL_ISSUES);
List<org.opencdmp.commonmodels.models.description.FieldModel> valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
try {
Dmp.EthicalIssuesExist value = Dmp.EthicalIssuesExist.fromValue(fieldValue.getTextValue());
if (!Dmp.EthicalIssuesExist.UNKNOWN.equals(value)) dmpRda.setEthicalIssuesExist(value);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
}
if (dmpRda.getEthicalIssuesDescription() == null || dmpRda.getEthicalIssuesDescription().isBlank()) {
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_ETHICAL_ISSUES_DESCRIPTION);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
dmpRda.setEthicalIssuesDescription(fieldValue.getTextValue());
break;
}
}
}
if (dmpRda.getEthicalIssuesReport() == null) {
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_ETHICAL_ISSUES_REPORT);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
try {
dmpRda.setEthicalIssuesReport(URI.create(fieldValue.getTextValue()));
break;
} catch (Exception ex){
logger.error(ex.getMessage(), ex);
}
}
}
}
}
}
private List<Cost> buildRdaCosts(DescriptionModel model){
List<Cost> values = new ArrayList<>();
for (FieldSetModel fieldSet : this.templateFieldSearcherService.searchFieldSetsBySemantics(model.getDescriptionTemplate(), List.of(SEMANTIC_COST_CURRENCY_CODE, SEMANTIC_COST_VALUE, SEMANTIC_COST_DESCRIPTION, SEMANTIC_COST_TITLE))) {
boolean valueFound = false;
Cost item = new Cost();
FieldModel field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_COST_CURRENCY_CODE);
List<org.opencdmp.commonmodels.models.description.FieldModel> valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
try {
item.setCurrencyCode(Cost.CurrencyCode.fromValue(fieldValue.getTextValue()));
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_COST_DESCRIPTION);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.setDescription(fieldValue.getTextValue());
valueFound = true;
break;
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_COST_TITLE);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.setTitle(fieldValue.getTextValue());
valueFound = true;
break;
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_COST_VALUE);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
try {
item.setValue(Double.valueOf(fieldValue.getTextValue()));
valueFound = true;
break;
} catch (Exception ex){
logger.error(ex.getMessage(), ex);
}
}
}
if (valueFound) values.add(item);
}
return values;
}
private List<Distribution> buildRdaDistribution(DescriptionModel model){
List<Distribution> values = new ArrayList<>();
for (FieldSetModel fieldSet : this.templateFieldSearcherService.searchFieldSetsBySemantics(model.getDescriptionTemplate(), List.of(
SEMANTIC_DATASET_DISTRIBUTION_LICENCE, SEMANTIC_DATASET_DISTRIBUTION_TITLE, SEMANTIC_DATASET_DISTRIBUTION_FORMAT,
SEMANTIC_DATASET_DISTRIBUTION_DOWNLOAD_URL, SEMANTIC_DATASET_DISTRIBUTION_DESCRIPTION, SEMANTIC_DATASET_DISTRIBUTION_DATA_ACCESS,
SEMANTIC_DATASET_DISTRIBUTION_BYTE_SIZE, SEMANTIC_DATASET_DISTRIBUTION_AVAILABLE_UTIL, SEMANTIC_DATASET_DISTRIBUTION_ACCESS_URL))) {
boolean valueFound = false;
Distribution item = new Distribution();
FieldModel field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_TITLE);
List<org.opencdmp.commonmodels.models.description.FieldModel> valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.setTitle(fieldValue.getTextValue());
valueFound = true;
break;
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_FORMAT);
valueField = this.findValueField(field, model.getProperties());
item.setFormat(new ArrayList<>());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.getFormat().add(fieldValue.getTextValue());
valueFound = true;
}
if (fieldValue.getTextListValue() != null && !fieldValue.getTextListValue().isEmpty()) {
item.getFormat().add(fieldValue.getTextValue());
valueFound = true;
}
}
item.setFormat(item.getFormat().stream().distinct().toList());
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_DOWNLOAD_URL);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
try {
item.setDownloadUrl(URI.create(fieldValue.getTextValue()));
valueFound = true;
break;
} catch (Exception ex){
logger.error(ex.getMessage(), ex);
}
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_DESCRIPTION);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.setDescription(fieldValue.getTextValue());
valueFound = true;
break;
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_DATA_ACCESS);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
try {
item.setDataAccess(Distribution.DataAccess.fromValue(fieldValue.getTextValue()));
valueFound = true;
break;
} catch (Exception ex){
logger.error(ex.getMessage(), ex);
}
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_BYTE_SIZE);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
try {
item.setByteSize(Integer.valueOf(fieldValue.getTextValue()));
valueFound = true;
break;
} catch (Exception ex){
logger.error(ex.getMessage(), ex);
}
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_AVAILABLE_UTIL);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
try {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.setAvailableUntil(fieldValue.getTextValue());
valueFound = true;
break;
} else if (fieldValue.getDateValue() != null){
item.setAvailableUntil(DateTimeFormatter.ISO_DATE.format(fieldValue.getDateValue()));
valueFound = true;
break;
}
}
catch (Exception ex){
logger.error(ex.getMessage(), ex);
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_ACCESS_URL);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.setAccessUrl(fieldValue.getTextValue());
valueFound = true;
break;
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_LICENCE);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getReferences() != null && !fieldValue.getReferences().isEmpty()) {
item.setLicense(new ArrayList<>());
for (ReferenceModel referenceModel : fieldValue.getReferences()){
if (referenceModel.getDefinition() != null && referenceModel.getDefinition().getFields() != null) {
try {
License license = new License();
String refValue = referenceModel.getDefinition().getFields().stream().filter(f -> this.configuration.getRdaFileTransformerServiceProperties().getLicenseRefCode().equalsIgnoreCase(f.getCode()) && f.getValue() != null && !f.getValue().isBlank()).map(ReferenceFieldModel::getValue).findFirst().orElse(null);
if (refValue != null && !refValue.isBlank()) license.setLicenseRef(URI.create(refValue));
String startDateValue = referenceModel.getDefinition().getFields().stream().filter(f -> this.configuration.getRdaFileTransformerServiceProperties().getLicenseStartDateCode().equalsIgnoreCase(f.getCode()) && f.getValue() != null && !f.getValue().isBlank()).map(ReferenceFieldModel::getValue).findFirst().orElse(null);
if (refValue != null && !refValue.isBlank()) license.setStartDate(startDateValue);
item.getLicense().add(license);
} catch (Exception ex){
logger.error(ex.getMessage(), ex);
}
}
}
if (!item.getLicense().isEmpty()) valueFound = true;
}
}
if (valueFound) {
item.setHost(this.buildRdaDistributionHost(model, fieldSet));
values.add(item);
}
}
return values.isEmpty() ? null : values;
}
private Host buildRdaDistributionHost(DescriptionModel model, FieldSetModel fieldSet) {
boolean valueFound = false;
Host item = new Host();
FieldModel field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_HOST_TITLE);
List<org.opencdmp.commonmodels.models.description.FieldModel> valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.setTitle(fieldValue.getTextValue());
valueFound = true;
break;
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_HOST_URL);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
try {
item.setUrl(URI.create(fieldValue.getTextValue()));
valueFound = true;
break;
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_HOST_DESCRIPTION);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.setDescription(fieldValue.getTextValue());
valueFound = true;
break;
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_HOST_STORAGE_TYPE);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.setStorageType(fieldValue.getTextValue());
valueFound = true;
break;
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_HOST_BACKUP_TYPE);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.setBackupType(fieldValue.getTextValue());
valueFound = true;
break;
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_HOST_AVAILABILITY);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.setAvailability(fieldValue.getTextValue());
valueFound = true;
break;
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_HOST_BACKUP_FREQUENCY);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.setBackupFrequency(fieldValue.getTextValue());
valueFound = true;
break;
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_HOST_GEO_LOCATION);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
try {
item.setGeoLocation(Host.GeoLocation.fromValue(fieldValue.getTextValue()));
valueFound = true;
break;
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_HOST_SUPPORT_VERSIONING);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
try {
item.setSupportVersioning(Host.SupportVersioning.fromValue(fieldValue.getTextValue()));
valueFound = true;
break;
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_HOST_CERTIFIED_WITH);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
try {
item.setCertifiedWith(Host.CertifiedWith.fromValue(fieldValue.getTextValue()));
valueFound = true;
break;
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DISTRIBUTION_HOST_PID_SYSTEM);
valueField = this.findValueField(field, model.getProperties());
item.setPidSystem(new ArrayList<>());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
try {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
try {
item.getPidSystem().add(PidSystem.fromValue(fieldValue.getTextValue()));
valueFound = true;
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
valueFound = true;
}
if (fieldValue.getTextListValue() != null && !fieldValue.getTextListValue().isEmpty()) {
try {
item.getPidSystem().add(PidSystem.fromValue(fieldValue.getTextValue()));
valueFound = true;
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
valueFound = true;
}
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
}
if (valueFound) return item;
return null;
}
private List<String> buildDataQualityAssurances(DescriptionModel model){
List<String> values = new ArrayList<>();
for (FieldModel field : this.templateFieldSearcherService.searchFieldsBySemanticsFlat(model.getDescriptionTemplate(), SEMANTIC_DATASET_DATA_QUALITY_ASSURANCE)) {
List<org.opencdmp.commonmodels.models.description.FieldModel> fieldValues = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : fieldValues) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
values.add(fieldValue.getTextValue());
}
}
}
return values;
}
private DatasetId buildRdaDatasetId(DescriptionModel model){
DatasetId datasetId = new DatasetId();
datasetId.setType(DatasetId.Type.OTHER);
for (FieldModel field : this.templateFieldSearcherService.searchFieldsBySemanticsFlat(model.getDescriptionTemplate(), SEMANTIC_DATASET_DATASET_ID)) {
List<org.opencdmp.commonmodels.models.description.FieldModel> fieldValues = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : fieldValues) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
datasetId.setIdentifier(fieldValue.getTextValue() );
return datasetId;
}
}
}
for (FieldSetModel fieldSet : this.templateFieldSearcherService.searchFieldSetsBySemantics(model.getDescriptionTemplate(), List.of(SEMANTIC_DATASET_DATASET_ID_ID, SEMANTIC_DATASET_DATASET_ID_TYPE))) {
boolean valueFound = false;
FieldModel field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DATASET_ID_ID);
List<org.opencdmp.commonmodels.models.description.FieldModel> valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
datasetId.setIdentifier(fieldValue.getTextValue());
valueFound = true;
break;
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_DATASET_ID_TYPE);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
datasetId.setType(DatasetId.Type.fromValue(fieldValue.getTextValue()));
valueFound = true;
break;
}
}
if (valueFound) return datasetId;
}
return new DatasetId(model.getId().toString(), DatasetId.Type.OTHER);
}
private List<Metadatum> buildRdaDatasetMetadata(DescriptionModel model){
List<Metadatum> values = new ArrayList<>();
for (FieldSetModel fieldSet : this.templateFieldSearcherService.searchFieldSetsBySemantics(model.getDescriptionTemplate(), List.of(SEMANTIC_DATASET_METADATA_DESCRIPTION, SEMANTIC_DATASET_METADATA_LANGUAGE, SEMANTIC_DATASET_METADATA_STANDARD_ID))) {
boolean valueFound = false;
Metadatum item = new Metadatum();
FieldModel field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_METADATA_LANGUAGE);
List<org.opencdmp.commonmodels.models.description.FieldModel> valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
try {
item.setLanguage(Metadatum.Language.fromValue(fieldValue.getTextValue()));
valueFound = true;
break;
} catch (Exception e){
logger.error(e.getMessage(), e);
}
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_METADATA_DESCRIPTION);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.setDescription(fieldValue.getTextValue());
valueFound = true;
break;
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_METADATA_STANDARD_ID);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
MetadataStandardId standardId = new MetadataStandardId();
standardId.setIdentifier(fieldValue.getTextValue());
standardId.setType(MetadataStandardId.Type.URL);
item.setMetadataStandardId(standardId);
valueFound = true;
break;
}
}
if (valueFound) values.add(item);
}
return values.isEmpty() ? null : values;
}
private List<SecurityAndPrivacy> buildRdaDatasetSecurityAndPrivacy(DescriptionModel model){
List<SecurityAndPrivacy> values = new ArrayList<>();
for (FieldSetModel fieldSet : this.templateFieldSearcherService.searchFieldSetsBySemantics(model.getDescriptionTemplate(), List.of(SEMANTIC_DATASET_SECURITY_AND_PRIVACY_TITLE, SEMANTIC_DATASET_SECURITY_AND_PRIVACY_DESCRIPTION))) {
boolean valueFound = false;
SecurityAndPrivacy item = new SecurityAndPrivacy();
FieldModel field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_SECURITY_AND_PRIVACY_TITLE);
List<org.opencdmp.commonmodels.models.description.FieldModel> valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.setTitle(fieldValue.getTextValue());
valueFound = true;
break;
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_SECURITY_AND_PRIVACY_DESCRIPTION);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.setDescription(fieldValue.getTextValue());
valueFound = true;
break;
}
}
if (valueFound) values.add(item);
}
return values.isEmpty() ? null : values;
}
private List<TechnicalResource> buildRdaDatasetTechnicalResources(DescriptionModel model){
List<TechnicalResource> values = new ArrayList<>();
for (FieldSetModel fieldSet : this.templateFieldSearcherService.searchFieldSetsBySemantics(model.getDescriptionTemplate(), List.of(SEMANTIC_DATASET_TECHNICAL_RESOURCE_NAME, SEMANTIC_DATASET_TECHNICAL_RESOURCE_DESCRIPTION))) {
boolean valueFound = false;
TechnicalResource item = new TechnicalResource();
FieldModel field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_TECHNICAL_RESOURCE_NAME);
List<org.opencdmp.commonmodels.models.description.FieldModel> valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.setName(fieldValue.getTextValue());
valueFound = true;
break;
}
}
field = this.templateFieldSearcherService.findFieldBySemantic(fieldSet, SEMANTIC_DATASET_TECHNICAL_RESOURCE_DESCRIPTION);
valueField = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : valueField) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
item.setDescription(fieldValue.getTextValue());
valueFound = true;
break;
}
}
if (valueFound) values.add(item);
}
return values;
}
private String buildRdaDatasetPreservationStatement(DescriptionModel model){
for (FieldModel field : this.templateFieldSearcherService.searchFieldsBySemanticsFlat(model.getDescriptionTemplate(), SEMANTIC_DATASET_PRESERVATION_STATEMENT)) {
List<org.opencdmp.commonmodels.models.description.FieldModel> fieldValues = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : fieldValues) {
if (fieldValue.getTextValue() != null && fieldValue.getTextValue().isBlank()) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
return fieldValue.getTextValue();
}
}
@ -484,7 +1122,7 @@ public class RdaFileTransformerService implements FileTransformerClient {
for (FieldModel field : this.templateFieldSearcherService.searchFieldsBySemanticsFlat(model.getDescriptionTemplate(), SEMANTIC_DATASET_SENSITIVE_DATA)) {
List<org.opencdmp.commonmodels.models.description.FieldModel> fieldValues = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : fieldValues) {
if (fieldValue.getTextValue() != null && fieldValue.getTextValue().isBlank()) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
try {
value = Dataset.PersonalData.fromValue(fieldValue.getTextValue());
} catch (IllegalArgumentException | MyApplicationException e) {
@ -503,7 +1141,7 @@ public class RdaFileTransformerService implements FileTransformerClient {
for (FieldModel field : this.templateFieldSearcherService.searchFieldsBySemanticsFlat(model.getDescriptionTemplate(), SEMANTIC_DATASET_PERSONAL_DATA)) {
List<org.opencdmp.commonmodels.models.description.FieldModel> fieldValues = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : fieldValues) {
if (fieldValue.getTextValue() != null && fieldValue.getTextValue().isBlank()) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
try {
value = Dataset.PersonalData.fromValue(fieldValue.getTextValue());
} catch (IllegalArgumentException | MyApplicationException e) {
@ -522,7 +1160,7 @@ public class RdaFileTransformerService implements FileTransformerClient {
for (FieldModel field : this.templateFieldSearcherService.searchFieldsBySemanticsFlat(model.getDescriptionTemplate(), SEMANTIC_DATASET_KEYWORD)) {
List<org.opencdmp.commonmodels.models.description.FieldModel> fieldValues = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : fieldValues) {
if (fieldValue.getTextValue() != null && fieldValue.getTextValue().isBlank()) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
values.add(fieldValue.getTextValue());
}
}
@ -534,7 +1172,7 @@ public class RdaFileTransformerService implements FileTransformerClient {
for (FieldModel field : this.templateFieldSearcherService.searchFieldsBySemanticsFlat(model.getDescriptionTemplate(), SEMANTIC_DATASET_ISSUED)) {
List<org.opencdmp.commonmodels.models.description.FieldModel> fieldValues = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : fieldValues) {
if (fieldValue.getTextValue() != null && fieldValue.getTextValue().isBlank()) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
return fieldValue.getTextValue();
} else if (fieldValue.getDateValue() != null){
return DateTimeFormatter.ISO_DATE.format(fieldValue.getDateValue());
@ -549,7 +1187,7 @@ public class RdaFileTransformerService implements FileTransformerClient {
for (FieldModel field : this.templateFieldSearcherService.searchFieldsBySemanticsFlat(model.getDescriptionTemplate(), SEMANTIC_DATASET_LANGUAGE)) {
List<org.opencdmp.commonmodels.models.description.FieldModel> fieldValues = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : fieldValues) {
if (fieldValue.getTextValue() != null && fieldValue.getTextValue().isBlank()) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
try {
value = Language.fromValue(fieldValue.getTextValue());
} catch (IllegalArgumentException | MyApplicationException e) {
@ -569,7 +1207,7 @@ public class RdaFileTransformerService implements FileTransformerClient {
for (FieldModel field : this.templateFieldSearcherService.searchFieldsBySemanticsFlat(model.getDescriptionTemplate(), SEMANTIC_DATASET_TYPE)) {
List<org.opencdmp.commonmodels.models.description.FieldModel> fieldValues = this.findValueField(field, model.getProperties());
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : fieldValues) {
if (fieldValue.getTextValue() != null && fieldValue.getTextValue().isBlank()) {
if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
return fieldValue.getTextValue();
}
}

View File

@ -19,6 +19,8 @@ public class RdaFileTransformerServiceProperties {
private String researcherMalCode;
private String projectStartDateCode;
private String projectEndDateCode;
private String licenseRefCode;
private String licenseStartDateCode;
private Map<String, String> languageMap;
@ -134,4 +136,20 @@ public class RdaFileTransformerServiceProperties {
public void setLanguageMap(Map<String, String> languageMap) {
this.languageMap = languageMap;
}
public String getLicenseRefCode() {
return licenseRefCode;
}
public void setLicenseRefCode(String licenseRefCode) {
this.licenseRefCode = licenseRefCode;
}
public String getLicenseStartDateCode() {
return licenseStartDateCode;
}
public void setLicenseStartDateCode(String licenseStartDateCode) {
this.licenseStartDateCode = licenseStartDateCode;
}
}

View File

@ -32,7 +32,7 @@
<dependency>
<groupId>org.opencdmp</groupId>
<artifactId>file-transformer-base</artifactId>
<version>0.0.21</version>
<version>0.0.22</version>
</dependency>
<dependency>
<groupId>gr.cite</groupId>

View File

@ -11,6 +11,8 @@ rda-file-transformer:
researcherMalCode: "primaryEmail"
projectStartDateCode: "startDate"
projectEndDateCode: "endDate"
licenseRefCode: "license_ref"
licenseStartDateCode: "start_date"
language-map:
aa: aar
ab: abk