This repository has been archived by the owner on Mar 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
5,405 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
HDX-System/src/main/java/org/ocha/hdx/cache/ApiV2CacheConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
HDX-System/src/main/java/org/ocha/hdx/config/api2/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |
99 changes: 99 additions & 0 deletions
99
HDX-System/src/main/java/org/ocha/hdx/model/api2/ApiIndicatorValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
103
HDX-System/src/main/java/org/ocha/hdx/model/api2/ApiResultWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.