/* * (non-Javadoc) * @see * au.org.aurin.wif.svc.ManualDemandScenarioService#updateManualDemandScenario * (au.org.aurin.wif.model.allocation.ManualDemandScenario, java.lang.String) */ public void updateDemandOutcome(final DemandOutcome demandOutcome, final String projectId) throws WifInvalidInputException, WifInvalidConfigException, ParsingException { LOGGER.info( "updating ManualDemandScenario: {}, with id: {}", demandOutcome.getLabel(), demandOutcome.getId()); try { if (demandOutcome.getProjectId().equals(projectId)) { demandOutcome.setRevision( demandOutcomeDao.findDemandOutcomeById(demandOutcome.getId()).getRevision()); demandOutcomeDao.updateDemandOutcome(demandOutcome); } else { LOGGER.error( "illegal argument, the ManualDemandScenario supplied doesn't belong to project: " + projectId); throw new WifInvalidInputException( "illegal argument, the ManualDemandScenario supplied doesn't belong to project: " + projectId); } } catch (final IllegalArgumentException e) { LOGGER.error("illegal argument, the ManualDemandScenario supplied is invalid "); throw new WifInvalidInputException( "illegal argument, the ManualDemandScenario supplied is invalid ", e); } }
/* * (non-Javadoc) * @see * au.org.aurin.wif.svc.ManualDemandScenarioService#getManualDemandScenario( * java.lang.String) */ public DemandOutcome getDemandOutcome(final String id, final String projectId) throws WifInvalidInputException, WifInvalidConfigException, ParsingException { final DemandOutcome demandOutcome = getDemandOutcome(id); if (demandOutcome.getProjectId().equals(projectId)) { return demandOutcome; } else { LOGGER.error( "illegal argument, the ManualDemandScenario supplied doesn't belong to project: " + projectId); throw new WifInvalidInputException( "illegal argument, the ManualDemandScenario supplied doesn't belong to this project: " + projectId); } }
public DemandOutcome createDemandOutcome( final List<AreaRequirement> outcome, final String projectId) throws WifInvalidInputException, WifInvalidConfigException { final DemandOutcome newDemandOutcome = new DemandOutcome(); newDemandOutcome.setLabel("automated-manualdemand"); LOGGER.debug("creating a new ManualDemandScenario={}", newDemandOutcome.getLabel()); final WifProject project = projectService.getProject(projectId); newDemandOutcome.setProjectId(project.getId()); for (final AreaRequirement areaRequirement : outcome) { // final ManualAreaRequirement manualAreaRequirement = new // ManualAreaRequirement(); // manualAreaRequirement.setAllocationLU(areaRequirement.getAllocationLU()); // manualAreaRequirement.setRequiredArea(areaRequirement.getRequiredArea()); // manualAreaRequirement.setProjection(areaRequirement.getProjection()); areaRequirement.setProjectionLabel(areaRequirement.getProjection().getLabel()); newDemandOutcome.addAreaRequirenment(areaRequirement); LOGGER.info( "recreating manually required area for land use {} in projection " + areaRequirement.getProjection().getLabel() + " is : {}", areaRequirement.getAllocationLU().getLabel(), areaRequirement.getRequiredArea()); } final DemandOutcome savedDemandOutcome = demandOutcomeDao.persistDemandOutcome(newDemandOutcome); LOGGER.debug("returning the ManualDemandScenario with id={}", savedDemandOutcome.getId()); return savedDemandOutcome; }
/* * (non-Javadoc) * @see au.org.aurin.wif.svc.suitability.ManualDemandScenarioService# * createManualDemandScenario * (au.org.aurin.wif.model.suitability.ManualDemandScenario, java.lang.String) */ public DemandOutcome createDemandOutcomeNew( final DemandOutcome demandOutcome, final String projectId) throws WifInvalidInputException, WifInvalidConfigException, ParsingException, IncompleteDemandOutcomeException { if (demandOutcome == null) { LOGGER.error("createManualDemandScenario failed: ManualDemandScenario is null or invalid"); throw new WifInvalidInputException( "createManualDemandScenario failed: ManualDemandScenario is null or invalid"); } final WifProject project = projectService.getProject(projectId); // final ManualDemandConfig manualdemandConfig = manualdemandConfigService // .getManualDemandConfig(projectId); final DemandConfig demandConfig = demandConfigService.getDemandConfig(projectId); project.setDemandConfig(demandConfig); // project.setManualDemandConfig(manualdemandConfig); try { // ManualDemandScenario = ManualDemandScenarioParser.parse( // ManualDemandScenario, manualdemandConfig, project); } catch (final Exception e) { LOGGER.error("Parsing new scenario failed", e); throw new IncompleteDemandOutcomeException("Parsing new scenario failed", e); } LOGGER.debug("persisting the DemandOutcome={}", demandOutcome.getLabel()); demandOutcome.setProjectId(projectId); final DemandOutcome savedDemandOutcome = demandOutcomeDao.persistDemandOutcome(demandOutcome); LOGGER.debug("returning the ManualDemandScenario with id={}", savedDemandOutcome.getId()); project.getDemandOutcomesMap().put(savedDemandOutcome.getId(), savedDemandOutcome.getLabel()); wifProjectDao.updateProject(project); return savedDemandOutcome; }
/* * (non-Javadoc) * @see * au.org.aurin.wif.svc.ManualDemandScenarioService#deleteManualDemandScenario * (java.lang.String, java.lang.String) */ public void deleteDemandOutcome(final String id, final String projectId) throws WifInvalidInputException, WifInvalidConfigException, ParsingException { LOGGER.info("deleting the ManualDemandScenario with ID={}", id); final DemandOutcome demandOutcome = demandOutcomeDao.findDemandOutcomeById(id); if (demandOutcome.getProjectId().equals(projectId)) { // Deleting associated area requirements final List<AreaRequirement> requirements = areaRequirementDao.getAreaRequirements(demandOutcome.getId()); for (final AreaRequirement areaRequirement : requirements) { areaRequirementDao.deleteAreaRequirement(areaRequirement); } demandOutcomeDao.deleteDemandOutcome(demandOutcome); final WifProject project = projectService.getProject(projectId); project.getDemandOutcomesMap().remove(id); wifProjectDao.updateProject(project); } else { LOGGER.error( "illegal argument, the ManualDemandScenario supplied doesn't belong to project: " + projectId); throw new WifInvalidInputException( "illegal argument, the ManualDemandScenario supplied doesn't belong to project: " + projectId); } }