Beispiel #1
0
 private void initializeMaterials(Set<Material> materials) {
     for (Material each: materials) {
         each.getDescription();
         if (each.getUnitType() != null) {
             each.getUnitType().getMeasure();
         }
     }
 }
Beispiel #2
0
 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());
         }
     }
 }
Beispiel #3
0
 @Override
 protected void restoreOldCodes() {
     getCurrentEntity().setCode(oldCodes.get(getCurrentEntity()));
     for (Material child : ((MaterialCategory) getCurrentEntity())
             .getMaterials()) {
         if (!child.isNewObject()) {
             child.setCode(oldMaterialCodes.get(child));
         }
     }
 }
Beispiel #4
0
 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);
     }
 }
Beispiel #5
0
 @Override
 @Transactional(readOnly = true)
 public boolean canRemoveMaterial(Material material) {
     if(material.isNewObject()) {
         return true;
     }
     return materialAssignmentDAO.getByMaterial(material).size() == 0;
 }
Beispiel #6
0
 @Override
 public void removeMaterial(Material material) {
     material.getCategory().removeMaterial(material);
 }
Beispiel #7
0
 private String asStringForUser(Material material) {
     return String.format("{code: %s, description: %s}", material.getCode(),
             material
             .getDescription());
 }
Beispiel #8
0
 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());
 }
Beispiel #9
0
 @Override
 public void addMaterialToMaterialCategory(MaterialCategory materialCategory) {
     Material material = Material.create("");
     material.setCategory(materialCategory);
     materialCategory.addMaterial(material);
 }