1. Changes on piwik api
2. Changes on repository interface (new response entities) 3. Changes on converter class due to new json response.
This commit is contained in:
parent
5227f60ce5
commit
ad50f63170
|
@ -4,6 +4,7 @@ import eu.dnetlib.domain.data.PiwikInfo;
|
|||
import eu.dnetlib.utils.md5.MD5;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -43,7 +44,11 @@ public class PiWikApiImpl implements PiWikApi{
|
|||
|
||||
@Override
|
||||
public PiwikInfo getPiwikSiteForRepo(@PathVariable("repositoryId") String repositoryId) {
|
||||
return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITE, new String[]{repositoryId}, new int[]{Types.VARCHAR}, piwikRowMapper);
|
||||
try{
|
||||
return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITE, new String[]{repositoryId}, new int[]{Types.VARCHAR}, piwikRowMapper);
|
||||
}catch (EmptyResultDataAccessException e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -58,7 +63,12 @@ public class PiWikApiImpl implements PiWikApi{
|
|||
@Override
|
||||
public List<PiwikInfo> getPiwikSitesForRepos() {
|
||||
LOGGER.debug("Getting piwik sites for repos! ");
|
||||
return new JdbcTemplate(dataSource).query(GET_PIWIK_SITES, piwikRowMapper);
|
||||
try{
|
||||
return new JdbcTemplate(dataSource).query(GET_PIWIK_SITES, piwikRowMapper);
|
||||
}catch (EmptyResultDataAccessException e){
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,7 +31,7 @@ public interface RepositoryApi {
|
|||
@RequestMapping(value = "/getRepositoriesByCountry/{country}/{mode}", method = RequestMethod.GET,
|
||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
List<Repository> getRepositoriesByCountry(String country,String mode) throws JSONException;
|
||||
List<Repository> getRepositoriesByCountry(String country, String mode, Boolean managed) throws JSONException;
|
||||
|
||||
@RequestMapping(value = "/getRepositoriesOfUser/{userEmail}/{page}/{size}",method = RequestMethod.GET,
|
||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
|
@ -67,7 +67,7 @@ public interface RepositoryApi {
|
|||
@RequestMapping(value = "/addRepository", method = RequestMethod.POST,
|
||||
consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
void addRepository( String datatype,Repository repository) throws Exception;
|
||||
void addRepository(String datatype, Repository repository) throws Exception;
|
||||
|
||||
|
||||
@RequestMapping(value = "/deleteInterface", method = RequestMethod.DELETE)
|
||||
|
|
|
@ -29,9 +29,7 @@ import org.springframework.web.util.UriComponents;
|
|||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.Normalizer;
|
||||
import java.util.*;
|
||||
|
@ -54,6 +52,9 @@ public class RepositoryApiImpl implements RepositoryApi {
|
|||
@Autowired
|
||||
private VocabularyLoader vocabularyLoader;
|
||||
|
||||
@Autowired
|
||||
private PiWikApi piWikApi;
|
||||
|
||||
private Map<String, Vocabulary> vocabularyMap = new ConcurrentHashMap<String, Vocabulary>();
|
||||
|
||||
private Map<String, String> countriesMap = new HashMap<>();
|
||||
|
@ -137,7 +138,8 @@ public class RepositoryApiImpl implements RepositoryApi {
|
|||
|
||||
@Override
|
||||
public List<Repository> getRepositoriesByCountry(@PathVariable("country") String country,
|
||||
@PathVariable("mode") String mode) throws JSONException {
|
||||
@PathVariable("mode") String mode,
|
||||
@RequestParam(value = "managed",required=false) Boolean managed) throws JSONException {
|
||||
|
||||
LOGGER.debug("Getting repositories by country!");
|
||||
int page = 0;
|
||||
|
@ -159,12 +161,15 @@ public class RepositoryApiImpl implements RepositoryApi {
|
|||
.fromHttpUrl(baseAddress + "/ds/search/country/")
|
||||
.path("/{page}/{size}/")
|
||||
.queryParam("country", countryCode)
|
||||
.queryParam("managed", managed)
|
||||
.build().expand(page, size).encode();
|
||||
|
||||
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
|
||||
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
||||
|
||||
List<Repository> resultSet = new ArrayList<>();
|
||||
while (!rs.equals("[]")) {
|
||||
List<Repository> rep = Converter.jsonToRepositoryList(new JSONArray(rs));
|
||||
while (jsonArray.length() > 0 ) {
|
||||
List<Repository> rep = Converter.jsonToRepositoryList(new JSONObject(rs));
|
||||
|
||||
Collection<Repository> repos = this.getRepositoriesByMode(filterKey, rep);
|
||||
resultSet.addAll(repos);
|
||||
|
@ -174,17 +179,23 @@ public class RepositoryApiImpl implements RepositoryApi {
|
|||
.fromHttpUrl(baseAddress + "/ds/search/country/")
|
||||
.path("/{page}/{size}/")
|
||||
.queryParam("country", countryCode)
|
||||
.queryParam("managed", managed)
|
||||
.build().expand(page, size).encode();
|
||||
rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
|
||||
jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
||||
}
|
||||
for (Repository r : resultSet){
|
||||
r.setInterfaces(this.getRepositoryInterface(r.getId()));
|
||||
r.setCountryName(getCountryName(r.getCountryCode()));
|
||||
}
|
||||
for (Repository r : resultSet)
|
||||
this.getRepositoryInfo(r);
|
||||
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
private void getRepositoryInfo(Repository r) throws JSONException {
|
||||
r.setInterfaces(this.getRepositoryInterface(r.getId()));
|
||||
r.setPiwikInfo(piWikApi.getPiwikSiteForRepo(r.getId()));
|
||||
r.setCountryName(getCountryName(r.getCountryCode()));
|
||||
}
|
||||
|
||||
|
||||
private Collection<Repository> getRepositoriesByMode(String mode, List<Repository> rs) {
|
||||
|
||||
|
@ -209,11 +220,9 @@ public class RepositoryApiImpl implements RepositoryApi {
|
|||
.build().expand(page, size).encode();
|
||||
|
||||
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
|
||||
List<Repository> repos = Converter.jsonToRepositoryList(new JSONArray(rs));
|
||||
for (Repository r : repos){
|
||||
r.setInterfaces(this.getRepositoryInterface(r.getId()));
|
||||
r.setCountryName(getCountryName(r.getCountryCode()));
|
||||
}
|
||||
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs));
|
||||
for (Repository r : repos)
|
||||
this.getRepositoryInfo(r);
|
||||
|
||||
return repos;
|
||||
}
|
||||
|
@ -228,10 +237,8 @@ public class RepositoryApiImpl implements RepositoryApi {
|
|||
|
||||
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
|
||||
Repository repo = Converter.jsonToRepositoryObject(new JSONObject(rs));
|
||||
if (repo != null) {
|
||||
repo.setCountryName(getCountryName(repo.getCountryCode()));
|
||||
repo.setInterfaces(this.getRepositoryInterface(repo.getId()));
|
||||
}
|
||||
if (repo != null)
|
||||
getRepositoryInfo(repo);
|
||||
return repo;
|
||||
}
|
||||
|
||||
|
@ -272,11 +279,9 @@ public class RepositoryApiImpl implements RepositoryApi {
|
|||
.build().expand(page, size).encode();
|
||||
|
||||
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
|
||||
List<Repository> repos = Converter.jsonToRepositoryList(new JSONArray(rs));
|
||||
for (Repository r : repos){
|
||||
// r.setInterfaces(this.getRepositoryInterface(r.getId()));
|
||||
r.setCountryName(getCountryName(r.getCountryCode()));
|
||||
}
|
||||
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs));
|
||||
for (Repository r : repos)
|
||||
getRepositoryInfo(r);
|
||||
return repos;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
package eu.dnetlib.repo.manager.service.utils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.dnetlib.domain.data.Repository;
|
||||
import eu.dnetlib.domain.data.RepositoryInterface;
|
||||
import eu.dnetlib.repo.manager.service.controllers.RepositoryApi;
|
||||
import eu.dnetlib.repo.manager.shared.*;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.*;
|
||||
import java.text.ParseException;
|
||||
|
@ -26,11 +22,13 @@ public class Converter {
|
|||
|
||||
Repository repository = new Repository();
|
||||
|
||||
if( repositoryObject.get("datasource").equals(null))
|
||||
|
||||
LOGGER.debug("datasource response -> " + repositoryObject);
|
||||
JSONObject datasource = repositoryObject.getJSONObject("datasource");
|
||||
|
||||
if( datasource.equals(null))
|
||||
return null;
|
||||
|
||||
JSONObject datasource = (JSONObject) repositoryObject.get("datasource");
|
||||
|
||||
|
||||
repository.setActivationId(datasource.get("activationId").toString());
|
||||
repository.setAggregator(datasource.get("aggregator").toString());
|
||||
repository.setCertificates(datasource.get("certificates").toString());
|
||||
|
@ -83,6 +81,10 @@ public class Converter {
|
|||
repository.setProvenanceActionClass( datasource.get("provenanceaction").toString());
|
||||
repository.setQualityManagementKind(datasource.get("qualitymanagementkind").toString());
|
||||
repository.setRegisteredBy(datasource.get("registeredby").toString());
|
||||
|
||||
if(repository.getRegisteredBy() != null)
|
||||
repository.setRegistered(true);
|
||||
|
||||
repository.setReleaseEndDate(convertStringToDate(datasource.get("releaseenddate").toString()));
|
||||
repository.setReleaseStartDate(convertStringToDate(datasource.get("releasestartdate").toString()));
|
||||
repository.setServiceProvider(Boolean.valueOf(datasource.get("serviceprovider").toString()));
|
||||
|
@ -149,9 +151,10 @@ public class Converter {
|
|||
return Double.valueOf(number);
|
||||
}
|
||||
|
||||
public static List<Repository> jsonToRepositoryList(JSONArray rs) throws JSONException {
|
||||
public static List<Repository> jsonToRepositoryList(JSONObject json) throws JSONException {
|
||||
|
||||
List<Repository> resultSet = new ArrayList<>();
|
||||
JSONArray rs = json.getJSONArray("datasourceInfo");
|
||||
for(int i=0;i<rs.length();i++)
|
||||
resultSet.add(jsonToRepositoryObject( rs.getJSONObject(i)) );
|
||||
return resultSet;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
http://www.springframework.org/schema/context/spring-context-4.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
|
||||
|
||||
<import resource="classpath:META-INF/cxf/cxf.xml"/>
|
||||
<!-- <import resource="classpath:META-INF/cxf/cxf.xml"/>
|
||||
<import resource="classpath:META-INF/cxf/cxf-extension-jaxws.xml"/>
|
||||
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
|
||||
<import resource="classpath*:/cxf.xml"/>
|
||||
|
@ -23,8 +23,8 @@
|
|||
<import resource="classpath*:/eu/dnetlib/enabling/hcm/springContext-hcmService.xml"/>
|
||||
<import resource="classpath*:/gr/uoa/di/driver/app/springContext-commons.xml"/>
|
||||
<import resource="classpath*:/gr/uoa/di/driver/app/springContext-registrator.xml"/>
|
||||
<import resource="classpath*:/eu/dnetlib/repos/springContext-repos-dms-cached.xml"/>
|
||||
<context:property-placeholder location="classpath*:/eu/**/application.properties" />
|
||||
<import resource="classpath*:/eu/dnetlib/repos/springContext-repos-dms-cached.xml"/>-->
|
||||
<context:property-placeholder location="classpath*:/eu/**/application.properties" />
|
||||
<tx:annotation-driven transaction-manager="txManager"/>
|
||||
|
||||
<bean class="eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader" id="propertyLoader">
|
||||
|
@ -79,4 +79,4 @@
|
|||
<property name="dataSource" ref="repomanager.dataSource"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
</beans>
|
||||
|
|
Loading…
Reference in New Issue