Search in sources :

Example 21 with Contract

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

the class ActDAOImplTest method testFindNumberOfActByPeriodAndIp.

public void testFindNumberOfActByPeriodAndIp() {
    Contract contract = contractDAO.read((Long.valueOf(1)));
    DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date limitDate = null;
    try {
        limitDate = dfm.parse("2011-01-01 00:00:00");
    } catch (ParseException ex) {
        Logger.getLogger(ActDAOImplTest.class.getName()).log(Level.SEVERE, null, ex);
    }
    assertEquals(2, actDAO.findNumberOfActByPeriodAndIp(contract, limitDate, "127.0.0.1"));
    assertEquals(0, actDAO.findNumberOfActByPeriodAndIp(contract, limitDate, "127.0.0.2"));
    try {
        limitDate = dfm.parse("2011-01-01 01:00:00");
    } catch (ParseException ex) {
        Logger.getLogger(ActDAOImplTest.class.getName()).log(Level.SEVERE, null, ex);
    }
    assertEquals(1, actDAO.findNumberOfActByPeriodAndIp(contract, limitDate, "127.0.0.1"));
    assertEquals(0, actDAO.findNumberOfActByPeriodAndIp(contract, limitDate, "127.0.0.2"));
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) Contract(org.asqatasun.webapp.entity.contract.Contract) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 22 with Contract

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

the class ContractDAOImplTest method testUpdate.

/**
     * Test of update method, of class ContractDAOImpl.
     */
public void testUpdate() {
    System.out.println("update");
    Contract contract = contractDAO.read((Long.valueOf(1)));
    Float contractPrice = contract.getPrice();
    contract.setPrice(contractPrice + 200);
    contractDAO.update(contract);
    assertEquals(contractPrice + 200, contractDAO.read((Long.valueOf(1))).getPrice());
}
Also used : Contract(org.asqatasun.webapp.entity.contract.Contract)

Example 23 with Contract

use of org.asqatasun.webapp.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) {
        Logger.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 = getContractDataService().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.webapp.entity.contract.Contract)

Example 24 with Contract

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

the class AbstractAuditDataHandlerController method isUserAllowedToDisplayResult.

/**
     * This methods checks whether the current user is allowed to display the
     * audit result of a given audit. To do so, we verify that the act
     * associated with the audit belongs to the current user and
     * that the current contract is not expired
     * 
     * @param audit
     * @return
     *      true if the user is allowed to display the result, false otherwise.
     */
protected boolean isUserAllowedToDisplayResult(Audit audit) {
    if (audit == null) {
        throw new ForbiddenPageException();
    }
    User user = getCurrentUser();
    Contract contract = getActDataService().getActFromAudit(audit).getContract();
    if (isAdminUser() || (!isContractExpired(contract) && user.getId().compareTo(contract.getUser().getId()) == 0)) {
        return true;
    }
    throw new ForbiddenUserException();
}
Also used : User(org.asqatasun.webapp.entity.user.User) Contract(org.asqatasun.webapp.entity.contract.Contract) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Example 25 with Contract

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

the class ManualAuditController method dispatchSubmitManualAuditValues.

/**
     * TO DO : replace this method with an call to the orchestrator 
     * to delegate the writes to the engine.
     * 
     * @param webresourceId
     * @param manualAuditCommand
     * @param result
     * @param model
     * @param request
     * @param isValidating
     * @return
     */
private String dispatchSubmitManualAuditValues(String webresourceId, ManualAuditCommand manualAuditCommand, BindingResult result, Model model, HttpServletRequest request, boolean isValidating) {
    WebResource webResource;
    try {
        webResource = getWebResourceDataService().ligthRead(Long.valueOf(webresourceId));
    } catch (NumberFormatException nfe) {
        throw new ForbiddenPageException();
    }
    if (webResource instanceof Site) {
        throw new ForbiddenPageException();
    }
    Audit audit = getAuditFromWebResource(webResource);
    if (isUserAllowedToDisplayResult(audit)) {
        model.addAttribute(TgolKeyStore.IS_MANUAL_AUDIT_KEY, true);
        List<ProcessResult> processResultList = TestResultFactory.getInstance().getProcessResultListFromTestsResult(manualAuditCommand.getModifiedManualResultMap(), webResource);
        processResultDataService.saveOrUpdate(processResultList);
        /**
             * if save the manual audit for the first time save we set the
             * manual audit start time and status to MANUAL_INITIALIZING
             */
        if (audit.getManualAuditDateOfCreation() == null) {
            audit.setManualAuditDateOfCreation(Calendar.getInstance().getTime());
            audit.setStatus(AuditStatus.MANUAL_INITIALIZING);
            getAuditDataService().update(audit);
        }
        List<ProcessResult> allProcessResultList = TestResultFactory.getInstance().getAllProcessResultListFromTestsResult(manualAuditCommand.getModifiedManualResultMap(), webResource);
        manualAuditCommand.setProcessResultList(allProcessResultList);
        if (isValidating) {
            manualAuditValidator.validate(manualAuditCommand, result);
            if (result.hasErrors()) {
                // ajout message d'erreur.
                model.addAttribute(TgolKeyStore.MANUAL_AUDIT_COMMAND_KEY, manualAuditCommand);
                return dispatchDisplayResultRequest(webResource.getId(), null, model, request, true, manualAuditCommand);
            } else {
                // mettre à jour le statut
                audit.setStatus(AuditStatus.MANUAL_COMPLETED);
                getAuditDataService().update(audit);
                webResourceStatisticsDataService.createWebResourceStatisticsForManualAudit(audit, webResource, allProcessResultList);
                Contract contract = retrieveContractFromAudit(audit);
                model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
                return TgolKeyStore.CONTRACT_VIEW_NAME_REDIRECT;
            }
        }
        webResourceStatisticsDataService.createWebResourceStatisticsForManualAudit(audit, webResource, allProcessResultList);
        return dispatchDisplayResultRequest(webResource.getId(), null, model, request, true, manualAuditCommand);
    } else {
        throw new ForbiddenPageException();
    }
}
Also used : Site(org.asqatasun.entity.subject.Site) Audit(org.asqatasun.entity.audit.Audit) ProcessResult(org.asqatasun.entity.audit.ProcessResult) WebResource(org.asqatasun.entity.subject.WebResource) Contract(org.asqatasun.webapp.entity.contract.Contract) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

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