Skip to content

Commit

Permalink
#37 AttributeStep and UserStep work.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmajirsky committed Dec 1, 2020
1 parent bd15e83 commit d32d2a3
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ private void handleTransitionToNext() {
}
} else {
try {
getSteps().forEach(step -> step.writeDataToStorage(dataStorage));
getSteps().forEach(step -> {
if (step.isValid()) {
step.writeDataToStorage(dataStorage);
}
});
wizardFinalizer.finalizeWizard(dataStorage);
setOpened(false);
} catch (WizardFinalizeException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,55 @@
import com.vaadin.flow.component.combobox.ComboBox;
import lombok.NonNull;
import org.vaadin.firitin.components.orderedlayout.VVerticalLayout;
import software.netcore.radman.buisness.service.attribute.dto.AttributeDto;
import software.netcore.radman.buisness.service.attribute.dto.AuthenticationAttributeDto;
import software.netcore.radman.buisness.service.attribute.dto.AuthorizationAttributeDto;
import software.netcore.radman.ui.component.wizard.Wizard;
import software.netcore.radman.buisness.service.auth.dto.AuthDto;
import software.netcore.radman.buisness.service.auth.dto.AuthenticationDto;
import software.netcore.radman.buisness.service.auth.dto.AuthorizationDto;
import software.netcore.radman.buisness.service.user.radius.RadiusUserService;
import software.netcore.radman.ui.component.wizard.WizardStep;
import software.netcore.radman.ui.view.attributes.widget.AttributeForm;
import software.netcore.radman.ui.view.auth.widget.AuthForm;

import java.util.List;

/**
* @author daniel
* @since v. 1.0.3
*/
public class AttributeStep implements WizardStep<NewEntityWizardDataStorage> {

private static final String AUTH_ATTR = "Authentication attribute";
private static final String AUTZ_ATTR = "Authorization attribute";

private final VVerticalLayout contentLayout = new VVerticalLayout();
private final RadiusUserService radiusUserService;
private final List<WizardStep<NewEntityWizardDataStorage>> steps;

public AttributeStep(List<WizardStep<NewEntityWizardDataStorage>> steps) {
private final VVerticalLayout contentLayout = new VVerticalLayout();
private ComboBox<String> attrType;
private AttributeForm<? extends AttributeDto> attributeForm;

public AttributeStep(RadiusUserService radiusUserService, List<WizardStep<NewEntityWizardDataStorage>> steps) {
this.radiusUserService = radiusUserService;
this.steps = steps;

VVerticalLayout formLayout = new VVerticalLayout();

ComboBox<String> attrType = new ComboBox<>();
attrType = new ComboBox<>();
attrType.setItems(AUTH_ATTR, AUTZ_ATTR);
attrType.addValueChangeListener(event -> {
if (event.getValue().equals(AUTH_ATTR)) {
formLayout.removeAll();
AttributeForm<AuthenticationAttributeDto> authForm = new AttributeForm<>(AuthenticationAttributeDto.class);
formLayout.add(authForm);
} else {
formLayout.removeAll();
AttributeForm<AuthorizationAttributeDto> autzForm = new AttributeForm<>(AuthorizationAttributeDto.class);
formLayout.add(autzForm);
}
if (event.getValue().equals(AUTH_ATTR)) {
formLayout.removeAll();
// AttributeForm<AuthenticationAttributeDto> authForm = new AttributeForm<>(AuthenticationAttributeDto.class);
attributeForm = new AttributeForm<>(AuthenticationAttributeDto.class);
formLayout.add(attributeForm);
} else {
formLayout.removeAll();
// AttributeForm<AuthorizationAttributeDto> autzForm = new AttributeForm<>(AuthorizationAttributeDto.class);
attributeForm = new AttributeForm<>(AuthorizationAttributeDto.class);
formLayout.add(attributeForm);
}
});

contentLayout.withComponent(attrType)
Expand All @@ -50,21 +66,46 @@ public Component getContent() {

@Override
public boolean isValid() {
return false;
return true;
}

@Override
public void writeDataToStorage(@NonNull NewEntityWizardDataStorage dataStorage) {
if (attrType.getValue().equals(AUTH_ATTR)) {
dataStorage.setAuthenticationAttributeDto((AuthenticationAttributeDto) attributeForm.getBean());
} else if (attrType.getValue().equals(AUTZ_ATTR)) {
dataStorage.setAuthorizationAttributeDto((AuthorizationAttributeDto) attributeForm.getBean());
}
}

@Override
public void onTransition() {
steps.add(new AttributeStepSecond(attrType.getValue(), attributeForm.getBean(), steps));
}

private class AttributeStepSecond implements WizardStep<NewEntityWizardDataStorage> {

private final VVerticalLayout contentLayout = new VVerticalLayout();
private final List<Wizard<NewEntityWizardDataStorage>> steps;
private final String attrType;
private final List<WizardStep<NewEntityWizardDataStorage>> steps;
private AuthForm<? extends AuthDto, ? extends AttributeDto> authForm;

AttributeStepSecond(List<Wizard<NewEntityWizardDataStorage>> steps) {
AttributeStepSecond(String attrType, AttributeDto attribute, List<WizardStep<NewEntityWizardDataStorage>> steps) {
this.attrType = attrType;
this.steps = steps;
if (attrType.equals(AUTH_ATTR)) {
authForm = new AuthForm<AuthenticationDto, AuthenticationAttributeDto>(AuthenticationDto.class,
radiusUserService, true, true, (AuthenticationAttributeDto) attribute,
null, null);
// authForm.setBean(new AuthenticationDto());
} else if (attrType.equals(AUTZ_ATTR)) {
authForm = new AuthForm<AuthorizationDto, AuthorizationAttributeDto>(AuthorizationDto.class,
radiusUserService, true, true, (AuthorizationAttributeDto) attribute,
null, null);
// authForm.setBean(new AuthorizationDto());
}

contentLayout.add(authForm);
}

@Override
Expand All @@ -74,22 +115,44 @@ public Component getContent() {

@Override
public boolean isValid() {
return false;
return true;
}

@Override
public void writeDataToStorage(@NonNull NewEntityWizardDataStorage dataStorage) {
if (attrType.equals(AUTH_ATTR)) {
dataStorage.getAuthenticationDto().add((AuthenticationDto) authForm.getBean());
} else if (attrType.equals(AUTZ_ATTR)) {
dataStorage.getAuthorizationDto().add((AuthorizationDto) authForm.getBean());
}
}

@Override
public void onTransition() {
steps.add(new AttributeStepThird(attrType, attributeForm.getBean()));
}

}

private class AttributeStepThird implements WizardStep<NewEntityWizardDataStorage> {

private final VVerticalLayout contentLayout = new VVerticalLayout();

AttributeStepThird() {

private final String attrType;
private AuthForm<? extends AuthDto, ? extends AttributeDto> authForm;

AttributeStepThird(String attrType, AttributeDto attribute) {
this.attrType = attrType;
if (attrType.equals(AUTH_ATTR)) {
authForm = new AuthForm<AuthenticationDto, AuthenticationAttributeDto>(AuthenticationDto.class,
radiusUserService, true, false, (AuthenticationAttributeDto) attribute,
null, null);
} else if (attrType.equals(AUTZ_ATTR)) {
authForm = new AuthForm<AuthorizationDto, AuthorizationAttributeDto>(AuthorizationDto.class,
radiusUserService, true, false, (AuthorizationAttributeDto) attribute,
null, null);
}

contentLayout.add(authForm);
}

@Override
Expand All @@ -104,9 +167,17 @@ public boolean isValid() {

@Override
public void writeDataToStorage(@NonNull NewEntityWizardDataStorage dataStorage) {

if (attrType.equals(AUTH_ATTR)) {
dataStorage.getAuthenticationDto().add((AuthenticationDto) authForm.getBean());
} else if (attrType.equals(AUTZ_ATTR)) {
dataStorage.getAuthorizationDto().add((AuthorizationDto) authForm.getBean());
}
}

@Override
public boolean hasNextStep() {
return false;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void buildWizardSteps() {
steps.add(new UserGroupStep(radiusUserService, securityService, steps));
break;
case ATTRIBUTE:
steps.add(new AttributeStep(steps));
steps.add(new AttributeStep(radiusUserService, steps));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

import lombok.Getter;
import lombok.Setter;
import software.netcore.radman.buisness.service.attribute.dto.AuthenticationAttributeDto;
import software.netcore.radman.buisness.service.attribute.dto.AuthorizationAttributeDto;
import software.netcore.radman.buisness.service.auth.dto.AuthenticationDto;
import software.netcore.radman.buisness.service.auth.dto.AuthorizationDto;
import software.netcore.radman.buisness.service.nas.dto.NasDto;
import software.netcore.radman.buisness.service.nas.dto.NasGroupDto;
import software.netcore.radman.buisness.service.user.radius.dto.RadiusGroupDto;
import software.netcore.radman.buisness.service.user.radius.dto.RadiusUserDto;
import software.netcore.radman.buisness.service.user.radius.dto.RadiusUserToGroupDto;
import software.netcore.radman.ui.component.wizard.DataStorage;

Expand All @@ -23,8 +28,18 @@ public class NewEntityWizardDataStorage implements DataStorage {

private Set<NasGroupDto> nasGroupDtos = new HashSet<>();

private RadiusGroupDto radiusGroupDto;
private Set<RadiusGroupDto> radiusGroupDtos = new HashSet<>();

private Set<RadiusUserToGroupDto> radiusUserToGroupDtos;
private RadiusUserDto radiusUserDto;

private Set<RadiusUserToGroupDto> radiusUserToGroupDtos = new HashSet<>();

private AuthenticationAttributeDto authenticationAttributeDto;

private AuthorizationAttributeDto authorizationAttributeDto;

private Set<AuthenticationDto> authenticationDto = new HashSet<>();

private Set<AuthorizationDto> authorizationDto = new HashSet<>();

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@

import java.util.*;

/**
* @author daniel
* @since v. 1.0.3
*/
public class UserGroupStep implements WizardStep<NewEntityWizardDataStorage> {

private final RadiusUserService userService;
Expand Down Expand Up @@ -63,13 +67,13 @@ public boolean isValid() {
}

@Override
public void onTransition() {
steps.add(new UserGroupStepSecond(securityService, userGroupsForm.getBean().getName()));
public void writeDataToStorage(@NonNull NewEntityWizardDataStorage dataStorage) {
dataStorage.getRadiusGroupDtos().add(userGroupsForm.getBean());
}

@Override
public void writeDataToStorage(@NonNull NewEntityWizardDataStorage dataStorage) {
dataStorage.setRadiusGroupDto(userGroupsForm.getBean());
public void onTransition() {
steps.add(new UserGroupStepSecond(securityService, userGroupsForm.getBean().getName()));
}

private class UserGroupStepSecond implements WizardStep<NewEntityWizardDataStorage> {
Expand Down
Loading

0 comments on commit d32d2a3

Please sign in to comment.