Added Host and License RDA imports & (not functional yet) dataset indexing
This commit is contained in:
parent
665a12f2cb
commit
9de0989976
|
@ -1356,7 +1356,25 @@ public class DataManagementPlanManager {
|
||||||
dataset.setCreated(new Date());
|
dataset.setCreated(new Date());
|
||||||
dataset.setModified(new Date());
|
dataset.setModified(new Date());
|
||||||
dataset.setDmp(dmp);
|
dataset.setDmp(dmp);
|
||||||
databaseRepository.getDatasetDao().createOrUpdate(dataset);
|
dataset = databaseRepository.getDatasetDao().createOrUpdate(dataset);
|
||||||
|
dataset.setRegistries(new HashSet<>());
|
||||||
|
dataset.setDatasetDataRepositories(new HashSet<>());
|
||||||
|
dataset.setDatasetExternalDatasets(new HashSet<>());
|
||||||
|
dataset.setServices(new HashSet<>());
|
||||||
|
if (dmp.getOrganisations() == null) {
|
||||||
|
dmp.setOrganisations(new HashSet<>());
|
||||||
|
}
|
||||||
|
if (dmp.getResearchers() == null) {
|
||||||
|
dmp.setResearchers(new HashSet<>());
|
||||||
|
}
|
||||||
|
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmp.getId())).toList()));
|
||||||
|
try {
|
||||||
|
DatasetWizardModel model = new DatasetWizardModel().fromDataModel(dataset);
|
||||||
|
model.setDatasetProfileDefinition(datasetManager.getPagedProfile(model, dataset));
|
||||||
|
datasetManager.updateTags(apiContext.getOperationsContext().getDatasetRepository(), model);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
result.add(dmp);
|
result.add(dmp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package eu.eudat.models.rda.mapper;
|
package eu.eudat.models.rda.mapper;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.lowagie.text.ExceptionConverter;
|
|
||||||
import eu.eudat.logic.utilities.helpers.MyStringUtils;
|
import eu.eudat.logic.utilities.helpers.MyStringUtils;
|
||||||
import eu.eudat.models.rda.Distribution;
|
import eu.eudat.models.rda.Distribution;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -110,6 +109,12 @@ public class DistributionRDAMapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
if (rda.getHost() != null) {
|
||||||
|
properties.putAll(HostRDAMapper.toProperties(rda.getHost()));
|
||||||
|
}
|
||||||
|
if (rda.getLicense() != null && !rda.getLicense().isEmpty()) {
|
||||||
|
properties.putAll(LicenseRDAMapper.toProperties(rda.getLicense()));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
|
|
|
@ -4,12 +4,17 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import eu.eudat.logic.utilities.helpers.MyStringUtils;
|
import eu.eudat.logic.utilities.helpers.MyStringUtils;
|
||||||
import eu.eudat.models.rda.Host;
|
import eu.eudat.models.rda.Host;
|
||||||
import eu.eudat.models.rda.PidSystem;
|
import eu.eudat.models.rda.PidSystem;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class HostRDAMapper {
|
public class HostRDAMapper {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(HostRDAMapper.class);
|
||||||
|
|
||||||
public static Host toRDA(List<JsonNode> nodes, String numbering) {
|
public static Host toRDA(List<JsonNode> nodes, String numbering) {
|
||||||
Host rda = new Host();
|
Host rda = new Host();
|
||||||
|
@ -19,41 +24,51 @@ public class HostRDAMapper {
|
||||||
int firstDiff = MyStringUtils.getFirstDifference(numbering, node.get("numbering").asText());
|
int firstDiff = MyStringUtils.getFirstDifference(numbering, node.get("numbering").asText());
|
||||||
if (firstDiff == -1 || firstDiff > 2) {
|
if (firstDiff == -1 || firstDiff > 2) {
|
||||||
String rdaValue = node.get("value").asText();
|
String rdaValue = node.get("value").asText();
|
||||||
for (PropertyName propertyName: PropertyName.values()) {
|
for (ExportPropertyName propertyName: ExportPropertyName.values()) {
|
||||||
if (rdaProperty.contains(propertyName.getName())) {
|
if (rdaProperty.contains(propertyName.getName())) {
|
||||||
switch (propertyName) {
|
switch (propertyName) {
|
||||||
case AVAILABILITY:
|
case AVAILABILITY:
|
||||||
rda.setAvailability(rdaValue);
|
rda.setAvailability(rdaValue);
|
||||||
|
rda.setAdditionalProperty(ImportPropertyName.AVAILABILITY.getName(), node.get("id").asText());
|
||||||
break;
|
break;
|
||||||
case BACKUP_FREQUENCY:
|
case BACKUP_FREQUENCY:
|
||||||
rda.setBackupFrequency(rdaValue);
|
rda.setBackupFrequency(rdaValue);
|
||||||
|
rda.setAdditionalProperty(ImportPropertyName.BACKUP_FREQUENCY.getName(), node.get("id").asText());
|
||||||
break;
|
break;
|
||||||
case BACKUP_TYPE:
|
case BACKUP_TYPE:
|
||||||
rda.setBackupType(rdaValue);
|
rda.setBackupType(rdaValue);
|
||||||
break;
|
break;
|
||||||
case CERTIFIED_WITH:
|
case CERTIFIED_WITH:
|
||||||
rda.setCertifiedWith(Host.CertifiedWith.fromValue(rdaValue));
|
rda.setCertifiedWith(Host.CertifiedWith.fromValue(rdaValue));
|
||||||
|
rda.setAdditionalProperty(ImportPropertyName.CERTIFIED_WITH.getName(), node.get("id").asText());
|
||||||
break;
|
break;
|
||||||
case DESCRIPTION:
|
case DESCRIPTION:
|
||||||
rda.setDescription(rdaValue);
|
rda.setDescription(rdaValue);
|
||||||
|
rda.setAdditionalProperty(ImportPropertyName.DESCRIPTION.getName(), node.get("id").asText());
|
||||||
break;
|
break;
|
||||||
case GEO_LOCATION:
|
case GEO_LOCATION:
|
||||||
rda.setGeoLocation(Host.GeoLocation.fromValue(rdaValue));
|
rda.setGeoLocation(Host.GeoLocation.fromValue(rdaValue));
|
||||||
|
rda.setAdditionalProperty(ImportPropertyName.GEO_LOCATION.getName(), node.get("id").asText());
|
||||||
break;
|
break;
|
||||||
case PID_SYSTEM:
|
case PID_SYSTEM:
|
||||||
rda.setPidSystem(Collections.singletonList(PidSystem.fromValue(rdaValue)));
|
rda.setPidSystem(Collections.singletonList(PidSystem.fromValue(rdaValue)));
|
||||||
|
rda.setAdditionalProperty(ImportPropertyName.PID_SYSTEM.getName(), node.get("id").asText());
|
||||||
break;
|
break;
|
||||||
case STORAGE_TYPE:
|
case STORAGE_TYPE:
|
||||||
rda.setStorageType(rdaValue);
|
rda.setStorageType(rdaValue);
|
||||||
|
rda.setAdditionalProperty(ImportPropertyName.STORAGE_TYPE.getName(), node.get("id").asText());
|
||||||
break;
|
break;
|
||||||
case SUPPORT_VERSIONING:
|
case SUPPORT_VERSIONING:
|
||||||
rda.setSupportVersioning(Host.SupportVersioning.fromValue(rdaValue));
|
rda.setSupportVersioning(Host.SupportVersioning.fromValue(rdaValue));
|
||||||
|
rda.setAdditionalProperty(ImportPropertyName.SUPPORT_VERSIONING.getName(), node.get("id").asText());
|
||||||
break;
|
break;
|
||||||
case TITLE:
|
case TITLE:
|
||||||
rda.setTitle(rdaValue);
|
rda.setTitle(rdaValue);
|
||||||
|
rda.setAdditionalProperty(ImportPropertyName.TITLE.getName(), node.get("id").asText());
|
||||||
break;
|
break;
|
||||||
case URL:
|
case URL:
|
||||||
rda.setUrl(URI.create(rdaValue));
|
rda.setUrl(URI.create(rdaValue));
|
||||||
|
rda.setAdditionalProperty(ImportPropertyName.URL.getName(), node.get("id").asText());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +80,56 @@ public class HostRDAMapper {
|
||||||
return rda;
|
return rda;
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum PropertyName {
|
public static Map<String, String> toProperties(Host rda) {
|
||||||
|
Map<String, String> properties = new HashMap<>();
|
||||||
|
rda.getAdditionalProperties().entrySet().forEach(entry -> {
|
||||||
|
try {
|
||||||
|
ImportPropertyName importPropertyName = ImportPropertyName.fromString(entry.getKey());
|
||||||
|
switch (importPropertyName) {
|
||||||
|
case AVAILABILITY:
|
||||||
|
properties.put(entry.getValue().toString(), rda.getAvailability());
|
||||||
|
break;
|
||||||
|
case TITLE:
|
||||||
|
properties.put(entry.getValue().toString(), rda.getTitle());
|
||||||
|
break;
|
||||||
|
case DESCRIPTION:
|
||||||
|
properties.put(entry.getValue().toString(), rda.getDescription());
|
||||||
|
break;
|
||||||
|
case BACKUP_FREQUENCY:
|
||||||
|
properties.put(entry.getValue().toString(), rda.getBackupFrequency());
|
||||||
|
break;
|
||||||
|
case BACKUP_TYPE:
|
||||||
|
properties.put(entry.getValue().toString(), rda.getBackupType());
|
||||||
|
break;
|
||||||
|
case CERTIFIED_WITH:
|
||||||
|
properties.put(entry.getValue().toString(), rda.getCertifiedWith().value());
|
||||||
|
break;
|
||||||
|
case GEO_LOCATION:
|
||||||
|
properties.put(entry.getValue().toString(), rda.getGeoLocation().value());
|
||||||
|
break;
|
||||||
|
case PID_SYSTEM:
|
||||||
|
properties.put(entry.getValue().toString(), rda.getPidSystem().get(0).value());
|
||||||
|
break;
|
||||||
|
case STORAGE_TYPE:
|
||||||
|
properties.put(entry.getValue().toString(), rda.getStorageType());
|
||||||
|
break;
|
||||||
|
case SUPPORT_VERSIONING:
|
||||||
|
properties.put(entry.getValue().toString(), rda.getSupportVersioning().value());
|
||||||
|
break;
|
||||||
|
case URL:
|
||||||
|
properties.put(entry.getValue().toString(), rda.getUrl().toString());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum ExportPropertyName {
|
||||||
AVAILABILITY("availability"),
|
AVAILABILITY("availability"),
|
||||||
BACKUP_FREQUENCY("backup_frequency"),
|
BACKUP_FREQUENCY("backup_frequency"),
|
||||||
BACKUP_TYPE("backup_type"),
|
BACKUP_TYPE("backup_type"),
|
||||||
|
@ -80,7 +144,7 @@ public class HostRDAMapper {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
PropertyName(String name) {
|
ExportPropertyName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,4 +152,37 @@ public class HostRDAMapper {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum ImportPropertyName {
|
||||||
|
AVAILABILITY("availabilityId"),
|
||||||
|
BACKUP_FREQUENCY("backup_frequencyId"),
|
||||||
|
BACKUP_TYPE("backup_typeId"),
|
||||||
|
CERTIFIED_WITH("certified_withId"),
|
||||||
|
DESCRIPTION("descriptionId"),
|
||||||
|
GEO_LOCATION("geo_locationId"),
|
||||||
|
PID_SYSTEM("pid_systemId"),
|
||||||
|
STORAGE_TYPE("storage_typeId"),
|
||||||
|
SUPPORT_VERSIONING("support_versioningId"),
|
||||||
|
TITLE("titleId"),
|
||||||
|
URL("urlId");
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
ImportPropertyName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ImportPropertyName fromString(String name) throws Exception {
|
||||||
|
for (ImportPropertyName importPropertyName: ImportPropertyName.values()) {
|
||||||
|
if (importPropertyName.getName().equals(name)) {
|
||||||
|
return importPropertyName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Exception("No name available");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,9 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import eu.eudat.models.rda.License;
|
import eu.eudat.models.rda.License;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class LicenseRDAMapper {
|
public class LicenseRDAMapper {
|
||||||
|
|
||||||
|
@ -14,10 +17,32 @@ public class LicenseRDAMapper {
|
||||||
|
|
||||||
if (rdaProperty.contains("license_ref")) {
|
if (rdaProperty.contains("license_ref")) {
|
||||||
rda.setLicenseRef(URI.create(value));
|
rda.setLicenseRef(URI.create(value));
|
||||||
|
rda.setAdditionalProperty("license_refId", node.get("id").asText());
|
||||||
} else if (rdaProperty.contains("start_date")) {
|
} else if (rdaProperty.contains("start_date")) {
|
||||||
rda.setStartDate(value);
|
rda.setStartDate(value);
|
||||||
|
rda.setAdditionalProperty("start_dateId", node.get("id").asText());
|
||||||
}
|
}
|
||||||
|
|
||||||
return rda;
|
return rda;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> toProperties(List<License> rdas) {
|
||||||
|
Map<String, String> properties = new HashMap<>();
|
||||||
|
|
||||||
|
rdas.forEach(rda -> {
|
||||||
|
rda.getAdditionalProperties().entrySet().forEach(entry -> {
|
||||||
|
switch (entry.getKey()) {
|
||||||
|
case "license_refId":
|
||||||
|
properties.put(entry.getValue().toString(), rda.getLicenseRef().toString());
|
||||||
|
break;
|
||||||
|
case "start_dateId":
|
||||||
|
properties.put(entry.getValue().toString(), rda.getStartDate());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue