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"));
}
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());
}
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);
}
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();
}
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();
}
}
Aggregations