Search in sources :

Example 1 with Scenario

use of org.asqatasun.entity.scenario.Scenario 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 2 with Scenario

use of org.asqatasun.entity.scenario.Scenario in project Asqatasun by Asqatasun.

the class AuditSetUpCommandFactory method getScenarioAuditSetUpCommand.

/**
 * @param contract
 * @param scenarioId
 * @param levelFormFieldList
 * @param optionalFormFieldMap
 * @return
 */
public AuditSetUpCommand getScenarioAuditSetUpCommand(Contract contract, String scenarioId, List<SelectFormField> levelFormFieldList, Map<String, List<AuditSetUpFormField>> optionalFormFieldMap) {
    AuditSetUpCommand scenarioAuditSetUpCommand = new AuditSetUpCommand();
    scenarioAuditSetUpCommand.setScope(ScopeEnum.SCENARIO);
    Scenario scenario = scenarioDataService.read(Long.valueOf(scenarioId));
    scenarioAuditSetUpCommand.setScenarioName(scenario.getLabel());
    scenarioAuditSetUpCommand.setScenarioId(scenario.getId());
    setUpAuditSetUpCommand(scenarioAuditSetUpCommand, contract, levelFormFieldList, optionalFormFieldMap, ScopeEnum.SCENARIO);
    return scenarioAuditSetUpCommand;
}
Also used : AuditSetUpCommand(org.asqatasun.webapp.command.AuditSetUpCommand) Scenario(org.asqatasun.entity.scenario.Scenario)

Example 3 with Scenario

use of org.asqatasun.entity.scenario.Scenario in project Asqatasun by Asqatasun.

the class AddScenarioFormValidator method checkScenarioLabel.

/**
 * @param addScenarioCommand
 * @param errors
 * @return  whether the scenario handled by the current AddScenarioCommand
 * has a well-formed label
 */
public boolean checkScenarioLabel(AddScenarioCommand addScenarioCommand, Errors errors) {
    if (StringUtils.isEmpty(addScenarioCommand.getScenarioLabel())) {
        // if no label set
        LOGGER.debug("empty Scenario Label");
        errors.rejectValue(GENERAL_ERROR_MSG_KEY, MANDATORY_FIELD_MSG_BUNDLE_KEY);
        errors.rejectValue(SCENARIO_LABEL_KEY, NO_SCENARIO_LABEL_MSG_BUNDLE_KEY);
        return false;
    }
    Contract contract = contractDataService.read(addScenarioCommand.getContractId());
    Set<String> scenarioLabelSet = new HashSet();
    for (Scenario scenario : contract.getScenarioSet()) {
        scenarioLabelSet.add(scenario.getLabel());
    }
    if (scenarioLabelSet.contains(addScenarioCommand.getScenarioLabel())) {
        errors.rejectValue(GENERAL_ERROR_MSG_KEY, MANDATORY_FIELD_MSG_BUNDLE_KEY);
        errors.rejectValue(SCENARIO_LABEL_KEY, SCENARIO_LABEL_EXISTS_MSG_BUNDLE_KEY);
        return false;
    }
    return true;
}
Also used : Contract(org.asqatasun.entity.contract.Contract) Scenario(org.asqatasun.entity.scenario.Scenario)

Example 4 with Scenario

use of org.asqatasun.entity.scenario.Scenario in project Asqatasun by Asqatasun.

the class AsqatasunOrchestrator method auditScenario.

public void auditScenario(Contract contract, Long idScenario, String clientIp, Set<Parameter> parameterSet, Locale locale) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Scenarion audit on scenario with id" + idScenario);
        for (Parameter param : parameterSet) {
            LOGGER.debug("param " + param.getValue() + " " + param.getParameterElement().getParameterElementCode());
        }
    }
    Act act = createAct(contract, ScopeEnum.SCENARIO, clientIp);
    Scenario scenario = scenarioDataService.read(idScenario);
    AuditThread auditScenarioThread = new AuditScenarioThread(scenario.getLabel(), scenario.getContent(), auditService, act, parameterSet, locale);
    threadPoolTaskExecutor.submit(auditScenarioThread);
}
Also used : Parameter(org.asqatasun.entity.parameterization.Parameter) Scenario(org.asqatasun.entity.scenario.Scenario)

Example 5 with Scenario

use of org.asqatasun.entity.scenario.Scenario in project Asqatasun by Asqatasun.

the class AuditScenarioController method displayScenarioSetUp.

@RequestMapping(value = TgolKeyStore.AUDIT_SCENARIO_SET_UP_CONTRACT_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String displayScenarioSetUp(@RequestParam(TgolKeyStore.CONTRACT_ID_KEY) String contractId, @RequestParam(TgolKeyStore.SCENARIO_ID_KEY) String scenarioId, HttpServletRequest request, HttpServletResponse response, Model model) {
    Scenario scenario = scenarioDataService.read(Long.valueOf(scenarioId));
    model.addAttribute(TgolKeyStore.SCENARIO_KEY, scenario);
    return displayAuditSetUpView(TgolKeyStore.AUDIT_SCENARIO_SET_UP_VIEW_NAME, contractId, scenarioId, scenarioOptionFormFieldBuilderMap, ScopeEnum.SCENARIO, model);
}
Also used : Scenario(org.asqatasun.entity.scenario.Scenario) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Scenario (org.asqatasun.entity.scenario.Scenario)7 Contract (org.asqatasun.entity.contract.Contract)3 Secured (org.springframework.security.access.annotation.Secured)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Parameter (org.asqatasun.entity.parameterization.Parameter)1 AuditSetUpCommand (org.asqatasun.webapp.command.AuditSetUpCommand)1