Skip to content

Commit

Permalink
Merge pull request #5 from wcmc-its/dev
Browse files Browse the repository at this point in the history
Upgrade to Java 11 and swagger 3.0
  • Loading branch information
sarbajitdutta authored Dec 29, 2020
2 parents 508a63a + 59b12e3 commit e486887
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:8-jre-slim
FROM openjdk:11-jre-slim

RUN mkdir -p /app
WORKDIR /app
Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: java -jar reciter-scopus-retrieval-tool-0.0.1-SNAPSHOT.jar
web: java -jar reciter-scopus-retrieval-tool-1.1.0.jar
6 changes: 4 additions & 2 deletions buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ version: 0.2
# https://docs.aws.amazon.com/codebuild/latest/userguide/getting-started.html
phases:
install:
runtime-versions:
java: openjdk11
commands:
- echo Nothing to do in the install phase...
pre_build:
Expand All @@ -14,9 +16,9 @@ phases:
post_build:
commands:
- echo Build completed on `date`
- cp target/reciter-scopus-retrieval-tool-0.0.1-SNAPSHOT.jar .
- cp target/reciter-scopus-retrieval-tool-1.1.0.jar .
artifacts:
files:
- reciter-scopus-retrieval-tool-0.0.1-SNAPSHOT.jar
- reciter-scopus-retrieval-tool-1.1.0.jar
- .ebextensions/**/*
- Procfile
2 changes: 2 additions & 0 deletions k8-buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
version: 0.2
phases:
install:
runtime-versions:
java: openjdk11
commands:
- kubectl version --short --client
pre_build:
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/k8-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data:
listen [::]:80 default_server;
location /scopus {
rewrite ^/scopus/swagger-ui.html$ /swagger-ui.html break;
rewrite ^/scopus/swagger-ui/index.html$ /swagger-ui/index.html break;
rewrite ^/scopus/(.*)$ /scopus/$1 break;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/k8-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ spec:
cpu: 0.6
livenessProbe:
httpGet:
path: "/swagger-ui.html"
path: "/scopus/ping"
port: 5000
initialDelaySeconds: 10
periodSeconds: 10
failureThreshold: 3
timeoutSeconds: 3
readinessProbe:
httpGet:
path: "/swagger-ui.html"
path: "/scopus/ping"
port: 5000
initialDelaySeconds: 10
periodSeconds: 10
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/k8-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: reciter-scopus
namespace: reciter
annotations:
alb.ingress.kubernetes.io/healthcheck-path: /scopus/swagger-ui.html
alb.ingress.kubernetes.io/healthcheck-path: /scopus/ping
alb.ingress.kubernetes.io/success-codes: 200-302
alb.ingress.kubernetes.io/healthcheck-protocol: HTTP
alb.ingress.kubernetes.io/healthcheck-interval-seconds: '15'
Expand Down
35 changes: 8 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
<modelVersion>4.0.0</modelVersion>
<groupId>edu.wcmc.reciter</groupId>
<artifactId>reciter-scopus-retrieval-tool</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.1.0</version>
<name>ReCiter-Scopus-Retrieval-Tool</name>
<description>A tool to retrieve Scopus articles.</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
<version>2.3.7.RELEASE</version>
<relativePath />
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<java.version>11</java.version>
</properties>

<dependencies>
Expand All @@ -29,19 +29,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>edu.cornell.weill.reciter</groupId>
<artifactId>reciter-scopus-model</artifactId>
Expand All @@ -68,15 +60,4 @@
</plugin>
</plugins>
</build>
<!-- <repositories>
<repository>
<id>wcmc-its</id>
<name>ReCiter-Maven-Repository</name>
<url>https://github.com/wcmc-its/ReCiter-Maven-Repository/raw/master/snapshots</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories> -->
</project>
23 changes: 23 additions & 0 deletions src/main/java/reciter/controller/PingController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package reciter.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/scopus")
@Api(value = "PingController", tags = {"Health Check"})
public class PingController {

@ApiOperation(value = "Health check", response = ResponseEntity.class)
@GetMapping(value = "/ping", produces = "text/plain")
@ResponseBody
public ResponseEntity<String> ping() {
return ResponseEntity.ok("Healthy");
}
}
26 changes: 15 additions & 11 deletions src/main/java/reciter/controller/ScopusController.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
package reciter.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import reciter.model.scopus.ScopusArticle;
import reciter.model.scopus.ScopusQuery;
import reciter.scopus.retriever.ScopusArticleRetriever;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/scopus")
@Api(value="ScopusController", description="Operations on querying the Scopus API.")
@Api(value="ScopusController", tags = {"Querying Scopus with PMID, SCOPUS-ID or DOI"})
public class ScopusController {
private static final Logger slf4jLogger = LoggerFactory.getLogger(ScopusController.class);

@ApiOperation(value = "Querying Scopus with PMIDs.", response = List.class)
@ApiOperation(value = "Querying Scopus with PMID, SCOPUS-ID or DOI. Add type it only accepts PMID,SCOPUS-ID or DOI(case-insensitive)", response = List.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully retrieved list"),
@ApiResponse(code = 401, message = "You are not authorized to view the resource"),
@ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
@ApiResponse(code = 404, message = "The resource you were trying to reach is not found")
})
@RequestMapping(value = "/query/", method = RequestMethod.POST, produces = "application/json")
@PostMapping(value = "/query/", produces = "application/json")
@ResponseBody
public ResponseEntity<List<ScopusArticle>> retrieve(@RequestBody ScopusQuery scopusQuery) {
slf4jLogger.info("calling retrieve with pmids size=[" + scopusQuery.getQuery().size() + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.rholder.retry.Retryer;
import com.github.rholder.retry.Retryer.RetryerCallable;
import com.github.rholder.retry.RetryerBuilder;
import com.github.rholder.retry.StopStrategies;
import com.github.rholder.retry.WaitStrategies;
import com.google.common.base.Predicates;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import reciter.model.scopus.ScopusArticle;
import reciter.scopus.callable.ScopusUriParserCallable;
import reciter.scopus.querybuilder.ScopusXmlQuery;
import reciter.scopus.xmlparser.ScopusXmlHandler;

public class ScopusArticleRetriever {

private final static Logger slf4jLogger = LoggerFactory.getLogger(ScopusArticleRetriever.class);
private static final Logger slf4jLogger = LoggerFactory.getLogger(ScopusArticleRetriever.class);

/**
* Scopus retrieval threshold.
Expand All @@ -49,7 +48,7 @@ public List<ScopusArticle> retrieveScopus(List<Object> pmids, String type) {
if (pmids.size() == 1) {
pmidQueries.add(type + "(" + pmids.get(0) + ")");
} else {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
int i = 0;
Iterator<Object> itr = pmids.iterator();
while (itr.hasNext()) {
Expand All @@ -65,7 +64,7 @@ public List<ScopusArticle> retrieveScopus(List<Object> pmids, String type) {
}
if (i != 0 && i % SCOPUS_DEFAULT_THRESHOLD == 0) {
pmidQueries.add(sb.toString());
sb = new StringBuffer();
sb = new StringBuilder();
}
i++;
}
Expand All @@ -76,7 +75,7 @@ public List<ScopusArticle> retrieveScopus(List<Object> pmids, String type) {
}
}

List<RetryerCallable<List<ScopusArticle>>> callables = new ArrayList<RetryerCallable<List<ScopusArticle>>>();
List<RetryerCallable<List<ScopusArticle>>> callables = new ArrayList<>();

Retryer<List<ScopusArticle>> retryer = RetryerBuilder.<List<ScopusArticle>>newBuilder()
.retryIfResult(Predicates.<List<ScopusArticle>>isNull())
Expand Down
23 changes: 2 additions & 21 deletions src/main/java/reciter/scopus/xmlparser/ScopusXmlHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
Expand All @@ -25,16 +21,13 @@
*/
public class ScopusXmlHandler extends DefaultHandler {

private final static Logger slf4jLogger = LoggerFactory.getLogger(ScopusXmlHandler.class);

private ScopusArticle scopusArticle;

private boolean bScopusDocId;

private boolean bAffiliation;
private boolean bAfid;
private boolean bAffilname;
// private boolean bNameVariant;
private boolean bAffiliationCity;
private boolean bAffiliationCountry;

Expand Down Expand Up @@ -65,7 +58,6 @@ public class ScopusXmlHandler extends DefaultHandler {

private int afid;
private StringBuilder affilname = new StringBuilder();
// private String nameVariant;
private String affiliationCity;
private String affiliationCountry;
private Map<Integer, Affiliation> affiliations = new HashMap<>();
Expand Down Expand Up @@ -112,9 +104,6 @@ public void startElement(String uri, String localName, String qName, Attributes
affilname.setLength(0);
bAffilname = true;
}
// if (qName.equalsIgnoreCase("name-variant")) {
// bNameVariant = true;
// }
if (qName.equalsIgnoreCase("affiliation-city")) {
bAffiliationCity = true;
}
Expand Down Expand Up @@ -234,12 +223,8 @@ public void characters(char[] ch, int start, int length) throws SAXException {
afid = Integer.parseInt(new String(ch, start, length));
}
if (bAffilname) {
//affilname = new String(ch, start, length);
affilname.append(ch, start, length);
}
// if (bNameVariant) {
// nameVariant = new String(ch, start, length);
// }
if (bAffiliationCity) {
affiliationCity = new String(ch, start, length);
}
Expand Down Expand Up @@ -360,9 +345,6 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
if (qName.equalsIgnoreCase("affilname")) {
bAffilname = false;
}
// if (qName.equalsIgnoreCase("name-variant")) {
// bNameVariant = false;
// }
if (qName.equalsIgnoreCase("affiliation-city")) {
bAffiliationCity = false;
}
Expand Down Expand Up @@ -472,8 +454,8 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
if (bError) {
scopusArticle = null;
} else {
List<Affiliation> affiliationList = new ArrayList<Affiliation>();
List<Author> authorList = new ArrayList<Author>();
List<Affiliation> affiliationList = new ArrayList<>();
List<Author> authorList = new ArrayList<>();
for (Affiliation affiliation : affiliations.values()) {
affiliationList.add(affiliation);
}
Expand All @@ -499,7 +481,6 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
.citedByCount(citedByCount)
.authors(authorList).build();
scopusArticles.add(scopusArticle);
// TODO refactor
scopusArticle = null;
doi=null;
affiliations.clear();
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/reciter/swagger/SwaggerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
Expand All @@ -18,6 +22,18 @@ public Docket productApi() {
.select()
.apis(RequestHandlerSelectors.basePackage("reciter.controller"))
.paths(regex("/scopus.*"))
.build()
.apiInfo(apiInfo());
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("ReCiter publication management system - Scopus Retrieval Tool")
.description("Retrieve publications from Scopus. More info here: http://github.com/wcmc-its/ReCiter-Scopus-Retrieval-Tool/").termsOfServiceUrl("")
.contact(new Contact("Paul J. Albert", "https://github.com/wcmc-its/ReCiter", "[email protected]"))
.contact(new Contact("Sarbajit Dutta", "https://github.com/wcmc-its/ReCiter", "[email protected]"))
.license("Apache License Version 2.0")
.licenseUrl("https://www.apache.org/licenses/LICENSE-2.0")
.version("1.1.0")
.build();
}
}

0 comments on commit e486887

Please sign in to comment.