fieldset comment change implementation model

This commit is contained in:
CITE\amentis 2024-10-09 14:06:49 +03:00
parent 285acf96ba
commit 36d59aa02c
15 changed files with 64 additions and 45 deletions

View File

@ -57,12 +57,12 @@
<dependency>
<groupId>org.opencdmp</groupId>
<artifactId>repositorydepositbase</artifactId>
<version>2.0.17</version>
<version>2.0.18</version>
</dependency>
<dependency>
<groupId>org.opencdmp</groupId>
<artifactId>common-models</artifactId>
<version>0.0.20</version>
<version>0.0.21</version>
</dependency>
<dependency>
<groupId>gr.cite</groupId>
@ -72,7 +72,7 @@
<dependency>
<groupId>org.opencdmp</groupId>
<artifactId>file-transformer-base</artifactId>
<version>0.0.25</version>
<version>0.0.26</version>
</dependency>
<dependency>
<groupId>gr.cite</groupId>

View File

@ -5,6 +5,8 @@ import java.util.List;
public class PropertyDefinitionFieldSetEntity {
private List<PropertyDefinitionFieldSetItemEntity> items;
private String comment;
public List<PropertyDefinitionFieldSetItemEntity> getItems() {
return this.items;
}
@ -12,4 +14,12 @@ public class PropertyDefinitionFieldSetEntity {
public void setItems(List<PropertyDefinitionFieldSetItemEntity> items) {
this.items = items;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}

View File

@ -16,6 +16,9 @@ public class DescriptionPropertyDefinitionFieldSetImportExport {
@XmlElement(name = "item")
private List<DescriptionPropertyDefinitionFieldSetItemImportExport> items;
@XmlElement(name = "comment")
private String comment;
public List<DescriptionPropertyDefinitionFieldSetItemImportExport> getItems() {
return this.items;
}
@ -31,4 +34,12 @@ public class DescriptionPropertyDefinitionFieldSetImportExport {
public void setFieldSetId(String fieldSetId) {
this.fieldSetId = fieldSetId;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}

View File

@ -14,8 +14,6 @@ public class DescriptionPropertyDefinitionFieldSetItemImportExport {
@XmlElementWrapper(name = "fields")
@XmlElement(name = "field")
private List<DescriptionFieldImportExport> fields;
@XmlElement(name = "comment")
private String comment;
@XmlElement(name = "ordinal")
private int ordinal;
@ -27,14 +25,6 @@ public class DescriptionPropertyDefinitionFieldSetItemImportExport {
this.fields = fields;
}
public String getComment() {
return this.comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public int getOrdinal() {
return this.ordinal;
}

View File

@ -57,6 +57,7 @@ public class PropertyDefinitionFieldSetCommonModelBuilder extends BaseCommonMode
List<CommonModelBuilderItemResponse<PropertyDefinitionFieldSetModel, PropertyDefinitionFieldSetEntity>> models = new ArrayList<>();
for (PropertyDefinitionFieldSetEntity d : data) {
PropertyDefinitionFieldSetModel m = new PropertyDefinitionFieldSetModel();
m.setComment(d.getComment());
if (d.getItems() != null) m.setItems(this.builderFactory.builder(PropertyDefinitionFieldSetItemModelCommonModelBuilder.class).useSharedStorage(useSharedStorage).withFieldSetEntity(this.fieldSetEntity).authorize(this.authorize).build(d.getItems()));
models.add(new CommonModelBuilderItemResponse<>(m, d));
}

View File

@ -61,7 +61,6 @@ public class PropertyDefinitionFieldSetItemModelCommonModelBuilder extends BaseC
for (PropertyDefinitionFieldSetItemEntity d : data) {
PropertyDefinitionFieldSetItemModel m = new PropertyDefinitionFieldSetItemModel();
m.setComment(d.getComment());
m.setOrdinal(d.getOrdinal());
if (d.getFields() != null && !d.getFields().isEmpty()) {
m.setFields(new HashMap<>());

View File

@ -58,6 +58,7 @@ public class PropertyDefinitionFieldSetBuilder extends BaseBuilder<PropertyDefin
for (PropertyDefinitionFieldSetEntity d : data) {
PropertyDefinitionFieldSet m = new PropertyDefinitionFieldSet();
if (!itemsFields.isEmpty() && d.getItems() != null) m.setItems(this.builderFactory.builder(PropertyDefinitionFieldSetItemBuilder.class).withFieldSetEntity(this.fieldSetEntity).authorize(this.authorize).build(itemsFields, d.getItems()));
if (fields.hasField(this.asIndexer(PropertyDefinitionFieldSet._comment))) m.setComment(d.getComment());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));

View File

@ -7,6 +7,9 @@ public class PropertyDefinitionFieldSet {
public final static String _items = "items";
private List<PropertyDefinitionFieldSetItem> items;
public final static String _comment = "comment";
private String comment;
public List<PropertyDefinitionFieldSetItem> getItems() {
return items;
}
@ -14,4 +17,12 @@ public class PropertyDefinitionFieldSet {
public void setItems(List<PropertyDefinitionFieldSetItem> items) {
this.items = items;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}

View File

@ -25,9 +25,6 @@ public class PropertyDefinitionFieldSetItemPersist {
public final static String _fields = "fields";
private Map<String, FieldPersist> fields;
public final static String _comment = "comment";
private String comment;
public final static String _ordinal = "ordinal";
private Integer ordinal = null;
@ -39,14 +36,6 @@ public class PropertyDefinitionFieldSetItemPersist {
this.fields = fields;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public Integer getOrdinal() {
return ordinal;
}

View File

@ -23,6 +23,9 @@ public class PropertyDefinitionFieldSetPersist {
public final static String _items = "items";
private List<PropertyDefinitionFieldSetItemPersist> items;
public final static String _comment = "comment";
private String comment;
public List<PropertyDefinitionFieldSetItemPersist> getItems() {
return items;
}
@ -31,6 +34,14 @@ public class PropertyDefinitionFieldSetPersist {
this.items = items;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
@Component(PersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class PersistValidator extends BaseValidator<PropertyDefinitionFieldSetPersist> {

View File

@ -582,6 +582,7 @@ public class DescriptionServiceImpl implements DescriptionService {
private @NotNull PropertyDefinitionFieldSetEntity buildPropertyDefinitionFieldSetEntity(PropertyDefinitionFieldSetPersist persist, FieldSetEntity fieldSetEntity, Map<String, List<UUID>> fieldToReferenceMap, VisibilityService visibilityService) throws InvalidApplicationException {
PropertyDefinitionFieldSetEntity data = new PropertyDefinitionFieldSetEntity();
if (persist == null) return data;
data.setComment(persist.getComment());
if (!this.conventionService.isListNullOrEmpty(persist.getItems())){
data.setItems(new ArrayList<>());
for (PropertyDefinitionFieldSetItemPersist itemsPersist: persist.getItems()) {
@ -596,7 +597,6 @@ public class DescriptionServiceImpl implements DescriptionService {
if (persist == null) return data;
if (persist.getFields() != null && !persist.getFields().isEmpty()){
data.setOrdinal(persist.getOrdinal());
data.setComment(persist.getComment());
data.setFields(new HashMap<>());
for (String key: persist.getFields().keySet()) {
org.opencdmp.commons.types.descriptiontemplate.FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getFieldById(key).stream().findFirst().orElse(null) : null;
@ -1108,6 +1108,7 @@ public class DescriptionServiceImpl implements DescriptionService {
private @NotNull PropertyDefinitionFieldSetPersist buildPropertyDefinitionFieldSetPersist(PropertyDefinitionFieldSetEntity data, FieldSetEntity fieldSetEntity, List<ReferenceEntity> references){
PropertyDefinitionFieldSetPersist persist = new PropertyDefinitionFieldSetPersist();
if (data == null) return persist;
persist.setComment(data.getComment());
if (!this.conventionService.isListNullOrEmpty(data.getItems())){
persist.setItems(new ArrayList<>());
for (PropertyDefinitionFieldSetItemEntity itemsPersist: data.getItems()) {
@ -1122,7 +1123,6 @@ public class DescriptionServiceImpl implements DescriptionService {
if (data == null) return persist;
if (data.getFields() != null && !data.getFields().isEmpty()){
persist.setOrdinal(data.getOrdinal());
persist.setComment(data.getComment());
persist.setFields(new HashMap<>());
for (String key: data.getFields().keySet()) {
org.opencdmp.commons.types.descriptiontemplate.FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getFieldById(key).stream().findFirst().orElse(null) : null;
@ -1367,6 +1367,7 @@ public class DescriptionServiceImpl implements DescriptionService {
xml.setFieldSetId(fieldSetId);
if (entity == null) return xml;
xml.setComment(entity.getComment());
if (entity.getItems() != null && !entity.getItems().isEmpty()) {
List<DescriptionPropertyDefinitionFieldSetItemImportExport> exports = new LinkedList<>();
for (PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity : entity.getItems()) {
@ -1382,7 +1383,6 @@ public class DescriptionServiceImpl implements DescriptionService {
DescriptionPropertyDefinitionFieldSetItemImportExport xml = new DescriptionPropertyDefinitionFieldSetItemImportExport();
if (entity == null) return xml;
xml.setComment(entity.getComment());
xml.setOrdinal(entity.getOrdinal());
if (entity.getFields() != null && !entity.getFields().isEmpty()) {
List<DescriptionFieldImportExport> exports = new LinkedList<>();
@ -1517,7 +1517,7 @@ public class DescriptionServiceImpl implements DescriptionService {
return null;
PropertyDefinitionFieldSetPersist persist = new PropertyDefinitionFieldSetPersist();
persist.setComment(importXml.getComment());
if (!this.conventionService.isListNullOrEmpty(importXml.getItems())){
List<PropertyDefinitionFieldSetItemPersist> items = new ArrayList<>();
for (DescriptionPropertyDefinitionFieldSetItemImportExport fieldSetItem: importXml.getItems()) {
@ -1535,8 +1535,6 @@ public class DescriptionServiceImpl implements DescriptionService {
return null;
PropertyDefinitionFieldSetItemPersist persist = new PropertyDefinitionFieldSetItemPersist();
persist.setComment(importXml.getComment());
persist.setOrdinal(importXml.getOrdinal());
Map<String, FieldPersist> fields = new HashMap<>();
@ -1730,7 +1728,7 @@ public class DescriptionServiceImpl implements DescriptionService {
return null;
PropertyDefinitionFieldSetPersist persist = new PropertyDefinitionFieldSetPersist();
persist.setComment(commonModel.getComment());
if (!this.conventionService.isListNullOrEmpty(commonModel.getItems())){
List<PropertyDefinitionFieldSetItemPersist> items = new ArrayList<>();
for (PropertyDefinitionFieldSetItemModel fieldSetItem: commonModel.getItems()) {
@ -1750,7 +1748,6 @@ public class DescriptionServiceImpl implements DescriptionService {
PropertyDefinitionFieldSetItemPersist persist = new PropertyDefinitionFieldSetItemPersist();
persist.setComment(commonModel.getComment());
persist.setOrdinal(commonModel.getOrdinal());
Map<String, FieldPersist> fields = new HashMap<>();

View File

@ -34,11 +34,11 @@ export interface DescriptionPropertyDefinition {
export interface DescriptionPropertyDefinitionFieldSet {
items?: DescriptionPropertyDefinitionFieldSetItem[];
comment?: string;
}
export interface DescriptionPropertyDefinitionFieldSetItem {
fields?: Map<string, DescriptionField>;
comment?: string;
ordinal?: number;
}
@ -93,11 +93,11 @@ export interface DescriptionPropertyDefinitionPersist {
export interface DescriptionPropertyDefinitionFieldSetPersist {
items?: DescriptionPropertyDefinitionFieldSetItemPersist[];
comment?: string;
}
export interface DescriptionPropertyDefinitionFieldSetItemPersist {
fields?: Map<string, DescriptionFieldPersist>;
comment?: string;
ordinal?: number;
}

View File

@ -268,6 +268,7 @@ export class DescriptionPropertyDefinitionEditorModel implements DescriptionProp
export class DescriptionPropertyDefinitionFieldSetEditorModel implements DescriptionPropertyDefinitionFieldSetPersist {
items?: DescriptionPropertyDefinitionFieldSetItemEditorModel[] = [];
comment?: string;
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
fieldSetDefinition: DescriptionTemplateFieldSet;
@ -279,6 +280,7 @@ export class DescriptionPropertyDefinitionFieldSetEditorModel implements Descrip
public fromModel(item: DescriptionPropertyDefinitionFieldSet, descriptionReferences: DescriptionReference[], definitionFieldSet: DescriptionTemplateFieldSet): DescriptionPropertyDefinitionFieldSetEditorModel {
this.fieldSetDefinition = definitionFieldSet;
if (item) {
this.comment = item.comment;
if (item.items) { item.items.sort(x=> x.ordinal).map(x => this.items.push(new DescriptionPropertyDefinitionFieldSetItemEditorModel(this.validationErrorModel).fromModel(x, descriptionReferences, definitionFieldSet))); }
}
return this;
@ -307,7 +309,8 @@ export class DescriptionPropertyDefinitionFieldSetEditorModel implements Descrip
visibilityRulesService: params.visibilityRulesService
})
), context.getValidation('items').validators
)
),
comment: [{ value: this.comment, disabled: disabled }, context.getValidation('comment').validators],
});
}
@ -336,6 +339,7 @@ export class DescriptionPropertyDefinitionFieldSetEditorModel implements Descrip
}
baseValidationArray.push({ key: 'items', validators: validators });
baseValidationArray.push({ key: 'comment', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}comment`)] });
baseContext.validation = baseValidationArray;
return baseContext;
}
@ -363,7 +367,6 @@ export class DescriptionPropertyDefinitionFieldSetEditorModel implements Descrip
export class DescriptionPropertyDefinitionFieldSetItemEditorModel implements DescriptionPropertyDefinitionFieldSetItemPersist {
fields: Map<string, DescriptionFieldEditorModel> = new Map<string, DescriptionFieldEditorModel>;
comment?: string;
ordinal?: number;
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
@ -373,7 +376,6 @@ export class DescriptionPropertyDefinitionFieldSetItemEditorModel implements Des
public fromModel(item: DescriptionPropertyDefinitionFieldSetItem, descriptionReferences: DescriptionReference[], definitionFieldSet: DescriptionTemplateFieldSet): DescriptionPropertyDefinitionFieldSetItemEditorModel {
if (item) {
this.comment = item.comment;
this.ordinal = item.ordinal;
if (item.fields) {
//TODO: don't like it. Find a common way to parse it either its Map or json.
@ -405,7 +407,6 @@ export class DescriptionPropertyDefinitionFieldSetItemEditorModel implements Des
}
const formGroup = this.formBuilder.group({});
formGroup.addControl('comment', new FormControl({ value: this.comment, disabled: disabled }, context.getValidation('comment').validators));
formGroup.addControl('ordinal', new FormControl({ value: this.ordinal, disabled: disabled }, context.getValidation('ordinal').validators));
@ -430,7 +431,6 @@ export class DescriptionPropertyDefinitionFieldSetItemEditorModel implements Des
const baseContext: ValidationContext = new ValidationContext();
const baseValidationArray: Validation[] = new Array<Validation>();
baseValidationArray.push({ key: 'fields', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}fields`)] });
baseValidationArray.push({ key: 'comment', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}comment`)] });
baseValidationArray.push({ key: 'ordinal', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}ordinal`)] });
baseContext.validation = baseValidationArray;
@ -465,7 +465,7 @@ export class DescriptionPropertyDefinitionFieldSetItemEditorModel implements Des
})
});
['comment', 'ordinal'].forEach(keyField => {
['ordinal'].forEach(keyField => {
const control = formGroup?.get(keyField);
control?.clearValidators();
control?.addValidators(context.getValidation(keyField).validators);

View File

@ -93,10 +93,9 @@
</table>
</div>
</div>
<!-- comment only on top level fieldset -->
<div class="row">
<div *ngIf="fieldSet.hasCommentField && propertiesFormGroup?.get('items')?.at(0)?.get('comment')" class="col-12">
<rich-text-editor-component [form]="propertiesFormGroup?.get('items')?.at(0)?.get('comment')" [id]="'editor1'" [placeholder]="'DESCRIPTION-EDITOR.FIELDS.COMMENT-PLACEHOLDER' | translate" [wrapperClasses]="'mb-2'" [editable]="!propertiesFormGroup?.get('items')?.at(0)?.get('comment').disabled" [required]="isRequired"></rich-text-editor-component>
<div *ngIf="fieldSet.hasCommentField && propertiesFormGroup?.get('comment')" class="col-12">
<rich-text-editor-component [form]="propertiesFormGroup?.get('comment')" [id]="'editor1'" [placeholder]="'DESCRIPTION-EDITOR.FIELDS.COMMENT-PLACEHOLDER' | translate" [wrapperClasses]="'mb-2'" [editable]="!propertiesFormGroup?.get('comment').disabled" [required]="isRequired"></rich-text-editor-component>
</div>
</div>
</div>

View File

@ -71,7 +71,7 @@ export class DescriptionEditorEntityResolver extends BaseEditorResolver {
[nameof<Description>(x => x.planDescriptionTemplate), nameof<PlanDescriptionTemplate>(x => x.sectionId)].join('.'),
[nameof<Description>(x => x.planDescriptionTemplate), nameof<PlanDescriptionTemplate>(x => x.isActive)].join('.'),
[nameof<Description>(x => x.properties), nameof<DescriptionPropertyDefinition>(x => x.fieldSets), nameof<DescriptionPropertyDefinitionFieldSet>(x => x.items), nameof<DescriptionPropertyDefinitionFieldSetItem>(x => x.comment)].join('.'),
[nameof<Description>(x => x.properties), nameof<DescriptionPropertyDefinition>(x => x.fieldSets), nameof<DescriptionPropertyDefinitionFieldSet>(x => x.comment)].join('.'),
[nameof<Description>(x => x.properties), nameof<DescriptionPropertyDefinition>(x => x.fieldSets), nameof<DescriptionPropertyDefinitionFieldSet>(x => x.items), nameof<DescriptionPropertyDefinitionFieldSetItem>(x => x.ordinal)].join('.'),
[nameof<Description>(x => x.properties), nameof<DescriptionPropertyDefinition>(x => x.fieldSets), nameof<DescriptionPropertyDefinitionFieldSet>(x => x.items), nameof<DescriptionPropertyDefinitionFieldSetItem>(x => x.fields), nameof<DescriptionField>(x => x.textValue)].join('.'),
[nameof<Description>(x => x.properties), nameof<DescriptionPropertyDefinition>(x => x.fieldSets), nameof<DescriptionPropertyDefinitionFieldSet>(x => x.items), nameof<DescriptionPropertyDefinitionFieldSetItem>(x => x.fields), nameof<DescriptionField>(x => x.textListValue)].join('.'),