Commit c9f0b55d authored by Adrien's avatar Adrien Committed by GitHub

feat(Orga) avoid errors when expected active orga is not present (#1811)

* Errors in actor mapping wizard
* Error in profile editor

[BST-398](https://bonitasoft.atlassian.net/browse/BST-398)
parent ab56c8da
......@@ -16,6 +16,7 @@ package org.bonitasoft.studio.actors.configuration;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import org.bonitasoft.studio.actors.ActorsPlugin;
import org.bonitasoft.studio.actors.action.ExportActorMappingAction;
......@@ -25,6 +26,7 @@ import org.bonitasoft.studio.actors.model.organization.Group;
import org.bonitasoft.studio.actors.model.organization.Organization;
import org.bonitasoft.studio.actors.model.organization.Role;
import org.bonitasoft.studio.actors.model.organization.User;
import org.bonitasoft.studio.actors.repository.OrganizationFileStore;
import org.bonitasoft.studio.actors.repository.OrganizationRepositoryStore;
import org.bonitasoft.studio.actors.ui.wizard.SelectGroupsWizard;
import org.bonitasoft.studio.actors.ui.wizard.SelectMembershipsWizard;
......@@ -82,7 +84,7 @@ public class ActorMappingConfigurationWizardPage extends WizardPage
private Button roleButton;
private Button membershipButton;
private Button userButton;
private Organization deployedOrganization;
private Optional<Organization> deployedOrganization;
public ActorMappingConfigurationWizardPage() {
super(ActorMappingConfigurationWizardPage.class.getName());
......@@ -90,10 +92,10 @@ public class ActorMappingConfigurationWizardPage extends WizardPage
setDescription(Messages.actorMappingDesc);
adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
adapterFactory.addAdapterFactory(new ActorMappingAdapterFactory());
deployedOrganization = RepositoryManager.getInstance()
deployedOrganization = Optional.ofNullable(RepositoryManager.getInstance()
.getRepositoryStore(OrganizationRepositoryStore.class)
.getChild(String.format("%s.organization", new ActiveOrganizationProvider().getActiveOrganization()))
.getContent();
.getChild(String.format("%s.organization", new ActiveOrganizationProvider().getActiveOrganization())))
.map(OrganizationFileStore::getContent);
}
@Override
......@@ -350,15 +352,18 @@ public class ActorMappingConfigurationWizardPage extends WizardPage
}
private boolean isUnknownGroup(String group) {
return deployedOrganization.getGroups().getGroup().stream().map(this::getGroupPath).noneMatch(group::equals);
return !deployedOrganization.isPresent() || deployedOrganization.get().getGroups().getGroup().stream()
.map(this::getGroupPath).noneMatch(group::equals);
}
private boolean isUnknownRole(String role) {
return deployedOrganization.getRoles().getRole().stream().map(Role::getName).noneMatch(role::equals);
return !deployedOrganization.isPresent()
|| deployedOrganization.get().getRoles().getRole().stream().map(Role::getName).noneMatch(role::equals);
}
private boolean isUnknownUser(String user) {
return deployedOrganization.getUsers().getUser().stream().map(User::getUserName).noneMatch(user::equals);
return !deployedOrganization.isPresent()
|| deployedOrganization.get().getUsers().getUser().stream().map(User::getUserName).noneMatch(user::equals);
}
private String getGroupPath(Group group) {
......
......@@ -14,6 +14,8 @@
*/
package org.bonitasoft.studio.actors.configuration;
import java.util.Optional;
import org.bonitasoft.studio.actors.model.organization.Group;
import org.bonitasoft.studio.actors.model.organization.Organization;
import org.bonitasoft.studio.actors.model.organization.Role;
......@@ -28,11 +30,12 @@ import org.eclipse.swt.widgets.Display;
public class ActorMappingLabelProvider extends ColumnLabelProvider {
private Organization deployedOrganization;
private Optional<Organization> deployedOrganization;
private Color errorColor;
private AdapterFactoryLabelProvider adapterFactory;
public ActorMappingLabelProvider(AdapterFactoryLabelProvider adapterFactory, Organization deployedOrganization) {
public ActorMappingLabelProvider(AdapterFactoryLabelProvider adapterFactory,
Optional<Organization> deployedOrganization) {
this.adapterFactory = adapterFactory;
this.deployedOrganization = deployedOrganization;
this.errorColor = new Color(Display.getDefault(), ColorConstants.ERROR_RGB);
......@@ -44,9 +47,11 @@ public class ActorMappingLabelProvider extends ColumnLabelProvider {
&& isPresentInDeployedOrganization(((MembershipType) element).getRole());
}
String elt = (String) element;
return deployedOrganization.getGroups().getGroup().stream().map(this::getGroupPath).anyMatch(elt::equals)
|| deployedOrganization.getRoles().getRole().stream().map(Role::getName).anyMatch(elt::equals)
|| deployedOrganization.getUsers().getUser().stream().map(User::getUserName).anyMatch(elt::equals);
return deployedOrganization.isPresent()
&& (deployedOrganization.get().getGroups().getGroup().stream().map(this::getGroupPath).anyMatch(elt::equals)
|| deployedOrganization.get().getRoles().getRole().stream().map(Role::getName).anyMatch(elt::equals)
|| deployedOrganization.get().getUsers().getUser().stream().map(User::getUserName)
.anyMatch(elt::equals));
}
private String getGroupPath(Group group) {
......
......@@ -14,6 +14,8 @@
*/
package org.bonitasoft.studio.actors.configuration;
import java.util.Optional;
import org.bonitasoft.studio.actors.i18n.Messages;
import org.bonitasoft.studio.actors.model.organization.Organization;
import org.bonitasoft.studio.model.actormapping.ActorMapping;
......@@ -30,7 +32,8 @@ public class ActorMappingStyledTreeLabelProvider extends StyledCellLabelProvider
private ActorMappingLabelProvider labelProvider;
public ActorMappingStyledTreeLabelProvider(ComposedAdapterFactory adapterFactory, Organization deployedOrganization) {
public ActorMappingStyledTreeLabelProvider(ComposedAdapterFactory adapterFactory,
Optional<Organization> deployedOrganization) {
labelProvider = new ActorMappingLabelProvider(new AdapterFactoryLabelProvider(adapterFactory), deployedOrganization);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment