use of org.cristalise.kernel.property.PropertyDescriptionList in project kernel by cristal-ise.
the class CreateItemFromDescription method instantiateProperties.
/**
* @param descItemPath
* @param descVer
* @param initProps
* @param newName
* @param agent
* @param locker
* @return props
* @throws ObjectNotFoundException
* @throws InvalidDataException
*/
protected PropertyArrayList instantiateProperties(ItemPath descItemPath, String descVer, PropertyArrayList initProps, String newName, AgentPath agent, Object locker) throws ObjectNotFoundException, InvalidDataException {
// copy properties -- intend to create from propdesc
PropertyDescriptionList pdList = PropertyUtility.getPropertyDescriptionOutcome(descItemPath, descVer, locker);
PropertyArrayList props = pdList.instantiate(initProps);
// set Name prop or create if not present
boolean foundName = false;
for (Property prop : props.list) {
if (prop.getName().equals(NAME.toString())) {
foundName = true;
prop.setValue(newName);
break;
}
}
if (!foundName)
props.list.add(new Property(NAME, newName, true));
props.list.add(new Property(CREATOR, agent.getAgentName(), false));
return props;
}
use of org.cristalise.kernel.property.PropertyDescriptionList 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;
}
Aggregations