Skip to content
This repository has been archived by the owner on Mar 26, 2019. It is now read-only.

Commit

Permalink
Merge branch 'ssl-testing'
Browse files Browse the repository at this point in the history
  • Loading branch information
seustachi committed Aug 25, 2014
2 parents 65a29c4 + 55f7877 commit 59eef91
Show file tree
Hide file tree
Showing 28 changed files with 5,405 additions and 40 deletions.
15 changes: 14 additions & 1 deletion HDX-System/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<javax.servlet.api.version>2.5</javax.servlet.api.version>
<derby.version>10.10.2.0</derby.version>
<jstl.impl.version>1.2</jstl.impl.version>
<jersey.version>2.9</jersey.version>
<jersey.version>2.11</jersey.version>
<aspectj.version>1.7.3</aspectj.version>
<!-- This value is ok for prod, can be overriden for other environments in profiles -->
<HDX_ROOT>/opt/www/tomcat/hdx</HDX_ROOT>
Expand Down Expand Up @@ -85,6 +85,13 @@
<version>1.2.16</version>
</dependency>

<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>


<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down Expand Up @@ -176,6 +183,12 @@
<artifactId>jersey-media-multipart</artifactId>
<version>${jersey.version}</version>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>

<dependency>
<groupId>net.sf.opencsv</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
*
*/
package org.ocha.hdx.cache;

import java.util.concurrent.TimeUnit;

import org.ocha.hdx.model.api2.ApiIndicatorValue;
import org.ocha.hdx.model.api2.ApiResultWrapper;
import org.ocha.hdx.model.api2util.RequestParamsWrapper;
import org.ocha.hdx.service.IntermediaryBackendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

/**
* @author alexandru-m-g
*
*/
@Configuration
public class ApiV2CacheConfiguration {

@Autowired
private IntermediaryBackendService intermediaryBackendService;

@Bean
public Cache<RequestParamsWrapper, ApiResultWrapper<ApiIndicatorValue>> indicatorResultCache() {
final LoadingCache<RequestParamsWrapper, ApiResultWrapper<ApiIndicatorValue>> indicatorResultCache =
CacheBuilder.newBuilder().maximumSize(5000)
.expireAfterWrite(1, TimeUnit.HOURS)
.recordStats()
.build(new CacheLoader<RequestParamsWrapper, ApiResultWrapper<ApiIndicatorValue>>() {
@Override
public ApiResultWrapper<ApiIndicatorValue> load(final RequestParamsWrapper paramsWrapper) throws Exception {
if ( paramsWrapper.getPageSize() == null && paramsWrapper.getPageNum() == null) {
return ApiV2CacheConfiguration.this.intermediaryBackendService.listIndicatorsByCriteria(paramsWrapper);
} else {
return ApiV2CacheConfiguration.this.intermediaryBackendService.listIndicatorsByCriteriaWithPagination(paramsWrapper);
}
}
});
return indicatorResultCache;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.ocha.hdx.config.api2;

public class Constants {
public final static Integer MAX_RESULTS = 2000;
public final static String DEFAULT_LANGUAGE = "en";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package org.ocha.hdx.model.api2;

public class ApiIndicatorValue {

private double value;

private String indicatorTypeCode;

private String indicatorTypeName;

private String locationCode;

private String locationName;

private String sourceCode;

private String sourceName;

private String time;


public ApiIndicatorValue(final double value, final String indicatorTypeCode, final String indicatorTypeName, final String locationCode, final String locationName, final String sourceCode,
final String sourceName, final String time) {
super();
this.value = value;
this.indicatorTypeCode = indicatorTypeCode;
this.indicatorTypeName = indicatorTypeName;
this.locationCode = locationCode;
this.locationName = locationName;
this.sourceCode = sourceCode;
this.sourceName = sourceName;
this.time = time;
}

public double getValue() {
return this.value;
}

public void setValue(final double value) {
this.value = value;
}

public String getIndicatorTypeCode() {
return this.indicatorTypeCode;
}

public void setIndicatorTypeCode(final String indicatorTypeCode) {
this.indicatorTypeCode = indicatorTypeCode;
}

public String getIndicatorTypeName() {
return this.indicatorTypeName;
}

public void setIndicatorTypeName(final String indicatorTypeName) {
this.indicatorTypeName = indicatorTypeName;
}

public String getLocationCode() {
return this.locationCode;
}

public void setLocationCode(final String locationCode) {
this.locationCode = locationCode;
}

public String getLocationName() {
return this.locationName;
}

public void setLocationName(final String locationName) {
this.locationName = locationName;
}

public String getSourceCode() {
return this.sourceCode;
}

public void setSourceCode(final String sourceCode) {
this.sourceCode = sourceCode;
}

public String getSourceName() {
return this.sourceName;
}

public void setSourceName(final String sourceName) {
this.sourceName = sourceName;
}

public String getTime() {
return this.time;
}

public void setTime(final String time) {
this.time = time;
}

}
103 changes: 103 additions & 0 deletions HDX-System/src/main/java/org/ocha/hdx/model/api2/ApiResultWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
*
*/
package org.ocha.hdx.model.api2;

import java.util.List;

/**
* @author alexandru-m-g
*
*/
public class ApiResultWrapper<T> {

private List<T> results;

/* used for pagination */
private Integer totalCount;

/* used for pagination */
private Integer currentPage;

/* used for pagination */
private Integer totalNumOfPages;

private boolean success;

private String errorMessage;

/* In case pagination is not used, this flag shows if there are more results than were returned */
private boolean moreResults;



public ApiResultWrapper(final List<T> results, final Integer totalCount, final Integer currentPage, final Integer totalNumOfPages, final boolean success, final String errorMessage,
final boolean moreResults) {
super();
this.results = results;
this.totalCount = totalCount;
this.currentPage = currentPage;
this.totalNumOfPages = totalNumOfPages;
this.success = success;
this.errorMessage = errorMessage;
this.moreResults = moreResults;
}

public List<T> getResults() {
return this.results;
}

public void setResults(final List<T> results) {
this.results = results;
}

public Integer getTotalCount() {
return this.totalCount;
}

public void setTotalCount(final Integer totalCount) {
this.totalCount = totalCount;
}

public Integer getCurrentPage() {
return this.currentPage;
}

public void setCurrentPage(final Integer currentPage) {
this.currentPage = currentPage;
}

public Integer getTotalNumOfPages() {
return this.totalNumOfPages;
}

public void setTotalNumOfPages(final Integer totalNumOfPages) {
this.totalNumOfPages = totalNumOfPages;
}

public boolean isSuccess() {
return this.success;
}

public void setSuccess(final boolean success) {
this.success = success;
}

public String getErrorMessage() {
return this.errorMessage;
}

public void setErrorMessage(final String errorMessage) {
this.errorMessage = errorMessage;
}

public boolean isMoreResults() {
return this.moreResults;
}

public void setMoreResults(final boolean moreResults) {
this.moreResults = moreResults;
}


}
Loading

0 comments on commit 59eef91

Please sign in to comment.