diff --git a/src/main/java/software/netcore/radman/ui/component/wizard/demo/AttributeStep.java b/src/main/java/software/netcore/radman/ui/component/wizard/demo/AttributeStep.java index f424669..a62159d 100644 --- a/src/main/java/software/netcore/radman/ui/component/wizard/demo/AttributeStep.java +++ b/src/main/java/software/netcore/radman/ui/component/wizard/demo/AttributeStep.java @@ -45,12 +45,10 @@ public AttributeStep(RadiusUserService radiusUserService, List { if (event.getValue().equals(AUTH_ATTR)) { formLayout.removeAll(); -// AttributeForm authForm = new AttributeForm<>(AuthenticationAttributeDto.class); attributeForm = new AttributeForm<>(AuthenticationAttributeDto.class); formLayout.add(attributeForm); } else { formLayout.removeAll(); -// AttributeForm autzForm = new AttributeForm<>(AuthorizationAttributeDto.class); attributeForm = new AttributeForm<>(AuthorizationAttributeDto.class); formLayout.add(attributeForm); } @@ -116,7 +114,7 @@ public Component getContent() { @Override public boolean isValid() { - return true; + return authForm.isValid(); } @Override @@ -163,7 +161,7 @@ public Component getContent() { @Override public boolean isValid() { - return false; + return authForm.isValid(); } @Override diff --git a/src/main/java/software/netcore/radman/ui/component/wizard/demo/NasStep.java b/src/main/java/software/netcore/radman/ui/component/wizard/demo/NasStep.java index 1909fb4..07f1e2b 100644 --- a/src/main/java/software/netcore/radman/ui/component/wizard/demo/NasStep.java +++ b/src/main/java/software/netcore/radman/ui/component/wizard/demo/NasStep.java @@ -11,6 +11,7 @@ import org.springframework.data.domain.Sort; import org.vaadin.firitin.components.orderedlayout.VHorizontalLayout; import org.vaadin.firitin.components.orderedlayout.VVerticalLayout; +import org.vaadin.firitin.components.textfield.VTextField; import software.netcore.radman.buisness.service.nas.NasService; import software.netcore.radman.buisness.service.nas.dto.NasDto; import software.netcore.radman.buisness.service.nas.dto.NasGroupDto; @@ -18,6 +19,7 @@ import software.netcore.radman.ui.view.nas.widget.NasForm; import java.util.List; +import java.util.Objects; /** * @author daniel @@ -42,7 +44,6 @@ public NasStep(NasService nasService, List { private static final String NO = "No"; @@ -75,6 +81,13 @@ public NasStepSecond(NasService nasService, String nasIpAddress) { VHorizontalLayout groupHolder = new VHorizontalLayout(); radioGroup = new RadioButtonGroup<>(); radioGroup.setItems(NO, EXISTING_GROUPS, NEW_GROUP); + radioGroup.setItemEnabledProvider(item -> { + if (EXISTING_GROUPS.equals((String) item) && nasService.countNasGroupRecords("") == 0) { + return false; + } + + return true; + }); existingGroups = new ComboBox<>("Group name"); existingGroups.setItemLabelGenerator(NasGroupDto::getGroupName); @@ -84,7 +97,9 @@ public NasStepSecond(NasService nasService, String nasIpAddress) { query -> (int) nasService.countNasGroupRecords(query.getFilter().orElse(null)))); newGroupName = new TextField("New group name"); + newGroupName.setRequired(true); binder.forField(newGroupName) + .asRequired("Group name is required") .bind(NasGroupDto::getGroupName, NasGroupDto::setGroupName); radioGroup.addValueChangeListener(event -> { @@ -119,7 +134,7 @@ public boolean isValid() { public void writeDataToStorage(@NonNull NewEntityWizardDataStorage dataStorage) { if (!radioGroup.getValue().equals(NO)) { NasGroupDto nasGroupDto = new NasGroupDto(); - if (radioGroup.getValue().equals(EXISTING_GROUPS)) { + if (radioGroup.getValue().equals(EXISTING_GROUPS) && Objects.nonNull(existingGroups.getValue())) { nasGroupDto.setGroupName(existingGroups.getValue().getGroupName()); } else if (radioGroup.getValue().equals(NEW_GROUP)) { nasGroupDto.setGroupName(newGroupName.getValue()); diff --git a/src/main/java/software/netcore/radman/ui/component/wizard/demo/UserGroupStep.java b/src/main/java/software/netcore/radman/ui/component/wizard/demo/UserGroupStep.java index a06202e..6bfbff4 100644 --- a/src/main/java/software/netcore/radman/ui/component/wizard/demo/UserGroupStep.java +++ b/src/main/java/software/netcore/radman/ui/component/wizard/demo/UserGroupStep.java @@ -9,6 +9,7 @@ import com.vaadin.flow.component.html.Hr; import com.vaadin.flow.component.orderedlayout.FlexComponent; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; +import com.vaadin.flow.data.binder.BeanValidationBinder; import com.vaadin.flow.data.provider.CallbackDataProvider; import com.vaadin.flow.data.provider.InMemoryDataProvider; import com.vaadin.flow.data.provider.ListDataProvider; @@ -145,11 +146,17 @@ public boolean hasNextStep() { private class AddUserDialog extends Dialog { AddUserDialog(String groupName, UpdateListener updateListener) { + BeanValidationBinder binder = new BeanValidationBinder<>(RadiusUserDto.class); add(new H3("Add user to group")); ComboBox username = new ComboBox<>("Username"); username.setItemLabelGenerator(RadiusUserDto::getUsername); + username.setAllowCustomValue(false); username.setAutofocus(true); + username.setRequired(true); + + binder.forField(username) + .asRequired(); username.setDataProvider(new CallbackDataProvider<>(query -> userService.pageRadiusUsers(new RadiusUserFilter(query.getFilter().orElse(null), @@ -160,13 +167,13 @@ private class AddUserDialog extends Dialog { .orElse(null), true, false)))); Button add = new Button("Add", event -> { - if (StringUtils.isNotEmpty(groupName)) { + if (StringUtils.isNotEmpty(groupName) && binder.isValid() && Objects.nonNull(username.getValue())) { RadiusUserToGroupDto dto = new RadiusUserToGroupDto(); dto.setUsername(username.getValue().getUsername()); dto.setGroupName(groupName); updateListener.onUpdated(this, dto); + close(); } - close(); }); Button cancel = new Button("Cancel", event -> setOpened(false)); diff --git a/src/main/java/software/netcore/radman/ui/menu/MenuTemplate.java b/src/main/java/software/netcore/radman/ui/menu/MenuTemplate.java index 3e1738d..682de27 100644 --- a/src/main/java/software/netcore/radman/ui/menu/MenuTemplate.java +++ b/src/main/java/software/netcore/radman/ui/menu/MenuTemplate.java @@ -169,12 +169,16 @@ void saveNewEntityWizardData(NewEntityWizardDataStorage dataStorage) { nasService.createNas(dataStorage.getNasDto()); } - if (Objects.nonNull(dataStorage.getNasGroupDtos())) { + if (!dataStorage.getNasGroupDtos().isEmpty()) { for (NasGroupDto dto : dataStorage.getNasGroupDtos()) { nasService.createNasGroup(dto); } } + if (Objects.nonNull(dataStorage.getRadiusUserDto())) { + radiusUserService.createRadiusUser(dataStorage.getRadiusUserDto()); + } + if (Objects.nonNull(dataStorage.getRadiusGroupDtos())) { for (RadiusGroupDto dto : dataStorage.getRadiusGroupDtos()) { radiusUserService.createRadiusUsersGroup(dto); @@ -186,7 +190,7 @@ void saveNewEntityWizardData(NewEntityWizardDataStorage dataStorage) { try { radiusUserService.addRadiusUserToGroup(dto); } catch (DuplicityException e) { - e.printStackTrace(); //TODO wizard +// e.printStackTrace(); //TODO wizard } } } diff --git a/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthForm.java b/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthForm.java index 9a587d8..9cd2254 100644 --- a/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthForm.java +++ b/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthForm.java @@ -179,8 +179,8 @@ public AuthForm(@NonNull Class clazz, .withComponents(authTargetConfigLayout) .withComponents(attrConfigLayout)); } else if (formConfig.isPredefinedUser()) { - username.setValue(formConfig.getPredefinedUserDto()); authTargetSelect.setValue(AuthTarget.RADIUS_USER); + username.setValue(formConfig.getPredefinedUserDto()); attrConfigLayout.add(attribute, opSelect, value); add(new VVerticalLayout() .withComponents(attrConfigLayout));