Search in sources :

Example 1 with Contract

use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.

the class LoginController method displayDemoPage.

@RequestMapping(value = TgolKeyStore.DEMO_URL, method = RequestMethod.GET)
public String displayDemoPage(HttpServletRequest request, HttpServletResponse response, Model model) {
    Locale locale = localeResolver.resolveLocale(request);
    String languageKey = locale.getLanguage().toLowerCase();
    String lGuestUser = null;
    if (guestListByLang.containsKey(languageKey)) {
        lGuestUser = guestListByLang.get(languageKey);
    } else if (guestListByLang.containsKey("default")) {
        lGuestUser = guestListByLang.get("default");
    }
    if (StringUtils.isBlank(lGuestUser) || StringUtils.isBlank(guestPassword)) {
        return TgolKeyStore.NO_DEMO_AVAILABLE_VIEW_NAME;
    }
    if (isAuthenticated()) {
        return TgolKeyStore.ACCESS_DENIED_VIEW_NAME;
    }
    if (guestUserDetails == null) {
        try {
            guestUserDetails = tgolUserDetailsService.loadUserByUsername(lGuestUser);
        } catch (UsernameNotFoundException unfe) {
            return TgolKeyStore.NO_DEMO_AVAILABLE_VIEW_NAME;
        }
    }
    doGuestAutoLogin(request, lGuestUser);
    if (forbiddenLangForOnlineDemo.contains(languageKey)) {
        return TgolKeyStore.HOME_VIEW_REDIRECT_NAME;
    }
    Collection<Contract> contractSet = getContractDataService().getAllContractsByUser(getCurrentUser());
    if (contractSet == null || contractSet.isEmpty()) {
        return TgolKeyStore.NO_DEMO_AVAILABLE_VIEW_NAME;
    }
    String contractId = contractSet.iterator().next().getId().toString();
    model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contractId);
    return TgolKeyStore.AUDIT_PAGE_SET_UP_REDIRECT_NAME;
}
Also used : Locale(java.util.Locale) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) Contract(org.asqatasun.webapp.entity.contract.Contract) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Contract

use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.

the class PageListController method pageLinkDispatcher.

/**
     * This method dispatches the result depending on the parameters passed to
     * the request. Only multi-pages audit are considered here.
     *
     * @param request
     * @param webResource
     * @param model
     * @return
     * @throws Exception
     */
private String pageLinkDispatcher(HttpServletRequest request, Audit audit, Model model) throws Exception {
    if (audit.getSubject() instanceof Page) {
        throw new ForbiddenPageException();
    }
    String status = ServletRequestUtils.getStringParameter(request, TgolKeyStore.STATUS_KEY);
    HttpStatusCodeFamily httpStatusCode = getHttpStatusCodeFamily(status);
    // the repartion of the pages regarding the httpStatusCode
    if (httpStatusCode == null) {
        if (!isAuthorizedScopeForPageList(audit)) {
            throw new ForbiddenScopeException();
        }
        try {
            Contract currentContract = retrieveContractFromAudit(audit);
            model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, currentContract.getLabel());
            model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, currentContract.getId());
            String testLabel = ServletRequestUtils.getStringParameter(request, TgolKeyStore.TEST_KEY);
            if (StringUtils.isNotBlank(testLabel)) {
                model.addAttribute(TgolKeyStore.TEST_CODE_KEY, getTestDataService().getTestFromAuditAndLabel(audit, testLabel));
            }
            return this.preparePageListData(audit, model);
        } catch (ServletRequestBindingException e) {
            return TgolKeyStore.OUPS_VIEW_REDIRECT_NAME;
        }
    } else {
        boolean isAuthorizedScopeForPageList = isAuthorizedScopeForPageList(audit);
        Contract currentContract = retrieveContractFromAudit(audit);
        model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, currentContract.getLabel());
        model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, currentContract.getId());
        // used in the jsp
        if (!isAuthorizedScopeForPageList) {
            model.addAttribute(TgolKeyStore.AUDIT_NUMBER_KEY, true);
        }
        String testLabel = ServletRequestUtils.getStringParameter(request, TgolKeyStore.TEST_KEY);
        if (StringUtils.isNotBlank(testLabel)) {
            model.addAttribute(TgolKeyStore.TEST_CODE_KEY, getTestDataService().getTestFromAuditAndLabel(audit, testLabel));
        }
        return this.preparePageListStatsByHttpStatusCode(audit, model, httpStatusCode, request, false);
    }
}
Also used : ServletRequestBindingException(org.springframework.web.bind.ServletRequestBindingException) HttpStatusCodeFamily(org.asqatasun.webapp.util.HttpStatusCodeFamily) Page(org.asqatasun.entity.subject.Page) ForbiddenScopeException(org.asqatasun.webapp.exception.ForbiddenScopeException) Contract(org.asqatasun.webapp.entity.contract.Contract) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Example 3 with Contract

use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.

the class UserManagementController method displayDeleteUserConfirmation.

/**
     * @param request
     * @param response
     * @param model
     * @return The pages audit set-up form page
     */
@RequestMapping(value = TgolKeyStore.DELETE_USER_URL, method = RequestMethod.POST)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String displayDeleteUserConfirmation(HttpServletRequest request, HttpServletResponse response, Model model) {
    Object userId = request.getSession().getAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY);
    Long lUserId;
    if (userId instanceof Long) {
        lUserId = (Long) userId;
    } else {
        try {
            lUserId = Long.valueOf(userId.toString());
        } catch (NumberFormatException nfe) {
            throw new ForbiddenUserException();
        }
    }
    User user = getCurrentUser();
    User userToDelete = getUserDataService().read(lUserId);
    if (userToDelete == null || user.getId().equals(userToDelete.getId())) {
        return TgolKeyStore.ACCESS_DENIED_VIEW_NAME;
    }
    for (Contract contract : userToDelete.getContractSet()) {
        deleteAllAuditsFromContract(contract);
    }
    getUserDataService().delete(userToDelete.getId());
    request.getSession().removeAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY);
    request.getSession().setAttribute(TgolKeyStore.DELETED_USER_NAME_KEY, userToDelete.getEmail1());
    return TgolKeyStore.ADMIN_VIEW_REDIRECT_NAME;
}
Also used : User(org.asqatasun.webapp.entity.user.User) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) Contract(org.asqatasun.webapp.entity.contract.Contract) Secured(org.springframework.security.access.annotation.Secured)

Example 4 with Contract

use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.

the class AddScenarioFormValidator method checkScenarioLabel.

/**
     * 
     * @param addScenarioCommand
     * @param errors 
     * @return  whether the scenario handled by the current AddScenarioCommand
     * has a well-formed label
     */
public boolean checkScenarioLabel(AddScenarioCommand addScenarioCommand, Errors errors) {
    if (StringUtils.isEmpty(addScenarioCommand.getScenarioLabel())) {
        // if no label set
        LOGGER.debug("empty Scenario Label");
        errors.rejectValue(GENERAL_ERROR_MSG_KEY, MANDATORY_FIELD_MSG_BUNDLE_KEY);
        errors.rejectValue(SCENARIO_LABEL_KEY, NO_SCENARIO_LABEL_MSG_BUNDLE_KEY);
        return false;
    }
    Contract contract = contractDataService.read(addScenarioCommand.getContractId());
    Set<String> scenarioLabelSet = new HashSet();
    for (Scenario scenario : contract.getScenarioSet()) {
        scenarioLabelSet.add(scenario.getLabel());
    }
    if (scenarioLabelSet.contains(addScenarioCommand.getScenarioLabel())) {
        errors.rejectValue(GENERAL_ERROR_MSG_KEY, MANDATORY_FIELD_MSG_BUNDLE_KEY);
        errors.rejectValue(SCENARIO_LABEL_KEY, SCENARIO_LABEL_EXISTS_MSG_BUNDLE_KEY);
        return false;
    }
    return true;
}
Also used : Contract(org.asqatasun.webapp.entity.contract.Contract) HashSet(java.util.HashSet) Scenario(org.asqatasun.webapp.entity.scenario.Scenario)

Example 5 with Contract

use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.

the class ContractManagementController method submitAddContractAdminPage.

/**
     * @param createContractCommand
     * @param result
     * @param request
     * @param response
     * @param model
     * @return The pages audit set-up form page
     */
@RequestMapping(value = TgolKeyStore.ADD_CONTRACT_FROM_CONTRACT_MNGT_URL, method = RequestMethod.POST)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String submitAddContractAdminPage(@ModelAttribute(TgolKeyStore.CREATE_CONTRACT_COMMAND_KEY) CreateContractCommand createContractCommand, BindingResult result, HttpServletRequest request, HttpServletResponse response, Model model) {
    Object userId = request.getSession().getAttribute(TgolKeyStore.USER_ID_KEY);
    Long lUserId;
    if (userId instanceof Long) {
        lUserId = (Long) userId;
    } else {
        try {
            lUserId = Long.valueOf(userId.toString());
        } catch (NumberFormatException nfe) {
            throw new ForbiddenUserException();
        }
    }
    Map<String, List<ContractOptionFormField>> optionFormFieldMap = ContractOptionFormFieldHelper.getFreshContractOptionFormFieldMap(getContractOptionFormFieldBuilderMap());
    getCreateContractFormValidator().setContractOptionFormFieldMap(optionFormFieldMap);
    // We check whether the form is valid
    getCreateContractFormValidator().validate(createContractCommand, result);
    // If the form has some errors, we display it again with errors' details
    User currentModifiedUser = getUserDataService().read(lUserId);
    if (result.hasErrors()) {
        return displayFormWithErrors(model, createContractCommand, currentModifiedUser.getEmail1(), lUserId, optionFormFieldMap, TgolKeyStore.EDIT_CONTRACT_VIEW_NAME);
    }
    Contract contract = getContractDataService().create();
    contract.setUser(currentModifiedUser);
    contract = CreateContractCommandFactory.getInstance().updateContractFromCommand(createContractCommand, contract);
    saveOrUpdateContract(contract);
    request.getSession().setAttribute(TgolKeyStore.ADDED_CONTRACT_NAME_KEY, contract.getLabel());
    model.addAttribute(TgolKeyStore.USER_ID_KEY, contract.getUser().getId());
    request.getSession().removeAttribute(TgolKeyStore.USER_ID_KEY);
    return TgolKeyStore.MANAGE_CONTRACTS_VIEW_REDIRECT_NAME;
}
Also used : User(org.asqatasun.webapp.entity.user.User) List(java.util.List) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) Contract(org.asqatasun.webapp.entity.contract.Contract) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Contract (org.asqatasun.webapp.entity.contract.Contract)43 Secured (org.springframework.security.access.annotation.Secured)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)17 ForbiddenUserException (org.asqatasun.webapp.exception.ForbiddenUserException)15 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)12 Audit (org.asqatasun.entity.audit.Audit)5 User (org.asqatasun.webapp.entity.user.User)5 List (java.util.List)4 Scenario (org.asqatasun.webapp.entity.scenario.Scenario)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 Site (org.asqatasun.entity.subject.Site)3 WebResource (org.asqatasun.entity.subject.WebResource)3 Functionality (org.asqatasun.webapp.entity.functionality.Functionality)3 AuditResultSortCommand (org.asqatasun.webapp.command.AuditResultSortCommand)2 AuditSetUpFormValidator (org.asqatasun.webapp.validator.AuditSetUpFormValidator)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1