Commit 217c0461d5b62f6a0c82459c53b55d6fd35d2c56

Authored by Pierrick
1 parent 4e413d92

Add global evaluation and its timer

skilldr-rs/src/main/java/eu/totoandco/rs/EndPoint.java
... ... @@ -12,5 +12,7 @@ import javax.ws.rs.core.MediaType;
12 12 @Produces(MediaType.APPLICATION_JSON+";charset=UTF-8")
13 13 public abstract class EndPoint {
14 14  
  15 + protected EndPoint(){}
  16 +
15 17 public static final String USERSESSION = "UserSession";
16 18 }
... ...
skilldr-service/src/main/java/eu/totoandco/business/SkillCalculator.java
... ... @@ -54,7 +54,7 @@ public class SkillCalculator {
54 54 }
55 55  
56 56 /**
57   - * Make an evaluation of skill mastery
  57 + * Make an evaluation of skill mastery for a user
58 58 * @param listUserSkill The list to evaluate
59 59 * @return An evaluation
60 60 */
... ... @@ -68,15 +68,15 @@ public class SkillCalculator {
68 68 }
69 69  
70 70 Double temp = (evaluation/baseExperience) * POURCENTAGE;
71   -
72   - return new SkillEvaluation(listUserSkill.get(0).getSkill().getName(), temp.intValue());
  71 + Skill skill = listUserSkill.get(0).getSkill();
  72 + return new SkillEvaluation(skill.getName(), skill.getId(), temp.intValue());
73 73 } else {
74 74 return null;
75 75 }
76 76 }
77 77  
78 78 /**
79   - * Make all evaluations of skill mastery
  79 + * Make all evaluations of skill mastery for a user
80 80 * @param request User's context
81 81 * @return A list of different evaluations
82 82 */
... ... @@ -115,6 +115,14 @@ public class SkillCalculator {
115 115 }
116 116  
117 117 /**
  118 + * Make global evaluations for all skill mastery
  119 + * @return A list of different evaluations
  120 + */
  121 + public List<SkillEvaluation> getGlobalEvaluation(){
  122 + return makeAllEvaluations(modelUserSkillAccess.getAll(UserSkill.class));
  123 + }
  124 +
  125 + /**
118 126 * Setter to modify Base_EXPERIENCE_SKILL in DB
119 127 * @param value New value to set
120 128 */
... ...
skilldr-service/src/main/java/eu/totoandco/business/SkillEvaluation.java
... ... @@ -3,14 +3,17 @@ package eu.totoandco.business;
3 3 public class SkillEvaluation {
4 4  
5 5 private String name;
  6 + private int id;
6 7 private int evaluation;
7 8  
8 9 public SkillEvaluation(){
9 10 this.evaluation = 0;
  11 + this.id = 0;
10 12 }
11 13  
12   - public SkillEvaluation(String name, int evaluation){
  14 + public SkillEvaluation(String name, int id, int evaluation){
13 15 this.name = name;
  16 + this.id = id;
14 17 this.evaluation = evaluation;
15 18 }
16 19  
... ... @@ -30,4 +33,12 @@ public class SkillEvaluation {
30 33 public void setEvaluation(int d){
31 34 this.evaluation = d;
32 35 }
  36 +
  37 + public int getId(){
  38 + return id;
  39 + }
  40 +
  41 + public void setId(int d){
  42 + this.id = d;
  43 + }
33 44 }
... ...
skilldr-service/src/main/java/eu/totoandco/cache/GlobalEvaluationCache.java 0 → 100644
  1 +package eu.totoandco.cache;
  2 +
  3 +import java.util.List;
  4 +
  5 +import javax.annotation.PostConstruct;
  6 +import javax.ejb.EJB;
  7 +import javax.ejb.Singleton;
  8 +import javax.ejb.Startup;
  9 +
  10 +import eu.totoandco.business.SkillCalculator;
  11 +import eu.totoandco.business.SkillEvaluation;
  12 +
  13 +/**
  14 + * @author Ronan Presle
  15 + * This class is a singleton reserved for Skilldr parameters stored in database. It is loaded at startup
  16 + */
  17 +@Singleton
  18 +@Startup
  19 +public class GlobalEvaluationCache {
  20 +
  21 + /**
  22 + * Map storing skilldr evaluations
  23 + */
  24 + private List<SkillEvaluation> evaluations;
  25 +
  26 + @EJB
  27 + SkillCalculator skillCalculator;
  28 +
  29 + /**
  30 + * Initialize the parameter Cache
  31 + */
  32 + @PostConstruct
  33 + public void init() {
  34 + evaluations = skillCalculator.getGlobalEvaluation();
  35 + }
  36 + public List<SkillEvaluation> getEvaluations() {
  37 + return evaluations;
  38 + }
  39 +
  40 + public void setEvaluations(List<SkillEvaluation> evaluations) {
  41 + this.evaluations = evaluations;
  42 + }
  43 +}
... ...
skilldr-service/src/main/java/eu/totoandco/timer/EvaluationTimer.java 0 → 100644
  1 +package eu.totoandco.timer;
  2 +
  3 +import javax.ejb.EJB;
  4 +import javax.ejb.Schedule;
  5 +import javax.ejb.Singleton;
  6 +import javax.ejb.Startup;
  7 +
  8 +import org.apache.commons.logging.Log;
  9 +import org.apache.commons.logging.LogFactory;
  10 +
  11 +import eu.totoandco.cache.GlobalEvaluationCache;
  12 +
  13 +/**
  14 + * Timer of globel evaluation from database
  15 + * @author Ronan Presle (ronan.presle@ttmail.eu)
  16 + */
  17 +@Singleton
  18 +@Startup
  19 +public class EvaluationTimer {
  20 + /**
  21 + * Instance of logger
  22 + */
  23 + private static final Log LOG = LogFactory.getLog("eu.totoandco.timer");
  24 +
  25 + @EJB
  26 + GlobalEvaluationCache globalEvaluationCache;
  27 +
  28 + /**
  29 + * Launch every day a midnight a new Global Evaluation
  30 + */
  31 + @Schedule(second="0", minute="0",hour="0", dayOfWeek="*", persistent=false)
  32 + public void getEvaluationsTimer() {
  33 + globalEvaluationCache.getEvaluations();
  34 + LOG.debug("REFRESH GLOBAL EVALUATION");
  35 + }
  36 +}
  37 +
... ...
skilldr-service/src/test/java/eu/totoandco/business/SkillCalculatorGetGetAlllTest.java renamed to skilldr-service/src/test/java/eu/totoandco/business/SkillCalculatorGetSetTest.java
... ... @@ -36,7 +36,7 @@ import eu.totoandco.model.UserSkill;
36 36 *
37 37 */
38 38 @RunWith(Arquillian.class)
39   -public class SkillCalculatorGetGetAlllTest {
  39 +public class SkillCalculatorGetSetTest {
40 40  
41 41 @Deployment
42 42 public static WebArchive createTestArchive() {
... ... @@ -121,12 +121,19 @@ public class SkillCalculatorGetGetAlllTest {
121 121 SkillEvaluation eval = skillCalculator.getEvaluation(user, skill1.getId());
122 122 Assert.assertNotNull("SkillEvaluation is null", eval);
123 123 Assert.assertNotNull("SkillEvaluation's name is null", eval.getName());
  124 + Assert.assertTrue("idSkill equals 0", eval.getId() != 0);
124 125 Assert.assertTrue("Evaluation equals 0", eval.getEvaluation() != 0);
125 126  
126 127 // getAllEvaluations
127 128 List<SkillEvaluation> evals = skillCalculator.getAllEvaluations(user);
128 129 Assert.assertNotNull("List SkillEvaluation is null", evals);
129 130 Assert.assertTrue("No skills found for this user", !evals.isEmpty());
  131 +
  132 + // getGlobalEvaluation
  133 + List<SkillEvaluation> globalEvals = skillCalculator.getGlobalEvaluation();
  134 + Assert.assertNotNull("List SkillEvaluation is null", globalEvals);
  135 + Assert.assertTrue("No skills found for this user", !globalEvals.isEmpty());
  136 +
130 137 }
131 138  
132 139 @Test
... ...