updateDescriptionTemplate changes
This commit is contained in:
parent
a556aef2cd
commit
0569e8bd6d
|
@ -28,16 +28,16 @@ public class UpdateDescriptionTemplatePersist {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
private UUID descriptionTemplateGroupId;
|
private String hash;
|
||||||
|
|
||||||
public static final String _descriptionTemplateGroupId = "descriptionTemplateGroupId";
|
public static final String _hash = "hash";
|
||||||
|
|
||||||
public UUID getDescriptionTemplateGroupId() {
|
public String getHash() {
|
||||||
return descriptionTemplateGroupId;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescriptionTemplateGroupId(UUID descriptionTemplateGroupId) {
|
public void setHash(String hash) {
|
||||||
this.descriptionTemplateGroupId = descriptionTemplateGroupId;
|
this.hash = hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component(UpdateDescriptionTemplatePersistValidator.ValidatorName)
|
@Component(UpdateDescriptionTemplatePersistValidator.ValidatorName)
|
||||||
|
@ -61,6 +61,10 @@ public class UpdateDescriptionTemplatePersist {
|
||||||
@Override
|
@Override
|
||||||
protected List<Specification> specifications(UpdateDescriptionTemplatePersist item) {
|
protected List<Specification> specifications(UpdateDescriptionTemplatePersist item) {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
|
this.spec()
|
||||||
|
.iff(() -> this.isValidGuid(item.getId()))
|
||||||
|
.must(() -> this.isValidHash(item.getHash()))
|
||||||
|
.failOn(UpdateDescriptionTemplatePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{UpdateDescriptionTemplatePersist._hash}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
.must(() -> this.isValidGuid(item.getId()))
|
.must(() -> this.isValidGuid(item.getId()))
|
||||||
.failOn(UpdateDescriptionTemplatePersist._id)
|
.failOn(UpdateDescriptionTemplatePersist._id)
|
||||||
|
|
|
@ -10,6 +10,7 @@ import gr.cite.tools.exception.MyForbiddenException;
|
||||||
import gr.cite.tools.exception.MyNotFoundException;
|
import gr.cite.tools.exception.MyNotFoundException;
|
||||||
import gr.cite.tools.exception.MyValidationException;
|
import gr.cite.tools.exception.MyValidationException;
|
||||||
import gr.cite.tools.fieldset.FieldSet;
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
|
import jakarta.xml.bind.JAXBException;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
@ -37,5 +38,5 @@ public interface DescriptionService {
|
||||||
|
|
||||||
StorageFile uploadFieldFile(DescriptionFieldFilePersist model, MultipartFile file, FieldSet fields) throws IOException;
|
StorageFile uploadFieldFile(DescriptionFieldFilePersist model, MultipartFile file, FieldSet fields) throws IOException;
|
||||||
StorageFileEntity getFieldFile(UUID descriptionId, UUID storageFileId);
|
StorageFileEntity getFieldFile(UUID descriptionId, UUID storageFileId);
|
||||||
void updateDescriptionTemplate(UpdateDescriptionTemplatePersist model) throws InvalidApplicationException, IOException;
|
void updateDescriptionTemplate(UpdateDescriptionTemplatePersist model) throws InvalidApplicationException, IOException, JAXBException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ import gr.cite.tools.fieldset.FieldSet;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import gr.cite.tools.logging.MapLogEntry;
|
import gr.cite.tools.logging.MapLogEntry;
|
||||||
import gr.cite.tools.validation.ValidatorFactory;
|
import gr.cite.tools.validation.ValidatorFactory;
|
||||||
|
import jakarta.xml.bind.JAXBException;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -236,7 +237,7 @@ public class DescriptionServiceImpl implements DescriptionService {
|
||||||
return this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, Description._id), data);
|
return this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, Description._id), data);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void updateDescriptionTemplate(UpdateDescriptionTemplatePersist model) throws InvalidApplicationException, IOException {
|
public void updateDescriptionTemplate(UpdateDescriptionTemplatePersist model) throws InvalidApplicationException, IOException, JAXBException {
|
||||||
logger.debug(new MapLogEntry("update description template").And("model", model));
|
logger.debug(new MapLogEntry("update description template").And("model", model));
|
||||||
|
|
||||||
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.descriptionAffiliation(model.getId())), Permission.EditDescription);
|
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.descriptionAffiliation(model.getId())), Permission.EditDescription);
|
||||||
|
@ -269,6 +270,7 @@ public class DescriptionServiceImpl implements DescriptionService {
|
||||||
eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, latestVersionDescriptionTemplates.getFirst().getDefinition());
|
eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, latestVersionDescriptionTemplates.getFirst().getDefinition());
|
||||||
PropertyDefinitionEntity propertyDefinition = this.xmlHandlingService.fromXmlSafe(PropertyDefinitionEntity.class, data.getProperties());
|
PropertyDefinitionEntity propertyDefinition = this.xmlHandlingService.fromXmlSafe(PropertyDefinitionEntity.class, data.getProperties());
|
||||||
|
|
||||||
|
data.setProperties(this.xmlHandlingService.toXml(this.cleanPropertyDefinitionEntity(propertyDefinition, definition)));
|
||||||
data.setUpdatedAt(Instant.now());
|
data.setUpdatedAt(Instant.now());
|
||||||
this.entityManager.merge(data);
|
this.entityManager.merge(data);
|
||||||
|
|
||||||
|
@ -304,6 +306,50 @@ public class DescriptionServiceImpl implements DescriptionService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private @NotNull PropertyDefinitionEntity cleanPropertyDefinitionEntity(PropertyDefinitionEntity data, eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition) {
|
||||||
|
PropertyDefinitionEntity cleanData = new PropertyDefinitionEntity();
|
||||||
|
if (data == null) return cleanData;
|
||||||
|
if (data.getFieldSets() != null && !data.getFieldSets().isEmpty()){
|
||||||
|
cleanData.setFieldSets(new HashMap<>());
|
||||||
|
for (String key: data.getFieldSets().keySet()) {
|
||||||
|
FieldSetEntity fieldSetEntity = definition != null ? definition.getFieldSetById(key).stream().findFirst().orElse(null) : null;
|
||||||
|
if (fieldSetEntity != null){
|
||||||
|
cleanData.getFieldSets().put(key, this.cleanPropertyDefinitionFieldSetEntity(data.getFieldSets().get(key), fieldSetEntity));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cleanData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private @NotNull PropertyDefinitionFieldSetEntity cleanPropertyDefinitionFieldSetEntity(PropertyDefinitionFieldSetEntity persist, FieldSetEntity fieldSetEntity) {
|
||||||
|
PropertyDefinitionFieldSetEntity cleanData = new PropertyDefinitionFieldSetEntity();
|
||||||
|
if (persist == null) return cleanData;
|
||||||
|
if (!this.conventionService.isListNullOrEmpty(persist.getItems())){
|
||||||
|
cleanData.setItems(new ArrayList<>());
|
||||||
|
for (PropertyDefinitionFieldSetItemEntity itemsPersist: persist.getItems()) {
|
||||||
|
cleanData.getItems().add(this.cleanPropertyDefinitionFieldSetItemEntity(itemsPersist, fieldSetEntity));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cleanData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private @NotNull PropertyDefinitionFieldSetItemEntity cleanPropertyDefinitionFieldSetItemEntity(PropertyDefinitionFieldSetItemEntity data, FieldSetEntity fieldSetEntity) {
|
||||||
|
PropertyDefinitionFieldSetItemEntity cleanData = new PropertyDefinitionFieldSetItemEntity();
|
||||||
|
if (data == null) return cleanData;
|
||||||
|
if (data.getFields() != null && !data.getFields().isEmpty()){
|
||||||
|
cleanData.setOrdinal(data.getOrdinal());
|
||||||
|
cleanData.setComment(data.getComment());
|
||||||
|
cleanData.setFields(new HashMap<>());
|
||||||
|
for (String key: data.getFields().keySet()) {
|
||||||
|
eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getFieldById(key).stream().findFirst().orElse(null) : null;
|
||||||
|
if (fieldEntity != null){
|
||||||
|
cleanData.getFields().put(key,data.getFields().get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cleanData;
|
||||||
|
}
|
||||||
|
|
||||||
private void createDescriptionNotificationEvent(DescriptionEntity description, UserEntity user, NotificationContactType type) throws InvalidApplicationException {
|
private void createDescriptionNotificationEvent(DescriptionEntity description, UserEntity user, NotificationContactType type) throws InvalidApplicationException {
|
||||||
NotifyIntegrationEvent event = new NotifyIntegrationEvent();
|
NotifyIntegrationEvent event = new NotifyIntegrationEvent();
|
||||||
event.setUserId(this.userScope.getUserId());
|
event.setUserId(this.userScope.getUserId());
|
||||||
|
|
|
@ -35,6 +35,7 @@ import gr.cite.tools.exception.MyNotFoundException;
|
||||||
import gr.cite.tools.fieldset.FieldSet;
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import gr.cite.tools.logging.MapLogEntry;
|
import gr.cite.tools.logging.MapLogEntry;
|
||||||
|
import jakarta.xml.bind.JAXBException;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
@ -272,7 +273,7 @@ public class DescriptionController {
|
||||||
@PostMapping("update-description-template")
|
@PostMapping("update-description-template")
|
||||||
@Transactional
|
@Transactional
|
||||||
@ValidationFilterAnnotation(validator = UpdateDescriptionTemplatePersist.UpdateDescriptionTemplatePersistValidator.ValidatorName, argumentName = "model")
|
@ValidationFilterAnnotation(validator = UpdateDescriptionTemplatePersist.UpdateDescriptionTemplatePersistValidator.ValidatorName, argumentName = "model")
|
||||||
public Boolean updateDescriptionTemplate(@RequestBody UpdateDescriptionTemplatePersist model) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, IOException {
|
public Boolean updateDescriptionTemplate(@RequestBody UpdateDescriptionTemplatePersist model) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, IOException, JAXBException {
|
||||||
logger.debug(new MapLogEntry("update description template" + Description.class.getSimpleName()).And("model", model));
|
logger.debug(new MapLogEntry("update description template" + Description.class.getSimpleName()).And("model", model));
|
||||||
this.descriptionService.updateDescriptionTemplate(model);
|
this.descriptionService.updateDescriptionTemplate(model);
|
||||||
|
|
||||||
|
|
|
@ -152,5 +152,5 @@ export interface DescriptionSectionPermissionResolver {
|
||||||
|
|
||||||
export interface UpdateDescriptionTemplatePersist {
|
export interface UpdateDescriptionTemplatePersist {
|
||||||
id: Guid;
|
id: Guid;
|
||||||
descriptionTemplateGroupId: Guid;
|
hash?: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,12 @@ export class DescriptionBaseFieldsEditorComponent extends BaseComponent {
|
||||||
@Input() description: Description;
|
@Input() description: Description;
|
||||||
availableDescriptionTemplates: DescriptionTemplate[] = [];
|
availableDescriptionTemplates: DescriptionTemplate[] = [];
|
||||||
viewOnly = false; //TODO: not used.
|
viewOnly = false; //TODO: not used.
|
||||||
|
|
||||||
@Output() refresh: EventEmitter<any> = new EventEmitter<any>();
|
@Output() refresh: EventEmitter<any> = new EventEmitter<any>();
|
||||||
|
|
||||||
constructor(private dialog: MatDialog,
|
constructor(private dialog: MatDialog,
|
||||||
private descriptionService: DescriptionService) {
|
private descriptionService: DescriptionService) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
@ -39,7 +39,7 @@ export class DescriptionBaseFieldsEditorComponent extends BaseComponent {
|
||||||
public compareWith(object1: any, object2: any) {
|
public compareWith(object1: any, object2: any) {
|
||||||
return object1 && object2 && object1.id === object2.id;
|
return object1 && object2 && object1.id === object2.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadDescriptionTemplates(): void {
|
private loadDescriptionTemplates(): void {
|
||||||
const dmpDescriptionTemplates: DmpDescriptionTemplate[] = this.description.dmp.dmpDescriptionTemplates.filter(x => x.sectionId == this.description.dmpDescriptionTemplate.sectionId && x.isActive == IsActive.Active);
|
const dmpDescriptionTemplates: DmpDescriptionTemplate[] = this.description.dmp.dmpDescriptionTemplates.filter(x => x.sectionId == this.description.dmpDescriptionTemplate.sectionId && x.isActive == IsActive.Active);
|
||||||
const currentVersionsOfDescriptionTemplates = dmpDescriptionTemplates.map(x => x.currentDescriptionTemplate);
|
const currentVersionsOfDescriptionTemplates = dmpDescriptionTemplates.map(x => x.currentDescriptionTemplate);
|
||||||
|
@ -53,7 +53,7 @@ export class DescriptionBaseFieldsEditorComponent extends BaseComponent {
|
||||||
}
|
}
|
||||||
this.availableDescriptionTemplates.push(...currentVersionsOfDescriptionTemplates);
|
this.availableDescriptionTemplates.push(...currentVersionsOfDescriptionTemplates);
|
||||||
}
|
}
|
||||||
|
|
||||||
private openDeprecatedDescriptionTemplateDialog(): void {
|
private openDeprecatedDescriptionTemplateDialog(): void {
|
||||||
const dialogRef = this.dialog.open(DeprecatedDescriptionTemplateDialog, {
|
const dialogRef = this.dialog.open(DeprecatedDescriptionTemplateDialog, {
|
||||||
data: {
|
data: {
|
||||||
|
@ -65,7 +65,7 @@ export class DescriptionBaseFieldsEditorComponent extends BaseComponent {
|
||||||
if(result) {
|
if(result) {
|
||||||
this.descriptionService.updateDescriptionTemplate({
|
this.descriptionService.updateDescriptionTemplate({
|
||||||
id: this.description.id,
|
id: this.description.id,
|
||||||
descriptionTemplateGroupId: this.description.descriptionTemplate.groupId
|
hash: this.description.hash
|
||||||
})
|
})
|
||||||
.subscribe(
|
.subscribe(
|
||||||
result => {
|
result => {
|
||||||
|
|
Loading…
Reference in New Issue