Adding definitions info on migrated licenses
This commit is contained in:
parent
f9a47f2de7
commit
aa648cda1d
|
@ -6,10 +6,14 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import com.fasterxml.jackson.databind.type.MapType;
|
||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||
import eu.eudat.commons.JsonHandlingService;
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.commons.enums.*;
|
||||
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.reference.DefinitionEntity;
|
||||
import eu.eudat.commons.types.reference.FieldEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DmpEntity;
|
||||
import eu.eudat.data.DmpReferenceEntity;
|
||||
import eu.eudat.data.ReferenceEntity;
|
||||
|
@ -23,6 +27,7 @@ import gr.cite.tools.exception.MyApplicationException;
|
|||
import gr.cite.tools.logging.LoggerService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
@ -34,20 +39,22 @@ 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 final QueryFactory queryFactory;
|
||||
private final ConventionService conventionService;
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
private final Environment environment;
|
||||
|
||||
private static final int PageSize = 500;
|
||||
private static final boolean TestMode = false;
|
||||
|
||||
public DmpMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager, QueryFactory queryFactory) {
|
||||
public DmpMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService, Environment environment) {
|
||||
this.databaseRepository = databaseRepository;
|
||||
this.jsonHandlingService = jsonHandlingService;
|
||||
this.entityManager = entityManager;
|
||||
this.queryFactory = queryFactory;
|
||||
this.conventionService = conventionService;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
public void migrate() throws JsonProcessingException, NoSuchFieldException, IllegalAccessException {
|
||||
|
@ -179,7 +186,7 @@ public class DmpMigrationService {
|
|||
if (model.getExtraProperties() != null) {
|
||||
if (model.getExtraProperties().containsKey("license") && model.getExtraProperties().get("license") != null) {
|
||||
Object license = model.getExtraProperties().get("license");
|
||||
HashMap<String, String> licenseMap = jsonHandlingService.mapFromJson(jsonHandlingService.toJson(license));
|
||||
HashMap<String, String> licenseMap = this.jsonHandlingService.mapFromJson(this.jsonHandlingService.toJson(license));
|
||||
ReferenceEntity referenceEntity = new ReferenceEntity();
|
||||
String licensePid;
|
||||
if (licenseMap.containsKey("pid") && licenseMap.get("pid") != null) {
|
||||
|
@ -190,35 +197,59 @@ public class DmpMigrationService {
|
|||
continue;
|
||||
boolean licenseExists = collectedLicenses.contains(licensePid);
|
||||
if (!licenseExists) {
|
||||
DefinitionEntity definitionEntity = new DefinitionEntity();
|
||||
List<FieldEntity> fields = new ArrayList<>();
|
||||
if (licenseMap.containsKey("name")) {
|
||||
referenceEntity.setLabel(licenseMap.get("name"));
|
||||
}
|
||||
if (licenseMap.containsKey("uri")) {
|
||||
referenceEntity.setSource(licenseMap.get("uri"));
|
||||
referenceEntity.setReference(licenseMap.get("uri"));
|
||||
if (!this.conventionService.isNullOrEmpty(licenseMap.get("uri"))){
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("uri");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Text);
|
||||
fieldEntity.setValue(licenseMap.get("uri"));
|
||||
fields.add(fieldEntity);
|
||||
}
|
||||
}
|
||||
if (licenseMap.containsKey("tag")) {
|
||||
if (!this.conventionService.isNullOrEmpty(licenseMap.get("tag"))){
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("tag");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Text);
|
||||
fieldEntity.setValue(licenseMap.get("tag"));
|
||||
fields.add(fieldEntity);
|
||||
}
|
||||
}
|
||||
if (licenseMap.containsKey("hint")) {
|
||||
if (!this.conventionService.isNullOrEmpty(licenseMap.get("hint"))){
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("hint");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Text);
|
||||
fieldEntity.setValue(licenseMap.get("hint"));
|
||||
fields.add(fieldEntity);
|
||||
}
|
||||
}
|
||||
if (licenseMap.containsKey("abbreviation")) {
|
||||
referenceEntity.setAbbreviation(licenseMap.get("abbreviation"));
|
||||
}
|
||||
if (licenseMap.containsKey("source") && licenseMap.get("source") != null) {
|
||||
logger.debug("License found with source '{}'", licenseMap.get("source"));
|
||||
}
|
||||
if (licenseMap.containsKey("created") && licenseMap.get("created") != null) {
|
||||
referenceEntity.setUpdatedAt(Instant.parse(licenseMap.get("created")));
|
||||
} else {
|
||||
referenceEntity.setCreatedAt(Instant.now());
|
||||
referenceEntity.setCreatedAt(item.getCreated() == null ? Instant.now() : item.getCreated().toInstant());
|
||||
}
|
||||
if (licenseMap.containsKey("modified") && licenseMap.get("modified") != null) {
|
||||
referenceEntity.setUpdatedAt(Instant.parse(licenseMap.get("modified")));
|
||||
} else {
|
||||
referenceEntity.setUpdatedAt(Instant.now());
|
||||
referenceEntity.setUpdatedAt(item.getModified() == null ? Instant.now() : item.getModified().toInstant());
|
||||
}
|
||||
// if (licenseMap.containsKey("tag") && licenseMap.get("tag") != null && !"Open Definition".equals(licenseMap.get("tag"))) {
|
||||
// logger.debug("License found with tag '{}'", licenseMap.get("tag"));
|
||||
// }
|
||||
referenceEntity.setId(UUID.randomUUID());
|
||||
referenceEntity.setSourceType(ReferenceSourceType.External);
|
||||
referenceEntity.setSource(this.environment.getProperty("migration.default-license-source", "null"));
|
||||
referenceEntity.setType(ReferenceType.Licenses);
|
||||
referenceEntity.setIsActive(IsActive.Active);
|
||||
definitionEntity.setFields(fields);
|
||||
referenceEntity.setDefinition(this.xmlHandlingService.toXmlSafe(definitionEntity));
|
||||
|
||||
collectedLicenses.add(licensePid);
|
||||
licenseIdByName.put(licensePid, referenceEntity.getId());
|
||||
|
|
|
@ -4,6 +4,7 @@ server.tomcat.max-connections = 10000
|
|||
logging.file=/logs/spring-boot-logging.log
|
||||
spring.profiles.active=devel
|
||||
eu.eudat.logic.proxy.allowed.host=https://eestore.paas2.uninett.no
|
||||
migration.default-license-source=opendefinition
|
||||
|
||||
####################Metrics##############
|
||||
management.endpoint.metrics.enabled=true
|
||||
|
|
Loading…
Reference in New Issue