Author: glandais
Date: 2008-02-20 23:22:26 +0000 (Wed, 20 Feb 2008)
New Revision: 1158
Added:
trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsLocalMassTestCase.java
trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsLocalTestCase.java
trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsServerMassTestCase.java
trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsServerTestCase.java
trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsTestCase.java
Removed:
trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersions.java
Modified:
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationService.java
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java
trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementRights.java
Log:
Business version rules
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java 2008-02-20 23:12:38 UTC (rev 1157)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java 2008-02-20 23:22:26 UTC (rev 1158)
@@ -82,17 +82,30 @@
p.setOwner(true);
} else {
List<Permission> permissions = dao.getPermissions(businessId);
- int minLevel = 0;
- for (Permission permission : permissions) {
- int relativeLevel = getRelativeLevel(user, permission);
- if (relativeLevel >= 0) {
- if (p == null || minLevel > relativeLevel) {
- p = permission;
- minLevel = relativeLevel;
+ if (permissions.size() > 0) {
+ int minLevel = 0;
+
+ for (Permission permission : permissions) {
+ int relativeLevel = getRelativeLevel(user, permission);
+ if (relativeLevel >= 0) {
+ if (p == null || minLevel > relativeLevel) {
+ p = permission;
+ minLevel = relativeLevel;
+ }
}
}
+ } else {
+ // no permission with this id exists, so create a default one with all rights
+ p = new Permission();
+ p.setActor(user);
+ p.setBusinessId(businessId);
+ p.setOwner(true);
+ p.setCanAdmin(true);
+ p.setCanRead(true);
+ p.setCanWrite(true);
}
+
}
if (p != null && p.isOwner()) {
@@ -119,18 +132,16 @@
*/
public void saveElement(String token, String businessId) {
User user = dao.getLoggedUser(token);
- if (!user.isSuperAdmin()) {
- Permission p = getPermission(token, businessId);
- if ((p == null) || (!user.getId().equals(p.getActor().getId()))) {
- p = new Permission();
- p.setActor(dao.getLoggedUser(token));
- p.setBusinessId(businessId);
- p.setOwner(true);
- dao.savePermission(p);
- } else {
- p.setOwner(true);
- dao.updatePermission(p);
- }
+ Permission p = getPermission(token, businessId);
+ if ((p == null) || (!user.getId().equals(p.getActor().getId()))) {
+ p = new Permission();
+ p.setActor(dao.getLoggedUser(token));
+ p.setBusinessId(businessId);
+ p.setOwner(true);
+ dao.savePermission(p);
+ } else {
+ p.setOwner(true);
+ dao.updatePermission(p);
}
}
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationService.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationService.java 2008-02-20 23:12:38 UTC (rev 1157)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationService.java 2008-02-20 23:22:26 UTC (rev 1158)
@@ -338,18 +338,22 @@
* Gets the permissions.
*
* @param uuid the uuid
+ * @param token the token
*
* @return the permissions
+ * @throws SimExplorerException
*/
- public Permission[] getPermissions(String uuid);
+ public Permission[] getPermissions(String token, String uuid) throws SimExplorerException;
/**
* Sets the permissions.
*
* @param uuid the uuid
* @param permissions the permissions
+ * @param token the token
+ * @throws SimExplorerException
*/
- public void setPermissions(String uuid, Permission[] permissions);
+ public void setPermissions(String token, String uuid, Permission[] permissions) throws SimExplorerException;
}
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java 2008-02-20 23:12:38 UTC (rev 1157)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java 2008-02-20 23:22:26 UTC (rev 1158)
@@ -39,6 +39,8 @@
import javax.naming.NamingException;
import org.apache.commons.lang.RandomStringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.codelutin.i18n.I18n;
import org.jboss.annotation.ejb.RemoteBinding;
@@ -46,12 +48,13 @@
import fr.cemagref.simexplorer.is.exceptions.SimExplorerException;
import fr.cemagref.simexplorer.is.exceptions.SimExplorerSecurityException;
import fr.cemagref.simexplorer.is.exceptions.SimExplorerTechnicalException;
-import fr.cemagref.simexplorer.is.storage.util.Config;
+import fr.cemagref.simexplorer.is.security.credentials.CredentialManager;
import fr.cemagref.simexplorer.is.security.dao.DaoSecurity;
import fr.cemagref.simexplorer.is.security.entities.Group;
import fr.cemagref.simexplorer.is.security.entities.LoginAction;
import fr.cemagref.simexplorer.is.security.entities.Permission;
import fr.cemagref.simexplorer.is.security.entities.User;
+import fr.cemagref.simexplorer.is.storage.util.Config;
/**
* The Class AuthenticationServiceImpl.
@@ -62,10 +65,17 @@
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class AuthenticationServiceImpl implements AuthenticationService {
+ /** The Constant log. */
+ private static final Log log = LogFactory.getLog(AuthenticationServiceImpl.class);
+
/** The dao. */
@EJB
private DaoSecurity dao;
+ /** The credential manager. */
+ @EJB
+ private CredentialManager credentialManager;
+
/** The super admin check. */
private static boolean superAdminCheck = false;
@@ -119,7 +129,6 @@
*/
private void sendMail(String mailFrom, String mailRecipient, String subject, String content)
throws SimExplorerException {
- /*
try {
javax.mail.Session mailSession = (javax.mail.Session) new InitialContext().lookup("java:/Mail");
javax.mail.Message msg = new MimeMessage(mailSession);
@@ -131,15 +140,12 @@
msg.setHeader("X-Mailer", "JavaMailer");
msg.setSentDate(new java.util.Date());
Transport.send(msg);
- */
- System.out.println(mailFrom + " - " + mailRecipient + " - " + subject + " - " + content);
- /*
+ log.info(mailFrom + " - " + mailRecipient + " - " + subject + " - " + content);
} catch (MessagingException e) {
throw new SimExplorerTechnicalException(e);
} catch (NamingException e) {
throw new SimExplorerTechnicalException(e);
}
- */
}
/**
@@ -735,11 +741,26 @@
}
}
+ /**
+ * Can admin permissions.
+ *
+ * @param token the token
+ * @param uuid the uuid
+ *
+ * @throws SimExplorerException the sim explorer exception
+ */
+ private void canAdminPermissions(String token, String uuid) throws SimExplorerException {
+ Permission permission = credentialManager.getPermission(token, uuid);
+ if (!permission.isCanAdmin()) {
+ throw new SimExplorerSecurityException();
+ }
+ }
+
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.service.AuthenticationService#getPermissions(java.lang.String)
*/
- public Permission[] getPermissions(String uuid) {
- // FIXME
+ public Permission[] getPermissions(String token, String uuid) throws SimExplorerException {
+ canAdminPermissions(token, uuid);
List<Permission> permissions = dao.getPermissions(uuid);
return permissions.toArray(new Permission[permissions.size()]);
}
@@ -747,8 +768,8 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.service.AuthenticationService#setPermissions(java.lang.String, fr.cemagref.simexplorer.is.security.entities.Permission[])
*/
- public void setPermissions(String uuid, Permission[] permissions) {
- // FIXME
+ public void setPermissions(String token, String uuid, Permission[] permissions) throws SimExplorerException {
+ canAdminPermissions(token, uuid);
dao.setPermissions(uuid, permissions);
}
Deleted: trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersions.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersions.java 2008-02-20 23:12:38 UTC (rev 1157)
+++ trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersions.java 2008-02-20 23:22:26 UTC (rev 1158)
@@ -1,250 +0,0 @@
-/*
-* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais
-*
-* 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
-* 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, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-* ##% */
-package fr.cemagref.simexplorer.is.service;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Random;
-import java.util.Set;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import junit.framework.TestCase;
-
-import com.healthmarketscience.rmiio.SerializableInputStream;
-
-import fr.cemagref.simexplorer.is.entities.attachment.Attachment;
-import fr.cemagref.simexplorer.is.entities.data.Code;
-import fr.cemagref.simexplorer.is.entities.data.Component;
-import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication;
-import fr.cemagref.simexplorer.is.entities.data.ExplorationData;
-import fr.cemagref.simexplorer.is.entities.data.Library;
-import fr.cemagref.simexplorer.is.entities.metadata.MetaData;
-import fr.cemagref.simexplorer.is.entities.metadata.Version;
-import fr.cemagref.simexplorer.is.exceptions.SimExplorerException;
-import fr.cemagref.simexplorer.is.factories.BaseEntityFactory;
-import fr.cemagref.simexplorer.is.factories.MetaDataFactory;
-import fr.cemagref.simexplorer.is.factories.XmlConstants;
-import fr.cemagref.simexplorer.is.storage.ElementGenerator;
-import fr.cemagref.simexplorer.is.storage.ElementGenerator.RandomStream;
-
-public class StorageServiceVersions extends TestCase {
-
- /** The storage service. */
- private StorageService storageService;
-
- /** The element generator. */
- private ElementGenerator elementGenerator;
-
- private String token;
-
- /** The r. */
- private Random r = new Random();
-
- private Map<Attachment, ElementGenerator.RandomStream> attachments;
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- elementGenerator = new ElementGenerator();
-
- //storageService = new StorageServiceClient();
-
-
- Properties properties = (Properties) System.getProperties().clone();
- properties.put("java.naming.provider.url", "jnp://localhost:1099");
- properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
- properties.put("java.naming.factory.url.pkgs", "org.jnp.interfaces");
-
- Context context = new InitialContext(properties);
- storageService = (StorageService) context.lookup("StorageService");
-
- }
-
- private MetaData saveEa(ExplorationApplication ea, boolean computeAttachments) throws Exception {
-
- if (computeAttachments) {
- attachments = new HashMap<Attachment, ElementGenerator.RandomStream>();
-
- List<Attachment> attachmentsKeys = new ArrayList<Attachment>();
-
- attachmentsKeys.addAll(ea.getMetaData().getAttachments());
- List<Component> components = ea.getComponents();
- for (Component component : components) {
- attachmentsKeys.addAll(component.getMetaData().getAttachments());
- List<Library> libraries = component.getLibraries();
- for (Library library : libraries) {
- attachmentsKeys.addAll(library.getMetaData().getAttachments());
- }
- }
- List<ExplorationData> explorations = ea.getExplorations();
- for (ExplorationData explorationData : explorations) {
- attachmentsKeys.addAll(explorationData.getMetaData().getAttachments());
- }
-
- for (Attachment attachment : attachmentsKeys) {
- RandomStream randomStream = elementGenerator.generateTextStream();
- attachment.setDataHash(randomStream.getMd5());
- attachments.put(attachment, randomStream);
- }
- }
-
- SerializableInputStream xmlStream = new SerializableInputStream(BaseEntityFactory.getFactory(
- ExplorationApplication.class).saveElement(XmlConstants.VALUE_METADATA_TYPE_EA, ea));
-
- Map<Attachment, SerializableInputStream> realAttachments = new HashMap<Attachment, SerializableInputStream>();
- for (Map.Entry<Attachment, ElementGenerator.RandomStream> element : attachments.entrySet()) {
- realAttachments.put(element.getKey(), new SerializableInputStream(element.getValue().getStream()));
- }
-
- return storageService.saveElement(token, xmlStream, realAttachments);
- }
-
- private void listExisting(String uuid) throws SimExplorerException {
- if (uuid != null) {
- Version[] versions = storageService.getVersions(token, uuid);
- System.out.println("Versions of uuid " + uuid + ":");
- for (int i = 0; i < versions.length; i++) {
- System.out.println(versions[i]);
- }
- }
- }
-
- private String testVersionUpdate(String firstVersion, String secondVersion, String assertFirst,
- String assertSecond, boolean different) throws Exception {
- System.out.println("-----------------------------");
-
- ExplorationApplication ea;
-
- MetaDataFactory<MetaData> mdeFactory = MetaDataFactory.getFactory(MetaData.class);
-
- ea = elementGenerator.generateRandomEA();
-
- StringBuffer task = new StringBuffer();
- task.append(firstVersion).append("A + ").append(secondVersion);
- if (different) {
- task.append("B");
- } else {
- task.append("A");
- }
- task.append(" = ").append(assertFirst).append("A");
- if (different) {
- task.append(" + ").append(assertSecond).append("B");
- }
- System.out.println(task.toString());
-
- System.out.println("UUID : " + ea.getMetaData().getUuid());
- System.out.println("Name : " + ea.getMetaData().getName());
-
- ea.getMetaData().setVersion(firstVersion);
-
- System.out.println("Saving " + firstVersion + "A");
- MetaData mde1 = saveEa(ea, true);
- listExisting(ea.getMetaData().getUuid());
-
- ea.getMetaData().setVersion(secondVersion);
-
- if (different) {
- Component component = ea.getComponents().iterator().next();
- Code code = new Code();
- code.setCode("regreg");
- code.setLanguage("regreg");
- component.getCodes().add(code);
- }
-
- System.out.print("Saving " + secondVersion);
- if (different) {
- System.out.println("B");
- } else {
- System.out.println("A");
- }
- MetaData mde2 = saveEa(ea, false);
- listExisting(ea.getMetaData().getUuid());
-
- System.out.println("A : " + mde1.getHash());
- if (different) {
- System.out.println("B : " + mde2.getHash());
- }
-
- return ea.getMetaData().getUuid();
- // assertEquals(mde1.getVersion().toString(), assertFirst);
- // assertEquals(mde2.getVersion().toString(), assertSecond);
- }
-
- public void testVersionUpdate() throws Exception {
-
- String password = "password";
- token = storageService.loginUser("superadmin",
- AuthenticationServiceHelper.computeHash(password.toCharArray()));
-
- List<String> uuids = new ArrayList<String>();
-
- uuids.add(testVersionUpdate("1.1", "1.0", "1.1", "1.1", false));
- uuids.add(testVersionUpdate("1.1", "1.1", "1.1", "1.1", false));
- uuids.add(testVersionUpdate("1.1", "2.1", "2.1", "2.1", false));
-
- uuids.add(testVersionUpdate("1.1", "1.0", "1.1", "1.2", true));
- uuids.add(testVersionUpdate("1.1", "1.1", "1.1", "1.2", true));
- uuids.add(testVersionUpdate("1.1", "1.1.5", "1.1", "1.2", true));
- uuids.add(testVersionUpdate("1.1", "1.2", "1.1", "1.2", true));
- uuids.add(testVersionUpdate("1.1", "2.1", "1.1", "2.1", true));
-
- System.out.println("-----------------------------");
- for (String uuid : uuids) {
- listExisting(uuid);
- }
-
- }
-
- /*
- public void testVersionUpdate2() throws Exception {
- ExplorationApplication ea;
-
- MetaDataFactory<MetaData> mdeFactory = MetaDataFactory
- .getFactory(MetaData.class);
-
- ea = elementGenerator.generateRandomEA();
- MetaData mde1 = saveEa(ea, true);
-
- Component component = ea.getComponents().iterator().next();
- Code code = new Code();
- code.setCode("regreg");
- code.setLanguage("regreg");
- component.getCodes().add(code);
-
- MetaData mde2 = saveEa(ea, false);
-
- InputStream stream1 = storageService.retrieveElementXML(null, mde1
- .getUuid(), mde1.getVersion().toString());
- InputStream stream2 = storageService.retrieveElementXML(null, mde2
- .getUuid(), mde2.getVersion().toString());
-
- assertFalse(mdeFactory.computeHash(stream1).equals(
- mdeFactory.computeHash(stream2)));
- assertEquals(mde1.getVersion(), mde2.getVersion().incVersion(1));
- }
- */
-
-}
Added: trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsLocalMassTestCase.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsLocalMassTestCase.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsLocalMassTestCase.java 2008-02-20 23:22:26 UTC (rev 1158)
@@ -0,0 +1,27 @@
+/*
+* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais
+*
+* 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
+* 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, write to the Free Software
+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+* ##% */
+package fr.cemagref.simexplorer.is.service;
+
+public class StorageServiceVersionsLocalMassTestCase extends StorageServiceVersionsLocalTestCase {
+
+ @Override
+ protected int getIterations() {
+ return 50;
+ }
+
+}
Added: trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsLocalTestCase.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsLocalTestCase.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsLocalTestCase.java 2008-02-20 23:22:26 UTC (rev 1158)
@@ -0,0 +1,64 @@
+/*
+* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais
+*
+* 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
+* 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, write to the Free Software
+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+* ##% */
+package fr.cemagref.simexplorer.is.service;
+
+import java.util.List;
+
+/**
+ * The Class StorageServiceVersionsLocalTestCase.
+ */
+public class StorageServiceVersionsLocalTestCase extends StorageServiceVersionsTestCase {
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.service.StorageServiceVersionsTestCase#buildStorageService()
+ */
+ @Override
+ protected void buildStorageService() {
+ storageService = new StorageServiceClient();
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.service.StorageServiceVersionsTestCase#loginOnService()
+ */
+ @Override
+ protected void loginOnService() throws Exception {
+ token = null;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.service.StorageServiceVersionsTestCase#versionsTest(java.util.List)
+ */
+ @Override
+ protected void versionsTest(List<String> uuids) throws Exception {
+ uuids.add(testVersionUpdate("1.1", "1.0", false, "1.1"));
+ uuids.add(testVersionUpdate("1.1", "1.1", false, "1.1"));
+ uuids.add(testVersionUpdate("1.1", "2.1", false, "1.1", "2.1"));
+
+ uuids.add(testVersionUpdate("1.1", "1.0", true, "1.1", "1.2"));
+ uuids.add(testVersionUpdate("1.1", "1.1", true, "1.1", "1.2"));
+ uuids.add(testVersionUpdate("1.1", "1.1.5", true, "1.1", "1.2"));
+ uuids.add(testVersionUpdate("1.1", "1.2", true, "1.1", "1.2"));
+ uuids.add(testVersionUpdate("1.1", "2.1", true, "1.1", "2.1"));
+ }
+
+ @Override
+ protected int getIterations() {
+ return 1;
+ }
+
+}
Added: trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsServerMassTestCase.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsServerMassTestCase.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsServerMassTestCase.java 2008-02-20 23:22:26 UTC (rev 1158)
@@ -0,0 +1,27 @@
+/*
+* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais
+*
+* 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
+* 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, write to the Free Software
+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+* ##% */
+package fr.cemagref.simexplorer.is.service;
+
+public class StorageServiceVersionsServerMassTestCase extends StorageServiceVersionsServerTestCase {
+
+ @Override
+ protected int getIterations() {
+ return 50;
+ }
+
+}
Added: trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsServerTestCase.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsServerTestCase.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsServerTestCase.java 2008-02-20 23:22:26 UTC (rev 1158)
@@ -0,0 +1,78 @@
+/*
+* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais
+*
+* 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
+* 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, write to the Free Software
+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+* ##% */
+package fr.cemagref.simexplorer.is.service;
+
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import fr.cemagref.simexplorer.is.exceptions.SimExplorerException;
+
+/**
+ * The Class StorageServiceVersionsServerTestCase.
+ */
+public class StorageServiceVersionsServerTestCase extends StorageServiceVersionsTestCase {
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.service.StorageServiceVersionsTestCase#buildStorageService()
+ */
+ @Override
+ protected void buildStorageService() throws Exception {
+ Properties properties = (Properties) System.getProperties().clone();
+ properties.put("java.naming.provider.url", "jnp://localhost:1099");
+ properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+ properties.put("java.naming.factory.url.pkgs", "org.jnp.interfaces");
+
+ Context context = new InitialContext(properties);
+ storageService = (StorageService) context.lookup("StorageService");
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.service.StorageServiceVersionsTestCase#loginOnService()
+ */
+ @Override
+ protected void loginOnService() throws Exception {
+ String password = "password";
+ token = storageService.loginUser("superadmin", AuthenticationServiceHelper.computeHash(password.toCharArray()));
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.service.StorageServiceVersionsTestCase#versionsTest(java.util.List)
+ */
+ @Override
+ protected void versionsTest(List<String> uuids) throws Exception {
+ uuids.add(testVersionUpdate("1.1", "1.0", false, "1.1"));
+ uuids.add(testVersionUpdate("1.1", "1.1", false, "1.1"));
+ uuids.add(testVersionUpdate("1.1", "2.1", false, "1.1", "2.1"));
+
+ uuids.add(testVersionUpdate("1.1", "1.0", true, "1.1", "2"));
+ uuids.add(testVersionUpdate("1.1", "1.1", true, "1.1", "2"));
+ uuids.add(testVersionUpdate("1.1", "1.999", true, "1.1", "2"));
+ uuids.add(testVersionUpdate("1.1", "2", true, "1.1", "2"));
+ uuids.add(testVersionUpdate("1.1", "2.1", true, "1.1", "2.1"));
+ }
+
+ @Override
+ protected int getIterations() {
+ return 1;
+ }
+
+}
Copied: trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsTestCase.java (from rev 1133, trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersions.java)
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsTestCase.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsTestCase.java 2008-02-20 23:22:26 UTC (rev 1158)
@@ -0,0 +1,288 @@
+/*
+* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais
+*
+* 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
+* 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, write to the Free Software
+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+* ##% */
+package fr.cemagref.simexplorer.is.service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+
+import org.apache.commons.collections.ListUtils;
+import org.apache.commons.collections.SetUtils;
+import org.codelutin.util.ArrayUtil;
+
+import junit.framework.TestCase;
+
+import com.healthmarketscience.rmiio.SerializableInputStream;
+
+import fr.cemagref.simexplorer.is.entities.attachment.Attachment;
+import fr.cemagref.simexplorer.is.entities.data.Code;
+import fr.cemagref.simexplorer.is.entities.data.Component;
+import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication;
+import fr.cemagref.simexplorer.is.entities.data.ExplorationData;
+import fr.cemagref.simexplorer.is.entities.data.Library;
+import fr.cemagref.simexplorer.is.entities.metadata.MetaData;
+import fr.cemagref.simexplorer.is.entities.metadata.Version;
+import fr.cemagref.simexplorer.is.exceptions.SimExplorerException;
+import fr.cemagref.simexplorer.is.factories.BaseEntityFactory;
+import fr.cemagref.simexplorer.is.factories.XmlConstants;
+import fr.cemagref.simexplorer.is.storage.ElementGenerator;
+import fr.cemagref.simexplorer.is.storage.ElementGenerator.RandomStream;
+
+/**
+ * The Class StorageServiceVersionsTestCase.
+ */
+public abstract class StorageServiceVersionsTestCase extends TestCase {
+
+ /** The storage service. */
+ protected StorageService storageService;
+
+ /** The element generator. */
+ protected ElementGenerator elementGenerator;
+
+ /** The token. */
+ protected String token;
+
+ /** The attachments. */
+ private Map<Attachment, ElementGenerator.RandomStream> attachments;
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ elementGenerator = new ElementGenerator();
+
+ buildStorageService();
+ }
+
+ /**
+ * Builds the storage service.
+ *
+ * @throws Exception the exception
+ */
+ protected abstract void buildStorageService() throws Exception;
+
+ /**
+ * Save ea.
+ *
+ * @param ea the ea
+ * @param computeAttachments the compute attachments
+ *
+ * @return the meta data
+ *
+ * @throws Exception the exception
+ */
+ private MetaData saveEa(ExplorationApplication ea, boolean computeAttachments) throws Exception {
+
+ if (computeAttachments) {
+ attachments = new HashMap<Attachment, ElementGenerator.RandomStream>();
+
+ List<Attachment> attachmentsKeys = new ArrayList<Attachment>();
+
+ attachmentsKeys.addAll(ea.getMetaData().getAttachments());
+ List<Component> components = ea.getComponents();
+ for (Component component : components) {
+ attachmentsKeys.addAll(component.getMetaData().getAttachments());
+ List<Library> libraries = component.getLibraries();
+ for (Library library : libraries) {
+ attachmentsKeys.addAll(library.getMetaData().getAttachments());
+ }
+ }
+ List<ExplorationData> explorations = ea.getExplorations();
+ for (ExplorationData explorationData : explorations) {
+ attachmentsKeys.addAll(explorationData.getMetaData().getAttachments());
+ }
+
+ for (Attachment attachment : attachmentsKeys) {
+ RandomStream randomStream = elementGenerator.generateTextStream();
+ attachment.setDataHash(randomStream.getMd5());
+ attachments.put(attachment, randomStream);
+ }
+ }
+
+ SerializableInputStream xmlStream = new SerializableInputStream(BaseEntityFactory.getFactory(
+ ExplorationApplication.class).saveElement(XmlConstants.VALUE_METADATA_TYPE_EA, ea));
+
+ Map<Attachment, SerializableInputStream> realAttachments = new HashMap<Attachment, SerializableInputStream>();
+ for (Map.Entry<Attachment, ElementGenerator.RandomStream> element : attachments.entrySet()) {
+ realAttachments.put(element.getKey(), new SerializableInputStream(element.getValue().getStream()));
+ }
+
+ return storageService.saveElement(token, xmlStream, realAttachments);
+ }
+
+ /**
+ * List existing.
+ *
+ * @param uuid the uuid
+ *
+ * @throws SimExplorerException the sim explorer exception
+ */
+ private void listExisting(String uuid) throws SimExplorerException {
+ if (uuid != null) {
+ Version[] versions = storageService.getVersions(token, uuid);
+ System.out.println("Versions of uuid " + uuid + ":");
+ for (int i = 0; i < versions.length; i++) {
+ System.out.println(versions[i]);
+ }
+ }
+ }
+
+ /**
+ * Test version update.
+ *
+ * @param firstVersion the first version
+ * @param secondVersion the second version
+ * @param different the different
+ * @param versions the versions
+ *
+ * @return the string
+ *
+ * @throws Exception the exception
+ */
+ protected String testVersionUpdate(String firstVersion, String secondVersion, boolean different, String... versions)
+ throws Exception {
+ System.out.println("-----------------------------");
+
+ ExplorationApplication ea;
+
+ ea = elementGenerator.generateRandomEA();
+
+ StringBuffer task = new StringBuffer();
+ task.append(firstVersion).append("A + ").append(secondVersion);
+ if (different) {
+ task.append("B");
+ } else {
+ task.append("A");
+ }
+
+ task.append(" = ");
+
+ int i = 0;
+ for (String version : versions) {
+ if (i != 0) {
+ task.append(" + ");
+ }
+ task.append(version);
+ i++;
+ }
+
+ System.out.println(task.toString());
+
+ System.out.println("UUID : " + ea.getMetaData().getUuid());
+ System.out.println("Name : " + ea.getMetaData().getName());
+
+ ea.getMetaData().setVersion(firstVersion);
+
+ System.out.println("Saving " + firstVersion + "A");
+ MetaData mde1 = saveEa(ea, true);
+ listExisting(ea.getMetaData().getUuid());
+
+ ea.getMetaData().setVersion(secondVersion);
+
+ if (different) {
+ Component component = ea.getComponents().iterator().next();
+ Code code = new Code();
+ code.setCode("regreg");
+ code.setLanguage("regreg");
+ component.getCodes().add(code);
+ }
+
+ System.out.print("Saving " + secondVersion);
+ if (different) {
+ System.out.println("B");
+ } else {
+ System.out.println("A");
+ }
+ MetaData mde2 = saveEa(ea, false);
+ listExisting(ea.getMetaData().getUuid());
+
+ System.out.println("A : " + mde1.getHash());
+ if (different) {
+ System.out.println("B : " + mde2.getHash());
+ }
+
+ Version[] fundVersions = storageService.getVersions(token, ea.getMetaData().getUuid());
+
+ Set<Version> expectedVersionSet = new HashSet<Version>();
+ for (String versionExpected : versions) {
+ expectedVersionSet.add(Version.valueOf(versionExpected));
+ }
+
+ Set<Version> fundVersionSet = new HashSet<Version>();
+ fundVersionSet.addAll(ArrayUtil.asList(fundVersions));
+
+ assertTrue(SetUtils.isEqualSet(expectedVersionSet, fundVersionSet));
+
+ return ea.getMetaData().getUuid();
+ // assertEquals(mde1.getVersion().toString(), assertFirst);
+ // assertEquals(mde2.getVersion().toString(), assertSecond);
+ }
+
+ /**
+ * Login on service.
+ *
+ * @throws Exception the exception
+ */
+ protected abstract void loginOnService() throws Exception;
+
+ /**
+ * Versions test.
+ *
+ * @param uuids the uuids
+ *
+ * @throws Exception the exception
+ */
+ protected abstract void versionsTest(List<String> uuids) throws Exception;
+
+ /**
+ * Gets the iterations.
+ *
+ * @return the iterations
+ */
+ protected abstract int getIterations();
+
+ /**
+ * Test version update.
+ *
+ * @throws Exception the exception
+ */
+ public void testVersionUpdate() throws Exception {
+
+ List<String> uuids = new ArrayList<String>();
+
+ loginOnService();
+
+ for (int i = 0; i < getIterations(); i++) {
+ System.out.println("Iteration " + i);
+ versionsTest(uuids);
+ }
+
+ System.out.println("-----------------------------");
+ for (String uuid : uuids) {
+ listExisting(uuid);
+ }
+
+ }
+
+}
Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementRights.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementRights.java 2008-02-20 23:12:38 UTC (rev 1157)
+++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementRights.java 2008-02-20 23:22:26 UTC (rev 1158)
@@ -113,7 +113,7 @@
adminUsers = new ArrayList<User>();
adminGroups = new ArrayList<Group>();
- Permission[] permissions = RemoteSecurityService.getAuthentificationService().getPermissions(
+ Permission[] permissions = RemoteSecurityService.getAuthentificationService().getPermissions(getToken(),
getMetadata().getUuid());
for (Permission permission : permissions) {
if (permission.isOwner() && permission.getActor() instanceof User) {
@@ -172,7 +172,7 @@
* On success.
*
* @return the object
- * @throws SimExplorerException
+ * @throws SimExplorerException
*/
public Object onSuccess() throws SimExplorerException {
Map<Actor, Permission> permissions = new HashMap<Actor, Permission>();
@@ -205,7 +205,8 @@
Permission[] permissionsArray = permissions.values().toArray(new Permission[permissions.values().size()]);
- RemoteSecurityService.getAuthentificationService().setPermissions(getMetadata().getUuid(), permissionsArray);
+ RemoteSecurityService.getAuthentificationService().setPermissions(getToken(), getMetadata().getUuid(),
+ permissionsArray);
return elementDetail;
}