From 1a26327fd3332951fa3ef242b71de503b02194e1 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Thu, 30 May 2024 17:56:38 +0300 Subject: [PATCH] migration changes --- ...escriptionTemplateXmlMigrationService.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlMigrationService.java index 4f9c5b20f..1568873aa 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlMigrationService.java @@ -194,6 +194,8 @@ public class DescriptionTemplateXmlMigrationService { data.setId(persist.getId().trim()); data.setOrdinal(persist.getOrdinal()); data.setSemantics(persist.getSchematics()); +// if (persist.getSchematics() != null && persist.getSchematics().stream().anyMatch("rda.dmp.cost"::equalsIgnoreCase)) throw new MyApplicationException("rda.dmp.cost not implemented"); +// if (persist.getSchematics() != null && persist.getSchematics().stream().anyMatch("rda.dataset.data_quality_assurance"::equalsIgnoreCase)) throw new MyApplicationException("rda.dataset.data_quality_assurance not implemented"); if (persist.getValidations() != null) data.setValidations(persist.getValidations().stream().map(x-> { switch (x){ case NONE -> { @@ -584,10 +586,20 @@ public class DescriptionTemplateXmlMigrationService { } private ReferenceTypeEntity getReferenceTypeEntityByUrl(ReferenceTypeDefinitionEntity definitionEntity, Map knownReferenceEntities){ - if (definitionEntity == null || this.conventionService.isListNullOrEmpty(definitionEntity.getSources()) || definitionEntity.getSources().size() != 1) return null; - ExternalFetcherApiSourceConfigurationEntity externalFetcherApiSourceConfigurationEntity = (ExternalFetcherApiSourceConfigurationEntity)definitionEntity.getSources().getFirst(); + if (definitionEntity == null || this.conventionService.isListNullOrEmpty(definitionEntity.getSources()) || definitionEntity.getSources().isEmpty()) return null; + List referenceTypeEntities = new ArrayList<>(); + for (ExternalFetcherBaseSourceConfigurationEntity externalFetcherApiSourceConfigurationEntity : definitionEntity.getSources()){ + ReferenceTypeEntity referenceTypeEntity = getReferenceTypeEntityForSourceByUrl((ExternalFetcherApiSourceConfigurationEntity)externalFetcherApiSourceConfigurationEntity, knownReferenceEntities); + if (referenceTypeEntity == null) return null; + if (referenceTypeEntities.stream().noneMatch(x-> x.getId().equals(referenceTypeEntity.getId()))) referenceTypeEntities.add(referenceTypeEntity); + } + if (referenceTypeEntities.size() == 1) return referenceTypeEntities.getFirst(); + return null; + } + + private ReferenceTypeEntity getReferenceTypeEntityForSourceByUrl(ExternalFetcherApiSourceConfigurationEntity externalFetcherApiSourceConfigurationEntity, Map knownReferenceEntities){ if (externalFetcherApiSourceConfigurationEntity == null || this.conventionService.isNullOrEmpty(externalFetcherApiSourceConfigurationEntity.getUrl())) return null; - + String url = StringUtils.stripEnd(externalFetcherApiSourceConfigurationEntity.getUrl().trim().toLowerCase(Locale.ROOT).replace(" ", ""), "/"); if (url.equals("https://eestore.paas2.uninett.no/api/license".trim().toLowerCase(Locale.ROOT).replace(" ", ""))) return knownReferenceEntities.get(ReferenceTypeIds.License); else if (url.equals("https://zenodo.org/api/licenses".trim().toLowerCase(Locale.ROOT).replace(" ", ""))) return knownReferenceEntities.get(ReferenceTypeIds.License); @@ -601,7 +613,7 @@ public class DescriptionTemplateXmlMigrationService { else if (url.equals("https://services.openaire.eu/search/v2/api/resources?query=oaftype exact datasource and {like} and ( datasourcetypeuiid = \"pubsrepository::journal\" or datasourcetypeuiid = \"aggregator::pubsrepository::journals\")&page=0&size=60&format=json".trim().toLowerCase(Locale.ROOT).replace(" ", ""))) return knownReferenceEntities.get(ReferenceTypeIds.Journal); else if (url.equals("https://eestore.paas2.uninett.no/api/metadataschema".trim().toLowerCase(Locale.ROOT).replace(" ", ""))) return knownReferenceEntities.get(ReferenceTypeIds.Registries); else if (url.equals("https://eestore.paas2.uninett.no/api/taxonomy".trim().toLowerCase(Locale.ROOT).replace(" ", ""))) return knownReferenceEntities.get(ReferenceTypeIds.Taxonomy); - + return null; }