Search in sources :

Example 1 with Contract

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

the class ContractDAO method read.

@Override
public Contract read(Long id) {
    try {
        Query query = entityManager.createQuery("SELECT c FROM " + getEntityClass().getName() + " c" + " LEFT JOIN FETCH c.optionElementSet o" + " LEFT JOIN FETCH c.functionalitySet f" + " LEFT JOIN FETCH c.referentialSet r" + " LEFT JOIN FETCH c.scenarioSet s" + " WHERE c.id = :id");
        query.setParameter("id", id);
        Contract contract = (Contract) query.getSingleResult();
        // to ensure the options associated with the contract is
        // retrieved
        contract.getOptionElementSet().size();
        contract.getFunctionalitySet().size();
        contract.getScenarioSet().size();
        contract.getReferentialSet().size();
        return contract;
    } catch (NoResultException nre) {
        return null;
    }
}
Also used : Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException) Contract(org.asqatasun.entity.contract.Contract)

Example 2 with Contract

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

the class AuditLauncherController method launchAudit.

/**
 * This methods enables an authenticated user to launch an audit.
 *
 * @param auditSetUpCommand
 * @param locale
 * @param model
 * @return
 */
public String launchAudit(final AuditSetUpCommand auditSetUpCommand, final Locale locale, Model model) {
    Contract contract = contractDataService.read(auditSetUpCommand.getContractId());
    if (isContractExpired(contract)) {
        return displayContractView(contract, model);
    } else {
        // before launching the audit, we check whether any restriction on the
        // contract forbids it.
        ScopeEnum scope = auditSetUpCommand.getScope();
        String checkResult = restrictionHandler.checkRestriction(contract, getClientIpAddress(), scope);
        if (!checkResult.equalsIgnoreCase(TgolKeyStore.ACT_ALLOWED)) {
            return checkResult;
        }
        if (scope.equals(ScopeEnum.PAGE) || scope.equals(ScopeEnum.FILE)) {
            return preparePageAudit(auditSetUpCommand, contract, locale, scope, model);
        }
        String url = contractDataService.getUrlFromContractOption(contract);
        if (scope.equals(ScopeEnum.DOMAIN)) {
            asqatasunOrchestrator.auditSite(contract, url, getClientIpAddress(), getUserParamSet(auditSetUpCommand, contract.getId(), -1, url), locale);
            model.addAttribute(TgolKeyStore.TESTED_URL_KEY, url);
        } else if (scope.equals(ScopeEnum.SCENARIO)) {
            asqatasunOrchestrator.auditScenario(contract, auditSetUpCommand.getScenarioId(), getClientIpAddress(), getUserParamSet(auditSetUpCommand, contract.getId(), -1, url), locale);
            model.addAttribute(TgolKeyStore.SCENARIO_NAME_KEY, auditSetUpCommand.getScenarioName());
            model.addAttribute(TgolKeyStore.SCENARIO_ID_KEY, auditSetUpCommand.getScenarioId());
        }
        model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
        model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
        return TgolKeyStore.AUDIT_IN_PROGRESS_VIEW_NAME;
    }
}
Also used : ScopeEnum(org.asqatasun.entity.contract.ScopeEnum) Contract(org.asqatasun.entity.contract.Contract)

Example 3 with Contract

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

the class AuditScenarioController method getScenarioFile.

@RequestMapping(value = TgolKeyStore.DOWNLOAD_SCENARIO_URL_CONTRACT_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public void getScenarioFile(@RequestParam(TgolKeyStore.CONTRACT_ID_KEY) String contractId, @RequestParam(TgolKeyStore.SCENARIO_ID_KEY) String scenarioId, HttpServletResponse response) {
    Contract contract = contractDataService.read(Long.valueOf(contractId));
    if (contract.getUser().getId().equals(getCurrentUser().getId())) {
        try {
            for (Scenario scenario : contract.getScenarioSet()) {
                if (scenario.getId().equals(Long.valueOf(scenarioId))) {
                    InputStream is = IOUtils.toInputStream(scenario.getContent());
                    IOUtils.copy(is, response.getOutputStream());
                    response.setContentType(TgolKeyStore.CONTENT_TYPE);
                    StringBuilder strb = new StringBuilder(TgolKeyStore.ATTACHMENT);
                    strb.append(scenario.getLabel());
                    strb.append(TgolKeyStore.JSON_EXTENSION);
                    response.setHeader(TgolKeyStore.CONTENT_DISPOSITION, strb.toString());
                    response.flushBuffer();
                    return;
                }
            }
            throw new ForbiddenPageException(getCurrentUser());
        } catch (IOException ex) {
            throw new RuntimeException("IOError writing file to output stream");
        }
    } else {
        throw new ForbiddenPageException(getCurrentUser());
    }
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) Contract(org.asqatasun.entity.contract.Contract) Scenario(org.asqatasun.entity.scenario.Scenario) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Contract

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

the class AuditScenarioController method submitForm.

@RequestMapping(value = TgolKeyStore.AUDIT_SCENARIO_SET_UP_CONTRACT_URL, method = RequestMethod.POST)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
protected String submitForm(@ModelAttribute(TgolKeyStore.ADD_SCENARIO_COMMAND_KEY) AuditSetUpCommand auditSetUpCommand, BindingResult result, Model model, HttpServletRequest request) {
    Contract contract = contractDataService.read(auditSetUpCommand.getContractId());
    Map<String, List<AuditSetUpFormField>> formFielMap = getFreshAuditSetUpFormFieldMap(contract, scenarioOptionFormFieldBuilderMap);
    return submitForm(contract, auditSetUpCommand, formFielMap, auditSiteSetUpFormValidator, model, result, request);
}
Also used : Contract(org.asqatasun.entity.contract.Contract) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Contract

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

the class AuditScenarioController method addScenario.

@RequestMapping(value = TgolKeyStore.AUDIT_SCENARIO_MANAGEMENT_CONTRACT_URL, method = RequestMethod.POST)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
protected String addScenario(@ModelAttribute(TgolKeyStore.ADD_SCENARIO_COMMAND_KEY) AddScenarioCommand addScenarioCommand, BindingResult result, Model model, HttpServletRequest request) {
    Contract contract = contractDataService.read(addScenarioCommand.getContractId());
    addScenarioFormValidator.validate(addScenarioCommand, result);
    // and the same page with updated data is displayed again
    if (!result.hasErrors()) {
        saveScenario(addScenarioCommand, contract);
        model.addAttribute(TgolKeyStore.NEW_SCENARIO_NAME_KEY, addScenarioCommand.getScenarioLabel());
        prepareScenarioManagementData(model, addScenarioCommand.getContractId().toString());
        return TgolKeyStore.SCENARIO_MANAGEMENT_VIEW_NAME;
    }
    addScenarioListToModel(contract, model);
    model.addAttribute(TgolKeyStore.ADD_SCENARIO_COMMAND_KEY, addScenarioCommand);
    model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
    return TgolKeyStore.SCENARIO_MANAGEMENT_VIEW_NAME;
}
Also used : Contract(org.asqatasun.entity.contract.Contract) Secured(org.springframework.security.access.annotation.Secured) 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