migration changes

This commit is contained in:
Efstratios Giannopoulos 2024-05-28 18:39:20 +03:00
parent 4043a67c9c
commit c03594f74a
4 changed files with 89 additions and 11 deletions

View File

@ -155,7 +155,7 @@ public class DescriptionTemplateXmlCleanInvalidReferenceTypesService {
data.setId(persist.getId());
data.setOrdinal(persist.getOrdinal());
data.setSchematics(persist.getSchematics());
data.setSemantics(persist.getSemantics());
data.setDefaultValue(persist.getDefaultValue());
data.setValidations(persist.getValidations());
data.setIncludeInExport(persist.getIncludeInExport());

View File

@ -193,7 +193,7 @@ public class DescriptionTemplateXmlMigrationService {
data.setId(persist.getId().trim());
data.setOrdinal(persist.getOrdinal());
data.setSchematics(persist.getSchematics());
data.setSemantics(persist.getSchematics());
if (persist.getValidations() != null) data.setValidations(persist.getValidations().stream().map(x-> {
switch (x){
case NONE -> {
@ -218,11 +218,11 @@ public class DescriptionTemplateXmlMigrationService {
type = FieldDataExternalDatasetType.of(((ExternalDatasetsData)persist.getData()).getType());
} catch (Exception e) { type = FieldDataExternalDatasetType.Other; }
if (type == null) type = FieldDataExternalDatasetType.Other;
if (data.getSchematics() == null) data.setSchematics(new ArrayList<>());
if (data.getSemantics() == null) data.setSemantics(new ArrayList<>());
switch (type){
case Other -> data.getSchematics().add("referencetype.externaldataset.type.other");
case ProducedDataset -> data.getSchematics().add("referencetype.externaldataset.type.produced");
case ReusedDataset -> data.getSchematics().add("referencetype.externaldataset.type.reused");
case Other -> data.getSemantics().add("referencetype.externaldataset.type.other");
case ProducedDataset -> data.getSemantics().add("referencetype.externaldataset.type.produced");
case ReusedDataset -> data.getSemantics().add("referencetype.externaldataset.type.reused");
default -> throw new MyApplicationException("Invalid type " + type);
}
}

View File

@ -1,6 +1,7 @@
package eu.old.eudat.migration;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.old.eudat.data.dao.entities.UserInfoDao;
import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.commonmodels.models.dmpblueprint.SectionModel;
import org.opencdmp.commons.JsonHandlingService;
@ -67,6 +68,7 @@ public class DmpMigrationService {
}
public void migrate() throws IOException, NoSuchFieldException, IllegalAccessException, JAXBException, ParserConfigurationException, InstantiationException, SAXException {
UserInfoDao userInfoDao = databaseRepository.getUserInfoDao();
DMPDao dmpDao = databaseRepository.getDmpDao();
long total = dmpDao.asQueryable().count();
logger.debug("Migrate Dmp Total : " + total);
@ -83,7 +85,8 @@ public class DmpMigrationService {
if (!groupDmpMap.containsKey(dmp.getGroupId())) groupDmpMap.put(dmp.getGroupId(), new ArrayList<>());
groupDmpMap.get(dmp.getGroupId()).add(dmp);
}
Map<UUID, UserInfo> oldUsers = userInfoDao.asQueryable().toList().stream().collect(Collectors.toMap(UserInfo::getId, x-> x));
if (items != null && !items.isEmpty()) {
logger.debug("Migrate Dmp " + page * PageSize + " of " + total);
@ -153,9 +156,23 @@ public class DmpMigrationService {
if (model.getExtraProperties().containsKey("visible") && model.getExtraProperties().get("visible") != null)
data.setAccessType((boolean) model.getExtraProperties().get("visible") ? DmpAccessType.Public : DmpAccessType.Restricted);
if (model.getExtraProperties().containsKey("contact") && model.getExtraProperties().get("contact") != null) {
DmpContactEntity contactEntity = new DmpContactEntity();
contactEntity.setUserId(UUID.fromString((String)model.getExtraProperties().get("contact")));
dmpProperties.getContacts().add(contactEntity);
UserInfo userInfo = oldUsers.getOrDefault(UUID.fromString((String)model.getExtraProperties().get("contact")), null);
if (userInfo != null) {
DmpContactEntity contactEntity = new DmpContactEntity();
contactEntity.setEmail(userInfo.getEmail());
contactEntity.setFirstName(userInfo.getName());
dmpProperties.getContacts().add(contactEntity);
} else {
throw new MyApplicationException("Contact not found " + UUID.fromString((String)model.getExtraProperties().get("contact")) + " Dmp " + item.getId());
}
}
if (model.getExtraProperties().containsKey("costs") && model.getExtraProperties().get("costs") != null) {
//if (!((String)model.getExtraProperties().get("costs")).equals("[]")) throw new MyApplicationException("ExtraProperties Cost value found. Migration not implemented");
if (!((ArrayList<?>)model.getExtraProperties().get("costs")).isEmpty()) throw new MyApplicationException("ExtraProperties Cost value found. Migration not implemented");
}
if (model.getExtraProperties().containsKey("ethicalIssues") && model.getExtraProperties().get("ethicalIssues") != null) {
throw new MyApplicationException("ExtraProperties ethicalIssues value found. Migration not implemented");
}
}
if (model.getProperties() != null) {
@ -163,7 +180,7 @@ public class DmpMigrationService {
DmpBlueprintValueEntity valueEntity = new DmpBlueprintValueEntity();
valueEntity.setFieldId(UUID.fromString(key));
org.opencdmp.commons.types.dmpblueprint.FieldEntity fieldEntity = this.getFieldOfId(definitionEntity, valueEntity.getFieldId());
if (fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)){
if (fieldEntity != null && fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)){
ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity;
switch (extraFieldEntity.getType()){
case Date -> valueEntity.setDateValue(Instant.parse((String) val));

View File

@ -2,8 +2,10 @@ package eu.old.eudat.publicapi.migration;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.old.eudat.migration.*;
import gr.cite.tools.logging.LoggerService;
import io.swagger.annotations.Api;
import jakarta.xml.bind.JAXBException;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
@ -23,6 +25,7 @@ import java.net.URISyntaxException;
@RequestMapping(value = {"/api/public/migration"})
public class MigrationController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(MigrationController.class));
private final DmpMigrationService dmpMigrationService;
private final DataRepositoryMigrationService dataRepositoryMigrationService;
private final ExternalDatasetMigrationService externalDatasetMigrationService;
@ -121,10 +124,68 @@ public class MigrationController {
//
this.storageFileMigrationService.migrate();
logger.info("Completed!!!");
// throw new RuntimeException("");
return true;
}
@GetMapping("step_1")
@Transactional
public boolean step1() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException, NoSuchFieldException, InvalidApplicationException, TransformerException, URISyntaxException {
//Reference
this.dataRepositoryMigrationService.migrate();
this.externalDatasetMigrationService.migrate();
this.funderMigrationService.migrate();
this.grantMigrationService.migrate();
this.organizationMigrationService.migrate();
this.projectMigrationService.migrate();
this.registryMigrationService.migrate();
this.researcherMigrationService.migrate();
this.serviceMigrationService.migrate();
//User
this.userContactInfoMigrationService.migrate();
this.userMigrationService.migrate();
//XML recreate
this.dmpBlueprintXmlMigrationService.migrate();
this.descriptionTemplateXmlMigrationService.migrate();
logger.info("Completed!!!");
return true;
}
@GetMapping("step_2")
@Transactional
public boolean step2() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException, NoSuchFieldException, InvalidApplicationException, TransformerException, URISyntaxException {
//Dmp
this.dmpMigrationService.migrate();
this.dmpDatasetProfileMigrationService.migrate();
this.dmpUserMigrationService.migrate();
logger.info("Completed!!!");
return true;
}
@GetMapping("step_3")
@Transactional
public boolean step3() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException, NoSuchFieldException, InvalidApplicationException, TransformerException, URISyntaxException {
//Description
this.datasetMigrationService.migrate();
this.datasetReferenceMigrationService.migrateDatasetReferences();
this.tagMigrationService.migrate();
this.storageFileMigrationService.migrate();
logger.info("Completed!!!");
return true;
}
@GetMapping("dmp-blueprints-xml")
@Transactional
public boolean migrateDmpBlueprint() throws JAXBException, InvalidApplicationException, IOException, ParserConfigurationException, NoSuchFieldException, TransformerException, IllegalAccessException, InstantiationException, SAXException {