Search in sources :

Example 6 with PropertyDescriptionList

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;
}
Also used : PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) PropertyDescriptionList(org.cristalise.kernel.property.PropertyDescriptionList) Property(org.cristalise.kernel.property.Property)

Example 7 with PropertyDescriptionList

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;
}
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) PropertyDescription(org.cristalise.kernel.property.PropertyDescription) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) CastorHashMap(org.cristalise.kernel.utils.CastorHashMap) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PropertyDescriptionList(org.cristalise.kernel.property.PropertyDescriptionList) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Aggregations

PropertyDescriptionList (org.cristalise.kernel.property.PropertyDescriptionList)7 DomainPath (org.cristalise.kernel.lookup.DomainPath)4 PropertyDescription (org.cristalise.kernel.property.PropertyDescription)4 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)3 ItemPath (org.cristalise.kernel.lookup.ItemPath)3 Aggregation (org.cristalise.kernel.collection.Aggregation)2 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)2 Property (org.cristalise.kernel.property.Property)2 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)2 AggregationDescription (org.cristalise.kernel.collection.AggregationDescription)1 AggregationInstance (org.cristalise.kernel.collection.AggregationInstance)1 Dependency (org.cristalise.kernel.collection.Dependency)1 DependencyDescription (org.cristalise.kernel.collection.DependencyDescription)1 InvalidCollectionModification (org.cristalise.kernel.common.InvalidCollectionModification)1 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)1 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)1 PersistencyException (org.cristalise.kernel.common.PersistencyException)1 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)1 ItemProxy (org.cristalise.kernel.entity.proxy.ItemProxy)1 GraphPoint (org.cristalise.kernel.graph.model.GraphPoint)1