1 |
35215
|
antonis.le
|
package eu.dnetlib.goldoa.service.eligibility;
|
2 |
|
|
|
3 |
|
|
import eu.dnetlib.goldoa.domain.Eligibility;
|
4 |
|
|
import eu.dnetlib.goldoa.domain.Project;
|
5 |
|
|
import eu.dnetlib.goldoa.domain.Request;
|
6 |
47598
|
antonis.le
|
import eu.dnetlib.goldoa.service.EligibilityManager;
|
7 |
|
|
import eu.dnetlib.goldoa.service.ProjectManager;
|
8 |
|
|
import eu.dnetlib.goldoa.service.RequestManager;
|
9 |
47704
|
panagiotis
|
import org.apache.commons.logging.Log;
|
10 |
|
|
import org.apache.commons.logging.LogFactory;
|
11 |
35478
|
antonis.le
|
import org.springframework.beans.factory.annotation.Autowired;
|
12 |
47704
|
panagiotis
|
import org.springframework.beans.factory.annotation.Value;
|
13 |
47339
|
panagiotis
|
import org.springframework.stereotype.Component;
|
14 |
35215
|
antonis.le
|
|
15 |
|
|
import java.util.Date;
|
16 |
|
|
import java.util.List;
|
17 |
|
|
|
18 |
45595
|
panagiotis
|
/*
|
19 |
|
|
* Created by antleb on 3/9/15.
|
20 |
45403
|
panagiotis
|
*/
|
21 |
47339
|
panagiotis
|
@Component(value = "projectEligibilityManager")
|
22 |
35215
|
antonis.le
|
public class ProjectEligibiliyManager implements EligibilityManager {
|
23 |
|
|
|
24 |
39076
|
antonis.le
|
@Autowired
|
25 |
35215
|
antonis.le
|
private ProjectManager projectManager;
|
26 |
39076
|
antonis.le
|
@Autowired
|
27 |
35215
|
antonis.le
|
private RequestManager requestManager;
|
28 |
|
|
|
29 |
47704
|
panagiotis
|
@Value("${goldoa.eligibility.project.expiration.limit}")
|
30 |
47339
|
panagiotis
|
private long expirationOk;
|
31 |
47704
|
panagiotis
|
@Value("${goldoa.eligibility.project.expiration.threshold}")
|
32 |
47339
|
panagiotis
|
private float expirationThreshold;
|
33 |
47704
|
panagiotis
|
@Value("${goldoa.eligibility.project.expiration.iffy.message}")
|
34 |
35215
|
antonis.le
|
private String expirationIffy;
|
35 |
47704
|
panagiotis
|
@Value("${goldoa.eligibility.project.expiration.nono.message}")
|
36 |
35215
|
antonis.le
|
private String expirationNono;
|
37 |
47704
|
panagiotis
|
@Value("${goldoa.eligibility.project.stillRunning.nono.message}")
|
38 |
39076
|
antonis.le
|
private String stillRunningNono;
|
39 |
47704
|
panagiotis
|
@Value("${goldoa.eligibility.project.request.count}")
|
40 |
47339
|
panagiotis
|
private int maxRequests;
|
41 |
47704
|
panagiotis
|
@Value("${goldoa.eligibility.project.request.nono.message}")
|
42 |
35215
|
antonis.le
|
private String maxRequestsNono;
|
43 |
|
|
|
44 |
47704
|
panagiotis
|
private Log log = LogFactory.getLog(ProjectEligibiliyManager.class);
|
45 |
|
|
|
46 |
35215
|
antonis.le
|
@Override
|
47 |
|
|
public Eligibility validate(Request request) {
|
48 |
|
|
Eligibility eligibility = new Eligibility();
|
49 |
|
|
|
50 |
39076
|
antonis.le
|
if (request.getProject() != null) {
|
51 |
45595
|
panagiotis
|
Project project = request.getProject();
|
52 |
35215
|
antonis.le
|
|
53 |
39076
|
antonis.le
|
eligibility.merge(validateExpirationDate(project));
|
54 |
|
|
eligibility.merge(validateNumberOfRequests(project));
|
55 |
48564
|
panagiotis
|
|
56 |
39076
|
antonis.le
|
}
|
57 |
35215
|
antonis.le
|
return eligibility;
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
private Eligibility validateNumberOfRequests(Project project) {
|
61 |
|
|
List<Request> requests = requestManager.getForProject(project.getId());
|
62 |
|
|
int completed = 0;
|
63 |
|
|
|
64 |
39076
|
antonis.le
|
for (Request request : requests) {
|
65 |
45595
|
panagiotis
|
switch (request.getStatus()) {
|
66 |
41390
|
antonis.le
|
case CONDITIONALLY_APPROVED:
|
67 |
|
|
case APPROVED:
|
68 |
|
|
case ACCOUNTING_PROCESSING:
|
69 |
|
|
case ACCOUNTING_ON_HOLD:
|
70 |
|
|
case ACCOUNTING_PAID:
|
71 |
|
|
completed++;
|
72 |
|
|
break;
|
73 |
|
|
}
|
74 |
35215
|
antonis.le
|
}
|
75 |
|
|
|
76 |
47347
|
panagiotis
|
if (completed >= maxRequests)
|
77 |
35215
|
antonis.le
|
return new Eligibility(Eligibility.Status.NONO, maxRequestsNono);
|
78 |
|
|
|
79 |
|
|
return Eligibility.OK;
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
private Eligibility validateExpirationDate(Project project) {
|
83 |
40672
|
antonis.le
|
|
84 |
47347
|
panagiotis
|
Date enddate = new Date(project.getEnddate().getTime());
|
85 |
|
|
|
86 |
|
|
if (!enddate.before(new Date())) {
|
87 |
42142
|
antonis.le
|
return new Eligibility(Eligibility.Status.NONO, stillRunningNono);
|
88 |
48571
|
panagiotis
|
} else if (enddate.after(new Date(System.currentTimeMillis() - expirationOk * 1000L * 60 * 60 * 24 * 30))) {
|
89 |
35215
|
antonis.le
|
return Eligibility.OK;
|
90 |
47347
|
panagiotis
|
} else if (enddate.after(new Date((long) (System.currentTimeMillis() - (1.0f + expirationThreshold) * expirationOk)))) {
|
91 |
42142
|
antonis.le
|
return new Eligibility(Eligibility.Status.IFFY, expirationIffy);
|
92 |
|
|
} else {
|
93 |
|
|
return new Eligibility(Eligibility.Status.NONO, expirationNono);
|
94 |
35215
|
antonis.le
|
}
|
95 |
42142
|
antonis.le
|
|
96 |
|
|
// try {
|
97 |
|
|
// Date date = new SimpleDateFormat("dd/MM/yyyy").parse("01/01/2013");
|
98 |
|
|
//
|
99 |
|
|
// if (project.getEndDate().after(date)) {
|
100 |
|
|
// if (project.getEndDate().before(new Date()))
|
101 |
|
|
// return new Eligibility(Eligibility.Status.OK);
|
102 |
|
|
// else
|
103 |
|
|
// return new Eligibility(Eligibility.Status.NONO, stillRunningNono);
|
104 |
|
|
// } else
|
105 |
|
|
// return new Eligibility(Eligibility.Status.NONO, expirationNono);
|
106 |
|
|
// } catch (ParseException e) {
|
107 |
|
|
// e.printStackTrace();
|
108 |
|
|
//
|
109 |
|
|
// return Eligibility.OK;
|
110 |
|
|
// }
|
111 |
35215
|
antonis.le
|
}
|
112 |
|
|
|
113 |
|
|
public ProjectManager getProjectManager() {
|
114 |
|
|
return projectManager;
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
public void setProjectManager(ProjectManager projectManager) {
|
118 |
|
|
this.projectManager = projectManager;
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
public RequestManager getRequestManager() {
|
122 |
|
|
return requestManager;
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
public void setRequestManager(RequestManager requestManager) {
|
126 |
|
|
this.requestManager = requestManager;
|
127 |
|
|
}
|
128 |
|
|
|
129 |
47339
|
panagiotis
|
public long getExpirationOk() {
|
130 |
35215
|
antonis.le
|
return expirationOk;
|
131 |
|
|
}
|
132 |
|
|
|
133 |
46139
|
panagiotis
|
public void setExpirationOk(Long expirationOk) {
|
134 |
47339
|
panagiotis
|
this.expirationOk = (expirationOk * 1000L * 60 * 60 * 24 * 30);
|
135 |
35215
|
antonis.le
|
}
|
136 |
|
|
|
137 |
47339
|
panagiotis
|
public float getExpirationThreshold() {
|
138 |
39076
|
antonis.le
|
return expirationThreshold;
|
139 |
|
|
}
|
140 |
35215
|
antonis.le
|
|
141 |
47339
|
panagiotis
|
public void setExpirationThreshold(float expirationThreshold) {
|
142 |
39076
|
antonis.le
|
this.expirationThreshold = expirationThreshold;
|
143 |
|
|
}
|
144 |
35215
|
antonis.le
|
|
145 |
39076
|
antonis.le
|
public String getExpirationIffy() {
|
146 |
35215
|
antonis.le
|
return expirationIffy;
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
public void setExpirationIffy(String expirationIffy) {
|
150 |
|
|
this.expirationIffy = expirationIffy;
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
public String getExpirationNono() {
|
154 |
|
|
return expirationNono;
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
public void setExpirationNono(String expirationNono) {
|
158 |
|
|
this.expirationNono = expirationNono;
|
159 |
|
|
}
|
160 |
|
|
|
161 |
47339
|
panagiotis
|
public int getMaxRequests() {
|
162 |
35215
|
antonis.le
|
return maxRequests;
|
163 |
|
|
}
|
164 |
|
|
|
165 |
47339
|
panagiotis
|
public void setMaxRequests(int maxRequests) {
|
166 |
35215
|
antonis.le
|
this.maxRequests = maxRequests;
|
167 |
|
|
}
|
168 |
|
|
|
169 |
|
|
public String getMaxRequestsNono() {
|
170 |
|
|
return maxRequestsNono;
|
171 |
|
|
}
|
172 |
|
|
|
173 |
|
|
public void setMaxRequestsNono(String maxRequestsNono) {
|
174 |
|
|
this.maxRequestsNono = maxRequestsNono;
|
175 |
|
|
}
|
176 |
36411
|
stefania.m
|
|
177 |
39076
|
antonis.le
|
public String getStillRunningNono() {
|
178 |
|
|
return stillRunningNono;
|
179 |
|
|
}
|
180 |
36411
|
stefania.m
|
|
181 |
39076
|
antonis.le
|
public void setStillRunningNono(String stillRunningNono) {
|
182 |
|
|
this.stillRunningNono = stillRunningNono;
|
183 |
|
|
}
|
184 |
35215
|
antonis.le
|
}
|