1. New rest api

2. Cors filter on web.xml 
3. Remove aai
This commit is contained in:
Panagiotis Kanakakis 2018-02-06 14:59:03 +00:00
parent 3c82be8b5a
commit cb360ec0d8
9 changed files with 118 additions and 50 deletions

View File

@ -230,6 +230,14 @@
<version>9.1-901.jdbc3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>LATEST</version>
</dependency>
<!--<dependency>
<groupId>org.mitre</groupId>
<artifactId>openid-connect-client</artifactId>

View File

@ -4,6 +4,7 @@ import eu.dnetlib.repo.manager.shared.BrokerException;
import eu.dnetlib.repo.manager.shared.Term;
import eu.dnetlib.repo.manager.shared.broker.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
@ -23,11 +24,15 @@ public interface BrokerApi {
@RequestMapping(value = "/getTopicsForDatasource/{datasourceName}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
List<BrowseEntry> getTopicsForDatasource(String datasourceName) throws BrokerException;
@RequestMapping(value = "/advancedShowEvents" , method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
EventsPage advancedShowEvents(@RequestBody String params) throws BrokerException, JSONException ,IOException;
@RequestMapping(value = "/advancedShowEvents/{page}/{size}" , method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
EventsPage advancedShowEvents(@PathVariable("page") String page,
@PathVariable("size") String size,
@RequestBody AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException;
@RequestMapping(value = "/showEvents" , method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
EventsPage showEvents(@RequestBody String params) throws BrokerException, JSONException;
@RequestMapping(value = "/showEvents/{datasourceName}/{topic}/{page}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
EventsPage showEvents(@PathVariable("datasourceName") String datasourceName,
@PathVariable("topic") String topic,
@PathVariable("page") String page) throws BrokerException, JSONException;
@RequestMapping(value = "/getSimpleSubscriptionsOfUser/{userEmail}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody

View File

@ -132,31 +132,27 @@ public class BrokerApiImpl implements BrokerApi {
}
@Override
public EventsPage advancedShowEvents(String params) throws BrokerException, JSONException ,IOException {
JSONObject json_params = new JSONObject(params);
public EventsPage advancedShowEvents(String page,String size,AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException {
/*JSONObject json_params = new JSONObject(params);
String page = json_params.getString("page");
String pagesize = json_params.getString("pagesize");
String json_advQueryObject = json_params.getString("advQueryObject");
ObjectMapper mapper = new ObjectMapper();
AdvQueryObject advQueryObject = mapper.readValue(json_advQueryObject, AdvQueryObject.class);
AdvQueryObject advQueryObject = mapper.readValue(json_advQueryObject, AdvQueryObject.class);*/
final String service = "/events/{page}/{pageSize}";
Map<String, Long> uriParams = new HashMap<>();
uriParams.put("page", Long.parseLong(page));
uriParams.put("pageSize", Long.parseLong(pagesize));
uriParams.put("pageSize", Long.parseLong(size));
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service);
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Content-Type", "application/json");
advQueryObject.setPage(Long.parseLong(page));
HttpEntity<AdvQueryObject> entity = new HttpEntity<>(advQueryObject, headers);
HttpEntity<AdvQueryObject> entity = new HttpEntity<>(advQueryObject, httpHeaders);
ResponseEntity<EventsPage> resp;
try {
resp = restTemplate.exchange(
@ -223,13 +219,13 @@ public class BrokerApiImpl implements BrokerApi {
}
@Override
public EventsPage showEvents(String params) throws BrokerException, JSONException {
public EventsPage showEvents(String datasourceName,String topic,String page) throws BrokerException, JSONException {
JSONObject json_params = new JSONObject(params);
/*JSONObject json_params = new JSONObject(params);
String datasourceName = json_params.getString("datasourceName");
String topic = json_params.getString("topic");
String page = json_params.getString("page");
String page = json_params.getString("page");*/
final String service = "/showEvents";

View File

@ -102,7 +102,7 @@ public interface RepositoryApi {
@RequestMapping(value = "/updateEnglishName", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updateEnglishName(String id, String englishName);
String updateEnglishName(String id,String officialName, String englishName);
@RequestMapping(value = "/updateLatitude", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)

View File

@ -1,11 +1,13 @@
package eu.dnetlib.repo.manager.service.controllers;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface;
import eu.dnetlib.domain.enabling.Vocabulary;
import eu.dnetlib.repo.manager.service.utils.Converter;
import eu.dnetlib.repo.manager.service.utils.RequestFilter;
import eu.dnetlib.repo.manager.shared.*;
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
import org.apache.commons.codec.digest.DigestUtils;
@ -16,10 +18,7 @@ import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.*;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
@ -31,7 +30,6 @@ import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.PostConstruct;
import javax.ws.rs.QueryParam;
import java.sql.Timestamp;
import java.text.Normalizer;
import java.util.*;
@ -222,12 +220,17 @@ public class RepositoryApiImpl implements RepositoryApi {
LOGGER.debug("Retreiving repositories of user : " + userEmail );
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/search/registeredby/")
.fromHttpUrl(baseAddress + "/ds/search/")
.path("/{page}/{size}/")
.queryParam("registeredBy", userEmail)
.queryParam("requestSortBy","id")
.queryParam("order","ASCENDING")
.build().expand(page, size).encode();
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
RequestFilter requestFilter = new RequestFilter();
requestFilter.setRegisteredby(userEmail);
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs));
for (Repository r : repos)
this.getRepositoryInfo(r);
@ -362,7 +365,7 @@ public class RepositoryApiImpl implements RepositoryApi {
private void updateRepository(Repository repository) {
this.updateRegisteredByValue(repository.getId(),repository.getRegisteredBy());
this.updateEnglishName(repository.getId(),repository.getEnglishName());
this.updateEnglishName(repository.getId(),repository.getOfficialName(),repository.getEnglishName());
this.updateLogoUrl(repository.getId(),repository.getLogoUrl());
this.updateTimezone(repository.getId(), String.valueOf(repository.getTimezone()));
//TODO update datasource type
@ -575,11 +578,13 @@ public class RepositoryApiImpl implements RepositoryApi {
@Override
public String updateEnglishName(@RequestParam(value = "id") String id,
@RequestParam(value = "officialName") String officialName,
@RequestParam(value = "englishname") String englishName) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/englishname/")
.fromHttpUrl(baseAddress + "/ds/name/")
.queryParam("dsId",id)
.queryParam("officialname",officialName)
.queryParam("englishname",englishName)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
@ -667,15 +672,18 @@ public class RepositoryApiImpl implements RepositoryApi {
}
@Override
public List<String> getUrlsOfUserRepos(@PathVariable("user_email") String user_email,
public List<String> getUrlsOfUserRepos(@PathVariable("user_email") String userEmail,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/api/baseurl/")
.path("/{page}/{size}")
.queryParam("userEmail",user_email)
.build().expand(page,size).encode();
return Arrays.asList(restTemplate.getForObject(uriComponents.toUri(), String[].class));
RequestFilter requestFilter = new RequestFilter();
requestFilter.setRegisteredby(userEmail);
return Arrays.asList(restTemplate.postForObject(uriComponents.toUri(),requestFilter, String[].class));
}
@Override

View File

@ -31,18 +31,18 @@ public class Converter {
repository.setActivationId(datasource.get("activationId").toString());
repository.setAggregator(datasource.get("aggregator").toString());
repository.setCertificates(datasource.get("certificates").toString());
repository.setCitationGuidelineUrl(datasource.get("citationguidelineurl").toString());
repository.setCollectedFrom( datasource.get("collectedfrom").toString());
// repository.setCertificates(datasource.get("certificates").toString());
// repository.setCitationGuidelineUrl(datasource.get("citationguidelineurl").toString());
// repository.setCollectedFrom( datasource.get("collectedfrom").toString());
repository.setContactEmail(datasource.get("contactemail").toString());
if(repository.getContactEmail().equals("null"))
repository.setContactEmail("");
repository.setDatabaseAccessRestriction(datasource.get("databaseaccessrestriction").toString());
repository.setDatabaseAccessType(datasource.get("databaseaccesstype").toString());
repository.setDataUploadRestriction(datasource.get("datauploadrestriction").toString());
repository.setDataUploadType(datasource.get("datauploadtype").toString());
// repository.setDatabaseAccessRestriction(datasource.get("databaseaccessrestriction").toString());
// repository.setDatabaseAccessType(datasource.get("databaseaccesstype").toString());
// repository.setDataUploadRestriction(datasource.get("datauploadrestriction").toString());
// repository.setDataUploadType(datasource.get("datauploadtype").toString());
repository.setDateOfCollection(convertStringToDate( datasource.get("dateofcollection").toString()));
repository.setDateOfValidation(convertStringToDate( datasource.get("dateofvalidation").toString()));
@ -69,30 +69,30 @@ public class Converter {
repository.setLongitude(toDouble(datasource.get("longitude").toString()));
//datasource.get("managed");
repository.setMissionStatementUrl(datasource.get("missionstatementurl").toString());
// repository.setMissionStatementUrl(datasource.get("missionstatementurl").toString());
repository.setNamespacePrefix(datasource.get("namespaceprefix").toString());
repository.setOdContentTypes(datasource.get("od_contenttypes").toString());
// repository.setOdContentTypes(datasource.get("od_contenttypes").toString());
repository.setOfficialName(datasource.get("officialname").toString());
if(repository.getOfficialName().equals("null"))
repository.setOfficialName("");
repository.setPidSystems(datasource.get("pidsystems").toString());
// repository.setPidSystems(datasource.get("pidsystems").toString());
//datasource.get("platform");
repository.setProvenanceActionClass( datasource.get("provenanceaction").toString());
repository.setQualityManagementKind(datasource.get("qualitymanagementkind").toString());
// repository.setProvenanceActionClass( datasource.get("provenanceaction").toString());
// repository.setQualityManagementKind(datasource.get("qualitymanagementkind").toString());
repository.setRegisteredBy(datasource.get("registeredby").toString());
if(Objects.equals(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()));
// repository.setReleaseEndDate(convertStringToDate(datasource.get("releaseenddate").toString()));
// repository.setReleaseStartDate(convertStringToDate(datasource.get("releasestartdate").toString()));
// repository.setServiceProvider(Boolean.valueOf(datasource.get("serviceprovider").toString()));
//datasource.get("subjects");
Double timezone = toDouble(datasource.get("timezone").toString());
repository.setTimezone(timezone!=null?timezone:0.0);
repository.setTypology(datasource.get("platform").toString());
repository.setVersioning(Boolean.valueOf(datasource.get("versioning").toString()));
// repository.setVersioning(Boolean.valueOf(datasource.get("versioning").toString()));
repository.setWebsiteUrl(datasource.get("websiteurl").toString());
repository.setDatasourceClass(datasource.get("typology").toString());
@ -102,7 +102,7 @@ public class Converter {
repository.setCountryCode(countryCode);
String collectedFrom = datasource.get("collectedfrom").toString();
/* String collectedFrom = datasource.get("collectedfrom").toString();
//TODO check data consistency
String type = "UNKNOWN";
if (collectedFrom.equalsIgnoreCase("openaire____::opendoar")) {
@ -111,9 +111,9 @@ public class Converter {
type = "re3data";
} else if (collectedFrom.equalsIgnoreCase("infrastruct_::openaire")) {
type = "journal";
}
}*/
repository.setDatasourceType(type);
// repository.setDatasourceType(type);
return repository;

View File

@ -0,0 +1,29 @@
package eu.dnetlib.repo.manager.service.utils;
public class RequestFilter{
private String registeredby = "";
private String typology = "";
public RequestFilter() {
}
public String getTypology() {
return typology;
}
public void setTypology(String typology) {
this.typology = typology;
}
public String getRegisteredby() {
return registeredby;
}
public void setRegisteredby(String registeredby) {
this.registeredby = registeredby;
}
}

View File

@ -30,7 +30,7 @@
<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"/>
<!--<import resource="classpath*:/eu/dnetlib/repos/springContext-repos-dms-cached.xml"/>-->
<context:property-placeholder location="classpath*:/eu/**/application.properties" />
<bean class="eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader" id="propertyLoader">

View File

@ -5,6 +5,28 @@
http://xmlns.jcp.org/xml/ns/javaee "
version="3.1">
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.headers</param-name>
<param-value>Content-Type,X-Requested-With,accept,authorization,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET, POST, PUT, DELETE, OPTIONS, HEAD</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>