Commit 21d51a79977b44ce9a8e43c05d35a6983592e55e

Authored by Pierrick
1 parent 1290ab4d

Add getAllExperienceType / removeUser / add parameterCheck

skilldr-data_model/src/main/java/eu/totoandco/data/parameter/ParameterName.java
... ... @@ -21,7 +21,8 @@ package eu.totoandco.data.parameter;
21 21 *
22 22 */
23 23 public enum ParameterName {
24   - ABILITY_SIGNIN(1);
  24 + ABILITY_SIGNIN(1),
  25 + ABILITY_RH_UPGRADE_USER(2);
25 26 private int id;
26 27  
27 28 private ParameterName(int id) {
... ...
skilldr-properties/src/main/resources/buildScript.sql
... ... @@ -86,4 +86,6 @@ INSERT INTO skill (`id`, `name`, `idJob`) VALUES (1,"Java",1);
86 86 INSERT INTO user (`id`, `login`, `password`, `firstname`, `name`, `tag`, `url`, `creationDate`, `lastUpdate`, `idrole`, `idJob`)
87 87 VALUES (1, "toto@totoandco.eu", "toto", "Toto", "AndCo", "TOTOTAG", "www.totoandco.eu/skilldr", "2015-01-05 14:54:27","2015-01-05 14:54:27", 1, 1);
88 88 INSERT INTO experienceType (`id`, `name`, `weight`) VALUES (1, "Stage", 2);
89   -INSERT INTO userSkill (`idUser`, `idSkill`, `period`, `date`, `idType`) VALUES (1, 1, 2, "2015-01-05 14:54:27", 1);
90 89 \ No newline at end of file
  90 +INSERT INTO userSkill (`idUser`, `idSkill`, `period`, `date`, `idType`) VALUES (1, 1, 2, "2015-01-05 14:54:27", 1);
  91 +INSERT INTO parameterSkilldr (`id`, `value`, `descriptor`) VALUES (1, 0,"Ability to signin for extern user");
  92 +INSERT INTO parameterSkilldr (`id`, `value`, `descriptor`) VALUES (2, 0,"Ability to upgrade an USER to RH");
91 93 \ No newline at end of file
... ...
skilldr-rs/src/main/java/eu/totoandco/rs/ExperienceTypeEndPoint.java
... ... @@ -16,12 +16,17 @@
16 16 */
17 17 package eu.totoandco.rs;
18 18  
  19 +import java.util.List;
  20 +
19 21 import javax.ejb.EJB;
20 22 import javax.ejb.Stateless;
  23 +import javax.servlet.http.HttpServletRequest;
21 24 import javax.ws.rs.DELETE;
22 25 import javax.ws.rs.FormParam;
  26 +import javax.ws.rs.GET;
23 27 import javax.ws.rs.POST;
24 28 import javax.ws.rs.Path;
  29 +import javax.ws.rs.core.Context;
25 30  
26 31 import eu.totoandco.business.ExperienceTypeManager;
27 32 import eu.totoandco.check.ParameterCheck;
... ... @@ -41,6 +46,12 @@ public class ExperienceTypeEndPoint extends EndPoint {
41 46 @EJB
42 47 ExperienceTypeManager experienceTypeManager;
43 48  
  49 + /**
  50 + * Add a new experience type in DB
  51 + * @param experienceType Name of new experience type
  52 + * @param value coefficient of new experience type
  53 + * @return new domain created
  54 + */
44 55 @POST
45 56 @Path("/p/experienceType")
46 57 public ExperienceType addExperienceType(
... ... @@ -59,7 +70,11 @@ public class ExperienceTypeEndPoint extends EndPoint {
59 70 }
60 71 return experienceTypeManager.addExperienceType(nameExperienceType, value);
61 72 }
62   -
  73 +
  74 + /**
  75 + * Remove an existing experience type in DB
  76 + * @param idExperienceType The id of experience type to remove
  77 + */
63 78 @DELETE
64 79 @Path("/p/experienceType")
65 80 public void removeExperienceType(
... ... @@ -71,4 +86,14 @@ public class ExperienceTypeEndPoint extends EndPoint {
71 86 }
72 87 experienceTypeManager.removeExperienceType(idExperienceType);
73 88 }
  89 +
  90 + /**
  91 + * Get all experience type
  92 + * @return the list of the experience type
  93 + */
  94 + @GET
  95 + @Path("/experienceType")
  96 + public List<ExperienceType> getAllExperienceType(@Context HttpServletRequest request) {
  97 + return experienceTypeManager.getAllExperienceType();
  98 + }
74 99 }
... ...
skilldr-rs/src/main/java/eu/totoandco/rs/SkillEndPoint.java
... ... @@ -75,6 +75,7 @@ public class SkillEndPoint extends EndPoint {
75 75 RestParameterCheck.checkNotNegativeOrZero(idSkill);
76 76 skillManager.removeSkill(idSkill);
77 77 }
  78 +
78 79 /**
79 80 * Associate a user and a skill with an experience
80 81 * @param idSkill skill to associate
... ... @@ -122,7 +123,7 @@ public class SkillEndPoint extends EndPoint {
122 123 */
123 124 @DELETE
124 125 @Path("/p/userSkill/{idSkill}")
125   - public void removeExperience(@PathParam("idSkill") int idSkill,
  126 + public void removeUserSkill(@PathParam("idSkill") int idSkill,
126 127 @Context HttpServletRequest request) {
127 128 RestParameterCheck.checkNotNegativeOrZero(idSkill);
128 129 skillManager.removeUserSkill(
... ...
skilldr-rs/src/main/java/eu/totoandco/rs/UserEndPoint.java
... ... @@ -21,6 +21,7 @@ import java.util.List;
21 21 import javax.ejb.EJB;
22 22 import javax.ejb.Stateless;
23 23 import javax.servlet.http.HttpServletRequest;
  24 +import javax.ws.rs.DELETE;
24 25 import javax.ws.rs.FormParam;
25 26 import javax.ws.rs.GET;
26 27 import javax.ws.rs.POST;
... ... @@ -30,6 +31,7 @@ import javax.ws.rs.core.Context;
30 31  
31 32 import eu.totoandco.business.UserManager;
32 33 import eu.totoandco.check.ParameterCheck;
  34 +import eu.totoandco.check.RestParameterCheck;
33 35 import eu.totoandco.exception.ExceptionLevel;
34 36 import eu.totoandco.exception.MessageCarrier;
35 37 import eu.totoandco.exception.MessageText;
... ... @@ -39,6 +41,7 @@ import eu.totoandco.model.User;
39 41  
40 42 /**
41 43 * WebService Class responsible for managing access to User Model data
  44 + *
42 45 * @author Pierrick Knecht
43 46 * @author Ronan Presle (ronan.presle@ttmail.eu)
44 47 */
... ... @@ -71,17 +74,19 @@ public class UserEndPoint extends EndPoint {
71 74 throw new RestException(MessageCarrier
72 75 .message(MessageText.ERROR_STRING_EMPTY)
73 76 .level(ExceptionLevel.INFO).build());
74   - }
  77 + }
75 78 User userSession = userAccess.connectUser(login, pwd);
76 79 if (userSession != null) {
77 80 request.getSession(true).setAttribute(USERSESSION, userSession);
78 81 }
79 82 return userSession;
80 83 }
81   -
  84 +
82 85 /**
83 86 * Return the currently connected user
84   - * @param request User's context
  87 + *
  88 + * @param request
  89 + * User's context
85 90 * @return the user connected.
86 91 */
87 92 @GET
... ... @@ -120,22 +125,44 @@ public class UserEndPoint extends EndPoint {
120 125 .message(MessageText.ERROR_STRING_EMPTY)
121 126 .level(ExceptionLevel.INFO).build());
122 127 }
123   - User userSession = userAccess.addUser(login, pwd, firstname,name);
  128 + User userSession = userAccess.addUser(login, pwd, firstname, name);
124 129 if (userSession != null) {
125 130 request.getSession(true).setAttribute(USERSESSION, userSession);
126 131 }
127 132 return userSession;
128 133 }
129   -
  134 +
  135 + /**
  136 + * Remove an User in DB
  137 + *
  138 + * @param idUser User's id to delete
  139 + * @param request User's context
  140 + * @return True if deleted else return false.
  141 + */
  142 + @DELETE
  143 + @Path("/p/user")
  144 + public boolean removeUser(@FormParam("idUser") int idUser,
  145 + @Context HttpServletRequest request) {
  146 + RestParameterCheck.checkNotNegativeOrZero(idUser);
  147 + if (!ParameterCheck.checkNotNull(idUser)) {
  148 + throw new RestException(MessageCarrier
  149 + .message(MessageText.ERROR_OBJECT_NULL)
  150 + .level(ExceptionLevel.INFO).build());
  151 + }
  152 + return userAccess.removeUser((User) request.getSession(false)
  153 + .getAttribute(USERSESSION), idUser);
  154 + }
  155 +
130 156 /**
131 157 * Add a tmp user and start a session
132   - * @param request
133   - * @return
  158 + *
  159 + * @param request User's context
  160 + * @return New user created
134 161 */
135 162 @POST
136 163 @Path("/userTmp")
137 164 public User addUserTmp(@Context HttpServletRequest request) {
138   - User userSession = userAccess.addUser(null,null,null,null);
  165 + User userSession = userAccess.addUser(null, null, null, null);
139 166 if (userSession != null) {
140 167 request.getSession(true).setAttribute(USERSESSION, userSession);
141 168 }
... ... @@ -195,14 +222,15 @@ public class UserEndPoint extends EndPoint {
195 222 .message(MessageText.ERROR_STRING_EMPTY)
196 223 .level(ExceptionLevel.INFO).build());
197 224 }
198   - return userAccess.updateUser(
199   - (User) request.getSession(false).getAttribute(USERSESSION), login,
200   - pwd, firstname, name);
  225 + return userAccess.updateUser((User) request.getSession(false)
  226 + .getAttribute(USERSESSION), login, pwd, firstname, name);
201 227 }
202   -
  228 +
203 229 /**
204 230 * Get all the skill of the current user
205   - * @param request User's context
  231 + *
  232 + * @param request
  233 + * User's context
206 234 * @return the list of the user's skills
207 235 */
208 236 @GET
... ...
skilldr-service/src/main/java/eu/totoandco/business/ExperienceTypeManager.java
... ... @@ -16,6 +16,8 @@
16 16 */
17 17 package eu.totoandco.business;
18 18  
  19 +import java.util.List;
  20 +
19 21 import javax.ejb.EJB;
20 22 import javax.ejb.LocalBean;
21 23 import javax.ejb.Stateless;
... ... @@ -55,4 +57,12 @@ public class ExperienceTypeManager {
55 57 et.setId(idExperienceType);
56 58 experienceTypeModel.remove(et);
57 59 }
  60 +
  61 + /**
  62 + * Get all experience type in DB
  63 + * @return the list of the experience type
  64 + */
  65 + public List<ExperienceType> getAllExperienceType() {
  66 + return experienceTypeModel.getAll(ExperienceType.class);
  67 + }
58 68 }
... ...
skilldr-service/src/main/java/eu/totoandco/business/UserManager.java
... ... @@ -6,8 +6,10 @@ import javax.ejb.EJB;
6 6 import javax.ejb.LocalBean;
7 7 import javax.ejb.Stateless;
8 8  
  9 +import eu.totoandco.cache.ParameterCache;
9 10 import eu.totoandco.check.ParameterCheck;
10 11 import eu.totoandco.data.Role;
  12 +import eu.totoandco.data.parameter.ParameterName;
11 13 import eu.totoandco.entitymanager.UserAccess;
12 14 import eu.totoandco.exception.ExceptionLevel;
13 15 import eu.totoandco.exception.MessageCarrier;
... ... @@ -28,6 +30,9 @@ public class UserManager {
28 30 @EJB
29 31 UserAccess modelUser;
30 32  
  33 + @EJB
  34 + ParameterCache parameterCache;
  35 +
31 36 /**
32 37 *
33 38 * @param login
... ... @@ -61,6 +66,28 @@ public class UserManager {
61 66 modelUser.save(user);
62 67 return user;
63 68 }
  69 +
  70 + /**
  71 + * Remove an User in DB
  72 + *
  73 + * @param idUser User's id to delete
  74 + * @param request User's context
  75 + * @return True if deleted else return false.
  76 + */
  77 + public boolean removeUser(User userSession, int idUser){
  78 + User user = modelUser.get(idUser, User.class);
  79 + if (userSession.getRole() == Role.ADMIN
  80 + || userSession == user){
  81 + modelUser.remove(user);
  82 + return true;
  83 + } else if (userSession.getRole() == Role.MANAGER) {
  84 + if(Integer.getInteger(parameterCache.getParameter(ParameterName.ABILITY_RH_UPGRADE_USER)) == 0){
  85 + modelUser.remove(user);
  86 + return true;
  87 + }
  88 + }
  89 + return false;
  90 + }
64 91  
65 92 /**
66 93 * Grant permission to specific user
... ...