Revision 39076
Added by Antonis Lempesis over 8 years ago
ProjectEligibiliyManager.java | ||
---|---|---|
16 | 16 |
*/ |
17 | 17 |
public class ProjectEligibiliyManager implements EligibilityManager { |
18 | 18 |
|
19 |
@Autowired
|
|
19 |
@Autowired
|
|
20 | 20 |
private ProjectManager projectManager; |
21 |
@Autowired
|
|
21 |
@Autowired
|
|
22 | 22 |
private RequestManager requestManager; |
23 | 23 |
|
24 | 24 |
private long expirationOk; |
25 | 25 |
private float expirationThreshold; |
26 | 26 |
private String expirationIffy; |
27 | 27 |
private String expirationNono; |
28 |
private String stillRunningNono;
|
|
28 |
private String stillRunningNono;
|
|
29 | 29 |
|
30 | 30 |
private int maxRequests; |
31 | 31 |
private String maxRequestsNono; |
... | ... | |
34 | 34 |
public Eligibility validate(Request request) { |
35 | 35 |
Eligibility eligibility = new Eligibility(); |
36 | 36 |
|
37 |
if (request.getProject() != null) {
|
|
38 |
Project project = projectManager.getById(request.getProject()).getProject();
|
|
37 |
if (request.getProject() != null) {
|
|
38 |
Project project = projectManager.getById(request.getProject()).getProject();
|
|
39 | 39 |
|
40 |
eligibility.merge(validateExpirationDate(project));
|
|
41 |
eligibility.merge(validateNumberOfRequests(project));
|
|
42 |
}
|
|
40 |
eligibility.merge(validateExpirationDate(project));
|
|
41 |
eligibility.merge(validateNumberOfRequests(project));
|
|
42 |
}
|
|
43 | 43 |
return eligibility; |
44 | 44 |
} |
45 | 45 |
|
... | ... | |
47 | 47 |
List<Request> requests = requestManager.getForProject(project.getId()); |
48 | 48 |
int completed = 0; |
49 | 49 |
|
50 |
for (Request request:requests) {
|
|
50 |
for (Request request : requests) {
|
|
51 | 51 |
if (request.getStatus(Request.RequestStatus.SUBMITTED) && !request.getStatus(Request.RequestStatus.REJECTED)) |
52 | 52 |
completed++; |
53 | 53 |
} |
... | ... | |
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
private Eligibility validateExpirationDate(Project project) { |
62 |
if (!project.getEndDate().before(new Date())) {
|
|
63 |
return new Eligibility(Eligibility.Status.NONO, stillRunningNono);
|
|
64 |
} else if (project.getEndDate().after(new Date(System.currentTimeMillis() - expirationOk))) {
|
|
62 |
if (!project.getEndDate().before(new Date())) {
|
|
63 |
return new Eligibility(Eligibility.Status.NONO, stillRunningNono);
|
|
64 |
} else if (project.getEndDate().after(new Date(System.currentTimeMillis() - expirationOk))) {
|
|
65 | 65 |
return Eligibility.OK; |
66 | 66 |
} else if (project.getEndDate().after(new Date((long) (System.currentTimeMillis() - (1.0f + expirationThreshold) * expirationOk)))) { |
67 | 67 |
return new Eligibility(Eligibility.Status.IFFY, expirationIffy); |
... | ... | |
94 | 94 |
this.expirationOk = expirationOk * 1000L * 60 * 60 * 24 * 30; |
95 | 95 |
} |
96 | 96 |
|
97 |
public float getExpirationThreshold() {
|
|
98 |
return expirationThreshold;
|
|
99 |
}
|
|
97 |
public float getExpirationThreshold() {
|
|
98 |
return expirationThreshold;
|
|
99 |
}
|
|
100 | 100 |
|
101 |
public void setExpirationThreshold(float expirationThreshold) {
|
|
102 |
this.expirationThreshold = expirationThreshold;
|
|
103 |
}
|
|
101 |
public void setExpirationThreshold(float expirationThreshold) {
|
|
102 |
this.expirationThreshold = expirationThreshold;
|
|
103 |
}
|
|
104 | 104 |
|
105 |
public String getExpirationIffy() {
|
|
105 |
public String getExpirationIffy() {
|
|
106 | 106 |
return expirationIffy; |
107 | 107 |
} |
108 | 108 |
|
... | ... | |
134 | 134 |
this.maxRequestsNono = maxRequestsNono; |
135 | 135 |
} |
136 | 136 |
|
137 |
public String getStillRunningNono() {
|
|
138 |
return stillRunningNono;
|
|
139 |
}
|
|
137 |
public String getStillRunningNono() {
|
|
138 |
return stillRunningNono;
|
|
139 |
}
|
|
140 | 140 |
|
141 |
public void setStillRunningNono(String stillRunningNono) {
|
|
142 |
this.stillRunningNono = stillRunningNono;
|
|
143 |
}
|
|
141 |
public void setStillRunningNono(String stillRunningNono) {
|
|
142 |
this.stillRunningNono = stillRunningNono;
|
|
143 |
}
|
|
144 | 144 |
} |
Also available in: Unified diff
reformatted code