migration changes
This commit is contained in:
parent
4043a67c9c
commit
c03594f74a
|
@ -155,7 +155,7 @@ public class DescriptionTemplateXmlCleanInvalidReferenceTypesService {
|
||||||
|
|
||||||
data.setId(persist.getId());
|
data.setId(persist.getId());
|
||||||
data.setOrdinal(persist.getOrdinal());
|
data.setOrdinal(persist.getOrdinal());
|
||||||
data.setSchematics(persist.getSchematics());
|
data.setSemantics(persist.getSemantics());
|
||||||
data.setDefaultValue(persist.getDefaultValue());
|
data.setDefaultValue(persist.getDefaultValue());
|
||||||
data.setValidations(persist.getValidations());
|
data.setValidations(persist.getValidations());
|
||||||
data.setIncludeInExport(persist.getIncludeInExport());
|
data.setIncludeInExport(persist.getIncludeInExport());
|
||||||
|
|
|
@ -193,7 +193,7 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
|
|
||||||
data.setId(persist.getId().trim());
|
data.setId(persist.getId().trim());
|
||||||
data.setOrdinal(persist.getOrdinal());
|
data.setOrdinal(persist.getOrdinal());
|
||||||
data.setSchematics(persist.getSchematics());
|
data.setSemantics(persist.getSchematics());
|
||||||
if (persist.getValidations() != null) data.setValidations(persist.getValidations().stream().map(x-> {
|
if (persist.getValidations() != null) data.setValidations(persist.getValidations().stream().map(x-> {
|
||||||
switch (x){
|
switch (x){
|
||||||
case NONE -> {
|
case NONE -> {
|
||||||
|
@ -218,11 +218,11 @@ public class DescriptionTemplateXmlMigrationService {
|
||||||
type = FieldDataExternalDatasetType.of(((ExternalDatasetsData)persist.getData()).getType());
|
type = FieldDataExternalDatasetType.of(((ExternalDatasetsData)persist.getData()).getType());
|
||||||
} catch (Exception e) { type = FieldDataExternalDatasetType.Other; }
|
} catch (Exception e) { type = FieldDataExternalDatasetType.Other; }
|
||||||
if (type == null) 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){
|
switch (type){
|
||||||
case Other -> data.getSchematics().add("referencetype.externaldataset.type.other");
|
case Other -> data.getSemantics().add("referencetype.externaldataset.type.other");
|
||||||
case ProducedDataset -> data.getSchematics().add("referencetype.externaldataset.type.produced");
|
case ProducedDataset -> data.getSemantics().add("referencetype.externaldataset.type.produced");
|
||||||
case ReusedDataset -> data.getSchematics().add("referencetype.externaldataset.type.reused");
|
case ReusedDataset -> data.getSemantics().add("referencetype.externaldataset.type.reused");
|
||||||
default -> throw new MyApplicationException("Invalid type " + type);
|
default -> throw new MyApplicationException("Invalid type " + type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.old.eudat.migration;
|
package eu.old.eudat.migration;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
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.dmp.DmpModel;
|
||||||
import org.opencdmp.commonmodels.models.dmpblueprint.SectionModel;
|
import org.opencdmp.commonmodels.models.dmpblueprint.SectionModel;
|
||||||
import org.opencdmp.commons.JsonHandlingService;
|
import org.opencdmp.commons.JsonHandlingService;
|
||||||
|
@ -67,6 +68,7 @@ public class DmpMigrationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void migrate() throws IOException, NoSuchFieldException, IllegalAccessException, JAXBException, ParserConfigurationException, InstantiationException, SAXException {
|
public void migrate() throws IOException, NoSuchFieldException, IllegalAccessException, JAXBException, ParserConfigurationException, InstantiationException, SAXException {
|
||||||
|
UserInfoDao userInfoDao = databaseRepository.getUserInfoDao();
|
||||||
DMPDao dmpDao = databaseRepository.getDmpDao();
|
DMPDao dmpDao = databaseRepository.getDmpDao();
|
||||||
long total = dmpDao.asQueryable().count();
|
long total = dmpDao.asQueryable().count();
|
||||||
logger.debug("Migrate Dmp Total : " + total);
|
logger.debug("Migrate Dmp Total : " + total);
|
||||||
|
@ -83,7 +85,8 @@ public class DmpMigrationService {
|
||||||
if (!groupDmpMap.containsKey(dmp.getGroupId())) groupDmpMap.put(dmp.getGroupId(), new ArrayList<>());
|
if (!groupDmpMap.containsKey(dmp.getGroupId())) groupDmpMap.put(dmp.getGroupId(), new ArrayList<>());
|
||||||
groupDmpMap.get(dmp.getGroupId()).add(dmp);
|
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()) {
|
if (items != null && !items.isEmpty()) {
|
||||||
|
|
||||||
logger.debug("Migrate Dmp " + page * PageSize + " of " + total);
|
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)
|
if (model.getExtraProperties().containsKey("visible") && model.getExtraProperties().get("visible") != null)
|
||||||
data.setAccessType((boolean) model.getExtraProperties().get("visible") ? DmpAccessType.Public : DmpAccessType.Restricted);
|
data.setAccessType((boolean) model.getExtraProperties().get("visible") ? DmpAccessType.Public : DmpAccessType.Restricted);
|
||||||
if (model.getExtraProperties().containsKey("contact") && model.getExtraProperties().get("contact") != null) {
|
if (model.getExtraProperties().containsKey("contact") && model.getExtraProperties().get("contact") != null) {
|
||||||
DmpContactEntity contactEntity = new DmpContactEntity();
|
UserInfo userInfo = oldUsers.getOrDefault(UUID.fromString((String)model.getExtraProperties().get("contact")), null);
|
||||||
contactEntity.setUserId(UUID.fromString((String)model.getExtraProperties().get("contact")));
|
if (userInfo != null) {
|
||||||
dmpProperties.getContacts().add(contactEntity);
|
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) {
|
if (model.getProperties() != null) {
|
||||||
|
@ -163,7 +180,7 @@ public class DmpMigrationService {
|
||||||
DmpBlueprintValueEntity valueEntity = new DmpBlueprintValueEntity();
|
DmpBlueprintValueEntity valueEntity = new DmpBlueprintValueEntity();
|
||||||
valueEntity.setFieldId(UUID.fromString(key));
|
valueEntity.setFieldId(UUID.fromString(key));
|
||||||
org.opencdmp.commons.types.dmpblueprint.FieldEntity fieldEntity = this.getFieldOfId(definitionEntity, valueEntity.getFieldId());
|
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;
|
ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity;
|
||||||
switch (extraFieldEntity.getType()){
|
switch (extraFieldEntity.getType()){
|
||||||
case Date -> valueEntity.setDateValue(Instant.parse((String) val));
|
case Date -> valueEntity.setDateValue(Instant.parse((String) val));
|
||||||
|
|
|
@ -2,8 +2,10 @@ package eu.old.eudat.publicapi.migration;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import eu.old.eudat.migration.*;
|
import eu.old.eudat.migration.*;
|
||||||
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import jakarta.xml.bind.JAXBException;
|
import jakarta.xml.bind.JAXBException;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
@ -23,6 +25,7 @@ import java.net.URISyntaxException;
|
||||||
@RequestMapping(value = {"/api/public/migration"})
|
@RequestMapping(value = {"/api/public/migration"})
|
||||||
public class MigrationController {
|
public class MigrationController {
|
||||||
|
|
||||||
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(MigrationController.class));
|
||||||
private final DmpMigrationService dmpMigrationService;
|
private final DmpMigrationService dmpMigrationService;
|
||||||
private final DataRepositoryMigrationService dataRepositoryMigrationService;
|
private final DataRepositoryMigrationService dataRepositoryMigrationService;
|
||||||
private final ExternalDatasetMigrationService externalDatasetMigrationService;
|
private final ExternalDatasetMigrationService externalDatasetMigrationService;
|
||||||
|
@ -121,10 +124,68 @@ public class MigrationController {
|
||||||
//
|
//
|
||||||
this.storageFileMigrationService.migrate();
|
this.storageFileMigrationService.migrate();
|
||||||
|
|
||||||
|
logger.info("Completed!!!");
|
||||||
|
|
||||||
// throw new RuntimeException("");
|
// throw new RuntimeException("");
|
||||||
return true;
|
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")
|
@GetMapping("dmp-blueprints-xml")
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean migrateDmpBlueprint() throws JAXBException, InvalidApplicationException, IOException, ParserConfigurationException, NoSuchFieldException, TransformerException, IllegalAccessException, InstantiationException, SAXException {
|
public boolean migrateDmpBlueprint() throws JAXBException, InvalidApplicationException, IOException, ParserConfigurationException, NoSuchFieldException, TransformerException, IllegalAccessException, InstantiationException, SAXException {
|
||||||
|
|
Loading…
Reference in New Issue