Search in sources :

Example 1 with Scenario

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

Example 2 with Scenario

use of org.asqatasun.webapp.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.webapp.entity.contract.Contract) HashSet(java.util.HashSet) Scenario(org.asqatasun.webapp.entity.scenario.Scenario)

Example 3 with Scenario

use of org.asqatasun.webapp.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 = getContractDataService().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();
                    break;
                }
            }
            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.webapp.entity.contract.Contract) Scenario(org.asqatasun.webapp.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 Scenario

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

the class AuditScenarioController method deleteScenarioFile.

@RequestMapping(value = TgolKeyStore.DELETE_SCENARIO_URL_CONTRACT_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String deleteScenarioFile(@RequestParam(TgolKeyStore.CONTRACT_ID_KEY) String contractId, @RequestParam(TgolKeyStore.SCENARIO_ID_KEY) String scenarioId, HttpServletRequest request, HttpServletResponse response, Model model) {
    Contract contract = getContractDataService().read(Long.valueOf(contractId));
    if (contract.getUser().getId().equals(getCurrentUser().getId())) {
        for (Scenario scenario : contract.getScenarioSet()) {
            if (scenario.getId().equals(Long.valueOf(scenarioId))) {
                deleteScenario(scenario, contract);
                model.addAttribute(TgolKeyStore.DELETED_SCENARIO_NAME_KEY, scenario.getLabel());
                prepareScenarioManagementData(model, contractId);
                return TgolKeyStore.SCENARIO_MANAGEMENT_VIEW_NAME;
            }
        }
        throw new ForbiddenPageException(getCurrentUser());
    } else {
        throw new ForbiddenPageException(getCurrentUser());
    }
}
Also used : Contract(org.asqatasun.webapp.entity.contract.Contract) Scenario(org.asqatasun.webapp.entity.scenario.Scenario) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Scenario

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

the class AuditScenarioController method saveScenario.

/**
     * Persist a scenario
     * 
     * @param addScenarioCommand
     * @param contract 
     */
private void saveScenario(AddScenarioCommand addScenarioCommand, Contract contract) {
    Scenario scenario = scenarioDataService.create();
    scenario.setLabel(addScenarioCommand.getScenarioLabel());
    scenario.setContent(addScenarioCommand.getScenarioContent());
    scenario.setContract(contract);
    scenario.setDateOfCreation(Calendar.getInstance().getTime());
    scenarioDataService.saveOrUpdate(scenario);
}
Also used : Scenario(org.asqatasun.webapp.entity.scenario.Scenario)

Aggregations

Scenario (org.asqatasun.webapp.entity.scenario.Scenario)8 Contract (org.asqatasun.webapp.entity.contract.Contract)4 Secured (org.springframework.security.access.annotation.Secured)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 HashSet (java.util.HashSet)2 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 Parameter (org.asqatasun.entity.parameterization.Parameter)1 AuditSetUpCommand (org.asqatasun.webapp.command.AuditSetUpCommand)1 Functionality (org.asqatasun.webapp.entity.functionality.Functionality)1 OptionElement (org.asqatasun.webapp.entity.option.OptionElement)1 Referential (org.asqatasun.webapp.entity.referential.Referential)1