Search in sources :

Example 26 with Contract

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

the class ContractControllerTest method setUpContractDataService.

private void setUpContractDataService(boolean expired) {
    when(mockContract.getLabel()).thenReturn("");
    when(mockContract.getFunctionalitySet()).thenReturn(new HashSet<>());
    when(mockContract.getId()).thenReturn(1L);
    GregorianCalendar calendar = new GregorianCalendar();
    if (expired) {
        calendar.set(2011, 01, 01);
    } else {
        calendar.set(2030, 01, 01);
    }
    when(mockContract.getEndDate()).thenReturn(calendar.getTime());
    calendar.set(2010, 01, 01);
    when(mockContract.getBeginDate()).thenReturn(calendar.getTime());
    when(mockContract.getOptionElementSet()).thenReturn(new HashSet<>());
    when(mockContractDataService.getAllContractsByUser(mockUser)).thenReturn(new HashSet<Contract>() {

        {
            add(mockContract);
        }
    });
    when(mockContractDataService.getUrlFromContractOption(mockContract)).thenReturn("");
    when(mockContractDataService.getPresetContractKeyContractOption(mockContract)).thenReturn("");
    when(mockContractDataService.doesContractHaveFunctionality(mockContract, "MANUAL")).thenReturn(true);
    when(mockContractDataService.read(1L)).thenReturn(mockContract);
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Contract(org.asqatasun.entity.contract.Contract)

Example 27 with Contract

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

the class ActDAOTest method testFindRunningActsByContract.

/**
 * Test of findRunningActsByContract method, of class ContractDAOImpl.
 */
@Test
public void testFindRunningActsByContract() {
    Contract contract = contractDAO.read((1L));
    assertEquals(1, actDAO.findRunningActsByContract(contract).size());
    assertEquals(Long.valueOf(3), actDAO.findRunningActsByContract(contract).iterator().next().getId());
    contract = contractDAO.read((2L));
    assertEquals(3, actDAO.findRunningActsByContract(contract).size());
}
Also used : Contract(org.asqatasun.entity.contract.Contract) Test(org.junit.Test)

Example 28 with Contract

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

the class AbstractAuditSetUpController method displayAuditSetUpView.

/**
 * @param viewName
 * @param contractId
 * @param scenarioId
 * @param optionFormFieldBuilderMap
 * @param scope
 * @param model
 * @return
 */
protected String displayAuditSetUpView(String viewName, String contractId, String scenarioId, Map<String, List<AuditSetUpFormFieldBuilder>> optionFormFieldBuilderMap, ScopeEnum scope, Model model) {
    Long contractIdValue;
    try {
        contractIdValue = Long.valueOf(contractId);
    } catch (NumberFormatException nfe) {
        throw new ForbiddenPageException(getCurrentUser());
    }
    Contract contract = contractDataService.read(contractIdValue);
    if (isUserAllowedToDisplaySetUpPage(contract, viewName)) {
        Collection<String> authorisedReferentialList = getAuthorisedReferentialCodeFromContract(contract);
        // Get a fresh list of the auditSetUpFormField that handles the choice
        // of the referential and its level
        List<SelectFormField> refAndLevelFormFieldList = this.getFreshRefAndLevelSetUpFormFieldList(authorisedReferentialList, referentialAndLevelFormFieldBuilderList);
        String defaultRef = getDefaultReferential(authorisedReferentialList);
        auditSetUpFormFieldHelper.selectDefaultLevelFromRefValue(refAndLevelFormFieldList, defaultRef);
        // Get a fresh map of auditSetUpFormField. The value of the field is
        // them set by Parameter mapping handled by the AuditSetUpCommandObject
        Map<String, List<AuditSetUpFormField>> optionFormFieldMap = this.getFreshAuditSetUpFormFieldMap(contract, optionFormFieldBuilderMap);
        AuditSetUpCommand asuc;
        // instance of AuditSetUpCommand
        switch(scope) {
            case DOMAIN:
                asuc = auditSetUpCommandFactory.getSiteAuditSetUpCommand(contract, refAndLevelFormFieldList, optionFormFieldMap);
                break;
            case FILE:
            case GROUPOFFILES:
                asuc = auditSetUpCommandFactory.getUploadAuditSetUpCommand(contract, refAndLevelFormFieldList, optionFormFieldMap);
                break;
            case SCENARIO:
                asuc = auditSetUpCommandFactory.getScenarioAuditSetUpCommand(contract, scenarioId, refAndLevelFormFieldList, optionFormFieldMap);
                break;
            case PAGE:
            case GROUPOFPAGES:
            default:
                asuc = auditSetUpCommandFactory.getPageAuditSetUpCommand(contract, refAndLevelFormFieldList, optionFormFieldMap);
        }
        model.addAttribute(TgolKeyStore.AUDIT_SET_UP_COMMAND_KEY, asuc);
        model.addAttribute(TgolKeyStore.DEFAULT_PARAM_SET_KEY, asuc.isDefaultParamSet());
        this.prepareFormModel(model, contract, refAndLevelFormFieldList, optionFormFieldMap);
        return viewName;
    } else {
        return TgolKeyStore.ACCESS_DENIED_VIEW_NAME;
    }
}
Also used : AuditSetUpCommand(org.asqatasun.webapp.command.AuditSetUpCommand) Contract(org.asqatasun.entity.contract.Contract) SelectFormField(org.asqatasun.webapp.ui.form.SelectFormField) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Example 29 with Contract

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

the class AbstractAuditSetUpController method submitForm.

/**
 * @param contract
 * @param auditSetUpCommand
 * @param formFielMap
 * @param auditSetUpFormValidator
 * @param model
 * @param result
 * @param request
 * @return
 */
protected String submitForm(Contract contract, AuditSetUpCommand auditSetUpCommand, Map<String, List<AuditSetUpFormField>> formFielMap, AuditSetUpFormValidator auditSetUpFormValidator, Model model, BindingResult result, HttpServletRequest request) {
    if (formFielMap == null || auditSetUpFormValidator == null) {
        LoggerFactory.getLogger(this.getClass()).info("oups");
        return TgolKeyStore.OUPS_VIEW_NAME;
    }
    Collection<String> authorisedReferentialList = getAuthorisedReferentialCodeFromContract(contract);
    auditSetUpFormValidator.setAuditSetUpFormFieldMap(formFielMap);
    auditSetUpFormValidator.validate(auditSetUpCommand, result);
    auditSetUpFormValidator.validateLevel(auditSetUpCommand, result, authorisedReferentialList);
    // If the form has some errors, we display it again with errors' details
    if (result.hasErrors()) {
        Contract currentContract = contractDataService.read(auditSetUpCommand.getContractId());
        return displayFormWithErrors(model, currentContract, auditSetUpCommand, authorisedReferentialList, formFielMap);
    }
    // If the form is valid, the audit is launched with data from form
    model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, auditSetUpCommand.getContractId());
    model.addAttribute(TgolKeyStore.AUDIT_SET_UP_COMMAND_KEY, auditSetUpCommand);
    return launchAudit(contract, auditSetUpCommand, model, request);
}
Also used : Contract(org.asqatasun.entity.contract.Contract)

Example 30 with Contract

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

the class AuditResultController method displayCriterionResult.

/**
 * @param webresourceId
 * @param criterionId
 * @param model
 * @return the test-result view name
 */
@RequestMapping(value = TgolKeyStore.CRITERION_RESULT_CONTRACT_URL, method = RequestMethod.GET)
public String displayCriterionResult(@RequestParam(TgolKeyStore.WEBRESOURCE_ID_KEY) String webresourceId, @RequestParam(TgolKeyStore.CRITERION_CODE_KEY) String criterionId, Model model) {
    Long wrId;
    Long critId;
    try {
        wrId = Long.valueOf(webresourceId);
        critId = Long.valueOf(criterionId);
    } catch (NumberFormatException nfe) {
        throw new ForbiddenUserException(getCurrentUser());
    }
    WebResource webResource = webResourceDataService.ligthRead(wrId);
    if (webResource == null || webResource instanceof Site) {
        throw new ForbiddenPageException();
    }
    Audit audit = getAuditFromWebResource(webResource);
    if (isUserAllowedToDisplayResult(audit)) {
        Contract contract = retrieveContractFromAudit(audit);
        // Attributes for breadcrumb
        model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
        model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
        model.addAttribute(TgolKeyStore.URL_KEY, webResource.getURL());
        Criterion crit = criterionDataService.read(critId);
        model.addAttribute(TgolKeyStore.CRITERION_LABEL_KEY, crit.getLabel());
        model.addAttribute(TgolKeyStore.AUDIT_ID_KEY, audit.getId());
        // Add a boolean used to display the breadcrumb.
        model.addAttribute(TgolKeyStore.AUTHORIZED_SCOPE_FOR_PAGE_LIST, isAuthorizedScopeForPageList(audit));
        model.addAttribute(TgolKeyStore.TEST_RESULT_LIST_KEY, testResultFactory.getTestResultListFromCriterion(webResource, crit));
        return TgolKeyStore.CRITERION_RESULT_VIEW_NAME;
    } else {
        throw new ForbiddenPageException();
    }
}
Also used : Site(org.asqatasun.entity.subject.Site) Audit(org.asqatasun.entity.audit.Audit) Criterion(org.asqatasun.entity.reference.Criterion) WebResource(org.asqatasun.entity.subject.WebResource) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) Contract(org.asqatasun.entity.contract.Contract) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

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