[New] Added tx.auditFrom()

- this allows to quickly create a new Audit which uses the details from
the current TX. This TX can then be added to the auditTrail for
persisting
This commit is contained in:
Robert von Burg 2015-01-20 19:47:49 +01:00
parent b731be86e3
commit bacf17b1a7
2 changed files with 71 additions and 119 deletions

View File

@ -687,7 +687,8 @@ public abstract class AbstractTransaction implements StrolchTransaction {
} }
} }
private Audit auditFrom(AccessType accessType, String elementType, String id) { @Override
public Audit auditFrom(AccessType accessType, String elementType, String id) {
Audit audit = new Audit(); Audit audit = new Audit();
audit.setId(StrolchAgent.getUniqueIdLong()); audit.setId(StrolchAgent.getUniqueIdLong());

View File

@ -29,6 +29,7 @@ import li.strolch.model.Resource;
import li.strolch.model.ResourceVisitor; import li.strolch.model.ResourceVisitor;
import li.strolch.model.StrolchElement; import li.strolch.model.StrolchElement;
import li.strolch.model.StrolchRootElement; import li.strolch.model.StrolchRootElement;
import li.strolch.model.audit.AccessType;
import li.strolch.model.audit.Audit; import li.strolch.model.audit.Audit;
import li.strolch.model.audit.AuditQuery; import li.strolch.model.audit.AuditQuery;
import li.strolch.model.audit.AuditVisitor; import li.strolch.model.audit.AuditVisitor;
@ -77,14 +78,15 @@ public interface StrolchTransaction extends AutoCloseable {
public void addCommand(Command command); public void addCommand(Command command);
public Audit auditFrom(AccessType accessType, String elementType, String id);
public List<Order> doQuery(OrderQuery query); public List<Order> doQuery(OrderQuery query);
public <U> List<U> doQuery(OrderQuery query, OrderVisitor<U> orderVisitor); public <U> List<U> doQuery(OrderQuery query, OrderVisitor<U> orderVisitor);
public List<Resource> doQuery(ResourceQuery query); public List<Resource> doQuery(ResourceQuery query);
public <U> List<U> doQuery(ResourceQuery query, public <U> List<U> doQuery(ResourceQuery query, ResourceVisitor<U> resourceVisitor);
ResourceVisitor<U> resourceVisitor);
public List<Audit> doQuery(AuditQuery query); public List<Audit> doQuery(AuditQuery query);
@ -96,233 +98,182 @@ public interface StrolchTransaction extends AutoCloseable {
* </p> * </p>
* *
* <p> * <p>
* A Locator has the form * A Locator has the form <i>&lt;ObjectClassType&gt;/&lt;Type&gt;/&lt;Id&gt;</i> - this is the least amount of path
* <i>&lt;ObjectClassType&gt;/&lt;Type&gt;/&lt;Id&gt;</i> - this is the * elements to find an object. Thus to query a {@link Resource} of type "MyType" and the id "@1" use the following
* least amount of path elements to find an object. Thus to query a * path: <i>Resourcee/MyType/@1</i>
* {@link Resource} of type "MyType" and the id "@1" use the following path:
* <i>Resourcee/MyType/@1</i>
* </p> * </p>
* *
* <p> * <p>
* This method can also be used to find a deeper element, e.g. a specific * This method can also be used to find a deeper element, e.g. a specific {@link Parameter} on an
* {@link Parameter} on an {@link ParameterBag} on an {@link Order}. This * {@link ParameterBag} on an {@link Order}. This would be done as follows: <i>Order/MyType/@1/myParam</i>
* would be done as follows: <i>Order/MyType/@1/myParam</i>
* </p> * </p>
* *
* @param locator * @param locator
* the locator defining the path to the element which is to be * the locator defining the path to the element which is to be found
* found
* *
* @return the element described by the locator * @return the element described by the locator
* *
* @throws StrolchException * @throws StrolchException
* if the element could not be found * if the element could not be found
* @throws ClassCastException * @throws ClassCastException
* if the querying code is not asking for the correct instance. * if the querying code is not asking for the correct instance. Do not query a {@link Parameter} if the
* Do not query a {@link Parameter} if the variable to which the * variable to which the result is to be is stored is a {@link Resource}, etc.
* result is to be is stored is a {@link Resource}, etc.
*/ */
public <T extends StrolchElement> T findElement(Locator locator) public <T extends StrolchElement> T findElement(Locator locator) throws StrolchException, ClassCastException;
throws StrolchException, ClassCastException;
/** /**
* Returns the {@link Resource} with the given type and id, or null if it * Returns the {@link Resource} with the given type and id, or null if it does not exist
* does not exist
* *
* @param type * @param type
* the type of the {@link Resource} * the type of the {@link Resource}
* @param id * @param id
* the id of the {@link Resource} * the id of the {@link Resource}
* *
* @return the {@link Resource} with the given type and id, or null if it * @return the {@link Resource} with the given type and id, or null if it does not exist
* does not exist
*/ */
public Resource getResourceBy(String type, String id); public Resource getResourceBy(String type, String id);
/** /**
* Returns the {@link Resource} with the given type and id, or null if it * Returns the {@link Resource} with the given type and id, or null if it does not exist
* does not exist
* *
* @param type * @param type
* the type of the {@link Resource} * the type of the {@link Resource}
* @param id * @param id
* the id of the {@link Resource} * the id of the {@link Resource}
* @param assertExists * @param assertExists
* if true, and resource does not exist, then a * if true, and resource does not exist, then a {@link StrolchException} is thrown
* {@link StrolchException} is thrown
* *
* @return the {@link Resource} with the given type and id, or null if it * @return the {@link Resource} with the given type and id, or null if it does not exist
* does not exist
* *
* @throws StrolchException * @throws StrolchException
* if the resource does not exist, and assertExists is true * if the resource does not exist, and assertExists is true
*/ */
public Resource getResourceBy(String type, String id, boolean assertExists) public Resource getResourceBy(String type, String id, boolean assertExists) throws StrolchException;
throws StrolchException;
/** /**
* Returns the {@link Resource} which is referenced by the given * Returns the {@link Resource} which is referenced by the given {@link StringParameter}. A reference
* {@link StringParameter}. A reference {@link Parameter} must have its * {@link Parameter} must have its interpretation set to {@link StrolchConstants#INTERPRETATION_RESOURCE_REF} and
* interpretation set to * the UOM must be set to the resource's type and the value is the id of the resource
* {@link StrolchConstants#INTERPRETATION_RESOURCE_REF} and the UOM must be
* set to the resource's type and the value is the id of the resource
* *
* @param refP * @param refP
* the {@link StringParameter} which references a * the {@link StringParameter} which references a {@link Resource}
* {@link Resource}
* *
* @return the resource referenced by the parameter, or null if it does not * @return the resource referenced by the parameter, or null if it does not exist
* exist
* *
* @throws StrolchException * @throws StrolchException
* if the {@link StringParameter} is not a properly configured * if the {@link StringParameter} is not a properly configured as a reference parameter
* as a reference parameter
*/ */
public Resource getResourceBy(StringParameter refP) throws StrolchException; public Resource getResourceBy(StringParameter refP) throws StrolchException;
/** /**
* Returns the {@link Resource} which is referenced by the given * Returns the {@link Resource} which is referenced by the given {@link StringParameter}. A reference
* {@link StringParameter}. A reference {@link Parameter} must have its * {@link Parameter} must have its interpretation set to {@link StrolchConstants#INTERPRETATION_RESOURCE_REF} and
* interpretation set to * the UOM must be set to the resource's type and the value is the id of the resource
* {@link StrolchConstants#INTERPRETATION_RESOURCE_REF} and the UOM must be
* set to the resource's type and the value is the id of the resource
* *
* @param refP * @param refP
* the {@link StringParameter} which references a * the {@link StringParameter} which references a {@link Resource}
* {@link Resource}
* @param assertExists * @param assertExists
* if true, and resource does not exist, then a * if true, and resource does not exist, then a {@link StrolchException} is thrown
* {@link StrolchException} is thrown
* *
* @return the resource referenced by the parameter, or null if it does not * @return the resource referenced by the parameter, or null if it does not exist
* exist
* *
* @throws StrolchException * @throws StrolchException
* if the {@link StringParameter} is not a properly configured * if the {@link StringParameter} is not a properly configured as a reference parameter, or if the
* as a reference parameter, or if the resource does not exist, * resource does not exist, and assertExists is true
* and assertExists is true
*/ */
public Resource getResourceBy(StringParameter refP, boolean assertExists) public Resource getResourceBy(StringParameter refP, boolean assertExists) throws StrolchException;
throws StrolchException;
/** /**
* Returns all {@link Resource Resources} which are referenced by the given * Returns all {@link Resource Resources} which are referenced by the given {@link StringListParameter}. A reference
* {@link StringListParameter}. A reference {@link Parameter} must have its * {@link Parameter} must have its interpretation set to {@link StrolchConstants#INTERPRETATION_RESOURCE_REF} and
* interpretation set to * the UOM must be set to the resource's type and the value is the id of the resource
* {@link StrolchConstants#INTERPRETATION_RESOURCE_REF} and the UOM must be
* set to the resource's type and the value is the id of the resource
* *
* @param refP * @param refP
* the {@link StringListParameter} which references a list of * the {@link StringListParameter} which references a list of {@link Resource Resources}
* {@link Resource Resources}
* *
* @return the resources referenced by the parameter, or the empty list if * @return the resources referenced by the parameter, or the empty list if they do not exist. <b>Note:</b> Any
* they do not exist. <b>Note:</b> Any missing resources are not * missing resources are not returned!
* returned!
* *
* @throws StrolchException * @throws StrolchException
* if the {@link StringListParameter} is not a properly * if the {@link StringListParameter} is not a properly configured as a reference parameter
* configured as a reference parameter
*/ */
public List<Resource> getResourcesBy(StringListParameter refP) public List<Resource> getResourcesBy(StringListParameter refP) throws StrolchException;
throws StrolchException;
/** /**
* Returns the {@link Order} with the given type and id, or null if it does * Returns the {@link Order} with the given type and id, or null if it does not exist
* not exist
* *
* @param type * @param type
* the type of the {@link Order} * the type of the {@link Order}
* @param id * @param id
* the id of the {@link Order} * the id of the {@link Order}
* *
* @return the {@link Order} with the given type and id, or null if it does * @return the {@link Order} with the given type and id, or null if it does not exist
* not exist
*/ */
public Order getOrderBy(String type, String id); public Order getOrderBy(String type, String id);
/** /**
* Returns the {@link Order} with the given type and id, or null if it does * Returns the {@link Order} with the given type and id, or null if it does not exist
* not exist
* *
* @param type * @param type
* the type of the {@link Order} * the type of the {@link Order}
* @param id * @param id
* the id of the {@link Order} * the id of the {@link Order}
* @param assertExists * @param assertExists
* if true, and order does not exist, then a * if true, and order does not exist, then a {@link StrolchException} is thrown
* {@link StrolchException} is thrown
* *
* @return the {@link Order} with the given type and id, or null if it does * @return the {@link Order} with the given type and id, or null if it does not exist
* not exist
* *
* @throws StrolchException * @throws StrolchException
* if the order does not exist, and assertExists is true * if the order does not exist, and assertExists is true
*/ */
public Order getOrderBy(String type, String id, boolean assertExists) public Order getOrderBy(String type, String id, boolean assertExists) throws StrolchException;
throws StrolchException;
/** /**
* Returns the {@link Order} which is referenced by the given * Returns the {@link Order} which is referenced by the given {@link StringParameter}. A reference {@link Parameter}
* {@link StringParameter}. A reference {@link Parameter} must have its * must have its interpretation set to {@link StrolchConstants#INTERPRETATION_ORDER_REF} and the UOM must be set to
* interpretation set to {@link StrolchConstants#INTERPRETATION_ORDER_REF} * the order's type and the value is the id of the order
* and the UOM must be set to the order's type and the value is the id of
* the order
* *
* @param refP * @param refP
* the {@link StringParameter} which references an {@link Order} * the {@link StringParameter} which references an {@link Order}
* *
* @return the order referenced by the parameter, or null if it does not * @return the order referenced by the parameter, or null if it does not exist
* exist
* *
* @throws StrolchException * @throws StrolchException
* if the {@link StringParameter} is not a properly configured * if the {@link StringParameter} is not a properly configured as a reference parameter
* as a reference parameter
*/ */
public Order getOrderBy(StringParameter refP) throws StrolchException; public Order getOrderBy(StringParameter refP) throws StrolchException;
/** /**
* Returns the {@link Order} which is referenced by the given * Returns the {@link Order} which is referenced by the given {@link StringParameter}. A reference {@link Parameter}
* {@link StringParameter}. A reference {@link Parameter} must have its * must have its interpretation set to {@link StrolchConstants#INTERPRETATION_ORDER_REF} and the UOM must be set to
* interpretation set to {@link StrolchConstants#INTERPRETATION_ORDER_REF} * the order's type and the value is the id of the order
* and the UOM must be set to the order's type and the value is the id of
* the order
* *
* @param refP * @param refP
* the {@link StringParameter} which references an {@link Order} * the {@link StringParameter} which references an {@link Order}
* @param assertExists * @param assertExists
* if true, and order does not exist, then a * if true, and order does not exist, then a {@link StrolchException} is thrown
* {@link StrolchException} is thrown
* *
* @return the order referenced by the parameter, or null if it does not * @return the order referenced by the parameter, or null if it does not exist
* exist
* *
* @throws StrolchException * @throws StrolchException
* if the {@link StringParameter} is not a properly configured * if the {@link StringParameter} is not a properly configured as a reference parameter, or if the order
* as a reference parameter, or if the order does not exist, and * does not exist, and assertExists is true
* assertExists is true
*/ */
public Order getOrderBy(StringParameter refP, boolean assertExists) public Order getOrderBy(StringParameter refP, boolean assertExists) throws StrolchException;
throws StrolchException;
/** /**
* Returns all {@link Order Orders} which are referenced by the given * Returns all {@link Order Orders} which are referenced by the given {@link StringListParameter}. A reference
* {@link StringListParameter}. A reference {@link Parameter} must have its * {@link Parameter} must have its interpretation set to {@link StrolchConstants#INTERPRETATION_ORDER_REF} and the
* interpretation set to {@link StrolchConstants#INTERPRETATION_ORDER_REF} * UOM must be set to the order's type and the value is the id of the order
* and the UOM must be set to the order's type and the value is the id of
* the order
* *
* @param refP * @param refP
* the {@link StringListParameter} which references a list of * the {@link StringListParameter} which references a list of {@link Order Orders}
* {@link Order Orders}
* *
* @return the orders referenced by the parameter, or the empty list if they * @return the orders referenced by the parameter, or the empty list if they do not exist. <b>Note:</b> Any missing
* do not exist. <b>Note:</b> Any missing orders are not returned! * orders are not returned!
* *
* @throws StrolchException * @throws StrolchException
* if the {@link StringListParameter} is not a properly * if the {@link StringListParameter} is not a properly configured as a reference parameter
* configured as a reference parameter
*/ */
public List<Order> getOrdersBy(StringListParameter refP) public List<Order> getOrdersBy(StringListParameter refP) throws StrolchException;
throws StrolchException;
} }