From 7bcf66900d5a6ac4efaaab9ff966269cc9cfbe9c Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Thu, 25 Apr 2024 13:13:44 +0300 Subject: [PATCH] migration changes --- ...escriptionTemplateXmlMigrationService.java | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 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 380e460ee..34798f34d 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 @@ -29,6 +29,7 @@ import gr.cite.tools.logging.LoggerService; import jakarta.persistence.EntityManager; import jakarta.ws.rs.NotSupportedException; import jakarta.xml.bind.JAXBException; +import org.apache.commons.lang3.StringUtils; import org.elasticsearch.common.inject.Guice; import org.jetbrains.annotations.NotNull; import org.slf4j.LoggerFactory; @@ -539,18 +540,20 @@ public class DescriptionTemplateXmlMigrationService { if (definitionEntity == null || this.conventionService.isListNullOrEmpty(definitionEntity.getSources()) || definitionEntity.getSources().size() != 1) return null; ExternalFetcherApiSourceConfigurationEntity externalFetcherApiSourceConfigurationEntity = (ExternalFetcherApiSourceConfigurationEntity)definitionEntity.getSources().getFirst(); if (externalFetcherApiSourceConfigurationEntity == null || this.conventionService.isNullOrEmpty(externalFetcherApiSourceConfigurationEntity.getUrl())) return null; - - if (externalFetcherApiSourceConfigurationEntity.getUrl().trim().toLowerCase(Locale.ROOT).equals("https://eestore.paas2.uninett.no/api/license/".trim().toLowerCase(Locale.ROOT))) return knownReferenceEntities.get(ReferenceTypeIds.License); - else if (externalFetcherApiSourceConfigurationEntity.getUrl().trim().toLowerCase(Locale.ROOT).equals("https://zenodo.org/api/licenses".trim().toLowerCase(Locale.ROOT))) return knownReferenceEntities.get(ReferenceTypeIds.License); - else if (externalFetcherApiSourceConfigurationEntity.getUrl().trim().toLowerCase(Locale.ROOT).equals("https://zenodo.org/api/licenses?q={like}".trim().toLowerCase(Locale.ROOT))) return knownReferenceEntities.get(ReferenceTypeIds.License); - else if (externalFetcherApiSourceConfigurationEntity.getUrl().trim().toLowerCase(Locale.ROOT).equals("http://api.openaire.eu/search/publications".trim().toLowerCase(Locale.ROOT))) return knownReferenceEntities.get(ReferenceTypeIds.Publication); - else if (externalFetcherApiSourceConfigurationEntity.getUrl().trim().toLowerCase(Locale.ROOT).equals("http://api.openaire.eu/search/publications?format=json&title={like}".trim().toLowerCase(Locale.ROOT))) return knownReferenceEntities.get(ReferenceTypeIds.Publication); - else if (externalFetcherApiSourceConfigurationEntity.getUrl().trim().toLowerCase(Locale.ROOT).equals("https://services.openaire.eu/openaire/ds/searchdetails/{page}/{pageSize}?requestSortBy=id&order=ASCENDING".trim().toLowerCase(Locale.ROOT))) return knownReferenceEntities.get(ReferenceTypeIds.Publication); - else if (externalFetcherApiSourceConfigurationEntity.getUrl().trim().toLowerCase(Locale.ROOT).equals("https://eestore.paas2.uninett.no/api/datarepo/".trim().toLowerCase(Locale.ROOT))) return knownReferenceEntities.get(ReferenceTypeIds.DataRepositories); - else if (externalFetcherApiSourceConfigurationEntity.getUrl().trim().toLowerCase(Locale.ROOT).equals("https://services.openaire.eu/search/v2/api/datasources?q={like}&fq=datasourcetypeuiname".trim().toLowerCase(Locale.ROOT))) return knownReferenceEntities.get(ReferenceTypeIds.DataRepositories); - else if (externalFetcherApiSourceConfigurationEntity.getUrl().trim().toLowerCase(Locale.ROOT).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))) return knownReferenceEntities.get(ReferenceTypeIds.Journal); - else if (externalFetcherApiSourceConfigurationEntity.getUrl().trim().toLowerCase(Locale.ROOT).equals("https://eestore.paas2.uninett.no/api/metadataschema/".trim().toLowerCase(Locale.ROOT))) return knownReferenceEntities.get(ReferenceTypeIds.Registries); - else if (externalFetcherApiSourceConfigurationEntity.getUrl().trim().toLowerCase(Locale.ROOT).equals("https://eestore.paas2.uninett.no/api/taxonomy/".trim().toLowerCase(Locale.ROOT))) return knownReferenceEntities.get(ReferenceTypeIds.Taxonomy); + + 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); + else if (url.equals("https://zenodo.org/api/licenses?q={like}".trim().toLowerCase(Locale.ROOT).replace(" ", ""))) return knownReferenceEntities.get(ReferenceTypeIds.License); + else if (url.equals("http://api.openaire.eu/search/publications".trim().toLowerCase(Locale.ROOT).replace(" ", ""))) return knownReferenceEntities.get(ReferenceTypeIds.Publication); + else if (url.equals("http://api.openaire.eu/search/publications?format=json&title={like}".trim().toLowerCase(Locale.ROOT).replace(" ", ""))) return knownReferenceEntities.get(ReferenceTypeIds.Publication); + else if (url.equals("https://services.openaire.eu/openaire/ds/searchdetails/{page}/{pageSize}?requestSortBy=id&order=ASCENDING".trim().toLowerCase(Locale.ROOT).replace(" ", ""))) return knownReferenceEntities.get(ReferenceTypeIds.Publication); + else if (url.equals("https://eestore.paas2.uninett.no/api/datarepo".trim().toLowerCase(Locale.ROOT).replace(" ", ""))) return knownReferenceEntities.get(ReferenceTypeIds.DataRepositories); + else if (url.equals("https://services.openaire.eu/search/v2/api/datasources?q={like}&fq=datasourcetypeuiname exact \"Data Repository\"&format=json".trim().toLowerCase(Locale.ROOT).replace(" ", ""))) return knownReferenceEntities.get(ReferenceTypeIds.DataRepositories); + else if (url.equals("https://services.openaire.eu/search/v2/api/datasources?q={like}&fq=datasourcetypeuiname".trim().toLowerCase(Locale.ROOT).replace(" ", ""))) return knownReferenceEntities.get(ReferenceTypeIds.DataRepositories); + 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; } @@ -560,16 +563,16 @@ public class DescriptionTemplateXmlMigrationService { if (definitionEntity.getSources() != null){ for (ExternalFetcherApiSourceConfigurationEntity source : definitionEntity.getSources().stream().map(x-> (ExternalFetcherApiSourceConfigurationEntity)x).toList()){ StringBuilder sourceStringBuilder = new StringBuilder(); - sourceStringBuilder.append(source.getUrl()); - sourceStringBuilder.append(source.getHttpMethod().getValue().toString()); - sourceStringBuilder.append(source.getKey()); - if (source.getResults() != null){ - sourceStringBuilder.append(source.getResults().getResultsArrayPath()); - if (source.getResults().getFieldsMapping() != null) { - sourceStringBuilder.append(source.getResults().getFieldsMapping().stream().filter(x-> x.getCode().equals(ReferenceEntity.KnownFields.ReferenceId)).map(ResultFieldsMappingConfigurationEntity::getResponsePath).findFirst().orElse("")); - sourceStringBuilder.append(source.getResults().getFieldsMapping().stream().filter(x-> x.getCode().equals(ReferenceEntity.KnownFields.Label)).map(ResultFieldsMappingConfigurationEntity::getResponsePath).findFirst().orElse("")); - } - } + sourceStringBuilder.append(StringUtils.stripEnd(source.getUrl().trim().toLowerCase(Locale.ROOT), "/")); + sourceStringBuilder.append(source.getHttpMethod().getValue().toString().trim().toLowerCase(Locale.ROOT)); +// sourceStringBuilder.append(source.getKey()); +// if (source.getResults() != null){ +// sourceStringBuilder.append(source.getResults().getResultsArrayPath()); +// if (source.getResults().getFieldsMapping() != null) { +// sourceStringBuilder.append(source.getResults().getFieldsMapping().stream().filter(x-> x.getCode().equals(ReferenceEntity.KnownFields.ReferenceId)).map(ResultFieldsMappingConfigurationEntity::getResponsePath).findFirst().orElse("")); +// sourceStringBuilder.append(source.getResults().getFieldsMapping().stream().filter(x-> x.getCode().equals(ReferenceEntity.KnownFields.Label)).map(ResultFieldsMappingConfigurationEntity::getResponsePath).findFirst().orElse("")); +// } +// } sourceKeys.add(sourceStringBuilder.toString().toLowerCase(Locale.ROOT)); } }