Search in sources :

Example 11 with C2KLocalObject

use of org.cristalise.kernel.entity.C2KLocalObject in project kernel by cristal-ise.

the class AddC2KObject method runActivityLogic.

// requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, PersistencyException {
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "AddC2KObject: agent:" + " item:" + item + " params:" + Arrays.toString(params));
    if (params.length != 1)
        throw new InvalidDataException("AddC2KObject: Invalid parameters " + Arrays.toString(params));
    try {
        C2KLocalObject obj = (C2KLocalObject) Gateway.getMarshaller().unmarshall(params[0]);
        Gateway.getStorage().put(item, obj, locker);
    } catch (Exception e) {
        throw new InvalidDataException("AddC2KObject: Could not unmarshall new object: " + params[0]);
    }
    return requestData;
}
Also used : C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Example 12 with C2KLocalObject

use of org.cristalise.kernel.entity.C2KLocalObject in project kernel by cristal-ise.

the class AddMemberToCollection method runActivityLogic.

/**
 * <pre>
 * Generates a new slot in a Dependency for the given item
 *
 * Params:
 * 0 - collection name
 * 1 - target entity key
 * 2 - slot properties
 * </pre>
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectAlreadyExistsException, PersistencyException, ObjectNotFoundException, InvalidCollectionModification {
    String collName;
    ItemPath newChild;
    Dependency dep;
    CastorHashMap props = null;
    // extract parameters
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "AddMemberToCollection: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    try {
        collName = params[0];
        try {
            newChild = new ItemPath(params[1]);
        } catch (InvalidItemPathException e) {
            newChild = new DomainPath(params[1]).getItemPath();
        }
        if (params.length > 2) {
            Logger.msg(5, "AddMemberToCollection: Unmarshalling Properties:" + params[2]);
            props = (CastorHashMap) Gateway.getMarshaller().unmarshall(params[2]);
        }
    } catch (Exception e) {
        Logger.error(e);
        throw new InvalidDataException("AddMemberToCollection: Invalid parameters " + Arrays.toString(params));
    }
    // load collection
    C2KLocalObject collObj = Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
    if (!(collObj instanceof Dependency))
        throw new InvalidDataException("AddMemberToCollection operates on Dependency only.");
    dep = (Dependency) collObj;
    // find member and assign entity
    if (props == null)
        dep.addMember(newChild);
    else
        dep.addMember(newChild, props, dep.getClassProps());
    Gateway.getStorage().put(item, dep, locker);
    return requestData;
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) CastorHashMap(org.cristalise.kernel.utils.CastorHashMap) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Dependency(org.cristalise.kernel.collection.Dependency) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 13 with C2KLocalObject

use of org.cristalise.kernel.entity.C2KLocalObject in project kernel by cristal-ise.

the class AssignItemToSlot method runActivityLogic.

/**
 * Params: 0 - collection name 1 - slot number 2 - target entity key
 *
 * @throws ObjectNotFoundException
 * @throws PersistencyException
 * @throws ObjectCannotBeUpdated
 * @throws InvalidCollectionModification
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectCannotBeUpdated, InvalidCollectionModification {
    String collName;
    int slotNo;
    ItemPath childItem;
    Aggregation agg;
    // extract parameters
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "AssignItemToSlot: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    try {
        collName = params[0];
        slotNo = Integer.parseInt(params[1]);
        try {
            childItem = new ItemPath(params[2]);
        } catch (InvalidItemPathException e) {
            childItem = new DomainPath(params[2]).getItemPath();
        }
    } catch (Exception e) {
        Logger.error(e);
        throw new InvalidDataException("AssignItemToSlot: Invalid parameters " + Arrays.toString(params));
    }
    // load collection
    C2KLocalObject collObj;
    try {
        collObj = Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
    } catch (PersistencyException ex) {
        Logger.error(ex);
        throw new PersistencyException("AssignItemToSlot: Error loading collection '\"+collName+\"': " + ex.getMessage());
    }
    if (!(collObj instanceof Aggregation))
        throw new InvalidDataException("AssignItemToSlot: AssignItemToSlot operates on Aggregation collections only.");
    agg = (Aggregation) collObj;
    // find member and assign entity
    boolean stored = false;
    for (AggregationMember member : agg.getMembers().list) {
        if (member.getID() == slotNo) {
            if (member.getItemPath() != null)
                throw new ObjectCannotBeUpdated("AssignItemToSlot: Member slot " + slotNo + " not empty");
            member.assignItem(childItem);
            stored = true;
            break;
        }
    }
    if (!stored) {
        throw new ObjectNotFoundException("AssignItemToSlot: Member slot " + slotNo + " not found.");
    }
    try {
        Gateway.getStorage().put(item, agg, locker);
    } catch (PersistencyException e) {
        throw new PersistencyException("AssignItemToSlot: Error saving collection '" + collName + "': " + e.getMessage());
    }
    return requestData;
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Aggregation(org.cristalise.kernel.collection.Aggregation) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) AggregationMember(org.cristalise.kernel.collection.AggregationMember) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 14 with C2KLocalObject

use of org.cristalise.kernel.entity.C2KLocalObject in project kernel by cristal-ise.

the class MemoryOnlyClusterStorage method dumpContents.

public void dumpContents(ItemPath thisItem) {
    synchronized (memoryCache) {
        Logger.msg(0, "Cached Objects of Entity " + thisItem);
        Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(thisItem);
        if (sysKeyMemCache == null) {
            Logger.msg(0, "No cache found");
            return;
        }
        try {
            synchronized (sysKeyMemCache) {
                for (Object name : sysKeyMemCache.keySet()) {
                    String path = (String) name;
                    try {
                        Logger.msg(0, "    Path " + path + ": " + sysKeyMemCache.get(path).getClass().getName());
                    } catch (NullPointerException e) {
                        Logger.msg(0, "    Path " + path + ": reaped");
                    }
                }
            }
        } catch (ConcurrentModificationException ex) {
            Logger.msg(0, "Cache modified - aborting");
        }
    }
    Logger.msg(0, "Total number of cached entities: " + memoryCache.size());
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject)

Example 15 with C2KLocalObject

use of org.cristalise.kernel.entity.C2KLocalObject in project kernel by cristal-ise.

the class ItemProxy method queryData.

/**
 * Query data of the Item located by the ClusterStorage path
 *
 * @param path the ClusterStorage path
 * @return the data in XML form
 * @throws ObjectNotFoundException path was not correct
 */
public String queryData(String path) throws ObjectNotFoundException {
    try {
        Logger.msg(7, "ItemProxy.queryData() - " + mItemPath + "/" + path);
        if (path.endsWith("all")) {
            Logger.msg(7, "ItemProxy.queryData() - listing contents");
            String[] result = Gateway.getStorage().getClusterContents(mItemPath, path.substring(0, path.length() - 3));
            StringBuffer retString = new StringBuffer();
            for (int i = 0; i < result.length; i++) {
                retString.append(result[i]);
                if (i < result.length - 1)
                    retString.append(",");
            }
            Logger.msg(7, "ItemProxy.queryData() - " + retString.toString());
            return retString.toString();
        } else {
            C2KLocalObject target = Gateway.getStorage().get(mItemPath, path, null);
            return Gateway.getMarshaller().marshall(target);
        }
    } catch (ObjectNotFoundException e) {
        throw e;
    } catch (Exception e) {
        Logger.error(e);
        return "<ERROR>" + e.getMessage() + "</ERROR>";
    }
}
Also used : C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) MappingException(org.exolab.castor.mapping.MappingException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ValidationException(org.exolab.castor.xml.ValidationException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) MarshalException(org.exolab.castor.xml.MarshalException) InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) IOException(java.io.IOException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Aggregations

C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)20 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)7 PersistencyException (org.cristalise.kernel.common.PersistencyException)6 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)5 DomainPath (org.cristalise.kernel.lookup.DomainPath)4 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)4 ItemPath (org.cristalise.kernel.lookup.ItemPath)4 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)3 ConcurrentModificationException (java.util.ConcurrentModificationException)2 Aggregation (org.cristalise.kernel.collection.Aggregation)2 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)2 Job (org.cristalise.kernel.entity.agent.Job)2 CastorHashMap (org.cristalise.kernel.utils.CastorHashMap)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 AggregationMember (org.cristalise.kernel.collection.AggregationMember)1 Collection (org.cristalise.kernel.collection.Collection)1 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)1