use of io.imunity.furms.api.validation.exceptions.ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException 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.ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException in project furms by unity-idm.
the class ProjectAllocationServiceValidator method assertProjectHasUniqueResourceTypeInGivenPointInTime.
private void assertProjectHasUniqueResourceTypeInGivenPointInTime(ProjectAllocation projectAllocation) {
CommunityAllocation communityAllocation = communityAllocationRepository.findById(projectAllocation.communityAllocationId).orElseThrow(() -> new IllegalStateException(String.format("Community Allocation %s doesn't exist", projectAllocation.communityAllocationId)));
ResourceCredit resourceCredit = resourceCreditRepository.findById(communityAllocation.resourceCreditId).orElseThrow(() -> new IllegalStateException(String.format("Resource Credit %s doesn't exist", communityAllocation.resourceCreditId)));
AllocationTimespan allocationTimespan = new AllocationTimespan(resourceCredit.utcStartTime, resourceCredit.utcEndTime);
boolean matches = projectAllocationRepository.findAllWithRelatedObjects(projectAllocation.projectId).stream().filter(x -> x.resourceType.id.equals(resourceCredit.resourceTypeId)).map(x -> new AllocationTimespan(x.resourceCredit.utcStartTime, x.resourceCredit.utcEndTime)).anyMatch(allocationTimespan::overlaps);
assertFalse(matches, () -> new ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException(projectAllocation.projectId, resourceCredit.resourceTypeId));
}
use of io.imunity.furms.api.validation.exceptions.ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException in project furms by unity-idm.
the class ProjectAllocationDashboardFormView method saveProjectAllocation.
private void saveProjectAllocation() {
final ProjectAllocationViewModel viewModel = binder.getBean();
final ProjectAllocation projectAllocation = ProjectAllocationModelsMapper.map(viewModel);
try {
projectAllocationService.create(viewModel.getCommunityId(), projectAllocation);
UI.getCurrent().navigate(DashboardView.class);
} catch (ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException e) {
showErrorNotification(getTranslation("project.allocation.resource.type.unique.message"));
} catch (Exception e) {
showErrorNotification(getTranslation("base.error.message"));
}
}
Aggregations