Added values retrieving

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/accounting-manager@119336 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-10-02 09:03:12 +00:00
parent 74c7a06ec8
commit cce7c3f363
3 changed files with 97 additions and 87 deletions

View File

@ -4,9 +4,6 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="accounting-manager-theme-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/accounting-manager-theme/accounting-manager-theme">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/accounting-manager/target/accounting-manager-0.0.1-SNAPSHOT/WEB-INF/classes"/>
<property name="context-root" value="accounting-manager"/>
</wb-module>

View File

@ -1,7 +1,6 @@
package org.gcube.portlets.admin.accountingmanager.server;
import java.util.ArrayList;
import java.util.Arrays;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
@ -144,62 +143,11 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.getAslSession(session);
if (filterValuesRequest.getFilterKey() == null) {
return new ArrayList<FilterValue>();
}
switch (filterValuesRequest.getFilterKey().getKey()) {
case "consumerId":
return new ArrayList<FilterValue>(Arrays.asList(
new FilterValue("giancarlo.panichi"), new FilterValue(
"luca.frosini"), new FilterValue(
"gianpaolo.coro"), new FilterValue(
"valentina.marioli")));
case "calledMethod":
return new ArrayList<FilterValue>(
Arrays.asList(new FilterValue("batchExecute")));
case "callerHost":
return new ArrayList<FilterValue>(
Arrays.asList(new FilterValue("146.48.122.190")));
case "host":
return new ArrayList<FilterValue>(
Arrays.asList(new FilterValue(
"node7.d.d4science.research-infrastructures.eu:8080")));
case "operationResult":
return new ArrayList<FilterValue>(
Arrays.asList(new FilterValue("SUCCESS")));
case "operationType":
return new ArrayList<FilterValue>(
Arrays.asList(new FilterValue("UPDATE")));
case "scope":
return new ArrayList<FilterValue>(
Arrays.asList(new FilterValue("/gcube/devsec/devVRE")));
case "serviceClass":
return new ArrayList<FilterValue>(
Arrays.asList(new FilterValue("DataAnalysis")));
case "serviceName":
return new ArrayList<FilterValue>(
Arrays.asList(new FilterValue("TabularData")));
case "dataType":
return new ArrayList<FilterValue>(
Arrays.asList(new FilterValue("STORAGE")));
case "providerURI":
return new ArrayList<FilterValue>(
Arrays.asList(new FilterValue("NOT_PROVIDED")));
case "resourceOwner":
return new ArrayList<FilterValue>(
Arrays.asList(new FilterValue("valentina.marioli")));
case "resourceScope":
return new ArrayList<FilterValue>(
Arrays.asList(new FilterValue("/gcube")));
case "resourceURI":
return new ArrayList<FilterValue>(
Arrays.asList(new FilterValue("NOT_PROVIDED")));
default:
return new ArrayList<FilterValue>();
}
AccountingCaller accountingCaller = new AccountingCaller();
ArrayList<FilterValue> filterValues = accountingCaller.getFilterValues(filterValuesRequest);
return filterValues;
} catch (AccountingManagerServiceException e) {
e.printStackTrace();
throw e;

View File

@ -28,6 +28,8 @@ import org.gcube.portlets.admin.accountingmanager.server.amservice.response.Seri
import org.gcube.portlets.admin.accountingmanager.server.amservice.response.SeriesResponseDirector;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException;
@ -47,44 +49,45 @@ public class AccountingCaller {
public AccountingCaller() {
}
public ArrayList<FilterKey> getFilterKeys(AccountingType accountingType)
throws AccountingManagerServiceException {
throws AccountingManagerServiceException {
try {
logger.debug("getFilterKeys(): [AccountingType=" + accountingType+"]");
if(accountingType==null){
logger.debug("getFilterKeys(): [AccountingType=" + accountingType
+ "]");
if (accountingType == null) {
return new ArrayList<FilterKey>();
}
ArrayList<FilterKey> filterKeys=new ArrayList<FilterKey>();
ArrayList<FilterKey> filterKeys = new ArrayList<FilterKey>();
List<String> keys;
ResourceRecordQuery rrq = new ResourceRecordQuery();
switch(accountingType){
switch (accountingType) {
case JOB:
//keys=rrq.getKeys(AggregatedJobUsageRecord.class);
// keys=rrq.getKeys(AggregatedJobUsageRecord.class);
return filterKeys;
case PORTLET:
//keys=rrq.getKeys(AggregatedPortletUsageRecord.class);
// keys=rrq.getKeys(AggregatedPortletUsageRecord.class);
return filterKeys;
case SERVICE:
keys=rrq.getKeys(AggregatedServiceUsageRecord.class);
keys = rrq.getKeys(AggregatedServiceUsageRecord.class);
break;
case STORAGE:
keys=rrq.getKeys(AggregatedStorageUsageRecord.class);
keys = rrq.getKeys(AggregatedStorageUsageRecord.class);
break;
case TASK:
//keys=rrq.getKeys(AggregatedTaskUsageRecord.class);
// keys=rrq.getKeys(AggregatedTaskUsageRecord.class);
return filterKeys;
default:
return filterKeys;
}
for(String key:keys){
if(key!=null&& !key.isEmpty()){
for (String key : keys) {
if (key != null && !key.isEmpty()) {
filterKeys.add(new FilterKey(key));
}
}
return filterKeys;
} catch (Throwable e) {
logger.error("Error in getFilterKeys(): " + e.getLocalizedMessage());
@ -93,16 +96,77 @@ public class AccountingCaller {
}
}
public ArrayList<FilterValue> getFilterValues(
FilterValuesRequest filterValuesRequest)
throws AccountingManagerServiceException {
try {
logger.debug("getFilterValue(): [FilterValueRequest="
+ filterValuesRequest + "]");
if (filterValuesRequest == null
|| filterValuesRequest.getAccountingType() == null
|| filterValuesRequest.getFilterKey() == null) {
return new ArrayList<FilterValue>();
}
ArrayList<FilterValue> filteValues = new ArrayList<FilterValue>();
List<String> values;
ResourceRecordQuery rrq = new ResourceRecordQuery();
switch (filterValuesRequest.getAccountingType()) {
case JOB:
//values = rrq.getPossibleValuesForKey(AggregatedJobUsageRecord.class, filterValuesRequest
// .getFilterKey().getKey());
return filteValues;
case PORTLET:
//values = rrq.getPossibleValuesForKey(
// AggregatedPortletUsageRecord.class, filterValuesRequest
// .getFilterKey().getKey());
return filteValues;
case SERVICE:
values = rrq.getPossibleValuesForKey(
AggregatedServiceUsageRecord.class, filterValuesRequest
.getFilterKey().getKey());
break;
case STORAGE:
values = rrq.getPossibleValuesForKey(
AggregatedStorageUsageRecord.class, filterValuesRequest
.getFilterKey().getKey());
break;
case TASK:
//values = rrq.getPossibleValuesForKey(
// AggregatedTaskUsageRecord.class, filterValuesRequest
// .getFilterKey().getKey());
return filteValues;
default:
return filteValues;
}
for (String value : values) {
if (value != null && !value.isEmpty()) {
filteValues.add(new FilterValue(value));
}
}
return filteValues;
} catch (Throwable e) {
logger.error("Error in getFilterValues(): "
+ e.getLocalizedMessage());
e.printStackTrace();
throw new AccountingManagerServiceException("No values available!");
}
}
public SeriesResponse getSeries(AccountingType accountingType,
SeriesRequest seriesRequest)
throws AccountingManagerServiceException {
try {
logger.debug("getSeries(): [AccountingType=" + accountingType
+ " , seriesRequest=" + seriesRequest + "]");
ResourceRecordQuery rrq = new ResourceRecordQuery();
AccountingQueryBuilder queryBuilder = getAccountQueryBuilder(
accountingType, seriesRequest);
@ -116,8 +180,8 @@ public class AccountingCaller {
"Error in invocation: Operation not supported");
}
logger.debug("Query: "+query);
logger.debug("Query: " + query);
List<Info> infos = rrq.getInfo(query.getType(),
query.getTemporalConstraint(), query.getFilters(), true);
if (infos == null) {
@ -125,7 +189,7 @@ public class AccountingCaller {
"Error retrieving list of info: list is null!");
}
logger.debug("Retrieved Infos");
logger.debug("Infos: "+infos);
logger.debug("Infos: " + infos);
SeriesResponseBuilder seriesResponseBuilder = getSeriesResponseBuilder(
accountingType, infos);
@ -141,7 +205,7 @@ public class AccountingCaller {
throw new AccountingManagerServiceException(
"Error creating series response!");
}
logger.debug("SeriesResponse Created: "+seriesResponse);
logger.debug("SeriesResponse Created: " + seriesResponse);
return seriesResponse;
} catch (Throwable e) {
logger.error("Error in GetSeries(): " + e.getLocalizedMessage());
@ -168,7 +232,7 @@ public class AccountingCaller {
startTempCalendar.get(GregorianCalendar.MONTH),
startTempCalendar.get(GregorianCalendar.DATE));
startCalendar.setTimeZone(TemporalConstraint.DEFAULT_TIME_ZONE);
Calendar endTempCalendar = new GregorianCalendar();
endTempCalendar.setTime(seriesRequest.getAccountingPeriod()
.getEndDate());
@ -183,10 +247,11 @@ public class AccountingCaller {
sdf.setTimeZone(TemporalConstraint.DEFAULT_TIME_ZONE);
logger.debug("StartCalendar: " + sdf.format(startCalendar.getTime()));
logger.debug("EndCalendar: " + sdf.format(endCalendar.getTime()));
seriesRequest.getAccountingPeriod().setStartDate(startCalendar.getTime());
seriesRequest.getAccountingPeriod().setStartDate(
startCalendar.getTime());
seriesRequest.getAccountingPeriod().setEndDate(endCalendar.getTime());
switch (accountingType) {
case JOB:
return new AccountingQuery4Job(seriesRequest);