From 7c45a1d29a7f4714d5b596a840e6fa2dd6956fd7 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 21 Sep 2017 12:54:33 +0000 Subject: [PATCH] reformatted code git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-analytics@154378 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../AccountingPersistenceQuery.java | 349 +++++++----------- 1 file changed, 131 insertions(+), 218 deletions(-) diff --git a/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQuery.java b/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQuery.java index 353f1ff..5d857c3 100644 --- a/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQuery.java +++ b/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQuery.java @@ -51,46 +51,39 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ } @Deprecated - public static SortedSet getQuerableKeys( - @SuppressWarnings("rawtypes") AggregatedRecord instance) - throws Exception { + public static SortedSet getQuerableKeys(@SuppressWarnings("rawtypes") AggregatedRecord instance) + throws Exception { return instance.getQuerableKeys(); } - public static SortedSet getQuerableKeys( - Class> clz) - throws Exception { - AggregatedRecord instance = clz.newInstance(); - - //limit filter key for accounting storage status (used from portlet accounting for tad space) - if (clz.equals(AggregatedStorageStatusRecord.class)){ - SortedSet storageStatus= new TreeSet<>(); + public static SortedSet getQuerableKeys(Class> clz) throws Exception { + AggregatedRecord instance = clz.newInstance(); + + // limit filter key for accounting storage status (used from portlet + // accounting for tad space) + if (clz.equals(AggregatedStorageStatusRecord.class)) { + SortedSet storageStatus = new TreeSet<>(); storageStatus.add(AggregatedStorageStatusRecord.CONSUMER_ID); storageStatus.add(AggregatedStorageStatusRecord.DATA_SERVICEID); return storageStatus; + } else { + return instance.getQuerableKeys(); } - else{ - return instance.getQuerableKeys(); - } - - - + } - public static String getDefaultOrderingProperties( - Class> clz){ - if(clz.isAssignableFrom(AggregatedStorageUsageRecord.class)){ + public static String getDefaultOrderingProperties(Class> clz) { + if (clz.isAssignableFrom(AggregatedStorageUsageRecord.class)) { return AggregatedStorageUsageRecord.DATA_VOLUME; } return AggregatedRecord.OPERATION_COUNT; } - protected static JSONObject getPaddingJSONObject( - Map unpaddedResults) throws JSONException { + protected static JSONObject getPaddingJSONObject(Map unpaddedResults) throws JSONException { JSONObject jsonObject = new JSONObject(); - //verify data consistency - if (unpaddedResults.size()!=0){ + // verify data consistency + if (unpaddedResults.size() != 0) { Info auxInfo = new ArrayList(unpaddedResults.values()).get(0); JSONObject auxJsonObject = auxInfo.getValue(); @SuppressWarnings("unchecked") @@ -115,8 +108,7 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ * @throws Exception * if fails */ - public static SortedMap padMap( - SortedMap unpaddedData, + public static SortedMap padMap(SortedMap unpaddedData, TemporalConstraint temporalConstraint) throws Exception { JSONObject jsonObject = getPaddingJSONObject(unpaddedData); @@ -134,124 +126,95 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ /** * {@inheritDoc} */ - public SortedMap getTimeSeries( - Class> clz, - TemporalConstraint temporalConstraint, List filters) - throws DuplicatedKeyFilterException, KeyException, ValueException, - Exception { + public SortedMap getTimeSeries(Class> clz, + TemporalConstraint temporalConstraint, List filters) + throws DuplicatedKeyFilterException, KeyException, ValueException, Exception { return this.getTimeSeries(clz, temporalConstraint, filters, false); } - public SortedMap getTimeSeries( - Class> clz, - TemporalConstraint temporalConstraint, List filters, - boolean pad) throws DuplicatedKeyFilterException, KeyException, - ValueException, Exception { - SortedMap ret = - AccountingPersistenceBackendQueryFactory.getInstance() - .getTimeSeries(clz, temporalConstraint, - filters); + public SortedMap getTimeSeries(Class> clz, + TemporalConstraint temporalConstraint, List filters, boolean pad) + throws DuplicatedKeyFilterException, KeyException, ValueException, Exception { + SortedMap ret = AccountingPersistenceBackendQueryFactory.getInstance().getTimeSeries(clz, + temporalConstraint, filters); - if(ret==null){ + if (ret == null) { ret = new TreeMap<>(); } - - if(pad){ + if (pad) { ret = padMap(ret, temporalConstraint); } return ret; } - - - - public SortedMap getNoContextTimeSeries( - Class> clz, - TemporalConstraint temporalConstraint, List filters) - throws DuplicatedKeyFilterException, KeyException, ValueException, - Exception { + + public SortedMap getNoContextTimeSeries(Class> clz, + TemporalConstraint temporalConstraint, List filters) + throws DuplicatedKeyFilterException, KeyException, ValueException, Exception { return this.getNoContextTimeSeries(clz, temporalConstraint, filters, false); } - public SortedMap getNoContextTimeSeries( - Class> clz, - TemporalConstraint temporalConstraint, List filters, - boolean pad) throws DuplicatedKeyFilterException, KeyException, - ValueException, Exception { - SortedMap ret = - AccountingPersistenceBackendQueryFactory.getInstance() - .getNoContextTimeSeries(clz, temporalConstraint, - filters); + public SortedMap getNoContextTimeSeries(Class> clz, + TemporalConstraint temporalConstraint, List filters, boolean pad) + throws DuplicatedKeyFilterException, KeyException, ValueException, Exception { + SortedMap ret = AccountingPersistenceBackendQueryFactory.getInstance() + .getNoContextTimeSeries(clz, temporalConstraint, filters); - if(ret==null){ + if (ret == null) { ret = new TreeMap<>(); } - - if(pad){ + if (pad) { ret = padMap(ret, temporalConstraint); } return ret; } - - - public SortedMap> getTopValues( - Class> clz, - TemporalConstraint temporalConstraint, List filters, - String topKey, String orderingProperty, boolean pad, int limit) - throws DuplicatedKeyFilterException, KeyException, ValueException, - Exception { + Class> clz, TemporalConstraint temporalConstraint, List filters, + String topKey, String orderingProperty, boolean pad, int limit) + throws DuplicatedKeyFilterException, KeyException, ValueException, Exception { SortedMap> got; - if(orderingProperty==null){ + if (orderingProperty == null) { orderingProperty = getDefaultOrderingProperties(clz); } - got = AccountingPersistenceBackendQueryFactory.getInstance() - .getTopValues(clz, temporalConstraint, filters, topKey, - orderingProperty); + got = AccountingPersistenceBackendQueryFactory.getInstance().getTopValues(clz, temporalConstraint, filters, + topKey, orderingProperty); int count = got.size() > limit ? limit : got.size(); NumberedFilter firstRemovalKey = null; - for(NumberedFilter nf : got.keySet()){ - if(--count>=0 || limit<=0){ - if(pad){ + for (NumberedFilter nf : got.keySet()) { + if (--count >= 0 || limit <= 0) { + if (pad) { padMap(got.get(nf), temporalConstraint); } - }else{ - if(firstRemovalKey==null){ + } else { + if (firstRemovalKey == null) { firstRemovalKey = nf; - }else{ + } else { break; } } } - if(firstRemovalKey!=null){ + if (firstRemovalKey != null) { return got.subMap(got.firstKey(), firstRemovalKey); } return got; } public SortedMap> getTopValues( - Class> clz, - TemporalConstraint temporalConstraint, List filters, - String topKey) throws DuplicatedKeyFilterException, - KeyException, ValueException, Exception { - String orderingProperty = AccountingPersistenceQuery - .getDefaultOrderingProperties(clz); + Class> clz, TemporalConstraint temporalConstraint, List filters, + String topKey) throws DuplicatedKeyFilterException, KeyException, ValueException, Exception { + String orderingProperty = AccountingPersistenceQuery.getDefaultOrderingProperties(clz); - - - - return this.getTopValues(clz, temporalConstraint, filters, topKey, - orderingProperty, false, 0); + return this.getTopValues(clz, temporalConstraint, filters, topKey, orderingProperty, false, 0); } /** @@ -259,56 +222,42 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ */ @Override public SortedMap> getTopValues( - Class> clz, - TemporalConstraint temporalConstraint, List filters, - String topKey, String orderingProperty) throws - DuplicatedKeyFilterException, KeyException, ValueException, - Exception { - return this.getTopValues(clz, temporalConstraint, filters, topKey, - orderingProperty, false, 0); + Class> clz, TemporalConstraint temporalConstraint, List filters, + String topKey, String orderingProperty) + throws DuplicatedKeyFilterException, KeyException, ValueException, Exception { + return this.getTopValues(clz, temporalConstraint, filters, topKey, orderingProperty, false, 0); } - public SortedSet getNextPossibleValues( - Class> clz, - TemporalConstraint temporalConstraint, List filters, - String key) throws DuplicatedKeyFilterException, KeyException, - ValueException, Exception { + public SortedSet getNextPossibleValues(Class> clz, + TemporalConstraint temporalConstraint, List filters, String key) + throws DuplicatedKeyFilterException, KeyException, ValueException, Exception { - String orderingProperty = AccountingPersistenceQuery - .getDefaultOrderingProperties(clz); + String orderingProperty = AccountingPersistenceQuery.getDefaultOrderingProperties(clz); - return this.getNextPossibleValues(clz, temporalConstraint, filters, - key, orderingProperty); + return this.getNextPossibleValues(clz, temporalConstraint, filters, key, orderingProperty); } /** * {@inheritDoc} */ @Override - public SortedSet getNextPossibleValues( - Class> clz, - TemporalConstraint temporalConstraint, List filters, - String key, String orderingProperty) throws - DuplicatedKeyFilterException, KeyException, ValueException, - Exception { + public SortedSet getNextPossibleValues(Class> clz, + TemporalConstraint temporalConstraint, List filters, String key, String orderingProperty) + throws DuplicatedKeyFilterException, KeyException, ValueException, Exception { - return AccountingPersistenceBackendQueryFactory.getInstance() - .getNextPossibleValues(clz, temporalConstraint, filters, - key, orderingProperty); + return AccountingPersistenceBackendQueryFactory.getInstance().getNextPossibleValues(clz, temporalConstraint, + filters, key, orderingProperty); } - @Override - public SortedSet getNextPossibleValuesWithMap( - Class> clz, - TemporalConstraint temporalConstraint, List filters, - String key, String orderingProperty) throws Exception { - return AccountingPersistenceBackendQueryFactory.getInstance() - .getNextPossibleValuesWithMap(clz, temporalConstraint, filters, - key, orderingProperty); + public SortedSet getNextPossibleValuesWithMap(Class> clz, + TemporalConstraint temporalConstraint, List filters, String key, String orderingProperty) + throws Exception { + return AccountingPersistenceBackendQueryFactory.getInstance().getNextPossibleValuesWithMap(clz, + temporalConstraint, filters, key, orderingProperty); } - + /** * {@inheritDoc} */ @@ -321,154 +270,121 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ * {@inheritDoc} */ @Override - public void prepareConnection( - AccountingPersistenceBackendQueryConfiguration configuration) - throws Exception { + public void prepareConnection(AccountingPersistenceBackendQueryConfiguration configuration) throws Exception { throw new InvalidActivityException(); } @Override - public SortedSet getFilterValues( - Class> clz, - TemporalConstraint temporalConstraint, List filters, - String key) throws Exception { - - return AccountingPersistenceBackendQueryFactory.getInstance() - .getFilterValues(clz, temporalConstraint, filters, - key); + public SortedSet getFilterValues(Class> clz, + TemporalConstraint temporalConstraint, List filters, String key) throws Exception { + + return AccountingPersistenceBackendQueryFactory.getInstance().getFilterValues(clz, temporalConstraint, filters, + key); } @Override - public JSONObject getUsageValue(Class> clz, - TemporalConstraint temporalConstraint, Filter applicant) - throws Exception { - - return AccountingPersistenceBackendQueryFactory.getInstance() - .getUsageValue(clz, temporalConstraint, applicant); - } + public JSONObject getUsageValue(Class> clz, TemporalConstraint temporalConstraint, + Filter applicant) throws Exception { + return AccountingPersistenceBackendQueryFactory.getInstance().getUsageValue(clz, temporalConstraint, applicant); + } @Override - public List getUsageValueQuotaTotal( List listUsage) - throws Exception { - - return AccountingPersistenceBackendQueryFactory.getInstance() - .getUsageValueQuotaTotal(listUsage); + public List getUsageValueQuotaTotal(List listUsage) throws Exception { + + return AccountingPersistenceBackendQueryFactory.getInstance().getUsageValueQuotaTotal(listUsage); } - - @Override public SortedMap> getContextTimeSeries( - Class> clz, - TemporalConstraint temporalConstraint, List filters,List contexts) - throws Exception { - - return AccountingPersistenceBackendQueryFactory.getInstance() - .getContextTimeSeries(clz, temporalConstraint, filters, contexts); + Class> clz, TemporalConstraint temporalConstraint, List filters, + List contexts) throws Exception { + + return AccountingPersistenceBackendQueryFactory.getInstance().getContextTimeSeries(clz, temporalConstraint, + filters, contexts); } - public SortedMap> getContextTimeSeries( - Class> clz, - TemporalConstraint temporalConstraint, List filters, - List contexts, boolean pad) - throws DuplicatedKeyFilterException, - Exception { + Class> clz, TemporalConstraint temporalConstraint, List filters, + List contexts, boolean pad) throws DuplicatedKeyFilterException, Exception { SortedMap> got; - got = AccountingPersistenceBackendQueryFactory.getInstance() - .getContextTimeSeries(clz, temporalConstraint, filters, contexts); + got = AccountingPersistenceBackendQueryFactory.getInstance().getContextTimeSeries(clz, temporalConstraint, + filters, contexts); int count = got.size(); Filter firstRemovalKey = null; - for(Filter nf : got.keySet()){ - if(--count>=0){ - if(pad){ + for (Filter nf : got.keySet()) { + if (--count >= 0) { + if (pad) { padMap(got.get(nf), temporalConstraint); } - }else{ - if(firstRemovalKey==null){ + } else { + if (firstRemovalKey == null) { firstRemovalKey = nf; - }else{ + } else { break; } } } - if(firstRemovalKey!=null){ + if (firstRemovalKey != null) { return got.subMap(got.firstKey(), firstRemovalKey); } return got; } - - - public String getRecord(String recordId, String type ) throws Exception { - String record= AccountingPersistenceBackendQueryFactory.getInstance().getRecord(recordId,type); + public String getRecord(String recordId, String type) throws Exception { + String record = AccountingPersistenceBackendQueryFactory.getInstance().getRecord(recordId, type); return record; - + } - - - @Override - public SortedSet getSpaceProvidersIds() throws Exception{ - SortedSet providersId= AccountingPersistenceBackendQueryFactory.getInstance().getSpaceProvidersIds(); + public SortedSet getSpaceProvidersIds() throws Exception { + SortedSet providersId = AccountingPersistenceBackendQueryFactory.getInstance().getSpaceProvidersIds(); return providersId; - + } - + @Override - public SortedMap> getSpaceTimeSeries( - Class> clz, - TemporalConstraint temporalConstraint, List filters, - List providersId) - throws Exception { - - - SortedMap> spaceTimeSeries= - AccountingPersistenceBackendQueryFactory.getInstance().getSpaceTimeSeries(clz, temporalConstraint, filters, providersId); - - - - + public SortedMap> getSpaceTimeSeries(Class> clz, + TemporalConstraint temporalConstraint, List filters, List providersId) throws Exception { + + SortedMap> spaceTimeSeries = AccountingPersistenceBackendQueryFactory + .getInstance().getSpaceTimeSeries(clz, temporalConstraint, filters, providersId); + int count = spaceTimeSeries.size(); Filter firstRemovalKey = null; - for(Filter nf : spaceTimeSeries.keySet()){ - if(--count>=0){ + for (Filter nf : spaceTimeSeries.keySet()) { + if (--count >= 0) { padMapStorage(spaceTimeSeries.get(nf), temporalConstraint); - }else{ - if(firstRemovalKey==null){ + } else { + if (firstRemovalKey == null) { firstRemovalKey = nf; - }else{ + } else { break; } } } - if(firstRemovalKey!=null){ + if (firstRemovalKey != null) { return spaceTimeSeries.subMap(spaceTimeSeries.firstKey(), firstRemovalKey); } return spaceTimeSeries; - - - + } - - - public SortedMap padMapStorage( - SortedMap unpaddedData, + + public SortedMap padMapStorage(SortedMap unpaddedData, TemporalConstraint temporalConstraint) throws Exception { SortedSet sequence = temporalConstraint.getCalendarSequence(); Long longValuePre = null; for (Calendar progressTime : sequence) { Long longValue = unpaddedData.get(progressTime); - + if (longValue == null) { unpaddedData.put(progressTime, longValuePre); - }else{ - longValuePre=longValue; + } else { + longValuePre = longValue; } - + } return unpaddedData; } @@ -478,7 +394,4 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ return AccountingPersistenceBackendQueryFactory.getInstance().isConnectionActive(); } - - - }