1
|
package eu.dnetlib.server;
|
2
|
|
3
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
4
|
import eu.dnetlib.client.DataService;
|
5
|
import eu.dnetlib.goldoa.domain.*;
|
6
|
import eu.dnetlib.goldoa.service.*;
|
7
|
import eu.dnetlib.shared.FundingWizardState;
|
8
|
import eu.dnetlib.shared.InitLoad;
|
9
|
import org.springframework.context.ApplicationContext;
|
10
|
import org.springframework.web.context.support.WebApplicationContextUtils;
|
11
|
|
12
|
import javax.mail.MessagingException;
|
13
|
import javax.servlet.ServletConfig;
|
14
|
import javax.servlet.ServletException;
|
15
|
import java.util.ArrayList;
|
16
|
import java.util.Date;
|
17
|
import java.util.List;
|
18
|
|
19
|
/**
|
20
|
* Created by stefania on 3/4/15.
|
21
|
*/
|
22
|
public class DataServiceImpl extends RemoteServiceServlet implements DataService {
|
23
|
|
24
|
private OrganizationManager organizationManager = null;
|
25
|
private PersonManager personManager = null;
|
26
|
private ProjectManager projectManager = null;
|
27
|
private PublisherManager publisherManager = null;
|
28
|
private JournalManager journalManager = null;
|
29
|
private PublicationManager publicationManager = null;
|
30
|
private RequestManager requestManager = null;
|
31
|
private EligibilityManager eligibilityManager = null;
|
32
|
|
33
|
public void init(ServletConfig config) throws ServletException {
|
34
|
|
35
|
super.init(config);
|
36
|
|
37
|
ApplicationContext context = WebApplicationContextUtils
|
38
|
.getWebApplicationContext(getServletContext());
|
39
|
|
40
|
this.organizationManager = (OrganizationManager) context.getBean("organisationManager");
|
41
|
this.personManager = (PersonManager) context.getBean("personManager");
|
42
|
this.projectManager = (ProjectManager) context.getBean("projectManager");
|
43
|
this.publisherManager = (PublisherManager) context.getBean("publisherManager");
|
44
|
this.journalManager = (JournalManager) context.getBean("journalManager");
|
45
|
this.publicationManager = (PublicationManager) context.getBean("publicationManager");
|
46
|
this.requestManager = (RequestManager) context.getBean("requestManager");
|
47
|
this.eligibilityManager = (EligibilityManager) context.getBean("eligibilityManager");
|
48
|
}
|
49
|
|
50
|
@Override
|
51
|
public InitLoad load(String hash, String email, String token, String cookie) {
|
52
|
|
53
|
InitLoad initLoad = new InitLoad();
|
54
|
String message = null;
|
55
|
String goTo = "home";
|
56
|
Person person = null;
|
57
|
|
58
|
String hashValue = "home";
|
59
|
if(hash!=null && !hash.equals(""))
|
60
|
hashValue = hash.substring(1);
|
61
|
|
62
|
if(hashValue.equals("activate")) {
|
63
|
|
64
|
if (email != null && token != null) {
|
65
|
|
66
|
try {
|
67
|
|
68
|
person = personManager.activate(email, token);
|
69
|
goTo = "myAccount";
|
70
|
|
71
|
} catch (PersonManagerException pme) {
|
72
|
if(pme.getErrorCause().equals(PersonManagerException.ErrorCause.NOT_EXISTS))
|
73
|
message = "Invalid email or activation token";
|
74
|
else
|
75
|
message = "Activation token has expired";
|
76
|
}
|
77
|
|
78
|
} else {
|
79
|
message = "Invalid activation URL";
|
80
|
}
|
81
|
|
82
|
} else {
|
83
|
|
84
|
if(cookie!=null) {
|
85
|
|
86
|
try {
|
87
|
person = personManager.getByEmail(cookie);
|
88
|
} catch (PersonManagerException pme) {
|
89
|
//TODO do we want to display a message like that or not?
|
90
|
if(pme.getErrorCause().equals(PersonManagerException.ErrorCause.NOT_EXISTS))
|
91
|
message = "User does not exist";
|
92
|
}
|
93
|
goTo = hashValue;
|
94
|
|
95
|
} else {
|
96
|
|
97
|
goTo = hashValue;
|
98
|
}
|
99
|
}
|
100
|
|
101
|
initLoad.setPerson(person);
|
102
|
initLoad.setGoTo(goTo);
|
103
|
initLoad.setErrorMessage(message);
|
104
|
|
105
|
initLoad.setUserRoles(personManager.getRoles());
|
106
|
|
107
|
return initLoad;
|
108
|
}
|
109
|
|
110
|
@Override
|
111
|
public String saveOrganization(Organization organization) throws OrganizationManagerException {
|
112
|
return organizationManager.saveOrganization(organization);
|
113
|
}
|
114
|
|
115
|
@Override
|
116
|
public Person loginUser(String email, String password) throws PersonManagerException {
|
117
|
return personManager.login(email, password);
|
118
|
}
|
119
|
|
120
|
@Override
|
121
|
public void registerUser(Person person) throws PersonManagerException {
|
122
|
personManager.register(person);
|
123
|
}
|
124
|
|
125
|
@Override
|
126
|
public Person updateUser(Person person) throws PersonManagerException {
|
127
|
return personManager.savePerson(person);
|
128
|
}
|
129
|
|
130
|
@Override
|
131
|
public void saveResearcher(Person person) throws PersonManagerException {
|
132
|
personManager.savePerson(person);
|
133
|
}
|
134
|
|
135
|
@Override
|
136
|
public Request saveRequest(Request request) {
|
137
|
return requestManager.saveRequest(request);
|
138
|
}
|
139
|
|
140
|
@Override
|
141
|
public Request submitRequest(Request request) throws PersonManagerException {
|
142
|
return requestManager.submitRequest(request);
|
143
|
}
|
144
|
|
145
|
@Override
|
146
|
public RequestInfo getProjectInfoAndEligibility(String projectId) {
|
147
|
|
148
|
RequestInfo requestInfo = new RequestInfo();
|
149
|
requestInfo.setProject(projectManager.getById(projectId));
|
150
|
|
151
|
Request request = new Request();
|
152
|
request.setProject(projectId);
|
153
|
requestInfo.setEligibility(eligibilityManager.validate(request));
|
154
|
|
155
|
return requestInfo;
|
156
|
}
|
157
|
|
158
|
@Override
|
159
|
public Publication savePublication(Publication publication) {
|
160
|
|
161
|
Publication savedPublication = null;
|
162
|
|
163
|
if(publication.getType().equals(Publication.Type.ARTICLE)) {
|
164
|
|
165
|
Journal journal = publication.getJournal();
|
166
|
if (journal.getId()==null) {
|
167
|
Journal savedJournal = journalManager.saveJournal(journal);
|
168
|
publication.setJournal(savedJournal);
|
169
|
}
|
170
|
|
171
|
savedPublication = publicationManager.savePublication(publication);
|
172
|
|
173
|
} else {
|
174
|
|
175
|
Publisher publisher = publication.getPublisher();
|
176
|
if(publisher.getId()==null) {
|
177
|
Publisher savedPublisher = publisherManager.savePublisher(publisher);
|
178
|
publication.setPublisher(savedPublisher);
|
179
|
}
|
180
|
|
181
|
savedPublication = publicationManager.savePublication(publication);
|
182
|
}
|
183
|
|
184
|
return savedPublication;
|
185
|
}
|
186
|
|
187
|
@Override
|
188
|
public Journal getJournal(String journalId) {
|
189
|
return journalManager.getJournal(journalId);
|
190
|
}
|
191
|
|
192
|
@Override
|
193
|
public Publisher getPublisher(String publisherId) {
|
194
|
return publisherManager.getPublisher(publisherId);
|
195
|
}
|
196
|
|
197
|
@Override
|
198
|
public Publication resolveDOI(String doi) throws ManagerException {
|
199
|
return publicationManager.resolveDOI(doi);
|
200
|
}
|
201
|
|
202
|
@Override
|
203
|
public List<RequestInfo> getRequests(Date from, Date to, RequestSort requestSortBy, RequestSortOrder order, RequestFilter requestFilter, String term) {
|
204
|
return requestManager.getRequests(from, to, requestSortBy, order, requestFilter, term);
|
205
|
}
|
206
|
|
207
|
@Override
|
208
|
public List<RequestInfo> getRequestsForUser(String userId, Date from, Date to, RequestSort requestSortBy, RequestSortOrder order, RequestFilter requestFilter, String term) {
|
209
|
return requestManager.getForUser(userId, from, to, requestSortBy, order, requestFilter, term);
|
210
|
}
|
211
|
|
212
|
@Override
|
213
|
public FundingWizardState getFundingWizardState(String requestId) {
|
214
|
|
215
|
RequestInfo requestInfo = requestManager.getById(requestId);
|
216
|
|
217
|
if(requestInfo!=null) {
|
218
|
|
219
|
FundingWizardState fundingWizardState = new FundingWizardState();
|
220
|
fundingWizardState.setRequest(new Request(requestInfo));
|
221
|
fundingWizardState.setResearcher(requestInfo.getResearcher());
|
222
|
fundingWizardState.setProject(requestInfo.getProject());
|
223
|
fundingWizardState.setPublication(requestInfo.getPublication());
|
224
|
fundingWizardState.setInvoice(requestInfo.getInvoice());
|
225
|
|
226
|
return fundingWizardState;
|
227
|
}
|
228
|
|
229
|
return null;
|
230
|
}
|
231
|
}
|