Author: glandais Date: 2008-02-13 14:56:36 +0000 (Wed, 13 Feb 2008) New Revision: 923 Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceHelper.java trunk/simexplorer-is/simexplorer-is-storage/src/resources/properties/config.properties Log: Business rules Admin mail Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java 2008-02-13 14:38:24 UTC (rev 922) +++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java 2008-02-13 14:56:36 UTC (rev 923) @@ -32,6 +32,7 @@ import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import javax.ejb.TransactionAttributeType; +import javax.mail.Address; import javax.mail.MessagingException; import javax.mail.Transport; import javax.mail.internet.InternetAddress; @@ -43,6 +44,7 @@ import org.codelutin.i18n.I18n; import org.jboss.annotation.ejb.RemoteBinding; +import fr.cemagref.simexplorer.is.storage.util.Config; import fr.cemagref.simexplorer.is.security.dao.DaoSecurity; import fr.cemagref.simexplorer.is.security.entities.Group; import fr.cemagref.simexplorer.is.security.entities.LoginAction; @@ -68,20 +70,16 @@ /** * Gets the mail content with password. * - * @param login - * the login - * @param password - * the password + * @param login the login + * @param password the password * * @return the mail content with password */ private String getMailContentWithPassword(String login, String password) { StringBuffer sb = new StringBuffer(""); sb.append(_("simexplorer.service.mail.header")).append("\n"); - sb.append(_("simexplorer.service.mail.login")).append(" : ").append( - login).append("\n"); - sb.append(_("simexplorer.service.mail.password")).append(" : ").append( - password).append("\n"); + sb.append(_("simexplorer.service.mail.login")).append(" : ").append(login).append("\n"); + sb.append(_("simexplorer.service.mail.password")).append(" : ").append(password).append("\n"); sb.append(_("simexplorer.service.mail.footer")).append("\n"); return sb.toString(); } @@ -89,20 +87,16 @@ /** * Gets the mail content request account. * - * @param login - * the login - * @param mail - * the mail + * @param login the login + * @param mail the mail * * @return the mail content request accont */ private String getMailContentRequestAccount(String login, String mail) { StringBuffer sb = new StringBuffer(""); sb.append(_("simexplorer.service.mail.requestheader")).append("\n"); - sb.append(_("simexplorer.service.mail.login")).append(" : ").append( - login).append("\n"); - sb.append(_("simexplorer.service.mail.mail")).append(" : ") - .append(mail).append("\n"); + sb.append(_("simexplorer.service.mail.login")).append(" : ").append(login).append("\n"); + sb.append(_("simexplorer.service.mail.mail")).append(" : ").append(mail).append("\n"); sb.append(_("simexplorer.service.mail.requestfooter")).append("\n"); return sb.toString(); } @@ -110,24 +104,22 @@ /** * Send mail. * - * @param mail - * the mail - * @param subject - * the subject - * @param content - * the content + * @param subject the subject + * @param content the content + * @param mailFrom the mail from + * @param mailRecipient the mail recipient * - * @throws SimExplorerServiceException - * the sim explorer service exception + * @throws SimExplorerServiceException the sim explorer service exception */ - private void sendMail(String mail, String subject, String content) + private void sendMail(String mailFrom, String mailRecipient, String subject, String content) throws SimExplorerServiceException { try { - javax.mail.Session mailSession = (javax.mail.Session) new InitialContext() - .lookup("java:/Mail"); + 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(mail, false)); + Address from = InternetAddress.parse(mailFrom)[0]; + msg.setFrom(from); + ; + msg.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(mailRecipient, false)); msg.setSubject(subject); msg.setContent(content, "text/plain"); msg.setHeader("X-Mailer", "JavaMailer"); @@ -143,16 +135,13 @@ /** * Compute hash. * - * @param clearString - * the clear string + * @param clearString the clear string * * @return the string * - * @throws SimExplorerServiceException - * the sim explorer service exception + * @throws SimExplorerServiceException the sim explorer service exception */ - private String computeHash(String clearString) - throws SimExplorerServiceException { + private String computeHash(String clearString) throws SimExplorerServiceException { MessageDigest messageDigest = null; try { messageDigest = MessageDigest.getInstance("SHA-1"); @@ -178,18 +167,14 @@ /** * Can admin group. * - * @param token - * the token - * @param id - * the id + * @param token the token + * @param id the id * * @return true, if successful * - * @throws SimExplorerServiceException - * the sim explorer service exception + * @throws SimExplorerServiceException the sim explorer service exception */ - private boolean canAdminGroup(String token, Integer id) - throws SimExplorerServiceException { + private boolean canAdminGroup(String token, Integer id) throws SimExplorerServiceException { User loggedUser = getLoggedUser(token); if (loggedUser != null) { if (loggedUser.isSuperAdmin()) { @@ -205,10 +190,8 @@ /** * User owner of group. * - * @param loggedUser - * the logged user - * @param group - * the group + * @param loggedUser the logged user + * @param group the group * * @return true, if successful */ @@ -228,18 +211,14 @@ /** * Can admin user. * - * @param token - * the token - * @param id - * the id + * @param token the token + * @param id the id * * @return true, if successful * - * @throws SimExplorerServiceException - * the sim explorer service exception + * @throws SimExplorerServiceException the sim explorer service exception */ - private boolean canAdminUser(String token, Integer id) - throws SimExplorerServiceException { + private boolean canAdminUser(String token, Integer id) throws SimExplorerServiceException { User loggedUser = getLoggedUser(token); if (loggedUser != null) { if (loggedUser.isSuperAdmin()) { @@ -261,10 +240,8 @@ /** * Removes the user from group. * - * @param user - * the user - * @param group - * the group + * @param user the user + * @param group the group */ private void removeUserFromGroup(User user, Group group) { List<Group> toRemove = new ArrayList<Group>(); @@ -281,26 +258,21 @@ /** * Can delete group. * - * @param token - * the token - * @param id - * the id + * @param token the token + * @param id the id * * @return true, if successful * @throws SimExplorerServiceException */ - private boolean canDeleteGroup(String token, Integer id) - throws SimExplorerServiceException { + private boolean canDeleteGroup(String token, Integer id) throws SimExplorerServiceException { return canAdminGroup(token, id); } /** * Delete group impl. * - * @param token - * the token - * @param id - * the id + * @param token the token + * @param id the id */ private void deleteGroupImpl(String token, Integer id) { dao.deleteGroup(id); @@ -309,41 +281,33 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#deleteGroup(java.lang.String, java.lang.Integer) */ - public void deleteGroup(String token, Integer id) - throws SimExplorerServiceException { + public void deleteGroup(String token, Integer id) throws SimExplorerServiceException { if (canDeleteGroup(token, id)) { deleteGroupImpl(token, id); } else { - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } } /** * Can delete user. * - * @param token - * the token - * @param id - * the id + * @param token the token + * @param id the id * * @return true, if successful * - * @throws SimExplorerServiceException - * the sim explorer service exception + * @throws SimExplorerServiceException the sim explorer service exception */ - private boolean canDeleteUser(String token, Integer id) - throws SimExplorerServiceException { + private boolean canDeleteUser(String token, Integer id) throws SimExplorerServiceException { return canAdminUser(token, id); } /** * Delete user impl. * - * @param token - * the token - * @param id - * the id + * @param token the token + * @param id the id */ private void deleteUserImpl(String token, Integer id) { dao.deleteUser(id); @@ -352,27 +316,23 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#deleteUser(java.lang.String, java.lang.Integer) */ - public void deleteUser(String token, Integer id) - throws SimExplorerServiceException { + public void deleteUser(String token, Integer id) throws SimExplorerServiceException { if (canDeleteUser(token, id)) { deleteUserImpl(token, id); } else { - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } } /** * Can view elements. * - * @param token - * the token + * @param token the token * * @return true, if successful * @throws SimExplorerServiceException */ - private boolean canViewElements(String token) - throws SimExplorerServiceException { + private boolean canViewElements(String token) throws SimExplorerServiceException { User loggedUser = getLoggedUser(token); // boolean canView = loggedUser.isAdmin() || loggedUser.isSuperAdmin(); // return canView; @@ -382,68 +342,57 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#getGroup(java.lang.String, java.lang.Integer) */ - public Group getGroup(String token, Integer id) - throws SimExplorerServiceException { + public Group getGroup(String token, Integer id) throws SimExplorerServiceException { if (canViewElements(token)) { Group group = dao.getGroup(id); return group; } - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#getGroup(java.lang.String, java.lang.String) */ - public Group getGroup(String token, String name) - throws SimExplorerServiceException { + public Group getGroup(String token, String name) throws SimExplorerServiceException { if (canViewElements(token)) { Group group = dao.getGroup(name); return group; } - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#getUser(java.lang.String, java.lang.Integer) */ - public User getUser(String token, Integer id) - throws SimExplorerServiceException { + public User getUser(String token, Integer id) throws SimExplorerServiceException { if (canViewElements(token)) { User user = dao.getUser(id); return user; } - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#getUser(java.lang.String, java.lang.String) */ - public User getUser(String token, String login) - throws SimExplorerServiceException { + public User getUser(String token, String login) throws SimExplorerServiceException { if (canViewElements(token)) { User user = dao.getUser(login); return user; } - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } /** * Can save element. * - * @param token - * the token + * @param token the token * * @return true, if successful * - * @throws SimExplorerServiceException - * the sim explorer service exception + * @throws SimExplorerServiceException the sim explorer service exception */ - private boolean canSaveElement(String token) - throws SimExplorerServiceException { + private boolean canSaveElement(String token) throws SimExplorerServiceException { User loggedUser = getLoggedUser(token); boolean canView = loggedUser.isAdmin() || loggedUser.isSuperAdmin(); return canView; @@ -452,13 +401,11 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#saveGroup(java.lang.String, java.lang.String) */ - public Group saveGroup(String token, String name) - throws SimExplorerServiceException { + public Group saveGroup(String token, String name) throws SimExplorerServiceException { if (canSaveElement(token)) { Group oldGroup = dao.getGroup(name); if (oldGroup != null) { - throw new SimExplorerServiceException( - _("simexplorer.service.business.groupexist")); + throw new SimExplorerServiceException(_("simexplorer.service.business.groupexist")); } Group group = new Group(); @@ -468,28 +415,25 @@ group = getGroup(token, group.getId()); return group; } - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#saveUser(java.lang.String, java.lang.String, java.lang.String) */ - public User saveUser(String token, String login, String mail) - throws SimExplorerServiceException { + public User saveUser(String token, String login, String mail) throws SimExplorerServiceException { if (canSaveElement(token)) { User oldUser = dao.getUser(login); if (oldUser != null) { - throw new SimExplorerServiceException( - _("simexplorer.service.business.userexist")); + throw new SimExplorerServiceException(_("simexplorer.service.business.userexist")); } User user = new User(); user.setLogin(login); user.setMail(mail); String password = generatePassword(); - sendMail(mail, _("simexplorer.service.mail.subject"), - getMailContentWithPassword(login, password)); + sendMail(Config.getProperties().getProperty("simexplorer.adminmail"), mail, + _("simexplorer.service.mail.subject"), getMailContentWithPassword(login, password)); String passwordHash = computeHash(password); user.setPasswordHash(passwordHash); user.setAdmin(false); @@ -498,62 +442,50 @@ user = getUser(token, user.getId()); return user; } - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } /** * Can update group. * - * @param token - * the token - * @param id - * the id + * @param token the token + * @param id the id * * @return true, if successful * - * @throws SimExplorerServiceException - * the sim explorer service exception + * @throws SimExplorerServiceException the sim explorer service exception */ - private boolean canUpdateGroup(String token, Integer id) - throws SimExplorerServiceException { + private boolean canUpdateGroup(String token, Integer id) throws SimExplorerServiceException { return canAdminGroup(token, id); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#updateGroup(java.lang.String, fr.cemagref.simexplorer.is.security.entities.Group) */ - public Group updateGroup(String token, Group group) - throws SimExplorerServiceException { + public Group updateGroup(String token, Group group) throws SimExplorerServiceException { if (canUpdateGroup(token, group.getId())) { return dao.updateGroup(group); } - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } /** * Can update user. * - * @param token - * the token - * @param user - * the user + * @param token the token + * @param user the user * * @return true, if successful * - * @throws SimExplorerServiceException - * the sim explorer service exception + * @throws SimExplorerServiceException the sim explorer service exception */ - private boolean canUpdateUser(String token, User user) - throws SimExplorerServiceException { + private boolean canUpdateUser(String token, User user) throws SimExplorerServiceException { if (canAdminUser(token, user.getId())) { if (getLoggedUser(token).isSuperAdmin()) { return true; } User oldUser = dao.getUser(user.getId()); - if (oldUser.isAdmin() == user.isAdmin() - && oldUser.isSuperAdmin() == user.isSuperAdmin()) { + if (oldUser.isAdmin() == user.isAdmin() && oldUser.isSuperAdmin() == user.isSuperAdmin()) { return true; } } @@ -563,13 +495,11 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#updateUser(java.lang.String, fr.cemagref.simexplorer.is.security.entities.User) */ - public User updateUser(String token, User user) - throws SimExplorerServiceException { + public User updateUser(String token, User user) throws SimExplorerServiceException { if (canUpdateUser(token, user)) { return dao.updateUser(user); } - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } /* (non-Javadoc) @@ -584,15 +514,13 @@ if (loggedUser != null) { return loggedUser; } - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } /** * Check super admin. * - * @throws SimExplorerServiceException - * the sim explorer service exception + * @throws SimExplorerServiceException the sim explorer service exception */ private void checkSuperAdmin() throws SimExplorerServiceException { if (dao.getUser("superadmin") == null) { @@ -611,8 +539,7 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#loginUser(java.lang.String, java.lang.String) */ - public String loginUser(String login, String password) - throws SimExplorerServiceException { + public String loginUser(String login, String password) throws SimExplorerServiceException { if (!superAdminCheck) { I18n.initISO88591("fr", "FR"); checkSuperAdmin(); @@ -637,11 +564,10 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#requestAccount(java.lang.String, java.lang.String) */ - public void requestAccount(String login, String mail) - throws SimExplorerServiceException { + public void requestAccount(String login, String mail) throws SimExplorerServiceException { User superadmin = dao.getUser("superadmin"); - sendMail(superadmin.getMail(), _("simexplorer.service.mail.subject"), - getMailContentRequestAccount(login, mail)); + sendMail(Config.getProperties().getProperty("simexplorer.adminmail"), superadmin.getMail(), + _("simexplorer.service.mail.subject"), getMailContentRequestAccount(login, mail)); } /* (non-Javadoc) @@ -657,19 +583,17 @@ /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#resetPassword(java.lang.String, java.lang.String) */ - public void resetPassword(String token, String login) - throws SimExplorerServiceException { + public void resetPassword(String token, String login) throws SimExplorerServiceException { User user = getUser(token, login); if (canAdminUser(token, user.getId())) { String password = generatePassword(); - sendMail(user.getMail(), _("simexplorer.service.mail.subject"), - getMailContentWithPassword(login, password)); + sendMail(Config.getProperties().getProperty("simexplorer.adminmail"), user.getMail(), + _("simexplorer.service.mail.subject"), getMailContentWithPassword(login, password)); String passwordHash = computeHash(password); user.setPasswordHash(passwordHash); dao.updateUser(user); } else { - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } } @@ -682,22 +606,19 @@ Group[] result = groups.toArray(new Group[groups.size()]); return result; } - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#getGroupsOwnedBy(java.lang.String, fr.cemagref.simexplorer.is.security.entities.User) */ - public Group[] getGroupsOwnedBy(String token, User user) - throws SimExplorerServiceException { + public Group[] getGroupsOwnedBy(String token, User user) throws SimExplorerServiceException { if (canViewElements(token)) { List<Group> list = dao.getGroupsOwnedBy(user); Group[] groups = list.toArray(new Group[list.size()]); return groups; } - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } /* (non-Javadoc) @@ -709,29 +630,25 @@ User[] arrayUsers = users.toArray(new User[users.size()]); return arrayUsers; } - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#getUsersOfGroup(java.lang.String, fr.cemagref.simexplorer.is.security.entities.Group) */ - public User[] getUsersOfGroup(String token, Group group) - throws SimExplorerServiceException { + public User[] getUsersOfGroup(String token, Group group) throws SimExplorerServiceException { if (canViewElements(token)) { List<User> usersOfGroup = dao.getUsersOfGroup(group); User[] array = usersOfGroup.toArray(new User[usersOfGroup.size()]); return array; } - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#setUsersOfGroup(java.lang.String, fr.cemagref.simexplorer.is.security.entities.Group, java.lang.Integer[]) */ - public void setUsersOfGroup(String token, Group group, - Integer[] usersInGroup) throws SimExplorerServiceException { + public void setUsersOfGroup(String token, Group group, Integer[] usersInGroup) throws SimExplorerServiceException { if (canUpdateGroup(token, group.getId())) { List<Integer> newUsers = new ArrayList<Integer>(); newUsers.addAll(Arrays.asList(usersInGroup)); @@ -768,16 +685,14 @@ dao.updateUser(user); } } else { - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#setGroupsOfUser(java.lang.String, fr.cemagref.simexplorer.is.security.entities.User, java.lang.Integer[]) */ - public void setGroupsOfUser(String token, User user, Integer[] groupsIds) - throws SimExplorerServiceException { + public void setGroupsOfUser(String token, User user, Integer[] groupsIds) throws SimExplorerServiceException { if (canUpdateUser(token, user)) { User realUser = dao.getUser(user.getId()); realUser.getGroups().clear(); @@ -787,42 +702,36 @@ } dao.updateUser(realUser); } else { - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#getGroupsOfUser(java.lang.String, fr.cemagref.simexplorer.is.security.entities.User) */ - public Group[] getGroupsOfUser(String token, User user) - throws SimExplorerServiceException { + public Group[] getGroupsOfUser(String token, User user) throws SimExplorerServiceException { if (canViewElements(token)) { List<Group> list = dao.getGroupsOfUser(user); return list.toArray(new Group[list.size()]); } - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#getGroupsOfGroup(java.lang.String, fr.cemagref.simexplorer.is.security.entities.Group) */ - public Group[] getGroupsOfGroup(String token, Group group) - throws SimExplorerServiceException { + public Group[] getGroupsOfGroup(String token, Group group) throws SimExplorerServiceException { if (canViewElements(token)) { List<Group> groupsOfGroup = dao.getGroupsOfGroup(group); return groupsOfGroup.toArray(new Group[groupsOfGroup.size()]); } - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.AuthenticationService#setGroupsOfGroup(java.lang.String, fr.cemagref.simexplorer.is.security.entities.Group, java.lang.Integer[]) */ - public void setGroupsOfGroup(String token, Group group, Integer[] groupsIds) - throws SimExplorerServiceException { + public void setGroupsOfGroup(String token, Group group, Integer[] groupsIds) throws SimExplorerServiceException { if (canUpdateGroup(token, group.getId())) { Group realGroup = dao.getGroup(group.getId()); realGroup.getGroups().clear(); @@ -832,8 +741,7 @@ } dao.updateGroup(realGroup); } else { - throw new SimExplorerServiceException( - _("simexplorer.service.security.norights")); + throw new SimExplorerServiceException(_("simexplorer.service.security.norights")); } } 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-13 14:38:24 UTC (rev 922) +++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-02-13 14:56:36 UTC (rev 923) @@ -492,7 +492,14 @@ } else { // trying to save a version with same hash but in superior version Version versionToUpgrade = previousVersion.getVersion().clone(); + + // 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); + // update already stored element with element being saved version + previousVersion.setLatest(true); previousVersion.setVersion(metaData.getVersion().toString()); // do not delete previous version, but create a copy of it with new version update(token, previousVersion.getUuid(), versionToUpgrade, previousVersion, false); Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceHelper.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceHelper.java 2008-02-13 14:38:24 UTC (rev 922) +++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceHelper.java 2008-02-13 14:56:36 UTC (rev 923) @@ -39,14 +39,27 @@ */ public static MetaData exportElementTo(String token, StorageService fromService, StorageService toService, String uuid, String version) throws SimExplorerServiceException { + // Extract element from source service InputStream fromElement = fromService.retrieveElementFull(token, uuid, version); + // Store element in remote service MetaData toElement = toService.saveElement(token, new SimExplorerServiceStream(fromElement)); - fromService.update(token, uuid, Version.valueOf(version), toElement, false); + + // fromElement has to be updated + if (!toElement.getUuid().equals(uuid) || !toElement.getVersion().equals(Version.valueOf(version))) { + MetaData previousVersion = fromService.getMetadata(token, uuid, version); + previousVersion.setLatest(false); + fromService.update(token, previousVersion.getUuid(), previousVersion.getVersion(), previousVersion, true); + + // Update element in source service, from what remote service returns on export + toElement.setLatest(true); + fromService.update(token, uuid, Version.valueOf(version), toElement, false); + } + return toElement; } protected StorageServiceHelper() { // not instanciable } - + } Modified: trunk/simexplorer-is/simexplorer-is-storage/src/resources/properties/config.properties =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/resources/properties/config.properties 2008-02-13 14:38:24 UTC (rev 922) +++ trunk/simexplorer-is/simexplorer-is-storage/src/resources/properties/config.properties 2008-02-13 14:56:36 UTC (rev 923) @@ -1,3 +1,4 @@ simexplorer.db=/var/local/simexplorer/db1 simexplorer.data=/var/local/simexplorer/data1/ simexplorer.optimizeperiod=3600 +simexplorer.adminmail=landais at codelutin.com
participants (1)
-
glandais@users.labs.libre-entreprise.org