Package com.sparc.knappsack.components.entities

Examples of com.sparc.knappsack.components.entities.Domain


        assertFalse(validator.supports(String.class));
    }

    @Test
    public void testValid() {
        Domain domain = new Organization();
        domain.setId(1L);
        domain.getUuid();

        form.setDomainUUID(domain.getUuid());
        form.setAddress("testAddress");
        form.setCompanyName("testCompany");
        form.setEmailAddress("test@test.com");
        form.setFirstName("firstName");
        form.setLastName("lastName");
        form.setRegion(1L);
        form.setDeviceType(DeviceType.IPAD_1);
        form.setPhoneNumber("1231231234");
        form.getLanguages().add(Language.ENGLISH);

        Mockito.when(domainService.getByUUID(form.getDomainUUID())).thenReturn(domain);
        Mockito.when(domainService.getDomainForRegion(form.getRegion())).thenReturn(domain);
        Mockito.when(domainRequestService.doesDomainRequestExist(domain.getId(), form.getEmailAddress())).thenReturn(false);

        validator.validate(form, errors);
        assertEquals(errors.getErrorCount(), 0);

    }
View Full Code Here


    }

    @Test
    public void testInvalid() {
        Domain domain = new Organization();
        domain.getUuid();

        Mockito.when(domainService.getByUUID(form.getDomainUUID())).thenReturn(null);
        Mockito.when(domainService.getDomainForRegion(form.getRegion())).thenReturn(null);
        Mockito.when(domainRequestService.doesDomainRequestExist(domain.getId(), form.getEmailAddress())).thenReturn(true);

        validator.validate(form, errors);
        assertEquals(errors.getErrorCount(), 10);

        setup();

        Mockito.when(domainService.getByUUID(form.getDomainUUID())).thenReturn(null);
        Mockito.when(domainService.getDomainForRegion(form.getRegion())).thenReturn(null);
        Mockito.when(domainRequestService.doesDomainRequestExist(domain.getId(), form.getEmailAddress())).thenReturn(true);

        validator.validate(form, errors);
        assertEquals(errors.getErrorCount(), 10);
    }
View Full Code Here

        assertEquals(errors.getErrorCount(), 10);
    }

    @Test
    public void testRequestExists() {
        Domain domain = new Organization();
        domain.setId(1L);
        domain.getUuid();

        form.setDomainUUID(domain.getUuid());
        form.setAddress("testAddress");
        form.setCompanyName("testCompany");
        form.setEmailAddress("test@test.com");
        form.setFirstName("firstName");
        form.setLastName("lastName");
        form.setRegion(1L);
        form.setDeviceType(DeviceType.IPAD_1);
        form.setPhoneNumber("1231231234");
        form.getLanguages().add(Language.ENGLISH);

        Mockito.when(domainService.getByUUID(form.getDomainUUID())).thenReturn(domain);
        Mockito.when(domainService.getDomainForRegion(form.getRegion())).thenReturn(domain);
        Mockito.when(domainRequestService.doesDomainRequestExist(domain.getId(), form.getEmailAddress())).thenReturn(true);

        validator.validate(form, errors);
        assertEquals(errors.getErrorCount(), 1);
        assertEquals(errors.getGlobalErrorCount(), 1);
    }
View Full Code Here

        result.setResult(false);
        boolean success = false;

        DomainRequest domainRequest = domainRequestService.get(requestId);
        for (Long domainId : domainIds) {
            Domain assignedDomain = domainService.get(domainId);
            InviteeForm inviteeForm = new InviteeForm();
            inviteeForm.setEmail(domainRequest.getEmailAddress());
            inviteeForm.setName(domainRequest.getFirstName() + " " + domainRequest.getLastName());
            UserRole userRole = DomainType.GROUP.equals(assignedDomain.getDomainType()) ? UserRole.ROLE_GROUP_USER : UserRole.ROLE_ORG_USER;
            inviteeForm.setUserRole(userRole);
            success = invitationControllerService.inviteUserToDomain(domainRequest.getEmailAddress(), domainId, userRole, false);
        }

        domainRequestService.delete(requestId);
View Full Code Here

    }

    @PreAuthorize("isDomainAdmin(#id) or hasRole('ROLE_ADMIN')")
    @RequestMapping(value = "/manager/requestsPending/{id}", method = RequestMethod.GET)
    public String requestsPending(@PathVariable Long id, Model model) {
        Domain domain = domainService.get(id);
        if (domain == null) {
            throw new EntityNotFoundException(String.format("Domain entity not found while viewing pending invites: %s", id));
        }
        model.addAttribute("domainType", domain.getDomainType().name());
        model.addAttribute("domainName", domain.getName());
        model.addAttribute("domainId", domain.getId());

        List<DomainRequestModel> domainRequestModels = domainRequestService.getAllDomainRequestModelsForDomain(id);
        model.addAttribute("domainRequests", domainRequestModels);

        return "manager/requestsTH";
View Full Code Here

    private DomainConfigurationService domainConfigurationService;

    @PreAuthorize("hasDomainConfigurationAccess(#domainId) or hasRole('ROLE_ADMIN')")
    @RequestMapping(value = "/manager/domainConfiguration/{domainId}", method = RequestMethod.GET)
    public String domainConfiguration(Model model, @PathVariable Long domainId) {
        Domain domain = domainService.get(domainId);
        if (domain == null) {
            throw new EntityNotFoundException(String.format("Domain entity not found while viewing DomainConfiguration page: %s", domainId));
        }
        DomainConfiguration domainConfiguration = domain.getDomainConfiguration() == null ? new DomainConfiguration() : domain.getDomainConfiguration();
        DomainConfigurationForm domainConfigurationForm = getDomainConfigurationForm(domain.getId(), domainConfiguration);

        model.addAttribute("domain", domain);
        model.addAttribute("domainConfiguration", domainConfigurationForm);
        model.addAttribute("domainType", domain.getDomainType().name());
        setSideBarNavAttribute(model, domain.getDomainType());

        return "manager/domainConfigurationTH";
    }
View Full Code Here

    }

    @PreAuthorize("hasDomainConfigurationAccess(#domainConfigurationForm.domainId) or hasRole('ROLE_ADMIN')")
    @RequestMapping(value = "/manager/saveDomainConfiguration", method = RequestMethod.POST)
    public String saveDomainConfiguration(Model model, @ModelAttribute DomainConfigurationForm domainConfigurationForm) {
        Domain domain = domainService.get(domainConfigurationForm.getDomainId());
        if (domain == null) {
            throw new EntityNotFoundException(String.format("Domain entity not found while saving DomainConfiguration: %s", domainConfigurationForm.getDomainId()));
        }
        model.addAttribute("domain", domain);

        DomainConfiguration domainConfiguration = getDomainConfiguration(domain, domainConfigurationForm);
        domainConfigurationService.update(domainConfiguration);
        model.addAttribute("domainConfiguration", domainConfigurationForm);
        model.addAttribute("domainType", domain.getDomainType().name());
        model.addAttribute("success", true);
        setSideBarNavAttribute(model, domain.getDomainType());

        return "manager/domainConfigurationTH";
    }
View Full Code Here

    }

    @PreAuthorize("isDomainAdmin(#domainId) or hasRole('ROLE_ADMIN')")
    @RequestMapping(value = "/{domainId}", method = RequestMethod.GET)
    public String viewDomainRegionsPage(HttpServletRequest request, Model model, @PathVariable Long domainId) {
        Domain domain = domainService.get(domainId);

        if (domain != null) {

            if (!model.containsAttribute("domainRegionForm")) {
                DomainRegionForm domainRegionForm = new DomainRegionForm();
                domainRegionForm.setDomainId(domainId);

                model.addAttribute("domainRegionForm", domainRegionForm);
            }

            model.addAttribute("domainId", domainId);
            model.addAttribute("domainName", domain.getName());
            model.addAttribute("domainType", domain.getDomainType());

            if (domain != null) {
                setSideBarNavAttribute(model, domain.getDomainType());
            }
        } else {
            log.info(String.format("Domain not found with id: %s", domainId));
            throw new EntityNotFoundException(String.format("Domain not found with id: %s", domainId));
        }
View Full Code Here

    @RequestMapping(value = "/getAllForDomain", method = RequestMethod.GET)
    public @ResponseBody
    List<RegionModel> getAllForDomain(@RequestParam(value = "id", required = true) Long domainId) {
        List<RegionModel> models = new ArrayList<RegionModel>();

        Domain domain = domainService.get(domainId);

        if (domain != null) {
            for (Region region : domain.getRegions()) {
                RegionModel model = regionService.createRegionModel(region);

                if (model != null) {
                    models.add(model);
                }
View Full Code Here

    @Override
    public void validate(Object target, Errors errors) {
        DomainRequestForm domainRequestForm = (DomainRequestForm) target;

        Domain domain = domainService.getByUUID(domainRequestForm.getDomainUUID());
        if (!doesBindingErrorExist(errors, DOMAIN_UUID_FIELD) && domain == null) {
            errors.reject(DOMAIN_UUID_FIELD, "domainRequestValidator.domainUUID.invalid");
        }

        if (!doesBindingErrorExist(errors, FIRST_NAME_FIELD) && !StringUtils.hasText(domainRequestForm.getFirstName())) {
            errors.rejectValue(FIRST_NAME_FIELD, "domainRequestValidator.firstName.empty");
        }

        if (!doesBindingErrorExist(errors, LAST_NAME_FIELD) && !StringUtils.hasText(domainRequestForm.getLastName())) {
            errors.rejectValue(LAST_NAME_FIELD, "domainRequestValidator.lastName.empty");
        }

        if (!doesBindingErrorExist(errors, COMPANY_NAME_FIELD) && !StringUtils.hasText(domainRequestForm.getCompanyName())) {
            errors.rejectValue(COMPANY_NAME_FIELD, "domainRequestValidator.companyName.empty");
        }

        if (!doesBindingErrorExist(errors, ADDRESS_FIELD) && !StringUtils.hasText(domainRequestForm.getAddress())) {
            errors.rejectValue(ADDRESS_FIELD, "domainRequestValidator.address.empty");
        }

        if (!doesBindingErrorExist(errors, PHONE_FIELD) && !StringUtils.hasText(domainRequestForm.getPhoneNumber())) {
            errors.rejectValue(PHONE_FIELD, "domainRequestValidator.phoneNumber.empty");
        }

        if (!doesBindingErrorExist(errors, EMAIL_ADDRESS_FIELD) && !StringUtils.hasText(domainRequestForm.getEmailAddress()) || !doesRegexMatch(domainRequestForm.getEmailAddress(), emailPattern)) {
            errors.rejectValue(EMAIL_ADDRESS_FIELD, "domainRequestValidator.emailAddress.invalid");
        }

        if (!doesBindingErrorExist(errors, DEVICE_TYPE_FIELD) && domainRequestForm.getDeviceType() == null) {
            errors.rejectValue(DEVICE_TYPE_FIELD, "domainRequestValidator.deviceType.empty");
        }

        if (!doesBindingErrorExist(errors, REGION_FIELD)) {
            Domain domainForRegion = domainService.getDomainForRegion(domainRequestForm.getRegion());
            if (domainForRegion == null || !domainForRegion.equals(domain)) {
                errors.rejectValue(REGION_FIELD, "domainRequestValidator.region.invalid");
            }
        }

        if (!doesFieldErrorExist(errors, EMAIL_ADDRESS_FIELD) && !doesFieldErrorExist(errors, DOMAIN_UUID_FIELD) && !doesFieldErrorExist(errors, REGION_FIELD) && domainRequestService.doesDomainRequestExist(domain.getId(), domainRequestForm.getEmailAddress())) {
View Full Code Here

TOP

Related Classes of com.sparc.knappsack.components.entities.Domain

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.