Commit e8eca789 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

BS-10855

parent 5b9b35bd
......@@ -256,3 +256,4 @@ nameLimitSize=the name is limited to 50 char
displayNameLimitSize=the display name is limited to 75 char
labelExplicationCustomUserInformation=The information below (default and custom) applies to all users. Custom information can be used in the processes (e.g. by implementing actor filters on tasks).
details=Details
groupDisplayLengthTooLong=Group display name \"{0}\" exceed max length of 75 characters.
\ No newline at end of file
......@@ -279,6 +279,7 @@ public class Messages extends NLS {
public static String labelExplicationCustomUserInformation;
public static String customUserInfoValueLimitSize;
public static String userNameIsEmpty;
public static String groupDisplayLengthTooLong;
}
......@@ -36,7 +36,6 @@ import org.bonitasoft.studio.actors.model.organization.util.OrganizationAdapterF
import org.bonitasoft.studio.actors.model.organization.util.OrganizationResourceFactoryImpl;
import org.bonitasoft.studio.actors.model.organization.util.OrganizationResourceImpl;
import org.bonitasoft.studio.actors.model.organization.util.OrganizationXMLProcessor;
import org.bonitasoft.studio.actors.ui.wizard.page.OrganizationUserValidator;
import org.bonitasoft.studio.common.FileUtil;
import org.bonitasoft.studio.common.ProjectUtil;
import org.bonitasoft.studio.common.jface.FileActionDialog;
......@@ -46,7 +45,6 @@ import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.store.AbstractEMFRepositoryStore;
import org.bonitasoft.studio.pics.Pics;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
......@@ -133,13 +131,13 @@ public class OrganizationRepositoryStore extends AbstractEMFRepositoryStore<Orga
final Organization orga = fileStore.getContent() ;
if(orga != null && (orga.getName() == null || orga.getName().isEmpty())){
orga.setName(newFileName.substring(0,newFileName.length()-ORGANIZATION_EXT.length() - 1)) ;
final IStatus status = new OrganizationUserValidator().validate(orga);
if(status.isOK()){
// final IStatus status = new OrganizationValidator().validate(orga);
//if(status.isOK()){
fileStore.save(orga) ;
}else{
fileStore.delete();
throw new CancellationException(status.getMessage());
}
//}else{
// fileStore.delete();
// throw new CancellationException(status.getMessage());
// }
}
}
......
......@@ -28,7 +28,7 @@ import org.bonitasoft.studio.actors.repository.OrganizationRepositoryStore;
import org.bonitasoft.studio.actors.ui.wizard.page.AbstractOrganizationWizardPage;
import org.bonitasoft.studio.actors.ui.wizard.page.GroupsWizardPage;
import org.bonitasoft.studio.actors.ui.wizard.page.ManageOrganizationWizardPage;
import org.bonitasoft.studio.actors.ui.wizard.page.OrganizationUserValidator;
import org.bonitasoft.studio.actors.ui.wizard.page.OrganizationValidator;
import org.bonitasoft.studio.actors.ui.wizard.page.RolesWizardPage;
import org.bonitasoft.studio.actors.ui.wizard.page.UsersWizardPage;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
......@@ -65,7 +65,7 @@ public class ManageOrganizationWizard extends Wizard {
private final List<Organization> organizations;
private final List<Organization> organizationsWorkingCopy;
private final OrganizationRepositoryStore store;
private final OrganizationUserValidator validator = new OrganizationUserValidator();
private final OrganizationValidator validator = new OrganizationValidator();
private Organization activeOrganization;
private boolean activeOrganizationHasBeenModified = false;
String userName;
......
/**
* Copyright (C) 2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.actors.ui.wizard;
import org.eclipse.core.runtime.IStatus;
/**
* @author Romain Bioteau
*
*/
public class OrganizationValidationException extends Exception {
private static final long serialVersionUID = 578679768520738028L;
public OrganizationValidationException(final IStatus status) {
super(status.getMessage());
}
}
......@@ -22,7 +22,9 @@ import org.bonitasoft.studio.actors.i18n.Messages;
import org.bonitasoft.studio.actors.model.organization.Organization;
import org.bonitasoft.studio.actors.model.organization.User;
import org.bonitasoft.studio.actors.preference.ActorsPreferenceConstants;
import org.bonitasoft.studio.actors.repository.OrganizationFileStore;
import org.bonitasoft.studio.actors.ui.wizard.page.DefaultUserOrganizationWizardPage;
import org.bonitasoft.studio.actors.ui.wizard.page.OrganizationValidator;
import org.bonitasoft.studio.actors.ui.wizard.page.SynchronizeOrganizationWizardPage;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
......@@ -33,6 +35,7 @@ import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.Parameterization;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
......@@ -53,12 +56,14 @@ public class SynchronizeOrganizationWizard extends Wizard {
private SynchronizeOrganizationWizardPage page;
private DefaultUserOrganizationWizardPage userPage;
private Organization activeOrganization;
private final OrganizationValidator validator;
public SynchronizeOrganizationWizard(){
setWindowTitle(Messages.synchronizeOrganizationTitle);
setDefaultPageImageDescriptor(Pics.getWizban()) ;
setForcePreviousAndNextButtons(false) ;
setNeedsProgressMonitor(true) ;
validator = new OrganizationValidator();
}
@Override
......@@ -75,7 +80,7 @@ public class SynchronizeOrganizationWizard extends Wizard {
@Override
public IWizardPage getNextPage(final IWizardPage page) {
if(page instanceof SynchronizeOrganizationWizardPage){
activeOrganization = (Organization) ((SynchronizeOrganizationWizardPage)page).getFileStore().getContent();
activeOrganization = ((SynchronizeOrganizationWizardPage)page).getFileStore().getContent();
userPage.setOrganization(activeOrganization) ;
return userPage ;
}else{
......@@ -88,28 +93,19 @@ public class SynchronizeOrganizationWizard extends Wizard {
*/
@Override
public boolean performFinish() {
final IPreferenceStore prefStore = updateDefaultUserPreference();
final OrganizationFileStore artifact = getFileStore();
try {
getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor maonitor) throws InvocationTargetException,InterruptedException {
maonitor.beginTask(Messages.synchronizingOrganization, IProgressMonitor.UNKNOWN) ;
final IPreferenceStore prefStore = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore() ;
final String userName = userPage.getUser();
String password = null;
if (activeOrganization!=null){
for (final User user:activeOrganization.getUsers().getUser()){
if (user.getUserName().equals(userPage.getUser())){
password = user.getPassword().getValue();
}
}
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(Messages.validatingOrganizationContent, IProgressMonitor.UNKNOWN);
final IStatus status = validator.validate(artifact.getContent());
if (!status.isOK()) {
throw new InvocationTargetException(new OrganizationValidationException(status));
}
prefStore.setValue(BonitaPreferenceConstants.USER_NAME,userName);
prefStore.setValue(BonitaPreferenceConstants.USER_PASSWORD,password);
final IRepositoryFileStore artifact = getFileStore() ;
monitor.beginTask(Messages.synchronizingOrganization, IProgressMonitor.UNKNOWN);
final ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class) ;
final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class) ;
final Command cmd = service.getCommand("org.bonitasoft.studio.engine.installOrganization") ;
......@@ -120,25 +116,40 @@ public class SynchronizeOrganizationWizard extends Wizard {
} catch (final Exception e) {
throw new InvocationTargetException(e);
}
final String organizationName = artifact.getDisplayName();
Display.getDefault().syncExec( new Runnable() {
@Override
public void run() {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.synchronizeInformationTitle,Messages.bind(Messages.synchronizeOrganizationSuccessMsg, organizationName));
}
});
}
}) ;
} catch (final Exception e) {
BonitaStudioLog.error(e) ;
} catch (final InvocationTargetException e) {
if (e.getCause() instanceof OrganizationValidationException) {
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.organizationValidationFailed, e.getCause().getMessage());
}
return false ;
} catch (final InterruptedException e) {
BonitaStudioLog.error(e);
return false;
}
final String organizationName = artifact.getDisplayName();
MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.synchronizeInformationTitle,
Messages.bind(Messages.synchronizeOrganizationSuccessMsg, organizationName));
return true;
}
public IRepositoryFileStore getFileStore() {
protected IPreferenceStore updateDefaultUserPreference() {
final IPreferenceStore prefStore = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore();
final String userName = userPage.getUser();
String password = null;
if (activeOrganization != null) {
for (final User user : activeOrganization.getUsers().getUser()) {
if (user.getUserName().equals(userPage.getUser())) {
password = user.getPassword().getValue();
}
}
}
prefStore.setValue(BonitaPreferenceConstants.USER_NAME, userName);
prefStore.setValue(BonitaPreferenceConstants.USER_PASSWORD, password);
return prefStore;
}
public OrganizationFileStore getFileStore() {
return page.getFileStore();
}
......
......@@ -36,39 +36,31 @@ import org.eclipse.core.runtime.Status;
* @author Romain Bioteau
*
*/
public class OrganizationUserValidator implements IValidator {
public class OrganizationValidator implements IValidator {
/* (non-Javadoc)
* @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object)
*/
@Override
public IStatus validate(Object input) {
public IStatus validate(final Object input) {
final Organization organization = (Organization) input;
for(User u : organization.getUsers().getUser()){
for(final User u : organization.getUsers().getUser()){
if(u.getUserName() == null || u.getUserName().isEmpty()){
return ValidationStatus.error(Messages.userNameMissing);
}
if(u.getPassword() == null || u.getPassword().getValue() == null || u.getPassword().getValue().isEmpty()){
return ValidationStatus.error(Messages.bind(Messages.userPasswordMissing,u.getUserName()));
}
// if(u.getFirstName() == null || u.getFirstName().isEmpty()){
// return ValidationStatus.error(Messages.bind(Messages.userFirstNameMissing,u.getUserName()));
// }
// if(u.getLastName() == null || u.getLastName().isEmpty()){
// return ValidationStatus.error(Messages.bind(Messages.userLastNameMissing,u.getUserName()));
// }
if(u.getManager() != null && !u.getManager().isEmpty()){
IStatus status = checkManagerCycles(organization,u);
final IStatus status = checkManagerCycles(organization,u);
if(!status.isOK()){
return status;
}
}
boolean membershipFound = false;
for(Membership membership : organization.getMemberships().getMembership()){
for(final Membership membership : organization.getMemberships().getMembership()){
final String userName = membership.getUserName() ;
if(userName != null){
if(userName.equals(u.getUserName())){
......@@ -84,7 +76,7 @@ public class OrganizationUserValidator implements IValidator {
}else{
groupPath = parentPath + GroupContentProvider.GROUP_SEPARATOR + groupName ;
}
IStatus groupStatus = validateGroupExists(organization,groupPath,membership) ;
final IStatus groupStatus = validateGroupExists(organization,groupPath,membership) ;
if(groupStatus.getSeverity() != IStatus.OK){
return groupStatus ;
}
......@@ -93,7 +85,7 @@ public class OrganizationUserValidator implements IValidator {
if(roleName == null){
return ValidationStatus.error(Messages.bind(Messages.missingRole,u.getUserName()));
}
IStatus roleStatus = validateRoleExists(organization,roleName,membership) ;
final IStatus roleStatus = validateRoleExists(organization,roleName,membership) ;
if(roleStatus.getSeverity() != IStatus.OK){
return roleStatus ;
}
......@@ -104,12 +96,17 @@ public class OrganizationUserValidator implements IValidator {
return ValidationStatus.error(Messages.bind(Messages.missingMembershipForUser,u.getUserName()));
}
}
for (final Group group : organization.getGroups().getGroup()) {
if (!group.getDisplayName().isEmpty() && group.getDisplayName().length() > 75) {
return ValidationStatus.error(Messages.bind(Messages.groupDisplayLengthTooLong, group.getDisplayName()));
}
}
return ValidationStatus.ok() ;
}
private IStatus checkManagerCycles(Organization organization,User u) {
private IStatus checkManagerCycles(final Organization organization,final User u) {
String managerUsername = u.getManager();
List<String> managers = new ArrayList<String>();
final List<String> managers = new ArrayList<String>();
managers.add(u.getUserName());
managers.add(managerUsername);
while (managerUsername != null ) {
......@@ -127,8 +124,8 @@ public class OrganizationUserValidator implements IValidator {
return ValidationStatus.ok();
}
private String getManagerOf(Organization organization,String managerUsername) {
for(User u : organization.getUsers().getUser()){
private String getManagerOf(final Organization organization,final String managerUsername) {
for(final User u : organization.getUsers().getUser()){
if(managerUsername.equals(u.getUserName())){
return u.getManager();
}
......@@ -136,8 +133,8 @@ public class OrganizationUserValidator implements IValidator {
return null;
}
private IStatus validateRoleExists(Organization organization,String roleName, Membership membership) {
for(Role role : organization.getRoles().getRole()){
private IStatus validateRoleExists(final Organization organization,final String roleName, final Membership membership) {
for(final Role role : organization.getRoles().getRole()){
if(role.getName().equals(roleName)){
return ValidationStatus.ok() ;
}
......@@ -145,8 +142,8 @@ public class OrganizationUserValidator implements IValidator {
return ValidationStatus.error(Messages.bind(Messages.missingRoleInMembership,roleName,membership.getUserName()));
}
private IStatus validateGroupExists(Organization organization,String groupPath, Membership membership) {
for(Group group : organization.getGroups().getGroup()){
private IStatus validateGroupExists(final Organization organization,final String groupPath, final Membership membership) {
for(final Group group : organization.getGroups().getGroup()){
if(GroupContentProvider.getGroupPath(group).equals(groupPath)){
return ValidationStatus.ok() ;
}
......
......@@ -16,8 +16,11 @@
*/
package org.bonitasoft.studio.actors.ui.wizard.page;
import static org.bonitasoft.studio.common.Messages.bonitaPortalModuleName;
import org.bonitasoft.studio.actors.i18n.Messages;
import org.bonitasoft.studio.actors.model.organization.Organization;
import org.bonitasoft.studio.actors.repository.OrganizationFileStore;
import org.bonitasoft.studio.actors.repository.OrganizationRepositoryStore;
import org.bonitasoft.studio.common.jface.TableColumnSorter;
import org.bonitasoft.studio.common.repository.RepositoryManager;
......@@ -37,37 +40,36 @@ import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TableColumn;
import static org.bonitasoft.studio.common.Messages.bonitaPortalModuleName;
/**
* @author Romain Bioteau
*
*/
public class SynchronizeOrganizationWizardPage extends WizardPage implements ISelectionChangedListener{
private IRepositoryFileStore file;
private OrganizationFileStore file;
private TableViewer viewer;
private final OrganizationRepositoryStore organizationStore;
public SynchronizeOrganizationWizardPage() {
super(SynchronizeOrganizationWizardPage.class.getName());
setTitle(Messages.synchronizeOrganizationTitle) ;
setDescription(Messages.bind(Messages.synchronizeOrganizationDesc, new Object[]{bonitaPortalModuleName})) ;
organizationStore = (OrganizationRepositoryStore) RepositoryManager.getInstance().getRepositoryStore(OrganizationRepositoryStore.class) ;
organizationStore = RepositoryManager.getInstance().getRepositoryStore(OrganizationRepositoryStore.class) ;
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createControl(Composite parent) {
Composite mainComposite = new Composite(parent, SWT.NONE) ;
public void createControl(final Composite parent) {
final Composite mainComposite = new Composite(parent, SWT.NONE) ;
mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()) ;
mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(10, 10).create()) ;
viewer = new TableViewer(mainComposite,SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE) ;
viewer.getTable().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).minSize(SWT.DEFAULT, 200).create());
TableLayout layout = new TableLayout() ;
final TableLayout layout = new TableLayout() ;
layout.addColumnData(new ColumnWeightData(30)) ;
layout.addColumnData(new ColumnWeightData(70)) ;
viewer.getTable().setLayout(layout);
......@@ -76,7 +78,7 @@ public class SynchronizeOrganizationWizardPage extends WizardPage implements ISe
viewer.setContentProvider(new ArrayContentProvider()) ;
TableViewerColumn column = new TableViewerColumn(viewer, SWT.FILL) ;
TableColumn nameColumn = column.getColumn() ;
final TableColumn nameColumn = column.getColumn() ;
column.getColumn().setText(Messages.name);
column.setLabelProvider(new OrganizationLabelProvider());
......@@ -85,12 +87,12 @@ public class SynchronizeOrganizationWizardPage extends WizardPage implements ISe
column.getColumn().setText(Messages.description);
column.setLabelProvider(new ColumnLabelProvider(){
@Override
public String getText(Object element) {
public String getText(final Object element) {
return ((Organization) ((IRepositoryFileStore) element).getContent()).getDescription();
}
});
TableColumnSorter sorter = new TableColumnSorter(viewer) ;
final TableColumnSorter sorter = new TableColumnSorter(viewer) ;
sorter.setColumn(nameColumn) ;
viewer.setInput(organizationStore.getChildren()) ;
......@@ -102,18 +104,18 @@ public class SynchronizeOrganizationWizardPage extends WizardPage implements ISe
@Override
public void selectionChanged(SelectionChangedEvent event) {
public void selectionChanged(final SelectionChangedEvent event) {
if(!event.getSelection().isEmpty()){
file = (IRepositoryFileStore) ((IStructuredSelection) event.getSelection()).getFirstElement() ;
DefaultUserOrganizationWizardPage nextPage = (DefaultUserOrganizationWizardPage)getNextPage();
nextPage.setOrganization((Organization)file.getContent());
file = (OrganizationFileStore) ((IStructuredSelection) event.getSelection()).getFirstElement();
final DefaultUserOrganizationWizardPage nextPage = (DefaultUserOrganizationWizardPage)getNextPage();
nextPage.setOrganization(file.getContent());
nextPage.refreshBindings();
}
getContainer().updateButtons() ;
}
public IRepositoryFileStore getFileStore() {
public OrganizationFileStore getFileStore() {
return file;
}
......
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