Search in sources :

Example 6 with Act

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

the class ParameterDAOImpl method findLastActByContract.

private Act findLastActByContract(Long idContract, ScopeEnum scope) {
    Query query = entityManager.createQuery("SELECT a FROM " + Act.class.getName() + " a" + " WHERE a.contract.id = :idContract" + " AND (a.status = :completedStatus OR a.status = :errorStatus)" + " AND a.scope.code =:scope " + " ORDER BY a.id DESC");
    query.setParameter("idContract", idContract);
    query.setParameter("completedStatus", ActStatus.COMPLETED);
    query.setParameter("errorStatus", ActStatus.ERROR);
    query.setParameter("scope", scope);
    query.setMaxResults(1);
    query.setHint(CACHEABLE_OPTION, "true");
    try {
        return (Act) query.getSingleResult();
    } catch (NoResultException nre) {
        return null;
    }
}
Also used : Act(org.asqatasun.entity.contract.Act) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 7 with Act

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

the class AuditResultController method displayAuditResultFromContract.

/**
 * General router when receive audit-result request. Regarding the scope of
 * the audit, the returned page may differ.
 *
 * @param auditId
 * @param request
 * @param model
 * @return
 */
@RequestMapping(value = TgolKeyStore.AUDIT_RESULT_CONTRACT_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String displayAuditResultFromContract(@RequestParam(TgolKeyStore.AUDIT_ID_KEY) String auditId, HttpServletRequest request, Model model) {
    try {
        Audit audit = auditDataService.read(Long.valueOf(auditId));
        Act act = actDataService.getActFromAudit(audit);
        switch(act.getScope().getCode()) {
            case FILE:
            case PAGE:
                model.addAttribute(TgolKeyStore.WEBRESOURCE_ID_KEY, audit.getSubject().getId());
                return TgolKeyStore.RESULT_PAGE_VIEW_REDIRECT_NAME;
            case DOMAIN:
            case SCENARIO:
                model.addAttribute(TgolKeyStore.AUDIT_ID_KEY, auditId);
                return TgolKeyStore.SYNTHESIS_SITE_VIEW_REDIRECT_NAME;
            case GROUPOFFILES:
            case GROUPOFPAGES:
                model.addAttribute(TgolKeyStore.AUDIT_ID_KEY, auditId);
                model.addAttribute(TgolKeyStore.STATUS_KEY, HttpStatusCodeFamily.f2xx.name());
                return TgolKeyStore.PAGE_LIST_XXX_VIEW_REDIRECT_NAME;
            default:
                throw new ForbiddenPageException();
        }
    } catch (NumberFormatException nfe) {
        throw new ForbiddenPageException();
    }
}
Also used : Audit(org.asqatasun.entity.audit.Audit) Act(org.asqatasun.entity.contract.Act) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with Act

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

the class AuditScenarioController method deleteScenario.

/**
 * Delete a scenario and the associated audits.
 * @param scenario
 * @param contract
 */
private void deleteScenario(Scenario scenario, Contract contract) {
    scenarioDataService.delete(scenario.getId());
    Collection<Act> actCollection = retrieveActCollection(scenario, contract);
    for (Act act : actCollection) {
        auditDataService.delete(act.getAudit().getId());
        act.setStatus(ActStatus.DELETED);
        act.setAudit(null);
        actDataService.saveOrUpdate(act);
    }
}
Also used : Act(org.asqatasun.entity.contract.Act)

Example 9 with Act

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

the class DetailedContractInfoFactory method setNLastActInfo.

/**
 * Sets the act info of the n last acts launched from this contract
 *
 * @param contract
 * @param detailedContractInfo
 * @return
 */
protected DetailedContractInfo setNLastActInfo(Contract contract, DetailedContractInfo detailedContractInfo) {
    int nb0fAct = actDataService.getNumberOfAct(contract);
    int nbMaxActInfo = getMaxAuthorizedNumberOfActByContract(contract);
    if (nbMaxActInfo > 0 && nb0fAct > nbMaxActInfo) {
        nb0fAct = nbMaxActInfo;
    }
    detailedContractInfo.setNumberOfAct(nb0fAct);
    Collection<Act> lastActSet = actDataService.getActsByContract(contract, nb0fAct, 2, null, false);
    for (Act act : lastActSet) {
        detailedContractInfo.addActInfo(actInfoFactory.getActInfo(act));
    }
    detailedContractInfo.setNumberOfDisplayedAct(lastActSet.size());
    detailedContractInfo.setSiteActInfoSet(actInfoFactory.getActInfoSet(actDataService.getActsByContract(contract, -1, 1, ScopeEnum.DOMAIN, true)));
    return detailedContractInfo;
}
Also used : Act(org.asqatasun.entity.contract.Act)

Aggregations

Act (org.asqatasun.entity.contract.Act)9 NoResultException (javax.persistence.NoResultException)2 Query (javax.persistence.Query)2 Audit (org.asqatasun.entity.audit.Audit)2 Contract (org.asqatasun.entity.contract.Contract)2 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)2 Secured (org.springframework.security.access.annotation.Secured)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Date (java.util.Date)1 Scope (org.asqatasun.entity.contract.Scope)1 Test (org.junit.Test)1