Ejemplo n.º 1
0
 private void initializeMaterials(Set<Material> materials) {
     for (Material each: materials) {
         each.getDescription();
         if (each.getUnitType() != null) {
             each.getUnitType().getMeasure();
         }
     }
 }
Ejemplo n.º 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());
         }
     }
 }
Ejemplo n.º 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));
         }
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 5
0
 @Override
 @Transactional(readOnly = true)
 public boolean canRemoveMaterial(Material material) {
     if(material.isNewObject()) {
         return true;
     }
     return materialAssignmentDAO.getByMaterial(material).size() == 0;
 }
Ejemplo n.º 6
0
 @Override
 public void removeMaterial(Material material) {
     material.getCategory().removeMaterial(material);
 }
Ejemplo n.º 7
0
 private String asStringForUser(Material material) {
     return String.format("{code: %s, description: %s}", material.getCode(),
             material
             .getDescription());
 }
Ejemplo n.º 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());
 }
Ejemplo n.º 9
0
 @Override
 public void addMaterialToMaterialCategory(MaterialCategory materialCategory) {
     Material material = Material.create("");
     material.setCategory(materialCategory);
     materialCategory.addMaterial(material);
 }