Package com.sparc.knappsack.forms

Examples of com.sparc.knappsack.forms.ApplicationForm


    private ApplicationForm applicationForm;
    private User user = mock(User.class);

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


                                       @ApiParam(name = "description", value = "The description of the application", required = true, internalDescription = "java.lang.String") @RequestParam(value = "description", required = true) String description,
                                       @ApiParam(name = "groupId", value = "The group that this application belongs to", required = true, internalDescription = "java.lang.Long") @RequestParam(value = "groupId", required = true) Long groupId,
                                       @ApiParam(name = "name", value = "The name of the application", required = true, internalDescription = "java.lang.String") @RequestParam(value = "name", required = true) String name,
                                       @ApiParam(name = "icon", value = "The icon image file", required = false, internalDescription = "org.springframework.web.multipart.MultipartFile") @RequestParam(value = "icon", required = false) MultipartFile icon) {

        ApplicationForm applicationForm = new ApplicationForm();
        applicationForm.setApplicationType(ApplicationType.valueOf(applicationType));
        applicationForm.setCategoryId(categoryId);
        applicationForm.setDescription(description);
        applicationForm.setGroupId(groupId);
        applicationForm.setName(name);
        if(icon != null) {
            applicationForm.setIcon(icon);
        }

        applicationForm.setContextPath(request.getHeader("origin") + request.getContextPath());

        return applicationService.getApplicationModel(applicationService.saveApplication(applicationForm).getId(), Application.class);
    }
View Full Code Here

    @PreAuthorize("isDomainAdmin() or hasRole('ROLE_ADMIN')")
    @RequestMapping(value = "/manager/addApplication", method = RequestMethod.GET)
    public String addApplication(Model model, @RequestParam(required = false) Long grp) {

        if (!model.containsAttribute("applicationForm")) {
            ApplicationForm applicationForm = new ApplicationForm();
            applicationForm.setApplicationVersion(new ApplicationVersionForm());
            applicationForm.setGroupId(grp);
            model.addAttribute("applicationForm", applicationForm);
        }

        User user = userService.getUserFromSecurityContext();
        Organization organization = user.getActiveOrganization();
View Full Code Here

        Application application = applicationService.get(id);

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

            ApplicationForm applicationForm = new ApplicationForm();
            applicationForm.setId(application.getId());
            applicationForm.setGroupId(application.getOwnedGroup().getId());
            applicationForm.setApplicationType(application.getApplicationType());
            applicationForm.setDescription(application.getDescription());
            applicationForm.setName(application.getName());
            applicationForm.setCategoryId(application.getCategory().getId());

            StorageService storageService = storageServiceFactory.getStorageService(application.getStorageConfiguration().getStorageType());

            AppFile icon = application.getIcon();
            if (icon != null) {
                MockMultipartFile iconMultipartFile = new MockMultipartFile(application.getIcon().getName(), application.getIcon().getName(), application.getIcon().getType(), new byte[0]);
                applicationForm.setIcon(iconMultipartFile);
                model.addAttribute("icon", appFileService.createImageModel(icon));
            }

            List<AppFile> screenShots = application.getScreenshots();
            List<MultipartFile> screenShotMultipartFiles = new ArrayList<MultipartFile>();
            List<ImageModel> screenshotImageModels = new ArrayList<ImageModel>();
            for (AppFile screenShot : screenShots) {
                MockMultipartFile screenShotMultipartFile = new MockMultipartFile(screenShot.getName(), screenShot.getName(), screenShot.getType(), storageService.getInputStream(screenShot));
                screenShotMultipartFiles.add(screenShotMultipartFile);
                screenshotImageModels.add(appFileService.createImageModel(screenShot));
            }
            applicationForm.setScreenshots(screenShotMultipartFiles);
            model.addAttribute("screenshots", screenshotImageModels);

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

        return ApplicationForm.class.isAssignableFrom(clazz);
    }

    @Override
    public void validate(Object target, Errors errors) {
        ApplicationForm applicationForm = (ApplicationForm) target;

        validateApplicationLimit(applicationForm, errors);

        if (applicationForm.getApplicationType() == null) {
            errors.rejectValue(APPLICATION_TYPE_FIELD, "applicationValidator.emptyApplicationType");
        }

        if (applicationForm.getName() == null || !StringUtils.hasText(applicationForm.getName())) {
            errors.rejectValue(NAME_FIELD, "applicationValidator.emptyName");
        }

        if (applicationForm.getDescription() == null || !StringUtils.hasText(applicationForm.getDescription())) {
            errors.rejectValue(DESCRIPTION_FIELD, "applicationValidator.emptyDescription");
        }

        if (applicationForm.getCategoryId() == null) {
            errors.rejectValue(CATEGORY_ID_FIELD, "applicationValidator.categoryId");
        }

        BufferedImage bufferedImage = imageValidator.createBufferedImage(applicationForm.getIcon());

        if (applicationForm.getIcon() != null && !imageValidator.isValidImageSize(applicationForm.getIcon(), 819200 /*Bytes: 800 KB*/)) {
            errors.rejectValue(ICON_FIELD, "validator.invalidIconSize");
        }

        if (applicationForm.getIcon() != null && !imageValidator.isValidImageType(applicationForm.getIcon())) {
            errors.rejectValue(ICON_FIELD, "validator.invalidIconType");
        }

        if (applicationForm.getIcon() != null && (!imageValidator.isValidMinDimensions(bufferedImage, 72, 72) || !imageValidator.isSquare(bufferedImage))) {
            errors.rejectValue(ICON_FIELD, "validator.invalidIconDimension");
        }

        validateScreenShots(applicationForm, errors);

View Full Code Here

    }

    @Test
    public void saveApplicationTest() {
        Application application = getApplication();
        ApplicationForm applicationForm = new ApplicationForm();
        applicationForm.setApplicationType(application.getApplicationType());
        applicationForm.setCategoryId(application.getCategory().getId());
        applicationForm.setName("New Application");
        applicationForm.setDescription(application.getDescription());
        applicationForm.setGroupId(application.getCategory().getOrganization().getGroups().get(0).getId());
        Application newApplication = applicationService.saveApplication(applicationForm);
        Assert.assertNotNull(newApplication);
    }
View Full Code Here

TOP

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

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.