r982 - in trunk/simexplorer-is: simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine
Author: glandais Date: 2008-02-14 23:07:20 +0000 (Thu, 14 Feb 2008) New Revision: 982 Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManager.java trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurity.java trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurityImpl.java trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java Log: Security Formatting Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManager.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManager.java 2008-02-14 20:18:28 UTC (rev 981) +++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManager.java 2008-02-14 23:07:20 UTC (rev 982) @@ -30,10 +30,8 @@ /** * Gets the permission. * - * @param token - * the token - * @param businessId - * the business id + * @param token the token + * @param businessId the business id * * @return the permission */ @@ -42,13 +40,10 @@ /** * Save element. * - * @param token - * the token - * @param businessId - * the business id + * @param token the token + * @param businessId the business id * - * @return the permission */ - public Permission saveElement(String token, String businessId); + public void saveElement(String token, String businessId); } Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java 2008-02-14 20:18:28 UTC (rev 981) +++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java 2008-02-14 23:07:20 UTC (rev 982) @@ -46,10 +46,8 @@ /** * Gets the relative level. * - * @param actor - * the actor - * @param permission - * the permission + * @param actor the actor + * @param permission the permission * * @return the relative level */ @@ -103,37 +101,37 @@ p.setCanWrite(true); } + if (p == null) { + p = new Permission(); + p.setActor(user); + p.setBusinessId(businessId); + p.setOwner(false); + p.setCanAdmin(false); + p.setCanRead(false); + p.setCanWrite(false); + } + return p; } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.security.credentials.CredentialManager#saveElement(java.lang.String, java.lang.String) */ - public Permission saveElement(String token, String businessId) { - Permission p = getPermission(token, businessId); - boolean createPermission = false; - if (p == null) { - createPermission = true; - } - if (p != null) { - User user = dao.getLoggedUser(token); - if (!user.getId().equals(p.getActor().getId())) { - createPermission = true; + public void saveElement(String token, String businessId) { + User user = dao.getLoggedUser(token); + if (!user.isSuperAdmin()) { + Permission p = getPermission(token, businessId); + if ((p == null) || (!user.getId().equals(p.getActor().getId()))) { + p = new Permission(); + p.setActor(dao.getLoggedUser(token)); + p.setBusinessId(businessId); + p.setOwner(true); + dao.savePermission(p); + } else { + p.setOwner(true); + dao.updatePermission(p); } } - if (createPermission) { - p = new Permission(); - p.setActor(dao.getLoggedUser(token)); - p.setBusinessId(businessId); - dao.savePermission(p); - } - p.setCanAdmin(true); - p.setCanRead(true); - p.setCanWrite(true); - p.setOwner(true); - dao.updatePermission(p); - - return p; } } Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurity.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurity.java 2008-02-14 20:18:28 UTC (rev 981) +++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurity.java 2008-02-14 23:07:20 UTC (rev 982) @@ -19,6 +19,7 @@ import java.util.List; +import fr.cemagref.simexplorer.is.security.entities.Actor; import fr.cemagref.simexplorer.is.security.entities.Group; import fr.cemagref.simexplorer.is.security.entities.LoginAction; import fr.cemagref.simexplorer.is.security.entities.Permission; @@ -32,16 +33,14 @@ /** * Save user. * - * @param user - * the user + * @param user the user */ public void saveUser(User user); /** * Gets the user. * - * @param id - * the id + * @param id the id * * @return the user */ @@ -50,8 +49,7 @@ /** * Gets the user. * - * @param login - * the login + * @param login the login * * @return the user */ @@ -60,8 +58,7 @@ /** * Update user. * - * @param user - * the user + * @param user the user * * @return the user */ @@ -70,24 +67,21 @@ /** * Delete user. * - * @param id - * the id + * @param id the id */ public void deleteUser(Integer id); /** * Save group. * - * @param group - * the group + * @param group the group */ public void saveGroup(Group group); /** * Gets the group. * - * @param id - * the id + * @param id the id * * @return the group */ @@ -96,8 +90,7 @@ /** * Gets the group. * - * @param name - * the name + * @param name the name * * @return the group */ @@ -106,8 +99,7 @@ /** * Update group. * - * @param group - * the group + * @param group the group * * @return the group */ @@ -116,16 +108,14 @@ /** * Delete group. * - * @param id - * the id + * @param id the id */ public void deleteGroup(Integer id); /** * Gets the logged user. * - * @param token - * the token + * @param token the token * * @return the logged user */ @@ -134,10 +124,8 @@ /** * Login user. * - * @param login - * the login - * @param passwordHash - * the password hash + * @param login the login + * @param passwordHash the password hash * * @return the user */ @@ -146,18 +134,15 @@ /** * Save token. * - * @param loginAction - * the login action + * @param loginAction the login action */ public void saveToken(LoginAction loginAction); /** * Delete old tokens associated to user. * - * @param login - * Login of user - * @param before - * ms before now + * @param login Login of user + * @param before ms before now */ public void deleteTokens(String login, long before); @@ -171,8 +156,7 @@ /** * Gets the groups owned by. * - * @param user - * the user + * @param user the user * * @return the groups owned by */ @@ -188,8 +172,7 @@ /** * Gets the users of group. * - * @param group - * the group + * @param group the group * * @return the users of group */ @@ -198,8 +181,7 @@ /** * Gets the groups of user. * - * @param user - * the user + * @param user the user * * @return the groups of user */ @@ -208,8 +190,7 @@ /** * Gets the groups of group. * - * @param group - * the group + * @param group the group * * @return the groups of group */ @@ -218,36 +199,41 @@ /** * Gets the permissions. * - * @param businessId - * the business id + * @param businessId the business id * * @return the permissions */ public List<Permission> getPermissions(String businessId); /** + * Gets the permissions. + * + * @param businessId the business id + * @param actor the actor + * + * @return the permissions + */ + public List<Permission> getPermissions(Actor actor, String businessId); + + /** * Save permission. * - * @param p - * the p + * @param p the p */ public void savePermission(Permission p); /** * Update permission. * - * @param p - * the p + * @param p the p */ public void updatePermission(Permission p); - + /** * Sets the permissions. * - * @param uuid - * the uuid - * @param permissions - * the permissions + * @param uuid the uuid + * @param permissions the permissions */ public void setPermissions(String uuid, Permission[] permissions); Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurityImpl.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurityImpl.java 2008-02-14 20:18:28 UTC (rev 981) +++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurityImpl.java 2008-02-14 23:07:20 UTC (rev 982) @@ -28,6 +28,7 @@ import org.codelutin.util.CollectionUtil; +import fr.cemagref.simexplorer.is.security.entities.Actor; import fr.cemagref.simexplorer.is.security.entities.Group; import fr.cemagref.simexplorer.is.security.entities.LoginAction; import fr.cemagref.simexplorer.is.security.entities.Permission; @@ -46,8 +47,7 @@ /** * Gets the single result. * - * @param query - * the query + * @param query the query * * @return the single result */ @@ -64,10 +64,8 @@ /** * Find. * - * @param clazz - * the clazz - * @param arg - * the arg + * @param clazz the clazz + * @param arg the arg * * @return the object */ @@ -111,8 +109,7 @@ * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getGroup(java.lang.String) */ public Group getGroup(String name) { - Group g = (Group) getSingleResult(em.createQuery( - "select g from Group g where g.name=:name").setParameter( + Group g = (Group) getSingleResult(em.createQuery("select g from Group g where g.name=:name").setParameter( "name", name)); return g; } @@ -159,8 +156,7 @@ public User getLoggedUser(String token) { User loggedUser = null; LoginAction loginAction = (LoginAction) getSingleResult(em.createQuery( - "select la from LoginAction la where la.token=:token") - .setParameter("token", token)); + "select la from LoginAction la where la.token=:token").setParameter("token", token)); if (loginAction != null) { loggedUser = loginAction.getLoggedUser(); loginAction.setTime(new Date()); @@ -173,11 +169,9 @@ * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#loginUser(java.lang.String, java.lang.String) */ public User loginUser(String login, String passwordHash) { - User user = (User) getSingleResult(em - .createQuery( - "select u from User u where u.login=:login and u.passwordHash=:passwordHash") - .setParameter("login", login).setParameter("passwordHash", - passwordHash)); + User user = (User) getSingleResult(em.createQuery( + "select u from User u where u.login=:login and u.passwordHash=:passwordHash").setParameter("login", + login).setParameter("passwordHash", passwordHash)); return user; } @@ -194,19 +188,15 @@ public void deleteTokens(String login, long before) { Date now = new Date(); Date date = new Date(now.getTime() - before); - em - .createQuery( - "delete from LoginAction la where la.loggedUser.login = :login and la.time < :time") - .setParameter("time", date).setParameter("login", login) - .executeUpdate(); + em.createQuery("delete from LoginAction la where la.loggedUser.login = :login and la.time < :time") + .setParameter("time", date).setParameter("login", login).executeUpdate(); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getUser(java.lang.String) */ public User getUser(String login) { - User user = (User) getSingleResult(em.createQuery( - "select u from User u where u.login=:login").setParameter( + User user = (User) getSingleResult(em.createQuery("select u from User u where u.login=:login").setParameter( "login", login)); return user; } @@ -215,8 +205,8 @@ * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getGroups() */ public List<Group> getGroups() { - List<Group> groups = CollectionUtil.toGenericList(em.createQuery( - "select g from Group g").getResultList(), Group.class); + List<Group> groups = CollectionUtil.toGenericList(em.createQuery("select g from Group g").getResultList(), + Group.class); return groups; } @@ -224,9 +214,8 @@ * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getGroupsOwnedBy(fr.cemagref.simexplorer.is.security.entities.User) */ public List<Group> getGroupsOwnedBy(User user) { - List<Group> groups = CollectionUtil.toGenericList(em.createQuery( - "select g from Group g where g.owner=:owner").setParameter( - "owner", user).getResultList(), Group.class); + List<Group> groups = CollectionUtil.toGenericList(em.createQuery("select g from Group g where g.owner=:owner") + .setParameter("owner", user).getResultList(), Group.class); return groups; } @@ -234,8 +223,8 @@ * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getUsers() */ public List<User> getUsers() { - List<User> users = CollectionUtil.toGenericList(em.createQuery( - "select u from User u").getResultList(), User.class); + List<User> users = CollectionUtil.toGenericList(em.createQuery("select u from User u").getResultList(), + User.class); return users; } @@ -243,13 +232,9 @@ * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getUsersOfGroup(fr.cemagref.simexplorer.is.security.entities.Group) */ public List<User> getUsersOfGroup(Group group) { - List<User> users = CollectionUtil - .toGenericList( - em - .createQuery( - "select distinct u from User u where :group member of u.groups") - .setParameter("group", group).getResultList(), - User.class); + List<User> users = CollectionUtil.toGenericList(em.createQuery( + "select distinct u from User u where :group member of u.groups").setParameter("group", group) + .getResultList(), User.class); return users; } @@ -258,8 +243,8 @@ */ public List<Group> getGroupsOfUser(User user) { List<Group> groups = CollectionUtil.toGenericList(em.createQuery( - "select distinct u.groups from User u where u = :user") - .setParameter("user", user).getResultList(), Group.class); + "select distinct u.groups from User u where u = :user").setParameter("user", user).getResultList(), + Group.class); return groups; } @@ -268,8 +253,8 @@ */ public List<Group> getGroupsOfGroup(Group group) { List<Group> groups = CollectionUtil.toGenericList(em.createQuery( - "select distinct g.groups from Group g where g = :group") - .setParameter("group", group).getResultList(), Group.class); + "select distinct g.groups from Group g where g = :group").setParameter("group", group).getResultList(), + Group.class); return groups; } @@ -277,17 +262,23 @@ * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getPermissions(java.lang.String) */ public List<Permission> getPermissions(String businessId) { - List<Permission> permissions = CollectionUtil - .toGenericList( - em - .createQuery( - "select p from Permission p where p.businessId=:businessId") - .setParameter("businessId", businessId) - .getResultList(), Permission.class); + List<Permission> permissions = CollectionUtil.toGenericList(em.createQuery( + "select p from Permission p where p.businessId=:businessId").setParameter("businessId", businessId) + .getResultList(), Permission.class); return permissions; } /* (non-Javadoc) + * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getPermissions(fr.cemagref.simexplorer.is.security.entities.Actor, java.lang.String) + */ + public List<Permission> getPermissions(Actor actor, String businessId) { + List<Permission> permissions = CollectionUtil.toGenericList(em.createQuery( + "select p from Permission p where p.businessId=:businessId and p.actor=:actor").setParameter( + "businessId", businessId).setParameter("actor", actor).getResultList(), Permission.class); + return permissions; + } + + /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#savePermission(fr.cemagref.simexplorer.is.security.entities.Permission) */ public void savePermission(Permission p) { @@ -298,9 +289,8 @@ * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#setPermissions(java.lang.String, fr.cemagref.simexplorer.is.security.entities.Permission[]) */ public void setPermissions(String uuid, Permission[] permissions) { - em.createQuery( - "delete from Permission p where p.businessId=:businessId") - .setParameter("businessId", uuid).executeUpdate(); + em.createQuery("delete from Permission p where p.businessId=:businessId").setParameter("businessId", uuid) + .executeUpdate(); for (Permission permission : permissions) { em.persist(permission); } Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-02-14 20:18:28 UTC (rev 981) +++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-02-14 23:07:20 UTC (rev 982) @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -369,7 +370,6 @@ attachments.put(attachment, getStorageEngine().retrieveData(token, oldMetaData, attachment)); } - // FIXME if (deleteOldElement) { getStorageEngine().deleteElement(token, oldUuid, oldVersion); } @@ -403,6 +403,7 @@ */ public void deleteElement(String token, String uuid, String version) throws SimExplorerServiceException { try { + // FIXME getStorageEngine().deleteElement(token, uuid, new Version(version)); getStorageEngine().commit(); } catch (SimExplorerStorageException e) { @@ -415,6 +416,7 @@ */ public void deleteElement(String token, String uuid) throws SimExplorerServiceException { try { + // FIXME getStorageEngine().deleteElements(token, uuid); getStorageEngine().commit(); } catch (SimExplorerStorageException e) { @@ -445,15 +447,23 @@ // If there is already an element with this id if (previousVersion != null) { - // set previous as not being the latest one - previousVersion.setLatest(false); - // update item in database, replace previous version - update(token, previousVersion.getUuid(), previousVersion.getVersion(), previousVersion, true); + // check if we have rights to create a subversion + if (getStorageEngine().canCreateSubVersion(token, metaData.getUuid())) { + // set previous as not being the latest one + previousVersion.setLatest(false); + // update item in database, replace previous version + update(token, previousVersion.getUuid(), previousVersion.getVersion(), previousVersion, true); - // Increment version only if needed - if (metaData.getVersion().compareTo(incrementVersion(previousVersion.getVersion())) <= 0) { - metaData.setVersion(incrementVersion(previousVersion.getVersion()).toString()); + // Increment version only if needed + if (metaData.getVersion().compareTo(incrementVersion(previousVersion.getVersion())) <= 0) { + metaData.setVersion(incrementVersion(previousVersion.getVersion()).toString()); + } + } else { + // Generates a new branch, with a new id + metaData.setVersion("1"); + metaData.setUuid(UUID.randomUUID().toString()); } + metaData.setParentVersionUuid(previousVersion.getUuid()); metaData.setParentVersionVersion(previousVersion.getVersion().toString()); @@ -628,7 +638,7 @@ Element entitiesElement = elementFactory.getXMLElementByTagName(node, entitiesNode); Set<Element> entityElements = elementFactory.getXMLElementsByTagName(entitiesElement, entityNode); for (Element element : entityElements) { - MetaData elementMetadata = saveElement(token, document, element, idsattachment); + saveElement(token, document, element, idsattachment); } } Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java 2008-02-14 20:18:28 UTC (rev 981) +++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java 2008-02-14 23:07:20 UTC (rev 982) @@ -49,15 +49,13 @@ * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#deleteElement(java.lang.String, java.lang.String, fr.cemagref.simexplorer.is.entities.metadata.Version) */ @Override - public void deleteElement(String token, String uuid, Version version) - throws SimExplorerStorageException { + public void deleteElement(String token, String uuid, Version version) throws SimExplorerStorageException { Permission permission = credentialManager.getPermission(token, uuid); // TODO check candelete = canadmin - if (permission != null && permission.isCanAdmin()) { + if (permission.isCanAdmin()) { super.deleteElement(token, uuid, version); } else { - throw new SimExplorerStorageException( - _("simexplorer.service.security.norights")); + throw new SimExplorerStorageException(_("simexplorer.service.security.norights")); } } @@ -65,15 +63,13 @@ * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#deleteElements(java.lang.String, java.lang.String) */ @Override - public void deleteElements(String token, String uuid) - throws SimExplorerStorageException { + public void deleteElements(String token, String uuid) throws SimExplorerStorageException { Permission permission = credentialManager.getPermission(token, uuid); // TODO check candelete = canadmin - if (permission != null && permission.isCanAdmin()) { + if (permission.isCanAdmin()) { super.deleteElements(token, uuid); } else { - throw new SimExplorerStorageException( - _("simexplorer.service.security.norights")); + throw new SimExplorerStorageException(_("simexplorer.service.security.norights")); } } @@ -81,12 +77,10 @@ * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#findElementsByType(java.lang.String, java.lang.String, boolean, int, int, int) */ @Override - public MetaData[] findElementsByType(String token, String type, - boolean onlyLatest, int start, int count, int dateOrder) - throws SimExplorerStorageException { + public MetaData[] findElementsByType(String token, String type, boolean onlyLatest, int start, int count, + int dateOrder) throws SimExplorerStorageException { MetaData[] list; - list = super.findElementsByType(token, type, onlyLatest, start, count, - dateOrder); + list = super.findElementsByType(token, type, onlyLatest, start, count, dateOrder); // TODO how to filter without losing pagination? return list; } @@ -95,8 +89,8 @@ * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#findElementsByTypeCount(java.lang.String, java.lang.String, boolean) */ @Override - public int findElementsByTypeCount(String token, String type, - boolean onlyLatest) throws SimExplorerStorageException { + public int findElementsByTypeCount(String token, String type, boolean onlyLatest) + throws SimExplorerStorageException { // TODO how to filter without losing pagination? return super.findElementsByTypeCount(token, type, onlyLatest); } @@ -105,20 +99,17 @@ * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#findFullText(java.lang.String, java.lang.String, boolean, int, int, int) */ @Override - public MetaData[] findFullText(String token, String query, - boolean onlyLatest, int indexStart, int count, int dateOrder) - throws SimExplorerStorageException { + public MetaData[] findFullText(String token, String query, boolean onlyLatest, int indexStart, int count, + int dateOrder) throws SimExplorerStorageException { // TODO how to filter without losing pagination? - return super.findFullText(token, query, onlyLatest, indexStart, count, - dateOrder); + return super.findFullText(token, query, onlyLatest, indexStart, count, dateOrder); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#findFullTextCount(java.lang.String, java.lang.String, boolean) */ @Override - public int findFullTextCount(String token, String query, boolean onlyLatest) - throws SimExplorerStorageException { + public int findFullTextCount(String token, String query, boolean onlyLatest) throws SimExplorerStorageException { // TODO how to filter without losing pagination? return super.findFullTextCount(token, query, onlyLatest); } @@ -127,15 +118,13 @@ * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#getMetadata(java.lang.String, java.lang.String, fr.cemagref.simexplorer.is.entities.metadata.Version) */ @Override - public MetaData getMetadata(String token, String uuid, Version version) - throws SimExplorerStorageException { + public MetaData getMetadata(String token, String uuid, Version version) throws SimExplorerStorageException { MetaData mde; Permission permission = credentialManager.getPermission(token, uuid); - if (permission != null && permission.isCanRead()) { + if (permission.isCanRead()) { mde = super.getMetadata(token, uuid, version); } else { - throw new SimExplorerStorageException( - _("simexplorer.service.security.norights")); + throw new SimExplorerStorageException(_("simexplorer.service.security.norights")); } return mde; } @@ -144,15 +133,13 @@ * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#getMetadata(java.lang.String, java.lang.String) */ @Override - public MetaData getMetadata(String token, String uuid) - throws SimExplorerStorageException { + public MetaData getMetadata(String token, String uuid) throws SimExplorerStorageException { MetaData mde; Permission permission = credentialManager.getPermission(token, uuid); - if (permission != null && permission.isCanRead()) { + if (permission.isCanRead()) { mde = super.getMetadata(token, uuid); } else { - throw new SimExplorerStorageException( - _("simexplorer.service.security.norights")); + throw new SimExplorerStorageException(_("simexplorer.service.security.norights")); } return mde; } @@ -161,15 +148,13 @@ * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#getVersions(java.lang.String, java.lang.String) */ @Override - public List<Version> getVersions(String token, String uuid) - throws SimExplorerStorageException { + public List<Version> getVersions(String token, String uuid) throws SimExplorerStorageException { List<Version> versions; Permission permission = credentialManager.getPermission(token, uuid); - if (permission != null && permission.isCanRead()) { + if (permission.isCanRead()) { versions = super.getVersions(token, uuid); } else { - throw new SimExplorerStorageException( - _("simexplorer.service.security.norights")); + throw new SimExplorerStorageException(_("simexplorer.service.security.norights")); } return versions; } @@ -181,32 +166,39 @@ public InputStream retrieveData(String token, MetaData entity, Attachment attachment) throws SimExplorerStorageException { InputStream stream; - Permission permission = credentialManager.getPermission(token, entity - .getUuid()); - if (permission != null && permission.isCanRead()) { + Permission permission = credentialManager.getPermission(token, entity.getUuid()); + if (permission.isCanRead()) { stream = super.retrieveData(token, entity, attachment); } else { - throw new SimExplorerStorageException( - _("simexplorer.service.security.norights")); + throw new SimExplorerStorageException(_("simexplorer.service.security.norights")); } return stream; } /* (non-Javadoc) + * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#canCreateSubVersion(java.lang.String, java.lang.String) + */ + @Override + public boolean canCreateSubVersion(String token, String uuid) throws SimExplorerStorageException { + Permission permission = credentialManager.getPermission(token, uuid); + if (permission.isCanWrite()) { + return true; + } + return false; + } + + /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#saveElement(java.lang.String, fr.cemagref.simexplorer.is.entities.metadata.MetaData, java.util.Map) */ @Override - public void saveElement(String token, MetaData element, - Map<Attachment, InputStream> attachments) + public void saveElement(String token, MetaData element, Map<Attachment, InputStream> attachments) throws SimExplorerStorageException { - Permission permission = credentialManager.getPermission(token, element - .getUuid()); - if (permission != null && permission.isCanWrite()) { + Permission permission = credentialManager.getPermission(token, element.getUuid()); + if (permission.isCanWrite()) { super.saveElement(token, element, attachments); credentialManager.saveElement(token, element.getUuid()); } else { - throw new SimExplorerStorageException( - _("simexplorer.service.security.norights")); + throw new SimExplorerStorageException(_("simexplorer.service.security.norights")); } } Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2008-02-14 20:18:28 UTC (rev 981) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2008-02-14 23:07:20 UTC (rev 982) @@ -38,311 +38,245 @@ /** * Open storage. * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ public abstract void open() throws SimExplorerStorageException; /** * Close storage. * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ public abstract void close() throws SimExplorerStorageException; /** * Commit changes to storage. * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ public abstract void commit() throws SimExplorerStorageException; /** * Save an element to storage. * - * @param element - * Element to save - * @param attachments - * Attachments related - * @param token - * the token + * @param element Element to save + * @param attachments Attachments related + * @param token the token * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ - public abstract void saveElement(String token, MetaData element, - Map<Attachment, InputStream> attachments) + public abstract void saveElement(String token, MetaData element, Map<Attachment, InputStream> attachments) throws SimExplorerStorageException; /** + * Can create sub version for element. + * + * @param token the token + * @param uuid the uuid + * + * @return true, if can create sub version + * + * @throws SimExplorerStorageException the sim explorer storage exception + */ + public abstract boolean canCreateSubVersion(String token, String uuid) throws SimExplorerStorageException; + + /** * Retrieve an element. * - * @param uuid - * Id of the element - * @param token - * the token + * @param uuid Id of the element + * @param token the token * * @return The element * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ - public abstract MetaData getMetadata(String token, String uuid) - throws SimExplorerStorageException; + public abstract MetaData getMetadata(String token, String uuid) throws SimExplorerStorageException; /** * Retrieve versions of an element<br> * Empty list if no element with this id. * - * @param uuid - * Id of the element - * @param token - * the token + * @param uuid Id of the element + * @param token the token * * @return List of versions of the element<br> * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ - public abstract List<Version> getVersions(String token, String uuid) - throws SimExplorerStorageException; + public abstract List<Version> getVersions(String token, String uuid) throws SimExplorerStorageException; /** * Retrieve all version of a metadata. * - * @param token - * the token - * @param uuid - * the uuid + * @param token the token + * @param uuid the uuid * * @return the element versions * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ - public abstract Set<MetaData> getElementVersions(String token, String uuid) - throws SimExplorerStorageException; + public abstract Set<MetaData> getElementVersions(String token, String uuid) throws SimExplorerStorageException; /** * Retrieve an element in a specific version. * - * @param uuid - * the uuid - * @param version - * the version - * @param token - * the token + * @param uuid the uuid + * @param version the version + * @param token the token * * @return the metadata * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ - public abstract MetaData getMetadata(String token, String uuid, - Version version) throws SimExplorerStorageException; + public abstract MetaData getMetadata(String token, String uuid, Version version) throws SimExplorerStorageException; /** * Get data associated to an element. * - * @param entity - * Element related - * @param token - * the token - * @param attachment - * the attachment + * @param entity Element related + * @param token the token + * @param attachment the attachment * * @return Data stream * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ - public abstract InputStream retrieveData(String token, MetaData entity, - Attachment attachment) throws SimExplorerStorageException; + public abstract InputStream retrieveData(String token, MetaData entity, Attachment attachment) + throws SimExplorerStorageException; /** * Get number of items corresponding to query. * - * @param query - * the query - * @param onlyLatest - * the only latest - * @param token - * the token + * @param query the query + * @param onlyLatest the only latest + * @param token the token * * @return the int * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ - public abstract int findFullTextCount(String token, String query, - boolean onlyLatest) throws SimExplorerStorageException; + public abstract int findFullTextCount(String token, String query, boolean onlyLatest) + throws SimExplorerStorageException; /** * Retrieve list of items corresponding to query. * - * @param query - * the query - * @param onlyLatest - * the only latest - * @param indexStart - * the index start - * @param count - * the count - * @param dateOrder - * the date order - * @param token - * the token + * @param query the query + * @param onlyLatest the only latest + * @param indexStart the index start + * @param count the count + * @param dateOrder the date order + * @param token the token * * @return the meta data[] * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ - public abstract MetaData[] findFullText(String token, String query, - boolean onlyLatest, int indexStart, int count, int dateOrder) - throws SimExplorerStorageException; + public abstract MetaData[] findFullText(String token, String query, boolean onlyLatest, int indexStart, int count, + int dateOrder) throws SimExplorerStorageException; /** * Retrieve list of items of type wanted. * - * @param type - * the type - * @param onlyLatest - * the only latest - * @param start - * the start - * @param count - * the count - * @param dateOrder - * the date order - * @param token - * the token + * @param type the type + * @param onlyLatest the only latest + * @param start the start + * @param count the count + * @param dateOrder the date order + * @param token the token * * @return the meta data[] * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ - public abstract MetaData[] findElementsByType(String token, String type, - boolean onlyLatest, int start, int count, int dateOrder) - throws SimExplorerStorageException; + public abstract MetaData[] findElementsByType(String token, String type, boolean onlyLatest, int start, int count, + int dateOrder) throws SimExplorerStorageException; /** * Retrieve number of items of type wanted. * - * @param type - * the type - * @param onlyLatest - * the only latest - * @param token - * the token + * @param type the type + * @param onlyLatest the only latest + * @param token the token * * @return the int * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ - public abstract int findElementsByTypeCount(String token, String type, - boolean onlyLatest) throws SimExplorerStorageException; + public abstract int findElementsByTypeCount(String token, String type, boolean onlyLatest) + throws SimExplorerStorageException; /** * Delete elements. * - * @param uuid - * the uuid - * @param token - * the token + * @param uuid the uuid + * @param token the token * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ - public abstract void deleteElements(String token, String uuid) - throws SimExplorerStorageException; + public abstract void deleteElements(String token, String uuid) throws SimExplorerStorageException; /** * Delete one element. * - * @param uuid - * the uuid - * @param version - * the version - * @param token - * the token + * @param uuid the uuid + * @param version the version + * @param token the token * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ - public abstract void deleteElement(String token, String uuid, - Version version) throws SimExplorerStorageException; + public abstract void deleteElement(String token, String uuid, Version version) throws SimExplorerStorageException; /** * Store temporary data, for stream duplication. * - * @param stream - * Stream to store + * @param stream Stream to store * * @return id for retrieval * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ - public abstract String storeTempData(InputStream stream) - throws SimExplorerStorageException; + public abstract String storeTempData(InputStream stream) throws SimExplorerStorageException; /** * Store temporary data, for stream duplication. * - * @param stream - * Stream to store + * @param stream Stream to store + * @param id the id * - * @return id for retrieval - * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ - public abstract void storeTempData(String id, InputStream stream) - throws SimExplorerStorageException; + public abstract void storeTempData(String id, InputStream stream) throws SimExplorerStorageException; /** * Retrieve temporary data. * - * @param id - * Id associated + * @param id Id associated * * @return Data stream * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ - public abstract InputStream retrieveTempData(String id) - throws SimExplorerStorageException; + public abstract InputStream retrieveTempData(String id) throws SimExplorerStorageException; /** * Retrieve MD5 temp data. * - * @param id - * the id + * @param id the id * * @return the string * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ - public abstract String retrieveMD5TempData(String id) - throws SimExplorerStorageException; + public abstract String retrieveMD5TempData(String id) throws SimExplorerStorageException; /** * Delete temporary data. * - * @param id - * the id + * @param id the id * - * @throws SimExplorerStorageException - * the sim explorer storage exception + * @throws SimExplorerStorageException the sim explorer storage exception */ - public abstract void deleteTempData(String id) - throws SimExplorerStorageException; + public abstract void deleteTempData(String id) throws SimExplorerStorageException; } \ No newline at end of file Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java 2008-02-14 20:18:28 UTC (rev 981) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java 2008-02-14 23:07:20 UTC (rev 982) @@ -98,14 +98,12 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#saveElement(fr.cemagref.simexplorer.is.entities.metadata.MetaData, java.util.Map) */ - public void saveElement(String token, MetaData element, - Map<Attachment, InputStream> attachments) + public void saveElement(String token, MetaData element, Map<Attachment, InputStream> attachments) throws SimExplorerStorageException { // Save all attachments in system for (Map.Entry<Attachment, InputStream> entry : attachments.entrySet()) { - attachmentHandler.storeData(element, entry.getKey(), entry - .getValue()); + attachmentHandler.storeData(element, entry.getKey(), entry.getValue()); } // Parse all attachments for indexing @@ -114,12 +112,10 @@ Attachment attachment = entry.getKey(); if (attachment.getContentType() != null) { - InputStream content = attachmentHandler.retrieveData(element, - attachment); + InputStream content = attachmentHandler.retrieveData(element, attachment); try { // Transform stream into indexable text - Reader reader = attachment.getContentType().renderToText( - content); + Reader reader = attachment.getContentType().renderToText(content); readers.add(reader); } catch (Exception e) { throw new SimExplorerStorageException(e); @@ -149,8 +145,7 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#getMetadata(java.lang.String) */ - public MetaData getMetadata(String token, String uuid) - throws SimExplorerStorageException { + public MetaData getMetadata(String token, String uuid) throws SimExplorerStorageException { MetaData mde = null; Set<MetaData> set = database.findElementsById(uuid, true); if (!set.isEmpty()) { @@ -162,16 +157,14 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#getVersions(java.lang.String) */ - public List<Version> getVersions(String token, String uuid) - throws SimExplorerStorageException { + public List<Version> getVersions(String token, String uuid) throws SimExplorerStorageException { return database.getVersions(uuid); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#getMetadata(java.lang.String, fr.cemagref.simexplorer.is.entities.metadata.Version) */ - public MetaData getMetadata(String token, String uuid, Version version) - throws SimExplorerStorageException { + public MetaData getMetadata(String token, String uuid, Version version) throws SimExplorerStorageException { MetaData mde = database.getElement(uuid, version); return mde; } @@ -179,8 +172,8 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#retrieveData(fr.cemagref.simexplorer.is.entities.metadata.MetaData, java.lang.String) */ - public InputStream retrieveData(String token, MetaData entity, - Attachment attachment) throws SimExplorerStorageException { + public InputStream retrieveData(String token, MetaData entity, Attachment attachment) + throws SimExplorerStorageException { InputStream result = attachmentHandler.retrieveData(entity, attachment); return result; } @@ -188,39 +181,35 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#findFullTextCount(java.lang.String, boolean) */ - public int findFullTextCount(String token, String query, boolean onlyLatest) - throws SimExplorerStorageException { + public int findFullTextCount(String token, String query, boolean onlyLatest) throws SimExplorerStorageException { return database.findElementsByContentSearchCount(query, onlyLatest); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#findFullText(java.lang.String, boolean, int, int, int) */ - public MetaData[] findFullText(String token, String query, - boolean onlyLatest, int indexStart, int count, int dateOrder) - throws SimExplorerStorageException { - MetaData[] result = database.findElementsByContentSearch(query, - onlyLatest, indexStart, count, dateOrder).toArray( - new MetaData[0]); + public MetaData[] findFullText(String token, String query, boolean onlyLatest, int indexStart, int count, + int dateOrder) throws SimExplorerStorageException { + MetaData[] result = database.findElementsByContentSearch(query, onlyLatest, indexStart, count, dateOrder) + .toArray(new MetaData[0]); return result; } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#findElementsByType(java.lang.String, boolean, int, int, int) */ - public MetaData[] findElementsByType(String token, String type, - boolean onlyLatest, int start, int count, int dateOrder) - throws SimExplorerStorageException { - MetaData[] result = database.findElementsByType(type, onlyLatest, - start, count, dateOrder).toArray(new MetaData[0]); + public MetaData[] findElementsByType(String token, String type, boolean onlyLatest, int start, int count, + int dateOrder) throws SimExplorerStorageException { + MetaData[] result = database.findElementsByType(type, onlyLatest, start, count, dateOrder).toArray( + new MetaData[0]); return result; } /* (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 SimExplorerStorageException { + public int findElementsByTypeCount(String token, String type, boolean onlyLatest) + throws SimExplorerStorageException { return database.findElementsByTypeCount(type, onlyLatest); } @@ -229,8 +218,7 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#deleteElements(java.lang.String) */ - public void deleteElements(String token, String uuid) - throws SimExplorerStorageException { + public void deleteElements(String token, String uuid) throws SimExplorerStorageException { List<Version> versions = getVersions(token, uuid); for (Version version : versions) { deleteElement(token, uuid, version); @@ -240,8 +228,7 @@ /* (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 SimExplorerStorageException { + public void deleteElement(String token, String uuid, Version version) throws SimExplorerStorageException { MetaData element = getMetadata(token, uuid, version); List<Attachment> attachments = element.getAttachments(); for (Attachment attachment : attachments) { @@ -269,34 +256,28 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#storeTempData(java.io.InputStream) */ - public String storeTempData(InputStream stream) - throws SimExplorerStorageException { + public String storeTempData(InputStream stream) throws SimExplorerStorageException { String id = UUID.randomUUID().toString(); storeTempData(id, stream); return id; } @Override - public void storeTempData(String id, InputStream stream) - throws SimExplorerStorageException { + public void storeTempData(String id, InputStream stream) throws SimExplorerStorageException { attachmentHandler.storeData(mdTmp, getTmpAttachment(id), stream); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#retrieveTempData(java.lang.String) */ - public InputStream retrieveTempData(String id) - throws SimExplorerStorageException { - InputStream is = attachmentHandler.retrieveData(mdTmp, - getTmpAttachment(id)); + public InputStream retrieveTempData(String id) throws SimExplorerStorageException { + InputStream is = attachmentHandler.retrieveData(mdTmp, getTmpAttachment(id)); return is; } @Override - public String retrieveMD5TempData(String id) - throws SimExplorerStorageException { - String md5 = attachmentHandler.retrieveMD5Data(mdTmp, - getTmpAttachment(id)); + public String retrieveMD5TempData(String id) throws SimExplorerStorageException { + String md5 = attachmentHandler.retrieveMD5Data(mdTmp, getTmpAttachment(id)); return md5; } @@ -310,9 +291,17 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#getElementVersions(java.lang.String, java.lang.String) */ - public Set<MetaData> getElementVersions(String token, String uuid) - throws SimExplorerStorageException { + public Set<MetaData> getElementVersions(String token, String uuid) throws SimExplorerStorageException { return database.findElementsById(uuid, false); } + /* (non-Javadoc) + * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#canCreateSubVersion(java.lang.String, java.lang.String) + */ + @Override + public boolean canCreateSubVersion(String token, String uuid) throws SimExplorerStorageException { + // by default + return true; + } + }
participants (1)
-
glandais@users.labs.libre-entreprise.org