示例#1
0
 private boolean equalsMaterialCategory(MaterialCategory obj1, MaterialCategory obj2) {
     String name1 = StringUtils.deleteWhitespace(obj1.getName()
             .toLowerCase());
     String name2 = StringUtils.deleteWhitespace(obj2.getName()
             .toLowerCase());
     return name1.equals(name2);
 }
示例#2
0
    @Override
    @Transactional
    public void confirmRemoveMaterialCategory(MaterialCategory materialCategory) {
        // Remove from list of material categories
        materialCategories.remove(materialCategory);

        // Remove from its parent
        final MaterialCategory parent = materialCategory.getParent();
        if (parent != null) {
            materialCategory.getParent().removeSubcategory(materialCategory);
        }

        final Long idMaterialCategory = materialCategory.getId();
        // It's not a yet-to-save element
        if (idMaterialCategory != null) {
            // It has a parent, in this case is enough with saving parent (all-delete-orphan)
            if (parent != null) {
                categoryDAO.save(materialCategory.getParent());
            } else {
                // It was a root element, should be deleted from DB
                try {
                    categoryDAO.remove(idMaterialCategory);
                } catch (InstanceNotFoundException e) {
                    throw new RuntimeException();
                }
            }
            reloadMaterialCategories();
        }
    }
示例#3
0
 private void generateMaterialCodesIfIsNecessary(List<MaterialCategory> categories,
         Integer numberOfDigits) {
     for (MaterialCategory category: categories) {
         if (category.isCodeAutogenerated()) {
             category.generateMaterialCodes(numberOfDigits);
         }
     }
 }
示例#4
0
 @Override
 @Transactional(readOnly = true)
 public Collection<? extends Material> getMaterials() {
     List<Material> result = new ArrayList<Material>();
     for (MaterialCategory each: materialCategories.asList()) {
         result.addAll(each.getMaterials());
     }
     return result;
 }
示例#5
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());
         }
     }
 }
示例#6
0
 private void initializeMaterialCategories() {
     final List<MaterialCategory> categories = categoryDAO.getAllRootMaterialCategories();
     for (MaterialCategory materialCategory: categories) {
         initializeMaterials(materialCategory.getMaterials());
         materialCategories.addToRoot(materialCategory);
         addCategories(materialCategory, materialCategory.getSubcategories());
         storeOldCodes(materialCategory);
     }
 }
示例#7
0
 private void addCategories(MaterialCategory materialCategory, Set<MaterialCategory> categories) {
     for (MaterialCategory category: categories) {
         initializeMaterials(category.getMaterials());
         materialCategories.add(materialCategory, category);
         storeOldCodes(category);
         final Set<MaterialCategory> subcategories = category.getSubcategories();
         if (subcategories != null) {
             addCategories(category, subcategories);
         }
     }
 }
示例#8
0
 @Override
 @Transactional(readOnly=true)
 public List<Material> getMaterials(MaterialCategory materialCategory) {
     List<Material> result = new ArrayList<Material>();
     result.addAll(materialCategory.getMaterials());
     return result;
 }
示例#9
0
    @Override
    @Transactional(readOnly=true)
    public void addMaterialCategory(MaterialCategory parent, String categoryName) throws ValidationException {
        Validate.notNull(categoryName);

        Boolean generateCode = configurationDAO.getConfiguration()
                .getGenerateCodeForMaterialCategories();
        MaterialCategory child = MaterialCategory.createUnvalidated("",
                _(categoryName));
        if (generateCode) {
            setCurrentMaterialCategory(child);
            setDefaultCode();
        }
        child.setCodeAutogenerated(generateCode);

        final MaterialCategory materialCategory = findMaterialCategory(child);
        if (materialCategory != null) {
            throw new ValidationException(invalidValue(
                    _("{0} already exists", materialCategory.getName()),
                    "name", materialCategory.getName(), materialCategory));
        }

        child.setParent(parent);
        if (parent == null) {
            materialCategories.addToRoot(child);
        } else {
            materialCategories.add(parent, child);
        }
    }
示例#10
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);
     }
 }
示例#11
0
 @Override
 public void addMaterialToMaterialCategory(MaterialCategory materialCategory) {
     Material material = Material.create("");
     material.setCategory(materialCategory);
     materialCategory.addMaterial(material);
 }