fix reassign visibility rules on description template clone
This commit is contained in:
parent
6edefb3db9
commit
93cbd788f5
|
@ -1,5 +1,6 @@
|
|||
package org.opencdmp.model.descriptiontemplate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Definition {
|
||||
|
@ -14,4 +15,32 @@ public class Definition {
|
|||
public void setPages(List<Page> pages) {
|
||||
this.pages = pages;
|
||||
}
|
||||
|
||||
public List<Field> getAllField(){
|
||||
List<Field> fields = new ArrayList<>();
|
||||
if (this.getPages() != null){
|
||||
for (Page page: this.getPages()) {
|
||||
fields.addAll(page.getAllField());
|
||||
}
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
public List<FieldSet> getAllFieldSets(){
|
||||
List<FieldSet> fieldSets = new ArrayList<>();
|
||||
if (this.getPages() != null){
|
||||
for (Page page: this.getPages()) {
|
||||
fieldSets.addAll(page.getAllFieldSets());
|
||||
}
|
||||
}
|
||||
return fieldSets;
|
||||
}
|
||||
|
||||
public List<FieldSet> getFieldSetById(String id) {
|
||||
return this.getAllFieldSets().stream().filter(x-> id.equals(x.getId())).toList();
|
||||
}
|
||||
|
||||
public List<Field> getFieldById(String id) {
|
||||
return this.getAllField().stream().filter(x-> id.equals(x.getId())).toList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.opencdmp.model.descriptiontemplate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FieldSet {
|
||||
|
@ -113,4 +114,12 @@ public class FieldSet {
|
|||
public void setFields(List<Field> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
public List<Field> getAllField() {
|
||||
return this.getFields() == null ? new ArrayList<>() : this.getFields();
|
||||
}
|
||||
|
||||
public List<Field> getFieldById(String id) {
|
||||
return this.getAllField().stream().filter(x-> id.equals(x.getId())).toList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.opencdmp.model.descriptiontemplate;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Page {
|
||||
|
@ -52,6 +53,26 @@ public class Page {
|
|||
public void setSections(List<Section> sections) {
|
||||
this.sections = sections;
|
||||
}
|
||||
|
||||
public List<Field> getAllField(){
|
||||
List<Field> fields = new ArrayList<>();
|
||||
if (this.getSections() != null){
|
||||
for (Section section: this.getSections()) {
|
||||
fields.addAll(section.getAllField());
|
||||
}
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
public List<FieldSet> getAllFieldSets(){
|
||||
List<FieldSet> fieldSets = new ArrayList<>();
|
||||
if (this.getSections() != null){
|
||||
for (Section section: this.getSections()) {
|
||||
fieldSets.addAll(section.getAllFieldSets());
|
||||
}
|
||||
}
|
||||
return fieldSets;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.opencdmp.model.descriptiontemplate;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Section {
|
||||
|
@ -81,6 +82,34 @@ public class Section {
|
|||
public void setFieldSets(List<FieldSet> fieldSets) {
|
||||
this.fieldSets = fieldSets;
|
||||
}
|
||||
|
||||
public List<Field> getAllField(){
|
||||
List<Field> fields = new ArrayList<>();
|
||||
if (this.getFieldSets() != null){
|
||||
for (FieldSet fieldSet: this.getFieldSets()) {
|
||||
fields.addAll(fieldSet.getAllField());
|
||||
}
|
||||
}
|
||||
if (this.getSections() != null){
|
||||
for (Section sectionEntity: this.getSections()) {
|
||||
fields.addAll(sectionEntity.getAllField());
|
||||
}
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
public List<FieldSet> getAllFieldSets(){
|
||||
List<FieldSet> fieldSet = new ArrayList<>();
|
||||
if (this.getFieldSets() != null){
|
||||
fieldSet.addAll(this.getFieldSets());
|
||||
}
|
||||
if (this.getSections() != null){
|
||||
for (Section section: this.getSections()) {
|
||||
fieldSet.addAll(section.getAllFieldSets());
|
||||
}
|
||||
}
|
||||
return fieldSet;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -558,59 +558,85 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
|
|||
if (model == null)
|
||||
return;
|
||||
|
||||
Map<String, String> visibilityRulesMap = new HashMap<>();
|
||||
List<Field> fields = model.getAllField();
|
||||
if (!this.conventionService.isListNullOrEmpty(fields)){
|
||||
for (Field field: fields) {
|
||||
if (!this.conventionService.isListNullOrEmpty(field.getVisibilityRules())){
|
||||
field.getVisibilityRules().stream().map(x -> x.getTarget()).collect(Collectors.toList()).forEach(y -> {
|
||||
visibilityRulesMap.put(y, null);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (model.getPages() != null) {
|
||||
for (Page page : model.getPages()) {
|
||||
this.reassignPage(page);
|
||||
this.reassignPage(page, visibilityRulesMap);
|
||||
}
|
||||
}
|
||||
|
||||
for (Field field: model.getAllField()) {
|
||||
if (!this.conventionService.isListNullOrEmpty(field.getVisibilityRules())){
|
||||
for (Rule rule: field.getVisibilityRules()) {
|
||||
if (visibilityRulesMap.containsKey(rule.getTarget())) rule.setTarget(visibilityRulesMap.get(rule.getTarget()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void reassignPage(Page model) {
|
||||
private void reassignPage(Page model, Map<String, String> visibilityRulesMap) {
|
||||
if (model == null)
|
||||
return;
|
||||
model.setId(UUID.randomUUID().toString());
|
||||
|
||||
if (model.getSections() != null) {
|
||||
for (Section section : model.getSections()) {
|
||||
this.reassignSection(section);
|
||||
this.reassignSection(section, visibilityRulesMap);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void reassignSection(Section model) {
|
||||
private void reassignSection(Section model, Map<String, String> visibilityRulesMap) {
|
||||
if (model == null)
|
||||
return;
|
||||
model.setId(UUID.randomUUID().toString());
|
||||
|
||||
if (model.getSections() != null) {
|
||||
for (Section section : model.getSections()) {
|
||||
this.reassignSection(section);
|
||||
this.reassignSection(section, visibilityRulesMap);
|
||||
}
|
||||
}
|
||||
if (model.getFieldSets() != null) {
|
||||
for (org.opencdmp.model.descriptiontemplate.FieldSet fieldSet : model.getFieldSets()) {
|
||||
this.reassignFieldSet(fieldSet);
|
||||
this.reassignFieldSet(fieldSet, visibilityRulesMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void reassignFieldSet(org.opencdmp.model.descriptiontemplate.FieldSet model) {
|
||||
private void reassignFieldSet(org.opencdmp.model.descriptiontemplate.FieldSet model, Map<String, String> visibilityRulesMap) {
|
||||
if (model == null)
|
||||
return;
|
||||
model.setId(UUID.randomUUID().toString());
|
||||
|
||||
if (model.getFields() != null) {
|
||||
for (Field field : model.getFields()) {
|
||||
this.reassignField(field);
|
||||
this.reassignField(field, visibilityRulesMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void reassignField(Field model) {
|
||||
private void reassignField(Field model, Map<String, String> visibilityRulesMap) {
|
||||
if (model == null)
|
||||
return;
|
||||
model.setId(UUID.randomUUID().toString());
|
||||
String oldFieldId = model.getId();
|
||||
if (visibilityRulesMap != null && visibilityRulesMap.containsKey(oldFieldId)){
|
||||
model.setId(UUID.randomUUID().toString());
|
||||
visibilityRulesMap.put(oldFieldId, model.getId());
|
||||
} else {
|
||||
model.setId(UUID.randomUUID().toString());
|
||||
}
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
|
Loading…
Reference in New Issue