Fixed jackson annotations for a proper marshalling/unmershalling

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@153169 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-09-18 13:08:46 +00:00
parent dff433de7c
commit 716952eaef
6 changed files with 27 additions and 12 deletions

View File

@ -97,7 +97,6 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public String getConsumerId() { public String getConsumerId() {
return (String) this.resourceProperties.get(CONSUMER_ID); return (String) this.resourceProperties.get(CONSUMER_ID);
@ -106,14 +105,12 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public void setConsumerId(String consumerId) throws InvalidValueException { public void setConsumerId(String consumerId) throws InvalidValueException {
setResourceProperty(CONSUMER_ID, consumerId); setResourceProperty(CONSUMER_ID, consumerId);
} }
@Override @Override
@JsonIgnore
public String getRecordType() { public String getRecordType() {
return BasicUsageRecord.class.getSimpleName(); return BasicUsageRecord.class.getSimpleName();
} }
@ -121,7 +118,6 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public String getScope() { public String getScope() {
return (String) this.resourceProperties.get(SCOPE); return (String) this.resourceProperties.get(SCOPE);
@ -130,7 +126,6 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public void setScope(String scope) throws InvalidValueException { public void setScope(String scope) throws InvalidValueException {
setResourceProperty(SCOPE, scope); setResourceProperty(SCOPE, scope);
@ -139,7 +134,6 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@JsonIgnore
@Override @Override
public OperationResult getOperationResult() { public OperationResult getOperationResult() {
try { try {

View File

@ -5,6 +5,8 @@ import java.io.Serializable;
import org.gcube.documentstore.exception.InvalidValueException; import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record; import org.gcube.documentstore.records.Record;
import com.fasterxml.jackson.annotation.JsonIgnore;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*/ */
@ -35,6 +37,7 @@ public interface UsageRecord extends Record {
/** /**
* @return the Operation Result of the accounted operation. * @return the Operation Result of the accounted operation.
*/ */
@JsonIgnore
public OperationResult getOperationResult(); public OperationResult getOperationResult();
/** /**
@ -49,6 +52,7 @@ public interface UsageRecord extends Record {
* communication is another service) * communication is another service)
* @return Consumer ID * @return Consumer ID
*/ */
@JsonIgnore
public String getConsumerId(); public String getConsumerId();
/** /**
@ -63,6 +67,7 @@ public interface UsageRecord extends Record {
* Return the scope of this {#UsageRecord} * Return the scope of this {#UsageRecord}
* @return The scope of this {#UsageRecord} * @return The scope of this {#UsageRecord}
*/ */
@JsonIgnore
public String getScope(); public String getScope();
/** /**
@ -71,8 +76,5 @@ public interface UsageRecord extends Record {
* @throws InvalidValueException * @throws InvalidValueException
*/ */
public void setScope(String scope) throws InvalidValueException; public void setScope(String scope) throws InvalidValueException;
} }

View File

@ -18,6 +18,7 @@ import org.gcube.documentstore.records.implementation.AggregatedField;
import org.gcube.documentstore.records.implementation.RequiredField; import org.gcube.documentstore.records.implementation.RequiredField;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong; import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeName; import com.fasterxml.jackson.annotation.JsonTypeName;
/** /**
@ -71,6 +72,7 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements
super.setOperationCount(operationCount); super.setOperationCount(operationCount);
} }
@JsonIgnore
public long getMaxInvocationTime() { public long getMaxInvocationTime() {
return (Long) this.resourceProperties.get(MAX_INVOCATION_TIME); return (Long) this.resourceProperties.get(MAX_INVOCATION_TIME);
} }
@ -79,6 +81,7 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements
super.setResourceProperty(MAX_INVOCATION_TIME, maxInvocationTime); super.setResourceProperty(MAX_INVOCATION_TIME, maxInvocationTime);
} }
@JsonIgnore
public long getMinInvocationTime() { public long getMinInvocationTime() {
return (Long) this.resourceProperties.get(MIN_INVOCATION_TIME); return (Long) this.resourceProperties.get(MIN_INVOCATION_TIME);
} }
@ -126,7 +129,7 @@ public class AggregatedJobUsageRecord extends AbstractJobUsageRecord implements
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Boolean isAggregated() { public Boolean isAggregated() {
return super.isAggregated(); return super.isAggregated();
} }

View File

@ -17,6 +17,7 @@ import org.gcube.documentstore.records.implementation.AggregatedField;
import org.gcube.documentstore.records.implementation.RequiredField; import org.gcube.documentstore.records.implementation.RequiredField;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong; import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeName; import com.fasterxml.jackson.annotation.JsonTypeName;
/** /**
@ -69,6 +70,7 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp
super.setOperationCount(operationCount); super.setOperationCount(operationCount);
} }
@JsonIgnore
public long getMaxInvocationTime() { public long getMaxInvocationTime() {
return (Long) this.resourceProperties.get(MAX_INVOCATION_TIME); return (Long) this.resourceProperties.get(MAX_INVOCATION_TIME);
} }
@ -77,6 +79,7 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp
super.setResourceProperty(MAX_INVOCATION_TIME, maxInvocationTime); super.setResourceProperty(MAX_INVOCATION_TIME, maxInvocationTime);
} }
@JsonIgnore
public long getMinInvocationTime() { public long getMinInvocationTime() {
return (Long) this.resourceProperties.get(MIN_INVOCATION_TIME); return (Long) this.resourceProperties.get(MIN_INVOCATION_TIME);
} }

View File

@ -12,6 +12,8 @@ import org.gcube.documentstore.records.implementation.RequiredField;
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty; import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong; import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
import com.fasterxml.jackson.annotation.JsonIgnore;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*/ */
@ -91,6 +93,7 @@ public abstract class AbstractServiceUsageRecord extends BasicUsageRecord {
} }
@JsonIgnore
public String getCallerHost() { public String getCallerHost() {
return (String) this.resourceProperties.get(CALLER_HOST); return (String) this.resourceProperties.get(CALLER_HOST);
} }
@ -99,6 +102,7 @@ public abstract class AbstractServiceUsageRecord extends BasicUsageRecord {
setResourceProperty(CALLER_HOST, callerHost); setResourceProperty(CALLER_HOST, callerHost);
} }
@JsonIgnore
public String getHost() { public String getHost() {
return (String) this.resourceProperties.get(HOST); return (String) this.resourceProperties.get(HOST);
} }
@ -107,6 +111,7 @@ public abstract class AbstractServiceUsageRecord extends BasicUsageRecord {
setResourceProperty(HOST, host); setResourceProperty(HOST, host);
} }
@JsonIgnore
public String getServiceClass() { public String getServiceClass() {
return (String) this.resourceProperties.get(SERVICE_CLASS); return (String) this.resourceProperties.get(SERVICE_CLASS);
} }
@ -115,6 +120,7 @@ public abstract class AbstractServiceUsageRecord extends BasicUsageRecord {
setResourceProperty(SERVICE_CLASS, serviceClass); setResourceProperty(SERVICE_CLASS, serviceClass);
} }
@JsonIgnore
public String getServiceName() { public String getServiceName() {
return (String) this.resourceProperties.get(SERVICE_NAME); return (String) this.resourceProperties.get(SERVICE_NAME);
} }
@ -123,6 +129,7 @@ public abstract class AbstractServiceUsageRecord extends BasicUsageRecord {
setResourceProperty(SERVICE_NAME, serviceName); setResourceProperty(SERVICE_NAME, serviceName);
} }
@JsonIgnore
public String getCalledMethod() { public String getCalledMethod() {
return (String) this.resourceProperties.get(CALLED_METHOD); return (String) this.resourceProperties.get(CALLED_METHOD);
} }
@ -131,6 +138,7 @@ public abstract class AbstractServiceUsageRecord extends BasicUsageRecord {
setResourceProperty(CALLED_METHOD, calledMethod); setResourceProperty(CALLED_METHOD, calledMethod);
} }
@JsonIgnore
public Long getDuration() { public Long getDuration() {
return (Long) this.resourceProperties.get(DURATION); return (Long) this.resourceProperties.get(DURATION);
} }
@ -139,6 +147,7 @@ public abstract class AbstractServiceUsageRecord extends BasicUsageRecord {
setResourceProperty(DURATION, duration); setResourceProperty(DURATION, duration);
} }
@JsonIgnore
public String getCallerQualifier() { public String getCallerQualifier() {
return (String) this.resourceProperties.get(CALLER_QUALIFIER); return (String) this.resourceProperties.get(CALLER_QUALIFIER);
} }

View File

@ -12,6 +12,7 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.documentstore.exception.InvalidValueException; import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions; import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
import org.gcube.documentstore.records.DSMapper;
import org.gcube.testutility.ScopedTest; import org.gcube.testutility.ScopedTest;
import org.gcube.testutility.TestUsageRecord; import org.gcube.testutility.TestUsageRecord;
import org.junit.Assert; import org.junit.Assert;
@ -19,6 +20,8 @@ import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
* *
@ -153,7 +156,7 @@ public class AggregatedServiceUsageRecordTest extends ScopedTest {
} }
@Test @Test
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions { public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions, JsonProcessingException {
SecurityTokenProvider.instance.reset(); SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset(); ScopeProvider.instance.reset();
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord(); ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
@ -204,8 +207,9 @@ public class AggregatedServiceUsageRecordTest extends ScopedTest {
} }
Assert.assertTrue(aggregated.getRecordType().compareTo(ServiceUsageRecord.class.getSimpleName())==0); Assert.assertTrue(aggregated.getRecordType().compareTo(ServiceUsageRecord.class.getSimpleName())==0);
Assert.assertTrue(aggregated.getOperationCount()==1001);
logger.debug("Resulting Aggregated ServiceUsageRecord: {}", aggregated); logger.debug("Resulting Aggregated ServiceUsageRecord: {}", DSMapper.marshal(aggregated));
} }
} }