Search in sources :

Example 1 with DuplicatedNameValidationError

use of io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError 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 DuplicatedNameValidationError

use of io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError in project furms by unity-idm.

the class SitesView method updateAction.

private void updateAction(Editor<SiteGridItem> siteEditor) {
    if (siteEditor.getBinder().isValid()) {
        Optional<Component> component = siteEditor.getGrid().getColumnByKey("name").getEditorComponent().getChildren().filter(c -> c instanceof TextField).findFirst();
        if (component.isPresent()) {
            TextField name = component.map(c -> (TextField) c).get();
            try {
                siteService.update(Site.builder().id(siteEditor.getItem().getId()).name(name.getValue()).build());
                siteEditor.cancel();
                refreshGrid(siteEditor);
                showSuccessNotification(getTranslation("view.sites.form.save.success"));
            } catch (DuplicatedNameValidationError e) {
                name.setErrorMessage(getTranslation("view.sites.form.error.validation.field.name.unique"));
                name.setInvalid(true);
            } catch (RuntimeException e) {
                LOG.warn("Could not update Site.", e);
                showErrorNotification(getTranslation("view.sites.form.error.unexpected", "update"));
            }
        }
    }
}
Also used : DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) Component(com.vaadin.flow.component.Component) LoggerFactory(org.slf4j.LoggerFactory) MenuButton(io.imunity.furms.ui.components.MenuButton) PageTitle(io.imunity.furms.ui.components.PageTitle) Route(com.vaadin.flow.router.Route) FlexLayout(com.vaadin.flow.component.orderedlayout.FlexLayout) DenseGrid(io.imunity.furms.ui.components.DenseGrid) Key(com.vaadin.flow.component.Key) UI(com.vaadin.flow.component.UI) TextField(com.vaadin.flow.component.textfield.TextField) USERS(com.vaadin.flow.component.icon.VaadinIcon.USERS) MethodHandles(java.lang.invoke.MethodHandles) Editor(com.vaadin.flow.component.grid.editor.Editor) RouterGridLink(io.imunity.furms.ui.components.RouterGridLink) END(com.vaadin.flow.component.grid.ColumnTextAlign.END) Objects(java.util.Objects) List(java.util.List) Optional(java.util.Optional) NotificationUtils.showSuccessNotification(io.imunity.furms.ui.utils.NotificationUtils.showSuccessNotification) ViewHeaderLayout(io.imunity.furms.ui.components.ViewHeaderLayout) EditorOpenEvent(com.vaadin.flow.component.grid.editor.EditorOpenEvent) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) SiteHasResourceCreditsRemoveValidationError(io.imunity.furms.api.validation.exceptions.SiteHasResourceCreditsRemoveValidationError) Binder(com.vaadin.flow.data.binder.Binder) Div(com.vaadin.flow.component.html.Div) FurmsDialog(io.imunity.furms.ui.components.FurmsDialog) PLUS_CIRCLE(com.vaadin.flow.component.icon.VaadinIcon.PLUS_CIRCLE) LUMO_TERTIARY(com.vaadin.flow.component.button.ButtonVariant.LUMO_TERTIARY) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) RouterLink(com.vaadin.flow.router.RouterLink) SiteService(io.imunity.furms.api.sites.SiteService) Icon(com.vaadin.flow.component.icon.Icon) EAGER(com.vaadin.flow.data.value.ValueChangeMode.EAGER) Logger(org.slf4j.Logger) Grid(com.vaadin.flow.component.grid.Grid) TRASH(com.vaadin.flow.component.icon.VaadinIcon.TRASH) FENIX_ADMIN_SITES(io.imunity.furms.domain.constant.RoutesConst.FENIX_ADMIN_SITES) EDIT(com.vaadin.flow.component.icon.VaadinIcon.EDIT) GridActionMenu(io.imunity.furms.ui.components.GridActionMenu) GridActionsButtonLayout(io.imunity.furms.ui.components.GridActionsButtonLayout) ClickEvent(com.vaadin.flow.component.ClickEvent) Site(io.imunity.furms.domain.sites.Site) FenixAdminMenu(io.imunity.furms.ui.views.fenix.menu.FenixAdminMenu) Collectors.toList(java.util.stream.Collectors.toList) Button(com.vaadin.flow.component.button.Button) SitesAdminsView(io.imunity.furms.ui.views.fenix.sites.admins.SitesAdminsView) Comparator(java.util.Comparator) SitesAddView(io.imunity.furms.ui.views.fenix.sites.add.SitesAddView) NAME_MAX_LENGTH(io.imunity.furms.ui.utils.FormSettings.NAME_MAX_LENGTH) DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) TextField(com.vaadin.flow.component.textfield.TextField) Component(com.vaadin.flow.component.Component) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent)

Example 3 with DuplicatedNameValidationError

use of io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError in project furms by unity-idm.

the class PolicyDocumentFormView method savePolicyDocument.

private void savePolicyDocument(boolean withRevision) {
    PolicyDocumentFormModel policyDocumentFormModel = binder.getBean();
    PolicyDocument policyDocument = PolicyDocumentFormModelMapper.map(policyDocumentFormModel);
    try {
        if (policyDocument.id == null)
            policyDocumentService.create(policyDocument);
        else if (withRevision)
            policyDocumentService.updateWithRevision(policyDocument);
        else
            policyDocumentService.update(policyDocument);
        UI.getCurrent().navigate(PolicyDocumentsView.class);
    } catch (DuplicatedNameValidationError e) {
        showErrorNotification(getTranslation("name.duplicated.error.message"));
    } catch (PolicyDocumentIsInconsistentException e) {
        showErrorNotification(getTranslation("policy.document.terminal-state.message"));
    } catch (Exception e) {
        showErrorNotification(getTranslation("base.error.message"));
        throw e;
    }
}
Also used : DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) PolicyDocumentIsInconsistentException(io.imunity.furms.api.validation.exceptions.PolicyDocumentIsInconsistentException) PolicyDocument(io.imunity.furms.domain.policy_documents.PolicyDocument) PolicyDocumentIsInconsistentException(io.imunity.furms.api.validation.exceptions.PolicyDocumentIsInconsistentException)

Example 4 with DuplicatedNameValidationError

use of io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError in project furms by unity-idm.

the class ResourceCreditFormView method saveResourceCredit.

private void saveResourceCredit() {
    ResourceCreditViewModel serviceViewModel = binder.getBean();
    ResourceCredit resourceCredit = ResourceCreditViewModelMapper.map(serviceViewModel);
    OptionalException<Void> optionalException;
    if (resourceCredit.id == null)
        optionalException = getResultOrException(() -> resourceCreditService.create(resourceCredit));
    else
        optionalException = getResultOrException(() -> resourceCreditService.update(resourceCredit), KNOWN_EXCEPTIONS);
    optionalException.getException().ifPresentOrElse(throwable -> {
        if (throwable.getCause() instanceof DuplicatedNameValidationError && resourceCreditFormComponent.isNameDefault()) {
            showErrorNotification(getTranslation("default.name.duplicated.error.message"));
            resourceCreditFormComponent.reloadDefaultName();
        } else
            showErrorNotification(getTranslation(throwable.getMessage()));
    }, () -> UI.getCurrent().navigate(ResourceCreditsView.class));
}
Also used : DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) ResourceCredit(io.imunity.furms.domain.resource_credits.ResourceCredit)

Example 5 with DuplicatedNameValidationError

use of io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError in project furms by unity-idm.

the class SiteServiceValidator method validateName.

void validateName(String name) {
    notNull(name, "Site name has to be declared.");
    assertTrue(!siteRepository.isNamePresent(name), () -> new DuplicatedNameValidationError("Site name has to be unique."));
}
Also used : DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError)

Aggregations

DuplicatedNameValidationError (io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError)13 Button (com.vaadin.flow.component.button.Button)2 CommunityAllocation (io.imunity.furms.domain.community_allocation.CommunityAllocation)2 CommunityAllocationViewModel (io.imunity.furms.ui.community.allocations.CommunityAllocationViewModel)2 ClickEvent (com.vaadin.flow.component.ClickEvent)1 Component (com.vaadin.flow.component.Component)1 Key (com.vaadin.flow.component.Key)1 UI (com.vaadin.flow.component.UI)1 LUMO_TERTIARY (com.vaadin.flow.component.button.ButtonVariant.LUMO_TERTIARY)1 END (com.vaadin.flow.component.grid.ColumnTextAlign.END)1 Grid (com.vaadin.flow.component.grid.Grid)1 Editor (com.vaadin.flow.component.grid.editor.Editor)1 EditorOpenEvent (com.vaadin.flow.component.grid.editor.EditorOpenEvent)1 Div (com.vaadin.flow.component.html.Div)1 Icon (com.vaadin.flow.component.icon.Icon)1 EDIT (com.vaadin.flow.component.icon.VaadinIcon.EDIT)1 PLUS_CIRCLE (com.vaadin.flow.component.icon.VaadinIcon.PLUS_CIRCLE)1 TRASH (com.vaadin.flow.component.icon.VaadinIcon.TRASH)1 USERS (com.vaadin.flow.component.icon.VaadinIcon.USERS)1 FlexLayout (com.vaadin.flow.component.orderedlayout.FlexLayout)1