Search in sources :

Example 11 with ObjectAlreadyExistsException

use of org.cristalise.kernel.common.ObjectAlreadyExistsException in project kernel by cristal-ise.

the class AggregationDescription method newInstance.

/**
 * For each  member get the {@link PropertyDescriptionList} of the member item and look for an explicit version
 */
@Override
public Aggregation newInstance() throws ObjectNotFoundException {
    AggregationInstance newInstance = new AggregationInstance(getName());
    for (int i = 0; i < size(); i++) {
        AggregationMember mem = mMembers.list.get(i);
        // 
        String descVer = getDescVer(mem);
        PropertyDescriptionList pdList = PropertyUtility.getPropertyDescriptionOutcome(mem.getItemPath(), descVer, null);
        if (pdList != null) {
            // create the new props of the member object
            try {
                Vertex v = getLayout().getVertexById(mem.getID());
                newInstance.addMember(null, PropertyUtility.convertTransitiveProperties(pdList), pdList.getClassProps(), v.getCentrePoint(), v.getWidth(), v.getHeight());
            } catch (InvalidCollectionModification e) {
            } catch (ObjectAlreadyExistsException e) {
            }
        } else {
            Logger.error("AggregationDescription::newInstance() There is no PropertyDescription. Cannot instantiate. " + mem.getItemPath());
            return null;
        }
    }
    return newInstance;
}
Also used : Vertex(org.cristalise.kernel.graph.model.Vertex) InvalidCollectionModification(org.cristalise.kernel.common.InvalidCollectionModification) PropertyDescriptionList(org.cristalise.kernel.property.PropertyDescriptionList) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException)

Example 12 with ObjectAlreadyExistsException

use of org.cristalise.kernel.common.ObjectAlreadyExistsException in project kernel by cristal-ise.

the class CreateAgentFromDescription method runActivityLogic.

/**
 * Params:
 * <ol>
 * <li>Agent name</li>
 * <li>Domain context</li>
 * <li>Comma-delimited Role names to assign to the Agent</li>
 * <li>Password (optional)</li>
 * <li>Initial properties to set in the new Agent (optional)</li>
 * <li>Description version to use(optional)</li>
 * </ol>
 * @throws ObjectNotFoundException
 * @throws InvalidDataException The input parameters were incorrect
 * @throws ObjectAlreadyExistsException The Agent already exists
 * @throws CannotManageException The Agent could not be created
 * @throws ObjectCannotBeUpdated The addition of the new entries into the LookupManager failed
 * @throws PersistencyException
 * @see org.cristalise.kernel.lifecycle.instance.predefined.item.CreateItemFromDescription#runActivityLogic(AgentPath, ItemPath, int, String, Object)
 */
@Override
protected String runActivityLogic(AgentPath agentPath, ItemPath descItemPath, int transitionID, String requestData, Object locker) throws ObjectNotFoundException, InvalidDataException, ObjectAlreadyExistsException, CannotManageException, ObjectCannotBeUpdated, PersistencyException {
    String[] input = getDataList(requestData);
    String newName = input[0];
    String contextS = input[1];
    String[] roles = input[2].split(",");
    String pwd = input.length > 3 ? input[3] : "";
    String descVer = input.length > 4 ? input[4] : "last";
    PropertyArrayList initProps = input.length > 5 ? unmarshallInitProperties(input[5]) : new PropertyArrayList();
    // generate new agent path with new UUID
    Logger.msg(1, "CreateAgentFromDescription - Requesting new agent path name:" + newName);
    AgentPath newAgentPath = new AgentPath(new ItemPath(), newName);
    // check if the agent's name is already taken
    if (Gateway.getLookup().exists(newAgentPath))
        throw new ObjectAlreadyExistsException("The agent name " + newName + " exists already.");
    DomainPath context = new DomainPath(new DomainPath(contextS), newName);
    if (context.exists())
        throw new ObjectAlreadyExistsException("The path " + context + " exists already.");
    ActiveEntity newAgent = createAgentAddRoles(newAgentPath, roles, pwd);
    initialiseItem(newAgent, agentPath, descItemPath, initProps, newName, descVer, context, newAgentPath, locker);
    // censor password from outcome
    if (input.length > 3)
        input[3] = "REDACTED";
    return bundleData(input);
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) AgentPath(org.cristalise.kernel.lookup.AgentPath) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) ActiveEntity(org.cristalise.kernel.entity.agent.ActiveEntity) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 13 with ObjectAlreadyExistsException

use of org.cristalise.kernel.common.ObjectAlreadyExistsException in project kernel by cristal-ise.

the class AddDomainContext method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectCannotBeUpdated, ObjectAlreadyExistsException, CannotManageException {
    String[] params = getDataList(requestData);
    Logger.msg(3, "AddDomainContext: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    if (params.length != 1)
        throw new InvalidDataException("AddDomainContext: Invalid parameters " + Arrays.toString(params));
    DomainPath pathToAdd = new DomainPath(params[0]);
    if (pathToAdd.exists())
        throw new ObjectAlreadyExistsException("Context " + pathToAdd + " already exists");
    // collect parent paths if they don't exist
    Stack<DomainPath> pathsToAdd = new Stack<DomainPath>();
    while (pathToAdd != null && !pathToAdd.exists()) {
        pathsToAdd.push(pathToAdd);
        pathToAdd = pathToAdd.getParent();
    }
    while (!pathsToAdd.empty()) {
        pathToAdd = pathsToAdd.pop();
        Gateway.getLookupManager().add(pathToAdd);
    }
    return requestData;
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) Stack(java.util.Stack)

Example 14 with ObjectAlreadyExistsException

use of org.cristalise.kernel.common.ObjectAlreadyExistsException 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)

Example 15 with ObjectAlreadyExistsException

use of org.cristalise.kernel.common.ObjectAlreadyExistsException in project kernel by cristal-ise.

the class BulkImport method importAgentPath.

public AgentPath importAgentPath(ItemPath item, Object locker) throws PersistencyException {
    try {
        AgentPath agentPath = (AgentPath) importCluster.get(item, PATH + "/Item");
        Gateway.getLookupManager().add(agentPath);
        Gateway.getLookupManager().setAgentPassword(agentPath, "aaa");
        return agentPath;
    } catch (ObjectCannotBeUpdated | ObjectAlreadyExistsException | CannotManageException | ObjectNotFoundException | NoSuchAlgorithmException e) {
        Logger.error(e);
        throw new PersistencyException(e.getMessage());
    }
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) PersistencyException(org.cristalise.kernel.common.PersistencyException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException)

Aggregations

ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)18 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)8 CannotManageException (org.cristalise.kernel.common.CannotManageException)7 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)7 PersistencyException (org.cristalise.kernel.common.PersistencyException)7 InvalidCollectionModification (org.cristalise.kernel.common.InvalidCollectionModification)5 DomainPath (org.cristalise.kernel.lookup.DomainPath)5 ItemPath (org.cristalise.kernel.lookup.ItemPath)5 AgentPath (org.cristalise.kernel.lookup.AgentPath)4 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)3 ActiveEntity (org.cristalise.kernel.entity.agent.ActiveEntity)3 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)3 IOException (java.io.IOException)2 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)2 Dependency (org.cristalise.kernel.collection.Dependency)2 TraceableEntity (org.cristalise.kernel.entity.TraceableEntity)2 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)2 RolePath (org.cristalise.kernel.lookup.RolePath)2 CastorHashMap (org.cristalise.kernel.utils.CastorHashMap)2 MappingException (org.exolab.castor.mapping.MappingException)2