Revision 50219
Added by Panagiotis Kanakakis over 6 years ago
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/utils/Converter.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.repo.manager.service.utils; |
2 | 2 |
|
3 |
import com.fasterxml.jackson.core.JsonProcessingException; |
|
4 |
import com.fasterxml.jackson.core.type.TypeReference; |
|
5 | 3 |
import com.fasterxml.jackson.databind.ObjectMapper; |
6 | 4 |
import eu.dnetlib.domain.data.Repository; |
7 | 5 |
import eu.dnetlib.domain.data.RepositoryInterface; |
8 |
import eu.dnetlib.repo.manager.service.controllers.RepositoryApi; |
|
9 | 6 |
import eu.dnetlib.repo.manager.shared.*; |
10 | 7 |
import org.apache.log4j.Logger; |
11 | 8 |
import org.json.JSONArray; |
12 | 9 |
import org.json.JSONException; |
13 | 10 |
import org.json.JSONObject; |
14 |
import org.springframework.beans.factory.annotation.Autowired; |
|
15 | 11 |
|
16 | 12 |
import java.io.*; |
17 | 13 |
import java.text.ParseException; |
... | ... | |
26 | 22 |
|
27 | 23 |
Repository repository = new Repository(); |
28 | 24 |
|
29 |
if( repositoryObject.get("datasource").equals(null)) |
|
30 |
return null; |
|
31 | 25 |
|
32 |
JSONObject datasource = (JSONObject) repositoryObject.get("datasource"); |
|
26 |
LOGGER.debug("datasource response -> " + repositoryObject); |
|
27 |
JSONObject datasource = repositoryObject.getJSONObject("datasource"); |
|
33 | 28 |
|
29 |
if( datasource.equals(null)) |
|
30 |
return null; |
|
31 |
|
|
34 | 32 |
repository.setActivationId(datasource.get("activationId").toString()); |
35 | 33 |
repository.setAggregator(datasource.get("aggregator").toString()); |
36 | 34 |
repository.setCertificates(datasource.get("certificates").toString()); |
... | ... | |
83 | 81 |
repository.setProvenanceActionClass( datasource.get("provenanceaction").toString()); |
84 | 82 |
repository.setQualityManagementKind(datasource.get("qualitymanagementkind").toString()); |
85 | 83 |
repository.setRegisteredBy(datasource.get("registeredby").toString()); |
84 |
|
|
85 |
if(repository.getRegisteredBy() != null) |
|
86 |
repository.setRegistered(true); |
|
87 |
|
|
86 | 88 |
repository.setReleaseEndDate(convertStringToDate(datasource.get("releaseenddate").toString())); |
87 | 89 |
repository.setReleaseStartDate(convertStringToDate(datasource.get("releasestartdate").toString())); |
88 | 90 |
repository.setServiceProvider(Boolean.valueOf(datasource.get("serviceprovider").toString())); |
... | ... | |
149 | 151 |
return Double.valueOf(number); |
150 | 152 |
} |
151 | 153 |
|
152 |
public static List<Repository> jsonToRepositoryList(JSONArray rs) throws JSONException {
|
|
154 |
public static List<Repository> jsonToRepositoryList(JSONObject json) throws JSONException {
|
|
153 | 155 |
|
154 | 156 |
List<Repository> resultSet = new ArrayList<>(); |
157 |
JSONArray rs = json.getJSONArray("datasourceInfo"); |
|
155 | 158 |
for(int i=0;i<rs.length();i++) |
156 | 159 |
resultSet.add(jsonToRepositoryObject( rs.getJSONObject(i)) ); |
157 | 160 |
return resultSet; |
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/controllers/PiWikApiImpl.java | ||
---|---|---|
4 | 4 |
import eu.dnetlib.utils.md5.MD5; |
5 | 5 |
import org.springframework.beans.factory.annotation.Autowired; |
6 | 6 |
import org.springframework.beans.factory.annotation.Qualifier; |
7 |
import org.springframework.dao.EmptyResultDataAccessException; |
|
7 | 8 |
import org.springframework.jdbc.core.JdbcTemplate; |
8 | 9 |
import org.springframework.jdbc.core.RowMapper; |
9 | 10 |
import org.springframework.stereotype.Component; |
... | ... | |
43 | 44 |
|
44 | 45 |
@Override |
45 | 46 |
public PiwikInfo getPiwikSiteForRepo(@PathVariable("repositoryId") String repositoryId) { |
46 |
return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITE, new String[]{repositoryId}, new int[]{Types.VARCHAR}, piwikRowMapper); |
|
47 |
try{ |
|
48 |
return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITE, new String[]{repositoryId}, new int[]{Types.VARCHAR}, piwikRowMapper); |
|
49 |
}catch (EmptyResultDataAccessException e){ |
|
50 |
return null; |
|
51 |
} |
|
47 | 52 |
} |
48 | 53 |
|
49 | 54 |
@Override |
... | ... | |
58 | 63 |
@Override |
59 | 64 |
public List<PiwikInfo> getPiwikSitesForRepos() { |
60 | 65 |
LOGGER.debug("Getting piwik sites for repos! "); |
61 |
return new JdbcTemplate(dataSource).query(GET_PIWIK_SITES, piwikRowMapper); |
|
66 |
try{ |
|
67 |
return new JdbcTemplate(dataSource).query(GET_PIWIK_SITES, piwikRowMapper); |
|
68 |
}catch (EmptyResultDataAccessException e){ |
|
69 |
return null; |
|
70 |
} |
|
71 |
|
|
62 | 72 |
} |
63 | 73 |
|
64 | 74 |
@Override |
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApi.java | ||
---|---|---|
31 | 31 |
@RequestMapping(value = "/getRepositoriesByCountry/{country}/{mode}", method = RequestMethod.GET, |
32 | 32 |
produces = MediaType.APPLICATION_JSON_VALUE) |
33 | 33 |
@ResponseBody |
34 |
List<Repository> getRepositoriesByCountry(String country,String mode) throws JSONException;
|
|
34 |
List<Repository> getRepositoriesByCountry(String country, String mode, Boolean managed) throws JSONException;
|
|
35 | 35 |
|
36 | 36 |
@RequestMapping(value = "/getRepositoriesOfUser/{userEmail}/{page}/{size}",method = RequestMethod.GET, |
37 | 37 |
produces = MediaType.APPLICATION_JSON_VALUE) |
... | ... | |
67 | 67 |
@RequestMapping(value = "/addRepository", method = RequestMethod.POST, |
68 | 68 |
consumes = MediaType.APPLICATION_JSON_VALUE) |
69 | 69 |
@ResponseBody |
70 |
void addRepository( String datatype,Repository repository) throws Exception;
|
|
70 |
void addRepository(String datatype, Repository repository) throws Exception;
|
|
71 | 71 |
|
72 | 72 |
|
73 | 73 |
@RequestMapping(value = "/deleteInterface", method = RequestMethod.DELETE) |
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApiImpl.java | ||
---|---|---|
29 | 29 |
import org.springframework.web.util.UriComponentsBuilder; |
30 | 30 |
|
31 | 31 |
import javax.annotation.PostConstruct; |
32 |
import javax.ws.rs.Path; |
|
33 | 32 |
import javax.ws.rs.QueryParam; |
34 |
import java.io.IOException; |
|
35 | 33 |
import java.sql.Timestamp; |
36 | 34 |
import java.text.Normalizer; |
37 | 35 |
import java.util.*; |
... | ... | |
54 | 52 |
@Autowired |
55 | 53 |
private VocabularyLoader vocabularyLoader; |
56 | 54 |
|
55 |
@Autowired |
|
56 |
private PiWikApi piWikApi; |
|
57 |
|
|
57 | 58 |
private Map<String, Vocabulary> vocabularyMap = new ConcurrentHashMap<String, Vocabulary>(); |
58 | 59 |
|
59 | 60 |
private Map<String, String> countriesMap = new HashMap<>(); |
... | ... | |
137 | 138 |
|
138 | 139 |
@Override |
139 | 140 |
public List<Repository> getRepositoriesByCountry(@PathVariable("country") String country, |
140 |
@PathVariable("mode") String mode) throws JSONException { |
|
141 |
@PathVariable("mode") String mode, |
|
142 |
@RequestParam(value = "managed",required=false) Boolean managed) throws JSONException { |
|
141 | 143 |
|
142 | 144 |
LOGGER.debug("Getting repositories by country!"); |
143 | 145 |
int page = 0; |
... | ... | |
159 | 161 |
.fromHttpUrl(baseAddress + "/ds/search/country/") |
160 | 162 |
.path("/{page}/{size}/") |
161 | 163 |
.queryParam("country", countryCode) |
164 |
.queryParam("managed", managed) |
|
162 | 165 |
.build().expand(page, size).encode(); |
163 | 166 |
|
164 | 167 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
168 |
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
|
169 |
|
|
165 | 170 |
List<Repository> resultSet = new ArrayList<>(); |
166 |
while (!rs.equals("[]")) {
|
|
167 |
List<Repository> rep = Converter.jsonToRepositoryList(new JSONArray(rs));
|
|
171 |
while (jsonArray.length() > 0 ) {
|
|
172 |
List<Repository> rep = Converter.jsonToRepositoryList(new JSONObject(rs));
|
|
168 | 173 |
|
169 | 174 |
Collection<Repository> repos = this.getRepositoriesByMode(filterKey, rep); |
170 | 175 |
resultSet.addAll(repos); |
... | ... | |
174 | 179 |
.fromHttpUrl(baseAddress + "/ds/search/country/") |
175 | 180 |
.path("/{page}/{size}/") |
176 | 181 |
.queryParam("country", countryCode) |
182 |
.queryParam("managed", managed) |
|
177 | 183 |
.build().expand(page, size).encode(); |
178 | 184 |
rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
185 |
jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
|
179 | 186 |
} |
180 |
for (Repository r : resultSet){ |
|
181 |
r.setInterfaces(this.getRepositoryInterface(r.getId())); |
|
182 |
r.setCountryName(getCountryName(r.getCountryCode())); |
|
183 |
} |
|
187 |
for (Repository r : resultSet) |
|
188 |
this.getRepositoryInfo(r); |
|
184 | 189 |
|
185 | 190 |
return resultSet; |
186 | 191 |
} |
187 | 192 |
|
193 |
private void getRepositoryInfo(Repository r) throws JSONException { |
|
194 |
r.setInterfaces(this.getRepositoryInterface(r.getId())); |
|
195 |
r.setPiwikInfo(piWikApi.getPiwikSiteForRepo(r.getId())); |
|
196 |
r.setCountryName(getCountryName(r.getCountryCode())); |
|
197 |
} |
|
188 | 198 |
|
199 |
|
|
189 | 200 |
private Collection<Repository> getRepositoriesByMode(String mode, List<Repository> rs) { |
190 | 201 |
|
191 | 202 |
List<Repository> reps = new ArrayList<>(); |
... | ... | |
209 | 220 |
.build().expand(page, size).encode(); |
210 | 221 |
|
211 | 222 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
212 |
List<Repository> repos = Converter.jsonToRepositoryList(new JSONArray(rs)); |
|
213 |
for (Repository r : repos){ |
|
214 |
r.setInterfaces(this.getRepositoryInterface(r.getId())); |
|
215 |
r.setCountryName(getCountryName(r.getCountryCode())); |
|
216 |
} |
|
223 |
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs)); |
|
224 |
for (Repository r : repos) |
|
225 |
this.getRepositoryInfo(r); |
|
217 | 226 |
|
218 | 227 |
return repos; |
219 | 228 |
} |
... | ... | |
228 | 237 |
|
229 | 238 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
230 | 239 |
Repository repo = Converter.jsonToRepositoryObject(new JSONObject(rs)); |
231 |
if (repo != null) { |
|
232 |
repo.setCountryName(getCountryName(repo.getCountryCode())); |
|
233 |
repo.setInterfaces(this.getRepositoryInterface(repo.getId())); |
|
234 |
} |
|
240 |
if (repo != null) |
|
241 |
getRepositoryInfo(repo); |
|
235 | 242 |
return repo; |
236 | 243 |
} |
237 | 244 |
|
... | ... | |
272 | 279 |
.build().expand(page, size).encode(); |
273 | 280 |
|
274 | 281 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
275 |
List<Repository> repos = Converter.jsonToRepositoryList(new JSONArray(rs)); |
|
276 |
for (Repository r : repos){ |
|
277 |
// r.setInterfaces(this.getRepositoryInterface(r.getId())); |
|
278 |
r.setCountryName(getCountryName(r.getCountryCode())); |
|
279 |
} |
|
282 |
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs)); |
|
283 |
for (Repository r : repos) |
|
284 |
getRepositoryInfo(r); |
|
280 | 285 |
return repos; |
281 | 286 |
} |
282 | 287 |
|
modules/uoa-repository-manager-service/trunk/src/main/resources/application-context.xml | ||
---|---|---|
9 | 9 |
http://www.springframework.org/schema/context/spring-context-4.0.xsd |
10 | 10 |
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> |
11 | 11 |
|
12 |
<import resource="classpath:META-INF/cxf/cxf.xml"/> |
|
12 |
<!-- <import resource="classpath:META-INF/cxf/cxf.xml"/>
|
|
13 | 13 |
<import resource="classpath:META-INF/cxf/cxf-extension-jaxws.xml"/> |
14 | 14 |
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> |
15 | 15 |
<import resource="classpath*:/cxf.xml"/> |
... | ... | |
23 | 23 |
<import resource="classpath*:/eu/dnetlib/enabling/hcm/springContext-hcmService.xml"/> |
24 | 24 |
<import resource="classpath*:/gr/uoa/di/driver/app/springContext-commons.xml"/> |
25 | 25 |
<import resource="classpath*:/gr/uoa/di/driver/app/springContext-registrator.xml"/> |
26 |
<import resource="classpath*:/eu/dnetlib/repos/springContext-repos-dms-cached.xml"/> |
|
27 |
<context:property-placeholder location="classpath*:/eu/**/application.properties" /> |
|
26 |
<import resource="classpath*:/eu/dnetlib/repos/springContext-repos-dms-cached.xml"/>-->
|
|
27 |
<context:property-placeholder location="classpath*:/eu/**/application.properties" />
|
|
28 | 28 |
<tx:annotation-driven transaction-manager="txManager"/> |
29 | 29 |
|
30 | 30 |
<bean class="eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader" id="propertyLoader"> |
... | ... | |
79 | 79 |
<property name="dataSource" ref="repomanager.dataSource"/> |
80 | 80 |
</bean> |
81 | 81 |
|
82 |
</beans> |
|
82 |
</beans> |
Also available in: Unified diff
1. Changes on piwik api
2. Changes on repository interface (new response entities)
3. Changes on converter class due to new json response.