Compare commits

...

2 Commits

3 changed files with 117 additions and 106 deletions

View File

@ -8,7 +8,6 @@ import gr.cite.tools.fieldset.FieldSet;
import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.JAXBException;
import org.opencdmp.commonmodels.models.description.DescriptionModel; import org.opencdmp.commonmodels.models.description.DescriptionModel;
import org.opencdmp.commons.types.description.importexport.DescriptionImportExport; import org.opencdmp.commons.types.description.importexport.DescriptionImportExport;
import org.opencdmp.data.DmpDescriptionTemplateEntity;
import org.opencdmp.data.StorageFileEntity; import org.opencdmp.data.StorageFileEntity;
import org.opencdmp.model.DescriptionValidationResult; import org.opencdmp.model.DescriptionValidationResult;
import org.opencdmp.model.StorageFile; import org.opencdmp.model.StorageFile;
@ -55,6 +54,6 @@ public interface DescriptionService {
Description importXml(DescriptionImportExport descriptionXml, UUID dmpId, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException; Description importXml(DescriptionImportExport descriptionXml, UUID dmpId, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
Description importCommonModel(DescriptionModel model, UUID dmpId, List<DmpDescriptionTemplateEntity> dmpDescriptionTemplates, FieldSet fields) throws MyForbiddenException, MyNotFoundException, InvalidApplicationException, IOException, JAXBException, ParserConfigurationException, TransformerException, InstantiationException, IllegalAccessException, SAXException; Description importCommonModel(DescriptionModel model, UUID dmpId, FieldSet fields) throws MyForbiddenException, MyNotFoundException, InvalidApplicationException, IOException, JAXBException, ParserConfigurationException, TransformerException, InstantiationException, IllegalAccessException, SAXException;
} }

View File

@ -1500,13 +1500,11 @@ public class DescriptionServiceImpl implements DescriptionService {
//region Import Common Model //region Import Common Model
@Override @Override
public Description importCommonModel(DescriptionModel model, UUID dmpId, List<DmpDescriptionTemplateEntity> dmpDescriptionTemplates, FieldSet fields) throws MyForbiddenException, MyNotFoundException, InvalidApplicationException, IOException, JAXBException, ParserConfigurationException, TransformerException, InstantiationException, IllegalAccessException, SAXException { public Description importCommonModel(DescriptionModel model, UUID dmpId, FieldSet fields) throws MyForbiddenException, MyNotFoundException, InvalidApplicationException, IOException, JAXBException, ParserConfigurationException, TransformerException, InstantiationException, IllegalAccessException, SAXException {
logger.debug(new MapLogEntry("import description").And("dmpId", dmpId).And("fields", fields)); logger.debug(new MapLogEntry("import description").And("dmpId", dmpId).And("fields", fields));
if (model == null) throw new IllegalArgumentException ("model"); if (model == null) throw new IllegalArgumentException ("model");
if (dmpId == null) throw new IllegalArgumentException ("dmpId"); if (dmpId == null) throw new IllegalArgumentException ("dmpId");
if (this.conventionService.isListNullOrEmpty(dmpDescriptionTemplates)) throw new MyValidationException(this.errors.getImportDescriptionWithoutDmpDescriptionTemplate().getCode(), this.errors.getImportDescriptionWithoutDmpDescriptionTemplate().getMessage());
DescriptionPersist persist = new DescriptionPersist(); DescriptionPersist persist = new DescriptionPersist();
persist.setLabel(model.getLabel()); persist.setLabel(model.getLabel());
persist.setDescription(model.getDescription()); persist.setDescription(model.getDescription());

View File

@ -27,6 +27,7 @@ import org.opencdmp.commonmodels.models.description.DescriptionModel;
import org.opencdmp.commonmodels.models.dmp.DmpBlueprintValueModel; import org.opencdmp.commonmodels.models.dmp.DmpBlueprintValueModel;
import org.opencdmp.commonmodels.models.dmp.DmpContactModel; import org.opencdmp.commonmodels.models.dmp.DmpContactModel;
import org.opencdmp.commonmodels.models.dmp.DmpModel; import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.commonmodels.models.dmp.DmpPropertiesModel;
import org.opencdmp.commonmodels.models.dmpblueprint.ExtraFieldModel; import org.opencdmp.commonmodels.models.dmpblueprint.ExtraFieldModel;
import org.opencdmp.commonmodels.models.dmpblueprint.FieldModel; import org.opencdmp.commonmodels.models.dmpblueprint.FieldModel;
import org.opencdmp.commonmodels.models.dmpblueprint.ReferenceTypeFieldModel; import org.opencdmp.commonmodels.models.dmpblueprint.ReferenceTypeFieldModel;
@ -2070,50 +2071,46 @@ public class DmpServiceImpl implements DmpService {
persist.setLanguage(model.getLanguage()); persist.setLanguage(model.getLanguage());
persist.setUsers(this.commonModelToDmpUsersPersist(model)); persist.setUsers(this.commonModelToDmpUsersPersist(model));
persist.setBlueprint(this.commonModelDmpBlueprintToPersist(model)); persist.setBlueprint(this.commonModelDmpBlueprintToPersist(model));
persist.setDescriptionTemplates(this.commonModelDmpDescriptionTemplatesToPersist(model)); //TODO maybe we should create templates if not exists
persist.setProperties(this.commonModelDmpPropertiesToPersist(model));
persist.setProperties(this.commonDmpPropertiesToPersist(model));
if (!this.conventionService.isListNullOrEmpty(model.getDescriptionTemplates())) {
List<DmpDescriptionTemplatePersist> descriptionTemplates = new ArrayList<>();
for (DmpDescriptionTemplateModel descriptionTemplate : model.getDescriptionTemplates()) {
descriptionTemplates.add(this.commonDmpDescriptionTemplateToPersist(descriptionTemplate));
}
persist.setDescriptionTemplates(descriptionTemplates);
}
this.validatorFactory.validator(DmpPersist.DmpPersistValidator.class).validateForce(persist); this.validatorFactory.validator(DmpPersist.DmpPersistValidator.class).validateForce(persist);
Dmp dmp = this.persist(persist, BaseFieldSet.build(fields, Dmp._id, Dmp._hash)); Dmp dmp = this.persist(persist, BaseFieldSet.build(fields, Dmp._id, Dmp._hash));
if (dmp == null) throw new MyApplicationException("Error creating dmp"); if (dmp == null) throw new MyApplicationException("Error creating dmp");
if (!this.conventionService.isListNullOrEmpty(model.getDescriptions())) { if (!this.conventionService.isListNullOrEmpty(model.getDescriptions())){
List<DmpDescriptionTemplateEntity> dmpDescriptionTemplates = this.queryFactory.query(DmpDescriptionTemplateQuery.class).disableTracking()
.isActive(IsActive.Active)
.dmpIds(dmp.getId())
.collect();
for (DescriptionModel description: model.getDescriptions()){ for (DescriptionModel description: model.getDescriptions()){
this.descriptionService.importCommonModel(description, dmp.getId(), dmpDescriptionTemplates, fields != null ? fields.extractPrefixed(this.conventionService.asPrefix(Dmp._description)) : null); this.descriptionService.importCommonModel(description, dmp.getId(), fields != null ? fields.extractPrefixed(this.conventionService.asPrefix(Dmp._description)) : null);
} }
} }
return dmp; return dmp;
} }
private List<DmpUserPersist> commonModelToDmpUsersPersist(DmpModel model){ private List<DmpDescriptionTemplatePersist> commonModelDmpDescriptionTemplatesToPersist(DmpModel commonModel){
if (!this.conventionService.isListNullOrEmpty(model.getUsers())) { if (!this.conventionService.isListNullOrEmpty(commonModel.getDescriptionTemplates())) {
List<UserEntity> users = this.queryFactory.query(UserQuery.class).disableTracking().ids(model.getUsers().stream().map(DmpUserModel::getUser).toList().stream().map(UserModel::getId).filter(Objects::nonNull).distinct().toList()).isActive(IsActive.Active).collect(); List<DmpDescriptionTemplatePersist> descriptionTemplates = new ArrayList<>();
List<UUID> userIds = users == null ? new ArrayList<>() : users.stream().map(UserEntity::getId).collect(Collectors.toList()); for (DmpDescriptionTemplateModel descriptionTemplate : commonModel.getDescriptionTemplates()) {
descriptionTemplates.add(this.commonModelDmpDescriptionTemplateToPersist(descriptionTemplate));
List<DmpUserPersist> dmpUsers = new ArrayList<>();
for (DmpUserModel user : model.getUsers()) {
dmpUsers.add(this.commonDmpUserToPersist(user, userIds));
} }
return dmpUsers; return descriptionTemplates.stream().filter(Objects::nonNull).toList();
} }
return null; return null;
} }
private DmpDescriptionTemplatePersist commonModelDmpDescriptionTemplateToPersist(DmpDescriptionTemplateModel commonModel) {
if (commonModel == null)
return null;
DmpDescriptionTemplatePersist persist = new DmpDescriptionTemplatePersist();
persist.setDescriptionTemplateGroupId(commonModel.getDescriptionTemplateGroupId());
persist.setSectionId(commonModel.getSectionId());
return persist;
}
private UUID commonModelDmpBlueprintToPersist(DmpModel dmpXml) throws JAXBException, InvalidApplicationException, ParserConfigurationException, IOException, TransformerException, InstantiationException, IllegalAccessException, SAXException { private UUID commonModelDmpBlueprintToPersist(DmpModel dmpXml) throws JAXBException, InvalidApplicationException, ParserConfigurationException, IOException, TransformerException, InstantiationException, IllegalAccessException, SAXException {
if (dmpXml.getDmpBlueprint() != null){ if (dmpXml.getDmpBlueprint() != null){
DmpBlueprintEntity dmpBlueprintEntity = this.queryFactory.query(DmpBlueprintQuery.class).disableTracking().ids(dmpXml.getDmpBlueprint().getId()).first(); DmpBlueprintEntity dmpBlueprintEntity = this.queryFactory.query(DmpBlueprintQuery.class).disableTracking().ids(dmpXml.getDmpBlueprint().getId()).first();
@ -2128,58 +2125,66 @@ public class DmpServiceImpl implements DmpService {
return null; return null;
} }
private DmpPropertiesPersist commonDmpPropertiesToPersist(DmpModel model) { private DmpPropertiesPersist commonModelDmpPropertiesToPersist(DmpModel commonModel) {
if (model == null) if (commonModel == null || commonModel.getProperties() == null) return null;
return null;
DmpPropertiesPersist persist = new DmpPropertiesPersist(); DmpPropertiesPersist persist = new DmpPropertiesPersist();
persist.setContacts(this.commonModelToDmpContactPersist(commonModel.getProperties()));
List<DmpContactPersist> contacts = new ArrayList<>(); persist.setDmpBlueprintValues(this.commonModelToDmpBlueprintValuePersist(commonModel));
if (model.getProperties() != null && !this.conventionService.isListNullOrEmpty(model.getProperties().getContacts())) {
for (DmpContactModel contact : model.getProperties().getContacts()) {
contacts.add(this.commonDmpContactToPersist(contact));
}
}
Map<UUID, DmpBlueprintValuePersist> dmpBlueprintValues = new HashMap<>();
if (model.getDmpBlueprint() != null && model.getDmpBlueprint().getDefinition() != null && !this.conventionService.isListNullOrEmpty(model.getDmpBlueprint().getDefinition().getSections())) {
List<SectionModel> sections = model.getDmpBlueprint().getDefinition().getSections();
if (!this.conventionService.isListNullOrEmpty(sections)){
for (SectionModel section : model.getDmpBlueprint().getDefinition().getSections()) {
if (!this.conventionService.isListNullOrEmpty(section.getFields()) && !this.conventionService.isListNullOrEmpty(model.getReferences())){
for (FieldModel field : section.getFields()) {
// reference
if (field.getCategory().equals(org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.ReferenceType)){
ReferenceTypeFieldModel referenceField = (ReferenceTypeFieldModel) field;
List<DmpReferenceModel> dmpReferencesByField = model.getReferences().stream().filter(x -> x.getData() != null && x.getData().getBlueprintFieldId().equals(referenceField.getId())).collect(Collectors.toList());
if (!this.conventionService.isListNullOrEmpty(dmpReferencesByField)){
dmpBlueprintValues.put(referenceField.getId(), this.commonDmpReferenceFieldToDmpBlueprintValuePersist(referenceField, dmpReferencesByField));
}
} else {
// custom fields
if (field.getCategory().equals(org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.Extra) && model.getProperties() != null && this.conventionService.isListNullOrEmpty(model.getProperties().getDmpBlueprintValues())){
DmpBlueprintValueModel dmpBlueprintValueModel = model.getProperties().getDmpBlueprintValues().stream().filter(x -> x.getFieldId().equals(field.getId())).findFirst().orElse(null);
ExtraFieldModel extraFieldModel = (ExtraFieldModel) field;
if (dmpBlueprintValueModel != null) dmpBlueprintValues.put(dmpBlueprintValueModel.getFieldId(), this.commonDmpBlueprintValueToPersist(dmpBlueprintValueModel, extraFieldModel));
}
}
}
}
}
}
}
persist.setContacts(contacts);
persist.setDmpBlueprintValues(dmpBlueprintValues);
return persist; return persist;
} }
private DmpBlueprintValuePersist commonDmpReferenceFieldToDmpBlueprintValuePersist(ReferenceTypeFieldModel model, List<DmpReferenceModel> dmpReferences) { private List<DmpContactPersist> commonModelToDmpContactPersist(DmpPropertiesModel commonModel){
if (model == null || this.conventionService.isListNullOrEmpty(dmpReferences)) if (!this.conventionService.isListNullOrEmpty(commonModel.getContacts())) {
List<DmpContactPersist> contacts = new ArrayList<>();
for (DmpContactModel contact : commonModel.getContacts()) {
contacts.add(this.commonModelDmpContactToPersist(contact));
}
return contacts;
}
return null; return null;
}
private Map<UUID, DmpBlueprintValuePersist> commonModelToDmpBlueprintValuePersist(DmpModel commonModel){
if (commonModel.getDmpBlueprint() != null && commonModel.getDmpBlueprint().getDefinition() != null && !this.conventionService.isListNullOrEmpty(commonModel.getDmpBlueprint().getDefinition().getSections())) {
Map<UUID, DmpBlueprintValuePersist> dmpBlueprintValues = new HashMap<>();
List<SectionModel> sections = commonModel.getDmpBlueprint().getDefinition().getSections();
if (!this.conventionService.isListNullOrEmpty(sections)){
for (SectionModel section : sections) {
if (!this.conventionService.isListNullOrEmpty(section.getFields())){
for (FieldModel field : section.getFields()) {
// reference
if (field.getCategory().equals(org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.ReferenceType)){
ReferenceTypeFieldModel referenceField = (ReferenceTypeFieldModel) field;
List<DmpReferenceModel> dmpReferencesByField = commonModel.getReferences().stream().filter(x -> x.getData() != null && x.getData().getBlueprintFieldId().equals(referenceField.getId())).collect(Collectors.toList());
if (!this.conventionService.isListNullOrEmpty(dmpReferencesByField)){
dmpBlueprintValues.put(referenceField.getId(), this.commonModelDmpReferenceFieldToDmpBlueprintValuePersist(referenceField, dmpReferencesByField));
}
} else {
// custom fields
if (field.getCategory().equals(org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.Extra) && commonModel.getProperties() != null && this.conventionService.isListNullOrEmpty(commonModel.getProperties().getDmpBlueprintValues())){
DmpBlueprintValueModel dmpBlueprintValueModel = commonModel.getProperties().getDmpBlueprintValues().stream().filter(x -> x.getFieldId().equals(field.getId())).findFirst().orElse(null);
ExtraFieldModel extraFieldModel = (ExtraFieldModel) field;
if (dmpBlueprintValueModel != null) dmpBlueprintValues.put(dmpBlueprintValueModel.getFieldId(), this.commonModelDmpBlueprintValueToPersist(dmpBlueprintValueModel, extraFieldModel));
}
}
}
}
}
}
return dmpBlueprintValues;
}
return null;
}
private DmpBlueprintValuePersist commonModelDmpReferenceFieldToDmpBlueprintValuePersist(ReferenceTypeFieldModel model, List<DmpReferenceModel> dmpReferences) {
if (model == null || this.conventionService.isListNullOrEmpty(dmpReferences) || model.getReferenceType() == null)
return null;
ReferenceTypeEntity referenceTypeEntity = this.queryFactory.query(ReferenceTypeQuery.class).ids(model.getReferenceType().getId()).first();//TODO: optimize
if (referenceTypeEntity == null) referenceTypeEntity = this.queryFactory.query(ReferenceTypeQuery.class).codes(model.getReferenceType().getCode()).first();
if (referenceTypeEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getReferenceType().getCode(), ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
DmpBlueprintValuePersist persist = new DmpBlueprintValuePersist(); DmpBlueprintValuePersist persist = new DmpBlueprintValuePersist();
@ -2187,99 +2192,108 @@ public class DmpServiceImpl implements DmpService {
if (model.getMultipleSelect()){ if (model.getMultipleSelect()){
List<ReferencePersist> references = new ArrayList<>(); List<ReferencePersist> references = new ArrayList<>();
for (DmpReferenceModel dmpReference : dmpReferences) { for (DmpReferenceModel dmpReference : dmpReferences) {
references.add(this.commonDmpReferenceToReferencePersist(dmpReference.getReference())); references.add(this.commonDmpReferenceToReferencePersist(dmpReference.getReference(), referenceTypeEntity));
} }
persist.setReferences(references); persist.setReferences(references);
} else { } else {
persist.setReference(this.commonDmpReferenceToReferencePersist(dmpReferences.getFirst().getReference())); persist.setReference(this.commonDmpReferenceToReferencePersist(dmpReferences.getFirst().getReference(), referenceTypeEntity));
} }
return persist; return persist;
} }
private ReferencePersist commonDmpReferenceToReferencePersist(ReferenceModel model) { private ReferencePersist commonDmpReferenceToReferencePersist(ReferenceModel model, ReferenceTypeEntity referenceTypeEntity) {
if (model == null) if (!referenceTypeEntity.getCode().equals(model.getType().getCode())) throw new MyApplicationException("Invalid reference for field " + model.getId());
return null;
if (this.conventionService.isNullOrEmpty(model.getLabel()) && this.conventionService.isNullOrEmpty(model.getReference())) throw new MyApplicationException("Dmp Reference without label and reference id ");
ReferenceEntity referenceEntity = this.queryFactory.query(ReferenceQuery.class).ids(model.getId()).first(); //TODO: optimize
if (referenceEntity == null) referenceEntity = this.queryFactory.query(ReferenceQuery.class).references(model.getReference()).typeIds(referenceTypeEntity.getId()).sources(model.getSource()).first();
ReferencePersist persist = new ReferencePersist(); ReferencePersist persist = new ReferencePersist();
persist.setId(model.getId()); persist.setTypeId(referenceTypeEntity.getId());
if (referenceEntity == null) {
persist.setLabel(model.getLabel()); persist.setLabel(model.getLabel());
persist.setDescription(model.getDescription());
persist.setReference(model.getReference()); persist.setReference(model.getReference());
persist.setAbbreviation(model.getAbbreviation()); persist.setSource("internal");
persist.setSource(model.getSource()); persist.setSourceType(ReferenceSourceType.Internal);
switch (model.getSourceType()){ } else {
case Internal -> persist.setSourceType(ReferenceSourceType.Internal); persist.setId(referenceEntity.getId());
case External -> persist.setSourceType(ReferenceSourceType.External); persist.setLabel(referenceEntity.getLabel());
default -> throw new MyApplicationException("Unrecognized Type " + model.getSourceType().getValue()); persist.setReference(referenceEntity.getReference());
persist.setSource(referenceEntity.getSource());
persist.setSourceType(referenceEntity.getSourceType());
persist.setAbbreviation(referenceEntity.getAbbreviation());
persist.setDescription(referenceEntity.getDescription());
persist.setHash(this.conventionService.hashValue(referenceEntity.getUpdatedAt()));
} }
return persist; return persist;
} }
private DmpBlueprintValuePersist commonDmpBlueprintValueToPersist(DmpBlueprintValueModel model, ExtraFieldModel extraFieldModel) { private DmpBlueprintValuePersist commonModelDmpBlueprintValueToPersist(DmpBlueprintValueModel commonModel, ExtraFieldModel extraFieldModel) {
if (model == null || extraFieldModel == null) if (commonModel == null || extraFieldModel == null)
return null; return null;
DmpBlueprintValuePersist persist = new DmpBlueprintValuePersist(); DmpBlueprintValuePersist persist = new DmpBlueprintValuePersist();
persist.setFieldId(model.getFieldId()); persist.setFieldId(commonModel.getFieldId());
if (extraFieldModel.getDataType().equals(org.opencdmp.commonmodels.enums.DmpBlueprintExtraFieldDataType.Date)){ switch (extraFieldModel.getDataType()){
persist.setDateValue(model.getDateValue()); case Date -> persist.setDateValue(commonModel.getDateValue());
} else if (extraFieldModel.getDataType().equals(org.opencdmp.commonmodels.enums.DmpBlueprintExtraFieldDataType.Number)){ case Number -> persist.setNumberValue(commonModel.getNumberValue());
persist.setNumberValue(model.getNumberValue()); case Text, RichTex -> persist.setFieldValue(commonModel.getValue());
} else { default -> throw new MyApplicationException("unrecognized type " + extraFieldModel.getDataType());
persist.setFieldValue(model.getValue());
} }
return persist; return persist;
} }
private DmpDescriptionTemplatePersist commonDmpDescriptionTemplateToPersist(DmpDescriptionTemplateModel model) { private List<DmpUserPersist> commonModelToDmpUsersPersist(DmpModel commonModel){
if (model == null) if (!this.conventionService.isListNullOrEmpty(commonModel.getUsers())) {
List<UserEntity> users = this.queryFactory.query(UserQuery.class).disableTracking().ids(commonModel.getUsers().stream().map(DmpUserModel::getUser).filter(Objects::nonNull).map(UserModel::getId).filter(Objects::nonNull).distinct().toList()).isActive(IsActive.Active).collect();
List<UUID> userIds = users == null ? new ArrayList<>() : users.stream().map(UserEntity::getId).collect(Collectors.toList());
List<DmpUserPersist> dmpUsers = new ArrayList<>();
for (DmpUserModel user : commonModel.getUsers()) {
dmpUsers.add(this.commonModelDmpUserToPersist(user, userIds));
}
return dmpUsers;
}
return null; return null;
DmpDescriptionTemplatePersist persist = new DmpDescriptionTemplatePersist();
persist.setDescriptionTemplateGroupId(model.getDescriptionTemplateGroupId());
persist.setSectionId(model.getSectionId());
return persist;
} }
private DmpUserPersist commonDmpUserToPersist(DmpUserModel model, List<UUID> userIds) {
if (model == null) private DmpUserPersist commonModelDmpUserToPersist(DmpUserModel commonModel, List<UUID> userIds) {
if (commonModel == null)
return null; return null;
if (model.getUser() != null && model.getUser().getId() != null && !userIds.isEmpty() && userIds.contains(model.getUser().getId())) { if (commonModel.getUser() != null && commonModel.getUser().getId() != null && !userIds.isEmpty() && userIds.contains(commonModel.getUser().getId())) {
DmpUserPersist persist = new DmpUserPersist(); DmpUserPersist persist = new DmpUserPersist();
persist.setUser(model.getUser().getId()); persist.setUser(commonModel.getUser().getId());
switch (model.getRole()){ switch (commonModel.getRole()){
case Owner -> persist.setRole(DmpUserRole.Owner); case Owner -> persist.setRole(DmpUserRole.Owner);
case Viewer -> persist.setRole(DmpUserRole.Viewer); case Viewer -> persist.setRole(DmpUserRole.Viewer);
case DescriptionContributor -> persist.setRole(DmpUserRole.DescriptionContributor); case DescriptionContributor -> persist.setRole(DmpUserRole.DescriptionContributor);
case Reviewer -> persist.setRole(DmpUserRole.Reviewer); case Reviewer -> persist.setRole(DmpUserRole.Reviewer);
default -> throw new MyApplicationException("Unrecognized Type " + model.getRole().getValue()); default -> throw new MyApplicationException("Unrecognized Type " + commonModel.getRole().getValue());
} }
persist.setSectionId(model.getSectionId()); persist.setSectionId(commonModel.getSectionId());
return persist; return persist;
} }
return null; return null;
} }
private DmpContactPersist commonDmpContactToPersist(DmpContactModel model) { private DmpContactPersist commonModelDmpContactToPersist(DmpContactModel commonModel) {
if (model == null) if (commonModel == null)
return null; return null;
DmpContactPersist persist = new DmpContactPersist(); DmpContactPersist persist = new DmpContactPersist();
persist.setEmail(model.getEmail()); persist.setEmail(commonModel.getEmail());
persist.setFirstName(model.getEmail()); persist.setFirstName(commonModel.getEmail());
persist.setLastName(model.getLastName()); persist.setLastName(commonModel.getLastName());
return persist; return persist;
} }