1 |
45968
|
panagiotis
|
package unitest;
|
2 |
|
|
|
3 |
46350
|
panagiotis
|
import eu.dnetlib.goldoa.domain.*;
|
4 |
46519
|
panagiotis
|
import eu.dnetlib.goldoa.service.*;
|
5 |
47100
|
panagiotis
|
import org.apache.commons.codec.digest.DigestUtils;
|
6 |
45968
|
panagiotis
|
import org.junit.Test;
|
7 |
|
|
import org.junit.runner.RunWith;
|
8 |
46350
|
panagiotis
|
import org.springframework.beans.factory.annotation.Autowired;
|
9 |
45968
|
panagiotis
|
import org.springframework.test.annotation.Rollback;
|
10 |
|
|
import org.springframework.test.context.ContextConfiguration;
|
11 |
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
12 |
|
|
|
13 |
|
|
import javax.transaction.Transactional;
|
14 |
|
|
|
15 |
46350
|
panagiotis
|
import java.util.ArrayList;
|
16 |
47100
|
panagiotis
|
import java.util.Date;
|
17 |
46350
|
panagiotis
|
import java.util.List;
|
18 |
47100
|
panagiotis
|
import java.util.concurrent.locks.StampedLock;
|
19 |
46350
|
panagiotis
|
|
20 |
45968
|
panagiotis
|
import static org.junit.Assert.*;
|
21 |
|
|
|
22 |
|
|
/**
|
23 |
|
|
* Created by panagiotis on 2/2/2017.
|
24 |
|
|
*/
|
25 |
|
|
@RunWith( SpringJUnit4ClassRunner.class )
|
26 |
|
|
@ContextConfiguration(locations = "classpath:applicationContext-goldoa-service-test.xml")
|
27 |
|
|
public class ManageRequestsTest {
|
28 |
|
|
|
29 |
46350
|
panagiotis
|
@Autowired
|
30 |
|
|
UserManager um;
|
31 |
|
|
@Autowired
|
32 |
46510
|
panagiotis
|
ProjectManager pm;
|
33 |
|
|
@Autowired
|
34 |
|
|
EligibilityManager em;
|
35 |
46519
|
panagiotis
|
@Autowired
|
36 |
|
|
PublicationManager pum;
|
37 |
|
|
@Autowired
|
38 |
|
|
OrganizationManager om;
|
39 |
|
|
@Autowired
|
40 |
|
|
SearchManager sm;
|
41 |
|
|
@Autowired
|
42 |
|
|
RequestManager rm;
|
43 |
|
|
@Autowired
|
44 |
|
|
JournalManager jm;
|
45 |
46738
|
panagiotis
|
@Autowired
|
46 |
|
|
PublisherManager pubm;
|
47 |
45968
|
panagiotis
|
|
48 |
|
|
@Test
|
49 |
|
|
@Transactional
|
50 |
|
|
@Rollback(true)
|
51 |
46350
|
panagiotis
|
public void getRequestsForLibrarian() throws PersonManagerException {
|
52 |
|
|
List<String> organizationIds = new ArrayList<>();
|
53 |
47054
|
panagiotis
|
for(Affiliation affiliation : um.getByEmail("ant.lebesis@gmail.com")
|
54 |
46350
|
panagiotis
|
.getAffiliations()) {
|
55 |
|
|
if(affiliation.getOrganization()!=null)
|
56 |
|
|
organizationIds.add(affiliation.getOrganization().getId());
|
57 |
|
|
}
|
58 |
|
|
System.out.println(organizationIds.get(0));
|
59 |
|
|
RequestPage rs = rm.getForOrganization(organizationIds,null, null, RequestSort.DATE,
|
60 |
|
|
RequestSortOrder.DESCENDING,
|
61 |
|
|
null, null, null, 0, 9);
|
62 |
|
|
List<Request> rss = rs.getRequests();
|
63 |
|
|
for(Request r:rss)
|
64 |
|
|
System.out.println(r.getId());
|
65 |
45968
|
panagiotis
|
}
|
66 |
|
|
|
67 |
47054
|
panagiotis
|
@Test
|
68 |
|
|
@Transactional
|
69 |
|
|
@Rollback(true)
|
70 |
|
|
public void getRequestsForGeneralUser() throws PersonManagerException {
|
71 |
|
|
List<String> organizationIds = new ArrayList<>();
|
72 |
|
|
for(Affiliation affiliation : um.getByEmail("ant.lebesis@gmail.com")
|
73 |
|
|
.getAffiliations()) {
|
74 |
|
|
if(affiliation.getOrganization()!=null)
|
75 |
|
|
organizationIds.add(affiliation.getOrganization().getId());
|
76 |
|
|
}
|
77 |
|
|
System.out.println(organizationIds.get(0));
|
78 |
|
|
RequestPage rs = rm.getForUser("ant.lebesis@gmail.com",null, null, RequestSort.DATE,
|
79 |
|
|
RequestSortOrder.DESCENDING,
|
80 |
|
|
null, null, null, 0, 9);
|
81 |
|
|
List<Request> rss = rs.getRequests();
|
82 |
|
|
for(Request r:rss)
|
83 |
|
|
System.out.println(r.getId());
|
84 |
|
|
}
|
85 |
46466
|
panagiotis
|
|
86 |
47054
|
panagiotis
|
|
87 |
|
|
|
88 |
46466
|
panagiotis
|
@Test
|
89 |
|
|
@Transactional
|
90 |
|
|
@Rollback(true)
|
91 |
|
|
public void getRequestsForPublisher() throws PersonManagerException {
|
92 |
|
|
User user = null;
|
93 |
|
|
|
94 |
|
|
try {
|
95 |
|
|
user = um.getByEmail("pkanakakis@di.uoa.gr");
|
96 |
|
|
} catch (PersonManagerException e) {
|
97 |
|
|
e.printStackTrace();
|
98 |
|
|
}
|
99 |
46680
|
panagiotis
|
|
100 |
|
|
RequestPage rs = rm.getForPublisher(user.getId(),null, null, RequestSort.DATE,
|
101 |
46466
|
panagiotis
|
RequestSortOrder.DESCENDING,
|
102 |
|
|
null, null, null, 0, 9);
|
103 |
|
|
List<Request> rss = rs.getRequests();
|
104 |
|
|
for(Request r:rss)
|
105 |
|
|
System.out.println(r.getId());
|
106 |
|
|
}
|
107 |
46519
|
panagiotis
|
|
108 |
46510
|
panagiotis
|
@Test
|
109 |
|
|
@Transactional
|
110 |
|
|
@Rollback(true)
|
111 |
|
|
public void getProjectInfoAndEligibility() {
|
112 |
|
|
|
113 |
|
|
Project project = pm.getById("corda::100016");
|
114 |
|
|
Request request = new Request();
|
115 |
|
|
request.setProject(project);
|
116 |
|
|
em.validate(request);
|
117 |
|
|
|
118 |
|
|
}
|
119 |
|
|
|
120 |
46519
|
panagiotis
|
@Test
|
121 |
|
|
@Transactional
|
122 |
|
|
@Rollback(true)
|
123 |
|
|
public void resolveDOI() {
|
124 |
|
|
try {
|
125 |
46738
|
panagiotis
|
Publication p = pum.resolveDOI("10.1038/srep12540");
|
126 |
|
|
|
127 |
46519
|
panagiotis
|
} catch (ManagerException e) {
|
128 |
|
|
e.printStackTrace();
|
129 |
|
|
}
|
130 |
|
|
}
|
131 |
46510
|
panagiotis
|
|
132 |
46519
|
panagiotis
|
@Test
|
133 |
|
|
@Transactional
|
134 |
|
|
@Rollback(true)
|
135 |
46741
|
panagiotis
|
public void savePublicationAndPublisherInfo() throws PersonManagerException, OrganizationManagerException {
|
136 |
46738
|
panagiotis
|
try {
|
137 |
|
|
Publication p = pum.resolveDOI("10.1038/srep12540");
|
138 |
46741
|
panagiotis
|
// pum.savePublication(p);
|
139 |
|
|
|
140 |
|
|
Request r = new Request();
|
141 |
|
|
r.setUser(um.getByEmail("pkanakakis@di.uoa.gr"));
|
142 |
|
|
r.setPublication(pum.getPublication("portal::d48191df0a20dfff1d1332574440ff29"));
|
143 |
|
|
r.setJournal(p.getJournal());
|
144 |
|
|
r.setOrganization(om.getById("corda::999643007"));
|
145 |
47100
|
panagiotis
|
r.setEligibility(em.validate(r));
|
146 |
|
|
|
147 |
|
|
RequestCoFunder rc = new RequestCoFunder();
|
148 |
|
|
RequestCoFunderPK rcpk = new RequestCoFunderPK();
|
149 |
|
|
|
150 |
|
|
List<Object> res = sm.search(SearchManager.TYPE.FUNDER, "1675 Foundation");
|
151 |
|
|
Funder f = (Funder)res.get(0);
|
152 |
|
|
|
153 |
|
|
rcpk.setFunder(f);
|
154 |
|
|
rcpk.setRequest(r);
|
155 |
|
|
rc.setPk(rcpk);
|
156 |
|
|
rc.setPercentage(50);
|
157 |
|
|
|
158 |
|
|
List<RequestCoFunder> rc_list = new ArrayList<>();
|
159 |
|
|
rc_list.add(rc);
|
160 |
|
|
|
161 |
|
|
r.setRequestCoFunders(rc_list);
|
162 |
|
|
|
163 |
|
|
|
164 |
|
|
Comment c = new Comment();
|
165 |
|
|
c.setId("portal::" + DigestUtils.md5Hex("fjkvbfjv" + new Date()));
|
166 |
|
|
c.setComment("fjkvbfjv");
|
167 |
|
|
List<Comment> c_list = new ArrayList<>();
|
168 |
|
|
c_list.add(c);
|
169 |
|
|
r.setRequestComments(c_list);
|
170 |
|
|
|
171 |
47137
|
panagiotis
|
rm.saveRequest(r);
|
172 |
46738
|
panagiotis
|
} catch (ManagerException e) {
|
173 |
46519
|
panagiotis
|
e.printStackTrace();
|
174 |
46738
|
panagiotis
|
}
|
175 |
46519
|
panagiotis
|
}
|
176 |
46510
|
panagiotis
|
|
177 |
47054
|
panagiotis
|
@Test
|
178 |
|
|
@Transactional
|
179 |
|
|
@Rollback(true)
|
180 |
|
|
public void getRequests() throws PersonManagerException {
|
181 |
|
|
User user = null;
|
182 |
46519
|
panagiotis
|
|
183 |
47054
|
panagiotis
|
try {
|
184 |
|
|
user = um.getByEmail("pkanakakis@di.uoa.gr");
|
185 |
|
|
} catch (PersonManagerException e) {
|
186 |
|
|
e.printStackTrace();
|
187 |
|
|
}
|
188 |
|
|
|
189 |
|
|
RequestPage rs = rm.getRequests(null, null, RequestSort.USER, RequestSortOrder.DESCENDING, null, null, null, 0, 9);
|
190 |
|
|
|
191 |
|
|
List<Request> rss = rs.getRequests();
|
192 |
47245
|
panagiotis
|
for(Request r:rss) {
|
193 |
|
|
System.out.println(r.getStatus() + "/" + r.getStatus().getValue());
|
194 |
47054
|
panagiotis
|
System.out.println(r.getId());
|
195 |
47245
|
panagiotis
|
}
|
196 |
47054
|
panagiotis
|
}
|
197 |
|
|
|
198 |
47100
|
panagiotis
|
@Test
|
199 |
|
|
@Transactional
|
200 |
|
|
@Rollback(true)
|
201 |
47137
|
panagiotis
|
public void updateRequest() throws PersonManagerException {
|
202 |
47245
|
panagiotis
|
Request r = rm.getById("20170512-1507");
|
203 |
47137
|
panagiotis
|
|
204 |
|
|
List<Object> res = sm.search(SearchManager.TYPE.FUNDER, "8020 Promotion Foundation");
|
205 |
|
|
Funder f = (Funder)res.get(0);
|
206 |
|
|
|
207 |
|
|
RequestCoFunder rc = new RequestCoFunder();
|
208 |
|
|
RequestCoFunderPK rcpk = new RequestCoFunderPK();
|
209 |
|
|
rcpk.setFunder(f);
|
210 |
|
|
rcpk.setRequest(r);
|
211 |
|
|
rc.setPk(rcpk);
|
212 |
|
|
rc.setPercentage(50);
|
213 |
|
|
|
214 |
|
|
r.getRequestCoFunders().add(rc);
|
215 |
47245
|
panagiotis
|
r.setPublisher((Publisher)sm.search(SearchManager.TYPE.PUBLISHER, "EDP Sciences-2").get(0));
|
216 |
47137
|
panagiotis
|
|
217 |
|
|
r.setApcPaid((float) 10000);
|
218 |
|
|
rm.saveRequest(r);
|
219 |
47100
|
panagiotis
|
}
|
220 |
47054
|
panagiotis
|
|
221 |
|
|
|
222 |
|
|
|
223 |
|
|
|
224 |
45968
|
panagiotis
|
}
|