Search in sources :

Example 1 with ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException

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"));
    }
}
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 ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException

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));
}
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) ResourceCredit(io.imunity.furms.domain.resource_credits.ResourceCredit) CommunityIsNotRelatedWithCommunityAllocation(io.imunity.furms.api.validation.exceptions.CommunityIsNotRelatedWithCommunityAllocation) CommunityAllocation(io.imunity.furms.domain.community_allocation.CommunityAllocation) ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException(io.imunity.furms.api.validation.exceptions.ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException)

Example 3 with ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException

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

Aggregations

ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException (io.imunity.furms.api.validation.exceptions.ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException)3 ProjectAllocation (io.imunity.furms.domain.project_allocation.ProjectAllocation)3 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 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