&& (materialCategory.getParent() != null)
&& (!materialCategory.getParent().getCode().equalsIgnoreCase(
materialCategoryDTO.parent)))
|| ((!(materialCategoryDTO.parent == null) && (materialCategory
.getParent() == null)))) {
throw new ValidationException("inconsistent parent code.");
}
/*
* 1: Update basic properties in existing material category and add new
* materials.
*/
if (materialCategoryDTO.materials != null) {
for (MaterialDTO materialDTO : materialCategoryDTO.materials) {
/* Step 1.1 requires each material DTO to have a code. */
if (StringUtils.isBlank(materialDTO.code)) {
throw new ValidationException("missing code in a material");
}
try {
Material material = materialCategory
.getMaterialByCode(materialDTO.code);
updateMaterial(material, materialDTO);
} catch (InstanceNotFoundException e) {
materialCategory.addMaterial(toEntity(materialDTO));
}
}
}
/*
* 2: Update basic properties in existing subcategories and add new
* subcategories.
*/
if (materialCategoryDTO.subcategories != null) {
for (MaterialCategoryDTO subcategoryDTO : materialCategoryDTO.subcategories.materialCategoryDTOs) {
/* Step 2.1 requires each subcategory DTO to have a code. */
if (StringUtils.isBlank(subcategoryDTO.code)) {
throw new ValidationException(
"missing code in a subcategory");
}
try {
MaterialCategory subcategory = materialCategory