Skip to content

Commit

Permalink
Create and finalise JournalsService
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgiobasile committed Jun 7, 2017
1 parent 689ad51 commit 07b00f3
Show file tree
Hide file tree
Showing 8 changed files with 354 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>uk.ac.core</groupId>
<artifactId>oacore4j</artifactId>
<version>0.1</version>
<version>1.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/uk/ac/core/oacore4j/OACoreService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;
import uk.ac.core.oacore4j.articles.ArticlesService;
import uk.ac.core.oacore4j.journals.JournalsService;
import uk.ac.core.oacore4j.repositories.RepositoriesService;
import uk.ac.core.oacore4j.search.SearchAllService;

Expand All @@ -25,6 +26,7 @@ public class OACoreService {
private ArticlesService articlesService;
private RepositoriesService repositoriesService;
private SearchAllService searchAllService;
private JournalsService journalsService;

public OACoreService(String apiKey){
this.apiKey = apiKey;
Expand All @@ -33,6 +35,7 @@ public OACoreService(String apiKey){
this.articlesService = retrofit.create(ArticlesService.class);
this.repositoriesService = retrofit.create(RepositoriesService.class);
this.searchAllService = retrofit.create(SearchAllService.class);
this.journalsService = retrofit.create(JournalsService.class);
}

public ArticlesService getArticlesService() {
Expand All @@ -47,6 +50,10 @@ public SearchAllService getSearchAllService() {
return searchAllService;
}

public JournalsService getJournalsService() {
return journalsService;
}

private Retrofit createRetrofit(String apiKey){

return new Retrofit.Builder()
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/uk/ac/core/oacore4j/journals/JournalsService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package uk.ac.core.oacore4j.journals;

import retrofit2.Call;
import retrofit2.http.*;
import uk.ac.core.oacore4j.commons.SearchRequest;
import uk.ac.core.oacore4j.journals.response.JournalResponse;
import uk.ac.core.oacore4j.journals.response.JournalSearchResponse;

import java.util.List;


/**
* @author Giorgio Basile
* @since 23/05/2017
*/

public interface JournalsService {

String QUERY = "query";
String PAGE = "page";
String PAGE_SIZE = "pageSize";
String ISSN = "issn";


@POST("journals/get")
Call<List<JournalResponse>> getJournals(@Body List<String> issnList);

@GET("journals/get/{issn}")
Call<JournalResponse> getJournal(@Path(ISSN) String issn);

@POST("journals/search")
Call<List<JournalSearchResponse>> searchJournals(@Body List<SearchRequest> searchRequests);

@GET("journals/search/{query}")
Call<JournalSearchResponse> searchJournals(@Path(QUERY) String query,
@Query(PAGE) Integer page,
@Query(PAGE_SIZE) Integer pageSize);

}
110 changes: 110 additions & 0 deletions src/main/java/uk/ac/core/oacore4j/journals/response/Journal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@

package uk.ac.core.oacore4j.journals.response;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"title",
"identifiers",
"subjects",
"language",
"rights",
"publisher"
})
public class Journal {

@JsonProperty("title")
private String title;
@JsonProperty("identifiers")
private List<String> identifiers = null;
@JsonProperty("subjects")
private List<String> subjects = null;
@JsonProperty("language")
private String language;
@JsonProperty("rights")
private String rights;
@JsonProperty("publisher")
private String publisher;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();

@JsonProperty("title")
public String getTitle() {
return title;
}

@JsonProperty("title")
public void setTitle(String title) {
this.title = title;
}

@JsonProperty("identifiers")
public List<String> getIdentifiers() {
return identifiers;
}

@JsonProperty("identifiers")
public void setIdentifiers(List<String> identifiers) {
this.identifiers = identifiers;
}

@JsonProperty("subjects")
public List<String> getSubjects() {
return subjects;
}

@JsonProperty("subjects")
public void setSubjects(List<String> subjects) {
this.subjects = subjects;
}

@JsonProperty("language")
public String getLanguage() {
return language;
}

@JsonProperty("language")
public void setLanguage(String language) {
this.language = language;
}

@JsonProperty("rights")
public String getRights() {
return rights;
}

@JsonProperty("rights")
public void setRights(String rights) {
this.rights = rights;
}

@JsonProperty("publisher")
public String getPublisher() {
return publisher;
}

@JsonProperty("publisher")
public void setPublisher(String publisher) {
this.publisher = publisher;
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

package uk.ac.core.oacore4j.journals.response;

import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"status",
"journal"
})
public class JournalResponse {

@JsonProperty("status")
private String status;
@JsonProperty("data")
private Journal journal;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<>();

@JsonProperty("status")
public String getStatus() {
return status;
}

@JsonProperty("status")
public void setStatus(String status) {
this.status = status;
}

@JsonProperty("data")
public Journal getJournal() {
return journal;
}

@JsonProperty("data")
public void setJournal(Journal journal) {
this.journal = journal;
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

package uk.ac.core.oacore4j.journals.response;

import com.fasterxml.jackson.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"status",
"journal"
})
public class JournalSearchResponse {

@JsonProperty("status")
private String status;
@JsonProperty("data")
private List<Journal> journal;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<>();

@JsonProperty("status")
public String getStatus() {
return status;
}

@JsonProperty("status")
public void setStatus(String status) {
this.status = status;
}

@JsonProperty("data")
public List<Journal> getJournal() {
return journal;
}

@JsonProperty("data")
public void setJournal(List<Journal> journal) {
this.journal = journal;
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

}
8 changes: 6 additions & 2 deletions src/test/java/uk/ac/core/oacore4j/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
*/
public class BaseTest {

protected String readApiKey(){
return System.getProperty("apiKey");
protected String readApiKey() throws NullPointerException{
String apiKey = System.getProperty("apiKey");
if(apiKey == null){
throw new NullPointerException("Please provide a valid CORE API key");
}
return apiKey;
}

}
Loading

0 comments on commit 07b00f3

Please sign in to comment.