Search in sources :

Example 6 with OptionalParameter

use of com.vaadin.flow.router.OptionalParameter in project furms by unity-idm.

the class ProjectFormView method setParameter.

@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
    ProjectViewModel projectViewModel = ofNullable(parameter).flatMap(id -> handleExceptions(() -> resolver.resolve(id, UIContext.getCurrent().getZone()))).orElseGet(() -> new ProjectViewModel(ResourceGetter.getCurrentResourceId()));
    String trans = parameter == null ? "view.community-admin.project.form.parameter.new" : "view.community-admin.project.form.parameter.update";
    breadCrumbParameter = new BreadCrumbParameter(parameter, getTranslation(trans));
    projectFormComponent.setFormPools(projectViewModel);
}
Also used : VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) Project(io.imunity.furms.domain.projects.Project) ProjectViewModel(io.imunity.furms.ui.project.ProjectViewModel) Binder(com.vaadin.flow.data.binder.Binder) NotificationUtils(io.imunity.furms.ui.utils.NotificationUtils) PageTitle(io.imunity.furms.ui.components.PageTitle) BeforeEvent(com.vaadin.flow.router.BeforeEvent) Route(com.vaadin.flow.router.Route) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) FurmsViewUserModelMapper(io.imunity.furms.ui.user_context.FurmsViewUserModelMapper) OptionalException(io.imunity.furms.ui.utils.OptionalException) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) Key(com.vaadin.flow.component.Key) UI(com.vaadin.flow.component.UI) UserService(io.imunity.furms.api.users.UserService) CommunityAdminMenu(io.imunity.furms.ui.views.community.CommunityAdminMenu) VaadinExceptionHandler.getResultOrException(io.imunity.furms.ui.utils.VaadinExceptionHandler.getResultOrException) FormButtons(io.imunity.furms.ui.components.FormButtons) FurmsViewUserModel(io.imunity.furms.ui.user_context.FurmsViewUserModel) UIContext(io.imunity.furms.ui.user_context.UIContext) ButtonVariant(com.vaadin.flow.component.button.ButtonVariant) ProjectFormComponent(io.imunity.furms.ui.project.ProjectFormComponent) Optional.ofNullable(java.util.Optional.ofNullable) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) OptionalParameter(com.vaadin.flow.router.OptionalParameter) ProjectViewModelMapper(io.imunity.furms.ui.project.ProjectViewModelMapper) List(java.util.List) Button(com.vaadin.flow.component.button.Button) ResourceGetter(io.imunity.furms.ui.utils.ResourceGetter) Optional(java.util.Optional) ProjectService(io.imunity.furms.api.projects.ProjectService) ProjectModelResolver(io.imunity.furms.ui.project.ProjectModelResolver) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) ProjectViewModel(io.imunity.furms.ui.project.ProjectViewModel)

Example 7 with OptionalParameter

use of com.vaadin.flow.router.OptionalParameter in project furms by unity-idm.

the class ProjectResourceAllocationsDetailsView method setParameter.

@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
    Optional<String> projectId = event.getLocation().getQueryParameters().getParameters().getOrDefault("projectId", List.of()).stream().findAny();
    Optional<ProjectAllocation> projectAllocation = ofNullable(parameter).filter(id -> projectId.isPresent()).flatMap(id -> handleExceptions(() -> projectAllocationService.findByProjectIdAndId(projectId.get(), id))).flatMap(Function.identity());
    if (projectAllocation.isPresent()) {
        getContent().removeAll();
        breadCrumbParameter = new BreadCrumbParameter(parameter, projectAllocation.get().name, getTranslation("view.user-settings.projects.page.details.bread-crumb"));
        ResourceAllocationChart resourceAllocationChart = new ResourceAllocationChart(chartPowerService.getChartDataForProjectAlloc(projectAllocation.get().projectId, projectAllocation.get().id), jsonExporter.getJsonForProjectAllocation(projectAllocation.get().projectId, projectAllocation.get().id), csvExporter.getCsvForProjectAllocation(projectAllocation.get().projectId, projectAllocation.get().id));
        getContent().add(resourceAllocationChart);
    }
}
Also used : VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) Optional.ofNullable(java.util.Optional.ofNullable) ResourceUsageJSONExporter(io.imunity.furms.api.export.ResourceUsageJSONExporter) ResourceAllocationChart(io.imunity.furms.ui.charts.ResourceAllocationChart) PageTitle(io.imunity.furms.ui.components.PageTitle) BeforeEvent(com.vaadin.flow.router.BeforeEvent) Function(java.util.function.Function) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) Route(com.vaadin.flow.router.Route) OptionalParameter(com.vaadin.flow.router.OptionalParameter) List(java.util.List) ProjectAllocationService(io.imunity.furms.api.project_allocation.ProjectAllocationService) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) Optional(java.util.Optional) ResourceUsageCSVExporter(io.imunity.furms.api.export.ResourceUsageCSVExporter) UserSettingsMenu(io.imunity.furms.ui.views.user_settings.UserSettingsMenu) ProjectAllocation(io.imunity.furms.domain.project_allocation.ProjectAllocation) ChartPowerService(io.imunity.furms.ui.charts.ChartPowerService) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) ProjectAllocation(io.imunity.furms.domain.project_allocation.ProjectAllocation) ResourceAllocationChart(io.imunity.furms.ui.charts.ResourceAllocationChart)

Example 8 with OptionalParameter

use of com.vaadin.flow.router.OptionalParameter in project furms by unity-idm.

the class SSHKeyFormView method setParameter.

@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
    try {
        sshKeyService.assertIsEligibleToManageKeys();
    } catch (UserWithoutFenixIdValidationError e) {
        LOG.debug(e.getMessage(), e);
        showErrorNotification(getTranslation("user.without.fenixid.error.message"));
        setVisible(false);
        return;
    } catch (UserWithoutSitesError e) {
        LOG.debug(e.getMessage(), e);
        showErrorNotification(getTranslation("view.user-settings.ssh-keys.user.without.sites.error.message"));
        return;
    } catch (AccessDeniedException e) {
        LOG.debug(e.getMessage(), e);
        showErrorNotification(getTranslation("view.user-settings.ssh-keys.access.denied.error.message"));
        setVisible(false);
        return;
    }
    SSHKeyUpdateModel serviceViewModel = ofNullable(parameter).flatMap(id -> handleExceptions(() -> sshKeyService.findById(id))).flatMap(Function.identity()).map(k -> SSHKeyViewModelMapper.mapToUpdate(k, zoneId)).orElseGet(() -> new SSHKeyUpdateModel(authzService.getCurrentUserId()));
    String trans = parameter == null ? "view.user-settings.ssh-keys.form.parameter.new" : "view.user-settings.ssh-keys.form.parameter.update";
    breadCrumbParameter = new BreadCrumbParameter(parameter, getTranslation(trans));
    sshKeyComponent.setFormPools(serviceViewModel);
}
Also used : VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) SSHKeyHistoryException(io.imunity.furms.api.ssh_keys.SSHKeyHistoryException) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) ZonedDateTime(java.time.ZonedDateTime) Binder(com.vaadin.flow.data.binder.Binder) LoggerFactory(org.slf4j.LoggerFactory) SSHKeyService(io.imunity.furms.api.ssh_keys.SSHKeyService) PageTitle(io.imunity.furms.ui.components.PageTitle) Function(java.util.function.Function) BeforeEvent(com.vaadin.flow.router.BeforeEvent) Route(com.vaadin.flow.router.Route) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) Key(com.vaadin.flow.component.Key) SiteService(io.imunity.furms.api.sites.SiteService) UserSettingsMenu(io.imunity.furms.ui.views.user_settings.UserSettingsMenu) UI(com.vaadin.flow.component.UI) FormButtons(io.imunity.furms.ui.components.FormButtons) Logger(org.slf4j.Logger) UIContext(io.imunity.furms.ui.user_context.UIContext) ButtonVariant(com.vaadin.flow.component.button.ButtonVariant) Optional.ofNullable(java.util.Optional.ofNullable) MethodHandles(java.lang.invoke.MethodHandles) Set(java.util.Set) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Site(io.imunity.furms.domain.sites.Site) UninstalledUserError(io.imunity.furms.api.validation.exceptions.UninstalledUserError) ZoneId(java.time.ZoneId) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) OptionalParameter(com.vaadin.flow.router.OptionalParameter) UserWithoutSitesError(io.imunity.furms.api.validation.exceptions.UserWithoutSitesError) Button(com.vaadin.flow.component.button.Button) AuthzService(io.imunity.furms.api.authz.AuthzService) Optional(java.util.Optional) UserWithoutFenixIdValidationError(io.imunity.furms.api.validation.exceptions.UserWithoutFenixIdValidationError) Collections(java.util.Collections) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) AccessDeniedException(org.springframework.security.access.AccessDeniedException) UserWithoutFenixIdValidationError(io.imunity.furms.api.validation.exceptions.UserWithoutFenixIdValidationError) UserWithoutSitesError(io.imunity.furms.api.validation.exceptions.UserWithoutSitesError)

Example 9 with OptionalParameter

use of com.vaadin.flow.router.OptionalParameter in project furms by unity-idm.

the class PolicyDocumentFormView method setParameter.

@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
    PolicyDocumentFormModel policyDocumentFormModel = ofNullable(parameter).flatMap(id -> handleExceptions(() -> policyDocumentService.findById(siteId, new PolicyId(id)))).flatMap(Function.identity()).map(PolicyDocumentFormModelMapper::map).orElseGet(() -> new PolicyDocumentFormModel(siteId));
    String trans = parameter == null ? "view.site-admin.policy-documents.form.parameter.new" : "view.site-admin.policy-documents.form.parameter.update";
    breadCrumbParameter = new BreadCrumbParameter(parameter, getTranslation(trans));
    binder.setBean(policyDocumentFormModel);
    revision.setText(String.valueOf(policyDocumentFormModel.revision));
    if (policyDocumentFormModel.id == null)
        addCreateButtons();
    else {
        addUpdateButtons();
        workflowComboBox.setReadOnly(true);
    }
}
Also used : VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) PolicyId(io.imunity.furms.domain.policy_documents.PolicyId) WysiwygE(org.vaadin.pekka.WysiwygE) Arrays(java.util.Arrays) ResourceGetter.getCurrentResourceId(io.imunity.furms.ui.utils.ResourceGetter.getCurrentResourceId) PolicyDocumentIsInconsistentException(io.imunity.furms.api.validation.exceptions.PolicyDocumentIsInconsistentException) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) Binder(com.vaadin.flow.data.binder.Binder) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) PageTitle(io.imunity.furms.ui.components.PageTitle) ComboBox(com.vaadin.flow.component.combobox.ComboBox) BeforeEvent(com.vaadin.flow.router.BeforeEvent) FurmsFormLayout(io.imunity.furms.ui.components.FurmsFormLayout) Function(java.util.function.Function) Route(com.vaadin.flow.router.Route) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) Key(com.vaadin.flow.component.Key) UI(com.vaadin.flow.component.UI) PolicyWorkflow(io.imunity.furms.domain.policy_documents.PolicyWorkflow) TextField(com.vaadin.flow.component.textfield.TextField) EAGER(com.vaadin.flow.data.value.ValueChangeMode.EAGER) PolicyFile(io.imunity.furms.domain.policy_documents.PolicyFile) SiteAdminMenu(io.imunity.furms.ui.views.site.SiteAdminMenu) PolicyDocument(io.imunity.furms.domain.policy_documents.PolicyDocument) FormButtons(io.imunity.furms.ui.components.FormButtons) ButtonVariant(com.vaadin.flow.component.button.ButtonVariant) Optional.ofNullable(java.util.Optional.ofNullable) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) FormLayout(com.vaadin.flow.component.formlayout.FormLayout) OptionalParameter(com.vaadin.flow.router.OptionalParameter) Objects(java.util.Objects) Button(com.vaadin.flow.component.button.Button) PolicyContentType(io.imunity.furms.domain.policy_documents.PolicyContentType) MAX_NAME_LENGTH(java.util.prefs.Preferences.MAX_NAME_LENGTH) Optional(java.util.Optional) PolicyFileUpload(io.imunity.furms.ui.components.PolicyFileUpload) Dialog(com.vaadin.flow.component.dialog.Dialog) PolicyDocumentService(io.imunity.furms.api.policy_documents.PolicyDocumentService) RevisionFurmsDialog(io.imunity.furms.ui.components.RevisionFurmsDialog) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) PolicyId(io.imunity.furms.domain.policy_documents.PolicyId)

Example 10 with OptionalParameter

use of com.vaadin.flow.router.OptionalParameter in project furms by unity-idm.

the class ResourceCreditFormView method setParameter.

@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
    ResourceCreditViewModel resourceCreditViewModel = ofNullable(parameter).flatMap(id -> handleExceptions(() -> resourceCreditService.findWithAllocationsByIdAndSiteId(id, getCurrentResourceId()))).flatMap(Function.identity()).map(credit -> ResourceCreditViewModelMapper.map(credit, zoneId)).orElseGet(() -> new ResourceCreditViewModel(getCurrentResourceId()));
    String trans = parameter == null ? "view.site-admin.resource-credits.form.parameter.new" : "view.site-admin.resource-credits.form.parameter.update";
    breadCrumbParameter = new BreadCrumbParameter(parameter, getTranslation(trans));
    resourceCreditFormComponent.setFormPools(resourceCreditViewModel, resourceCreditService.hasCommunityAllocations(resourceCreditViewModel.getId(), resourceCreditViewModel.getSiteId()), () -> resourceCreditService.getOccupiedNames(resourceCreditViewModel.getSiteId()));
}
Also used : VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) ResourceGetter.getCurrentResourceId(io.imunity.furms.ui.utils.ResourceGetter.getCurrentResourceId) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) Binder(com.vaadin.flow.data.binder.Binder) PageTitle(io.imunity.furms.ui.components.PageTitle) BeforeEvent(com.vaadin.flow.router.BeforeEvent) Function(java.util.function.Function) Route(com.vaadin.flow.router.Route) ResourceCredit(io.imunity.furms.domain.resource_credits.ResourceCredit) ResourceTypeService(io.imunity.furms.api.resource_types.ResourceTypeService) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) OptionalException(io.imunity.furms.ui.utils.OptionalException) Map(java.util.Map) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) Key(com.vaadin.flow.component.Key) UI(com.vaadin.flow.component.UI) SiteAdminMenu(io.imunity.furms.ui.views.site.SiteAdminMenu) ResourceCreditService(io.imunity.furms.api.resource_credits.ResourceCreditService) VaadinExceptionHandler.getResultOrException(io.imunity.furms.ui.utils.VaadinExceptionHandler.getResultOrException) FormButtons(io.imunity.furms.ui.components.FormButtons) UIContext(io.imunity.furms.ui.user_context.UIContext) ButtonVariant(com.vaadin.flow.component.button.ButtonVariant) CreditUpdateBelowDistributedAmountException(io.imunity.furms.api.validation.exceptions.CreditUpdateBelowDistributedAmountException) ResourceCreditHasAllocationException(io.imunity.furms.api.validation.exceptions.ResourceCreditHasAllocationException) Optional.ofNullable(java.util.Optional.ofNullable) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) ZoneId(java.time.ZoneId) OptionalParameter(com.vaadin.flow.router.OptionalParameter) Button(com.vaadin.flow.component.button.Button) Optional(java.util.Optional) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter)

Aggregations

BeforeEvent (com.vaadin.flow.router.BeforeEvent)16 OptionalParameter (com.vaadin.flow.router.OptionalParameter)16 Route (com.vaadin.flow.router.Route)16 FurmsViewComponent (io.imunity.furms.ui.components.FurmsViewComponent)14 PageTitle (io.imunity.furms.ui.components.PageTitle)14 BreadCrumbParameter (io.imunity.furms.ui.components.layout.BreadCrumbParameter)14 VaadinExceptionHandler.handleExceptions (io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions)14 Optional (java.util.Optional)14 Optional.ofNullable (java.util.Optional.ofNullable)14 Function (java.util.function.Function)13 UI (com.vaadin.flow.component.UI)11 Button (com.vaadin.flow.component.button.Button)11 Key (com.vaadin.flow.component.Key)10 ButtonVariant (com.vaadin.flow.component.button.ButtonVariant)10 BeanValidationBinder (com.vaadin.flow.data.binder.BeanValidationBinder)10 Binder (com.vaadin.flow.data.binder.Binder)10 FormButtons (io.imunity.furms.ui.components.FormButtons)10 ResourceGetter.getCurrentResourceId (io.imunity.furms.ui.utils.ResourceGetter.getCurrentResourceId)8 NotificationUtils.showErrorNotification (io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification)6 DuplicatedNameValidationError (io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError)5