fixes
This commit is contained in:
parent
f88d5ed456
commit
eaeaf890dc
|
@ -39,7 +39,8 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.time.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -179,7 +180,7 @@ public class RdaFileTransformerService implements FileTransformerClient {
|
|||
rda.setModified(plan.getUpdatedAt());
|
||||
rda.setTitle(plan.getLabel());
|
||||
rda.setLanguage(this.buildRdaLanguage(plan.getLanguage() != null ? plan.getLanguage() : "en"));
|
||||
rda.setContributor(buildRdaContributors(researchers));
|
||||
rda.setContributor(buildRdaContributors(researchers, plan.getUsers()));
|
||||
rda.setContact(buildRdaContact(plan));
|
||||
rda.setEthicalIssuesExist(buildRdaEthicalIssuesExist(plan));
|
||||
rda.setEthicalIssuesDescription(buildRdaEthicalIssuesDescription(plan));
|
||||
|
@ -334,62 +335,63 @@ public class RdaFileTransformerService implements FileTransformerClient {
|
|||
if (creator == null) throw new MyApplicationException("Creator Name is missing");
|
||||
if (creator.getName() == null) throw new MyApplicationException("Contact Name is missing");
|
||||
UserContactInfoModel emailContact = creator.getContacts() != null ? creator.getContacts().stream().filter(userContactInfo -> userContactInfo.getType().equals(ContactInfoType.Email)).findFirst().orElse(null) : null;
|
||||
if (emailContact == null) throw new MyApplicationException("Contact Email is missing");
|
||||
|
||||
Contact rdaModel = new Contact();
|
||||
rdaModel.setName(creator.getName());
|
||||
|
||||
rdaModel.setMbox(emailContact.getValue());
|
||||
ContactId rdaContactId = new ContactId();
|
||||
rdaContactId.setIdentifier(emailContact.getId().toString());
|
||||
rdaContactId.setType(ContactId.Type.OTHER);
|
||||
rdaModel.setContactId(rdaContactId);
|
||||
if (emailContact != null) {
|
||||
rdaModel.setMbox(emailContact.getValue());
|
||||
if (emailContact.getId() != null) {
|
||||
ContactId rdaContactId = new ContactId();
|
||||
rdaContactId.setIdentifier(emailContact.getId().toString());
|
||||
rdaContactId.setType(ContactId.Type.OTHER);
|
||||
rdaModel.setContactId(rdaContactId);
|
||||
}
|
||||
}
|
||||
|
||||
return rdaModel;
|
||||
}
|
||||
|
||||
public List<Contributor> buildRdaContributorsByUsers(List<PlanUserModel> models) {
|
||||
|
||||
public List<Contributor> buildRdaContributors(List<ReferenceModel> referenceModels, List<PlanUserModel> userModels) {
|
||||
List<Contributor> rdaModels = new ArrayList<>();
|
||||
if (models == null) return rdaModels;
|
||||
for (PlanUserModel planUser : models){
|
||||
rdaModels.add(this.buildRdaContributorsByUser(planUser));
|
||||
}
|
||||
return rdaModels;
|
||||
}
|
||||
|
||||
public Contributor buildRdaContributorsByUser(PlanUserModel model) {
|
||||
if (model == null) throw new MyApplicationException("User is missing");
|
||||
if (model.getUser() == null) throw new MyApplicationException("User is missing");
|
||||
if (model.getUser().getName() == null) throw new MyApplicationException("Contributor Name is missing");
|
||||
|
||||
Contributor rdaModel = new Contributor();
|
||||
rdaModel.setContributorId(buildRdaContributorId(model.getUser().getId().toString()));
|
||||
|
||||
rdaModel.setName(model.getUser().getName());
|
||||
UserContactInfoModel emailContact = model.getUser().getContacts() == null ? null : model.getUser().getContacts().stream().filter(userContactInfo -> userContactInfo.getType().equals(ContactInfoType.Email)).findFirst().orElse(null);
|
||||
if (emailContact != null) {
|
||||
rdaModel.setMbox(emailContact.getValue());
|
||||
}
|
||||
rdaModel.setRole(new HashSet<>(List.of(model.getRole().name())));
|
||||
return rdaModel;
|
||||
}
|
||||
|
||||
public List<Contributor> buildRdaContributors(List<ReferenceModel> models) {
|
||||
List<Contributor> rdaModels = new ArrayList<>();
|
||||
if (models == null) return rdaModels;
|
||||
for (ReferenceModel researcher : models){
|
||||
for (ReferenceModel researcher : referenceModels){
|
||||
Contributor item = this.buildRdaContributor(researcher);
|
||||
if (item != null) rdaModels.add(item);
|
||||
}
|
||||
if (userModels != null && !userModels.isEmpty()) {
|
||||
if (userModels.stream().anyMatch(x -> x.getUser() == null || x.getUser().getId() == null|| x.getUser().getName() == null || x.getUser().getName().isEmpty())) throw new MyApplicationException("User is missing");
|
||||
Map<UUID, List<PlanUserModel>> userModelsGrouped = userModels.stream().collect(Collectors.groupingBy(x -> x.getUser().getId()));
|
||||
if (userModelsGrouped != null) {
|
||||
for (UUID userId: userModelsGrouped.keySet()) {
|
||||
rdaModels.add(this.buildRdaContributorsByUser(userModelsGrouped.get(userId)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rdaModels;
|
||||
}
|
||||
|
||||
public Contributor buildRdaContributorsByUser(List<PlanUserModel> useModelGroupByRoles) {
|
||||
Contributor rdaModel = new Contributor();
|
||||
rdaModel.setContributorId(buildRdaContributorId(useModelGroupByRoles.getFirst().getUser().getId().toString()));
|
||||
|
||||
rdaModel.setName(useModelGroupByRoles.getFirst().getUser().getName());
|
||||
UserContactInfoModel emailContact = useModelGroupByRoles.getFirst().getUser().getContacts() == null ? null : useModelGroupByRoles.getFirst().getUser().getContacts().stream().filter(userContactInfo -> userContactInfo.getType().equals(ContactInfoType.Email)).findFirst().orElse(null);
|
||||
if (emailContact != null) {
|
||||
rdaModel.setMbox(emailContact.getValue());
|
||||
}
|
||||
rdaModel.setRole(new HashSet<>(useModelGroupByRoles.stream().map(x -> x.getRole().name()).collect(Collectors.toList())));
|
||||
return rdaModel;
|
||||
}
|
||||
|
||||
public Contributor buildRdaContributor(ReferenceModel model) {
|
||||
if (model == null) throw new MyApplicationException("Contributor is missing");
|
||||
|
||||
Contributor rdaModel = new Contributor();
|
||||
rdaModel.setContributorId(buildRdaContributorId(model.getReference()));
|
||||
rdaModel.setName(model.getLabel());
|
||||
rdaModel.setRole(new HashSet<>(List.of(model.getType().getName())));
|
||||
if (model.getDefinition() != null && model.getDefinition().getFields() != null) {
|
||||
model.getDefinition().getFields().stream().filter(field -> this.configuration.getRdaFileTransformerServiceProperties().getResearcherMalCode().equalsIgnoreCase(field.getCode())).findFirst().ifPresent(emailField -> rdaModel.setMbox(emailField.getValue()));
|
||||
}
|
||||
|
@ -694,8 +696,8 @@ public class RdaFileTransformerService implements FileTransformerClient {
|
|||
|
||||
fieldValue = this.findValueFieldBySemantic(fieldSet, propertyDefinitionFieldSetItemModel, SEMANTIC_DATASET_DISTRIBUTION_AVAILABLE_UTIL);
|
||||
if (fieldValue != null && fieldValue.getDateValue() != null) {
|
||||
// item.setAvailableUntil(DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneId.systemDefault()).format(fieldValue.getDateValue()));
|
||||
item.setAvailableUntil(fieldValue.getDateValue().toString());
|
||||
LocalDateTime ldt = LocalDateTime.ofInstant(fieldValue.getDateValue(), ZoneOffset.UTC);
|
||||
item.setAvailableUntil(ldt.format(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||
valueFound = true;
|
||||
} else if (fieldValue != null && fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
|
||||
item.setAvailableUntil(fieldValue.getTextValue());
|
||||
|
@ -755,7 +757,8 @@ public class RdaFileTransformerService implements FileTransformerClient {
|
|||
|
||||
fieldValue = this.findValueFieldBySemantic(fieldSet, propertyDefinitionFieldSetItemModel, SEMANTIC_DATASET_DISTRIBUTION_LICENCE_START_DATE);
|
||||
if (fieldValue != null && fieldValue.getDateValue() != null) {
|
||||
license.setStartDate(fieldValue.getDateValue().toString());
|
||||
LocalDateTime ldt = LocalDateTime.ofInstant(fieldValue.getDateValue(), ZoneOffset.UTC);
|
||||
license.setStartDate(ldt.format(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||
} else if (fieldValue != null && fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
|
||||
license.setStartDate(fieldValue.getTextValue());
|
||||
}
|
||||
|
@ -922,6 +925,15 @@ public class RdaFileTransformerService implements FileTransformerClient {
|
|||
datasetId.setIdentifier(fieldValue.getTextValue() );
|
||||
return datasetId;
|
||||
}
|
||||
if (fieldValue.getExternalIdentifier() != null) {
|
||||
datasetId.setIdentifier(fieldValue.getExternalIdentifier().getIdentifier());
|
||||
try {
|
||||
datasetId.setType(DatasetId.Type.fromValue(fieldValue.getExternalIdentifier().getType()));
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
return datasetId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1192,8 +1204,8 @@ public class RdaFileTransformerService implements FileTransformerClient {
|
|||
List<org.opencdmp.commonmodels.models.description.FieldModel> fieldValues = this.findValueField(field, model.getProperties());
|
||||
for (org.opencdmp.commonmodels.models.description.FieldModel fieldValue : fieldValues) {
|
||||
if (fieldValue.getDateValue() != null){
|
||||
// return DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneId.systemDefault()).format(fieldValue.getDateValue());
|
||||
return fieldValue.getDateValue().toString();
|
||||
LocalDateTime ldt = LocalDateTime.ofInstant(fieldValue.getDateValue(), ZoneOffset.UTC);
|
||||
return ldt.format(DateTimeFormatter.ISO_LOCAL_DATE);
|
||||
} else if (fieldValue.getTextValue() != null && !fieldValue.getTextValue().isBlank()) {
|
||||
return fieldValue.getTextValue();
|
||||
}
|
||||
|
@ -1702,7 +1714,8 @@ public class RdaFileTransformerService implements FileTransformerClient {
|
|||
fieldModel.setTextValue(dataset.getDatasetId().getIdentifier());
|
||||
ExternalIdentifierModel externalIdentifierModel = new ExternalIdentifierModel();
|
||||
externalIdentifierModel.setIdentifier(dataset.getDatasetId().getIdentifier());
|
||||
externalIdentifierModel.setType(dataset.getDatasetId().getIdentifier());
|
||||
externalIdentifierModel.setType(dataset.getDatasetId().getType().toString());
|
||||
fieldModel.setExternalIdentifier(externalIdentifierModel);
|
||||
valueFound = true;
|
||||
}
|
||||
if (dataset.getDatasetId() != null && templateFieldModel.getSemantics().contains(SEMANTIC_DATASET_DATASET_ID_ID)){
|
||||
|
@ -1732,7 +1745,7 @@ public class RdaFileTransformerService implements FileTransformerClient {
|
|||
if (dataset.getIssued() != null && templateFieldModel.getSemantics().contains(SEMANTIC_DATASET_ISSUED)){
|
||||
fieldModel.setTextValue(dataset.getIssued());
|
||||
try {
|
||||
fieldModel.setDateValue(Instant.parse(dataset.getIssued()));
|
||||
fieldModel.setDateValue(LocalDate.parse(dataset.getIssued(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
@ -2128,7 +2141,7 @@ public class RdaFileTransformerService implements FileTransformerClient {
|
|||
if (distribution.getAvailableUntil() != null && templateFieldModel.getSemantics().contains(SEMANTIC_DATASET_DISTRIBUTION_AVAILABLE_UTIL)){
|
||||
fieldModel.setTextValue(distribution.getAvailableUntil());
|
||||
try {
|
||||
fieldModel.setDateValue(Instant.parse(distribution.getAvailableUntil()));
|
||||
fieldModel.setDateValue(LocalDate.parse(distribution.getAvailableUntil(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
@ -2208,7 +2221,7 @@ public class RdaFileTransformerService implements FileTransformerClient {
|
|||
if (license.getStartDate() != null && templateFieldModel.getSemantics().contains(SEMANTIC_DATASET_DISTRIBUTION_LICENCE_START_DATE)) {
|
||||
fieldModel.setTextValue(license.getStartDate());
|
||||
try {
|
||||
fieldModel.setDateValue(Instant.parse(license.getStartDate()));
|
||||
fieldModel.setDateValue(LocalDate.parse(license.getStartDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue