migration currency changes

This commit is contained in:
Efstratios Giannopoulos 2024-04-09 18:14:16 +03:00
parent c27ba6ee6a
commit a84332001e
4 changed files with 26 additions and 25 deletions

View File

@ -408,25 +408,6 @@ public class DatasetMigrationService {
fieldEntity.setTextValue(UUID.fromString(id).toString());
}
}
case CURRENCY -> {
if(!this.conventionService.isNullOrEmpty(textValue)) {
Currency currency = migrationTools.tryParseJsonAsObjectString(Currency.class, textValue);
if (currency == null && textValue.toUpperCase(Locale.ROOT).contains("EUR")) {
currency = new Currency();
currency.setName("Euro");
currency.setValue("EUR");
}
if (currency == null && textValue.toUpperCase(Locale.ROOT).contains("US DOLLAR")) {
currency = new Currency();
currency.setName("US DOLLAR");
currency.setValue("USD");
}
if (currency == null) throw new MyApplicationException("Could not parse Currency : " + textValue);
//TODO: {"name":"Euro","value":"EUR"} what we want to keep ?
fieldEntity.setTextValue(currency.getName());
}
}
case TAGS -> {
if(!this.conventionService.isNullOrEmpty(textValue)) {
Tag[] tags = migrationTools.tryParseJsonAsObjectString(Tag[].class, textValue);
@ -444,11 +425,32 @@ public class DatasetMigrationService {
case INTERNAL_ENTRIES_DESCRIPTIONS -> throw new MyApplicationException("Found INTERNAL_ENTRIES_DMPS into description");
case REFERENCE_TYPES -> {
if(!this.conventionService.isNullOrEmpty(textValue)) { //TODO
Map<String, Object>[] references = migrationTools.tryParseJsonAsObjectString(Map[].class, textValue);
ReferenceTypeDataEntity referenceTypeDataEntity = (ReferenceTypeDataEntity)currentField.getData();
if (referenceTypeDataEntity == null) throw new MyApplicationException("Could not parse description template reference : " + textValue);
Map<String, Object>[] references = migrationTools.tryParseJsonAsObjectString(Map[].class, textValue);
if (referenceTypeDataEntity.getReferenceTypeId().equals(ReferenceTypeIds.Currency)){
Currency currency = migrationTools.tryParseJsonAsObjectString(Currency.class, textValue);
if (currency == null && textValue.toUpperCase(Locale.ROOT).contains("EUR")) {
currency = new Currency();
currency.setName("Euro");
currency.setValue("EUR");
}
if (currency == null && textValue.toUpperCase(Locale.ROOT).contains("US DOLLAR")) {
currency = new Currency();
currency.setName("US DOLLAR");
currency.setValue("USD");
}
if (currency == null) throw new MyApplicationException("Could not parse Currency : " + textValue);
//TODO: {"name":"Euro","value":"EUR"} what we want to keep ?
Map<String, Object> reference = new HashMap<>();
reference.put(ReferenceEntity.KnownFields.ReferenceId, currency.getValue());
reference.put(ReferenceEntity.KnownFields.Label, currency.getName());
references = List.of(reference).toArray(Map[]::new);
}
if (references == null) {
Map<String, Object> reference = migrationTools.tryParseJsonAsObjectString(Map.class, textValue);
if (reference != null) references = List.of(reference).toArray(Map[]::new);

View File

@ -109,7 +109,6 @@ public class DescriptionTemplateXmlCleanInvalidReferenceTypesService {
data.setNumbering(persist.getNumbering());
data.setOrdinal(persist.getOrdinal());
data.setDefaultVisibility(persist.isDefaultVisibility());
data.setMultiplicity(persist.getMultiplicity());
data.setTitle(persist.getTitle());
if (!this.conventionService.isListNullOrEmpty(persist.getSections())) {

View File

@ -140,7 +140,6 @@ public class DescriptionTemplateXmlMigrationService {
data.setNumbering(persist.getNumbering());
data.setOrdinal(persist.getOrdinal());
data.setDefaultVisibility(persist.isDefaultVisibility());
data.setMultiplicity(persist.getMultiplicity());
data.setTitle(persist.getTitle());
if (!this.conventionService.isListNullOrEmpty(persist.getSections())) {
@ -263,7 +262,7 @@ public class DescriptionTemplateXmlMigrationService {
return this.buildLabelDataEntity(persist.getLabel(), FieldType.DATASET_IDENTIFIER);
}
if (renderStyle.equals("currency")){
return this.buildLabelDataEntity(persist.getLabel(), FieldType.CURRENCY);
return this.buildReferenceTypeDataEntity(persist.getLabel(), false, ReferenceTypeIds.Currency);
}
if (renderStyle.equals("taxonomies")){
return this.buildReferenceTypeDataEntity(persist.getLabel(), ((TaxonomiesData)persist).getMultiAutoComplete(), ReferenceTypeIds.Taxonomy);

View File

@ -18,8 +18,9 @@ public class ReferenceTypeIds {
public static UUID Publication = UUID.fromString("51225b6a-86a6-48ac-9192-f15096dbcb8a");
public static UUID Journal = UUID.fromString("8ec7556b-749d-4c4a-a4b9-43d064693795");
public static UUID PubRepositories = UUID.fromString("1e927daa-b856-443f-96da-22f325f7322f");
public static UUID Currency = UUID.fromString("f39dbc8c-1e31-48cd-a0b1-0bf2921d87c4");
public static List<UUID> KnownReferenceTypeIds = List.of(DataRepositories, Datasets, Funder, Grants, Organizations,
Project, Registries, Researcher, Services, License, Taxonomy, Publication, Journal, PubRepositories);
Project, Registries, Researcher, Services, License, Taxonomy, Publication, Journal, PubRepositories, Currency);
}