Updated RDA Mapper's Cardinality check

This commit is contained in:
George Kalampokis 2020-11-13 18:26:09 +02:00
parent 0ad797d033
commit cbbfec2ccc
11 changed files with 86 additions and 9 deletions

View File

@ -8,7 +8,13 @@ public class ContactRDAMapper {
public static Contact toRDA(UserInfo creator) {
Contact rda = new Contact();
if (creator.getName() == null) {
throw new IllegalArgumentException("Contact Name is missing");
}
rda.setName(creator.getName());
if (creator.getEmail() == null) {
throw new IllegalArgumentException("Contact Email is missing");
}
rda.setMbox(creator.getEmail());
rda.setContactId(ContactIdRDAMapper.toRDA(creator.getId()));
return rda;

View File

@ -17,6 +17,9 @@ public class ContributorRDAMapper {
public static Contributor toRDA(UserDMP userDMP) {
Contributor rda = new Contributor();
rda.setContributorId(ContributorIdRDAMapper.toRDA(userDMP.getUser().getId()));
if (userDMP.getUser().getName() == null) {
throw new IllegalArgumentException("Contributor Name is missing");
}
rda.setName(userDMP.getUser().getName());
rda.setMbox(userDMP.getUser().getEmail());
rda.setRole(new HashSet<>(Arrays.asList(UserDMP.UserDMPRoles.fromInteger(userDMP.getRole()).name())));

View File

@ -0,0 +1,22 @@
package eu.eudat.models.rda.mapper;
import java.util.Map;
import eu.eudat.models.rda.Cost;
public class CostRDAMapper {
public static Cost toRDA(Map<String, Object> cost) {
Cost rda = new Cost();
Map<String, Object> code = new org.json.JSONObject((String) cost.get("code")).toMap();
rda.setCurrencyCode(Cost.CurrencyCode.fromValue((String) code.get("value")));
rda.setDescription((String) cost.get("description"));
if (cost.get("title") == null) {
throw new IllegalArgumentException("Cost Title is missing");
}
rda.setTitle((String) cost.get("title"));
rda.setValue(((Integer) cost.get("value")).doubleValue());
return rda;
}
}

View File

@ -42,6 +42,9 @@ public class DatasetRDAMapper {
public Dataset toRDA(eu.eudat.data.entities.Dataset dataset, List<Contributor> contributors) {
Dataset rda = new Dataset();
// rda.setDatasetId(DatasetIdRDAMapper.toRDA(dataset.getId()));
if (dataset.getLabel() == null) {
throw new IllegalArgumentException("Dataaset Label is missing");
}
rda.setTitle(dataset.getLabel());
rda.setDescription(dataset.getDescription());
rda.setAdditionalProperty("template", dataset.getProfile().getId());

View File

@ -246,7 +246,14 @@ public class DistributionRDAMapper {
}*/
}
if (rda.getTitle() == null) {
throw new IllegalArgumentException("Distribution title is missing");
}
if (rda.getDataAccess() == null) {
throw new IllegalArgumentException("Distribution Data Access is missing");
}
return rda;
}

View File

@ -31,6 +31,9 @@ public class DmpRDAMapper {
@Transactional
public Dmp toRDA(DMP dmp) {
if (dmp.getDataset() == null || dmp.getDataset().isEmpty()) {
throw new IllegalArgumentException("DMP has no Datasets");
}
Map<String, Object> extraProperties;
if (dmp.getExtraProperties() == null) {
throw new IllegalArgumentException("DMP is missing required Data for RDA export");
@ -49,6 +52,15 @@ public class DmpRDAMapper {
} else {
rda.setDmpId(DmpIdRDAMapper.toRDA(dmp.getId()));
}
if (dmp.getCreated() == null) {
throw new IllegalArgumentException("DMP Created is missing");
}
if (dmp.getModified() == null) {
throw new IllegalArgumentException("DMP Modified is missing");
}
if (dmp.getLabel() == null) {
throw new IllegalArgumentException("DMP Label is missing");
}
rda.setCreated(dmp.getCreated());
rda.setDescription(dmp.getDescription());
rda.setModified(dmp.getModified());
@ -64,13 +76,7 @@ public class DmpRDAMapper {
if (extraProperties.get("costs") != null) {
rda.setCost(new ArrayList<>());
((List) extraProperties.get("costs")).forEach(costl -> {
Cost cost = new Cost();
Map<String, Object> code = new org.json.JSONObject((String) ((Map) costl).get("code")).toMap();
cost.setCurrencyCode(Cost.CurrencyCode.fromValue((String) code.get("value")));
cost.setDescription((String) ((Map) costl).get("description"));
cost.setTitle((String) ((Map) costl).get("title"));
cost.setValue(((Integer) ((Map) costl).get("value")).doubleValue());
rda.getCost().add(cost);
rda.getCost().add(CostRDAMapper.toRDA((Map)costl));
});
}
UserInfo contact = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(UUID.fromString((String) extraProperties.get("contact")));

View File

@ -76,6 +76,14 @@ public class HostRDAMapper {
}
}
}
if (rda.getTitle() == null) {
throw new IllegalArgumentException("Host Title is missing");
}
if (rda.getUrl() == null) {
throw new IllegalArgumentException("Host Url is missing");
}
return rda;
}

View File

@ -38,6 +38,14 @@ public class LicenseRDAMapper {
rda.setAdditionalProperty("start_dateId", node.get("id").asText());
}*/
}
if (rda.getLicenseRef() == null) {
throw new IllegalArgumentException("Licence Reference is missing");
}
if (rda.getStartDate() == null) {
throw new IllegalArgumentException("License Start Date is missing");
}
return rda;
}

View File

@ -20,6 +20,10 @@ public class ProjectRDAMapper {
rda.setEnd(project.getEnddate().toString());
}
rda.setFunding(Collections.singletonList(FundingRDAMapper.toRDA(grant)));
if (rda.getTitle() == null) {
throw new IllegalArgumentException("Project Title is missing");
}
return rda;
}

View File

@ -69,9 +69,14 @@ public class SecurityAndPrivacyRDAMapper {
if (rdaProperty.contains("description")) {
rda.setDescription(value);
} else if (rdaProperty.contains("title")) {
}
if (rdaProperty.contains("title")) {
rda.setTitle(value);
}
if (rda.getTitle() == null) {
throw new IllegalArgumentException("Security And Privacy Title is missing");
}
return rda;
}

View File

@ -70,9 +70,14 @@ public class TechnicalResourceRDAMapper {
if (rdaProperty.contains("description")) {
rda.setDescription(value);
} else if (rdaProperty.contains("name")) {
}
if (rdaProperty.contains("name")) {
rda.setName(value);
}
if (rda.getName() == null) {
throw new IllegalArgumentException("Technical Resources Name is missing");
}
return rda;
}