From f531cd4e8cddcf504b3a51ecd06232a01e816c95 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 21 Sep 2017 07:53:53 +0000 Subject: [PATCH] Fix to support old usage records git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-aggregator-se-plugin@154348 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../aggregator/aggregation/Aggregator.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/gcube/accounting/aggregator/aggregation/Aggregator.java b/src/main/java/org/gcube/accounting/aggregator/aggregation/Aggregator.java index b4628f3..d06db06 100644 --- a/src/main/java/org/gcube/accounting/aggregator/aggregation/Aggregator.java +++ b/src/main/java/org/gcube/accounting/aggregator/aggregation/Aggregator.java @@ -12,6 +12,7 @@ import org.gcube.accounting.aggregator.utility.Constant; import org.gcube.accounting.aggregator.utility.Utility; import org.gcube.accounting.datamodel.AggregatedUsageRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord; +import org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord; import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; import org.gcube.documentstore.exception.InvalidValueException; import org.gcube.documentstore.records.AggregatedRecord; @@ -112,7 +113,9 @@ public class Aggregator { } } - + private static final String USAGE_RECORD_TYPE = "usageRecordType"; + private static final String SINGLE = "Single"; + private static final String SIMPLE = "Simple"; protected void retrieveAndAggregate(ViewResult viewResult) throws Exception { AggregatorBuffer aggregatorBuffer = new AggregatorBuffer(); @@ -130,9 +133,9 @@ public class Aggregator { try { JsonObject content = row.document().content(); - if(content.containsKey("usageRecordType")){ - String recordType = content.getString("usageRecordType"); - content.removeKey("usageRecordType"); + if(content.containsKey(USAGE_RECORD_TYPE)){ + String recordType = content.getString(USAGE_RECORD_TYPE); + content.removeKey(USAGE_RECORD_TYPE); content.put(Record.RECORD_TYPE, recordType); } @@ -143,10 +146,15 @@ public class Aggregator { if(!aggregated){ String recordType = content.getString(Record.RECORD_TYPE); - content.put(Record.RECORD_TYPE, "Simple" + recordType); + content.put(Record.RECORD_TYPE, SINGLE + recordType); } + String recordType = content.getString(Record.RECORD_TYPE); + if(recordType.contains(SIMPLE)){ + recordType.replace(SIMPLE, SINGLE); + } + String record = content.toString(); // Backup the Record on local file @@ -201,7 +209,6 @@ public class Aggregator { protected void aggregateRow(AggregatorBuffer aggregatorBuffer, String json) throws Exception { Record record = RecordUtility.getRecord(json); - try { record.validate(); }catch (InvalidValueException e) { @@ -215,6 +222,9 @@ public class Aggregator { if(record.getResourceProperty(AggregatedServiceUsageRecord.MAX_INVOCATION_TIME)==null) { record.setResourceProperty(AggregatedServiceUsageRecord.MAX_INVOCATION_TIME, record.getResourceProperty(ServiceUsageRecord.DURATION)); } + if(record.getResourceProperty(AggregatedServiceUsageRecord.CALLER_QUALIFIER)==null) { + record.setResourceProperty(AggregatedServiceUsageRecord.CALLER_QUALIFIER, AbstractServiceUsageRecord.UNKNOWN); + } } record.validate(); }