Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring
This commit is contained in:
commit
3dbfc18fd6
|
@ -64,7 +64,6 @@ public class DescriptionEntity implements DataEntity<DescriptionEntity, UUID> {
|
|||
public static final String _isActive = "isActive";
|
||||
|
||||
@Column(name = "\"finalized_at\"")
|
||||
@Convert(converter = DateToUTCConverter.class)
|
||||
private Instant finalizedAt;
|
||||
|
||||
public static final String _finalizedAt = "finalizedAt";
|
||||
|
|
|
@ -6,6 +6,7 @@ import eu.eudat.commons.enums.DmpVersionStatus;
|
|||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.data.converters.enums.DmpAccessTypeConverter;
|
||||
import eu.eudat.data.converters.enums.DmpStatusConverter;
|
||||
import eu.eudat.data.converters.enums.DmpVersionStatusConverter;
|
||||
import eu.eudat.data.converters.enums.IsActiveConverter;
|
||||
import eu.eudat.data.old.queryableentity.DataEntity;
|
||||
import jakarta.persistence.*;
|
||||
|
@ -35,7 +36,7 @@ public class DmpEntity implements DataEntity<DmpEntity, UUID> {
|
|||
public static final String _version = "version";
|
||||
|
||||
@Column(name = "version_status", nullable = false)
|
||||
@Convert(converter = DmpStatusConverter.class)
|
||||
@Convert(converter = DmpVersionStatusConverter.class)
|
||||
private DmpVersionStatus versionStatus;
|
||||
|
||||
public static final String _versionStatus = "versionStatus";
|
||||
|
|
|
@ -1,51 +1,61 @@
|
|||
ALTER TABLE public."DescriptionTemplate" RENAME "ID" TO id;
|
||||
DO $$DECLARE
|
||||
this_version CONSTANT varchar := '00.01.010';
|
||||
BEGIN
|
||||
PERFORM * FROM "DBVersion" WHERE version = this_version;
|
||||
IF FOUND THEN RETURN; END IF;
|
||||
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Label" TO label;
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "ID" TO id;
|
||||
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Definition" TO definition;
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Label" TO label;
|
||||
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Status" TO status;
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Definition" TO definition;
|
||||
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Created" TO created_at;
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Status" TO status;
|
||||
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Modified" TO updated_at;
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Created" TO created_at;
|
||||
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Description" TO description;
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Modified" TO updated_at;
|
||||
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "GroupId" TO group_id;
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Description" TO description;
|
||||
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Version" TO version;
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "GroupId" TO group_id;
|
||||
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Language" TO "language";
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Version" TO version;
|
||||
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Type" TO "type";
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Language" TO "language";
|
||||
|
||||
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN created_at TYPE timestamp without time zone ;
|
||||
ALTER TABLE public."DescriptionTemplate" RENAME "Type" TO "type";
|
||||
|
||||
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN updated_at TYPE timestamp without time zone ;
|
||||
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN created_at TYPE timestamp without time zone ;
|
||||
|
||||
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN group_id DROP DEFAULT;
|
||||
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN updated_at TYPE timestamp without time zone ;
|
||||
|
||||
ALTER TABLE public."DescriptionTemplate" ADD COLUMN is_active smallint;
|
||||
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN group_id DROP DEFAULT;
|
||||
|
||||
UPDATE public."DescriptionTemplate" SET is_active = 1;
|
||||
ALTER TABLE public."DescriptionTemplate" ADD COLUMN is_active smallint;
|
||||
|
||||
UPDATE public."DescriptionTemplate" SET is_active = 0 where status = 99;
|
||||
UPDATE public."DescriptionTemplate" SET status = 0 where is_active = 0;
|
||||
UPDATE public."DescriptionTemplate" SET is_active = 1;
|
||||
|
||||
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN is_active SET NOT NULL;
|
||||
UPDATE public."DescriptionTemplate" SET is_active = 0 where status = 99;
|
||||
UPDATE public."DescriptionTemplate" SET status = 0 where is_active = 0;
|
||||
|
||||
ALTER TABLE public."DescriptionTemplate" ADD COLUMN version_status smallint;
|
||||
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN is_active SET NOT NULL;
|
||||
|
||||
UPDATE public."DescriptionTemplate" SET version_status = 1;
|
||||
ALTER TABLE public."DescriptionTemplate" ADD COLUMN version_status smallint;
|
||||
|
||||
UPDATE public."DescriptionTemplate" SET version_status = 0 where id in (
|
||||
UPDATE public."DescriptionTemplate" SET version_status = 1;
|
||||
|
||||
UPDATE public."DescriptionTemplate" SET version_status = 0 where id in (
|
||||
select dt.id from public."DescriptionTemplate" as dt
|
||||
where dt.version =
|
||||
(
|
||||
select Max(f.version)
|
||||
from public."DescriptionTemplate" as f where f.group_id=dt.group_id
|
||||
)
|
||||
);
|
||||
);
|
||||
|
||||
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN version_status SET NOT NULL;
|
||||
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN version_status SET NOT NULL;
|
||||
|
||||
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.010', '2023-11-02 12:00:00.000000+02', now(), 'Aling DescriptionTemplate table.');
|
||||
|
||||
END$$;
|
|
@ -9,7 +9,7 @@ CREATE TABLE IF NOT EXISTS public."DmpDescriptionTemplate"
|
|||
"id" uuid NOT NULL,
|
||||
"dmp" uuid NOT NULL,
|
||||
"description_template" uuid NOT NULL,
|
||||
"data" text COLLATE pg_catalog."default" NOT NULL,
|
||||
"section_id" uuid NOT NULL,
|
||||
"created_at" timestamp without time zone NOT NULL DEFAULT now(),
|
||||
"updated_at" timestamp without time zone NOT NULL DEFAULT now(),
|
||||
"is_active" smallint NOT NULL DEFAULT 1,
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package eu.old.eudat.migration;
|
||||
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.commons.enums.ReferenceFieldDataType;
|
||||
import eu.eudat.commons.enums.ReferenceSourceType;
|
||||
import eu.eudat.commons.enums.ReferenceType;
|
||||
import eu.eudat.commons.types.reference.DefinitionEntity;
|
||||
import eu.eudat.commons.types.reference.FieldEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.ReferenceEntity;
|
||||
import eu.old.eudat.data.dao.entities.DataRepositoryDao;
|
||||
import eu.old.eudat.data.entities.DataRepository;
|
||||
|
@ -23,9 +28,13 @@ public class DataRepositoryMigrationService {
|
|||
private static final String InternalReferenceSource = "dmp";
|
||||
private final DatabaseRepository databaseRepository;
|
||||
private final EntityManager entityManager;
|
||||
public DataRepositoryMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
|
||||
private final ConventionService conventionService;
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
public DataRepositoryMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService) {
|
||||
this.databaseRepository = databaseRepository;
|
||||
this.entityManager = entityManager;
|
||||
this.conventionService = conventionService;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public void migrate(){
|
||||
|
@ -50,6 +59,8 @@ public class DataRepositoryMigrationService {
|
|||
String[] referenceParts = item.getReference().split(":", 2);
|
||||
boolean isInternal = referenceParts[0].equals(InternalReferenceSource);
|
||||
|
||||
|
||||
|
||||
ReferenceEntity data = new ReferenceEntity();
|
||||
data.setId(item.getId());
|
||||
data.setLabel(item.getLabel());
|
||||
|
@ -61,6 +72,16 @@ public class DataRepositoryMigrationService {
|
|||
data.setReference(referenceParts[1]);
|
||||
data.setSource(isInternal? "Internal" : referenceParts[0]);
|
||||
data.setSourceType(isInternal? ReferenceSourceType.Internal : ReferenceSourceType.External);
|
||||
if (!this.conventionService.isNullOrEmpty(item.getUri())){
|
||||
DefinitionEntity definitionEntity = new DefinitionEntity();
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("uri");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Text);
|
||||
fieldEntity.setValue(item.getUri());
|
||||
definitionEntity.setFields(List.of(fieldEntity));
|
||||
data.setDefinition(this.xmlHandlingService.toXmlSafe(definitionEntity));
|
||||
}
|
||||
|
||||
this.entityManager.persist(data);
|
||||
}
|
||||
this.entityManager.flush();
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
package eu.old.eudat.migration;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import eu.eudat.commons.JsonHandlingService;
|
||||
import eu.eudat.commons.enums.*;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.old.eudat.data.entities.Dataset;
|
||||
import eu.old.eudat.logic.services.operations.DatabaseRepository;
|
||||
import eu.old.eudat.models.data.datasetwizard.DatasetWizardModel;
|
||||
import eu.old.eudat.queryable.QueryableList;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class DatasetMigrationService {
|
||||
|
||||
private final DatabaseRepository databaseRepository;
|
||||
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
|
||||
private final EntityManager entityManager;
|
||||
|
||||
public DatasetMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager) {
|
||||
this.databaseRepository = databaseRepository;
|
||||
this.jsonHandlingService = jsonHandlingService;
|
||||
this.entityManager = entityManager;
|
||||
}
|
||||
|
||||
public QueryableList<Dataset> datasetQueryableList() {
|
||||
return databaseRepository.getDatasetDao().asQueryable();
|
||||
}
|
||||
|
||||
public List<DatasetWizardModel> getDatasets(Integer skip, Integer take) {
|
||||
List<Dataset> datasets = datasetQueryableList()
|
||||
.orderBy((builder, root) -> builder.desc(root.get("created")))
|
||||
.skip(skip)
|
||||
.take(take)
|
||||
.toList();
|
||||
|
||||
return datasets.stream().map(x -> {
|
||||
DatasetWizardModel dataset = new DatasetWizardModel();
|
||||
dataset.fromDataModel(x);
|
||||
return dataset;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
public List<DatasetMigrationCollectedInfo> collectDatasetsInfo() throws JsonProcessingException {
|
||||
List<DatasetMigrationCollectedInfo> collectedInfoList = new ArrayList<>();
|
||||
List<DatasetWizardModel> datasets = getDatasets(0, Integer.MAX_VALUE);
|
||||
for (DatasetWizardModel datasetWizardModel : datasets) {
|
||||
DatasetMigrationCollectedInfo datasetMigrationCollectedInfo = new DatasetMigrationCollectedInfo();
|
||||
|
||||
//Collect basic dataset information
|
||||
DescriptionEntity descriptionEntity = new DescriptionEntity();
|
||||
descriptionEntity.setId(datasetWizardModel.getId());
|
||||
descriptionEntity.setDescription(datasetWizardModel.getDescription());
|
||||
descriptionEntity.setCreatedById(datasetWizardModel.getCreatedBy());
|
||||
descriptionEntity.setDmpId(datasetWizardModel.getDmp().getId());
|
||||
descriptionEntity.setLabel(datasetWizardModel.getLabel());
|
||||
if (datasetWizardModel.getCreated() != null)
|
||||
descriptionEntity.setCreatedAt(datasetWizardModel.getCreated().toInstant());
|
||||
if (datasetWizardModel.getModified() != null)
|
||||
descriptionEntity.setUpdatedAt(datasetWizardModel.getModified().toInstant());
|
||||
if (datasetWizardModel.getFinalized() != null)
|
||||
descriptionEntity.setFinalizedAt(datasetWizardModel.getFinalized().toInstant());
|
||||
if (datasetWizardModel.getStatus() == 99) {
|
||||
descriptionEntity.setIsActive(IsActive.Inactive);
|
||||
descriptionEntity.setStatus(DescriptionStatus.Canceled);
|
||||
} else {
|
||||
descriptionEntity.setIsActive(IsActive.Active);
|
||||
descriptionEntity.setStatus(DescriptionStatus.of(datasetWizardModel.getStatus()));
|
||||
}
|
||||
// descriptionEntity.setDmpDescriptionTemplateId(); //TODO MIGRATE DMPDESCRIPTIONTEMPLATES
|
||||
|
||||
datasetMigrationCollectedInfo.descriptionEntity = descriptionEntity;
|
||||
|
||||
collectedInfoList.add(datasetMigrationCollectedInfo);
|
||||
}
|
||||
return collectedInfoList;
|
||||
}
|
||||
|
||||
public String migrate() throws JsonProcessingException {
|
||||
for (DatasetMigrationCollectedInfo collectedInfo : collectDatasetsInfo()) {
|
||||
this.entityManager.persist(collectedInfo.descriptionEntity);
|
||||
}
|
||||
this.entityManager.flush();
|
||||
return "Migrated dmps";
|
||||
}
|
||||
|
||||
public static class DatasetMigrationCollectedInfo {
|
||||
|
||||
public DescriptionEntity descriptionEntity;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,214 @@
|
|||
package eu.old.eudat.migration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import eu.eudat.commons.JsonHandlingService;
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.commons.enums.ReferenceFieldDataType;
|
||||
import eu.eudat.commons.enums.ReferenceSourceType;
|
||||
import eu.eudat.commons.enums.ReferenceType;
|
||||
import eu.eudat.commons.types.reference.FieldEntity;
|
||||
import eu.eudat.data.DescriptionTemplateEntity;
|
||||
import eu.eudat.data.DmpBlueprintEntity;
|
||||
import eu.eudat.data.DmpDescriptionTemplateEntity;
|
||||
import eu.eudat.data.ReferenceEntity;
|
||||
import eu.eudat.model.DmpBlueprint;
|
||||
import eu.eudat.query.DescriptionTemplateQuery;
|
||||
import eu.eudat.query.DmpBlueprintQuery;
|
||||
import eu.old.eudat.data.dao.entities.DmpDatasetProfileDao;
|
||||
import eu.old.eudat.data.dao.entities.ResearcherDao;
|
||||
import eu.old.eudat.data.entities.DMPDatasetProfile;
|
||||
import eu.old.eudat.data.entities.Researcher;
|
||||
import eu.old.eudat.logic.services.operations.DatabaseRepository;
|
||||
import eu.old.eudat.queryable.QueryableList;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.xml.bind.JAXBException;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.xml.sax.SAXException;
|
||||
import eu.eudat.commons.types.dmpblueprint.DefinitionEntity;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class DmpDatasetProfileMigrationService {
|
||||
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpDatasetProfileMigrationService.class));
|
||||
private final DatabaseRepository databaseRepository;
|
||||
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
private final QueryFactory queryFactory;
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
private static final int PageSize = 500;
|
||||
private static final boolean TestMode = false;
|
||||
private final EntityManager entityManager;
|
||||
|
||||
public DmpDatasetProfileMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, QueryFactory queryFactory, XmlHandlingService xmlHandlingService, EntityManager entityManager) {
|
||||
this.databaseRepository = databaseRepository;
|
||||
this.jsonHandlingService = jsonHandlingService;
|
||||
this.queryFactory = queryFactory;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
this.entityManager = entityManager;
|
||||
}
|
||||
|
||||
public void migrate() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException {
|
||||
DmpDatasetProfileDao dmpDatasetProfileDao = databaseRepository.getDmpDatasetProfileDao();
|
||||
long total = dmpDatasetProfileDao.asQueryable().count();
|
||||
logger.debug("Migrate DmpDatasetProfile Total : " + total);
|
||||
int page = 0;
|
||||
|
||||
List<DMPDatasetProfile> items;
|
||||
do {
|
||||
items = dmpDatasetProfileDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
|
||||
if (items != null && !items.isEmpty()) {
|
||||
logger.debug("Migrate DmpDatasetProfile " + page * PageSize + " of " + total);
|
||||
|
||||
List<DmpBlueprintEntity> dmpBlueprints = this.queryFactory.query(DmpBlueprintQuery.class).ids(items.stream().map(x-> x.getDmp().getProfile().getId()).distinct().toList()).collect();
|
||||
Map<UUID, DefinitionEntity> dmpBlueprintsMap = new HashMap<>();
|
||||
for (DmpBlueprintEntity dmpBlueprint : dmpBlueprints) {
|
||||
DefinitionEntity definitionEntity = this.xmlHandlingService.fromXml(DefinitionEntity.class, dmpBlueprint.getDefinition());
|
||||
dmpBlueprintsMap.put(dmpBlueprint.getId(), definitionEntity);
|
||||
}
|
||||
|
||||
for (DMPDatasetProfile item : items) {
|
||||
entityManager.detach(item);
|
||||
|
||||
DmpDatasetProfileData profileData = jsonHandlingService.fromJson(DmpDatasetProfileData.class, item.getData());
|
||||
|
||||
if (profileData == null || profileData.dmpSectionIndex == null || profileData.dmpSectionIndex.isEmpty()){
|
||||
logger.error("Migrate DmpDatasetProfile " + item.getId() + " failed no section info ");
|
||||
throw new MyApplicationException();
|
||||
}
|
||||
DefinitionEntity definition = dmpBlueprintsMap.getOrDefault(item.getDmp().getProfile().getId(), null);
|
||||
if (definition == null){
|
||||
logger.error("Migrate DmpDatasetProfile " + item.getId() + " failed blueprint definition not found for blueprint " + item.getDmp().getProfile().getId());
|
||||
}
|
||||
|
||||
for (int sectionIndex: profileData.dmpSectionIndex) {
|
||||
if (definition == null || definition.getSections() == null || definition.getSections().size() < sectionIndex) {
|
||||
logger.error("Migrate DmpDatasetProfile " + item.getId() + " can nto found section id for section " + sectionIndex);
|
||||
throw new MyApplicationException();
|
||||
}
|
||||
UUID sectionId = definition.getSections().get(sectionIndex).getId();
|
||||
if (sectionId == null) {
|
||||
logger.error("Migrate DmpDatasetProfile " + item.getId() + " can nto found section id for section " + sectionIndex);
|
||||
throw new MyApplicationException();
|
||||
}
|
||||
|
||||
DmpDescriptionTemplateEntity data = new DmpDescriptionTemplateEntity();
|
||||
data.setId(UUID.randomUUID());
|
||||
data.setDescriptionTemplateId(item.getDatasetprofile().getId());
|
||||
data.setDmpId(item.getDmp().getId());
|
||||
data.setCreatedAt(Instant.now());
|
||||
data.setUpdatedAt(Instant.now());
|
||||
data.setSectionId(sectionId);
|
||||
data.setIsActive(IsActive.Active);
|
||||
this.entityManager.persist(data);
|
||||
}
|
||||
}
|
||||
this.entityManager.flush();
|
||||
|
||||
page++;
|
||||
}
|
||||
} while (items != null && !items.isEmpty() && !TestMode);
|
||||
}
|
||||
//
|
||||
// public QueryableList<DMPDatasetProfile> dmpDatasetProfileQueryableList() {
|
||||
// return databaseRepository.getDmpDatasetProfileDao().asQueryable();
|
||||
// }
|
||||
//
|
||||
// public List<DMPDatasetProfile> getDatasets(Integer skip, Integer take) {
|
||||
// return dmpDatasetProfileQueryableList()
|
||||
//// .orderBy((builder, root) -> builder.desc(root.get("created")))
|
||||
// .skip(skip)
|
||||
// .take(take)
|
||||
// .toList();
|
||||
// }
|
||||
//
|
||||
// public List<DmpDatasetProfileMigrationCollectedInfo> collectDatasetsInfo() throws Exception {
|
||||
// List<DmpDatasetProfileMigrationCollectedInfo> collectedInfoList = new ArrayList<>();
|
||||
// List<DMPDatasetProfile> items = getDatasets(0, 4);
|
||||
//
|
||||
// List<DmpBlueprintEntity> dmpBlueprints = this.queryFactory.query(DmpBlueprintQuery.class).ids(items.stream().map(x-> x.getDmp().getProfile().getId()).distinct().toList()).collect();
|
||||
// Map<UUID, DefinitionEntity> dmpBlueprintsMap = new HashMap<>();
|
||||
// for (DmpBlueprintEntity dmpBlueprint : dmpBlueprints) {
|
||||
// DefinitionEntity definitionEntity = this.xmlHandlingService.fromXml(DefinitionEntity.class, dmpBlueprint.getDefinition());
|
||||
// dmpBlueprintsMap.put(dmpBlueprint.getId(), definitionEntity);
|
||||
// }
|
||||
//
|
||||
// for (DMPDatasetProfile item : items) {
|
||||
// this.entityManager.detach(item);
|
||||
//
|
||||
// DmpDatasetProfileMigrationCollectedInfo dmpDatasetProfileMigrationCollectedInfo = new DmpDatasetProfileMigrationCollectedInfo();
|
||||
//
|
||||
// DmpDatasetProfileData profileData = jsonHandlingService.fromJson(DmpDatasetProfileData.class, item.getData());
|
||||
//
|
||||
// if (profileData == null || profileData.dmpSectionIndex == null || profileData.dmpSectionIndex.isEmpty()){
|
||||
// throw new Exception();
|
||||
// }
|
||||
// DefinitionEntity definition = dmpBlueprintsMap.getOrDefault(item.getDmp().getProfile().getId(), null);
|
||||
// if (definition == null){
|
||||
// throw new Exception();
|
||||
// }
|
||||
//
|
||||
// for (int sectionIndex: profileData.dmpSectionIndex) {
|
||||
// if ( definition.getSections().size() < sectionIndex) {
|
||||
// throw new Exception();
|
||||
// }
|
||||
// UUID sectionId = definition.getSections().get(sectionIndex).getId();
|
||||
//
|
||||
// DmpDescriptionTemplateEntity data = new DmpDescriptionTemplateEntity();
|
||||
// data.setDescriptionTemplateId(item.getDatasetprofile().getId());
|
||||
// data.setDmpId(item.getDmp().getId());
|
||||
// data.setCreatedAt(Instant.now());
|
||||
// data.setUpdatedAt(Instant.now());
|
||||
// data.setSectionId(sectionId); //TODO
|
||||
// data.setIsActive(IsActive.Active);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// dmpDatasetProfileMigrationCollectedInfo.dmpDescriptionTemplateEntity = data;
|
||||
//
|
||||
// collectedInfoList.add(dmpDatasetProfileMigrationCollectedInfo);
|
||||
// }
|
||||
// return collectedInfoList;
|
||||
// }
|
||||
//
|
||||
// public String migrate() throws JsonProcessingException {
|
||||
// for (DmpDatasetProfileMigrationCollectedInfo collectedInfo : collectDatasetsInfo()) {
|
||||
//// this.entityManager.persist(collectedInfo.dmpDescriptionTemplateEntity);
|
||||
// }
|
||||
// this.entityManager.flush();
|
||||
// return "Migrated dmps";
|
||||
// }
|
||||
//
|
||||
// public static class DmpDatasetProfileMigrationCollectedInfo {
|
||||
//
|
||||
// public DmpDescriptionTemplateEntity dmpDescriptionTemplateEntity;
|
||||
//
|
||||
// }
|
||||
//
|
||||
@JsonIgnoreProperties({"validationErrorModel"})
|
||||
public static class DmpDatasetProfileData {
|
||||
|
||||
private List<Integer> dmpSectionIndex;
|
||||
|
||||
public List<Integer> getDmpSectionIndex() {
|
||||
return dmpSectionIndex;
|
||||
}
|
||||
|
||||
public void setDmpSectionIndex(List<Integer> dmpSectionIndex) {
|
||||
this.dmpSectionIndex = dmpSectionIndex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -9,30 +9,43 @@ import eu.eudat.commons.enums.IsActive;
|
|||
import eu.eudat.commons.types.dmp.DmpBlueprintValueEntity;
|
||||
import eu.eudat.commons.types.dmp.DmpContactEntity;
|
||||
import eu.eudat.commons.types.dmp.DmpPropertiesEntity;
|
||||
import eu.eudat.commons.types.dmpblueprint.DefinitionEntity;
|
||||
import eu.eudat.data.DmpBlueprintEntity;
|
||||
import eu.eudat.data.DmpDescriptionTemplateEntity;
|
||||
import eu.eudat.data.DmpEntity;
|
||||
import eu.eudat.query.DmpBlueprintQuery;
|
||||
import eu.old.eudat.data.dao.entities.DMPDao;
|
||||
import eu.old.eudat.data.dao.entities.DmpDatasetProfileDao;
|
||||
import eu.old.eudat.data.entities.DMP;
|
||||
import eu.old.eudat.data.entities.DMPDatasetProfile;
|
||||
import eu.old.eudat.logic.services.operations.DatabaseRepository;
|
||||
import eu.old.eudat.models.data.dmp.DataManagementPlan;
|
||||
import eu.old.eudat.publicapi.migration.MigrationController;
|
||||
import eu.old.eudat.queryable.QueryableList;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.xml.bind.JAXBException;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class DmpMigrationService {
|
||||
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpMigrationService.class));
|
||||
private final DatabaseRepository databaseRepository;
|
||||
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
|
||||
private final EntityManager entityManager;
|
||||
private static final int PageSize = 500;
|
||||
private static final boolean TestMode = false;
|
||||
|
||||
public DmpMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager) {
|
||||
this.databaseRepository = databaseRepository;
|
||||
|
@ -40,99 +53,189 @@ public class DmpMigrationService {
|
|||
this.entityManager = entityManager;
|
||||
}
|
||||
|
||||
public QueryableList<DMP> dmpQueryableList() {
|
||||
return databaseRepository.getDmpDao().asQueryable();
|
||||
}
|
||||
public void migrate() throws JsonProcessingException {
|
||||
DMPDao dmpDao = databaseRepository.getDmpDao();
|
||||
long total = dmpDao.asQueryable().count();
|
||||
logger.debug("Migrate Dmp Total : " + total);
|
||||
int page = 0;
|
||||
|
||||
public List<DataManagementPlan> getDmps(@PathVariable("skip") Integer skip, @PathVariable("take") Integer take) {
|
||||
List<DMP> dmps = dmpQueryableList()
|
||||
.orderBy((builder, root) -> builder.desc(root.get("created")))
|
||||
.skip(skip)
|
||||
.take(take)
|
||||
.toList();
|
||||
List<DMP> items;
|
||||
do {
|
||||
items = dmpDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
|
||||
if (items != null && !items.isEmpty()) {
|
||||
logger.debug("Migrate Dmp " + page * PageSize + " of " + total);
|
||||
|
||||
return dmps.stream().map(x -> {
|
||||
DataManagementPlan dmp = new DataManagementPlan();
|
||||
dmp.fromDataModel(x);
|
||||
return dmp;
|
||||
}).toList();
|
||||
}
|
||||
for (DMP item : items) {
|
||||
//entityManager.detach(item);
|
||||
|
||||
public List<DmpMigrationCollectedInfo> collectDmpsInfo() throws JsonProcessingException {
|
||||
List<DmpMigrationCollectedInfo> collectedInfoList = new ArrayList<>();
|
||||
List<DataManagementPlan> dmps = getDmps(0, 4);
|
||||
for (DataManagementPlan dataManagementPlan : dmps) {
|
||||
DmpMigrationCollectedInfo dmpMigrationCollectedInfo = new DmpMigrationCollectedInfo();
|
||||
DataManagementPlan model = new DataManagementPlan();
|
||||
model.fromDataModel(item);
|
||||
|
||||
DmpPropertiesEntity dmpProperties = new DmpPropertiesEntity();
|
||||
dmpProperties.setDmpBlueprintValues(new ArrayList<>());
|
||||
dmpProperties.setContacts(new ArrayList<>());
|
||||
|
||||
//Collect basic dmp information
|
||||
DmpEntity dmpEntity = new DmpEntity();
|
||||
dmpEntity.setId(UUID.randomUUID());
|
||||
dmpEntity.setLabel(dataManagementPlan.getLabel());
|
||||
dmpEntity.setDescription(dataManagementPlan.getDescription());
|
||||
if (dataManagementPlan.getCreator() != null)
|
||||
dmpEntity.setCreatorId(dataManagementPlan.getCreator().getId());
|
||||
dmpEntity.setGroupId(dataManagementPlan.getGroupId());
|
||||
dmpEntity.setVersion((short) dataManagementPlan.getVersion());
|
||||
dmpEntity.setVersionStatus(DmpVersionStatus.of((short) dataManagementPlan.getVersionStatus()));
|
||||
if (dataManagementPlan.getCreated() != null)
|
||||
dmpEntity.setCreatedAt(dataManagementPlan.getCreated().toInstant());
|
||||
if (dataManagementPlan.getModified() != null)
|
||||
dmpEntity.setUpdatedAt(dataManagementPlan.getModified().toInstant());
|
||||
if (dataManagementPlan.getFinalized() != null)
|
||||
dmpEntity.setFinalizedAt(dataManagementPlan.getFinalized().toInstant());
|
||||
dmpEntity.setBlueprintId(dataManagementPlan.getProfile().getId());
|
||||
if (dataManagementPlan.getExtraProperties() != null) {
|
||||
if (dataManagementPlan.getExtraProperties().containsKey("language") && dataManagementPlan.getExtraProperties().get("language") != null)
|
||||
dmpEntity.setLanguage((String) dataManagementPlan.getExtraProperties().get("language"));
|
||||
if (dataManagementPlan.getExtraProperties().containsKey("visible") && dataManagementPlan.getExtraProperties().get("visible") != null)
|
||||
dmpEntity.setAccessType((boolean) dataManagementPlan.getExtraProperties().get("visible") ? DmpAccessType.Public : DmpAccessType.Restricted);
|
||||
if (dataManagementPlan.getExtraProperties().containsKey("contact") && dataManagementPlan.getExtraProperties().get("contact") != null) {
|
||||
DmpEntity data = new DmpEntity();
|
||||
data.setId(model.getId());
|
||||
data.setLabel(model.getLabel());
|
||||
data.setDescription(model.getDescription());
|
||||
if (model.getCreator() != null)
|
||||
data.setCreatorId(model.getCreator().getId());
|
||||
data.setGroupId(model.getGroupId());
|
||||
data.setVersion((short) model.getVersion());
|
||||
data.setVersionStatus(DmpVersionStatus.of((short) model.getVersionStatus()));
|
||||
if (model.getCreated() != null)
|
||||
data.setCreatedAt(model.getCreated().toInstant());
|
||||
if (model.getModified() != null)
|
||||
data.setUpdatedAt(model.getModified().toInstant());
|
||||
if (model.getFinalized() != null)
|
||||
data.setFinalizedAt(model.getFinalized().toInstant());
|
||||
data.setBlueprintId(model.getProfile().getId());
|
||||
if (model.getExtraProperties() != null) {
|
||||
if (model.getExtraProperties().containsKey("language") && model.getExtraProperties().get("language") != null)
|
||||
data.setLanguage((String) model.getExtraProperties().get("language"));
|
||||
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((String) dataManagementPlan.getExtraProperties().get("contact"));
|
||||
contactEntity.setUserId((String) model.getExtraProperties().get("contact"));
|
||||
dmpProperties.getContacts().add(contactEntity);
|
||||
}
|
||||
}
|
||||
if (dataManagementPlan.getProperties() != null) {
|
||||
dataManagementPlan.getProperties().forEach((key,val) -> {
|
||||
if (model.getProperties() != null) {
|
||||
model.getProperties().forEach((key,val) -> {
|
||||
DmpBlueprintValueEntity valueEntity = new DmpBlueprintValueEntity();
|
||||
valueEntity.setFieldId(key);
|
||||
valueEntity.setValue((String) val);
|
||||
dmpProperties.getDmpBlueprintValues().add(valueEntity);
|
||||
});
|
||||
}
|
||||
if (dataManagementPlan.getStatus() == 99) {
|
||||
dmpEntity.setIsActive(IsActive.Inactive);
|
||||
if (model.getStatus() == 99) {
|
||||
data.setIsActive(IsActive.Inactive);
|
||||
data.setStatus(DmpStatus.Draft);
|
||||
} else {
|
||||
dmpEntity.setIsActive(IsActive.Active);
|
||||
dmpEntity.setStatus(DmpStatus.of((short) dataManagementPlan.getStatus()));
|
||||
data.setIsActive(IsActive.Active);
|
||||
data.setStatus(DmpStatus.of((short) model.getStatus()));
|
||||
}
|
||||
dmpEntity.setProperties(jsonHandlingService.toJson(dmpProperties));
|
||||
dmpMigrationCollectedInfo.dmpEntity = dmpEntity;
|
||||
data.setProperties(jsonHandlingService.toJson(dmpProperties));
|
||||
|
||||
//Collect dmp Organization info
|
||||
|
||||
collectedInfoList.add(dmpMigrationCollectedInfo);
|
||||
if (data.getAccessType() == null) {
|
||||
logger.warn("AccessType not found set to default for dmp " + item.getId());
|
||||
data.setAccessType(DmpAccessType.Restricted); //TODO
|
||||
}
|
||||
return collectedInfoList;
|
||||
if (data.getLanguage() == null) {
|
||||
logger.warn("Language not found set to default for dmp " + item.getId());
|
||||
data.setLanguage(""); //TODO
|
||||
}
|
||||
if (data.getCreatorId() == null){
|
||||
logger.warn("Migration skipped creator not found " + item.getId());
|
||||
continue;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public String migrate() throws JsonProcessingException {
|
||||
for (DmpMigrationCollectedInfo collectedInfo : collectDmpsInfo()) {
|
||||
this.entityManager.persist(collectedInfo.dmpEntity);
|
||||
}
|
||||
|
||||
this.entityManager.persist(data);
|
||||
this.entityManager.flush();
|
||||
return "Migrated dmps";
|
||||
}
|
||||
|
||||
public static class DmpMigrationCollectedInfo {
|
||||
|
||||
public DmpEntity dmpEntity;
|
||||
|
||||
page++;
|
||||
}
|
||||
} while (items != null && !items.isEmpty() && !TestMode);
|
||||
}
|
||||
|
||||
// public QueryableList<DMP> dmpQueryableList() {
|
||||
// return databaseRepository.getDmpDao().asQueryable();
|
||||
// }
|
||||
//
|
||||
// public List<DataManagementPlan> getDmps(Integer skip, Integer take) {
|
||||
// List<DMP> dmps = dmpQueryableList()
|
||||
// .orderBy((builder, root) -> builder.desc(root.get("created")))
|
||||
// .skip(skip)
|
||||
// .take(take)
|
||||
// .toList();
|
||||
//
|
||||
// return dmps.stream().map(x -> {
|
||||
// DataManagementPlan dmp = new DataManagementPlan();
|
||||
// dmp.fromDataModel(x);
|
||||
// return dmp;
|
||||
// }).toList();
|
||||
// }
|
||||
|
||||
// public List<DmpMigrationCollectedInfo> collectDmpsInfo() throws JsonProcessingException {
|
||||
// List<DmpMigrationCollectedInfo> collectedInfoList = new ArrayList<>();
|
||||
// List<DataManagementPlan> dmps = getDmps(0, Integer.MAX_VALUE);
|
||||
// for (DataManagementPlan dataManagementPlan : dmps) {
|
||||
// DmpMigrationCollectedInfo dmpMigrationCollectedInfo = new DmpMigrationCollectedInfo();
|
||||
//
|
||||
// DmpPropertiesEntity dmpProperties = new DmpPropertiesEntity();
|
||||
// dmpProperties.setDmpBlueprintValues(new ArrayList<>());
|
||||
// dmpProperties.setContacts(new ArrayList<>());
|
||||
//
|
||||
// //Collect basic dmp information
|
||||
// DmpEntity dmpEntity = new DmpEntity();
|
||||
// dmpEntity.setId(dataManagementPlan.getId());
|
||||
// dmpEntity.setLabel(dataManagementPlan.getLabel());
|
||||
// dmpEntity.setDescription(dataManagementPlan.getDescription());
|
||||
// if (dataManagementPlan.getCreator() != null)
|
||||
// dmpEntity.setCreatorId(dataManagementPlan.getCreator().getId());
|
||||
// dmpEntity.setGroupId(dataManagementPlan.getGroupId());
|
||||
// dmpEntity.setVersion((short) dataManagementPlan.getVersion());
|
||||
// dmpEntity.setVersionStatus(DmpVersionStatus.of((short) dataManagementPlan.getVersionStatus()));
|
||||
// if (dataManagementPlan.getCreated() != null)
|
||||
// dmpEntity.setCreatedAt(dataManagementPlan.getCreated().toInstant());
|
||||
// if (dataManagementPlan.getModified() != null)
|
||||
// dmpEntity.setUpdatedAt(dataManagementPlan.getModified().toInstant());
|
||||
// if (dataManagementPlan.getFinalized() != null)
|
||||
// dmpEntity.setFinalizedAt(dataManagementPlan.getFinalized().toInstant());
|
||||
// dmpEntity.setBlueprintId(dataManagementPlan.getProfile().getId());
|
||||
// if (dataManagementPlan.getExtraProperties() != null) {
|
||||
// if (dataManagementPlan.getExtraProperties().containsKey("language") && dataManagementPlan.getExtraProperties().get("language") != null)
|
||||
// dmpEntity.setLanguage((String) dataManagementPlan.getExtraProperties().get("language"));
|
||||
// if (dataManagementPlan.getExtraProperties().containsKey("visible") && dataManagementPlan.getExtraProperties().get("visible") != null)
|
||||
// dmpEntity.setAccessType((boolean) dataManagementPlan.getExtraProperties().get("visible") ? DmpAccessType.Public : DmpAccessType.Restricted);
|
||||
// if (dataManagementPlan.getExtraProperties().containsKey("contact") && dataManagementPlan.getExtraProperties().get("contact") != null) {
|
||||
// DmpContactEntity contactEntity = new DmpContactEntity();
|
||||
// contactEntity.setUserId((String) dataManagementPlan.getExtraProperties().get("contact"));
|
||||
// dmpProperties.getContacts().add(contactEntity);
|
||||
// }
|
||||
// }
|
||||
// if (dataManagementPlan.getProperties() != null) {
|
||||
// dataManagementPlan.getProperties().forEach((key,val) -> {
|
||||
// DmpBlueprintValueEntity valueEntity = new DmpBlueprintValueEntity();
|
||||
// valueEntity.setFieldId(key);
|
||||
// valueEntity.setValue((String) val);
|
||||
// dmpProperties.getDmpBlueprintValues().add(valueEntity);
|
||||
// });
|
||||
// }
|
||||
// if (dataManagementPlan.getStatus() == 99) {
|
||||
// dmpEntity.setIsActive(IsActive.Inactive);
|
||||
// dmpEntity.setStatus(DmpStatus.Draft);
|
||||
// } else {
|
||||
// dmpEntity.setIsActive(IsActive.Active);
|
||||
// dmpEntity.setStatus(DmpStatus.of((short) dataManagementPlan.getStatus()));
|
||||
// }
|
||||
// dmpEntity.setProperties(jsonHandlingService.toJson(dmpProperties));
|
||||
// dmpMigrationCollectedInfo.dmpEntity = dmpEntity;
|
||||
//
|
||||
// //Collect dmp Organization info
|
||||
//
|
||||
// collectedInfoList.add(dmpMigrationCollectedInfo);
|
||||
// }
|
||||
// return collectedInfoList;
|
||||
// }
|
||||
//
|
||||
// public String migrate() throws JsonProcessingException {
|
||||
// for (DmpMigrationCollectedInfo collectedInfo : collectDmpsInfo()) {
|
||||
// this.entityManager.persist(collectedInfo.dmpEntity);
|
||||
// }
|
||||
// this.entityManager.flush();
|
||||
// return "Migrated dmps";
|
||||
// }
|
||||
//
|
||||
// public static class DmpMigrationCollectedInfo {
|
||||
//
|
||||
// public DmpEntity dmpEntity;
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ public class ExternalDatasetMigrationService {
|
|||
ReferenceEntity data = new ReferenceEntity();
|
||||
data.setId(item.getId());
|
||||
data.setLabel(item.getLabel());
|
||||
data.setAbbreviation(item.getAbbreviation());
|
||||
data.setIsActive(IsActive.Active);
|
||||
data.setType(ReferenceType.Datasets);
|
||||
data.setCreatedAt(item.getCreated().toInstant());
|
||||
|
|
|
@ -54,7 +54,7 @@ public class FunderMigrationService {
|
|||
ReferenceEntity data = new ReferenceEntity();
|
||||
data.setId(item.getId());
|
||||
data.setLabel(item.getLabel());
|
||||
data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active);
|
||||
data.setIsActive(IsActive.Active);
|
||||
data.setType(ReferenceType.Funder);
|
||||
data.setCreatedAt(item.getCreated().toInstant());
|
||||
data.setUpdatedAt(item.getModified().toInstant());
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package eu.old.eudat.migration;
|
||||
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.commons.enums.ReferenceFieldDataType;
|
||||
import eu.eudat.commons.enums.ReferenceSourceType;
|
||||
import eu.eudat.commons.enums.ReferenceType;
|
||||
import eu.eudat.commons.types.reference.DefinitionEntity;
|
||||
import eu.eudat.commons.types.reference.FieldEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.ReferenceEntity;
|
||||
import eu.old.eudat.data.dao.entities.GrantDao;
|
||||
import eu.old.eudat.data.entities.DMP;
|
||||
import eu.old.eudat.data.entities.Grant;
|
||||
import eu.old.eudat.logic.services.operations.DatabaseRepository;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
|
@ -13,6 +17,7 @@ import jakarta.persistence.EntityManager;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -24,9 +29,13 @@ public class GrantMigrationService {
|
|||
private static final String InternalReferenceSource = "dmp";
|
||||
private final DatabaseRepository databaseRepository;
|
||||
private final EntityManager entityManager;
|
||||
public GrantMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
|
||||
private final ConventionService conventionService;
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
public GrantMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService) {
|
||||
this.databaseRepository = databaseRepository;
|
||||
this.entityManager = entityManager;
|
||||
this.conventionService = conventionService;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public void migrate(){
|
||||
|
@ -54,7 +63,8 @@ public class GrantMigrationService {
|
|||
data.setId(item.getId());
|
||||
data.setLabel(item.getLabel());
|
||||
data.setDescription(item.getDescription());
|
||||
data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active);
|
||||
data.setAbbreviation(item.getAbbreviation());
|
||||
data.setIsActive(IsActive.Active);
|
||||
data.setType(ReferenceType.Grants);
|
||||
data.setCreatedAt(item.getCreated().toInstant());
|
||||
data.setUpdatedAt(item.getModified().toInstant());
|
||||
|
@ -62,6 +72,37 @@ public class GrantMigrationService {
|
|||
data.setReference(referenceParts[1]);
|
||||
data.setSource(isInternal? "Internal" : referenceParts[0]);
|
||||
data.setSourceType(isInternal ? ReferenceSourceType.Internal : ReferenceSourceType.External);
|
||||
|
||||
DefinitionEntity definitionEntity = new DefinitionEntity();
|
||||
definitionEntity.setFields(new ArrayList<>());
|
||||
if (!this.conventionService.isNullOrEmpty(item.getUri())){
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("uri");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Text);
|
||||
fieldEntity.setValue(item.getUri());
|
||||
definitionEntity.getFields().add(fieldEntity);
|
||||
}
|
||||
|
||||
if (item.getStartdate() != null){
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("startDate");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Date);
|
||||
fieldEntity.setValue(item.getStartdate().toInstant().toString());
|
||||
definitionEntity.getFields().add(fieldEntity);
|
||||
}
|
||||
|
||||
if (item.getEnddate() != null){
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("endDate");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Date);
|
||||
fieldEntity.setValue(item.getEnddate().toInstant().toString());
|
||||
definitionEntity.getFields().add(fieldEntity);
|
||||
}
|
||||
|
||||
if (!definitionEntity.getFields().isEmpty()){
|
||||
data.setDefinition(this.xmlHandlingService.toXmlSafe(definitionEntity));
|
||||
}
|
||||
|
||||
this.entityManager.persist(data);
|
||||
}
|
||||
this.entityManager.flush();
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package eu.old.eudat.migration;
|
||||
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.commons.enums.ReferenceFieldDataType;
|
||||
import eu.eudat.commons.enums.ReferenceSourceType;
|
||||
import eu.eudat.commons.enums.ReferenceType;
|
||||
import eu.eudat.commons.types.reference.DefinitionEntity;
|
||||
import eu.eudat.commons.types.reference.FieldEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.ReferenceEntity;
|
||||
import eu.old.eudat.data.dao.entities.OrganisationDao;
|
||||
import eu.old.eudat.data.entities.DMP;
|
||||
import eu.old.eudat.data.entities.Organisation;
|
||||
import eu.old.eudat.logic.services.operations.DatabaseRepository;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
|
@ -13,7 +17,6 @@ import jakarta.persistence.EntityManager;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -25,9 +28,13 @@ public class OrganizationMigrationService {
|
|||
private static final String InternalReferenceSource = "Internal";
|
||||
private final DatabaseRepository databaseRepository;
|
||||
private final EntityManager entityManager;
|
||||
public OrganizationMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
|
||||
private final ConventionService conventionService;
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
public OrganizationMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService) {
|
||||
this.databaseRepository = databaseRepository;
|
||||
this.entityManager = entityManager;
|
||||
this.conventionService = conventionService;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public void migrate(){
|
||||
|
@ -56,7 +63,8 @@ public class OrganizationMigrationService {
|
|||
ReferenceEntity data = new ReferenceEntity();
|
||||
data.setId(item.getId());
|
||||
data.setLabel(item.getLabel());
|
||||
data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active);
|
||||
data.setAbbreviation(item.getAbbreviation());
|
||||
data.setIsActive(IsActive.Active);
|
||||
data.setType(ReferenceType.Organizations);
|
||||
data.setCreatedAt(item.getCreated().toInstant());
|
||||
data.setUpdatedAt(item.getModified().toInstant());
|
||||
|
@ -64,6 +72,15 @@ public class OrganizationMigrationService {
|
|||
data.setAbbreviation(item.getAbbreviation());
|
||||
data.setSource(isInternal? "Internal" : referenceParts[0]);
|
||||
data.setSourceType(isInternal? ReferenceSourceType.Internal : ReferenceSourceType.External);
|
||||
if (!this.conventionService.isNullOrEmpty(item.getUri())){
|
||||
DefinitionEntity definitionEntity = new DefinitionEntity();
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("uri");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Text);
|
||||
fieldEntity.setValue(item.getUri());
|
||||
definitionEntity.setFields(List.of(fieldEntity));
|
||||
data.setDefinition(this.xmlHandlingService.toXmlSafe(definitionEntity));
|
||||
}
|
||||
this.entityManager.persist(data);
|
||||
}
|
||||
this.entityManager.flush();
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package eu.old.eudat.migration;
|
||||
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.commons.enums.ReferenceFieldDataType;
|
||||
import eu.eudat.commons.enums.ReferenceSourceType;
|
||||
import eu.eudat.commons.enums.ReferenceType;
|
||||
import eu.eudat.commons.types.reference.DefinitionEntity;
|
||||
import eu.eudat.commons.types.reference.FieldEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.ReferenceEntity;
|
||||
import eu.old.eudat.data.dao.entities.ProjectDao;
|
||||
import eu.old.eudat.data.entities.DMP;
|
||||
import eu.old.eudat.data.entities.Project;
|
||||
import eu.old.eudat.logic.services.operations.DatabaseRepository;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
|
@ -13,6 +17,7 @@ import jakarta.persistence.EntityManager;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -24,9 +29,13 @@ public class ProjectMigrationService {
|
|||
private static final String InternalReferenceSource = "dmp";
|
||||
private final DatabaseRepository databaseRepository;
|
||||
private final EntityManager entityManager;
|
||||
public ProjectMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
|
||||
private final ConventionService conventionService;
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
public ProjectMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService) {
|
||||
this.databaseRepository = databaseRepository;
|
||||
this.entityManager = entityManager;
|
||||
this.conventionService = conventionService;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public void migrate(){
|
||||
|
@ -54,8 +63,9 @@ public class ProjectMigrationService {
|
|||
ReferenceEntity data = new ReferenceEntity();
|
||||
data.setId(item.getId());
|
||||
data.setLabel(item.getLabel());
|
||||
data.setAbbreviation(item.getAbbreviation());
|
||||
data.setDescription(item.getDescription());
|
||||
data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active);
|
||||
data.setIsActive(IsActive.Active);
|
||||
data.setType(ReferenceType.Project);
|
||||
data.setCreatedAt(item.getCreated().toInstant());
|
||||
data.setUpdatedAt(item.getModified().toInstant());
|
||||
|
@ -63,6 +73,36 @@ public class ProjectMigrationService {
|
|||
data.setReference(referenceParts[1]);
|
||||
data.setSource(isInternal? "Internal" : referenceParts[0]);
|
||||
data.setSourceType(Project.ProjectType.INTERNAL.getValue().equals(item.getType())? ReferenceSourceType.Internal : ReferenceSourceType.External);
|
||||
|
||||
DefinitionEntity definitionEntity = new DefinitionEntity();
|
||||
definitionEntity.setFields(new ArrayList<>());
|
||||
if (!this.conventionService.isNullOrEmpty(item.getUri())){
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("uri");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Text);
|
||||
fieldEntity.setValue(item.getUri());
|
||||
definitionEntity.getFields().add(fieldEntity);
|
||||
}
|
||||
|
||||
if (item.getStartdate() != null){
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("startDate");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Date);
|
||||
fieldEntity.setValue(item.getStartdate().toInstant().toString());
|
||||
definitionEntity.getFields().add(fieldEntity);
|
||||
}
|
||||
|
||||
if (item.getEnddate() != null){
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("endDate");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Date);
|
||||
fieldEntity.setValue(item.getEnddate().toInstant().toString());
|
||||
definitionEntity.getFields().add(fieldEntity);
|
||||
}
|
||||
|
||||
if (!definitionEntity.getFields().isEmpty()){
|
||||
data.setDefinition(this.xmlHandlingService.toXmlSafe(definitionEntity));
|
||||
}
|
||||
this.entityManager.persist(data);
|
||||
}
|
||||
this.entityManager.flush();
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package eu.old.eudat.migration;
|
||||
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.commons.enums.ReferenceFieldDataType;
|
||||
import eu.eudat.commons.enums.ReferenceSourceType;
|
||||
import eu.eudat.commons.enums.ReferenceType;
|
||||
import eu.eudat.commons.types.reference.DefinitionEntity;
|
||||
import eu.eudat.commons.types.reference.FieldEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.ReferenceEntity;
|
||||
import eu.old.eudat.data.dao.entities.RegistryDao;
|
||||
import eu.old.eudat.data.entities.DMP;
|
||||
import eu.old.eudat.data.entities.Registry;
|
||||
import eu.old.eudat.logic.services.operations.DatabaseRepository;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
|
@ -24,9 +28,13 @@ public class RegistryMigrationService {
|
|||
private static final String InternalReferenceSource = "dmp";
|
||||
private final DatabaseRepository databaseRepository;
|
||||
private final EntityManager entityManager;
|
||||
public RegistryMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
|
||||
private final ConventionService conventionService;
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
public RegistryMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService) {
|
||||
this.databaseRepository = databaseRepository;
|
||||
this.entityManager = entityManager;
|
||||
this.conventionService = conventionService;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public void migrate(){
|
||||
|
@ -54,7 +62,8 @@ public class RegistryMigrationService {
|
|||
ReferenceEntity data = new ReferenceEntity();
|
||||
data.setId(item.getId());
|
||||
data.setLabel(item.getLabel());
|
||||
data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active);
|
||||
data.setAbbreviation(item.getAbbreviation());
|
||||
data.setIsActive(IsActive.Active);
|
||||
data.setType(ReferenceType.Registries);
|
||||
data.setCreatedAt(item.getCreated().toInstant());
|
||||
data.setUpdatedAt(item.getModified().toInstant());
|
||||
|
@ -62,6 +71,15 @@ public class RegistryMigrationService {
|
|||
data.setReference(referenceParts[1]);
|
||||
data.setSource(isInternal? "Internal" : referenceParts[0]);
|
||||
data.setSourceType(isInternal? ReferenceSourceType.Internal : ReferenceSourceType.External);
|
||||
if (!this.conventionService.isNullOrEmpty(item.getUri())){
|
||||
DefinitionEntity definitionEntity = new DefinitionEntity();
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("uri");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Text);
|
||||
fieldEntity.setValue(item.getUri());
|
||||
definitionEntity.setFields(List.of(fieldEntity));
|
||||
data.setDefinition(this.xmlHandlingService.toXmlSafe(definitionEntity));
|
||||
}
|
||||
this.entityManager.persist(data);
|
||||
}
|
||||
this.entityManager.flush();
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
package eu.old.eudat.migration;
|
||||
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.commons.enums.ReferenceFieldDataType;
|
||||
import eu.eudat.commons.enums.ReferenceSourceType;
|
||||
import eu.eudat.commons.enums.ReferenceType;
|
||||
import eu.eudat.commons.types.reference.DefinitionEntity;
|
||||
import eu.eudat.commons.types.reference.FieldEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.ReferenceEntity;
|
||||
import eu.old.eudat.data.dao.entities.OrganisationDao;
|
||||
import eu.old.eudat.data.dao.entities.ResearcherDao;
|
||||
import eu.old.eudat.data.entities.DMP;
|
||||
import eu.old.eudat.data.entities.Organisation;
|
||||
import eu.old.eudat.data.entities.Researcher;
|
||||
import eu.old.eudat.logic.services.operations.DatabaseRepository;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
|
@ -15,6 +17,7 @@ import jakarta.persistence.EntityManager;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -26,9 +29,13 @@ public class ResearcherMigrationService {
|
|||
private static final String InternalReferenceSource = "dmp";
|
||||
private final DatabaseRepository databaseRepository;
|
||||
private final EntityManager entityManager;
|
||||
public ResearcherMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
|
||||
private final ConventionService conventionService;
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
public ResearcherMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService) {
|
||||
this.databaseRepository = databaseRepository;
|
||||
this.entityManager = entityManager;
|
||||
this.conventionService = conventionService;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public void migrate(){
|
||||
|
@ -56,7 +63,7 @@ public class ResearcherMigrationService {
|
|||
ReferenceEntity data = new ReferenceEntity();
|
||||
data.setId(item.getId());
|
||||
data.setLabel(item.getLabel());
|
||||
data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active);
|
||||
data.setIsActive(IsActive.Active);
|
||||
data.setType(ReferenceType.Researcher);
|
||||
data.setCreatedAt(item.getCreated().toInstant());
|
||||
data.setUpdatedAt(item.getModified().toInstant());
|
||||
|
@ -64,6 +71,29 @@ public class ResearcherMigrationService {
|
|||
data.setReference(referenceParts[1]);
|
||||
data.setSource(isInternal? "Internal" : referenceParts[0]);
|
||||
data.setSourceType(isInternal? ReferenceSourceType.Internal : ReferenceSourceType.External);
|
||||
|
||||
DefinitionEntity definitionEntity = new DefinitionEntity();
|
||||
definitionEntity.setFields(new ArrayList<>());
|
||||
if (!this.conventionService.isNullOrEmpty(item.getUri())){
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("uri");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Text);
|
||||
fieldEntity.setValue(item.getUri());
|
||||
definitionEntity.getFields().add(fieldEntity);
|
||||
}
|
||||
if (!this.conventionService.isNullOrEmpty(item.getPrimaryEmail())){
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("primaryEmail");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Text);
|
||||
fieldEntity.setValue(item.getPrimaryEmail());
|
||||
definitionEntity.getFields().add(fieldEntity);
|
||||
}
|
||||
|
||||
|
||||
if (!definitionEntity.getFields().isEmpty()){
|
||||
data.setDefinition(this.xmlHandlingService.toXmlSafe(definitionEntity));
|
||||
}
|
||||
|
||||
this.entityManager.persist(data);
|
||||
}
|
||||
this.entityManager.flush();
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package eu.old.eudat.migration;
|
||||
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.commons.enums.ReferenceFieldDataType;
|
||||
import eu.eudat.commons.enums.ReferenceSourceType;
|
||||
import eu.eudat.commons.enums.ReferenceType;
|
||||
import eu.eudat.commons.types.reference.DefinitionEntity;
|
||||
import eu.eudat.commons.types.reference.FieldEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.ReferenceEntity;
|
||||
import eu.old.eudat.data.dao.entities.ServiceDao;
|
||||
import eu.old.eudat.data.entities.DMP;
|
||||
import eu.old.eudat.logic.services.operations.DatabaseRepository;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
|
@ -23,9 +27,13 @@ public class ServiceMigrationService {
|
|||
private static final String InternalReferenceSource = "dmp";
|
||||
private final DatabaseRepository databaseRepository;
|
||||
private final EntityManager entityManager;
|
||||
public ServiceMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
|
||||
private final ConventionService conventionService;
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
public ServiceMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService) {
|
||||
this.databaseRepository = databaseRepository;
|
||||
this.entityManager = entityManager;
|
||||
this.conventionService = conventionService;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public void migrate(){
|
||||
|
@ -53,8 +61,8 @@ public class ServiceMigrationService {
|
|||
ReferenceEntity data = new ReferenceEntity();
|
||||
data.setId(item.getId());
|
||||
data.setLabel(item.getLabel());
|
||||
data.setDescription(item.getLabel());
|
||||
data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active);
|
||||
data.setAbbreviation(item.getAbbreviation());
|
||||
data.setIsActive(IsActive.Active);
|
||||
data.setType(ReferenceType.Services);
|
||||
data.setCreatedAt(item.getCreated().toInstant());
|
||||
data.setUpdatedAt(item.getModified().toInstant());
|
||||
|
@ -62,6 +70,16 @@ public class ServiceMigrationService {
|
|||
data.setReference(referenceParts[1]);
|
||||
data.setSource(isInternal? "Internal" : referenceParts[0]);
|
||||
data.setSourceType(isInternal? ReferenceSourceType.Internal : ReferenceSourceType.External);
|
||||
if (!this.conventionService.isNullOrEmpty(item.getUri())){
|
||||
DefinitionEntity definitionEntity = new DefinitionEntity();
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("uri");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Text);
|
||||
fieldEntity.setValue(item.getUri());
|
||||
definitionEntity.setFields(List.of(fieldEntity));
|
||||
data.setDefinition(this.xmlHandlingService.toXmlSafe(definitionEntity));
|
||||
}
|
||||
|
||||
this.entityManager.persist(data);
|
||||
}
|
||||
this.entityManager.flush();
|
||||
|
|
|
@ -22,6 +22,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
private String description;
|
||||
private short status;
|
||||
private Date created;
|
||||
private UUID createdBy;
|
||||
private DataManagementPlan dmp;
|
||||
private Integer dmpSectionIndex;
|
||||
private PagedDatasetProfile datasetProfileDefinition;
|
||||
|
@ -33,6 +34,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
private DatasetProfileOverviewModel profile;
|
||||
private Boolean isProfileLatestVersion;
|
||||
private Date modified;
|
||||
private Date finalized;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
|
@ -83,6 +85,13 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
this.created = created;
|
||||
}
|
||||
|
||||
public UUID getCreatedBy() {
|
||||
return createdBy;
|
||||
}
|
||||
public void setCreatedBy(UUID createdBy) {
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
|
||||
public DataManagementPlan getDmp() {
|
||||
return dmp;
|
||||
}
|
||||
|
@ -161,6 +170,13 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
this.modified = modified;
|
||||
}
|
||||
|
||||
public Date getFinalized() {
|
||||
return finalized;
|
||||
}
|
||||
public void setFinalized(Date finalized) {
|
||||
this.finalized = finalized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatasetWizardModel fromDataModel(Dataset entity) {
|
||||
this.id = entity.getId();
|
||||
|
@ -183,6 +199,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
}).collect(Collectors.toList()) : new ArrayList<>();
|
||||
this.services = entity.getServices() != null ? entity.getServices().stream().map(item -> new eu.old.eudat.models.data.dataset.Service().fromDataModel(item.getService())).collect(Collectors.toList()) : new ArrayList<>();
|
||||
this.created = entity.getCreated();
|
||||
this.createdBy = entity.getCreator().getId();
|
||||
this.dmp = new DataManagementPlan().fromDataModelNoDatasets(entity.getDmp());
|
||||
this.dmpSectionIndex = entity.getDmpSectionIndex();
|
||||
this.externalDatasets = entity.getDatasetExternalDatasets() != null ? entity.getDatasetExternalDatasets().stream().map(item -> {
|
||||
|
@ -196,6 +213,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
return externalDatasetListingModel;
|
||||
}).collect(Collectors.toList()) : new ArrayList<>();
|
||||
this.modified = entity.getModified();
|
||||
this.finalized = entity.getFinalizedAt();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -251,7 +269,11 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
entity.setDmpSectionIndex(this.dmpSectionIndex);
|
||||
entity.setDescription(this.description);
|
||||
entity.setCreated(this.created != null ? this.created : new Date());
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setId(this.createdBy);
|
||||
entity.setCreator(userInfo);
|
||||
entity.setModified(new Date());
|
||||
entity.setFinalizedAt(this.finalized != null ? this.finalized : new Date());
|
||||
DescriptionTemplate profile = new DescriptionTemplate();
|
||||
profile.setId(this.profile.getId());
|
||||
entity.setProfile(profile);
|
||||
|
|
|
@ -3,8 +3,16 @@ package eu.old.eudat.publicapi.migration;
|
|||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import eu.old.eudat.migration.*;
|
||||
import io.swagger.annotations.Api;
|
||||
import jakarta.xml.bind.JAXBException;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
|
||||
@Api(tags = "Migration")
|
||||
@RestController
|
||||
|
@ -21,11 +29,14 @@ public class MigrationController {
|
|||
private final RegistryMigrationService registryMigrationService;
|
||||
private final ResearcherMigrationService researcherMigrationService;
|
||||
private final ServiceMigrationService serviceMigrationService;
|
||||
|
||||
private final DatasetMigrationService datasetMigrationService;
|
||||
private final DmpDatasetProfileMigrationService dmpDatasetProfileMigrationService;
|
||||
private final OrganizationMigrationService organizationMigrationService;
|
||||
|
||||
public MigrationController(
|
||||
DmpMigrationService dmpMigrationService,
|
||||
DatasetMigrationService datasetMigrationService,
|
||||
DmpDatasetProfileMigrationService dmpDatasetProfileMigrationService,
|
||||
DataRepositoryMigrationService dataRepositoryMigrationService,
|
||||
ExternalDatasetMigrationService externalDatasetMigrationService,
|
||||
FunderMigrationService funderMigrationService,
|
||||
|
@ -37,6 +48,8 @@ public class MigrationController {
|
|||
OrganizationMigrationService organizationMigrationService
|
||||
) {
|
||||
this.dmpMigrationService = dmpMigrationService;
|
||||
this.datasetMigrationService = datasetMigrationService;
|
||||
this.dmpDatasetProfileMigrationService = dmpDatasetProfileMigrationService;
|
||||
this.dataRepositoryMigrationService = dataRepositoryMigrationService;
|
||||
this.externalDatasetMigrationService = externalDatasetMigrationService;
|
||||
this.funderMigrationService = funderMigrationService;
|
||||
|
@ -48,19 +61,28 @@ public class MigrationController {
|
|||
this.organizationMigrationService = organizationMigrationService;
|
||||
}
|
||||
|
||||
@GetMapping("dmps/migrate")
|
||||
@GetMapping("dmps")
|
||||
@Transactional
|
||||
public String migrateDmps() throws JsonProcessingException {
|
||||
return this.dmpMigrationService.migrate();
|
||||
}
|
||||
|
||||
@GetMapping("organizations")
|
||||
@Transactional
|
||||
public boolean migrateOrganizations() {
|
||||
this.organizationMigrationService.migrate();
|
||||
public boolean migrateDmps() throws JsonProcessingException {
|
||||
this.dmpMigrationService.migrate();
|
||||
return true;
|
||||
}
|
||||
|
||||
@GetMapping("datasets/migrate")
|
||||
@Transactional
|
||||
public String migrateDatasets() throws JsonProcessingException {
|
||||
return this.datasetMigrationService.migrate();
|
||||
}
|
||||
|
||||
@GetMapping("dmp-dataset-profiles")
|
||||
@Transactional
|
||||
public boolean migrateDmpDatasetProfiles() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException {
|
||||
this.dmpDatasetProfileMigrationService.migrate();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("references")
|
||||
@Transactional
|
||||
public boolean migrateReferences() {
|
||||
|
@ -76,6 +98,14 @@ public class MigrationController {
|
|||
return true;
|
||||
}
|
||||
|
||||
@GetMapping("organizations")
|
||||
@Transactional
|
||||
public boolean migrateOrganizations() {
|
||||
this.organizationMigrationService.migrate();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("dataRepositories")
|
||||
@Transactional
|
||||
public boolean migrateDataRepositories() {
|
||||
|
|
Loading…
Reference in New Issue