Revision 54525
Added by Panagiotis Kanakakis over 5 years ago
modules/uoa-repository-manager-service/branches/dev-api/src/test/java/unitest/PiwikTest.java | ||
---|---|---|
2 | 2 |
package unitest; |
3 | 3 |
|
4 | 4 |
import com.fasterxml.jackson.databind.ObjectMapper; |
5 |
import eu.dnetlib.repo.manager.service.config.RepoManagerContextLoaderListener;
|
|
5 |
import eu.dnetlib.repo.manager.config.RepoManagerContextLoaderListener; |
|
6 | 6 |
import org.apache.commons.lang.StringEscapeUtils; |
7 | 7 |
import org.junit.Test; |
8 | 8 |
import org.junit.runner.RunWith; |
modules/uoa-repository-manager-service/branches/dev-api/src/test/java/unitest/ValidatorTest.java | ||
---|---|---|
1 | 1 |
package unitest; |
2 | 2 |
|
3 |
import eu.dnetlib.repo.manager.service.config.RepoManagerContextLoaderListener;
|
|
4 |
import eu.dnetlib.repo.manager.service.utils.OaiTools;
|
|
3 |
import eu.dnetlib.repo.manager.config.RepoManagerContextLoaderListener; |
|
4 |
import eu.dnetlib.repo.manager.utils.OaiTools; |
|
5 | 5 |
import org.junit.Test; |
6 | 6 |
import org.junit.runner.RunWith; |
7 | 7 |
import org.springframework.test.context.ContextConfiguration; |
8 | 8 |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
9 |
import org.springframework.test.context.web.WebAppConfiguration; |
|
10 | 9 |
|
11 | 10 |
@RunWith(SpringJUnit4ClassRunner.class) |
12 | 11 |
@ContextConfiguration(classes = RepoManagerContextLoaderListener.class) |
modules/uoa-repository-manager-service/branches/dev-api/src/test/resources/application-context.xml | ||
---|---|---|
10 | 10 |
<context:component-scan base-package="eu.dnetlib.repo.manager.service.*"/> |
11 | 11 |
<tx:annotation-driven transaction-manager="txManager"/> |
12 | 12 |
|
13 |
<bean class="eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader"
|
|
13 |
<bean class="eu.dnetlib.repo.manager.config.CascadingPropertyLoader" |
|
14 | 14 |
id="propertyLoader"> |
15 | 15 |
<property name="order" value="2"/> |
16 | 16 |
<property name="properties"> |
modules/uoa-repository-manager-service/branches/dev-api/src/test/resources/applicationContext.xml | ||
---|---|---|
36 | 36 |
<property name="debug" value="${services.validator.mail.debug}"/> |
37 | 37 |
</bean> |
38 | 38 |
|
39 |
<bean class="eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader"
|
|
39 |
<bean class="eu.dnetlib.repo.manager.config.CascadingPropertyLoader" |
|
40 | 40 |
id="propertyLoader"> |
41 | 41 |
<property name="order" value="2"/> |
42 | 42 |
<property name="properties"> |
... | ... | |
94 | 94 |
|
95 | 95 |
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/> |
96 | 96 |
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/> |
97 |
<bean class="eu.dnetlib.repo.manager.service.config.SwaggerConfig"/>
|
|
97 |
<bean class="eu.dnetlib.repo.manager.config.SwaggerConfig"/> |
|
98 | 98 |
|
99 | 99 |
</beans> |
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/utils/Converter.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.utils; |
|
2 |
|
|
3 |
import com.fasterxml.jackson.core.JsonProcessingException; |
|
4 |
import com.fasterxml.jackson.databind.ObjectMapper; |
|
5 |
import eu.dnetlib.domain.data.Repository; |
|
6 |
import eu.dnetlib.domain.data.RepositoryInterface; |
|
7 |
import eu.dnetlib.repo.manager.service.domain.RepositorySnippet; |
|
8 |
import eu.dnetlib.repo.manager.shared.AggregationDetails; |
|
9 |
import eu.dnetlib.repo.manager.shared.Timezone; |
|
10 |
import org.apache.commons.codec.digest.DigestUtils; |
|
11 |
import org.apache.log4j.Logger; |
|
12 |
import org.json.JSONArray; |
|
13 |
import org.json.JSONException; |
|
14 |
import org.json.JSONObject; |
|
15 |
|
|
16 |
import java.io.BufferedReader; |
|
17 |
import java.io.IOException; |
|
18 |
import java.io.InputStream; |
|
19 |
import java.io.InputStreamReader; |
|
20 |
import java.text.ParseException; |
|
21 |
import java.text.SimpleDateFormat; |
|
22 |
import java.util.*; |
|
23 |
|
|
24 |
public class Converter { |
|
25 |
|
|
26 |
private static final Logger LOGGER = Logger.getLogger(Converter.class); |
|
27 |
|
|
28 |
public static Repository jsonToRepositoryObject(JSONObject repositoryObject) throws JSONException { |
|
29 |
|
|
30 |
Repository repository = new Repository(); |
|
31 |
|
|
32 |
JSONObject datasource = repositoryObject.getJSONObject("datasource"); |
|
33 |
|
|
34 |
//if( datasource.equals(null)) |
|
35 |
// return null; |
|
36 |
|
|
37 |
repository.setId(datasource.get("id").toString()); |
|
38 |
repository.setOfficialName(datasource.get("officialname").toString()); |
|
39 |
|
|
40 |
repository.setEnglishName( datasource.get("englishname").toString()); |
|
41 |
if(repository.getEnglishName().equals("null")) |
|
42 |
repository.setEnglishName(""); |
|
43 |
|
|
44 |
repository.setWebsiteUrl(datasource.get("websiteurl").toString()); |
|
45 |
if(repository.getWebsiteUrl().equals("null")) |
|
46 |
repository.setWebsiteUrl(""); |
|
47 |
|
|
48 |
repository.setLogoUrl(datasource.get("logourl").toString()); |
|
49 |
if(repository.getLogoUrl().equals("null")) |
|
50 |
repository.setLogoUrl(""); |
|
51 |
|
|
52 |
repository.setContactEmail(datasource.get("contactemail").toString()); |
|
53 |
if(repository.getContactEmail().equals("null")) |
|
54 |
repository.setContactEmail(""); |
|
55 |
|
|
56 |
|
|
57 |
repository.setLatitude( toDouble(datasource.get("latitude").toString())); |
|
58 |
repository.setLongitude(toDouble(datasource.get("longitude").toString())); |
|
59 |
Double timezone = toDouble(datasource.get("timezone").toString()); |
|
60 |
repository.setTimezone(timezone!=null?timezone:0.0); |
|
61 |
repository.setNamespacePrefix(datasource.get("namespaceprefix").toString()); |
|
62 |
repository.setOdLanguages(datasource.get("languages").toString()); |
|
63 |
repository.setDateOfValidation(convertStringToDate( datasource.get("dateofvalidation").toString())); |
|
64 |
|
|
65 |
/* typology -> platform |
|
66 |
* datasource class -> typology */ |
|
67 |
repository.setTypology(datasource.get("platform").toString()); |
|
68 |
if(repository.getTypology().equals("null")) |
|
69 |
repository.setTypology(""); |
|
70 |
repository.setDatasourceClass(datasource.get("typology").toString()); |
|
71 |
|
|
72 |
repository.setDateOfCollection(convertStringToDate( datasource.get("dateofcollection").toString())); |
|
73 |
repository.setActivationId(datasource.get("activationId").toString()); |
|
74 |
|
|
75 |
repository.setDescription(datasource.get("description").toString()); |
|
76 |
if(repository.getDescription().equals("null")) |
|
77 |
repository.setDescription(""); |
|
78 |
|
|
79 |
repository.setIssn(datasource.get("issn").toString()); |
|
80 |
repository.setLissn(datasource.get("lissn").toString()); |
|
81 |
if(repository.getLissn().equals("null")) |
|
82 |
repository.setLissn(""); |
|
83 |
repository.setEissn(datasource.get("eissn").toString()); |
|
84 |
if(repository.getEissn().equals("null")) |
|
85 |
repository.setEissn(""); |
|
86 |
repository.setRegisteredBy(datasource.get("registeredby").toString()); |
|
87 |
|
|
88 |
/* managed field */ |
|
89 |
repository.setRegistered(Boolean.parseBoolean(datasource.get("managed").toString())); |
|
90 |
|
|
91 |
//subjects |
|
92 |
|
|
93 |
repository.setAggregator(datasource.get("aggregator").toString()); |
|
94 |
repository.setCollectedFrom(datasource.get("collectedfrom").toString()); |
|
95 |
|
|
96 |
//TODO change organization to list |
|
97 |
JSONArray organizations = ((JSONArray)datasource.get("organizations")); |
|
98 |
if(organizations.length() != 0) { |
|
99 |
repository.setOrganization(((JSONArray) datasource.get("organizations")).getJSONObject(0).get("legalname").toString()); |
|
100 |
String countryCode = ((JSONArray) datasource.get("organizations")).getJSONObject(0).get("country").toString(); |
|
101 |
repository.setCountryCode(countryCode); |
|
102 |
} |
|
103 |
|
|
104 |
/* identities field */ |
|
105 |
|
|
106 |
return repository; |
|
107 |
} |
|
108 |
|
|
109 |
public static Date convertStringToDate(String date){ |
|
110 |
|
|
111 |
if(Objects.equals(date, "null")) |
|
112 |
return null; |
|
113 |
|
|
114 |
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
|
115 |
try { |
|
116 |
return formatter.parse(date); |
|
117 |
} catch (ParseException e) { |
|
118 |
e.printStackTrace(); |
|
119 |
} |
|
120 |
return null; |
|
121 |
} |
|
122 |
|
|
123 |
public static String convertDateToString(Date date){ |
|
124 |
|
|
125 |
if(Objects.equals(date, null)) |
|
126 |
return null; |
|
127 |
|
|
128 |
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
|
129 |
return formatter.format(date); |
|
130 |
} |
|
131 |
|
|
132 |
public static Double toDouble(String number){ |
|
133 |
if(Objects.equals(number, "null")) |
|
134 |
return 0.0; |
|
135 |
else |
|
136 |
return Double.valueOf(number); |
|
137 |
} |
|
138 |
|
|
139 |
public static List<RepositorySnippet> jsonToRepositorySnippetList(JSONObject json) throws JSONException { |
|
140 |
|
|
141 |
List<RepositorySnippet> resultSet = new ArrayList<>(); |
|
142 |
JSONArray rs = json.getJSONArray("datasourceInfo"); |
|
143 |
for(int i=0;i<rs.length();i++) |
|
144 |
resultSet.add(jsonToRepositorySnippetObject( rs.getJSONObject(i)) ); |
|
145 |
return resultSet; |
|
146 |
} |
|
147 |
|
|
148 |
private static RepositorySnippet jsonToRepositorySnippetObject(JSONObject repositorySnippetObject) throws JSONException { |
|
149 |
|
|
150 |
|
|
151 |
RepositorySnippet repositorySnippet = new RepositorySnippet(); |
|
152 |
|
|
153 |
// JSONObject datasource = repositorySnippetObject.getJSONObject("datasource"); |
|
154 |
|
|
155 |
|
|
156 |
repositorySnippet.setId(repositorySnippetObject.get("id").toString()); |
|
157 |
repositorySnippet.setOfficialname(repositorySnippetObject.get("officialname").toString()); |
|
158 |
|
|
159 |
repositorySnippet.setEnglishname( repositorySnippetObject.get("englishname").toString()); |
|
160 |
if(repositorySnippet.getEnglishname().equals("null")) |
|
161 |
repositorySnippet.setEnglishname(""); |
|
162 |
|
|
163 |
repositorySnippet.setWebsiteurl(repositorySnippetObject.get("websiteurl").toString()); |
|
164 |
if(repositorySnippet.getWebsiteurl().equals("null")) |
|
165 |
repositorySnippet.setWebsiteurl(""); |
|
166 |
|
|
167 |
repositorySnippet.setRegisteredby(repositorySnippetObject.get("registeredby").toString()); |
|
168 |
if(repositorySnippet.getRegisteredby().equals("null")) |
|
169 |
repositorySnippet.setRegisteredby(""); |
|
170 |
return repositorySnippet; |
|
171 |
|
|
172 |
} |
|
173 |
|
|
174 |
public static List<Repository> jsonToRepositoryList(JSONObject json) throws JSONException { |
|
175 |
|
|
176 |
List<Repository> resultSet = new ArrayList<>(); |
|
177 |
JSONArray rs = json.getJSONArray("datasourceInfo"); |
|
178 |
for(int i=0;i<rs.length();i++) |
|
179 |
resultSet.add(jsonToRepositoryObject( rs.getJSONObject(i)) ); |
|
180 |
return resultSet; |
|
181 |
} |
|
182 |
|
|
183 |
public static List<RepositoryInterface> jsonToRepositoryInterfaceList(JSONObject json) throws JSONException { |
|
184 |
|
|
185 |
List<RepositoryInterface> resultSet = new ArrayList<>(); |
|
186 |
JSONArray rs = json.getJSONArray("api"); |
|
187 |
for(int i=0;i<rs.length();i++) |
|
188 |
resultSet.add(jsonToRepositoryInterfaceObject( rs.getJSONObject(i)) ); |
|
189 |
return resultSet; |
|
190 |
} |
|
191 |
|
|
192 |
public static RepositoryInterface jsonToRepositoryInterfaceObject(JSONObject repositoryInterfaceObject) throws JSONException { |
|
193 |
|
|
194 |
RepositoryInterface repositoryInterface = new RepositoryInterface(); |
|
195 |
|
|
196 |
repositoryInterface.setId(repositoryInterfaceObject.get("id").toString()); |
|
197 |
repositoryInterface.setAccessProtocol(repositoryInterfaceObject.get("protocol").toString()); |
|
198 |
repositoryInterface.setContentDescription(repositoryInterfaceObject.get("contentdescription").toString()); |
|
199 |
repositoryInterface.setTypology(repositoryInterfaceObject.get("typology").toString()); |
|
200 |
repositoryInterface.setCompliance(repositoryInterfaceObject.get("compatibility").toString()); |
|
201 |
repositoryInterface.setLastCollectionDate(repositoryInterfaceObject.get("lastCollectionDate").toString()); |
|
202 |
|
|
203 |
repositoryInterface.setBaseUrl(repositoryInterfaceObject.get("baseurl").toString()); |
|
204 |
repositoryInterface.setRemovable(Boolean.parseBoolean(repositoryInterfaceObject.get("removable").toString())); |
|
205 |
|
|
206 |
|
|
207 |
// repositoryInterface.setMetadataIdentifierPath(repositoryInterfaceObject.get("metadataIdentifierPath").toString()); |
|
208 |
repositoryInterface.setDesiredCompatibilityLevel(repositoryInterfaceObject.get("compatibility").toString()); |
|
209 |
//repositoryInterface.setActive(Boolean.parseBoolean(repositoryInterfaceObject.get("active").toString())); |
|
210 |
|
|
211 |
|
|
212 |
Map<String, String> accessParams = new HashMap<>(); |
|
213 |
Map<String, String> extraFields = new HashMap<>(); |
|
214 |
|
|
215 |
ObjectMapper mapper = new ObjectMapper(); |
|
216 |
JSONArray apiparams = repositoryInterfaceObject.getJSONArray("apiParams"); |
|
217 |
|
|
218 |
for(int i=0;i<apiparams.length();i++) |
|
219 |
accessParams.put(apiparams.getJSONObject(i).getString("param"),apiparams.getJSONObject(i).getString("value")); |
|
220 |
|
|
221 |
repositoryInterface.setAccessParams(accessParams); |
|
222 |
|
|
223 |
return repositoryInterface; |
|
224 |
} |
|
225 |
|
|
226 |
public static String repositoryObjectToJson(Repository repository) throws JSONException, JsonProcessingException { |
|
227 |
|
|
228 |
JSONObject jsonObject = new JSONObject(); |
|
229 |
|
|
230 |
jsonObject.put("id",repository.getId()); |
|
231 |
jsonObject.put("openaireId",getOpenaireId(repository.getId())); |
|
232 |
jsonObject.put("officialname",repository.getOfficialName()); |
|
233 |
jsonObject.put("englishname",repository.getEnglishName()); |
|
234 |
jsonObject.put("websiteurl",repository.getWebsiteUrl()); |
|
235 |
jsonObject.put("logourl",repository.getLogoUrl()); |
|
236 |
jsonObject.put("contactemail",repository.getContactEmail()); |
|
237 |
jsonObject.put("longitude",repository.getLongitude().toString()); |
|
238 |
jsonObject.put("latitude",repository.getLatitude().toString()); |
|
239 |
jsonObject.put("timezone",repository.getTimezone()); |
|
240 |
|
|
241 |
jsonObject.put("namespaceprefix",repository.getNamespacePrefix()!=null?repository.getNamespacePrefix():""); |
|
242 |
jsonObject.put("languages",repository.getOdLanguages()!=null?repository.getOdLanguages():""); |
|
243 |
|
|
244 |
jsonObject.put("dateofcollection",repository.getDateOfCollection()!=null?convertDateToString(repository.getDateOfCollection()):""); |
|
245 |
|
|
246 |
/* |
|
247 |
* typology -> platform |
|
248 |
* datasource class -> typology |
|
249 |
* */ |
|
250 |
jsonObject.put("typology",repository.getDatasourceClass()); |
|
251 |
jsonObject.put("platform",repository.getTypology()); |
|
252 |
|
|
253 |
jsonObject.put("dateofvalidation",repository.getDateOfCollection()!=null?convertDateToString(repository.getDateOfCollection()):""); |
|
254 |
jsonObject.put("activationId",repository.getActivationId()!=null?repository.getActivationId():""); |
|
255 |
|
|
256 |
jsonObject.put("description",repository.getDescription()); |
|
257 |
|
|
258 |
jsonObject.put("eissn",repository.getEissn()!=null?repository.getEissn():""); |
|
259 |
jsonObject.put("issn",repository.getIssn()!=null?repository.getIssn():""); |
|
260 |
jsonObject.put("lissn",repository.getLissn()!=null?repository.getLissn():""); |
|
261 |
|
|
262 |
jsonObject.put("registeredby",repository.getRegisteredBy()); |
|
263 |
|
|
264 |
jsonObject.put("aggregator",repository.getAggregator()!=null?repository.getAggregator():""); |
|
265 |
jsonObject.put("collectedfrom",repository.getCollectedFrom()!=null?repository.getCollectedFrom():""); |
|
266 |
|
|
267 |
jsonObject.put("managed",repository.isRegistered()); |
|
268 |
|
|
269 |
JSONObject organization = new JSONObject(); |
|
270 |
organization.put("legalname",repository.getOrganization()); |
|
271 |
organization.put("country",repository.getCountryCode()); |
|
272 |
organization.put("legalshortname",""); |
|
273 |
organization.put("websiteurl",""); |
|
274 |
organization.put("logourl",""); |
|
275 |
|
|
276 |
JSONArray organizations = new JSONArray(); |
|
277 |
organizations.put(organization); |
|
278 |
jsonObject.put("organizations",organizations); |
|
279 |
|
|
280 |
//TODO check identitites |
|
281 |
JSONArray identities = new JSONArray(); |
|
282 |
identities.put(identities); |
|
283 |
jsonObject.put("identities",identities); |
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
//TODO check fields |
|
288 |
/* jsonObject.put("certificates",repository.getCertificates()); |
|
289 |
jsonObject.put("citationguidelineurl",repository.getCitationGuidelineUrl()); |
|
290 |
jsonObject.put("databaseaccessrestriction",repository.getDatabaseAccessRestriction()); |
|
291 |
jsonObject.put("databaseaccesstype",repository.getDatabaseAccessType()); |
|
292 |
jsonObject.put("datauploadrestriction",repository.getDataUploadRestriction()); |
|
293 |
jsonObject.put("datauploadtype",repository.getDataUploadType()); |
|
294 |
jsonObject.put("missionstatementurl",repository.getMissionStatementUrl()); |
|
295 |
jsonObject.put("od_contenttypes",repository.getOdContentTypes()); |
|
296 |
jsonObject.put("officialname",repository.getOfficialname()); |
|
297 |
jsonObject.put("pidsystems",repository.getPidSystems()); |
|
298 |
jsonObject.put("provenanceaction",repository.getProvenanceActionClass()); |
|
299 |
jsonObject.put("qualitymanagementkind",repository.getQualityManagementKind()); |
|
300 |
jsonObject.put("releaseenddate",convertDateToString(repository.getReleaseEndDate())); |
|
301 |
jsonObject.put("releasestartdate",convertDateToString(repository.getReleaseStartDate())); |
|
302 |
jsonObject.put("serviceprovider",repository.getServiceProvider()); |
|
303 |
jsonObject.put("versioning",repository.getVersioning()); |
|
304 |
//datasource.get("platform"); |
|
305 |
//datasource.get("subjects");*/ |
|
306 |
|
|
307 |
ObjectMapper mapper = new ObjectMapper(); |
|
308 |
return mapper.writeValueAsString(jsonObject); |
|
309 |
} |
|
310 |
|
|
311 |
public static String repositoryInterfaceObjectToJson(Repository repository,RepositoryInterface repositoryInterface) throws JSONException { |
|
312 |
|
|
313 |
JSONObject jsonObject = new JSONObject(); |
|
314 |
|
|
315 |
jsonObject.put("id",repositoryInterface.getId()); |
|
316 |
jsonObject.put("protocol",repositoryInterface.getAccessProtocol()); |
|
317 |
jsonObject.put("datasource",repository.getId()); |
|
318 |
jsonObject.put("contentdescription",repositoryInterface.getContentDescription()); |
|
319 |
jsonObject.put("typology",repositoryInterface.getTypology()); |
|
320 |
jsonObject.put("compatibility",repositoryInterface.getDesiredCompatibilityLevel()); |
|
321 |
jsonObject.put("compatibilityOverride",repositoryInterface.getDesiredCompatibilityLevel()); |
|
322 |
|
|
323 |
jsonObject.put("lastCollectionTotal",""); |
|
324 |
|
|
325 |
jsonObject.put("lastCollectionDate",repositoryInterface.getLastCollectionDate()); |
|
326 |
jsonObject.put("lastAggregationTotal",""); |
|
327 |
jsonObject.put("lastAggregationDate",""); |
|
328 |
jsonObject.put("lastDownloadTotal",""); |
|
329 |
jsonObject.put("lastDownloadDate",""); |
|
330 |
|
|
331 |
jsonObject.put("baseurl",repositoryInterface.getBaseUrl()); |
|
332 |
jsonObject.put("removable",repositoryInterface.isRemovable()); |
|
333 |
|
|
334 |
|
|
335 |
JSONArray apiparams = new JSONArray(); |
|
336 |
for(String param: repositoryInterface.getAccessParams().keySet()){ |
|
337 |
JSONObject jo = new JSONObject(); |
|
338 |
jo.put("param",param); |
|
339 |
jo.put("value",repositoryInterface.getAccessParams().get(param)); |
|
340 |
apiparams.put(jo); |
|
341 |
} |
|
342 |
jsonObject.put("apiParams",apiparams); |
|
343 |
|
|
344 |
|
|
345 |
// jsonObject.put("metadataIdentifierPath",repositoryInterface.getMetadataIdentifierPath()); |
|
346 |
|
|
347 |
|
|
348 |
return jsonObject.toString(); |
|
349 |
} |
|
350 |
|
|
351 |
public static ArrayList<String> readFile(String filename) { |
|
352 |
String line; |
|
353 |
ArrayList<String> list = new ArrayList<String>(); |
|
354 |
try { |
|
355 |
//InputStream in = Converter.class.getResourceAsStream("resources/eu/dnetlib/repo/manager/service/utils/"+filename); |
|
356 |
InputStream in = Converter.class.getClass().getResourceAsStream("/eu/**/" + filename); |
|
357 |
BufferedReader br = new BufferedReader(new InputStreamReader(in)); |
|
358 |
while((line = br.readLine()) != null) { |
|
359 |
list.add(line.trim()); |
|
360 |
} |
|
361 |
br.close(); |
|
362 |
} catch (IOException e) { |
|
363 |
LOGGER.debug("Error opening file!"); |
|
364 |
e.printStackTrace(); |
|
365 |
} |
|
366 |
return list; |
|
367 |
} |
|
368 |
|
|
369 |
public static List<AggregationDetails> getAggregationHistoryFromJson(JSONObject datasourceInfo) throws JSONException { |
|
370 |
|
|
371 |
JSONArray rs = new JSONArray(datasourceInfo.get("aggregationHistory").toString()); |
|
372 |
List<AggregationDetails> aggregationDetailsList = new ArrayList<>(); |
|
373 |
for(int i=0;i<rs.length();i++) |
|
374 |
aggregationDetailsList.add(jsonToAggregationDetails(rs.getJSONObject(i))); |
|
375 |
return aggregationDetailsList; |
|
376 |
} |
|
377 |
|
|
378 |
private static AggregationDetails jsonToAggregationDetails(JSONObject aggregationObject) throws JSONException { |
|
379 |
|
|
380 |
AggregationDetails aggregationDetails = new AggregationDetails(); |
|
381 |
|
|
382 |
aggregationDetails.setAggregationStage(aggregationObject.get("aggregationStage").toString()); |
|
383 |
if(aggregationObject.has("collectionMode")) |
|
384 |
aggregationDetails.setCollectionMode(aggregationObject.get("collectionMode").toString()); |
|
385 |
if(aggregationObject.has("indexedVersion")) |
|
386 |
aggregationDetails.setIndexedVersion(Boolean.parseBoolean(aggregationObject.get("indexedVersion").toString())); |
|
387 |
aggregationDetails.setDate(convertStringToDate(aggregationObject.get("date").toString())); |
|
388 |
aggregationDetails.setNumberOfRecords(Integer.parseInt(aggregationObject.get("numberOfRecords").toString())); |
|
389 |
return aggregationDetails; |
|
390 |
} |
|
391 |
|
|
392 |
public static AggregationDetails getLastCollectionFromJson(JSONObject datasourceInfo) throws JSONException { |
|
393 |
|
|
394 |
if( datasourceInfo.get("lastCollection").equals(null)) |
|
395 |
return null; |
|
396 |
|
|
397 |
return jsonToAggregationDetails(datasourceInfo.getJSONObject("lastCollection")); |
|
398 |
} |
|
399 |
|
|
400 |
public static AggregationDetails getLastTransformationFromJson(JSONObject datasourceInfo) throws JSONException { |
|
401 |
|
|
402 |
if( datasourceInfo.get("lastTransformation").equals(null)) |
|
403 |
return null; |
|
404 |
|
|
405 |
return jsonToAggregationDetails(datasourceInfo.getJSONObject("lastTransformation")); |
|
406 |
} |
|
407 |
|
|
408 |
public static List<Timezone> toTimezones(List<String> timezones) { |
|
409 |
|
|
410 |
List<Timezone> tmz = new ArrayList<>(); |
|
411 |
for(String t : timezones){ |
|
412 |
String[] s = t.split("\t"); |
|
413 |
tmz.add(new Timezone(s[1],Double.parseDouble(s[0]))); |
|
414 |
} |
|
415 |
return tmz; |
|
416 |
} |
|
417 |
|
|
418 |
public static String getOpenaireId(String repositoryId) { |
|
419 |
if (repositoryId != null && repositoryId.contains("::")) |
|
420 |
return repositoryId.split("::")[0] + "::" + DigestUtils.md5Hex(repositoryId.split("::")[1]); |
|
421 |
return null; |
|
422 |
} |
|
423 |
|
|
424 |
} |
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/utils/OaiTools.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.utils; |
|
2 |
|
|
3 |
import org.apache.log4j.Logger; |
|
4 |
import org.dom4j.io.DOMWriter; |
|
5 |
import org.w3c.dom.Document; |
|
6 |
import se.kb.oai.pmh.*; |
|
7 |
import se.kb.oai.pmh.Set; |
|
8 |
|
|
9 |
import javax.net.ssl.*; |
|
10 |
import javax.xml.namespace.NamespaceContext; |
|
11 |
import javax.xml.xpath.XPath; |
|
12 |
import javax.xml.xpath.XPathExpressionException; |
|
13 |
import javax.xml.xpath.XPathFactory; |
|
14 |
import java.security.KeyManagementException; |
|
15 |
import java.security.NoSuchAlgorithmException; |
|
16 |
import java.security.cert.X509Certificate; |
|
17 |
import java.util.*; |
|
18 |
|
|
19 |
public class OaiTools { |
|
20 |
|
|
21 |
{ |
|
22 |
disableSslVerification(); |
|
23 |
} |
|
24 |
|
|
25 |
private static Logger LOGGER = Logger.getLogger(OaiTools.class); |
|
26 |
|
|
27 |
public static List<String> getSetsOfRepo(String baseUrl) throws Exception { |
|
28 |
try { |
|
29 |
LOGGER.debug("Getting sets of repository " + baseUrl); |
|
30 |
OaiPmhServer harvester = new OaiPmhServer(baseUrl); |
|
31 |
SetsList setList = harvester.listSets(); |
|
32 |
ResumptionToken token = setList.getResumptionToken(); |
|
33 |
List<Set> sets = new ArrayList<Set>(); |
|
34 |
sets.addAll(setList.asList()); |
|
35 |
while (token != null) { |
|
36 |
setList = harvester.listSets(token); |
|
37 |
token = setList.getResumptionToken(); |
|
38 |
sets.addAll(setList.asList()); |
|
39 |
} |
|
40 |
|
|
41 |
List<String> ret = new ArrayList<String>(); |
|
42 |
for (Set set : sets) { |
|
43 |
ret.add(set.getSpec().trim()); |
|
44 |
} |
|
45 |
if (ret.size() > 0 ) |
|
46 |
Collections.sort(ret); |
|
47 |
return ret; |
|
48 |
|
|
49 |
} catch (Exception e) { |
|
50 |
LOGGER.error("Error getting sets of repository " + baseUrl, e); |
|
51 |
return new ArrayList<String>(); |
|
52 |
//throw e; |
|
53 |
} |
|
54 |
} |
|
55 |
|
|
56 |
public static boolean identifyRepository(String baseUrl) throws Exception { |
|
57 |
LOGGER.debug("sending identify request to repo " + baseUrl); |
|
58 |
|
|
59 |
OaiPmhServer harvester = new OaiPmhServer(baseUrl); |
|
60 |
|
|
61 |
if (baseUrl.trim().isEmpty()) { |
|
62 |
return false; |
|
63 |
} |
|
64 |
|
|
65 |
try { |
|
66 |
Identification identification = harvester.identify(); |
|
67 |
DOMWriter d4Writer = new DOMWriter(); |
|
68 |
Document d = d4Writer.write(identification.getResponse()); |
|
69 |
|
|
70 |
return verifyIdentify(d); |
|
71 |
} catch (Exception e) { |
|
72 |
LOGGER.debug("Error verifying identify response", e); |
|
73 |
throw e; |
|
74 |
} |
|
75 |
} |
|
76 |
|
|
77 |
private static boolean verifyIdentify(Document doc) throws XPathExpressionException { |
|
78 |
NamespaceContext ctx = new NamespaceContext() { |
|
79 |
public String getNamespaceURI(String prefix) { |
|
80 |
String uri; |
|
81 |
if (prefix.equals("oai")) |
|
82 |
uri = "http://www.openarchives.org/OAI/2.0/"; |
|
83 |
else |
|
84 |
uri = null; |
|
85 |
return uri; |
|
86 |
} |
|
87 |
|
|
88 |
// Dummy implementation - not used! |
|
89 |
public Iterator<String> getPrefixes(String val) { |
|
90 |
return null; |
|
91 |
} |
|
92 |
|
|
93 |
// Dummy implemenation - not used! |
|
94 |
public String getPrefix(String uri) { |
|
95 |
return null; |
|
96 |
} |
|
97 |
}; |
|
98 |
|
|
99 |
// Now the XPath expression |
|
100 |
|
|
101 |
String xpathStr = "//oai:OAI-PMH/oai:Identify"; |
|
102 |
XPathFactory xpathFact = XPathFactory.newInstance(); |
|
103 |
XPath xpath = xpathFact.newXPath(); |
|
104 |
xpath.setNamespaceContext(ctx); |
|
105 |
String result = xpath.evaluate(xpathStr, doc); |
|
106 |
|
|
107 |
return (result != null && !result.equals("")); |
|
108 |
} |
|
109 |
|
|
110 |
private static void disableSslVerification() { |
|
111 |
try |
|
112 |
{ |
|
113 |
LOGGER.debug("disabling ssl verification"); |
|
114 |
// Create a trust manager that does not validate certificate chains |
|
115 |
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() { |
|
116 |
public X509Certificate[] getAcceptedIssuers() { |
|
117 |
return null; |
|
118 |
} |
|
119 |
public void checkClientTrusted(X509Certificate[] certs, String authType) { |
|
120 |
} |
|
121 |
public void checkServerTrusted(X509Certificate[] certs, String authType) { |
|
122 |
} |
|
123 |
} |
|
124 |
}; |
|
125 |
|
|
126 |
// Install the all-trusting trust manager |
|
127 |
SSLContext sc = SSLContext.getInstance("SSL"); |
|
128 |
sc.init(null, trustAllCerts, new java.security.SecureRandom()); |
|
129 |
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); |
|
130 |
|
|
131 |
// Create all-trusting host name verifier |
|
132 |
HostnameVerifier allHostsValid = new HostnameVerifier() { |
|
133 |
public boolean verify(String hostname, SSLSession session) { |
|
134 |
return true; |
|
135 |
} |
|
136 |
}; |
|
137 |
|
|
138 |
// Install the all-trusting host verifier |
|
139 |
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); |
|
140 |
} catch (NoSuchAlgorithmException e) { |
|
141 |
LOGGER.error("disabling ssl verification", e); |
|
142 |
} catch (KeyManagementException e) { |
|
143 |
LOGGER.error("error while disabling ssl verification", e); |
|
144 |
} |
|
145 |
} |
|
146 |
} |
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/config/RepoManagerContextLoaderListener.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.config; |
|
2 |
|
|
3 |
import org.apache.commons.lang.ArrayUtils; |
|
4 |
import org.apache.log4j.Logger; |
|
5 |
import org.springframework.beans.BeansException; |
|
6 |
import org.springframework.context.support.ClassPathXmlApplicationContext; |
|
7 |
import org.springframework.web.context.ContextLoaderListener; |
|
8 |
import org.springframework.web.context.WebApplicationContext; |
|
9 |
import org.springframework.web.context.support.XmlWebApplicationContext; |
|
10 |
|
|
11 |
import javax.servlet.ServletContext; |
|
12 |
import java.util.Properties; |
|
13 |
|
|
14 |
public class RepoManagerContextLoaderListener extends ContextLoaderListener { |
|
15 |
private static Logger logger = Logger.getLogger(RepoManagerContextLoaderListener.class); |
|
16 |
|
|
17 |
|
|
18 |
public RepoManagerContextLoaderListener() { |
|
19 |
super(); |
|
20 |
} |
|
21 |
|
|
22 |
public RepoManagerContextLoaderListener(WebApplicationContext context) { |
|
23 |
super(context); |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
protected WebApplicationContext createWebApplicationContext( |
|
28 |
ServletContext servletContext) |
|
29 |
throws BeansException { |
|
30 |
logger.debug("Creating web application context"); |
|
31 |
Properties props = this.loadProperties(); |
|
32 |
String repoMode = props.getProperty("services.validator.mode.repo"); |
|
33 |
String userMode = props.getProperty("services.validator.mode.user"); |
|
34 |
Boolean standaloneMode = Boolean.parseBoolean(props.getProperty("services.validator.mode.standalone")); |
|
35 |
|
|
36 |
logger.info("User mode: " + userMode); |
|
37 |
logger.info("Repo mode: " + repoMode); |
|
38 |
logger.info("Standalone mode: " + standaloneMode); |
|
39 |
// logger.info("Dnet workflow enabled: " + repoMode); |
|
40 |
XmlWebApplicationContext ctx = new XmlWebApplicationContext(); |
|
41 |
|
|
42 |
ctx.setServletContext(servletContext); |
|
43 |
|
|
44 |
String userApiContext = null; |
|
45 |
if (userMode.equalsIgnoreCase("local")) |
|
46 |
userApiContext = "eu/dnetlib/validator/web/api/impls/users/springContext-validator-user-local.xml"; |
|
47 |
else if (userMode.equalsIgnoreCase("ldap")) |
|
48 |
userApiContext = "eu/dnetlib/users/springContext-users-ldap.xml"; |
|
49 |
|
|
50 |
String[] springContextCore = new String[] { |
|
51 |
"classpath:META-INF/cxf/cxf.xml", |
|
52 |
"classpath:META-INF/cxf/cxf-extension-soap.xml", |
|
53 |
"classpath:META-INF/cxf/cxf-extension-jaxws.xml", |
|
54 |
"classpath:META-INF/cxf/cxf-servlet.xml", |
|
55 |
"classpath*:/cxf.xml", |
|
56 |
"classpath*:/eu/dnetlib/repos/ehcacher/springContext-repos-ehcacher.xml", |
|
57 |
"classpath*:/eu/dnetlib/clients/ws/springContext-locatorFactory.xml", |
|
58 |
"classpath*:/eu/dnetlib/soap/cxf/applicationContext-eprbuilders.xml", |
|
59 |
// "classpath*:/eu/dnetlib/validator/web/actions/springContext-validator-struts.xml", |
|
60 |
// "classpath*:/eu/dnetlib/validator/web/actions/springContext-validator-emailer.xml", |
|
61 |
// "classpath*:/eu/dnetlib/validator/web/config/springContext-validator.xml", |
|
62 |
"classpath*:/eu/dnetlib/repo/manager/server/config/springContext-repo-manager-config.xml", |
|
63 |
// "classpath*:/eu/dnetlib/validator/commons/dao/springContext-*.xml", |
|
64 |
"classpath*:/eu/dnetlib/repos/springContext-repos-" + repoMode + ".xml", |
|
65 |
"classpath*:/" + userApiContext |
|
66 |
}; |
|
67 |
|
|
68 |
|
|
69 |
String[] springContextForStandalone = new String[] { |
|
70 |
}; |
|
71 |
|
|
72 |
String[] springContextForIS = new String[] { |
|
73 |
"classpath*:/gr/uoa/di/driver/util/springContext-locators.xml", |
|
74 |
"classpath*:/gr/uoa/di/driver/app/springContext-lookupFactory.xml", |
|
75 |
"classpath*:/gr/uoa/di/driver/app/springContext-lookupClients.xml", |
|
76 |
"classpath*:/eu/dnetlib/enabling/hcm/springContext-hcmService.xml", |
|
77 |
"classpath*:/gr/uoa/di/driver/app/springContext-commons.xml", |
|
78 |
"classpath*:/gr/uoa/di/driver/app/springContext-registrator.xml" |
|
79 |
}; |
|
80 |
|
|
81 |
if (standaloneMode) { |
|
82 |
logger.debug("Loading contexts for standalone mode"); |
|
83 |
ctx.setConfigLocations((String[])ArrayUtils.addAll(springContextCore,springContextForStandalone)); |
|
84 |
} else { |
|
85 |
logger.debug("Loading contexts for dnet"); |
|
86 |
ctx.setConfigLocations((String[])ArrayUtils.addAll(springContextCore,springContextForIS)); |
|
87 |
} |
|
88 |
|
|
89 |
ctx.refresh(); |
|
90 |
|
|
91 |
logger.debug("done"); |
|
92 |
|
|
93 |
return ctx; |
|
94 |
} |
|
95 |
|
|
96 |
private Properties loadProperties() { |
|
97 |
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { |
|
98 |
"classpath*:/eu/dnetlib/repo/manager/server/config/springContext-repo-manager-config.xml" |
|
99 |
}); |
|
100 |
|
|
101 |
CascadingPropertyLoader pLoader = (CascadingPropertyLoader) ctx.getBean("propertyLoader"); |
|
102 |
Properties props = pLoader.getProperties(); |
|
103 |
|
|
104 |
ctx.destroy(); |
|
105 |
ctx.close(); |
|
106 |
return props; |
|
107 |
} |
|
108 |
|
|
109 |
} |
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/config/OpenAireProviderAuthoritiesMapper.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.config; |
|
2 |
|
|
3 |
import com.nimbusds.jwt.JWT; |
|
4 |
import org.mitre.openid.connect.client.OIDCAuthoritiesMapper; |
|
5 |
import org.mitre.openid.connect.model.UserInfo; |
|
6 |
import org.slf4j.Logger; |
|
7 |
import org.slf4j.LoggerFactory; |
|
8 |
import org.springframework.security.core.GrantedAuthority; |
|
9 |
import org.springframework.security.core.authority.SimpleGrantedAuthority; |
|
10 |
|
|
11 |
import java.util.*; |
|
12 |
|
|
13 |
public class OpenAireProviderAuthoritiesMapper implements OIDCAuthoritiesMapper { |
|
14 |
|
|
15 |
private static Logger logger = LoggerFactory.getLogger(OpenAireProviderAuthoritiesMapper.class); |
|
16 |
|
|
17 |
final private static String ROLE_CLAIMS = "edu_person_entitlements"; |
|
18 |
|
|
19 |
private Map<String,SimpleGrantedAuthority> userRolesMap; |
|
20 |
|
|
21 |
OpenAireProviderAuthoritiesMapper(Map<String,String> userRoles) { |
|
22 |
userRolesMap = new HashMap<>(); |
|
23 |
userRoles.forEach((openaireRole, appRole) -> userRolesMap.put(openaireRole, new SimpleGrantedAuthority(appRole))); |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public Collection<? extends GrantedAuthority> mapAuthorities(JWT idToken, UserInfo userInfo) { |
|
28 |
Set<GrantedAuthority> out = new HashSet<>(); |
|
29 |
out.add(new SimpleGrantedAuthority("ROLE_USER")); |
|
30 |
|
|
31 |
if(userInfo.getSource().getAsJsonArray(ROLE_CLAIMS) != null) { |
|
32 |
userInfo.getSource().getAsJsonArray(ROLE_CLAIMS).forEach(role -> { |
|
33 |
SimpleGrantedAuthority authority = userRolesMap.get(role.getAsString()); |
|
34 |
if (authority != null) { |
|
35 |
logger.debug("Role mapped " + role); |
|
36 |
out.add(authority); |
|
37 |
} |
|
38 |
}); |
|
39 |
} |
|
40 |
return out; |
|
41 |
} |
|
42 |
} |
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/config/FrontEndLinkURIAuthenticationSuccessHandler.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.config; |
|
2 |
|
|
3 |
import com.google.gson.JsonObject; |
|
4 |
import org.apache.log4j.Logger; |
|
5 |
import org.mitre.openid.connect.model.OIDCAuthenticationToken; |
|
6 |
import org.springframework.beans.factory.annotation.Value; |
|
7 |
import org.springframework.security.core.Authentication; |
|
8 |
import org.springframework.security.web.authentication.AuthenticationSuccessHandler; |
|
9 |
|
|
10 |
import javax.servlet.ServletException; |
|
11 |
import javax.servlet.http.Cookie; |
|
12 |
import javax.servlet.http.HttpServletRequest; |
|
13 |
import javax.servlet.http.HttpServletResponse; |
|
14 |
import java.io.IOException; |
|
15 |
import java.net.URLEncoder; |
|
16 |
import com.google.gson.*; |
|
17 |
|
|
18 |
public class FrontEndLinkURIAuthenticationSuccessHandler implements AuthenticationSuccessHandler { |
|
19 |
|
|
20 |
private String frontEndURI; |
|
21 |
|
|
22 |
private static final Logger LOGGER = Logger |
|
23 |
.getLogger(FrontEndLinkURIAuthenticationSuccessHandler.class); |
|
24 |
|
|
25 |
public void init(){ |
|
26 |
LOGGER.debug("Front end uri : " + frontEndURI); |
|
27 |
} |
|
28 |
|
|
29 |
|
|
30 |
@Value("${aai.mode}") |
|
31 |
private String aai_mode; |
|
32 |
|
|
33 |
@Override |
|
34 |
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { |
|
35 |
|
|
36 |
OIDCAuthenticationToken authOIDC = (OIDCAuthenticationToken) authentication; |
|
37 |
JsonObject userInfo = new JsonObject(); |
|
38 |
|
|
39 |
if (authOIDC.getUserInfo().getSub() == null) |
|
40 |
userInfo.addProperty("sub", ""); |
|
41 |
else |
|
42 |
userInfo.addProperty("sub", URLEncoder.encode(authOIDC.getUserInfo().getSub(), "UTF-8")); |
|
43 |
|
|
44 |
|
|
45 |
if(authOIDC.getUserInfo().getName() != null) |
|
46 |
userInfo.addProperty("fullname", URLEncoder.encode(authOIDC.getUserInfo().getName(), "UTF-8")); |
|
47 |
|
|
48 |
if (authOIDC.getUserInfo().getGivenName() == null) |
|
49 |
userInfo.addProperty("firstname", ""); |
|
50 |
else |
|
51 |
userInfo.addProperty("firstname", URLEncoder.encode(authOIDC.getUserInfo().getGivenName(), "UTF-8") + ""); |
|
52 |
|
|
53 |
if (authOIDC.getUserInfo().getFamilyName() == null) |
|
54 |
userInfo.addProperty("lastname", ""); |
|
55 |
else |
|
56 |
userInfo.addProperty("lastname", URLEncoder.encode(authOIDC.getUserInfo().getFamilyName(), "UTF-8") + ""); |
|
57 |
|
|
58 |
userInfo.addProperty("email", authOIDC.getUserInfo().getEmail() + ""); |
|
59 |
if (authOIDC.getUserInfo().getSource().getAsJsonArray("edu_person_entitlements") == null) |
|
60 |
userInfo.addProperty("role", ""); |
|
61 |
else |
|
62 |
userInfo.addProperty("role", URLEncoder.encode(authOIDC.getUserInfo() |
|
63 |
.getSource().getAsJsonArray("edu_person_entitlements").toString(), "UTF-8") + ""); |
|
64 |
|
|
65 |
|
|
66 |
Cookie openAIREUser = new Cookie("openAIREUser", new Gson().toJson(userInfo) ); |
|
67 |
openAIREUser.setMaxAge(14400); |
|
68 |
openAIREUser.setPath("/"); |
|
69 |
if(aai_mode.equalsIgnoreCase("production") || aai_mode.equalsIgnoreCase("beta")) |
|
70 |
openAIREUser .setDomain(".openaire.eu"); |
|
71 |
// openAIREUser.setDomain(".athenarc.gr"); |
|
72 |
response.addCookie(openAIREUser); |
|
73 |
|
|
74 |
|
|
75 |
Cookie accessToken = new Cookie("AccessToken", authOIDC.getAccessTokenValue()); |
|
76 |
accessToken.setMaxAge(14400); |
|
77 |
if(aai_mode.equalsIgnoreCase("production") || aai_mode.equalsIgnoreCase("beta")) |
|
78 |
accessToken.setDomain(".openaire.eu"); |
|
79 |
accessToken.setPath("/"); |
|
80 |
|
|
81 |
// accessToken.setDomain(".athenarc.gr"); |
|
82 |
response.addCookie(accessToken); |
|
83 |
response.sendRedirect(frontEndURI); |
|
84 |
} |
|
85 |
|
|
86 |
public String getFrontEndURI() { |
|
87 |
return frontEndURI; |
|
88 |
} |
|
89 |
|
|
90 |
public void setFrontEndURI(String frontEndURI) { |
|
91 |
this.frontEndURI = frontEndURI; |
|
92 |
} |
|
93 |
} |
|
94 |
|
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/config/Config.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.config; |
|
2 |
|
|
3 |
import org.apache.log4j.Logger; |
|
4 |
import org.springframework.beans.factory.annotation.Value; |
|
5 |
import org.springframework.context.annotation.Bean; |
|
6 |
import org.springframework.context.annotation.ComponentScan; |
|
7 |
import org.springframework.context.annotation.Configuration; |
|
8 |
import org.springframework.context.annotation.PropertySource; |
|
9 |
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; |
|
10 |
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; |
|
11 |
import org.springframework.session.web.http.CookieSerializer; |
|
12 |
import org.springframework.session.web.http.DefaultCookieSerializer; |
|
13 |
|
|
14 |
import javax.annotation.PostConstruct; |
|
15 |
|
|
16 |
@Configuration |
|
17 |
@EnableRedisHttpSession |
|
18 |
@PropertySource(value = {"classpath:application.properties"} ) |
|
19 |
@ComponentScan(basePackages = "eu.dnetlib.repo.manager.service.controllers") |
|
20 |
|
|
21 |
public class Config { |
|
22 |
|
|
23 |
private static Logger LOGGER = Logger.getLogger(Config.class); |
|
24 |
|
|
25 |
@Value("${redis.host:194.177.192.121}") |
|
26 |
private String host; |
|
27 |
|
|
28 |
@Value("${redis.port:6379}") |
|
29 |
private String port; |
|
30 |
|
|
31 |
@Value("${redis.password}") |
|
32 |
private String password; |
|
33 |
|
|
34 |
@Value("${aai.mode}") |
|
35 |
private String aai_mode; |
|
36 |
|
|
37 |
@PostConstruct |
|
38 |
private void init(){ |
|
39 |
LOGGER.info(host); |
|
40 |
} |
|
41 |
|
|
42 |
@Bean |
|
43 |
JedisConnectionFactory connectionFactory() { |
|
44 |
LOGGER.info(String.format("Redis : %s Port : %s Password : %s",host,port,password)); |
|
45 |
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(); |
|
46 |
jedisConnectionFactory.setHostName(host); |
|
47 |
jedisConnectionFactory.setPort(Integer.parseInt(port)); |
|
48 |
if(password != null) jedisConnectionFactory.setPassword(password); |
|
49 |
return jedisConnectionFactory; |
|
50 |
} |
|
51 |
|
|
52 |
@Bean |
|
53 |
public CookieSerializer cookieSerializer() { |
|
54 |
DefaultCookieSerializer serializer = new DefaultCookieSerializer(); |
|
55 |
serializer.setCookieName("openAIRESession"); |
|
56 |
serializer.setCookiePath("/"); |
|
57 |
if(aai_mode.equalsIgnoreCase("production") || aai_mode.equalsIgnoreCase("beta")) |
|
58 |
serializer.setDomainName(".openaire.eu"); |
|
59 |
// serializer.setDomainName(".athenarc.gr"); |
|
60 |
LOGGER.info("Serializer : " + serializer); |
|
61 |
return serializer; |
|
62 |
} |
|
63 |
|
|
64 |
} |
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/config/SwaggerConfig.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.config; |
|
2 |
|
|
3 |
import eu.dnetlib.repo.manager.service.controllers.MonitorApi; |
|
4 |
import eu.dnetlib.repo.manager.service.controllers.PiWikApi; |
|
5 |
import eu.dnetlib.repo.manager.service.controllers.RepositoryApi; |
|
6 |
import eu.dnetlib.repo.manager.service.controllers.ValidatorApi; |
|
7 |
import org.springframework.context.annotation.Bean; |
|
8 |
import org.springframework.context.annotation.ComponentScan; |
|
9 |
import org.springframework.context.annotation.Configuration; |
|
10 |
import org.springframework.web.servlet.config.annotation.EnableWebMvc; |
|
11 |
import springfox.documentation.builders.PathSelectors; |
|
12 |
import springfox.documentation.builders.RequestHandlerSelectors; |
|
13 |
import springfox.documentation.service.ApiInfo; |
|
14 |
import springfox.documentation.service.Contact; |
|
15 |
import springfox.documentation.service.VendorExtension; |
|
16 |
import springfox.documentation.spi.DocumentationType; |
|
17 |
import springfox.documentation.spring.web.plugins.Docket; |
|
18 |
import springfox.documentation.swagger2.annotations.EnableSwagger2; |
|
19 |
import java.util.ArrayList; |
|
20 |
|
|
21 |
|
|
22 |
/** |
|
23 |
* Created by panagiotis on 16/11/2017. |
|
24 |
*/ |
|
25 |
@Configuration |
|
26 |
@EnableSwagger2 |
|
27 |
@EnableWebMvc |
|
28 |
@ComponentScan(basePackageClasses = { |
|
29 |
RepositoryApi.class, |
|
30 |
MonitorApi.class, |
|
31 |
ValidatorApi.class, |
|
32 |
PiWikApi.class |
|
33 |
}) |
|
34 |
public class SwaggerConfig { |
|
35 |
|
|
36 |
@Bean |
|
37 |
public Docket productApi() { |
|
38 |
return new Docket(DocumentationType.SWAGGER_2) |
|
39 |
.select() |
|
40 |
.apis(RequestHandlerSelectors.any()) |
|
41 |
.paths(PathSelectors.any()) |
|
42 |
.build() |
|
43 |
.pathMapping("/") |
|
44 |
.apiInfo(getApiInfo()); |
|
45 |
} |
|
46 |
|
|
47 |
private ApiInfo getApiInfo() { |
|
48 |
return new ApiInfo("Repository Manager Dashboard API Documentation", |
|
49 |
"Repository Manager Dashboard API Documentation", |
|
50 |
"1.0", |
|
51 |
"urn:tos", |
|
52 |
new Contact("", "", ""), |
|
53 |
"Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", |
|
54 |
new ArrayList<VendorExtension>()); |
|
55 |
} |
|
56 |
|
|
57 |
} |
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/config/CascadingPropertyLoader.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.config; |
|
2 |
|
|
3 |
import org.springframework.beans.BeansException; |
|
4 |
import org.springframework.beans.factory.InitializingBean; |
|
5 |
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; |
|
6 |
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; |
|
7 |
|
|
8 |
import java.util.Properties; |
|
9 |
|
|
10 |
/** |
|
11 |
* CascadingPropertyLoader loads a number of property files and mergers them together, so that the last properties |
|
12 |
* override the previous. It also supports property expansion like: |
|
13 |
* |
|
14 |
* <code> |
|
15 |
* something = 1 |
|
16 |
* somethingelse = 2 |
|
17 |
* test = ${something}/${somethingelse} |
|
18 |
* </code> |
|
19 |
* |
|
20 |
* <p> |
|
21 |
* And if you override something to XX, then test will become XX/2 |
|
22 |
* </p> |
|
23 |
* |
|
24 |
* |
|
25 |
* @author marko |
|
26 |
* |
|
27 |
*/ |
|
28 |
public class CascadingPropertyLoader extends PropertyPlaceholderConfigurer implements InitializingBean { |
|
29 |
|
|
30 |
private Properties properties; |
|
31 |
|
|
32 |
public void afterPropertiesSet() throws Exception { |
|
33 |
this.properties = mergeProperties(); |
|
34 |
|
|
35 |
// Convert the merged properties, if necessary. |
|
36 |
convertProperties(this.properties); |
|
37 |
|
|
38 |
logger.debug("Properties: " + properties); |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
protected void processProperties(final ConfigurableListableBeanFactory beanFactoryToProcess, final Properties props) throws BeansException { |
|
43 |
super.processProperties(beanFactoryToProcess, props); |
|
44 |
} |
|
45 |
|
|
46 |
public Properties getProperties() { |
|
47 |
return properties; |
|
48 |
} |
|
49 |
|
|
50 |
public void setProperties(final Properties properties) { |
|
51 |
super.setProperties(properties); |
|
52 |
|
|
53 |
this.properties = properties; |
|
54 |
} |
|
55 |
} |
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/controllers/EmailUtils.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
import eu.dnetlib.domain.data.PiwikInfo; |
|
4 |
import eu.dnetlib.domain.data.Repository; |
|
5 |
import eu.dnetlib.domain.functionality.validator.JobForValidation; |
|
6 |
import org.springframework.security.core.Authentication; |
|
7 |
|
|
8 |
public interface EmailUtils { |
|
9 |
|
|
10 |
|
|
11 |
void reportException(Exception exception); |
|
12 |
|
|
13 |
void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception; |
|
14 |
|
|
15 |
void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception; |
|
16 |
|
|
17 |
void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) throws Exception; |
|
18 |
|
|
19 |
void sendUserMetricsEnabled(PiwikInfo piwikInfo) throws Exception; |
|
20 |
|
|
21 |
void sendUserRegistrationEmail(Repository repository, Authentication authentication) throws Exception; |
|
22 |
|
|
23 |
void sendUserUpdateRepositoryEmail(Repository repository, Authentication authentication) throws Exception; |
|
24 |
|
|
25 |
void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation) throws Exception; |
|
26 |
} |
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/controllers/UserApi.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
import io.swagger.annotations.Api; |
|
4 |
import org.springframework.http.ResponseEntity; |
|
5 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
6 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
7 |
import org.springframework.web.bind.annotation.RestController; |
|
8 |
|
|
9 |
@RestController |
|
10 |
@RequestMapping(value = "/user") |
|
11 |
@Api(description = "User API", tags = {"user"}) |
|
12 |
public interface UserApi { |
|
13 |
|
|
14 |
@RequestMapping(value = "/login" , method = RequestMethod.GET) |
|
15 |
ResponseEntity<Object> login(); |
|
16 |
|
|
17 |
|
|
18 |
} |
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApi.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
import eu.dnetlib.domain.data.Repository; |
|
4 |
import eu.dnetlib.domain.data.RepositoryInterface; |
|
5 |
import eu.dnetlib.repo.manager.service.domain.RepositorySnippet; |
|
6 |
import eu.dnetlib.repo.manager.service.exception.ResourceNotFoundException; |
|
7 |
import eu.dnetlib.repo.manager.shared.*; |
|
8 |
import io.swagger.annotations.Api; |
|
9 |
import org.json.JSONException; |
|
10 |
import org.springframework.http.MediaType; |
|
11 |
import org.springframework.security.core.Authentication; |
|
12 |
import org.springframework.web.bind.annotation.*; |
|
13 |
|
|
14 |
import java.io.IOException; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Map; |
|
17 |
|
|
18 |
|
|
19 |
@RestController |
|
20 |
@RequestMapping(value = "/repository") |
|
21 |
@Api(description = "Repository API", tags = {"repository"}) |
|
22 |
public interface RepositoryApi { |
|
23 |
|
|
24 |
@RequestMapping(value = "/getCountries", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) |
|
25 |
@ResponseBody |
|
26 |
Country[] getCountries() ; |
|
27 |
|
|
28 |
@RequestMapping(value = "/getRepositoriesByCountry/{country}/{mode}", method = RequestMethod.GET, |
|
29 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
30 |
@ResponseBody |
|
31 |
List<RepositorySnippet> getRepositoriesByCountry(String country, String mode, Boolean managed) throws JSONException, IOException; |
|
32 |
|
|
33 |
@RequestMapping(value = "/getRepositoriesOfUser/{userEmail}/{page}/{size}",method = RequestMethod.GET, |
|
34 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
35 |
@ResponseBody |
|
36 |
List<Repository> getRepositoriesOfUser(String userEmail, |
|
37 |
String page, |
|
38 |
String size) throws JSONException; |
|
39 |
|
|
40 |
@RequestMapping(value = "/getRepositoryById/{id}", method = RequestMethod.GET, |
|
41 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
42 |
@ResponseBody |
|
43 |
Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException; |
|
44 |
|
|
45 |
|
|
46 |
@RequestMapping(value = "/getRepositoryAggregations/{id}", method = RequestMethod.GET, |
|
47 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
48 |
@ResponseBody |
|
49 |
List<AggregationDetails> getRepositoryAggregations(String id) throws JSONException; |
|
50 |
|
|
51 |
@RequestMapping(value = "/getRepositoryAggregationsByYear/{id}", method = RequestMethod.GET, |
|
52 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
53 |
@ResponseBody |
|
54 |
Map<String,List<AggregationDetails>> getRepositoryAggregationsByYear(String id) throws JSONException; |
|
55 |
|
|
56 |
|
|
57 |
@RequestMapping(value = "/getRepositoriesByName/{name:.+}/{page}/{size}/", method = RequestMethod.GET, |
|
58 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
59 |
@ResponseBody |
|
60 |
List<Repository> getRepositoriesByName(String name, |
|
61 |
String page, |
|
62 |
String size) throws JSONException; |
|
63 |
|
|
64 |
@RequestMapping(value = "/getRepositoryInterface/{id}", method = RequestMethod.GET, |
|
65 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
66 |
@ResponseBody |
|
67 |
List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException; |
|
68 |
|
|
69 |
@RequestMapping(value = "/addRepository", method = RequestMethod.POST, |
|
70 |
consumes = MediaType.APPLICATION_JSON_VALUE) |
|
71 |
@ResponseBody |
|
72 |
Repository addRepository(String datatype, Repository repository) throws Exception; |
|
73 |
|
|
74 |
|
|
75 |
@RequestMapping(value = "/deleteInterface/", method = RequestMethod.DELETE) |
|
76 |
void deleteRepositoryInterface(String id,String registeredBy); |
|
77 |
|
|
78 |
@RequestMapping(value = "/addInterface", method = RequestMethod.POST, |
|
79 |
consumes = MediaType.APPLICATION_JSON_VALUE) |
|
80 |
@ResponseBody |
|
81 |
RepositoryInterface addRepositoryInterface(String datatype, |
|
82 |
String repoId, |
|
83 |
String registeredBy, |
|
84 |
RepositoryInterface iFace) throws JSONException,ResourceNotFoundException; |
|
85 |
|
|
86 |
@RequestMapping(value = "/getDnetCountries", method = RequestMethod.GET, |
|
87 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
88 |
@ResponseBody |
|
89 |
List<String> getDnetCountries(); |
|
90 |
|
|
91 |
@RequestMapping(value = "/getTypologies", method = RequestMethod.GET, |
|
92 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
93 |
@ResponseBody |
|
94 |
List<String> getTypologies(); |
|
95 |
|
|
96 |
@RequestMapping(value = "/getTimezones", method = RequestMethod.GET, |
|
97 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
98 |
@ResponseBody |
|
99 |
List<Timezone> getTimezones(); |
|
100 |
|
|
101 |
@RequestMapping(value = "/updateRepository", method = RequestMethod.POST, |
|
102 |
consumes = MediaType.APPLICATION_JSON_VALUE) |
|
103 |
@ResponseBody |
|
104 |
Repository updateRepository(Repository repository, Authentication authentication) throws Exception; |
|
105 |
|
|
106 |
@RequestMapping(value = "/getUrlsOfUserRepos/{user_email}/{page}/{size}/",method = RequestMethod.GET, |
|
107 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
108 |
@ResponseBody |
|
109 |
List<String> getUrlsOfUserRepos(String user_email, |
|
110 |
String page, |
|
111 |
String size) throws JSONException; |
|
112 |
|
|
113 |
@RequestMapping(value = "/getDatasourceVocabularies/{mode}",method = RequestMethod.GET, |
|
114 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
115 |
@ResponseBody |
|
116 |
List<String> getDatasourceVocabularies(String mode); |
|
117 |
|
|
118 |
@RequestMapping(value = "/getCompatibilityClasses/{mode}",method = RequestMethod.GET, |
|
119 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
120 |
@ResponseBody |
|
121 |
Map<String, String> getCompatibilityClasses(String mode); |
|
122 |
|
|
123 |
@RequestMapping(value = "/getDatasourceClasses/{mode}",method = RequestMethod.GET, |
|
124 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
125 |
@ResponseBody |
|
126 |
Map<String, String> getDatasourceClasses(String mode); |
|
127 |
|
|
128 |
|
|
129 |
String getCountryName(String countryCode); |
|
130 |
|
|
131 |
@RequestMapping(value = "/getMetricsInfoForRepository/{repoId}",method = RequestMethod.GET, |
|
132 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
133 |
@ResponseBody |
|
134 |
MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException; |
|
135 |
|
|
136 |
@RequestMapping(value = "/getListLatestUpdate/{mode}",method = RequestMethod.GET, |
|
137 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
138 |
@ResponseBody |
|
139 |
Map<String, String> getListLatestUpdate(String mode) throws RepositoryServiceException, JSONException; |
|
140 |
|
|
141 |
@RequestMapping(value = "/updateRepositoryInterface", method = RequestMethod.POST, |
|
142 |
consumes = MediaType.APPLICATION_JSON_VALUE) |
|
143 |
@ResponseBody |
|
144 |
RepositoryInterface updateRepositoryInterface(String repositoryId,String registeredBy,RepositoryInterface repositoryInterface) throws JSONException; |
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
} |
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/controllers/StatsApiImpl.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
import com.mongodb.util.JSON; |
|
4 |
import org.apache.log4j.Logger; |
|
5 |
import org.json.JSONArray; |
|
6 |
import org.json.JSONException; |
|
7 |
import org.json.JSONObject; |
|
8 |
import org.springframework.beans.factory.annotation.Value; |
|
9 |
import org.springframework.http.HttpHeaders; |
|
10 |
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
|
11 |
import org.springframework.stereotype.Component; |
|
12 |
import org.springframework.web.client.RestTemplate; |
|
13 |
import org.springframework.web.util.UriComponents; |
|
14 |
import org.springframework.web.util.UriComponentsBuilder; |
|
15 |
|
|
16 |
import javax.annotation.PostConstruct; |
|
17 |
import java.util.HashMap; |
|
18 |
import java.util.Map; |
|
19 |
|
|
20 |
@Component |
|
21 |
public class StatsApiImpl implements StatsApi { |
|
22 |
|
|
23 |
private RestTemplate restTemplate = null; |
|
24 |
|
|
25 |
private HttpHeaders httpHeaders; |
|
26 |
|
|
27 |
private static final Logger LOGGER = Logger.getLogger(RepositoryApiImpl.class); |
|
28 |
|
|
29 |
@Value("${search.api.baseAddress}") |
|
30 |
private String baseAddress; |
|
31 |
|
|
32 |
@Value("${search.api.usagestats}") |
|
33 |
private String usagestatsBaseAddress; |
|
34 |
|
|
35 |
@Value("${search.api.usageEvents}") |
|
36 |
private String usagestatsEvents; |
|
37 |
|
|
38 |
@PostConstruct |
|
39 |
private void init() { |
|
40 |
LOGGER.debug("Initialization method of statistics api!"); |
|
41 |
|
|
42 |
restTemplate = new RestTemplate(); |
|
43 |
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); |
|
44 |
|
|
45 |
httpHeaders = new HttpHeaders(); |
|
46 |
httpHeaders.set("Content-Type", "application/json"); |
|
47 |
} |
|
48 |
|
|
49 |
|
|
50 |
@Override |
|
51 |
public Map<String, Object> getStatistics() throws JSONException { |
|
52 |
|
|
53 |
|
|
54 |
String aggregators = getTotalByType("datasource",baseAddress+"/resources", |
|
55 |
"?query= " + |
|
56 |
" oaftype exact datasource and " + |
|
57 |
" ( datasourcetypename exact Institutional Repository Aggregator " + |
|
58 |
" or datasourcetypename exact Publication Repository Aggregator )"); |
|
59 |
|
|
60 |
String dataRepositories = getTotalByType("datasource",baseAddress+"/resources", |
|
61 |
"?query= " + |
|
62 |
" oaftype exact datasource and " + |
|
63 |
" datasourcetypename exact Data Repository " ); |
|
64 |
|
|
65 |
String literature = getTotalByType("datasource",baseAddress+"/resources", |
|
66 |
"?query= " + |
|
67 |
" oaftype exact datasource and " + |
|
68 |
" ( datasourcetypename exact Institutional Repository " + |
|
69 |
" or datasourcetypename exact Publication Repository )"); |
|
70 |
|
|
71 |
String journal = getTotalByType("datasource",baseAddress+"/resources", |
|
72 |
"?query= " + |
|
73 |
" oaftype exact datasource and " + |
|
74 |
" datasourcetypename exact Journal"); |
|
75 |
|
|
76 |
String publications = getTotalByType("other",baseAddress,"/publications/count"); |
|
77 |
String datasets = getTotalByType("other",baseAddress,"/datasets/count"); |
|
78 |
String software = getTotalByType("other",baseAddress,"/software/count"); |
|
79 |
JSONObject lastYearUsagestats = getLastYearUsageStatsTotal(); |
|
80 |
Integer usagestats = getUsageStatsTotal(); |
|
81 |
|
|
82 |
|
|
83 |
HashMap<String,Object> stats = new HashMap<>(); |
|
84 |
stats.put("aggregators",aggregators); |
|
85 |
stats.put("dataRepositories",dataRepositories); |
|
86 |
stats.put("literature",literature); |
|
87 |
stats.put("journal",journal); |
|
88 |
|
|
89 |
stats.put("publications",publications); |
|
90 |
stats.put("datasets",datasets); |
|
91 |
stats.put("software",software); |
|
92 |
|
|
93 |
stats.put("lastYearUsagestats",lastYearUsagestats.toString()); |
|
94 |
stats.put("usagestats",usagestats.toString()); |
|
95 |
|
|
96 |
|
|
97 |
return stats; |
|
98 |
} |
|
99 |
|
|
100 |
|
|
101 |
private String getTotalByType(String type,String url,String query) throws JSONException { |
|
102 |
UriComponents uriComponents = UriComponentsBuilder |
|
103 |
.fromHttpUrl(url + query) |
|
104 |
.queryParam("page",0) |
|
105 |
.queryParam("size",0) |
|
106 |
.queryParam("format","json") |
|
107 |
.build().encode(); |
|
108 |
|
|
109 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
|
110 |
|
|
111 |
if(type.equalsIgnoreCase("datasource")){ |
|
112 |
JSONObject metadata = (JSONObject) new JSONObject(rs).get("meta"); |
|
113 |
return String.valueOf(metadata.get("total")); |
|
114 |
}else |
|
115 |
return String.valueOf(new JSONObject(rs).get("total")); |
|
116 |
|
|
117 |
} |
|
118 |
|
|
119 |
private JSONObject getLastYearUsageStatsTotal() throws JSONException { |
|
120 |
|
|
121 |
UriComponents uriComponents = UriComponentsBuilder |
|
122 |
.fromHttpUrl(usagestatsBaseAddress + "/totals") |
|
123 |
.build().encode(); |
|
124 |
|
|
125 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
|
126 |
|
|
127 |
JSONArray resultSet = (JSONArray) new JSONObject(rs).getJSONArray("yearly_stats"); |
|
128 |
JSONObject lastYear = resultSet.getJSONObject(resultSet.length()-1); |
|
129 |
|
|
130 |
Integer downloads = lastYear.getInt("downloads"); |
|
131 |
Integer views = lastYear.getInt("views"); |
|
132 |
String year = lastYear.getString("year"); |
|
133 |
|
|
134 |
JSONObject usagestats = new JSONObject(); |
|
135 |
usagestats.put("number",String.valueOf(downloads+views)); |
|
136 |
usagestats.put("year",year); |
|
137 |
|
|
138 |
return usagestats; |
|
139 |
|
|
140 |
} |
|
141 |
|
|
142 |
private Integer getUsageStatsTotal() throws JSONException { |
|
143 |
UriComponents uriComponents = UriComponentsBuilder |
|
144 |
.fromHttpUrl(usagestatsEvents) |
|
145 |
.build().encode(); |
|
146 |
|
|
147 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
|
148 |
JSONObject resultSet = new JSONObject(rs); |
|
149 |
JSONObject totals = resultSet.getJSONObject("totals"); |
|
150 |
return Integer.valueOf(totals.getString("events")); |
|
151 |
} |
|
152 |
} |
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/controllers/PiWikApi.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
|
|
4 |
import eu.dnetlib.domain.data.PiwikInfo; |
|
5 |
import eu.dnetlib.repo.manager.shared.RepositoryServiceException; |
|
6 |
import io.swagger.annotations.Api; |
|
7 |
import org.springframework.http.MediaType; |
|
8 |
import org.springframework.http.ResponseEntity; |
|
9 |
import org.springframework.web.bind.annotation.*; |
|
10 |
|
|
11 |
import java.util.List; |
|
12 |
|
|
13 |
@RestController |
|
14 |
@RequestMapping(value = "/piwik") |
|
15 |
@Api(description = "Piwik API", tags = {"piwik"}) |
|
16 |
public interface PiWikApi { |
|
17 |
|
|
18 |
|
|
19 |
@RequestMapping(value = "/getPiwikSiteForRepo/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
20 |
@ResponseBody |
|
21 |
PiwikInfo getPiwikSiteForRepo(String repositoryId); |
|
22 |
|
|
23 |
@RequestMapping(value = "/savePiwikInfo" , method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE) |
|
24 |
PiwikInfo savePiwikInfo( PiwikInfo piwikInfo); |
|
25 |
|
|
26 |
@RequestMapping(value = "/getPiwikSitesForRepos" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
27 |
List<PiwikInfo> getPiwikSitesForRepos(); |
|
28 |
|
|
29 |
@RequestMapping(value = "/approvePiwikSite/{repositoryId}" , method = RequestMethod.GET) |
|
30 |
@ResponseBody |
|
31 |
ResponseEntity<Object> approvePiwikSite(String repositoryId); |
|
32 |
|
Also available in: Unified diff
New project structure