Created fake accounting-lib
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/fake-accounting-lib@160562 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
729dfde0b7
commit
d27a5d28dc
|
@ -0,0 +1,13 @@
|
|||
package org.gcube.documentstore.exception;
|
||||
|
||||
public class InvalidValueException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2449589259703195853L;
|
||||
|
||||
public InvalidValueException() {
|
||||
super();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.documentstore.records;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Calendar;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public interface Record extends Comparable<Record>, Serializable {
|
||||
/**
|
||||
* @return a Set containing the keys of required fields
|
||||
* The returned Set MUST be a copy of the internal representation.
|
||||
* Any modification to the returned Set MUST not affect the object
|
||||
*/
|
||||
public Set<String> getRequiredFields();
|
||||
|
||||
/**
|
||||
* @return a Set containing the keys of computed fields
|
||||
* The returned Set MUST be a copy of the internal representation.
|
||||
* Any modification to the returned Set MUST not affect the object
|
||||
*/
|
||||
public Set<String> getComputedFields();
|
||||
|
||||
/**
|
||||
* @return Querable Keys as SortedSet
|
||||
* @throws Exception
|
||||
*/
|
||||
public SortedSet<String> getQuerableKeys() throws Exception;
|
||||
|
||||
/**
|
||||
* Return the {@link Record} Type
|
||||
* @return {@link Record} Type
|
||||
*/
|
||||
public String getRecordType();
|
||||
|
||||
|
||||
/**
|
||||
* Return the unique id for this {@link Record}
|
||||
* @return {@link Record} Unique ID
|
||||
*/
|
||||
public String getId();
|
||||
|
||||
/**
|
||||
* The ID SHOULD be automatically created by the implementation Class.
|
||||
* Set the ID only if you really know what you are going to do.
|
||||
* Set the unique id for this {@link Record}
|
||||
* @param id Unique ID
|
||||
* @throws InvalidValueException
|
||||
*/
|
||||
public void setId(String id) throws InvalidValueException;
|
||||
|
||||
/**
|
||||
* Return the instant when this {@link Record} was created.
|
||||
* @return the creation time for this {@link Record}
|
||||
*/
|
||||
public Calendar getCreationTime();
|
||||
|
||||
/**
|
||||
* The CreationTime is automatically created by the implementation Class.
|
||||
* Set the CreationTime only if you really know what you are going to do.
|
||||
* Set the instant when this {@link Record} was created.
|
||||
* @param creationTime Creation Time
|
||||
* @throws InvalidValueException
|
||||
*/
|
||||
public void setCreationTime(Calendar creationTime) throws InvalidValueException;
|
||||
|
||||
/**
|
||||
* Return all resource-specific properties. The returned Map is a copy of
|
||||
* the internal representation. Any modification to the returned Map MUST
|
||||
* not affect the object
|
||||
* @return a Map containing the properties
|
||||
*/
|
||||
public Map<String, Serializable> getResourceProperties();
|
||||
|
||||
/**
|
||||
* Set all resource-specific properties, replacing existing ones
|
||||
*/
|
||||
public void setResourceProperties(Map<String, ? extends Serializable> resourceSpecificProperties) throws InvalidValueException;
|
||||
|
||||
/**
|
||||
* Return the value of the given resource property.
|
||||
* @param key the key of the requested property
|
||||
* @return the value of the given resource property
|
||||
*/
|
||||
public Serializable getResourceProperty(String key);
|
||||
|
||||
/**
|
||||
* Set the value of the given resource property.
|
||||
* If the key has the value of one of the predefined property, the value
|
||||
* is validated.
|
||||
* @param key the key of the requested property
|
||||
* @param value the value of the given resource property
|
||||
*/
|
||||
public void setResourceProperty(String key, Serializable value) throws InvalidValueException;
|
||||
|
||||
/**
|
||||
* Remove a property from Record.
|
||||
* This API is intended for intern use only.
|
||||
* @param key the key of the requested property to remove
|
||||
*/
|
||||
public void removeResourceProperty(String key);
|
||||
|
||||
/**
|
||||
* Validate the Resource Record.
|
||||
* The validation check if all the Required Field are set and has valid
|
||||
* value.
|
||||
* @throws InvalidValueException
|
||||
*/
|
||||
public void validate() throws InvalidValueException;
|
||||
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.documentstore.records.implementation;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public abstract class AbstractRecord implements Record {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 8746066891880733502L;
|
||||
|
||||
@Override
|
||||
public SortedSet<String> getQuerableKeys() throws Exception {
|
||||
return new TreeSet<>();
|
||||
}
|
||||
|
||||
public AbstractRecord() {
|
||||
}
|
||||
|
||||
public AbstractRecord(Map<String,? extends Serializable> properties) throws InvalidValueException {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getRequiredFields() {
|
||||
return new HashSet<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getComputedFields() {
|
||||
return new HashSet<String>();
|
||||
}
|
||||
|
||||
public Set<String> getAggregatedFields() {
|
||||
return new HashSet<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getId() {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setId(String id) throws InvalidValueException {
|
||||
|
||||
}
|
||||
|
||||
public static Calendar timestampToCalendar(long millis) {
|
||||
return Calendar.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Calendar getCreationTime() {
|
||||
return Calendar.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setCreationTime(Calendar creationTime) throws InvalidValueException {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Map<String,Serializable> getResourceProperties() {
|
||||
return new HashMap<String,Serializable>();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setResourceProperties(Map<String,? extends Serializable> properties) throws InvalidValueException {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Serializable getResourceProperty(String key) {
|
||||
return "TEST";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeResourceProperty(String key) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setResourceProperty(String key, Serializable value) throws InvalidValueException {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void validate() throws InvalidValueException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{}";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(Record record) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue