branch feature/6012-create-user created (now 3b099c5)
This is an automated email from the git hooks/post-receive script. New change to branch feature/6012-create-user in repository coselmar. See http://git.codelutin.com/coselmar.git at 3b099c5 prepare User Service This branch includes the following new commits: new 3b099c5 prepare User Service The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 3b099c50c0979ed3dc43d58ba02e8763afe15969 Author: Yannick Martel <martel@©odelutin.com> Date: Mon Nov 10 17:50:19 2014 +0100 prepare User Service -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/6012-create-user in repository coselmar. See http://git.codelutin.com/coselmar.git commit 3b099c50c0979ed3dc43d58ba02e8763afe15969 Author: Yannick Martel <martel@©odelutin.com> Date: Mon Nov 10 17:50:19 2014 +0100 prepare User Service --- .../src/main/xmi/coselmar-model.zargo | Bin 5234 -> 5991 bytes .../java/fr/ifremer/coselmar/beans/UserBean.java | 73 ++++++++++++++++++ .../coselmar/converter/BeanEntityConverter.java | 12 +++ .../coselmar/services/v1/UserWebService.java | 85 +++++++++++++++++++++ 4 files changed, 170 insertions(+) diff --git a/coselmar-persistence/src/main/xmi/coselmar-model.zargo b/coselmar-persistence/src/main/xmi/coselmar-model.zargo index 82b4570..0ddcf03 100644 Binary files a/coselmar-persistence/src/main/xmi/coselmar-model.zargo and b/coselmar-persistence/src/main/xmi/coselmar-model.zargo differ diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/UserBean.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/UserBean.java new file mode 100644 index 0000000..81246b8 --- /dev/null +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/UserBean.java @@ -0,0 +1,73 @@ +package fr.ifremer.coselmar.beans; + +import java.io.Serializable; + +/** + * @author ymartel <martel@codelutin.com> + */ +public class UserBean implements Serializable { + + protected String id; + protected String firstName; + protected String name; + protected String mail; + protected String role; + protected String qualification; + + public UserBean(String id, String firstName, String name, String mail, String role, String qualification) { + this.id = id; + this.firstName = firstName; + this.name = name; + this.mail = mail; + this.role = role; + this.qualification = qualification; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMail() { + return mail; + } + + public void setMail(String mail) { + this.mail = mail; + } + + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } + + public String getQualification() { + return qualification; + } + + public void setQualification(String qualification) { + this.qualification = qualification; + } +} diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java index 26c884a..ddc7ce6 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java @@ -3,7 +3,9 @@ package fr.ifremer.coselmar.converter; import java.util.Date; import fr.ifremer.coselmar.beans.DocumentBean; +import fr.ifremer.coselmar.beans.UserBean; import fr.ifremer.coselmar.persistence.entity.Document; +import fr.ifremer.coselmar.persistence.entity.User; /** * @author ymartel <martel@codelutin.com> @@ -22,4 +24,14 @@ public class BeanEntityConverter { document.getMimeType()); } + public static UserBean toBean(User user) { + String userLightId = user.getTopiaId().replace(User.class.getCanonicalName() + "_", ""); + return new UserBean(userLightId, + user.getFirstname(), + user.getName(), + user.getMail(), + user.getRole().name(), + user.getQualification()); + } + } diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UserWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UserWebService.java new file mode 100644 index 0000000..0005b1f --- /dev/null +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UserWebService.java @@ -0,0 +1,85 @@ +package fr.ifremer.coselmar.services.v1; + +import java.util.ArrayList; +import java.util.List; + +import com.google.common.base.Preconditions; +import fr.ifremer.coselmar.beans.UserBean; +import fr.ifremer.coselmar.converter.BeanEntityConverter; +import fr.ifremer.coselmar.persistence.entity.User; +import fr.ifremer.coselmar.persistence.entity.UserRole; +import fr.ifremer.coselmar.services.CoselmarWebServiceSupport; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; + +import static org.apache.commons.logging.LogFactory.getLog; + +/** + * @author ymartel <martel@codelutin.com> + */ +public class UserWebService extends CoselmarWebServiceSupport { + + private static final Log log = getLog(UserWebService.class); + + public UserBean getUser(String userId) { + + // reconstitute full id + String fullId = User.class.getCanonicalName() + "_" + userId; + + User user = getUserDao().forTopiaIdEquals(fullId).findUnique(); + UserBean userBean = BeanEntityConverter.toBean(user); + return userBean; + } + + public List<UserBean> getUsers(String searchKey) { + + List<User> userList; + if (StringUtils.isNotBlank(searchKey)) { + //TODO find on all parts ? + userList = new ArrayList<>(); + } else { + userList = getUserDao().findAll(); + } + List<UserBean> result = new ArrayList<>(userList.size()); + + for (User user : userList) { + UserBean userBean = BeanEntityConverter.toBean(user); + result.add(userBean); + } + + return result; + } + + public void addUser(UserBean user) { + Preconditions.checkNotNull(user); + + User userEntity = getUserDao().create(); + + userEntity.setFirstname(user.getFirstName()); + userEntity.setName(user.getName()); + userEntity.setMail(user.getMail()); + userEntity.setRole(UserRole.valueOf(user.getRole().toUpperCase())); + userEntity.setQualification(user.getQualification()); + + //generate a password & a salt + + commit(); + + // send mail to user with password + } + + public void changePassword() { + //TODO ymartel + } + + public void deleteUser(String userId) { + + // reconstitute full id + String fullId = User.class.getCanonicalName() + "_" + userId; + + User user = getUserDao().forTopiaIdEquals(fullId).findUnique(); + getUserDao().delete(user); + + commit(); + } +} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm