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