diff --git a/src/main/java/org/gcube/documentstore/records/AggregatedRecord.java b/src/main/java/org/gcube/documentstore/records/AggregatedRecord.java
index dc9b1d7..7b8beec 100644
--- a/src/main/java/org/gcube/documentstore/records/AggregatedRecord.java
+++ b/src/main/java/org/gcube/documentstore/records/AggregatedRecord.java
@@ -10,6 +10,11 @@ import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
import org.gcube.documentstore.records.implementation.AggregatedField;
import org.gcube.documentstore.records.implementation.RequiredField;
+import org.gcube.documentstore.records.implementation.validations.annotations.ValidBoolean;
+import org.gcube.documentstore.records.implementation.validations.annotations.ValidInteger;
+import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
/**
@@ -20,13 +25,13 @@ public interface AggregatedRecord, R extends Rec
/**
* KEY : Indicate that this {@link Record} is an aggregation
*/
- @RequiredField @AggregatedField
+ @RequiredField @AggregatedField @ValidBoolean
public static final String AGGREGATED = "aggregated";
/**
* KEY : Indicate The Number of {@link AggregatedRecord}
*/
- @RequiredField @AggregatedField
+ @RequiredField @AggregatedField @ValidInteger
public static final String OPERATION_COUNT = "operationCount";
/**
@@ -34,7 +39,7 @@ public interface AggregatedRecord, R extends Rec
* {@link AggregatedRecord}. The value will be recorded in UTC milliseconds
* from the epoch.
*/
- @RequiredField @AggregatedField
+ @RequiredField @AggregatedField @ValidLong
public static final String START_TIME = "startTime";
/**
@@ -42,7 +47,7 @@ public interface AggregatedRecord, R extends Rec
* {@link AggregatedRecord}. The value will be recorded in UTC milliseconds
* from the epoch.
*/
- @RequiredField @AggregatedField
+ @RequiredField @AggregatedField @ValidLong
public static final String END_TIME = "endTime";
/**
@@ -50,28 +55,36 @@ public interface AggregatedRecord, R extends Rec
* The returned Set MUST be a copy of the internal representation.
* Any modification to the returned Set MUST not affect the object
*/
+ @JsonIgnore
public Set getAggregatedFields();
public int getOperationCount();
public void setOperationCount(int operationCount) throws InvalidValueException;
-
+
+ @JsonIgnore
public Calendar getStartTime();
+ @JsonIgnore
public void setStartTime(Calendar startTime) throws InvalidValueException;
+ @JsonIgnore
public Calendar getEndTime();
+ @JsonIgnore
public void setEndTime(Calendar endTime) throws InvalidValueException;
public A aggregate(A record) throws NotAggregatableRecordsExceptions;
public A aggregate(R record) throws NotAggregatableRecordsExceptions;
+ @JsonIgnore
public boolean isAggregable(A record) throws NotAggregatableRecordsExceptions;
+ @JsonIgnore
public boolean isAggregable(R record) throws NotAggregatableRecordsExceptions;
+ @JsonIgnore
public Class getAggregable();
}
diff --git a/src/main/java/org/gcube/documentstore/records/Record.java b/src/main/java/org/gcube/documentstore/records/Record.java
index 864dad1..db7cc56 100644
--- a/src/main/java/org/gcube/documentstore/records/Record.java
+++ b/src/main/java/org/gcube/documentstore/records/Record.java
@@ -69,7 +69,6 @@ public interface Record extends Comparable, Serializable {
* Return the {@link Record} Type
* @return {@link Record} Type
*/
- @JsonIgnore
public String getRecordType();
@@ -77,7 +76,6 @@ public interface Record extends Comparable, Serializable {
* Return the unique id for this {@link Record}
* @return {@link Record} Unique ID
*/
- @JsonIgnore
public String getId();
/**
@@ -87,7 +85,6 @@ public interface Record extends Comparable, Serializable {
* @param id Unique ID
* @throws InvalidValueException
*/
- @JsonIgnore
public void setId(String id) throws InvalidValueException;
/**
@@ -119,6 +116,7 @@ public interface Record extends Comparable, Serializable {
/**
* Set all resource-specific properties, replacing existing ones
*/
+ @JsonIgnore
public void setResourceProperties(Map resourceSpecificProperties) throws InvalidValueException;
/**
@@ -126,6 +124,7 @@ public interface Record extends Comparable, Serializable {
* @param key the key of the requested property
* @return the value of the given resource property
*/
+ @JsonIgnore
public Serializable getResourceProperty(String key);
/**
@@ -143,6 +142,7 @@ public interface Record extends Comparable, Serializable {
* This API is intended for intern use only.
* @param key the key of the requested property to remove
*/
+ @JsonIgnore
public void removeResourceProperty(String key);
/**
diff --git a/src/main/java/org/gcube/documentstore/records/implementation/AbstractRecord.java b/src/main/java/org/gcube/documentstore/records/implementation/AbstractRecord.java
index e6005de..87ef68f 100644
--- a/src/main/java/org/gcube/documentstore/records/implementation/AbstractRecord.java
+++ b/src/main/java/org/gcube/documentstore/records/implementation/AbstractRecord.java
@@ -21,7 +21,6 @@ import java.util.UUID;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.AggregatedRecord;
-import org.gcube.documentstore.records.CustomMapDeserializer;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
@@ -29,11 +28,8 @@ import org.gcube.documentstore.records.implementation.validations.validators.Val
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.annotation.JsonAnyGetter;
-import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+
/**
* @author Luca Frosini (ISTI - CNR)
@@ -54,19 +50,12 @@ public abstract class AbstractRecord implements Record {
protected static final String CREATION_TIME = Record.CREATION_TIME;
/** resource-specific properties */
-
- @JsonDeserialize(using = CustomMapDeserializer.class)
- @JsonIgnoreProperties(ignoreUnknown = true)
protected Map resourceProperties;
-
protected Map> validation;
protected Map> computation;
- @JsonIgnore
protected Set requiredFields;
- @JsonIgnore
protected Set computedFields;
- @JsonIgnore
protected Set aggregatedFields;
protected static Set getAllFields(Class> type) {
@@ -188,7 +177,6 @@ public abstract class AbstractRecord implements Record {
}
- @JsonIgnoreProperties(ignoreUnknown = true)
public AbstractRecord(){
init();
this.resourceProperties.put(ID, UUID.randomUUID().toString());
@@ -197,7 +185,6 @@ public abstract class AbstractRecord implements Record {
}
- @JsonIgnoreProperties(ignoreUnknown = true)
public AbstractRecord(Map properties) throws InvalidValueException {
init();
setResourceProperties(properties);
@@ -211,6 +198,7 @@ public abstract class AbstractRecord implements Record {
* {@inheritDoc}
*/
@Override
+ @JsonIgnore
public Set getRequiredFields() {
return new HashSet(requiredFields);
}
@@ -219,6 +207,7 @@ public abstract class AbstractRecord implements Record {
* {@inheritDoc}
*/
@Override
+ @JsonIgnore
public Set getComputedFields() {
return new HashSet(computedFields);
}
@@ -226,6 +215,7 @@ public abstract class AbstractRecord implements Record {
/**
* {@inheritDoc}
*/
+ @JsonIgnore
public Set getAggregatedFields() {
return new HashSet(aggregatedFields);
}
@@ -277,8 +267,6 @@ public abstract class AbstractRecord implements Record {
/**
* {@inheritDoc}
*/
- //insert here for discovery auto
- //@JsonAnyGetter
@Override
public Map getResourceProperties() {
return new HashMap(this.resourceProperties);
@@ -287,9 +275,6 @@ public abstract class AbstractRecord implements Record {
/**
* {@inheritDoc}
*/
-
-
- @JsonAnySetter
@Override
public void setResourceProperties(Map properties) throws InvalidValueException {
Map validated = validateProperties(properties);
@@ -299,7 +284,6 @@ public abstract class AbstractRecord implements Record {
/**
* {@inheritDoc}
*/
- @JsonAnyGetter
@Override
public Serializable getResourceProperty(String key) {
return this.resourceProperties.get(key);
@@ -313,7 +297,6 @@ public abstract class AbstractRecord implements Record {
/**
* {@inheritDoc}
*/
- @JsonAnySetter
@Override
public void setResourceProperty(String key, Serializable value) throws InvalidValueException {
Serializable checkedValue = validateField(key, value);
@@ -339,6 +322,23 @@ public abstract class AbstractRecord implements Record {
setResourceProperty(AggregatedRecord.END_TIME, endTime.getTimeInMillis());
}
+ /**
+ * Return the right end of the time interval covered by this Record
+ * @return End Time
+ */
+ protected long getEndTimeInMillis() {
+ return (Long) this.resourceProperties.get(AggregatedRecord.END_TIME);
+ }
+
+ /**
+ * Return the right end of the time interval covered by this Record
+ * @return End Time
+ */
+ protected Calendar getEndTimeAsCalendar() {
+ long millis = getEndTimeInMillis();
+ return timestampToCalendar(millis);
+ }
+
protected int getOperationCount() {
return (Integer) this.resourceProperties.get(AggregatedRecord.OPERATION_COUNT);
}
@@ -373,42 +373,25 @@ public abstract class AbstractRecord implements Record {
setResourceProperty(AggregatedRecord.START_TIME, startTime.getTimeInMillis());
}
- /**
- * Return the right end of the time interval covered by this Record
- * @return End Time
- */
- protected long getEndTimeInMillis() {
- return (Long) this.resourceProperties.get(AggregatedRecord.END_TIME);
- }
-
- //Introduce for to serialize Java Object
/**
* Set the boolean aggregate by this Record
* @param Boolean aggregate
* @throws InvalidValueException
*/
- protected void setAggregate(Boolean aggregate) throws InvalidValueException {
+ protected void setAggregated(Boolean aggregate) throws InvalidValueException {
setResourceProperty(AggregatedRecord.AGGREGATED, aggregate);
}
/**
* Return the boolean aggregate by this Record
* @return Boolean Aggregate
*/
- protected Boolean getAggregate() {
- return (Boolean) this.resourceProperties.get(AggregatedRecord.AGGREGATED);
+ protected Boolean isAggregated() {
+ Boolean bool = (Boolean) this.resourceProperties.get(AggregatedRecord.AGGREGATED);
+ if(bool==null){
+ return false;
+ }
+ return bool;
}
- //End Introduce for to serialize Java Object
-
-
- /**
- * Return the right end of the time interval covered by this Record
- * @return End Time
- */
- protected Calendar getEndTimeAsCalendar() {
- long millis = getEndTimeInMillis();
- return timestampToCalendar(millis);
- }
-
protected Serializable validateField(String key, Serializable value) throws InvalidValueException {
if(key == null){
@@ -458,7 +441,6 @@ public abstract class AbstractRecord implements Record {
}
}
-
protected Map validateProperties(Map properties) throws InvalidValueException{
Map validated = new HashMap();
for(String key : properties.keySet()){
diff --git a/src/main/java/org/gcube/documentstore/records/implementation/validations/validators/ValidIntegerValidator.java b/src/main/java/org/gcube/documentstore/records/implementation/validations/validators/ValidIntegerValidator.java
index 6b97b2a..1c16c3d 100644
--- a/src/main/java/org/gcube/documentstore/records/implementation/validations/validators/ValidIntegerValidator.java
+++ b/src/main/java/org/gcube/documentstore/records/implementation/validations/validators/ValidIntegerValidator.java
@@ -18,13 +18,24 @@ public class ValidIntegerValidator implements FieldAction {
*/
@Override
public Serializable validate(String key, Serializable value, Record record) throws InvalidValueException {
+
if(value instanceof Integer){
return value;
}
- Integer integerObj = Integer.valueOf((String) value);
- if(integerObj!=null){
- return integerObj;
- }
+
+ try {
+ Integer integerObj = Integer.valueOf((String) value);
+ if(integerObj!=null){
+ return integerObj;
+ }
+ }catch (Exception e) {}
+
+ try {
+ Double doubleObj = Double.valueOf((String) value);
+ if(doubleObj!=null){
+ return doubleObj.intValue();
+ }
+ }catch (Exception e) {}
throw new InvalidValueException(ERROR);
}
diff --git a/src/main/java/org/gcube/documentstore/records/implementation/validations/validators/ValidLongValidator.java b/src/main/java/org/gcube/documentstore/records/implementation/validations/validators/ValidLongValidator.java
index 09a3b62..1e453c6 100644
--- a/src/main/java/org/gcube/documentstore/records/implementation/validations/validators/ValidLongValidator.java
+++ b/src/main/java/org/gcube/documentstore/records/implementation/validations/validators/ValidLongValidator.java
@@ -21,14 +21,21 @@ public class ValidLongValidator implements FieldAction {
if(value instanceof Long){
return value;
}
+
try {
Long longObj = Long.valueOf((String) value);
if(longObj!=null){
- return longObj;
+ return longObj.longValue();
}
- }catch (Exception e) {
- throw new InvalidValueException(ERROR, e);
- }
+ }catch (Exception e) {}
+
+ try {
+ Double doubleObj = Double.valueOf((String) value);
+ if(doubleObj!=null){
+ return doubleObj.longValue();
+ }
+ }catch (Exception e) {}
+
throw new InvalidValueException(ERROR);
}