Package com.sparc.knappsack.forms

Examples of com.sparc.knappsack.forms.CategoryForm


    private Errors errors;
    private CategoryForm categoryForm;

    @Before
    public void setup() {
        categoryForm = new CategoryForm();
        errors = new BeanPropertyBindingResult(categoryForm, "categoryForm");
    }
View Full Code Here


        Organization organization = organizationService.get(orgId);

        if (organization != null) {
            if (!model.containsAttribute("category")) {
                CategoryForm categoryForm = new CategoryForm();
                categoryForm.setOrganizationId(organization.getId());
                categoryForm.setOrgStorageConfigId(organization.getOrgStorageConfig().getId());

                model.addAttribute("category", categoryForm);
            }

            model.addAttribute("parentOrgId", organization.getId());
View Full Code Here

        }

        if (!model.containsAttribute("category")) {

            if (category != null) {
                CategoryForm categoryForm = new CategoryForm();
                categoryForm.setDescription(category.getDescription());
                categoryForm.setId(category.getId());
                categoryForm.setName(category.getName());
                categoryForm.setStorageConfigurationId(category.getStorageConfiguration().getId());

                AppFile icon = category.getIcon();
                if (icon != null) {
                    MockMultipartFile iconMultipartFile = new MockMultipartFile(category.getIcon().getName(), category.getIcon().getName(), category.getIcon().getType(), new byte[0]);
                    categoryForm.setIcon(iconMultipartFile);
                }

                model.addAttribute("category", categoryForm);
            }
        }
View Full Code Here

        return CategoryForm.class.isAssignableFrom(clazz);
    }

    @Override
    public void validate(Object target, Errors errors) {
        CategoryForm category = (CategoryForm) target;
        if (category.getName() == null || category.getName().isEmpty()) {
            errors.rejectValue(NAME_FIELD, "categoryValidator.emptyName");
        }

        if (category.getDescription() == null || category.getDescription().isEmpty()) {
            errors.rejectValue(DESCRIPTION_FIELD, "categoryValidator.emptyDescription");
        }

        if (category.isEditing()) {
            if (category.getIcon() != null && !category.getIcon().isEmpty()) {
                validateImageAttributes(category.getIcon(), errors);
            }
        } else {
            if (category.getIcon() == null || category.getIcon().isEmpty()) {
                errors.rejectValue(ICON_FIELD, "categoryValidator.emptyIcon");
            } else {
                validateImageAttributes(category.getIcon(), errors);
            }
        }
    }
View Full Code Here

        Organization organization = getOrganization();

        List<Category> categories = categoryService.getAll();
        assertTrue(categories.size() == 0);

        CategoryForm categoryForm = new CategoryForm();
        categoryForm.setName("Test Category");
        categoryForm.setDescription("Test Description");
        categoryForm.setEditing(false);
        categoryForm.setOrganizationId(organization.getId());
        categoryForm.setStorageConfigurationId(organization.getStorageConfigurations().get(0).getId());
        Category category = categoryService.saveCategory(categoryForm);
        categories = categoryService.getAll();
        assertTrue(categories.size() == 1);
        assertTrue(category.getName().equals("Test Category"));
    }
View Full Code Here

        Organization organization = getOrganization();

        List<Category> categories = categoryService.getAll();
        assertTrue(categories.size() == 0);

        CategoryForm categoryForm = new CategoryForm();
        categoryForm.setName("Test Category");
        categoryForm.setDescription("Test Description");
        categoryForm.setEditing(false);
        categoryForm.setOrganizationId(organization.getId());
        categoryForm.setStorageConfigurationId(organization.getStorageConfigurations().get(0).getId());
        Category category = categoryService.saveCategory(categoryForm);
        categories = categoryService.getAll();
        assertTrue(categories.size() == 1);
        assertTrue(category.getName().equals("Test Category"));

        categoryForm.setName("Test Category 2");
        categoryForm.setId(category.getId());
        categoryService.updateCategory(categoryForm);
        categories = categoryService.getAll();
        assertTrue(categories.size() == 1);
        assertTrue(category.getName().equals("Test Category 2"));
    }
View Full Code Here

TOP

Related Classes of com.sparc.knappsack.forms.CategoryForm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.