Search in sources :

Example 1 with ProjectAllocationWrongAmountException

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"));
    }
}
Also used : ProjectAllocationIncreaseInExpiredProjectException(io.imunity.furms.api.validation.exceptions.ProjectAllocationIncreaseInExpiredProjectException) DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) ProjectAllocationDecreaseBeyondUsageException(io.imunity.furms.api.validation.exceptions.ProjectAllocationDecreaseBeyondUsageException) ProjectAllocation(io.imunity.furms.domain.project_allocation.ProjectAllocation) ProjectAllocationIsNotInTerminalStateException(io.imunity.furms.api.validation.exceptions.ProjectAllocationIsNotInTerminalStateException) ProjectAllocationWrongAmountException(io.imunity.furms.api.validation.exceptions.ProjectAllocationWrongAmountException) ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException(io.imunity.furms.api.validation.exceptions.ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException) ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException(io.imunity.furms.api.validation.exceptions.ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException) ProjectAllocationIncreaseInExpiredProjectException(io.imunity.furms.api.validation.exceptions.ProjectAllocationIncreaseInExpiredProjectException) ProjectAllocationIsNotInTerminalStateException(io.imunity.furms.api.validation.exceptions.ProjectAllocationIsNotInTerminalStateException) ProjectAllocationDecreaseBeyondUsageException(io.imunity.furms.api.validation.exceptions.ProjectAllocationDecreaseBeyondUsageException) ProjectAllocationWrongAmountException(io.imunity.furms.api.validation.exceptions.ProjectAllocationWrongAmountException)

Example 2 with ProjectAllocationWrongAmountException

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");
}
Also used : ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException(io.imunity.furms.api.validation.exceptions.ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException) Project(io.imunity.furms.domain.projects.Project) DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) ResourceUsageRepository(io.imunity.furms.spi.resource_usage.ResourceUsageRepository) ProjectAllocationInstallationRepository(io.imunity.furms.spi.project_allocation_installation.ProjectAllocationInstallationRepository) CommunityIsNotRelatedWithCommunityAllocation(io.imunity.furms.api.validation.exceptions.CommunityIsNotRelatedWithCommunityAllocation) ResourceCreditExpiredException(io.imunity.furms.api.validation.exceptions.ResourceCreditExpiredException) ProjectInstallationService(io.imunity.furms.core.project_installation.ProjectInstallationService) ValidationUtils.assertFalse(io.imunity.furms.utils.ValidationUtils.assertFalse) ResourceCredit(io.imunity.furms.domain.resource_credits.ResourceCredit) BigDecimal(java.math.BigDecimal) ValidationUtils.assertTrue(io.imunity.furms.utils.ValidationUtils.assertTrue) ProjectNotInTerminalStateException(io.imunity.furms.api.validation.exceptions.ProjectNotInTerminalStateException) ProjectAllocationInstallation(io.imunity.furms.domain.project_allocation_installation.ProjectAllocationInstallation) ProjectAllocationRepository(io.imunity.furms.spi.project_allocation.ProjectAllocationRepository) ProjectExpiredException(io.imunity.furms.api.validation.exceptions.ProjectExpiredException) ProjectAllocation(io.imunity.furms.domain.project_allocation.ProjectAllocation) ProjectIsNotRelatedWithCommunity(io.imunity.furms.api.validation.exceptions.ProjectIsNotRelatedWithCommunity) ProjectAllocationIncreaseInExpiredProjectException(io.imunity.furms.api.validation.exceptions.ProjectAllocationIncreaseInExpiredProjectException) Assert.notNull(org.springframework.util.Assert.notNull) ProjectAllocationIsNotInTerminalStateException(io.imunity.furms.api.validation.exceptions.ProjectAllocationIsNotInTerminalStateException) IdNotFoundValidationError(io.imunity.furms.api.validation.exceptions.IdNotFoundValidationError) CommunityAllocation(io.imunity.furms.domain.community_allocation.CommunityAllocation) ProjectIsNotRelatedWithProjectAllocation(io.imunity.furms.api.validation.exceptions.ProjectIsNotRelatedWithProjectAllocation) ProjectAllocationDecreaseBeyondUsageException(io.imunity.furms.api.validation.exceptions.ProjectAllocationDecreaseBeyondUsageException) ResourceCreditRepository(io.imunity.furms.spi.resource_credits.ResourceCreditRepository) Objects(java.util.Objects) CommunityAllocationRepository(io.imunity.furms.spi.community_allocation.CommunityAllocationRepository) Component(org.springframework.stereotype.Component) ProjectDeallocation(io.imunity.furms.domain.project_allocation_installation.ProjectDeallocation) Optional(java.util.Optional) ProjectRepository(io.imunity.furms.spi.projects.ProjectRepository) ProjectAllocationWrongAmountException(io.imunity.furms.api.validation.exceptions.ProjectAllocationWrongAmountException) MAX_NAME_LENGTH(io.imunity.furms.core.constant.ValidationConst.MAX_NAME_LENGTH) ProjectAllocationWrongAmountException(io.imunity.furms.api.validation.exceptions.ProjectAllocationWrongAmountException) BigDecimal(java.math.BigDecimal)

Aggregations

DuplicatedNameValidationError (io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError)2 ProjectAllocationDecreaseBeyondUsageException (io.imunity.furms.api.validation.exceptions.ProjectAllocationDecreaseBeyondUsageException)2 ProjectAllocationIncreaseInExpiredProjectException (io.imunity.furms.api.validation.exceptions.ProjectAllocationIncreaseInExpiredProjectException)2 ProjectAllocationIsNotInTerminalStateException (io.imunity.furms.api.validation.exceptions.ProjectAllocationIsNotInTerminalStateException)2 ProjectAllocationWrongAmountException (io.imunity.furms.api.validation.exceptions.ProjectAllocationWrongAmountException)2 ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException (io.imunity.furms.api.validation.exceptions.ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException)2 ProjectAllocation (io.imunity.furms.domain.project_allocation.ProjectAllocation)2 CommunityIsNotRelatedWithCommunityAllocation (io.imunity.furms.api.validation.exceptions.CommunityIsNotRelatedWithCommunityAllocation)1 IdNotFoundValidationError (io.imunity.furms.api.validation.exceptions.IdNotFoundValidationError)1 ProjectExpiredException (io.imunity.furms.api.validation.exceptions.ProjectExpiredException)1 ProjectIsNotRelatedWithCommunity (io.imunity.furms.api.validation.exceptions.ProjectIsNotRelatedWithCommunity)1 ProjectIsNotRelatedWithProjectAllocation (io.imunity.furms.api.validation.exceptions.ProjectIsNotRelatedWithProjectAllocation)1 ProjectNotInTerminalStateException (io.imunity.furms.api.validation.exceptions.ProjectNotInTerminalStateException)1 ResourceCreditExpiredException (io.imunity.furms.api.validation.exceptions.ResourceCreditExpiredException)1 MAX_NAME_LENGTH (io.imunity.furms.core.constant.ValidationConst.MAX_NAME_LENGTH)1 ProjectInstallationService (io.imunity.furms.core.project_installation.ProjectInstallationService)1 CommunityAllocation (io.imunity.furms.domain.community_allocation.CommunityAllocation)1 ProjectAllocationInstallation (io.imunity.furms.domain.project_allocation_installation.ProjectAllocationInstallation)1 ProjectDeallocation (io.imunity.furms.domain.project_allocation_installation.ProjectDeallocation)1 Project (io.imunity.furms.domain.projects.Project)1