diff --git a/core/src/main/java/org/opencdmp/filetransformer/rda/service/rdafiletransformer/RdaFileTransformerService.java b/core/src/main/java/org/opencdmp/filetransformer/rda/service/rdafiletransformer/RdaFileTransformerService.java index 3e4e8cb..eb622b4 100644 --- a/core/src/main/java/org/opencdmp/filetransformer/rda/service/rdafiletransformer/RdaFileTransformerService.java +++ b/core/src/main/java/org/opencdmp/filetransformer/rda/service/rdafiletransformer/RdaFileTransformerService.java @@ -35,7 +35,6 @@ import org.springframework.stereotype.Service; import java.net.URI; import java.nio.charset.StandardCharsets; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.*; @@ -193,13 +192,13 @@ public class RdaFileTransformerService implements FileTransformerClient { rda.setCost(new ArrayList<>()); if (cost != null) rda.getCost().add(cost); - if (dmp.getDescriptions() != null) rda.setAdditionalProperty("templates", jsonHandlingService.toJsonSafe(dmp.getDescriptions().stream().filter(x-> x.getDescriptionTemplate() != null && x.getDescriptionTemplate().getId() != null).map(descriptionModel -> descriptionModel.getDescriptionTemplate().getId()).toList())); - if (dmp.getDmpBlueprint() != null) rda.setAdditionalProperty("blueprintId", dmp.getDmpBlueprint().getId().toString()); - if (!licences.isEmpty()) rda.setAdditionalProperty("license", jsonHandlingService.toJsonSafe(licences)); - if (dmp.getAccessType() != null) rda.setAdditionalProperty("visible", dmp.getAccessType()); - if (dmp.getPublicAfter() != null) rda.setAdditionalProperty("publicDate", jsonHandlingService.toJsonSafe(dmp.getPublicAfter())); - if (dmp.getProperties() != null && dmp.getProperties().getContacts() != null) rda.setAdditionalProperty("contact", jsonHandlingService.toJsonSafe(dmp.getProperties().getContacts())); - if (dmp.getProperties() != null && dmp.getProperties().getDmpBlueprintValues() != null) rda.setAdditionalProperty("dmpProperties", jsonHandlingService.toJsonSafe(dmp.getProperties().getDmpBlueprintValues())); +// if (dmp.getDescriptions() != null) rda.setAdditionalProperty("templates", jsonHandlingService.toJsonSafe(dmp.getDescriptions().stream().filter(x-> x.getDescriptionTemplate() != null && x.getDescriptionTemplate().getId() != null).map(descriptionModel -> descriptionModel.getDescriptionTemplate().getId()).toList())); +// if (dmp.getDmpBlueprint() != null) rda.setAdditionalProperty("blueprintId", dmp.getDmpBlueprint().getId().toString()); +// if (!licences.isEmpty()) rda.setAdditionalProperty("license", jsonHandlingService.toJsonSafe(licences)); +// if (dmp.getAccessType() != null) rda.setAdditionalProperty("visible", dmp.getAccessType()); +// if (dmp.getPublicAfter() != null) rda.setAdditionalProperty("publicDate", jsonHandlingService.toJsonSafe(dmp.getPublicAfter())); +// if (dmp.getProperties() != null && dmp.getProperties().getContacts() != null) rda.setAdditionalProperty("contact", jsonHandlingService.toJsonSafe(dmp.getProperties().getContacts())); +// if (dmp.getProperties() != null && dmp.getProperties().getDmpBlueprintValues() != null) rda.setAdditionalProperty("dmpProperties", jsonHandlingService.toJsonSafe(dmp.getProperties().getDmpBlueprintValues())); if (dmp.getDescriptions() != null){ rda.setDataset(new ArrayList<>()); @@ -273,15 +272,9 @@ public class RdaFileTransformerService implements FileTransformerClient { public Funding buildRRdaFunding(ReferenceModel funder, ReferenceModel grant) { if (grant == null && funder == null) return null; Funding rda = new Funding(); - String referencePrefix; - String shortReference; - int prefixLength; if (funder != null && funder.getReference() != null) { - referencePrefix =funder.getReference().split(":")[0]; - prefixLength = referencePrefix.length() == funder.getReference().length() ? referencePrefix.length() - 1 : referencePrefix.length(); - shortReference = funder.getReference().substring(prefixLength + 1); FunderId funderId = new FunderId(); - funderId.setIdentifier(shortReference); + funderId.setIdentifier(funder.getReference()); funderId.setType(FunderId.Type.FUNDREF); rda.setFunderId(funderId); } else if (funder != null){ @@ -291,12 +284,8 @@ public class RdaFileTransformerService implements FileTransformerClient { rda.setFunderId(funderId); } if (grant != null && grant.getReference() != null) { - referencePrefix = grant.getReference().split(":")[0]; - prefixLength = referencePrefix.length() == grant.getReference().length() ? referencePrefix.length() - 1 : referencePrefix.length(); - shortReference = grant.getReference().substring(prefixLength + 1); - GrantId grantId = new GrantId(); - grantId.setIdentifier(shortReference); + grantId.setIdentifier(grant.getReference()); grantId.setType(GrantId.Type.OTHER); rda.setGrantId(grantId); } else if (grant != null) { @@ -507,13 +496,13 @@ public class RdaFileTransformerService implements FileTransformerClient { 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 = 1; - for (String keyword : rda.getKeyword()) rda.setAdditionalProperty("keyword" + (i++), keyword); - } //TODO Old logic not moved +// 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 = 1; +// for (String keyword : rda.getKeyword()) rda.setAdditionalProperty("keyword" + (i++), keyword); +// } //TODO Old logic not moved return rda; } @@ -558,6 +547,16 @@ public class RdaFileTransformerService implements FileTransformerClient { if (!Dmp.EthicalIssuesExist.UNKNOWN.equals(value)) dmpRda.setEthicalIssuesExist(value); } catch (Exception e) { logger.error(e.getMessage(), e); } } + if (fieldValue != null && fieldValue.getTextListValue() != null && !fieldValue.getTextListValue().isEmpty()) { + for (String val : fieldValue.getTextListValue()) { + try { + Dmp.EthicalIssuesExist value = Dmp.EthicalIssuesExist.fromValue(val); + if (!Dmp.EthicalIssuesExist.UNKNOWN.equals(value)) dmpRda.setEthicalIssuesExist(value); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + } + } if (dmpRda.getEthicalIssuesDescription() == null || dmpRda.getEthicalIssuesDescription().isBlank()) { fieldValue = this.findValueFieldBySemantic(fieldSet, propertyDefinitionFieldSetItemModel, SEMANTIC_ETHICAL_ISSUES_DESCRIPTION); @@ -644,8 +643,13 @@ public class RdaFileTransformerService implements FileTransformerClient { } fieldValue = this.findValueFieldBySemantic(fieldSet, propertyDefinitionFieldSetItemModel, SEMANTIC_DATASET_DISTRIBUTION_FORMAT); - if (fieldValue != null && fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) { //TODO: multiple - item.setFormat(List.of(fieldValue.getTextValue())); + item.setFormat(new ArrayList<>()); + if (fieldValue != null && fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) { + item.getFormat().add(fieldValue.getTextValue()); + valueFound = true; + } + if (fieldValue != null && fieldValue.getTextListValue() != null && !fieldValue.getTextListValue().isEmpty()) { + item.getFormat().addAll(fieldValue.getTextListValue()); valueFound = true; } @@ -670,6 +674,17 @@ public class RdaFileTransformerService implements FileTransformerClient { valueFound = true; } catch (Exception ex) { logger.error(ex.getMessage(), ex); } } + if (fieldValue != null && fieldValue.getTextListValue() != null && !fieldValue.getTextListValue().isEmpty()) { + for (String val : fieldValue.getTextListValue()) { + try { + item.setDataAccess(Distribution.DataAccess.fromValue(val)); + valueFound = true; + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + } + + } fieldValue = this.findValueFieldBySemantic(fieldSet, propertyDefinitionFieldSetItemModel, SEMANTIC_DATASET_DISTRIBUTION_BYTE_SIZE); if (fieldValue != null && fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) { @@ -681,7 +696,8 @@ public class RdaFileTransformerService implements FileTransformerClient { fieldValue = this.findValueFieldBySemantic(fieldSet, propertyDefinitionFieldSetItemModel, SEMANTIC_DATASET_DISTRIBUTION_AVAILABLE_UTIL); if (fieldValue != null && fieldValue.getDateValue() != null) { - item.setAvailableUntil(DateTimeFormatter.ISO_DATE.withZone(ZoneId.systemDefault()).format(fieldValue.getDateValue())); +// item.setAvailableUntil(DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneId.systemDefault()).format(fieldValue.getDateValue())); + item.setAvailableUntil(fieldValue.getDateValue().toString()); valueFound = true; } else if (fieldValue != null && fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) { item.setAvailableUntil(fieldValue.getTextValue()); @@ -700,7 +716,7 @@ public class RdaFileTransformerService implements FileTransformerClient { for (ReferenceModel referenceModel : fieldValue.getReferences()) { if (referenceModel.getDefinition() != null && referenceModel.getDefinition().getFields() != null) { try { - License license = new License(); + License license = new License(); //TODO 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); @@ -778,6 +794,16 @@ public class RdaFileTransformerService implements FileTransformerClient { valueFound = true; } catch (Exception ex) { logger.error(ex.getMessage(), ex); } } + if (fieldValue != null && fieldValue.getTextListValue() != null && !fieldValue.getTextListValue().isEmpty()) { + for (String val : fieldValue.getTextListValue()) { + try { + item.setGeoLocation(Host.GeoLocation.fromValue(val)); + valueFound = true; + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + } + } fieldValue = this.findValueFieldBySemantic(fieldSet, propertyDefinitionFieldSetItemModel, SEMANTIC_DATASET_DISTRIBUTION_HOST_SUPPORT_VERSIONING); if (fieldValue != null && fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) { @@ -788,6 +814,16 @@ public class RdaFileTransformerService implements FileTransformerClient { logger.error(ex.getMessage(), ex); } } + if (fieldValue != null && fieldValue.getTextListValue() != null && !fieldValue.getTextListValue().isEmpty()) { + for (String val : fieldValue.getTextListValue()) { + try { + item.setSupportVersioning(Host.SupportVersioning.fromValue(val)); + valueFound = true; + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + } + } fieldValue = this.findValueFieldBySemantic(fieldSet, propertyDefinitionFieldSetItemModel, SEMANTIC_DATASET_DISTRIBUTION_HOST_CERTIFIED_WITH); if (fieldValue != null && fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) { @@ -798,8 +834,19 @@ public class RdaFileTransformerService implements FileTransformerClient { logger.error(ex.getMessage(), ex); } } + if (fieldValue != null && fieldValue.getTextListValue() != null && !fieldValue.getTextListValue().isEmpty()) { + for (String val : fieldValue.getTextListValue()) { + try { + item.setCertifiedWith(Host.CertifiedWith.fromValue(val)); + valueFound = true; + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + } + } fieldValue = this.findValueFieldBySemantic(fieldSet, propertyDefinitionFieldSetItemModel, SEMANTIC_DATASET_DISTRIBUTION_HOST_PID_SYSTEM); + item.setPidSystem(new ArrayList<>()); if (fieldValue != null && fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) { try { item.getPidSystem().add(PidSystem.fromValue(fieldValue.getTextValue())); @@ -1119,7 +1166,8 @@ public class RdaFileTransformerService implements FileTransformerClient { List fieldValues = this.findValueField(field, model.getProperties()); for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : fieldValues) { if (fieldValue.getDateValue() != null){ - return DateTimeFormatter.ISO_DATE.withZone(ZoneId.systemDefault()).format(fieldValue.getDateValue()); +// return DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneId.systemDefault()).format(fieldValue.getDateValue()); + return fieldValue.getDateValue().toString(); } else if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) { return fieldValue.getTextValue(); }