Simexplorer-si-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
January 2008
- 2 participants
- 470 discussions
r514 - trunk/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/factories
by tchemit@users.labs.libre-entreprise.org 24 Jan '08
by tchemit@users.labs.libre-entreprise.org 24 Jan '08
24 Jan '08
Author: tchemit
Date: 2008-01-24 21:28:39 +0000 (Thu, 24 Jan 2008)
New Revision: 514
Modified:
trunk/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/factories/BaseEntityFactory.java
trunk/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/factories/LoggableElementFactory.java
trunk/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/factories/MetaDataEntityFactory.java
Log:
changement prototype de la m?\195?\169thode getFactory
ajout d'une surcharge dans MetaDataEntityFactory pour ne pas casser les casts
Modified: trunk/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/factories/BaseEntityFactory.java
===================================================================
--- trunk/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/factories/BaseEntityFactory.java 2008-01-24 20:40:32 UTC (rev 513)
+++ trunk/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/factories/BaseEntityFactory.java 2008-01-24 21:28:39 UTC (rev 514)
@@ -55,24 +55,22 @@
/**
* Retrieve instance of the factory
*
- * @param <T>
- * Factory spec. class
* @param entityClass
* Class wanted
* @return Factory
* @throws Exception
*/
@SuppressWarnings("unchecked")
- public static <T extends DataEntity> BaseEntityFactory<T> getFactory(
+ public static <E extends DataEntity> BaseEntityFactory<E> getFactory(
Class entityClass) throws Exception {
- BaseEntityFactory<T> result = (BaseEntityFactory<T>) factories
+ BaseEntityFactory<E> result = (BaseEntityFactory<E>) factories
.get(entityClass.getSimpleName());
if (result == null) {
String elementFactoryClassName = BaseEntityFactory.class
.getPackage().getName()
+ "." + entityClass.getSimpleName() + "Factory";
- Class<? extends BaseEntityFactory<T>> factoryClass = (Class<? extends BaseEntityFactory<T>>) Class
+ Class<? extends BaseEntityFactory<E>> factoryClass = (Class<? extends BaseEntityFactory<E>>) Class
.forName(elementFactoryClassName).asSubclass(
BaseEntityFactory.class);
@@ -166,6 +164,7 @@
/**
* Save an element to a XML stream
*
+ * @param rootNodeName
* @param element
* @return
* @throws Exception
@@ -271,7 +270,7 @@
/**
* Save an element as a XML stream
*
- * @param rootNode
+ * @param node
* @return
* @throws Exception
*/
@@ -290,7 +289,8 @@
Transformer transformer = tf.newTransformer();
transformer.transform(domSource, result);
- ByteArrayInputStream inputStream = new ByteArrayInputStream(os
+ ByteArrayInputStream inputStream;
+ inputStream = new ByteArrayInputStream(os
.toByteArray());
return inputStream;
Modified: trunk/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/factories/LoggableElementFactory.java
===================================================================
--- trunk/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/factories/LoggableElementFactory.java 2008-01-24 20:40:32 UTC (rev 513)
+++ trunk/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/factories/LoggableElementFactory.java 2008-01-24 21:28:39 UTC (rev 514)
@@ -29,8 +29,7 @@
public E loadElement(Element xmlElement) throws Exception {
E element = super.loadElement(xmlElement);
- MetaDataEntityFactory elementFactory = (MetaDataEntityFactory) BaseEntityFactory
- .getFactory(MetaDataEntity.class);
+ MetaDataEntityFactory elementFactory = MetaDataEntityFactory.getFactory(MetaDataEntity.class);
// Load metadata informations
Element mdeElement = getXMLElementByTagName(xmlElement, KEY_METADATA);
@@ -43,8 +42,7 @@
@Override
public void saveElement(org.w3c.dom.Document document, Element xmlElement,
E element) throws Exception {
- MetaDataEntityFactory elementFactory = (MetaDataEntityFactory) BaseEntityFactory
- .getFactory(MetaDataEntity.class);
+ MetaDataEntityFactory elementFactory = MetaDataEntityFactory.getFactory(MetaDataEntity.class);
// Save metadata informations
Element mdeElement = document.createElement(KEY_METADATA);
Modified: trunk/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/factories/MetaDataEntityFactory.java
===================================================================
--- trunk/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/factories/MetaDataEntityFactory.java 2008-01-24 20:40:32 UTC (rev 513)
+++ trunk/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/factories/MetaDataEntityFactory.java 2008-01-24 21:28:39 UTC (rev 514)
@@ -39,14 +39,20 @@
@Override
public MetaDataEntity createInstance() {
- return new MetaDataEntity();
+ return new MetaDataEntity();
}
+ @SuppressWarnings({"unchecked"})
+ public static <E extends MetaDataEntity> MetaDataEntityFactory<E> getFactory(
+ Class<E> entityClass) throws Exception {
+ return (MetaDataEntityFactory) BaseEntityFactory.getFactory(entityClass);
+ }
/*
* (non-Javadoc)
*
* @see fr.cemagref.simexplorer.is.storage.factories.BaseEntityFactory#loadXMLElement(org.w3c.dom.Element)
*/
+
@Override
public MetaDataEntity loadElement(Element xmlElement) throws Exception {
MetaDataEntity entity = super.loadElement(xmlElement);
@@ -215,7 +221,8 @@
Document document = getXMLBuilder().parse(xmlStream);
Element rootElement = (Element) document.getFirstChild();
Element mdeElement = getXMLElementByTagName(rootElement, KEY_METADATA);
- MetaDataEntity mde = loadElement(mdeElement);
+ MetaDataEntity mde;
+ mde = loadElement(mdeElement);
return mde;
}
1
0
r513 - trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services
by tchemit@users.labs.libre-entreprise.org 24 Jan '08
by tchemit@users.labs.libre-entreprise.org 24 Jan '08
24 Jan '08
Author: tchemit
Date: 2008-01-24 20:40:32 +0000 (Thu, 24 Jan 2008)
New Revision: 513
Modified:
trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/RemoteSecurityService.java
trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/RemoteService.java
Log:
d?\195?\169placement du service d'authentification vers le module service
Modified: trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/RemoteSecurityService.java
===================================================================
--- trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/RemoteSecurityService.java 2008-01-24 20:39:51 UTC (rev 512)
+++ trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/RemoteSecurityService.java 2008-01-24 20:40:32 UTC (rev 513)
@@ -17,7 +17,7 @@
* ##% */
package fr.cemagref.simexplorer.is.ui.web.services;
-import fr.cemagref.simexplorer.is.security.service.AuthenticationService;
+import fr.cemagref.simexplorer.is.service.AuthenticationService;
public class RemoteSecurityService extends RemoteService {
Modified: trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/RemoteService.java
===================================================================
--- trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/RemoteService.java 2008-01-24 20:39:51 UTC (rev 512)
+++ trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/RemoteService.java 2008-01-24 20:40:32 UTC (rev 513)
@@ -39,7 +39,7 @@
properties
.put("java.naming.factory.url.pkgs", "org.jnp.interfaces");
- Context context = null;
+ Context context;
try {
context = new InitialContext(properties);
} catch (Exception e) {
1
0
r512 - trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui
by tchemit@users.labs.libre-entreprise.org 24 Jan '08
by tchemit@users.labs.libre-entreprise.org 24 Jan '08
24 Jan '08
Author: tchemit
Date: 2008-01-24 20:39:51 +0000 (Thu, 24 Jan 2008)
New Revision: 512
Modified:
trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/SimExplorerContext.java
Log:
suppression service d'authentification, pas besoin pour le client lourd (utiliser le storage service)
Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/SimExplorerContext.java
===================================================================
--- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/SimExplorerContext.java 2008-01-24 20:39:02 UTC (rev 511)
+++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/SimExplorerContext.java 2008-01-24 20:39:51 UTC (rev 512)
@@ -18,7 +18,6 @@
* ##% */
package fr.cemagref.simexplorer.is.ui;
-import fr.cemagref.simexplorer.is.security.service.AuthenticationService;
import fr.cemagref.simexplorer.is.service.MockStorageServiceImpl;
import fr.cemagref.simexplorer.is.service.StorageService;
import fr.cemagref.simexplorer.is.ui.actions.SimExplorerCommonActions;
@@ -69,9 +68,6 @@
/** le service de données distant */
protected StorageService storageService;
- /** le service d'authentification */
- protected AuthenticationService authenticationService;
-
/**
* @return le parseur utilisé pour parser les options de la ligne de
* commande.
@@ -187,14 +183,6 @@
return service;
}
- /** @return le service d'authentification */
- public AuthenticationService getAuthenticationService() {
- if (authenticationService == null) {
- //authenticationService = new AuthenticationService();
- }
- return authenticationService;
- }
-
public void setQuit(boolean quit) {
this.quit = quit;
}
1
0
r511 - trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine
by tchemit@users.labs.libre-entreprise.org 24 Jan '08
by tchemit@users.labs.libre-entreprise.org 24 Jan '08
24 Jan '08
Author: tchemit
Date: 2008-01-24 20:39:02 +0000 (Thu, 24 Jan 2008)
New Revision: 511
Modified:
trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java
Log:
suppression intializer inutiles
Modified: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java
===================================================================
--- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java 2008-01-24 20:38:42 UTC (rev 510)
+++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java 2008-01-24 20:39:02 UTC (rev 511)
@@ -62,7 +62,8 @@
public MetaDataEntity[] findElementsByType(String token, String type,
boolean onlyLatest, int start, int count, int dateOrder)
throws StorageException {
- MetaDataEntity[] list = super.findElementsByType(token, type,
+ MetaDataEntity[] list;
+ list = super.findElementsByType(token, type,
onlyLatest, start, count, dateOrder);
// TODO how to filter without losing pagination?
return list;
@@ -94,7 +95,7 @@
@Override
public MetaDataEntity getMetadata(String token, String uuid, Version version)
throws StorageException {
- MetaDataEntity mde = null;
+ MetaDataEntity mde;
Permission permission = credentialManager.getPermission(token, uuid);
if (permission.isCanRead()) {
mde = super.getMetadata(token, uuid, version);
@@ -107,7 +108,7 @@
@Override
public MetaDataEntity getMetadata(String token, String uuid)
throws StorageException {
- MetaDataEntity mde = null;
+ MetaDataEntity mde;
Permission permission = credentialManager.getPermission(token, uuid);
if (permission.isCanRead()) {
mde = super.getMetadata(token, uuid);
@@ -120,7 +121,7 @@
@Override
public List<Version> getVersions(String token, String uuid)
throws StorageException {
- List<Version> versions = null;
+ List<Version> versions;
Permission permission = credentialManager.getPermission(token, uuid);
if (permission.isCanRead()) {
versions = super.getVersions(token, uuid);
@@ -133,7 +134,7 @@
@Override
public InputStream retrieveData(String token, MetaDataEntity entity,
String field) throws StorageException {
- InputStream stream = null;
+ InputStream stream;
Permission permission = credentialManager.getPermission(token, entity
.getUuid());
if (permission.isCanRead()) {
1
0
r510 - trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service
by tchemit@users.labs.libre-entreprise.org 24 Jan '08
by tchemit@users.labs.libre-entreprise.org 24 Jan '08
24 Jan '08
Author: tchemit
Date: 2008-01-24 20:38:42 +0000 (Thu, 24 Jan 2008)
New Revision: 510
Modified:
trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceClient.java
trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceServer.java
Log:
suppression imports inutiles
Modified: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceClient.java
===================================================================
--- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceClient.java 2008-01-24 20:38:22 UTC (rev 509)
+++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceClient.java 2008-01-24 20:38:42 UTC (rev 510)
@@ -18,8 +18,6 @@
package fr.cemagref.simexplorer.is.service;
import fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl;
-import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity;
-import com.healthmarketscience.rmiio.RemoteInputStream;
public class StorageServiceClient extends StorageServiceCommon {
Modified: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceServer.java
===================================================================
--- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceServer.java 2008-01-24 20:38:22 UTC (rev 509)
+++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceServer.java 2008-01-24 20:38:42 UTC (rev 510)
@@ -23,10 +23,7 @@
import org.jboss.annotation.ejb.RemoteBinding;
-import fr.cemagref.simexplorer.is.security.service.AuthenticationService;
import fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl;
-import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity;
-import com.healthmarketscience.rmiio.RemoteInputStream;
@Stateless(name = "StorageService")
@Remote(StorageService.class)
1
0
r509 - trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities
by tchemit@users.labs.libre-entreprise.org 24 Jan '08
by tchemit@users.labs.libre-entreprise.org 24 Jan '08
24 Jan '08
Author: tchemit
Date: 2008-01-24 20:38:22 +0000 (Thu, 24 Jan 2008)
New Revision: 509
Modified:
trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Actor.java
trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/User.java
Log:
foreach et simplify test
Modified: trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Actor.java
===================================================================
--- trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Actor.java 2008-01-24 20:37:52 UTC (rev 508)
+++ trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Actor.java 2008-01-24 20:38:22 UTC (rev 509)
@@ -77,9 +77,7 @@
return false;
}
Iterator<Group> iterator2 = groups2.iterator();
- for (Iterator<Group> iterator1 = groups1.iterator(); iterator1
- .hasNext();) {
- Group group1 = iterator1.next();
+ for (Group group1 : groups1) {
Group group2 = iterator2.next();
if (group1 == null) {
if (group2 != null)
Modified: trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/User.java
===================================================================
--- trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/User.java 2008-01-24 20:37:52 UTC (rev 508)
+++ trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/User.java 2008-01-24 20:38:22 UTC (rev 509)
@@ -110,9 +110,7 @@
return false;
} else if (!passwordHash.equals(other.passwordHash))
return false;
- if (superAdmin != other.superAdmin)
- return false;
- return true;
+ return superAdmin == other.superAdmin;
}
}
1
0
r508 - in trunk: simexplorer-is-security simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test simexplorer-is-service simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service
by tchemit@users.labs.libre-entreprise.org 24 Jan '08
by tchemit@users.labs.libre-entreprise.org 24 Jan '08
24 Jan '08
Author: tchemit
Date: 2008-01-24 20:37:52 +0000 (Thu, 24 Jan 2008)
New Revision: 508
Added:
trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationService.java
trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java
trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockAuthenticationServiceImpl.java
trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/SecurityEqualsTestCase.java
trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/SecurityTestCase.java
Removed:
trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationService.java
trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationServiceImpl.java
trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/MockAuthenticationServiceImpl.java
trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityEqualsTestCase.java
trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityTestCase.java
Modified:
trunk/simexplorer-is-security/pom.xml
trunk/simexplorer-is-service/pom.xml
Log:
ajout description du module + suppression d?\195?\169pendances inutiles suite au d?\195?\169placement du service vers le module service
Modified: trunk/simexplorer-is-security/pom.xml
===================================================================
--- trunk/simexplorer-is-security/pom.xml 2008-01-24 20:10:18 UTC (rev 507)
+++ trunk/simexplorer-is-security/pom.xml 2008-01-24 20:37:52 UTC (rev 508)
@@ -10,7 +10,7 @@
<name>Security</name>
<version>0.0.1-SNAPSHOT</version>
- <description></description>
+ <description>SimExplorer SI security module</description>
<packaging>ejb</packaging>
<parent>
@@ -43,11 +43,11 @@
<artifactId>h2</artifactId>
<version>1.0.64</version>
</dependency>
- <dependency>
+ <!--dependency>
<groupId>jboss</groupId>
<artifactId>jbossall-client</artifactId>
<version>4.2.2.GA</version>
<scope>provided</scope>
- </dependency>
+ </dependency-->
</dependencies>
</project>
Deleted: trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationService.java
===================================================================
--- trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationService.java 2008-01-24 20:10:18 UTC (rev 507)
+++ trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationService.java 2008-01-24 20:37:52 UTC (rev 508)
@@ -1,79 +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.security.service;
-
-import javax.ejb.Remote;
-
-import fr.cemagref.simexplorer.is.security.entities.Group;
-import fr.cemagref.simexplorer.is.security.entities.User;
-
- at Remote
-public interface AuthenticationService {
-
- public String loginUser(String login, String password);
-
- public void closeSessionTimer(String token);
-
- public User requestAccount(String login, String mail);
-
- public User saveUser(String token, String login, String mail);
-
- public void resetPassword(String token, String login);
-
- public void changePassword(String token, String login, String password);
-
- public User getUser(String token, Integer id);
-
- public User getUser(String token, String login);
-
- public User updateUser(String token, User user);
-
- public void deleteUser(String token, Integer id);
-
- public User[] getUsers(String token);
-
- public User[] getUsersOfGroup(String token, Group group);
-
- public void setUsersOfGroup(String token, Group group,
- Integer[] usersInGroup);
-
- public void setGroupsOfGroup(String token, Group group, Integer[] groupsIds);
-
- public Group[] getGroupsOfUser(String token, User user);
-
- public Group[] getGroupsOfGroup(String token, Group group);
-
- public void setGroupsOfUser(String token, User user, Integer[] groupsIds);
-
- public Group saveGroup(String token, String name, User owner);
-
- public Group getGroup(String token, Integer id);
-
- public Group getGroup(String token, String name);
-
- public Group updateGroup(String token, Group group);
-
- public void deleteGroup(String token, Integer id);
-
- public Group[] getGroups(String token);
-
- public Group[] getGroupsOwnedBy(String token, User user);
-
- public User getLoggedUser(String token);
-
-}
Deleted: trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationServiceImpl.java
===================================================================
--- trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationServiceImpl.java 2008-01-24 20:10:18 UTC (rev 507)
+++ trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationServiceImpl.java 2008-01-24 20:37:52 UTC (rev 508)
@@ -1,331 +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.security.service;
-
-import java.security.MessageDigest;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.UUID;
-import java.util.Arrays;
-
-import javax.annotation.Resource;
-import javax.ejb.EJB;
-import javax.ejb.Remote;
-import javax.ejb.SessionContext;
-import javax.ejb.Stateless;
-import javax.ejb.Timeout;
-import javax.ejb.Timer;
-import javax.ejb.TimerService;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
-
-import org.jboss.annotation.ejb.RemoteBinding;
-
-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.User;
-
- at Stateless(name = "AuthenticationService")
- at Remote(AuthenticationService.class)
- at RemoteBinding(jndiBinding = "AuthenticationService")
- at TransactionAttribute(TransactionAttributeType.REQUIRED)
-public class AuthenticationServiceImpl implements AuthenticationService {
-
- @EJB
- private DaoSecurity dao;
-
- @Resource
- private SessionContext sessionContext;
-
- private static boolean superAdminCheck = false;
-
- private void sendMail(String login, String mail, String password) {
- /*
- javax.mail.Session mailSession = (javax.mail.Session) new InitialContext().lookup("java:/Mail");
- javax.mail.Message msg = new MimeMessage(mailSession);
- msg.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse("AQui at aQui.be,siplusieuradresse at hotmail.com", false));
- msg.setSubject("This is a test");
- msg.setContent("<html><body><h2>Helle le monde mondial des terriens " +
- " Petit test de jboss Mail-Service" +
- " Ne m'en voulez pas si vous recevez ce mail alors que vous nedevrez pas " +
- " Braim " +
- "</h2></body></html>", "text/html");
- msg.setHeader("X-Mailer", "JavaMailer");
- msg.setSentDate(new java.util.Date());
- Transport.send(msg);
- */
- }
-
- private String computeHash(String clearString) {
- MessageDigest messageDigest = null;
- try {
- messageDigest = MessageDigest.getInstance("SHA-1");
- } catch (Exception e) {
- // TODO: handle exception
- }
- messageDigest.reset();
- messageDigest.update(clearString.getBytes());
- String hashedPassword;
- hashedPassword = new String(messageDigest.digest());
- return hashedPassword;
- }
-
- private String generatePassword() {
- // FIXME
- return "password";
- }
-
- private void removeUserFromGroup(User user, Group group) {
- List<Group> toRemove = new ArrayList<Group>();
- for (Group testGroup : user.getGroups()) {
- if (testGroup.getId().equals(group.getId())) {
- toRemove.add(testGroup);
- }
- }
- for (Group groupToRemove : toRemove) {
- user.getGroups().remove(groupToRemove);
- }
- }
-
- public void deleteGroup(String token, Integer id) {
- dao.deleteGroup(id);
- }
-
- public void deleteUser(String token, Integer id) {
- dao.deleteUser(id);
- }
-
- public Group getGroup(String token, Integer id) {
- return dao.getGroup(id);
- }
-
- public Group getGroup(String token, String name) {
- return dao.getGroup(name);
- }
-
- public User getUser(String token, Integer id) {
- return dao.getUser(id);
- }
-
- public User getUser(String token, String login) {
- return dao.getUser(login);
- }
-
- public Group saveGroup(String token, String name, User owner) {
- Group group = new Group();
- group.setName(name);
- group.setOwner(owner);
- dao.saveGroup(group);
- group = getGroup(token, group.getId());
- return group;
- }
-
- public User saveUser(String token, String login, String mail) {
- User user = new User();
- user.setLogin(login);
- user.setMail(mail);
- String password = generatePassword();
- sendMail(login, mail, password);
- String passwordHash = computeHash(password);
- user.setPasswordHash(passwordHash);
- user.setAdmin(false);
- user.setSuperAdmin(false);
- dao.saveUser(user);
- user = getUser(token, user.getId());
- return user;
- }
-
- public Group updateGroup(String token, Group group) {
- return dao.updateGroup(group);
- }
-
- public User updateUser(String token, User user) {
- return dao.updateUser(user);
- }
-
- public User getLoggedUser(String token) {
- User loggedUser;
- loggedUser = dao.getLoggedUser(token);
- return loggedUser;
- }
-
- private void checkSuperAdmin() {
- if (dao.getUser("superadmin") == null) {
- User user = new User();
- user.setLogin("superadmin");
- user.setMail("");
- String password = "password";
- String passwordHash = computeHash(password);
- user.setPasswordHash(passwordHash);
- user.setAdmin(true);
- user.setSuperAdmin(true);
- dao.saveUser(user);
- }
- }
-
- public String loginUser(String login, String password) {
- if (!superAdminCheck) {
- checkSuperAdmin();
- superAdminCheck = true;
- }
- String token = null;
- User loggedUser = dao.loginUser(login, computeHash(password));
- if (loggedUser != null) {
- LoginAction loginAction = new LoginAction();
- loginAction.setLoggedUser(loggedUser);
- loginAction.setTime(new Date());
- loginAction.setToken(UUID.randomUUID().toString());
- dao.saveToken(loginAction);
- token = loginAction.getToken();
- }
- return token;
- }
-
- public void closeSessionTimer(String token) {
- // FIXME session length
- TimerService timerService = sessionContext.getTimerService();
- timerService.createTimer(10 * 60 * 1000, token);
- }
-
- @Timeout
- public void timeoutHandler(Timer timer) {
- String token = (String) timer.getInfo();
- dao.deleteToken(token);
- }
-
- public User requestAccount(String login, String mail) {
- User user = new User();
- user.setLogin(login);
- user.setMail(mail);
- String password = generatePassword();
- sendMail(login, mail, password);
- String passwordHash = computeHash(password);
- user.setPasswordHash(passwordHash);
- dao.saveUser(user);
- return user;
- }
-
- public void changePassword(String token, String login, String password) {
- User user = getUser(token, login);
- String passwordHash = computeHash(password);
- user.setPasswordHash(passwordHash);
- dao.saveUser(user);
- }
-
- public void resetPassword(String token, String login) {
- User user = getUser(token, login);
- String password = generatePassword();
- sendMail(login, user.getMail(), password);
- String passwordHash = computeHash(password);
- user.setPasswordHash(passwordHash);
- dao.saveUser(user);
- }
-
- public Group[] getGroups(String token) {
- List<Group> groups = dao.getGroups();
- Group[] result;
- result = groups.toArray(new Group[groups.size()]);
- return result;
- }
-
- public Group[] getGroupsOwnedBy(String token, User user) {
- List<Group> list = dao.getGroupsOwnedBy(user);
- return list.toArray(new Group[list.size()]);
- }
-
- public User[] getUsers(String token) {
- return dao.getUsers().toArray(new User[dao.getUsers().size()]);
- }
-
- public User[] getUsersOfGroup(String token, Group group) {
- List<User> usersOfGroup = dao.getUsersOfGroup(group);
- return usersOfGroup.toArray(new User[usersOfGroup.size()]);
- }
-
- public void setUsersOfGroup(String token, Group group,
- Integer[] usersInGroup) {
- List<Integer> newUsers = new ArrayList<Integer>();
- newUsers.addAll(Arrays.asList(usersInGroup));
-
- List<Integer> usersToAdd = new ArrayList<Integer>();
- List<Integer> usersToRemove = new ArrayList<Integer>();
-
- List<User> users = dao.getUsersOfGroup(group);
-
- List<Integer> currentUsers = new ArrayList<Integer>();
- for (User user : users) {
- currentUsers.add(user.getId());
- }
-
- for (Integer user : currentUsers) {
- if (!newUsers.contains(user)) {
- usersToRemove.add(user);
- }
- }
- for (Integer user : newUsers) {
- if (!currentUsers.contains(user)) {
- usersToAdd.add(user);
- }
- }
-
- for (Integer idUser : usersToAdd) {
- User user = dao.getUser(idUser);
- user.getGroups().add(group);
- dao.updateUser(user);
- }
- for (Integer idUser : usersToRemove) {
- User user = dao.getUser(idUser);
- removeUserFromGroup(user, group);
- dao.updateUser(user);
- }
- }
-
- public void setGroupsOfUser(String token, User user, Integer[] groupsIds) {
- User realUser = dao.getUser(user.getId());
- realUser.getGroups().clear();
- for (Integer groupsId : groupsIds) {
- Group group = dao.getGroup(groupsId);
- realUser.getGroups().add(group);
- }
- dao.updateUser(realUser);
-
- }
-
- public Group[] getGroupsOfUser(String token, User user) {
- List<Group> list = dao.getGroupsOfUser(user);
- return list.toArray(new Group[list.size()]);
- }
-
- public Group[] getGroupsOfGroup(String token, Group group) {
- List<Group> groupsOfGroup = dao.getGroupsOfGroup(group);
- return groupsOfGroup.toArray(new Group[groupsOfGroup.size()]);
- }
-
- public void setGroupsOfGroup(String token, Group group, Integer[] groupsIds) {
- Group realGroup = dao.getGroup(group.getId());
- realGroup.getGroups().clear();
- for (Integer groupsId : groupsIds) {
- Group groupOwned = dao.getGroup(groupsId);
- realGroup.getGroups().add(groupOwned);
- }
- dao.updateGroup(realGroup);
- }
-
-}
Deleted: trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/MockAuthenticationServiceImpl.java
===================================================================
--- trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/MockAuthenticationServiceImpl.java 2008-01-24 20:10:18 UTC (rev 507)
+++ trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/MockAuthenticationServiceImpl.java 2008-01-24 20:37:52 UTC (rev 508)
@@ -1,130 +0,0 @@
-/*
-* ##% Copyright (C) 2008 Code Lutin, Tony Chemit, 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.security.service;
-
-import fr.cemagref.simexplorer.is.security.entities.Group;
-import fr.cemagref.simexplorer.is.security.entities.User;
-
-
-public class MockAuthenticationServiceImpl implements AuthenticationService {
-
-
- public String loginUser(String login, String password) {
- return (String) checkImplemented();
- }
-
- public void closeSessionTimer(String token) {
- checkImplemented();
- }
-
- public User requestAccount(String login, String mail) {
- return (User) checkImplemented();
- }
-
- public User saveUser(String token, String login, String mail) {
- return (User) checkImplemented();
- }
-
- public void resetPassword(String token, String login) {
- checkImplemented();
- }
-
- public void changePassword(String token, String login, String password) {
- checkImplemented();
- }
-
- public User getUser(String token, Integer id) {
- return (User) checkImplemented();
- }
-
- public User getUser(String token, String login) {
- return (User) checkImplemented();
- }
-
- public User updateUser(String token, User user) {
- return (User) checkImplemented();
- }
-
- public void deleteUser(String token, Integer id) {
- checkImplemented();
- }
-
- public User[] getUsers(String token) {
- return (User[]) checkImplemented();
- }
-
- public User[] getUsersOfGroup(String token, Group group) {
- return (User[]) checkImplemented();
- }
-
- public void setUsersOfGroup(String token, Group group, Integer[] usersInGroup) {
- checkImplemented();
- }
-
- public void setGroupsOfGroup(String token, Group group, Integer[] groupsIds) {
- checkImplemented();
- }
-
- public Group[] getGroupsOfUser(String token, User user) {
- return (Group[]) checkImplemented();
- }
-
- public Group[] getGroupsOfGroup(String token, Group group) {
- return (Group[]) checkImplemented();
- }
-
- public void setGroupsOfUser(String token, User user, Integer[] groupsIds) {
- checkImplemented();
- }
-
- public Group saveGroup(String token, String name, User owner) {
- return (Group) checkImplemented();
- }
-
- public Group getGroup(String token, Integer id) {
- return (Group) checkImplemented();
- }
-
- public Group getGroup(String token, String name) {
- return (Group) checkImplemented();
- }
-
- public Group updateGroup(String token, Group group) {
- return (Group) checkImplemented();
- }
-
- public void deleteGroup(String token, Integer id) {
- checkImplemented();
- }
-
- public Group[] getGroups(String token) {
- return (Group[]) checkImplemented();
- }
-
- public Group[] getGroupsOwnedBy(String token, User user) {
- return (Group[]) checkImplemented();
- }
-
- public User getLoggedUser(String token) {
- return (User) checkImplemented();
- }
-
- private Object checkImplemented() {
- throw new IllegalStateException("not implemented");
- }
-}
\ No newline at end of file
Deleted: trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityEqualsTestCase.java
===================================================================
--- trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityEqualsTestCase.java 2008-01-24 20:10:18 UTC (rev 507)
+++ trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityEqualsTestCase.java 2008-01-24 20:37:52 UTC (rev 508)
@@ -1,61 +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.security.test;
-
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import junit.framework.TestCase;
-import fr.cemagref.simexplorer.is.security.entities.User;
-import fr.cemagref.simexplorer.is.security.service.AuthenticationService;
-
-public class SecurityEqualsTestCase extends TestCase {
-
- AuthenticationService authenticationService = null;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- 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);
- authenticationService = (AuthenticationService) context
- .lookup("AuthenticationService");
-
- }
-
- public void testHashCode() {
- String token = authenticationService.loginUser("superadmin", "password");
- User[] users1 = authenticationService.getUsers(token);
- User[] users2 = authenticationService.getUsers(token);
- for (int i = 0; i < users1.length; i++) {
- User user1 = users1[i];
- User user2 = users2[i];
- System.out.println("User " + i + " :");
- System.out.println(user1.hashCode() + " " + user2.hashCode());
- System.out.println(user1.equals(user2));
- }
- }
-
-}
Deleted: trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityTestCase.java
===================================================================
--- trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityTestCase.java 2008-01-24 20:10:18 UTC (rev 507)
+++ trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityTestCase.java 2008-01-24 20:37:52 UTC (rev 508)
@@ -1,128 +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.security.test;
-
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import junit.framework.TestCase;
-import fr.cemagref.simexplorer.is.security.entities.Group;
-import fr.cemagref.simexplorer.is.security.entities.User;
-import fr.cemagref.simexplorer.is.security.service.AuthenticationService;
-
-public class SecurityTestCase extends TestCase {
-
- AuthenticationService authenticationService = null;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- 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);
- authenticationService = (AuthenticationService) context
- .lookup("AuthenticationService");
-
- }
-
- public void testSecurityEntities() {
- /*
- User user = authenticationService.getUser("user3");
- Group[] groups = authenticationService.getGroupsOfUser(user);
- for (Group group : groups) {
- System.out.println(group.getName());
- }
- */
- String token = authenticationService
- .loginUser("superadmin", "password");
-
- Group everybody = authenticationService.saveGroup(token, "everybody",
- authenticationService.getLoggedUser(token));
-
- User me = authenticationService.getLoggedUser(token);
- me.getGroups().add(everybody);
- authenticationService.updateUser(token, me);
-
- User[] simpleUsers = new User[20];
- for (int i = 0; i < 20; i++) {
- simpleUsers[i] = authenticationService.saveUser(token, "user" + i,
- "landais+simtest at codelutin.com");
- simpleUsers[i].setAdmin(false);
- simpleUsers[i].setSuperAdmin(false);
- simpleUsers[i].getGroups().add(everybody);
- authenticationService.updateUser(token, simpleUsers[i]);
- }
-
- User[] adminUsers = new User[4];
- Group[] groups = new Group[4];
- for (int i = 0; i < 4; i++) {
- adminUsers[i] = authenticationService.saveUser(token, "admin" + i,
- "landais+simtest at codelutin.com");
- adminUsers[i].setAdmin(true);
- adminUsers[i].setSuperAdmin(false);
- adminUsers[i].getGroups().add(everybody);
- authenticationService.updateUser(token, adminUsers[i]);
-
- groups[i] = authenticationService.saveGroup(token, "group" + i,
- adminUsers[i]);
- for (int j = i * 4; j < (i * 4 + 5); j++) {
- simpleUsers[j].getGroups().add(groups[i]);
- authenticationService.updateUser(token, simpleUsers[j]);
- }
- }
-
- /*
- User superAdminUser = authenticationService.saveUser(token,
- "superadmin", "landais+simtest at codelutin.com");
- superAdminUser.setAdmin(true);
- superAdminUser.setSuperAdmin(true);
- authenticationService.updateUser(token, superAdminUser);
- */
-
- /*
- User[] users = new User[10];
- Group[] groups = new Group[10];
- for (int i = 0; i < 10; i++) {
- users[i] = authenticationService.saveUser("user" + i,
- "user1 at abc.fr");
- users[i].setAdmin(true);
- users[i].setSuperAdmin(true);
- authenticationService.updateUser(users[i]);
- groups[i] = authenticationService.saveGroup("group" + i, users[i]);
- }
-
- for (int i = 0; i < 10; i++) {
- System.out.println(users[i].getId());
- System.out.println(groups[i].getId());
- }
-
- String token = authenticationService.loginUser(users[4].getLogin(),
- "hierugheriugh");
- User userLogged = authenticationService.getLoggedUser(token);
-
- assertEquals(userLogged.getLogin(), users[4].getLogin());
- */
- }
-
-}
Modified: trunk/simexplorer-is-service/pom.xml
===================================================================
--- trunk/simexplorer-is-service/pom.xml 2008-01-24 20:10:18 UTC (rev 507)
+++ trunk/simexplorer-is-service/pom.xml 2008-01-24 20:37:52 UTC (rev 508)
@@ -44,5 +44,11 @@
<version>4.2.2.GA</version>
<scope>provided</scope>
</dependency>
- </dependencies>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jbossall-client</artifactId>
+ <version>4.2.2.GA</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
</project>
Copied: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationService.java (from rev 506, trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationService.java)
===================================================================
--- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationService.java (rev 0)
+++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationService.java 2008-01-24 20:37:52 UTC (rev 508)
@@ -0,0 +1,79 @@
+/*
+* ##% 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 javax.ejb.Remote;
+
+import fr.cemagref.simexplorer.is.security.entities.Group;
+import fr.cemagref.simexplorer.is.security.entities.User;
+
+ at Remote
+public interface AuthenticationService {
+
+ public String loginUser(String login, String password);
+
+ public void closeSessionTimer(String token);
+
+ public User requestAccount(String login, String mail);
+
+ public User saveUser(String token, String login, String mail);
+
+ public void resetPassword(String token, String login);
+
+ public void changePassword(String token, String login, String password);
+
+ public User getUser(String token, Integer id);
+
+ public User getUser(String token, String login);
+
+ public User updateUser(String token, User user);
+
+ public void deleteUser(String token, Integer id);
+
+ public User[] getUsers(String token);
+
+ public User[] getUsersOfGroup(String token, Group group);
+
+ public void setUsersOfGroup(String token, Group group,
+ Integer[] usersInGroup);
+
+ public void setGroupsOfGroup(String token, Group group, Integer[] groupsIds);
+
+ public Group[] getGroupsOfUser(String token, User user);
+
+ public Group[] getGroupsOfGroup(String token, Group group);
+
+ public void setGroupsOfUser(String token, User user, Integer[] groupsIds);
+
+ public Group saveGroup(String token, String name, User owner);
+
+ public Group getGroup(String token, Integer id);
+
+ public Group getGroup(String token, String name);
+
+ public Group updateGroup(String token, Group group);
+
+ public void deleteGroup(String token, Integer id);
+
+ public Group[] getGroups(String token);
+
+ public Group[] getGroupsOwnedBy(String token, User user);
+
+ public User getLoggedUser(String token);
+
+}
Copied: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java (from rev 506, trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationServiceImpl.java)
===================================================================
--- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java (rev 0)
+++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java 2008-01-24 20:37:52 UTC (rev 508)
@@ -0,0 +1,331 @@
+/*
+* ##% 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.security.MessageDigest;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+import java.util.Arrays;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Remote;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateless;
+import javax.ejb.Timeout;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+
+import org.jboss.annotation.ejb.RemoteBinding;
+
+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.User;
+
+ at Stateless(name = "AuthenticationService")
+ at Remote(AuthenticationService.class)
+ at RemoteBinding(jndiBinding = "AuthenticationService")
+ at TransactionAttribute(TransactionAttributeType.REQUIRED)
+public class AuthenticationServiceImpl implements AuthenticationService {
+
+ @EJB
+ private DaoSecurity dao;
+
+ @Resource
+ private SessionContext sessionContext;
+
+ private static boolean superAdminCheck = false;
+
+ private void sendMail(String login, String mail, String password) {
+ /*
+ javax.mail.Session mailSession = (javax.mail.Session) new InitialContext().lookup("java:/Mail");
+ javax.mail.Message msg = new MimeMessage(mailSession);
+ msg.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse("AQui at aQui.be,siplusieuradresse at hotmail.com", false));
+ msg.setSubject("This is a test");
+ msg.setContent("<html><body><h2>Helle le monde mondial des terriens " +
+ " Petit test de jboss Mail-Service" +
+ " Ne m'en voulez pas si vous recevez ce mail alors que vous nedevrez pas " +
+ " Braim " +
+ "</h2></body></html>", "text/html");
+ msg.setHeader("X-Mailer", "JavaMailer");
+ msg.setSentDate(new java.util.Date());
+ Transport.send(msg);
+ */
+ }
+
+ private String computeHash(String clearString) {
+ MessageDigest messageDigest = null;
+ try {
+ messageDigest = MessageDigest.getInstance("SHA-1");
+ } catch (Exception e) {
+ // TODO: handle exception
+ }
+ messageDigest.reset();
+ messageDigest.update(clearString.getBytes());
+ String hashedPassword;
+ hashedPassword = new String(messageDigest.digest());
+ return hashedPassword;
+ }
+
+ private String generatePassword() {
+ // FIXME
+ return "password";
+ }
+
+ private void removeUserFromGroup(User user, Group group) {
+ List<Group> toRemove = new ArrayList<Group>();
+ for (Group testGroup : user.getGroups()) {
+ if (testGroup.getId().equals(group.getId())) {
+ toRemove.add(testGroup);
+ }
+ }
+ for (Group groupToRemove : toRemove) {
+ user.getGroups().remove(groupToRemove);
+ }
+ }
+
+ public void deleteGroup(String token, Integer id) {
+ dao.deleteGroup(id);
+ }
+
+ public void deleteUser(String token, Integer id) {
+ dao.deleteUser(id);
+ }
+
+ public Group getGroup(String token, Integer id) {
+ return dao.getGroup(id);
+ }
+
+ public Group getGroup(String token, String name) {
+ return dao.getGroup(name);
+ }
+
+ public User getUser(String token, Integer id) {
+ return dao.getUser(id);
+ }
+
+ public User getUser(String token, String login) {
+ return dao.getUser(login);
+ }
+
+ public Group saveGroup(String token, String name, User owner) {
+ Group group = new Group();
+ group.setName(name);
+ group.setOwner(owner);
+ dao.saveGroup(group);
+ group = getGroup(token, group.getId());
+ return group;
+ }
+
+ public User saveUser(String token, String login, String mail) {
+ User user = new User();
+ user.setLogin(login);
+ user.setMail(mail);
+ String password = generatePassword();
+ sendMail(login, mail, password);
+ String passwordHash = computeHash(password);
+ user.setPasswordHash(passwordHash);
+ user.setAdmin(false);
+ user.setSuperAdmin(false);
+ dao.saveUser(user);
+ user = getUser(token, user.getId());
+ return user;
+ }
+
+ public Group updateGroup(String token, Group group) {
+ return dao.updateGroup(group);
+ }
+
+ public User updateUser(String token, User user) {
+ return dao.updateUser(user);
+ }
+
+ public User getLoggedUser(String token) {
+ User loggedUser;
+ loggedUser = dao.getLoggedUser(token);
+ return loggedUser;
+ }
+
+ private void checkSuperAdmin() {
+ if (dao.getUser("superadmin") == null) {
+ User user = new User();
+ user.setLogin("superadmin");
+ user.setMail("");
+ String password = "password";
+ String passwordHash = computeHash(password);
+ user.setPasswordHash(passwordHash);
+ user.setAdmin(true);
+ user.setSuperAdmin(true);
+ dao.saveUser(user);
+ }
+ }
+
+ public String loginUser(String login, String password) {
+ if (!superAdminCheck) {
+ checkSuperAdmin();
+ superAdminCheck = true;
+ }
+ String token = null;
+ User loggedUser = dao.loginUser(login, computeHash(password));
+ if (loggedUser != null) {
+ LoginAction loginAction = new LoginAction();
+ loginAction.setLoggedUser(loggedUser);
+ loginAction.setTime(new Date());
+ loginAction.setToken(UUID.randomUUID().toString());
+ dao.saveToken(loginAction);
+ token = loginAction.getToken();
+ }
+ return token;
+ }
+
+ public void closeSessionTimer(String token) {
+ // FIXME session length
+ TimerService timerService = sessionContext.getTimerService();
+ timerService.createTimer(10 * 60 * 1000, token);
+ }
+
+ @Timeout
+ public void timeoutHandler(Timer timer) {
+ String token = (String) timer.getInfo();
+ dao.deleteToken(token);
+ }
+
+ public User requestAccount(String login, String mail) {
+ User user = new User();
+ user.setLogin(login);
+ user.setMail(mail);
+ String password = generatePassword();
+ sendMail(login, mail, password);
+ String passwordHash = computeHash(password);
+ user.setPasswordHash(passwordHash);
+ dao.saveUser(user);
+ return user;
+ }
+
+ public void changePassword(String token, String login, String password) {
+ User user = getUser(token, login);
+ String passwordHash = computeHash(password);
+ user.setPasswordHash(passwordHash);
+ dao.saveUser(user);
+ }
+
+ public void resetPassword(String token, String login) {
+ User user = getUser(token, login);
+ String password = generatePassword();
+ sendMail(login, user.getMail(), password);
+ String passwordHash = computeHash(password);
+ user.setPasswordHash(passwordHash);
+ dao.saveUser(user);
+ }
+
+ public Group[] getGroups(String token) {
+ List<Group> groups = dao.getGroups();
+ Group[] result;
+ result = groups.toArray(new Group[groups.size()]);
+ return result;
+ }
+
+ public Group[] getGroupsOwnedBy(String token, User user) {
+ List<Group> list = dao.getGroupsOwnedBy(user);
+ return list.toArray(new Group[list.size()]);
+ }
+
+ public User[] getUsers(String token) {
+ return dao.getUsers().toArray(new User[dao.getUsers().size()]);
+ }
+
+ public User[] getUsersOfGroup(String token, Group group) {
+ List<User> usersOfGroup = dao.getUsersOfGroup(group);
+ return usersOfGroup.toArray(new User[usersOfGroup.size()]);
+ }
+
+ public void setUsersOfGroup(String token, Group group,
+ Integer[] usersInGroup) {
+ List<Integer> newUsers = new ArrayList<Integer>();
+ newUsers.addAll(Arrays.asList(usersInGroup));
+
+ List<Integer> usersToAdd = new ArrayList<Integer>();
+ List<Integer> usersToRemove = new ArrayList<Integer>();
+
+ List<User> users = dao.getUsersOfGroup(group);
+
+ List<Integer> currentUsers = new ArrayList<Integer>();
+ for (User user : users) {
+ currentUsers.add(user.getId());
+ }
+
+ for (Integer user : currentUsers) {
+ if (!newUsers.contains(user)) {
+ usersToRemove.add(user);
+ }
+ }
+ for (Integer user : newUsers) {
+ if (!currentUsers.contains(user)) {
+ usersToAdd.add(user);
+ }
+ }
+
+ for (Integer idUser : usersToAdd) {
+ User user = dao.getUser(idUser);
+ user.getGroups().add(group);
+ dao.updateUser(user);
+ }
+ for (Integer idUser : usersToRemove) {
+ User user = dao.getUser(idUser);
+ removeUserFromGroup(user, group);
+ dao.updateUser(user);
+ }
+ }
+
+ public void setGroupsOfUser(String token, User user, Integer[] groupsIds) {
+ User realUser = dao.getUser(user.getId());
+ realUser.getGroups().clear();
+ for (Integer groupsId : groupsIds) {
+ Group group = dao.getGroup(groupsId);
+ realUser.getGroups().add(group);
+ }
+ dao.updateUser(realUser);
+
+ }
+
+ public Group[] getGroupsOfUser(String token, User user) {
+ List<Group> list = dao.getGroupsOfUser(user);
+ return list.toArray(new Group[list.size()]);
+ }
+
+ public Group[] getGroupsOfGroup(String token, Group group) {
+ List<Group> groupsOfGroup = dao.getGroupsOfGroup(group);
+ return groupsOfGroup.toArray(new Group[groupsOfGroup.size()]);
+ }
+
+ public void setGroupsOfGroup(String token, Group group, Integer[] groupsIds) {
+ Group realGroup = dao.getGroup(group.getId());
+ realGroup.getGroups().clear();
+ for (Integer groupsId : groupsIds) {
+ Group groupOwned = dao.getGroup(groupsId);
+ realGroup.getGroups().add(groupOwned);
+ }
+ dao.updateGroup(realGroup);
+ }
+
+}
Copied: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockAuthenticationServiceImpl.java (from rev 506, trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/MockAuthenticationServiceImpl.java)
===================================================================
--- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockAuthenticationServiceImpl.java (rev 0)
+++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockAuthenticationServiceImpl.java 2008-01-24 20:37:52 UTC (rev 508)
@@ -0,0 +1,130 @@
+/*
+* ##% Copyright (C) 2008 Code Lutin, Tony Chemit, 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 fr.cemagref.simexplorer.is.security.entities.Group;
+import fr.cemagref.simexplorer.is.security.entities.User;
+
+
+public class MockAuthenticationServiceImpl implements AuthenticationService {
+
+
+ public String loginUser(String login, String password) {
+ return (String) checkImplemented();
+ }
+
+ public void closeSessionTimer(String token) {
+ checkImplemented();
+ }
+
+ public User requestAccount(String login, String mail) {
+ return (User) checkImplemented();
+ }
+
+ public User saveUser(String token, String login, String mail) {
+ return (User) checkImplemented();
+ }
+
+ public void resetPassword(String token, String login) {
+ checkImplemented();
+ }
+
+ public void changePassword(String token, String login, String password) {
+ checkImplemented();
+ }
+
+ public User getUser(String token, Integer id) {
+ return (User) checkImplemented();
+ }
+
+ public User getUser(String token, String login) {
+ return (User) checkImplemented();
+ }
+
+ public User updateUser(String token, User user) {
+ return (User) checkImplemented();
+ }
+
+ public void deleteUser(String token, Integer id) {
+ checkImplemented();
+ }
+
+ public User[] getUsers(String token) {
+ return (User[]) checkImplemented();
+ }
+
+ public User[] getUsersOfGroup(String token, Group group) {
+ return (User[]) checkImplemented();
+ }
+
+ public void setUsersOfGroup(String token, Group group, Integer[] usersInGroup) {
+ checkImplemented();
+ }
+
+ public void setGroupsOfGroup(String token, Group group, Integer[] groupsIds) {
+ checkImplemented();
+ }
+
+ public Group[] getGroupsOfUser(String token, User user) {
+ return (Group[]) checkImplemented();
+ }
+
+ public Group[] getGroupsOfGroup(String token, Group group) {
+ return (Group[]) checkImplemented();
+ }
+
+ public void setGroupsOfUser(String token, User user, Integer[] groupsIds) {
+ checkImplemented();
+ }
+
+ public Group saveGroup(String token, String name, User owner) {
+ return (Group) checkImplemented();
+ }
+
+ public Group getGroup(String token, Integer id) {
+ return (Group) checkImplemented();
+ }
+
+ public Group getGroup(String token, String name) {
+ return (Group) checkImplemented();
+ }
+
+ public Group updateGroup(String token, Group group) {
+ return (Group) checkImplemented();
+ }
+
+ public void deleteGroup(String token, Integer id) {
+ checkImplemented();
+ }
+
+ public Group[] getGroups(String token) {
+ return (Group[]) checkImplemented();
+ }
+
+ public Group[] getGroupsOwnedBy(String token, User user) {
+ return (Group[]) checkImplemented();
+ }
+
+ public User getLoggedUser(String token) {
+ return (User) checkImplemented();
+ }
+
+ private Object checkImplemented() {
+ throw new IllegalStateException("not implemented");
+ }
+}
\ No newline at end of file
Copied: trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/SecurityEqualsTestCase.java (from rev 506, trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityEqualsTestCase.java)
===================================================================
--- trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/SecurityEqualsTestCase.java (rev 0)
+++ trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/SecurityEqualsTestCase.java 2008-01-24 20:37:52 UTC (rev 508)
@@ -0,0 +1,61 @@
+/*
+* ##% 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.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.TestCase;
+import fr.cemagref.simexplorer.is.security.entities.User;
+
+public class SecurityEqualsTestCase extends TestCase {
+
+ AuthenticationService authenticationService = null;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ 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);
+ authenticationService = (AuthenticationService) context
+ .lookup("AuthenticationService");
+
+ }
+
+ public void testHashCode() {
+ String token = authenticationService.loginUser("superadmin", "password");
+ User[] users1 = authenticationService.getUsers(token);
+ User[] users2 = authenticationService.getUsers(token);
+ for (int i = 0; i < users1.length; i++) {
+ User user1 = users1[i];
+ User user2 = users2[i];
+ System.out.println("User " + i + " :");
+ System.out.println(user1.hashCode() + " " + user2.hashCode());
+ assertEquals(user1.hashCode(),user2.hashCode());
+ assertEquals(user1,user2);
+ }
+ }
+
+}
Copied: trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/SecurityTestCase.java (from rev 506, trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityTestCase.java)
===================================================================
--- trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/SecurityTestCase.java (rev 0)
+++ trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/SecurityTestCase.java 2008-01-24 20:37:52 UTC (rev 508)
@@ -0,0 +1,127 @@
+/*
+* ##% 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.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.TestCase;
+import fr.cemagref.simexplorer.is.security.entities.Group;
+import fr.cemagref.simexplorer.is.security.entities.User;
+
+public class SecurityTestCase extends TestCase {
+
+ AuthenticationService authenticationService = null;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ 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);
+ authenticationService = (AuthenticationService) context
+ .lookup("AuthenticationService");
+
+ }
+
+ public void testSecurityEntities() {
+ /*
+ User user = authenticationService.getUser("user3");
+ Group[] groups = authenticationService.getGroupsOfUser(user);
+ for (Group group : groups) {
+ System.out.println(group.getName());
+ }
+ */
+ String token = authenticationService
+ .loginUser("superadmin", "password");
+
+ Group everybody = authenticationService.saveGroup(token, "everybody",
+ authenticationService.getLoggedUser(token));
+
+ User me = authenticationService.getLoggedUser(token);
+ me.getGroups().add(everybody);
+ authenticationService.updateUser(token, me);
+
+ User[] simpleUsers = new User[20];
+ for (int i = 0; i < 20; i++) {
+ simpleUsers[i] = authenticationService.saveUser(token, "user" + i,
+ "landais+simtest at codelutin.com");
+ simpleUsers[i].setAdmin(false);
+ simpleUsers[i].setSuperAdmin(false);
+ simpleUsers[i].getGroups().add(everybody);
+ authenticationService.updateUser(token, simpleUsers[i]);
+ }
+
+ User[] adminUsers = new User[4];
+ Group[] groups = new Group[4];
+ for (int i = 0; i < 4; i++) {
+ adminUsers[i] = authenticationService.saveUser(token, "admin" + i,
+ "landais+simtest at codelutin.com");
+ adminUsers[i].setAdmin(true);
+ adminUsers[i].setSuperAdmin(false);
+ adminUsers[i].getGroups().add(everybody);
+ authenticationService.updateUser(token, adminUsers[i]);
+
+ groups[i] = authenticationService.saveGroup(token, "group" + i,
+ adminUsers[i]);
+ for (int j = i * 4; j < (i * 4 + 5); j++) {
+ simpleUsers[j].getGroups().add(groups[i]);
+ authenticationService.updateUser(token, simpleUsers[j]);
+ }
+ }
+
+ /*
+ User superAdminUser = authenticationService.saveUser(token,
+ "superadmin", "landais+simtest at codelutin.com");
+ superAdminUser.setAdmin(true);
+ superAdminUser.setSuperAdmin(true);
+ authenticationService.updateUser(token, superAdminUser);
+ */
+
+ /*
+ User[] users = new User[10];
+ Group[] groups = new Group[10];
+ for (int i = 0; i < 10; i++) {
+ users[i] = authenticationService.saveUser("user" + i,
+ "user1 at abc.fr");
+ users[i].setAdmin(true);
+ users[i].setSuperAdmin(true);
+ authenticationService.updateUser(users[i]);
+ groups[i] = authenticationService.saveGroup("group" + i, users[i]);
+ }
+
+ for (int i = 0; i < 10; i++) {
+ System.out.println(users[i].getId());
+ System.out.println(groups[i].getId());
+ }
+
+ String token = authenticationService.loginUser(users[4].getLogin(),
+ "hierugheriugh");
+ User userLogged = authenticationService.getLoggedUser(token);
+
+ assertEquals(userLogged.getLogin(), users[4].getLogin());
+ */
+ }
+
+}
1
0
24 Jan '08
Author: tchemit
Date: 2008-01-24 20:10:18 +0000 (Thu, 24 Jan 2008)
New Revision: 507
Modified:
trunk/simexplorer-is-service/pom.xml
Log:
ajout description du module
Modified: trunk/simexplorer-is-service/pom.xml
===================================================================
--- trunk/simexplorer-is-service/pom.xml 2008-01-24 18:01:24 UTC (rev 506)
+++ trunk/simexplorer-is-service/pom.xml 2008-01-24 20:10:18 UTC (rev 507)
@@ -7,7 +7,7 @@
<name>Service</name>
<version>0.0.1-SNAPSHOT</version>
- <description></description>
+ <description>services ejb de SimExplorer-IS</description>
<packaging>ejb</packaging>
<parent>
1
0
r506 - in trunk/simexplorer-is-web: . src/java/fr/cemagref/simexplorer/is/ui/web/pages src/java/fr/cemagref/simexplorer/is/ui/web/services src/main/webapp
by glandais@users.labs.libre-entreprise.org 24 Jan '08
by glandais@users.labs.libre-entreprise.org 24 Jan '08
24 Jan '08
Author: glandais
Date: 2008-01-24 18:01:24 +0000 (Thu, 24 Jan 2008)
New Revision: 506
Added:
trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDelete.java
trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementExport.java
trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementRights.java
trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ExceptionReport.java
trunk/simexplorer-is-web/src/main/webapp/ElementDelete.tml
trunk/simexplorer-is-web/src/main/webapp/ElementExport.tml
trunk/simexplorer-is-web/src/main/webapp/ElementRights.tml
trunk/simexplorer-is-web/src/main/webapp/ExceptionReport.tml
Modified:
trunk/simexplorer-is-web/pom.xml
trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDetail.java
trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementHistory.java
trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/RemoteService.java
Log:
Delete, export, rights, exception pages
Modified: trunk/simexplorer-is-web/pom.xml
===================================================================
--- trunk/simexplorer-is-web/pom.xml 2008-01-24 18:00:48 UTC (rev 505)
+++ trunk/simexplorer-is-web/pom.xml 2008-01-24 18:01:24 UTC (rev 506)
@@ -75,6 +75,7 @@
<groupId>jboss</groupId>
<artifactId>jbossall-client</artifactId>
<version>4.2.2.GA</version>
+ <scope>provided</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
Added: trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDelete.java
===================================================================
--- trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDelete.java (rev 0)
+++ trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDelete.java 2008-01-24 18:01:24 UTC (rev 506)
@@ -0,0 +1,63 @@
+/*
+* ##% 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.ui.web.pages;
+
+import org.apache.tapestry.ComponentResources;
+import org.apache.tapestry.annotations.Persist;
+import org.apache.tapestry.ioc.annotations.Inject;
+
+import fr.cemagref.simexplorer.is.entities.data.LoggableElement;
+import fr.cemagref.simexplorer.is.ui.web.pages.security.UserPage;
+import fr.cemagref.simexplorer.is.ui.web.services.RemoteStorageService;
+
+public class ElementDelete extends UserPage {
+
+ @Inject
+ private ComponentResources resources;
+
+ @Persist
+ private LoggableElement element;
+
+ /**
+ * Prepare page
+ *
+ * @param uuid
+ * Id of element to display
+ * @param version
+ * Version of element to display
+ * @throws Exception
+ */
+ public void setup(String uuid, String version) throws Exception {
+ element = RemoteStorageService.getStorageService().getElement(
+ getToken(), uuid, version);
+ }
+
+// public Object onDelete() throws Exception {
+// RemoteStorageService.getStorageService().deleteElement(getToken(),
+// element.getMetaData().getUuid(),
+// element.getMetaData().getVersion());
+// return null;
+// }
+//
+// public Object onDeleteAll() throws Exception {
+// RemoteStorageService.getStorageService().deleteElement(getToken(),
+// element.getMetaData().getUuid());
+// return null;
+// }
+
+}
Modified: trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDetail.java
===================================================================
--- trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDetail.java 2008-01-24 18:00:48 UTC (rev 505)
+++ trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDetail.java 2008-01-24 18:01:24 UTC (rev 506)
@@ -62,8 +62,17 @@
private LoggableElement element;
@InjectPage
+ private ElementExport elementExport;
+
+ @InjectPage
private ElementHistory elementHistory;
-
+
+ @InjectPage
+ private ElementDelete elementDelete;
+
+ @InjectPage
+ private ElementRights elementRights;
+
/**
* Prepare page
*
@@ -120,7 +129,9 @@
StringTokenizer st = new StringTokenizer(context, ",");
String uuid = st.nextToken();
String version = st.nextToken();
- return exportElement(uuid, version);
+ elementExport.setup(uuid, version);
+ // exportElement(uuid, version)
+ return elementExport;
}
public Object onHistory(String context) throws Exception {
@@ -131,11 +142,20 @@
return elementHistory;
}
+ public Object onDelete(String context) throws Exception {
+ StringTokenizer st = new StringTokenizer(context, ",");
+ String uuid = st.nextToken();
+ String version = st.nextToken();
+ elementDelete.setup(uuid, version);
+ return elementDelete;
+ }
+
public Object onRights(String context) throws Exception {
StringTokenizer st = new StringTokenizer(context, ",");
String uuid = st.nextToken();
String version = st.nextToken();
- return null;
+ elementRights.setup(uuid, version);
+ return elementRights;
}
private Object downloadElement(String uuid, String version)
@@ -196,8 +216,8 @@
sb.append(generateString(anAction, anAction, element));
}
sb.append("<br>");
+ // TODO add security
sb.append(generateString("rights", "rights", element));
- // TODO add security
res = sb.substring(4);
return res;
@@ -239,7 +259,7 @@
node.setColumns(generateStringArray("Application exploration", element
.getMetaData().getName(), element.getMetaData().getVersion()
- .toString(), element, "export", "history"));
+ .toString(), element, "export", "history", "delete"));
List<TreeNode> children = new ArrayList<TreeNode>();
TreeNode node1 = new TreeNode();
@@ -278,7 +298,7 @@
explorationDataNode.setColumns(generateStringArray("Exploration data",
explorationData.getMetaData().getName(), explorationData
.getMetaData().getVersion().toString(),
- explorationData, "history"));
+ explorationData, "history", "delete"));
List<TreeNode> children = new ArrayList<TreeNode>();
@@ -343,7 +363,7 @@
componentNode.setColumns(generateStringArray("Component", component
.getMetaData().getName(), component.getMetaData().getVersion()
- .toString(), component, "history"));
+ .toString(), component, "history", "delete"));
List<TreeNode> children = new ArrayList<TreeNode>();
Added: trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementExport.java
===================================================================
--- trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementExport.java (rev 0)
+++ trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementExport.java 2008-01-24 18:01:24 UTC (rev 506)
@@ -0,0 +1,50 @@
+/*
+* ##% 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.ui.web.pages;
+
+import org.apache.tapestry.ComponentResources;
+import org.apache.tapestry.annotations.Persist;
+import org.apache.tapestry.ioc.annotations.Inject;
+
+import fr.cemagref.simexplorer.is.entities.data.LoggableElement;
+import fr.cemagref.simexplorer.is.ui.web.pages.security.UserPage;
+import fr.cemagref.simexplorer.is.ui.web.services.RemoteStorageService;
+
+public class ElementExport extends UserPage {
+
+ @Inject
+ private ComponentResources resources;
+
+ @Persist
+ private LoggableElement element;
+
+ /**
+ * Prepare page
+ *
+ * @param uuid
+ * Id of element to display
+ * @param version
+ * Version of element to display
+ * @throws Exception
+ */
+ public void setup(String uuid, String version) throws Exception {
+ element = RemoteStorageService.getStorageService().getElement(
+ getToken(), uuid, version);
+ }
+
+}
Modified: trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementHistory.java
===================================================================
--- trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementHistory.java 2008-01-24 18:00:48 UTC (rev 505)
+++ trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementHistory.java 2008-01-24 18:01:24 UTC (rev 506)
@@ -57,9 +57,8 @@
public List<String> getHeaders() {
List<String> result = new ArrayList<String>();
result.add("Version");
- result.add("Author");
- result.add("Name");
result.add("Description");
+ result.add("Date");
return result;
}
@@ -73,7 +72,7 @@
Arrays.sort(versions, new MetadataVersionComparator());
TreeNode rootNode = new TreeNode();
rootNode.setType(TreeNode.TYPE_FOLDER);
- rootNode.setColumns(generateStringArray("History", ""));
+ rootNode.setColumns(generateStringArray("History"));
rootNode.setObject(new Version(""));
rootNode.setChildren(new ArrayList<TreeNode>());
for (MetaDataEntity mde : versions) {
@@ -123,7 +122,9 @@
private TreeNode generateLeaf(MetaDataEntity mde) {
TreeNode node = new TreeNode();
- node.setColumns(generateStringArray(mde.getVersion().toString()));
+ // FIXME date tostring
+ node.setColumns(generateStringArray(mde.getVersion().toString(), mde
+ .getDescription(), mde.getCreationDate().toString()));
node.setObject(mde.getVersion());
node.setType(TreeNode.TYPE_DOCUMENT);
return node;
Added: trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementRights.java
===================================================================
--- trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementRights.java (rev 0)
+++ trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementRights.java 2008-01-24 18:01:24 UTC (rev 506)
@@ -0,0 +1,50 @@
+/*
+* ##% 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.ui.web.pages;
+
+import org.apache.tapestry.ComponentResources;
+import org.apache.tapestry.annotations.Persist;
+import org.apache.tapestry.ioc.annotations.Inject;
+
+import fr.cemagref.simexplorer.is.entities.data.LoggableElement;
+import fr.cemagref.simexplorer.is.ui.web.pages.security.UserPage;
+import fr.cemagref.simexplorer.is.ui.web.services.RemoteStorageService;
+
+public class ElementRights extends UserPage {
+
+ @Inject
+ private ComponentResources resources;
+
+ @Persist
+ private LoggableElement element;
+
+ /**
+ * Prepare page
+ *
+ * @param uuid
+ * Id of element to display
+ * @param version
+ * Version of element to display
+ * @throws Exception
+ */
+ public void setup(String uuid, String version) throws Exception {
+ element = RemoteStorageService.getStorageService().getElement(
+ getToken(), uuid, version);
+ }
+
+}
Added: trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ExceptionReport.java
===================================================================
--- trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ExceptionReport.java (rev 0)
+++ trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ExceptionReport.java 2008-01-24 18:01:24 UTC (rev 506)
@@ -0,0 +1,44 @@
+/*
+* ##% 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.ui.web.pages;
+
+import java.io.FileNotFoundException;
+
+import org.apache.tapestry.services.ExceptionReporter;
+
+public class ExceptionReport extends
+ org.apache.tapestry.corelib.pages.ExceptionReport implements
+ ExceptionReporter {
+
+ private boolean unknown;
+
+ @Override
+ public void reportException(Throwable exception) {
+ if (exception instanceof FileNotFoundException) {
+ unknown = false;
+ } else {
+ unknown = true;
+ super.reportException(exception);
+ }
+ }
+
+ public boolean isUnknown() {
+ return unknown;
+ }
+
+}
Modified: trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/RemoteService.java
===================================================================
--- trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/RemoteService.java 2008-01-24 18:00:48 UTC (rev 505)
+++ trunk/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/RemoteService.java 2008-01-24 18:01:24 UTC (rev 506)
@@ -39,7 +39,12 @@
properties
.put("java.naming.factory.url.pkgs", "org.jnp.interfaces");
- Context context = new InitialContext(properties);
+ Context context = null;
+ try {
+ context = new InitialContext(properties);
+ } catch (Exception e) {
+ context = new InitialContext();
+ }
services.put(serviceName, context.lookup(serviceName));
}
return services.get(serviceName);
Added: trunk/simexplorer-is-web/src/main/webapp/ElementDelete.tml
===================================================================
--- trunk/simexplorer-is-web/src/main/webapp/ElementDelete.tml (rev 0)
+++ trunk/simexplorer-is-web/src/main/webapp/ElementDelete.tml 2008-01-24 18:01:24 UTC (rev 506)
@@ -0,0 +1,4 @@
+<t:layout xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"
+ title="message:windowtitle">
+
+</t:layout>
Added: trunk/simexplorer-is-web/src/main/webapp/ElementExport.tml
===================================================================
--- trunk/simexplorer-is-web/src/main/webapp/ElementExport.tml (rev 0)
+++ trunk/simexplorer-is-web/src/main/webapp/ElementExport.tml 2008-01-24 18:01:24 UTC (rev 506)
@@ -0,0 +1,4 @@
+<t:layout xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"
+ title="message:windowtitle">
+
+</t:layout>
Added: trunk/simexplorer-is-web/src/main/webapp/ElementRights.tml
===================================================================
--- trunk/simexplorer-is-web/src/main/webapp/ElementRights.tml (rev 0)
+++ trunk/simexplorer-is-web/src/main/webapp/ElementRights.tml 2008-01-24 18:01:24 UTC (rev 506)
@@ -0,0 +1,4 @@
+<t:layout xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"
+ title="message:windowtitle">
+
+</t:layout>
Added: trunk/simexplorer-is-web/src/main/webapp/ExceptionReport.tml
===================================================================
--- trunk/simexplorer-is-web/src/main/webapp/ExceptionReport.tml (rev 0)
+++ trunk/simexplorer-is-web/src/main/webapp/ExceptionReport.tml 2008-01-24 18:01:24 UTC (rev 506)
@@ -0,0 +1,50 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+<head>
+<title>Application Exception</title>
+</head>
+<body>
+<h1 class="t-exception-report">An unexpected application exception
+has occurred.</h1>
+
+
+<div class="t-exception-report">
+<ul>
+ <t:loop source="stack" value="info">
+ <li><span class="t-exception-class-name">${info.className}</span>
+
+ <t:if test="info.message">
+ <div class="t-exception-message">${info.message}</div>
+ </t:if> <t:if test="showPropertyList">
+ <dl>
+ <t:loop source="info.propertyNames" value="propertyName">
+ <dt>${propertyName}</dt>
+ <dd><t:renderobject object="propertyValue" /></dd>
+ </t:loop>
+ <t:if test="info.stackTrace">
+ <dt>Stack trace</dt>
+ <dd>
+ <ul class="t-stack-trace">
+ <t:loop source="info.stackTrace" value="frame">
+ <li>${frame}</li>
+ </t:loop>
+ </ul>
+ </dd>
+ </t:if>
+ </dl>
+ </t:if></li>
+ </t:loop>
+</ul>
+</div>
+<div class="t-env-data">
+<h2>Request</h2>
+<t:renderobject object="request" /> <t:if test="hasSession">
+ <h2>Session</h2>
+ <dl>
+ <t:loop source="session.attributeNames" value="attributeName">
+ <dt>${attributeName}</dt>
+ <dd><t:renderobject object="attributeValue" /></dd>
+ </t:loop>
+ </dl>
+</t:if></div>
+</body>
+</html>
1
0
r505 - in trunk: simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine simexplorer-is-sto
by glandais@users.labs.libre-entreprise.org 24 Jan '08
by glandais@users.labs.libre-entreprise.org 24 Jan '08
24 Jan '08
Author: glandais
Date: 2008-01-24 18:00:48 +0000 (Thu, 24 Jan 2008)
New Revision: 505
Added:
trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/StorageException.java
Modified:
trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java
trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java
trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/FileSystemAttachmentHandler.java
trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java
trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java
trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java
trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java
trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/util/Config.java
Log:
StorageException
Modified: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java
===================================================================
--- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java 2008-01-24 18:00:06 UTC (rev 504)
+++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java 2008-01-24 18:00:48 UTC (rev 505)
@@ -27,6 +27,7 @@
import fr.cemagref.simexplorer.is.entities.metadata.Version;
import fr.cemagref.simexplorer.is.security.credentials.CredentialManager;
import fr.cemagref.simexplorer.is.security.entities.Permission;
+import fr.cemagref.simexplorer.is.storage.StorageException;
public class StorageEngineSecuImpl extends StorageEngineImpl {
@@ -35,27 +36,32 @@
@Override
public void deleteElement(String token, String uuid, Version version)
- throws Exception {
+ throws StorageException {
Permission permission = credentialManager.getPermission(token, uuid);
// TODO check candelete = canadmin
if (permission != null && permission.isCanAdmin()) {
super.deleteElement(token, uuid, version);
+ } else {
+ throw new StorageException("Permission denied");
}
}
@Override
- public void deleteElements(String token, String uuid) throws Exception {
+ public void deleteElements(String token, String uuid)
+ throws StorageException {
Permission permission = credentialManager.getPermission(token, uuid);
// TODO check candelete = canadmin
if (permission != null && permission.isCanAdmin()) {
super.deleteElements(token, uuid);
+ } else {
+ throw new StorageException("Permission denied");
}
}
@Override
public MetaDataEntity[] findElementsByType(String token, String type,
boolean onlyLatest, int start, int count, int dateOrder)
- throws Exception {
+ throws StorageException {
MetaDataEntity[] list = super.findElementsByType(token, type,
onlyLatest, start, count, dateOrder);
// TODO how to filter without losing pagination?
@@ -64,7 +70,7 @@
@Override
public int findElementsByTypeCount(String token, String type,
- boolean onlyLatest) throws Exception {
+ boolean onlyLatest) throws StorageException {
// TODO how to filter without losing pagination?
return super.findElementsByTypeCount(token, type, onlyLatest);
}
@@ -72,7 +78,7 @@
@Override
public MetaDataEntity[] findFullText(String token, String query,
boolean onlyLatest, int indexStart, int count, int dateOrder)
- throws Exception {
+ throws StorageException {
// TODO how to filter without losing pagination?
return super.findFullText(token, query, onlyLatest, indexStart, count,
dateOrder);
@@ -80,64 +86,74 @@
@Override
public int findFullTextCount(String token, String query, boolean onlyLatest)
- throws Exception {
+ throws StorageException {
// TODO how to filter without losing pagination?
return super.findFullTextCount(token, query, onlyLatest);
}
@Override
public MetaDataEntity getMetadata(String token, String uuid, Version version)
- throws Exception {
+ throws StorageException {
MetaDataEntity mde = null;
Permission permission = credentialManager.getPermission(token, uuid);
if (permission.isCanRead()) {
mde = super.getMetadata(token, uuid, version);
+ } else {
+ throw new StorageException("Permission denied");
}
return mde;
}
@Override
public MetaDataEntity getMetadata(String token, String uuid)
- throws Exception {
+ throws StorageException {
MetaDataEntity mde = null;
Permission permission = credentialManager.getPermission(token, uuid);
if (permission.isCanRead()) {
mde = super.getMetadata(token, uuid);
+ } else {
+ throw new StorageException("Permission denied");
}
return mde;
}
@Override
public List<Version> getVersions(String token, String uuid)
- throws Exception {
+ throws StorageException {
List<Version> versions = null;
Permission permission = credentialManager.getPermission(token, uuid);
if (permission.isCanRead()) {
versions = super.getVersions(token, uuid);
+ } else {
+ throw new StorageException("Permission denied");
}
return versions;
}
@Override
public InputStream retrieveData(String token, MetaDataEntity entity,
- String field) throws Exception {
+ String field) throws StorageException {
InputStream stream = null;
Permission permission = credentialManager.getPermission(token, entity
.getUuid());
if (permission.isCanRead()) {
stream = super.retrieveData(token, entity, field);
+ } else {
+ throw new StorageException("Permission denied");
}
return stream;
}
@Override
public void saveElement(String token, MetaDataEntity element,
- Map<String, InputStream> attachments) throws Exception {
+ Map<String, InputStream> attachments) throws StorageException {
Permission permission = credentialManager.getPermission(token, element
.getUuid());
if (permission.isCanWrite()) {
super.saveElement(token, element, attachments);
credentialManager.saveElement(token, element.getUuid());
+ } else {
+ throw new StorageException("Permission denied");
}
}
Added: trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/StorageException.java
===================================================================
--- trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/StorageException.java (rev 0)
+++ trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/StorageException.java 2008-01-24 18:00:48 UTC (rev 505)
@@ -0,0 +1,40 @@
+/*
+* ##% 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.storage;
+
+public class StorageException extends Exception {
+
+ private static final long serialVersionUID = 4405447107690074844L;
+
+ public StorageException() {
+ super();
+ }
+
+ public StorageException(String message) {
+ super(message);
+ }
+
+ public StorageException(Throwable cause) {
+ super(cause);
+ }
+
+ public StorageException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
Modified: trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java
===================================================================
--- trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java 2008-01-24 18:00:06 UTC (rev 504)
+++ trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java 2008-01-24 18:00:48 UTC (rev 505)
@@ -20,6 +20,7 @@
import java.io.InputStream;
import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity;
+import fr.cemagref.simexplorer.is.storage.StorageException;
/**
* Store, retrieve and delete content
@@ -38,10 +39,10 @@
* Unique field for content
* @param is
* Content
- * @throws Exception
+ * @throws StorageException
*/
public abstract void storeData(MetaDataEntity entity, String field,
- InputStream is) throws Exception;
+ InputStream is) throws StorageException;
/**
* Retrieve content
@@ -51,10 +52,10 @@
* @param field
* Unique field for content
* @return Content
- * @throws Exception
+ * @throws StorageException
*/
public abstract InputStream retrieveData(MetaDataEntity entity, String field)
- throws Exception;
+ throws StorageException;
/**
* Delete content
@@ -63,9 +64,9 @@
* DataEntity related to content
* @param field
* Unique field for content
- * @throws Exception
+ * @throws StorageException
*/
public abstract void deleteData(MetaDataEntity entity, String field)
- throws Exception;
+ throws StorageException;
}
\ No newline at end of file
Modified: trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/FileSystemAttachmentHandler.java
===================================================================
--- trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/FileSystemAttachmentHandler.java 2008-01-24 18:00:06 UTC (rev 504)
+++ trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/FileSystemAttachmentHandler.java 2008-01-24 18:00:48 UTC (rev 505)
@@ -21,10 +21,13 @@
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.InputStream;
import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity;
+import fr.cemagref.simexplorer.is.storage.StorageException;
import fr.cemagref.simexplorer.is.storage.util.Config;
/**
@@ -49,7 +52,6 @@
* @param field
* Unique field for content
* @return Instance of file
- * @throws Exception
*/
private File getFile(MetaDataEntity entity, String field) {
String resultPath = baseFolder;
@@ -77,37 +79,48 @@
@Override
public InputStream retrieveData(MetaDataEntity entity, String field)
- throws Exception {
+ throws StorageException {
// Simple stream on file
- FileInputStream fis = new FileInputStream(getFile(entity, field));
+ FileInputStream fis = null;
+ try {
+ fis = new FileInputStream(getFile(entity, field));
+ } catch (FileNotFoundException e) {
+ throw new StorageException(e);
+ }
return fis;
}
@Override
public void storeData(MetaDataEntity entity, String field, InputStream is)
- throws Exception {
+ throws StorageException {
// Simple stream on file
- FileOutputStream fos = new FileOutputStream(getFile(entity, field));
+ try {
+ FileOutputStream fos = new FileOutputStream(getFile(entity, field));
- // Buffer copy stream to stream
- BufferedInputStream bin = new BufferedInputStream(is);
- BufferedOutputStream bout = new BufferedOutputStream(fos);
+ // Buffer copy stream to stream
+ BufferedInputStream bin = new BufferedInputStream(is);
+ BufferedOutputStream bout = new BufferedOutputStream(fos);
- while (true) {
- int datum = bin.read();
- if (datum == -1)
- break;
- bout.write(datum);
+ while (true) {
+ int datum = bin.read();
+ if (datum == -1)
+ break;
+ bout.write(datum);
+ }
+ bout.flush();
+
+ // Close file
+ fos.close();
+ } catch (FileNotFoundException e) {
+ throw new StorageException(e);
+ } catch (IOException e) {
+ throw new StorageException(e);
}
- bout.flush();
-
- // Close file
- fos.close();
}
@Override
public void deleteData(MetaDataEntity entity, String field)
- throws Exception {
+ throws StorageException {
// Simple delete on file
getFile(entity, field).delete();
}
Modified: trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java
===================================================================
--- trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java 2008-01-24 18:00:06 UTC (rev 504)
+++ trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java 2008-01-24 18:00:48 UTC (rev 505)
@@ -25,6 +25,7 @@
import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity;
import fr.cemagref.simexplorer.is.entities.metadata.Version;
+import fr.cemagref.simexplorer.is.storage.StorageException;
/**
* Interface of a database able to manage metadata elements
@@ -37,9 +38,9 @@
/**
* Open database connection
*
- * @throws Exception
+ * @throws StorageException
*/
- public void open() throws Exception {
+ public void open() throws StorageException {
open(false);
}
@@ -48,23 +49,23 @@
*
* @param create
* Create database
- * @throws Exception
+ * @throws StorageException
*/
- public abstract void open(boolean create) throws Exception;
+ public abstract void open(boolean create) throws StorageException;
/**
* Close database connection
*
- * @throws Exception
+ * @throws StorageException
*/
- public abstract void close() throws Exception;
+ public abstract void close() throws StorageException;
/**
* Commit pending modifications
*
- * @throws Exception
+ * @throws StorageException
*/
- public abstract void commit() throws Exception;
+ public abstract void commit() throws StorageException;
// Create / Update
@@ -74,10 +75,11 @@
*
* @param element
* Element to insert
- * @throws Exception
+ * @param readers
+ * @throws StorageException
*/
public abstract void insertElement(MetaDataEntity element,
- List<Reader> readers) throws Exception;
+ List<Reader> readers) throws StorageException;
// Read
@@ -89,10 +91,10 @@
* @param version
* version
* @return Fund element, null if not fund
- * @throws Exception
+ * @throws StorageException
*/
public abstract MetaDataEntity getElement(String uuid, Version version)
- throws Exception;
+ throws StorageException;
/**
* Get all version of an element thanks to its id <br>
@@ -101,20 +103,21 @@
* @param uuid
* Id
* @return Versions
- * @throws Exception
+ * @throws StorageException
*/
- public abstract List<Version> getVersions(String uuid) throws Exception;
+ public abstract List<Version> getVersions(String uuid) throws StorageException;
/**
* Retrieve all elements by id Empty list if no element with this id
*
* @param uuid
* Id
+ * @param onlyLatest
* @return Element list
- * @throws Exception
+ * @throws StorageException
*/
public abstract Set<MetaDataEntity> findElementsById(String uuid,
- boolean onlyLatest) throws Exception;
+ boolean onlyLatest) throws StorageException;
/**
* Retrieve elements with specific properties<br>
@@ -123,10 +126,10 @@
* @param properties
* Matching properties needed
* @return Element list
- * @throws Exception
+ * @throws StorageException
*/
public Set<MetaDataEntity> findElementsByProperties(
- Map<String, String> properties) throws Exception {
+ Map<String, String> properties) throws StorageException {
return findElementsByProperties(properties, 0, -1, 0);
}
@@ -140,12 +143,13 @@
* Index of first element returned
* @param count
* Number of elements to return
+ * @param dateOrder
* @return Element list
- * @throws Exception
+ * @throws StorageException
*/
public abstract Set<MetaDataEntity> findElementsByProperties(
Map<String, String> properties, int start, int count, int dateOrder)
- throws Exception;
+ throws StorageException;
/**
* Retrieve element count specific properties
@@ -153,10 +157,10 @@
* @param properties
* Matching properties needed
* @return Number of elements fund
- * @throws Exception
+ * @throws StorageException
*/
public abstract int findElementsByPropertiesCount(
- Map<String, String> properties) throws Exception;
+ Map<String, String> properties) throws StorageException;
/**
* Prepare properties for query
@@ -191,11 +195,11 @@
* @param dateOrder
* Sorting
* @return Element list
- * @throws Exception
+ * @throws StorageException
*/
public Set<MetaDataEntity> findElementsByType(String type,
boolean onlyLatest, int start, int count, int dateOrder)
- throws Exception {
+ throws StorageException {
return findElementsByProperties(getPropertiesByType(type, onlyLatest),
start, count, dateOrder);
}
@@ -208,10 +212,10 @@
* @param onlyLatest
* Only latest elements
* @return Number of elements
- * @throws Exception
+ * @throws StorageException
*/
public int findElementsByTypeCount(String type, boolean onlyLatest)
- throws Exception {
+ throws StorageException {
return findElementsByPropertiesCount(getPropertiesByType(type,
onlyLatest));
}
@@ -222,27 +226,30 @@
*
* @param queryText
* Searched text
+ * @param onlyLatest
* @param start
* Index of first element returned
* @param count
* Number of elements to return
+ * @param dateOrder
* @return Element list
- * @throws Exception
+ * @throws StorageException
*/
public abstract Set<MetaDataEntity> findElementsByContentSearch(
String queryText, boolean onlyLatest, int start, int count,
- int dateOrder) throws Exception;
+ int dateOrder) throws StorageException;
/**
* Retrieve element count with specific content
*
* @param queryText
* Searched text
+ * @param onlyLatest
* @return Number of elements fund
- * @throws Exception
+ * @throws StorageException
*/
public abstract int findElementsByContentSearchCount(String queryText,
- boolean onlyLatest) throws Exception;
+ boolean onlyLatest) throws StorageException;
// Delete
@@ -251,9 +258,9 @@
*
* @param element
* Element to delete
- * @throws Exception
+ * @throws StorageException
*/
- public void deleteElement(MetaDataEntity element) throws Exception {
+ public void deleteElement(MetaDataEntity element) throws StorageException {
deleteElement(element.getUuid(), element.getVersion());
}
@@ -264,9 +271,9 @@
* Id
* @param version
* Version
- * @throws Exception
+ * @throws StorageException
*/
public abstract void deleteElement(String uuid, Version version)
- throws Exception;
+ throws StorageException;
}
Modified: trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java
===================================================================
--- trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2008-01-24 18:00:06 UTC (rev 504)
+++ trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2008-01-24 18:00:48 UTC (rev 505)
@@ -57,6 +57,7 @@
import fr.cemagref.simexplorer.is.contenttype.ContentTypeFactory;
import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity;
import fr.cemagref.simexplorer.is.entities.metadata.Version;
+import fr.cemagref.simexplorer.is.storage.StorageException;
import fr.cemagref.simexplorer.is.storage.database.Database;
import fr.cemagref.simexplorer.is.storage.util.Config;
@@ -114,15 +115,14 @@
}
return searcherPool;
}
-
+
/**
* Retrieve searcher for a new query
*
* @return Searcher
- * @throws CorruptIndexException
* @throws IOException
*/
- private Searcher getSearcher() throws CorruptIndexException, IOException {
+ private Searcher getSearcher() throws IOException {
synchronized (searcherSynchronizer) {
// If cached searcher is null (as after an index write)
if (cachedSearcher == null) {
@@ -165,7 +165,7 @@
}
@Override
- public void open(boolean create) throws Exception {
+ public void open(boolean create) throws StorageException {
if (writer == null) {
// Create an analyzer
Analyzer analyzer = new SimpleAnalyzer();
@@ -177,43 +177,49 @@
resultFolder.mkdirs();
}
- // Base directory index
- directory = FSDirectory.getDirectory(indexDir, lockFactory);
+ try {
+ // Base directory index
+ directory = FSDirectory.getDirectory(indexDir, lockFactory);
+ // force creation if index doesn't exist
+ boolean realCreate = create;
+ if (!IndexReader.indexExists(directory)) {
+ realCreate = true;
+ }
- // force creation if index doesn't exist
- boolean realCreate = create;
- if (!IndexReader.indexExists(directory)) {
- realCreate = true;
- }
+ // Instanciate unique writer
+ writer = new IndexWriter(directory, true, analyzer, realCreate);
- // Instanciate unique writer
- writer = new IndexWriter(directory, true, analyzer, realCreate);
-
- // Write index on create
- if (realCreate) {
- commit();
+ // Write index on create
+ if (realCreate) {
+ commit();
+ }
+ } catch (IOException e) {
+ throw new StorageException(e);
}
}
}
@Override
- public void close() throws Exception {
- synchronized (writerSynchronizer) {
- // Close writer and invalidate reader
- writer.close();
- writer = null;
+ public void close() throws StorageException {
+ try {
+ synchronized (writerSynchronizer) {
+ // Close writer and invalidate reader
+ writer.close();
+ writer = null;
+ }
+ resetReader();
+ } catch (IOException e) {
+ throw new StorageException(e);
}
- resetReader();
searcherPool = null;
}
/**
* Push commit to db
*
- * @throws CorruptIndexException
* @throws IOException
*/
- private void synchedCommit() throws CorruptIndexException, IOException {
+ private void synchedCommit() throws IOException {
synchronized (writerSynchronizer) {
// Flush in ram data
writer.flush();
@@ -221,7 +227,8 @@
Date now = new Date();
long elapsed = now.getTime() - lastOptimize.getTime();
// One optimize per period, if readers are closed
- if (elapsed > optimizePeriod * 1000 && getSearcherPool().allClosed()) {
+ if (elapsed > optimizePeriod * 1000
+ && getSearcherPool().allClosed()) {
writer.optimize();
lastOptimize = new Date();
}
@@ -231,14 +238,18 @@
}
@Override
- public void commit() throws Exception {
- // Allows concurent access
- synchedCommit();
+ public void commit() throws StorageException {
+ try {
+ // Allows concurent access
+ synchedCommit();
+ } catch (IOException e) {
+ throw new StorageException(e);
+ }
}
@Override
public void insertElement(MetaDataEntity element, List<Reader> readers)
- throws Exception {
+ throws StorageException {
// Save element to a Lucene document
Document document = saveLuceneElement(element, readers);
@@ -251,28 +262,36 @@
deleteElement(element);
}
- synchronized (writerSynchronizer) {
- // add document to index
- writer.addDocument(document);
+ try {
+ synchronized (writerSynchronizer) {
+ // add document to index
+ writer.addDocument(document);
+ }
+ } catch (IOException e) {
+ throw new StorageException(e);
}
}
@Override
public MetaDataEntity getElement(String uuid, Version version)
- throws Exception {
+ throws StorageException {
MetaDataEntity result = null;
- // Get current searcher instance
- Searcher searcher = getSearcher();
try {
- Hits hits = getHitsByIdVersion(uuid, version, searcher);
- if (hits != null && hits.length() != 0) {
- // convert first document to element
- result = loadLuceneElement(hits.doc(0));
+ // Get current searcher instance
+ Searcher searcher = getSearcher();
+ try {
+ Hits hits = getHitsByIdVersion(uuid, version, searcher);
+ if (hits != null && hits.length() != 0) {
+ // convert first document to element
+ result = loadLuceneElement(hits.doc(0));
+ }
+ } finally {
+ // Release searcher instance
+ releaseSearcher(searcher);
}
- } finally {
- // Release searcher instance
- releaseSearcher(searcher);
+ } catch (Exception e) {
+ throw new StorageException(e);
}
return result;
@@ -298,28 +317,33 @@
}
@Override
- public List<Version> getVersions(String uuid) throws Exception {
+ public List<Version> getVersions(String uuid) throws StorageException {
// Retrieve all document corresponding to id
Map<String, String> properties = new HashMap<String, String>();
properties.put(KEY_UUID, uuid);
List<Version> versions = null;
- // Get current searcher instance
- Searcher searcher = getSearcher();
+
try {
- Hits hits = findHits(properties, searcher, SORT_DATE_NONE);
+ // Get current searcher instance
+ Searcher searcher = getSearcher();
+ try {
+ Hits hits = findHits(properties, searcher, SORT_DATE_NONE);
- // Add all versions to a list
- versions = new ArrayList<Version>();
- if (hits != null) {
- for (int i = 0; i < hits.length(); i++) {
- Document doc = hits.doc(i);
- versions.add(new Version(doc.get(KEY_VERSION)));
+ // Add all versions to a list
+ versions = new ArrayList<Version>();
+ if (hits != null) {
+ for (int i = 0; i < hits.length(); i++) {
+ Document doc = hits.doc(i);
+ versions.add(new Version(doc.get(KEY_VERSION)));
+ }
}
+ } finally {
+ // Release searcher instance
+ releaseSearcher(searcher);
}
- } finally {
- // Release searcher instance
- releaseSearcher(searcher);
+ } catch (Exception e) {
+ throw new StorageException(e);
}
return versions;
@@ -327,7 +351,7 @@
@Override
public Set<MetaDataEntity> findElementsById(String uuid, boolean onlyLatest)
- throws Exception {
+ throws StorageException {
// Create hash map with id
Map<String, String> properties = new HashMap<String, String>();
properties.put(KEY_UUID, uuid);
@@ -337,14 +361,18 @@
Set<MetaDataEntity> result = null;
- // Get current searcher instance
- Searcher searcher = getSearcher();
try {
- Hits hits = findHits(properties, searcher, SORT_DATE_NONE);
- result = convertHitsToElements(hits, 0, -1);
- } finally {
- // Release searcher instance
- releaseSearcher(searcher);
+ // Get current searcher instance
+ Searcher searcher = getSearcher();
+ try {
+ Hits hits = findHits(properties, searcher, SORT_DATE_NONE);
+ result = convertHitsToElements(hits, 0, -1);
+ } finally {
+ // Release searcher instance
+ releaseSearcher(searcher);
+ }
+ } catch (Exception e) {
+ throw new StorageException(e);
}
// Return all elements parsed from documents fund
@@ -353,17 +381,21 @@
@Override
public int findElementsByPropertiesCount(Map<String, String> properties)
- throws Exception {
+ throws StorageException {
int result = 0;
- // Get current searcher instance
- Searcher searcher = getSearcher();
try {
- Hits hits = findHits(properties, searcher, SORT_DATE_NONE);
- result = hits.length();
- } finally {
- // Release searcher instance
- releaseSearcher(searcher);
+ // Get current searcher instance
+ Searcher searcher = getSearcher();
+ try {
+ Hits hits = findHits(properties, searcher, SORT_DATE_NONE);
+ result = hits.length();
+ } finally {
+ // Release searcher instance
+ releaseSearcher(searcher);
+ }
+ } catch (Exception e) {
+ throw new StorageException(e);
}
// Return all elements parsed from documents fund
@@ -373,17 +405,21 @@
@Override
public Set<MetaDataEntity> findElementsByProperties(
Map<String, String> properties, int start, int count, int dateOrder)
- throws Exception {
+ throws StorageException {
Set<MetaDataEntity> result = null;
- // Get current searcher instance
- Searcher searcher = getSearcher();
try {
- Hits hits = findHits(properties, searcher, dateOrder);
- result = convertHitsToElements(hits, start, count);
- } finally {
- // Release searcher instance
- releaseSearcher(searcher);
+ // Get current searcher instance
+ Searcher searcher = getSearcher();
+ try {
+ Hits hits = findHits(properties, searcher, dateOrder);
+ result = convertHitsToElements(hits, start, count);
+ } finally {
+ // Release searcher instance
+ releaseSearcher(searcher);
+ }
+ } catch (Exception e) {
+ throw new StorageException(e);
}
// Return all elements parsed from documents fund
@@ -392,21 +428,30 @@
@Override
public int findElementsByContentSearchCount(String queryText,
- boolean onlyLatest) throws Exception {
- Query query = getQueryByContentSearch(queryText, onlyLatest);
+ boolean onlyLatest) throws StorageException {
+ Query query = null;
+ try {
+ query = getQueryByContentSearch(queryText, onlyLatest);
+ } catch (ParseException e) {
+ throw new StorageException(e);
+ }
int result = 0;
Hits hits;
- // Get current searcher instance
- Searcher searcher = getSearcher();
try {
- hits = searcher.search(query);
- // Return hits length
- result = hits.length();
- } finally {
- // Release searcher instance
- releaseSearcher(searcher);
+ // Get current searcher instance
+ Searcher searcher = getSearcher();
+ try {
+ hits = searcher.search(query);
+ // Return hits length
+ result = hits.length();
+ } finally {
+ // Release searcher instance
+ releaseSearcher(searcher);
+ }
+ } catch (Exception e) {
+ throw new StorageException(e);
}
return result;
@@ -434,21 +479,30 @@
@Override
public Set<MetaDataEntity> findElementsByContentSearch(String queryText,
boolean onlyLatest, int start, int count, int dateOrder)
- throws Exception {
- Query query = getQueryByContentSearch(queryText, onlyLatest);
+ throws StorageException {
+ Query query = null;
+ try {
+ query = getQueryByContentSearch(queryText, onlyLatest);
+ } catch (ParseException e) {
+ throw new StorageException(e);
+ }
Set<MetaDataEntity> result = null;
Hits hits;
- // Get current searcher instance
- Searcher searcher = getSearcher();
try {
- hits = searcher.search(query, getSortDate(dateOrder));
- // Convert hits to elements
- result = convertHitsToElements(hits, start, count);
- } finally {
- // Release searcher instance
- releaseSearcher(searcher);
+ // Get current searcher instance
+ Searcher searcher = getSearcher();
+ try {
+ hits = searcher.search(query, getSortDate(dateOrder));
+ // Convert hits to elements
+ result = convertHitsToElements(hits, start, count);
+ } finally {
+ // Release searcher instance
+ releaseSearcher(searcher);
+ }
+ } catch (Exception e) {
+ throw new StorageException(e);
}
return result;
@@ -491,14 +545,19 @@
}
@Override
- public void deleteElement(String uuid, Version version) throws Exception {
+ public void deleteElement(String uuid, Version version)
+ throws StorageException {
// Delete element in db with term search
Term[] terms = new Term[2];
terms[0] = new Term(KEY_UUID, uuid);
terms[1] = new Term(KEY_VERSION, version.toString());
- synchronized (writerSynchronizer) {
- writer.deleteDocuments(terms);
+ try {
+ synchronized (writerSynchronizer) {
+ writer.deleteDocuments(terms);
+ }
+ } catch (Exception e) {
+ throw new StorageException(e);
}
}
Modified: trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java
===================================================================
--- trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2008-01-24 18:00:06 UTC (rev 504)
+++ trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2008-01-24 18:00:48 UTC (rev 505)
@@ -24,6 +24,7 @@
import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity;
import fr.cemagref.simexplorer.is.entities.metadata.Version;
+import fr.cemagref.simexplorer.is.storage.StorageException;
public interface StorageEngine {
@@ -32,21 +33,21 @@
*
* @throws Exception
*/
- public abstract void open() throws Exception;
+ public abstract void open() throws StorageException;
/**
* Close storage
*
* @throws Exception
*/
- public abstract void close() throws Exception;
+ public abstract void close() throws StorageException;
/**
* Commit changes to storage
*
* @throws Exception
*/
- public abstract void commit() throws Exception;
+ public abstract void commit() throws StorageException;
/**
* Save an element to storage
@@ -58,7 +59,7 @@
* @throws Exception
*/
public abstract void saveElement(String token, MetaDataEntity element,
- Map<String, InputStream> attachments) throws Exception;
+ Map<String, InputStream> attachments) throws StorageException;
/**
* Retrieve an element
@@ -69,7 +70,7 @@
* @throws Exception
*/
public abstract MetaDataEntity getMetadata(String token, String uuid)
- throws Exception;
+ throws StorageException;
/**
* Retrieve versions of an element<br>
@@ -82,7 +83,7 @@
* @throws Exception
*/
public abstract List<Version> getVersions(String token, String uuid)
- throws Exception;
+ throws StorageException;
/**
* Retrieve all version of a metadata
@@ -92,7 +93,7 @@
* @return
*/
public abstract Set<MetaDataEntity> getElementVersions(String token,
- String uuid) throws Exception;
+ String uuid) throws StorageException;
/**
* Retrieve an element in a specific version
@@ -103,7 +104,7 @@
* @throws Exception
*/
public abstract MetaDataEntity getMetadata(String token, String uuid,
- Version version) throws Exception;
+ Version version) throws StorageException;
/**
* Get data associated to an element
@@ -116,7 +117,7 @@
* @throws Exception
*/
public abstract InputStream retrieveData(String token,
- MetaDataEntity entity, String field) throws Exception;
+ MetaDataEntity entity, String field) throws StorageException;
/**
* Get number of items corresponding to query
@@ -127,7 +128,7 @@
* @throws Exception
*/
public abstract int findFullTextCount(String token, String query,
- boolean onlyLatest) throws Exception;
+ boolean onlyLatest) throws StorageException;
/**
* Retrieve list of items corresponding to query
@@ -142,7 +143,7 @@
*/
public abstract MetaDataEntity[] findFullText(String token, String query,
boolean onlyLatest, int indexStart, int count, int dateOrder)
- throws Exception;
+ throws StorageException;
/**
* Retrieve list of items of type wanted
@@ -157,7 +158,7 @@
*/
public abstract MetaDataEntity[] findElementsByType(String token,
String type, boolean onlyLatest, int start, int count, int dateOrder)
- throws Exception;
+ throws StorageException;
/**
* Retrieve number of items of type wanted
@@ -168,7 +169,7 @@
* @throws Exception
*/
public abstract int findElementsByTypeCount(String token, String type,
- boolean onlyLatest) throws Exception;
+ boolean onlyLatest) throws StorageException;
/**
* Delete elements
@@ -177,7 +178,7 @@
* @throws Exception
*/
public abstract void deleteElements(String token, String uuid)
- throws Exception;
+ throws StorageException;
/**
* Delete one element
@@ -187,7 +188,7 @@
* @throws Exception
*/
public abstract void deleteElement(String token, String uuid,
- Version version) throws Exception;
+ Version version) throws StorageException;
/**
* Store temporary data, for stream duplication
@@ -197,7 +198,7 @@
* @return id for retrieval
* @throws Exception
*/
- public abstract String storeTempData(InputStream stream) throws Exception;
+ public abstract String storeTempData(InputStream stream) throws StorageException;
/**
* Retrieve temporary data
@@ -207,7 +208,7 @@
* @return Data stream
* @throws Exception
*/
- public abstract InputStream retrieveTempData(String id) throws Exception;
+ public abstract InputStream retrieveTempData(String id) throws StorageException;
/**
* Delete temporary data
@@ -215,6 +216,6 @@
* @param id
* @throws Exception
*/
- public abstract void deleteTempData(String id) throws Exception;
+ public abstract void deleteTempData(String id) throws StorageException;
}
\ No newline at end of file
Modified: trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java
===================================================================
--- trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java 2008-01-24 18:00:06 UTC (rev 504)
+++ trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java 2008-01-24 18:00:48 UTC (rev 505)
@@ -29,6 +29,7 @@
import fr.cemagref.simexplorer.is.contenttype.ContentType;
import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity;
import fr.cemagref.simexplorer.is.entities.metadata.Version;
+import fr.cemagref.simexplorer.is.storage.StorageException;
import fr.cemagref.simexplorer.is.storage.attachment.AttachmentHandler;
import fr.cemagref.simexplorer.is.storage.attachment.FileSystemAttachmentHandler;
import fr.cemagref.simexplorer.is.storage.database.Database;
@@ -75,21 +76,21 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#open()
*/
- public void open() throws Exception {
+ public void open() throws StorageException {
database.open();
}
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#close()
*/
- public void close() throws Exception {
+ public void close() throws StorageException {
database.close();
}
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#commit()
*/
- public void commit() throws Exception {
+ public void commit() throws StorageException {
database.commit();
}
@@ -99,7 +100,7 @@
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#saveElement(fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity, java.util.Map)
*/
public void saveElement(String token, MetaDataEntity element,
- Map<String, InputStream> attachments) throws Exception {
+ Map<String, InputStream> attachments) throws StorageException {
// Save all attachments in system
for (Map.Entry<String, InputStream> entry : attachments.entrySet()) {
@@ -116,9 +117,13 @@
if (element.getAttachments() != null) {
ContentType contentType = element.getAttachments().get(field);
if (contentType != null) {
- // Transform stream into indexable text
- Reader reader = contentType.renderToText(content);
- readers.add(reader);
+ try {
+ // Transform stream into indexable text
+ Reader reader = contentType.renderToText(content);
+ readers.add(reader);
+ } catch (Exception e) {
+ throw new StorageException(e);
+ }
}
}
}
@@ -141,7 +146,8 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#getMetadata(java.lang.String)
*/
- public MetaDataEntity getMetadata(String token, String uuid) throws Exception {
+ public MetaDataEntity getMetadata(String token, String uuid)
+ throws StorageException {
MetaDataEntity mde = null;
Set<MetaDataEntity> set = database.findElementsById(uuid, true);
if (!set.isEmpty()) {
@@ -153,7 +159,8 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#getVersions(java.lang.String)
*/
- public List<Version> getVersions(String token, String uuid) throws Exception {
+ public List<Version> getVersions(String token, String uuid)
+ throws StorageException {
return database.getVersions(uuid);
}
@@ -161,7 +168,7 @@
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#getMetadata(java.lang.String, fr.cemagref.simexplorer.is.entities.metadata.Version)
*/
public MetaDataEntity getMetadata(String token, String uuid, Version version)
- throws Exception {
+ throws StorageException {
MetaDataEntity mde = database.getElement(uuid, version);
return mde;
}
@@ -169,8 +176,8 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#retrieveData(fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity, java.lang.String)
*/
- public InputStream retrieveData(String token, MetaDataEntity entity, String field)
- throws Exception {
+ public InputStream retrieveData(String token, MetaDataEntity entity,
+ String field) throws StorageException {
InputStream result = attachmentHandler.retrieveData(entity, field);
return result;
}
@@ -179,15 +186,16 @@
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#findFullTextCount(java.lang.String, boolean)
*/
public int findFullTextCount(String token, String query, boolean onlyLatest)
- throws Exception {
+ throws StorageException {
return database.findElementsByContentSearchCount(query, onlyLatest);
}
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#findFullText(java.lang.String, boolean, int, int, int)
*/
- public MetaDataEntity[] findFullText(String token, String query, boolean onlyLatest,
- int indexStart, int count, int dateOrder) throws Exception {
+ public MetaDataEntity[] findFullText(String token, String query,
+ boolean onlyLatest, int indexStart, int count, int dateOrder)
+ throws StorageException {
MetaDataEntity[] result = database.findElementsByContentSearch(query,
onlyLatest, indexStart, count, dateOrder).toArray(
new MetaDataEntity[0]);
@@ -197,8 +205,9 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#findElementsByType(java.lang.String, boolean, int, int, int)
*/
- public MetaDataEntity[] findElementsByType(String token, String type, boolean onlyLatest,
- int start, int count, int dateOrder) throws Exception {
+ public MetaDataEntity[] findElementsByType(String token, String type,
+ boolean onlyLatest, int start, int count, int dateOrder)
+ throws StorageException {
MetaDataEntity[] result = database.findElementsByType(type, onlyLatest,
start, count, dateOrder).toArray(new MetaDataEntity[0]);
return result;
@@ -207,8 +216,8 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#findElementsByTypeCount(java.lang.String, boolean)
*/
- public int findElementsByTypeCount(String token, String type, boolean onlyLatest)
- throws Exception {
+ public int findElementsByTypeCount(String token, String type,
+ boolean onlyLatest) throws StorageException {
return database.findElementsByTypeCount(type, onlyLatest);
}
@@ -217,7 +226,8 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#deleteElements(java.lang.String)
*/
- public void deleteElements(String token, String uuid) throws Exception {
+ public void deleteElements(String token, String uuid)
+ throws StorageException {
List<Version> versions = getVersions(token, uuid);
for (Version version : versions) {
deleteElement(token, uuid, version);
@@ -227,7 +237,8 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#deleteElement(java.lang.String, fr.cemagref.simexplorer.is.entities.metadata.Version)
*/
- public void deleteElement(String token, String uuid, Version version) throws Exception {
+ public void deleteElement(String token, String uuid, Version version)
+ throws StorageException {
MetaDataEntity element = getMetadata(token, uuid, version);
Map<String, ContentType> attachments = element.getAttachments();
for (Map.Entry<String, ContentType> entry : attachments.entrySet()) {
@@ -241,7 +252,7 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#storeTempData(java.io.InputStream)
*/
- public String storeTempData(InputStream stream) throws Exception {
+ public String storeTempData(InputStream stream) throws StorageException {
String id = UUID.randomUUID().toString();
attachmentHandler.storeData(mdTmp, id, stream);
return id;
@@ -250,7 +261,7 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#retrieveTempData(java.lang.String)
*/
- public InputStream retrieveTempData(String id) throws Exception {
+ public InputStream retrieveTempData(String id) throws StorageException {
InputStream is = attachmentHandler.retrieveData(mdTmp, id);
return is;
}
@@ -258,11 +269,12 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#deleteTempData(java.lang.String)
*/
- public void deleteTempData(String id) throws Exception {
+ public void deleteTempData(String id) throws StorageException {
attachmentHandler.deleteData(mdTmp, id);
}
- public Set<MetaDataEntity> getElementVersions(String token, String uuid) throws Exception {
+ public Set<MetaDataEntity> getElementVersions(String token, String uuid)
+ throws StorageException {
return database.findElementsById(uuid, false);
}
Modified: trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/util/Config.java
===================================================================
--- trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/util/Config.java 2008-01-24 18:00:06 UTC (rev 504)
+++ trunk/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/util/Config.java 2008-01-24 18:00:48 UTC (rev 505)
@@ -26,7 +26,6 @@
public class Config {
- /** to use log facility, just put in your code: log.info(\"...\"); */
private static final Log log = LogFactory.getLog(Config.class);
private static Properties properties = null;
@@ -34,7 +33,7 @@
private static void initProperties() throws IOException {
log.info("Loading properties");
-
+
properties = new Properties();
URL inClasspath = ClassLoader.getSystemClassLoader().getResource(
1
0