handle error when import blueprint description template not found
This commit is contained in:
parent
dc3e26e581
commit
76c29f8b79
|
@ -11,6 +11,8 @@ import java.util.UUID;
|
||||||
public class BlueprintDescriptionTemplateImportExport {
|
public class BlueprintDescriptionTemplateImportExport {
|
||||||
@XmlElement(name = "descriptionTemplateGroupId")
|
@XmlElement(name = "descriptionTemplateGroupId")
|
||||||
private UUID descriptionTemplateGroupId;
|
private UUID descriptionTemplateGroupId;
|
||||||
|
@XmlElement(name = "descriptionTemplateCode")
|
||||||
|
private String descriptionTemplateCode;
|
||||||
@XmlElement(name = "label")
|
@XmlElement(name = "label")
|
||||||
private String label;
|
private String label;
|
||||||
@XmlAttribute(name = "minMultiplicity")
|
@XmlAttribute(name = "minMultiplicity")
|
||||||
|
@ -26,6 +28,14 @@ public class BlueprintDescriptionTemplateImportExport {
|
||||||
this.descriptionTemplateGroupId = descriptionTemplateGroupId;
|
this.descriptionTemplateGroupId = descriptionTemplateGroupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDescriptionTemplateCode() {
|
||||||
|
return descriptionTemplateCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionTemplateCode(String descriptionTemplateCode) {
|
||||||
|
this.descriptionTemplateCode = descriptionTemplateCode;
|
||||||
|
}
|
||||||
|
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return this.label;
|
return this.label;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,10 @@ public class DescriptionTemplatePersist {
|
||||||
|
|
||||||
public static final String _descriptionTemplateGroupId = "descriptionTemplateGroupId";
|
public static final String _descriptionTemplateGroupId = "descriptionTemplateGroupId";
|
||||||
|
|
||||||
|
private String descriptionTemplateCode;
|
||||||
|
public static final String _descriptionTemplateCode = "descriptionTemplateCode";
|
||||||
|
|
||||||
|
|
||||||
private String label;
|
private String label;
|
||||||
|
|
||||||
public static final String _label = "label";
|
public static final String _label = "label";
|
||||||
|
|
|
@ -581,7 +581,7 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService {
|
||||||
List<BlueprintDescriptionTemplateImportExport> planBlueprintDescriptionTemplates = new LinkedList<>();
|
List<BlueprintDescriptionTemplateImportExport> planBlueprintDescriptionTemplates = new LinkedList<>();
|
||||||
if (!this.conventionService.isListNullOrEmpty(entity.getDescriptionTemplates())) {
|
if (!this.conventionService.isListNullOrEmpty(entity.getDescriptionTemplates())) {
|
||||||
for (DescriptionTemplateEntity descriptionTemplate : entity.getDescriptionTemplates()) {
|
for (DescriptionTemplateEntity descriptionTemplate : entity.getDescriptionTemplates()) {
|
||||||
planBlueprintDescriptionTemplates.add(this.prefillingSourceXmlToExport(descriptionTemplate));
|
planBlueprintDescriptionTemplates.add(this.blueprintDescriptionTemplateXmlToExport(descriptionTemplate));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xml.setDescriptionTemplates(planBlueprintDescriptionTemplates);
|
xml.setDescriptionTemplates(planBlueprintDescriptionTemplates);
|
||||||
|
@ -596,8 +596,11 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService {
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlueprintDescriptionTemplateImportExport prefillingSourceXmlToExport(DescriptionTemplateEntity entity) {
|
private BlueprintDescriptionTemplateImportExport blueprintDescriptionTemplateXmlToExport(DescriptionTemplateEntity entity) {
|
||||||
BlueprintDescriptionTemplateImportExport xml = new BlueprintDescriptionTemplateImportExport();
|
BlueprintDescriptionTemplateImportExport xml = new BlueprintDescriptionTemplateImportExport();
|
||||||
|
org.opencdmp.data.DescriptionTemplateEntity data = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().groupIds(entity.getDescriptionTemplateGroupId()).disableTracking().firstAs(new BaseFieldSet().ensure(org.opencdmp.data.DescriptionTemplateEntity._code));
|
||||||
|
|
||||||
|
if (data != null) xml.setDescriptionTemplateCode(data.getCode());
|
||||||
xml.setDescriptionTemplateGroupId(entity.getDescriptionTemplateGroupId());
|
xml.setDescriptionTemplateGroupId(entity.getDescriptionTemplateGroupId());
|
||||||
xml.setLabel(entity.getLabel());
|
xml.setLabel(entity.getLabel());
|
||||||
if (entity.getMinMultiplicity() != null ) xml.setMinMultiplicity(entity.getMinMultiplicity());
|
if (entity.getMinMultiplicity() != null ) xml.setMinMultiplicity(entity.getMinMultiplicity());
|
||||||
|
@ -797,11 +800,20 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private DescriptionTemplatePersist xmlDescriptionTemplateToPersist(BlueprintDescriptionTemplateImportExport importXml) {
|
private DescriptionTemplatePersist xmlDescriptionTemplateToPersist(BlueprintDescriptionTemplateImportExport importXml) {
|
||||||
org.opencdmp.data.DescriptionTemplateEntity data = importXml.getDescriptionTemplateGroupId() != null ? this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().groupIds(importXml.getDescriptionTemplateGroupId()).disableTracking().firstAs(new BaseFieldSet().ensure(DescriptionTemplate._groupId)) : null;
|
|
||||||
if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{importXml.getDescriptionTemplateGroupId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
|
||||||
|
|
||||||
DescriptionTemplatePersist persist = new DescriptionTemplatePersist();
|
DescriptionTemplatePersist persist = new DescriptionTemplatePersist();
|
||||||
persist.setDescriptionTemplateGroupId(importXml.getDescriptionTemplateGroupId());
|
|
||||||
|
org.opencdmp.data.DescriptionTemplateEntity data = importXml.getDescriptionTemplateGroupId() != null ? this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().groupIds(importXml.getDescriptionTemplateGroupId()).disableTracking().firstAs(new BaseFieldSet().ensure(DescriptionTemplate._groupId)) : null;
|
||||||
|
if (data != null ) {
|
||||||
|
persist.setDescriptionTemplateGroupId(importXml.getDescriptionTemplateGroupId());
|
||||||
|
} else {
|
||||||
|
if (!this.conventionService.isNullOrEmpty(importXml.getDescriptionTemplateCode())) {
|
||||||
|
data = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().codes(importXml.getDescriptionTemplateCode()).disableTracking().firstAs(new BaseFieldSet().ensure(DescriptionTemplate._code).ensure(DescriptionTemplate._groupId));
|
||||||
|
if (data != null) persist.setDescriptionTemplateGroupId(data.getGroupId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data == null) throw new MyValidationException(this.errors.getDescriptionTemplateImportNotFound().getCode(), !this.conventionService.isNullOrEmpty(importXml.getDescriptionTemplateCode()) ? importXml.getDescriptionTemplateCode() : importXml.getDescriptionTemplateGroupId().toString());
|
||||||
|
|
||||||
persist.setLabel(importXml.getLabel());
|
persist.setLabel(importXml.getLabel());
|
||||||
persist.setMinMultiplicity(importXml.getMinMultiplicity());
|
persist.setMinMultiplicity(importXml.getMinMultiplicity());
|
||||||
persist.setMaxMultiplicity(importXml.getMaxMultiplicity());
|
persist.setMaxMultiplicity(importXml.getMaxMultiplicity());
|
||||||
|
|
Loading…
Reference in New Issue