use of io.imunity.furms.api.validation.exceptions.ProjectAllocationWrongAmountException in project furms by unity-idm.
the class ProjectAllocationFormView method saveProjectAllocation.
private void saveProjectAllocation() {
ProjectAllocationViewModel allocationViewModel = binder.getBean();
ProjectAllocation projectAllocation = ProjectAllocationModelsMapper.map(allocationViewModel);
try {
if (projectAllocation.id == null)
projectAllocationService.create(communityId, projectAllocation);
else
projectAllocationService.update(communityId, projectAllocation);
UI.getCurrent().navigate(ProjectView.class, projectId);
} catch (ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException e) {
showErrorNotification(getTranslation("project.allocation.resource.type.unique.message"));
} catch (ProjectAllocationWrongAmountException e) {
showErrorNotification(getTranslation("project.allocation.wrong.amount.message"));
} catch (ProjectAllocationIncreaseInExpiredProjectException e) {
showErrorNotification(getTranslation("project.allocation.increase.amount.in.expired.project.message"));
} catch (ProjectAllocationDecreaseBeyondUsageException e) {
showErrorNotification(getTranslation("project.allocation.decrease.amount.beyond.usage.message"));
} catch (ProjectAllocationIsNotInTerminalStateException e) {
showErrorNotification(getTranslation("project.allocation.terminal-state.message"));
} catch (DuplicatedNameValidationError e) {
if (projectAllocationFormComponent.isNameDefault()) {
showErrorNotification(getTranslation("default.name.duplicated.error.message"));
projectAllocationFormComponent.reloadDefaultName();
} else
showErrorNotification(getTranslation("name.duplicated.error.message"));
} catch (Exception e) {
showErrorNotification(getTranslation("base.error.message"));
}
}
use of io.imunity.furms.api.validation.exceptions.ProjectAllocationWrongAmountException in project furms by unity-idm.
the class ProjectAllocationServiceValidator method assertAmountNotIncreasedBeyondCommunityAllocationLimit.
private void assertAmountNotIncreasedBeyondCommunityAllocationLimit(ProjectAllocation projectAllocation) {
BigDecimal availableAmount = projectAllocationRepository.getAvailableAmount(projectAllocation.communityAllocationId);
BigDecimal currentAllocatedAmount = projectAllocationRepository.findById(projectAllocation.id).map(x -> x.amount).orElseThrow(() -> new IllegalArgumentException(String.format("Project Allocation %s doesn't exist", projectAllocation.id)));
BigDecimal realIncreasedValue = projectAllocation.amount.subtract(currentAllocatedAmount);
if (availableAmount.subtract(realIncreasedValue).compareTo(BigDecimal.ZERO) <= 0)
throw new ProjectAllocationWrongAmountException("Allocation amount have to be less then community allocation limit");
}
Aggregations