package org.gcube.portlets.admin.accountingmanager.server.amservice.response; import java.util.ArrayList; import java.util.List; import org.gcube.accounting.analytics.Info; import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesJob; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesJobData; import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Series Response 4 Job * * @author "Giancarlo Panichi" email: g.panichi@isti.cnr.it * */ public class SeriesResponse4Job extends SeriesResponseBuilder { protected static Logger logger = LoggerFactory .getLogger(SeriesResponse4Job.class); private List infos; public SeriesResponse4Job(List infos) { this.infos=infos; } @Override public void buildSeriesResponse() throws AccountingManagerServiceException { try { if(infos.size()<=0){ logger.error("Error creating series for job accounting: No data available!"); throw new AccountingManagerServiceException("No data available!"); } ArrayList series=new ArrayList(); for (Info info : infos) { JSONObject jso = info.getValue(); //Long duration = jso.getLong(AggregatedJobUsageRecord.DURATION); Long operationCount = jso .getLong(AggregatedJobUsageRecord.OPERATION_COUNT); //Long maxInvocationTime = jso.getLong(AggregatedServiceUsageRecord.MAX_INVOCATION_TIME); //Long minInvocationTime = jso.getLong(AggregatedServiceUsageRecord.MIN_INVOCATION_TIME); series.add(new SeriesJobData(info.getCalendar().getTime(), operationCount)); } SeriesJob seriesService = new SeriesJob(series); seriesResponseSpec.setSr(seriesService); } catch (Throwable e) { logger.error("Error creating series for job accounting: "+e.getLocalizedMessage()); e.printStackTrace(); throw new AccountingManagerServiceException("Error creating series for job accounting: "+e.getLocalizedMessage()); } } }