use of org.cristalise.kernel.lookup.ItemPath in project kernel by cristal-ise.
the class AddNewSlot method runActivityLogic.
/**
* Creates a new slot in the given aggregation, that holds instances of the given item description
*
* Params:
* <ol>
* <li>Collection name</li>
* <li>Item Description key (optional)</li>
* <li>Item Description version (optional)</li>
* </ol>
*
* @throws InvalidDataException
* Then the parameters were incorrect
* @throws PersistencyException
* There was a problem loading or saving the collection from persistency
* @throws ObjectNotFoundException
* A required object, such as the collection or a PropertyDescription outcome, wasn't found
*/
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, PersistencyException, ObjectNotFoundException {
String collName;
ItemPath descKey = null;
String descVer = "last";
// extract parameters
String[] params = getDataList(requestData);
if (Logger.doLog(3))
Logger.msg(3, "AddNewSlot: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
// resolve desc item path and version
try {
collName = params[0];
if (params.length > 1 && params[1].length() > 0) {
try {
descKey = new ItemPath(params[1]);
} catch (InvalidItemPathException e) {
descKey = new DomainPath(params[1]).getItemPath();
}
}
if (params.length > 2 && params[2].length() > 0)
descVer = params[2];
} catch (Exception e) {
throw new InvalidDataException("AddNewSlot: Invalid parameters " + Arrays.toString(params));
}
// load collection
C2KLocalObject collObj = Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
if (!(collObj instanceof Aggregation))
throw new InvalidDataException("AddNewSlot operates on Aggregation only.");
Aggregation agg = (Aggregation) collObj;
// get props
CastorHashMap props = new CastorHashMap();
StringBuffer classProps = new StringBuffer();
if (descKey != null) {
PropertyDescriptionList propList;
propList = PropertyUtility.getPropertyDescriptionOutcome(descKey, descVer, locker);
for (PropertyDescription pd : propList.list) {
props.put(pd.getName(), pd.getDefaultValue());
if (pd.getIsClassIdentifier())
classProps.append((classProps.length() > 0 ? "," : "")).append(pd.getName());
}
}
agg.addSlot(props, classProps.toString());
Gateway.getStorage().put(item, agg, locker);
return requestData;
}
use of org.cristalise.kernel.lookup.ItemPath in project kernel by cristal-ise.
the class RemoveSlotFromCollection method runActivityLogic.
/**
* Params: 0 - collection name 1 - slot number OR if -1: 2 - target entity key
*
* @throws ObjectNotFoundException
* @throws PersistencyException
*/
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, PersistencyException {
String collName;
int slotNo = -1;
ItemPath currentChild = null;
Collection<? extends CollectionMember> coll;
// extract parameters
String[] params = getDataList(requestData);
if (Logger.doLog(3))
Logger.msg(3, "RemoveSlotFromCollection: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
try {
collName = params[0];
if (params.length > 1 && params[1].length() > 0)
slotNo = Integer.parseInt(params[1]);
if (params.length > 2 && params[2].length() > 0) {
try {
currentChild = new ItemPath(params[2]);
} catch (InvalidItemPathException e) {
currentChild = new DomainPath(params[2]).getItemPath();
}
}
} catch (Exception e) {
throw new InvalidDataException("RemoveSlotFromCollection: Invalid parameters " + Arrays.toString(params));
}
if (slotNo == -1 && currentChild == null)
throw new InvalidDataException("RemoveSlotFromCollection: Must give either slot number or item UUID");
// load collection
try {
coll = (Collection<? extends CollectionMember>) Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
} catch (PersistencyException ex) {
Logger.error(ex);
throw new PersistencyException("RemoveSlotFromCollection: Error loading collection '\"+collName+\"': " + ex.getMessage());
}
// check the slot is there if it's given by id
CollectionMember slot = null;
if (slotNo > -1) {
slot = coll.getMember(slotNo);
}
// if both parameters are supplied, check the given item is actually in that slot
if (slot != null && currentChild != null && !slot.getItemPath().equals(currentChild)) {
throw new ObjectNotFoundException("RemoveSlotFromCollection: Item " + currentChild + " was not in slot " + slotNo);
}
if (slotNo == -1) {
// find slot from entity key
for (CollectionMember member : coll.getMembers().list) {
if (member.getItemPath().equals(currentChild)) {
slotNo = member.getID();
break;
}
}
}
if (slotNo == -1) {
throw new ObjectNotFoundException("Could not find " + currentChild + " in collection " + coll.getName());
}
// Remove the slot
coll.removeMember(slotNo);
// Store the collection
try {
Gateway.getStorage().put(item, coll, locker);
} catch (PersistencyException e) {
Logger.error(e);
throw new PersistencyException("Error storing collection");
}
return requestData;
}
use of org.cristalise.kernel.lookup.ItemPath in project kernel by cristal-ise.
the class LookupPathClusterStorageTest method storeItemPath.
@Test
public void storeItemPath() throws Exception {
ItemPath item = new ItemPath(UUID.randomUUID(), ior);
inMemoryCluster.put(storingItem, item);
ItemPath itemPrime = (ItemPath) inMemoryCluster.get(storingItem, PATH + "/Item");
assertNotNull(itemPrime);
assertEquals(item.getUUID(), itemPrime.getUUID());
assertEquals(item.getIORString(), itemPrime.getIORString());
}
use of org.cristalise.kernel.lookup.ItemPath in project kernel by cristal-ise.
the class XMLClusterStorageTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
Logger.addLogStream(System.out, 8);
Properties props = FileStringUtility.loadConfigFile(MainTest.class.getResource("/server.conf").getPath());
Gateway.init(props);
itemPath = new ItemPath("fcecd4ad-40eb-421c-a648-edc1d74f339b");
}
use of org.cristalise.kernel.lookup.ItemPath in project kernel by cristal-ise.
the class DescriptionObjectCache method findItem.
public ItemPath findItem(String name) throws ObjectNotFoundException, InvalidDataException {
if (Gateway.getLookup() == null)
throw new ObjectNotFoundException("Cannot find Items without a Lookup");
// first check for a UUID name
try {
ItemPath resItem = new ItemPath(name);
if (resItem.exists())
return resItem;
} catch (InvalidItemPathException ex) {
}
// then check for a direct path
DomainPath directPath = new DomainPath(name);
if (directPath.exists() && directPath.getItemPath() != null) {
return directPath.getItemPath();
}
// else search for it in the whole tree using property description
Property[] searchProps = new Property[classIdProps.length + 1];
searchProps[0] = new Property(NAME, name);
System.arraycopy(classIdProps, 0, searchProps, 1, classIdProps.length);
Iterator<Path> e = Gateway.getLookup().search(new DomainPath(), searchProps);
if (e.hasNext()) {
Path defPath = e.next();
if (e.hasNext())
throw new ObjectNotFoundException("Too many matches for " + getTypeCode() + " " + name);
if (defPath.getItemPath() == null)
throw new InvalidDataException(getTypeCode() + " " + name + " was found, but was not an Item");
return defPath.getItemPath();
} else {
throw new ObjectNotFoundException("No match for " + getTypeCode() + " " + name);
}
}
Aggregations