private void initializeMaterials(Set<Material> materials) { for (Material each: materials) { each.getDescription(); if (each.getUnitType() != null) { each.getUnitType().getMeasure(); } } }
private void storeOldCodes(MaterialCategory materialCategory) { // it stores temporaly the autogenerated code. if (materialCategory.isCodeAutogenerated()) { oldCodes.put(materialCategory, materialCategory.getCode()); for (Material child : materialCategory.getMaterials()) { oldMaterialCodes.put(child, child.getCode()); } } }
@Override protected void restoreOldCodes() { getCurrentEntity().setCode(oldCodes.get(getCurrentEntity())); for (Material child : ((MaterialCategory) getCurrentEntity()) .getMaterials()) { if (!child.isNewObject()) { child.setCode(oldMaterialCodes.get(child)); } } }
private void checkNoCodeRepeatedAtNewMaterials( final List<MaterialCategory> categories) throws ValidationException { List<Material> allMaterials = MaterialCategory .getAllMaterialsWithoutAutogeneratedCodeFrom(categories); Map<String, Material> byCode = new HashMap<String, Material>(); for (Material each : allMaterials) { if (byCode.containsKey(each.getCode())) { throw new ValidationException(sameCodeMessage(each, byCode .get(each.getCode()))); } byCode.put(each.getCode(), each); } }
@Override @Transactional(readOnly = true) public boolean canRemoveMaterial(Material material) { if(material.isNewObject()) { return true; } return materialAssignmentDAO.getByMaterial(material).size() == 0; }
@Override public void removeMaterial(Material material) { material.getCategory().removeMaterial(material); }
private String asStringForUser(Material material) { return String.format("{code: %s, description: %s}", material.getCode(), material .getDescription()); }
private String sameCodeMessage(Material first, Material second) { return _( "both {0} of category {1} and {2} of category {3} have the same code", asStringForUser(first), first.getCategory().getName(), asStringForUser(second), second.getCategory().getName()); }
@Override public void addMaterialToMaterialCategory(MaterialCategory materialCategory) { Material material = Material.create(""); material.setCategory(materialCategory); materialCategory.addMaterial(material); }