Search in sources :

Example 1 with DependencyDescription

use of org.cristalise.kernel.collection.DependencyDescription in project kernel by cristal-ise.

the class ImportDependency method create.

public Dependency create() throws InvalidCollectionModification, ObjectNotFoundException, ObjectAlreadyExistsException {
    Dependency newDep = isDescription ? new DependencyDescription(name) : new Dependency(name);
    if (version != null)
        newDep.setVersion(version);
    if (itemDescriptionPath != null && itemDescriptionPath.length() > 0) {
        ItemPath itemPath;
        try {
            itemPath = new ItemPath(itemDescriptionPath);
        } catch (InvalidItemPathException ex) {
            itemPath = new DomainPath(itemDescriptionPath).getItemPath();
        }
        String descVer = itemDescriptionVersion == null ? "last" : itemDescriptionVersion;
        PropertyDescriptionList propList = PropertyUtility.getPropertyDescriptionOutcome(itemPath, descVer, null);
        StringBuffer classProps = new StringBuffer();
        for (PropertyDescription pd : propList.list) {
            props.put(pd.getName(), pd.getDefaultValue());
            if (pd.getIsClassIdentifier())
                classProps.append((classProps.length() > 0 ? "," : "")).append(pd.getName());
        }
        newDep.setProperties(props);
        newDep.setClassProps(classProps.toString());
    }
    for (ImportDependencyMember thisMem : dependencyMemberList) {
        ItemPath itemPath;
        try {
            itemPath = new ItemPath(thisMem.itemPath);
        } catch (InvalidItemPathException ex) {
            itemPath = new DomainPath(thisMem.itemPath).getItemPath();
        }
        org.cristalise.kernel.collection.DependencyMember newDepMem = newDep.addMember(itemPath);
        newDepMem.getProperties().putAll(thisMem.props);
    }
    return newDep;
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) Dependency(org.cristalise.kernel.collection.Dependency) PropertyDescription(org.cristalise.kernel.property.PropertyDescription) DependencyDescription(org.cristalise.kernel.collection.DependencyDescription) PropertyDescriptionList(org.cristalise.kernel.property.PropertyDescriptionList) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 2 with DependencyDescription

use of org.cristalise.kernel.collection.DependencyDescription in project kernel by cristal-ise.

the class AddNewCollectionDescription method runActivityLogic.

/**
 * Params: 0 - collection name 1 - collection type (Aggregation, Dependency)
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectAlreadyExistsException, PersistencyException {
    // extract parameters
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "AddNewCollectionDescription: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    if (params.length != 2)
        throw new InvalidDataException("AddNewCollectionDescription: Invalid parameters " + Arrays.toString(params));
    String collName = params[0];
    String collType = params[1];
    // check if collection already exists
    try {
        Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
        throw new ObjectAlreadyExistsException("Collection '" + collName + "' already exists");
    } catch (ObjectNotFoundException ex) {
    // collection doesn't exist
    }
    CollectionDescription<?> newCollDesc;
    if (collType.equalsIgnoreCase("Aggregation"))
        newCollDesc = new AggregationDescription(collName);
    else if (collType.equalsIgnoreCase("Dependency"))
        newCollDesc = new DependencyDescription(collName);
    else
        throw new InvalidDataException("AddNewCollectionDescription: Invalid type: '" + collType + "' /Aggregation or Dependency)");
    // store it
    try {
        Gateway.getStorage().put(item, newCollDesc, locker);
    } catch (PersistencyException e) {
        throw new PersistencyException("AddNewCollectionDescription: Error saving new collection '" + collName + "': " + e.getMessage());
    }
    return requestData;
}
Also used : AggregationDescription(org.cristalise.kernel.collection.AggregationDescription) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) DependencyDescription(org.cristalise.kernel.collection.DependencyDescription) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException)

Aggregations

DependencyDescription (org.cristalise.kernel.collection.DependencyDescription)2 AggregationDescription (org.cristalise.kernel.collection.AggregationDescription)1 Dependency (org.cristalise.kernel.collection.Dependency)1 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)1 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)1 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)1 PersistencyException (org.cristalise.kernel.common.PersistencyException)1 DomainPath (org.cristalise.kernel.lookup.DomainPath)1 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)1 ItemPath (org.cristalise.kernel.lookup.ItemPath)1 PropertyDescription (org.cristalise.kernel.property.PropertyDescription)1 PropertyDescriptionList (org.cristalise.kernel.property.PropertyDescriptionList)1