Search in sources :

Example 6 with ObjectAlreadyExistsException

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

the class CreateNewRole method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException, ObjectNotFoundException {
    try {
        ImportRole newRole = (ImportRole) Gateway.getMarshaller().unmarshall(requestData);
        if (Gateway.getLookup().exists(new RolePath(newRole.getName(), newRole.jobList)))
            throw new ObjectAlreadyExistsException("CreateNewRole: Role '" + newRole.getName() + "' already exists.");
        newRole.create(agent, true);
        return requestData;
    } catch (MarshalException | ValidationException | IOException | MappingException e) {
        Logger.error(e);
        throw new InvalidDataException("CreateNewRole: Couldn't unmarshall new Role: " + requestData);
    }
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) ImportRole(org.cristalise.kernel.entity.imports.ImportRole) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) IOException(java.io.IOException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) RolePath(org.cristalise.kernel.lookup.RolePath) MappingException(org.exolab.castor.mapping.MappingException)

Example 7 with ObjectAlreadyExistsException

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

the class CorbaServer method createItem.

public TraceableEntity createItem(ItemPath itemPath) throws CannotManageException, ObjectAlreadyExistsException {
    if (itemPath.exists())
        throw new ObjectAlreadyExistsException();
    itemPath.setIOR(getItemIOR(itemPath));
    TraceableEntity item = new TraceableEntity(itemPath, mItemPOA);
    synchronized (mItemCache) {
        mItemCache.put(itemPath, item);
    }
    return item;
}
Also used : ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException)

Example 8 with ObjectAlreadyExistsException

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

the class ImportAgent method create.

@Override
public Path create(AgentPath agentPath, boolean reset) throws ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, ObjectAlreadyExistsException {
    if (roles.isEmpty())
        throw new ObjectNotFoundException("Agent '" + name + "' must declare at least one Role ");
    AgentPath newAgent = new AgentPath(getItemPath(), name);
    ActiveEntity newAgentEnt = Gateway.getCorbaServer().createAgent(newAgent);
    Gateway.getLookupManager().add(newAgent);
    // assemble properties
    properties.add(new Property(NAME, name, true));
    properties.add(new Property(TYPE, "Agent", false));
    try {
        if (StringUtils.isNotBlank(password))
            Gateway.getLookupManager().setAgentPassword(newAgent, password);
        newAgentEnt.initialise(agentPath.getSystemKey(), Gateway.getMarshaller().marshall(new PropertyArrayList(properties)), null, null);
    } catch (Exception ex) {
        Logger.error(ex);
        throw new CannotManageException("Error initialising new agent name:" + name);
    }
    for (ImportRole role : roles) {
        RolePath thisRole = (RolePath) role.create(agentPath, reset);
        Gateway.getLookupManager().addRole(newAgent, thisRole);
    }
    return newAgent;
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) Property(org.cristalise.kernel.property.Property) ActiveEntity(org.cristalise.kernel.entity.agent.ActiveEntity) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) CannotManageException(org.cristalise.kernel.common.CannotManageException) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 9 with ObjectAlreadyExistsException

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

the class ImportItem method create.

/**
 */
@Override
public Path create(AgentPath agentPath, boolean reset) throws InvalidDataException, ObjectCannotBeUpdated, ObjectNotFoundException, CannotManageException, ObjectAlreadyExistsException, InvalidCollectionModification, PersistencyException {
    domainPath = new DomainPath(new DomainPath(initialPath), name);
    if (domainPath.exists()) {
        ItemPath domItem = domainPath.getItemPath();
        if (!getItemPath().equals(domItem)) {
            throw new CannotManageException("Item " + domainPath + " was found with the wrong itemPath (" + domainPath.getItemPath() + " vs " + getItemPath() + ")");
        }
    } else
        isDOMPathExists = false;
    TraceableEntity newItem = getTraceableEntitiy();
    // (re)initialise the new item with properties, workflow and collections
    try {
        newItem.initialise(agentPath.getSystemKey(), Gateway.getMarshaller().marshall(createItemProperties()), Gateway.getMarshaller().marshall(createCompositeActivity()), Gateway.getMarshaller().marshall(createCollections()));
    } catch (Exception ex) {
        Logger.error("Error initialising new item " + ns + "/" + name);
        Logger.error(ex);
        if (isNewItem)
            Gateway.getLookupManager().delete(itemPath);
        throw new CannotManageException("Problem initialising new item. See server log:" + ex.getMessage());
    }
    History hist = new History(getItemPath(), null);
    // import outcomes
    for (ImportOutcome thisOutcome : outcomes) {
        String outcomeData = thisOutcome.getData(ns);
        // load schema and state machine
        Schema schema = LocalObjectLoader.getSchema(thisOutcome.schema, thisOutcome.version);
        // parse new outcome and validate
        Outcome newOutcome = new Outcome(-1, outcomeData, schema);
        newOutcome.validateAndCheck();
        Viewpoint impView;
        try {
            impView = (Viewpoint) Gateway.getStorage().get(getItemPath(), ClusterType.VIEWPOINT + "/" + thisOutcome.schema + "/" + thisOutcome.viewname, null);
            if (newOutcome.isIdentical(impView.getOutcome())) {
                Logger.msg(5, "ImportItem.create() - View " + thisOutcome.schema + "/" + thisOutcome.viewname + " in " + ns + "/" + name + " identical, no update required");
                continue;
            } else {
                Logger.msg("ImportItem.create() - Difference found in view " + thisOutcome.schema + "/" + thisOutcome.viewname + " in " + ns + "/" + name);
                if (!reset && !impView.getEvent().getStepPath().equals("Import")) {
                    Logger.msg("ImportItem.create() - Last edit was not done by import, and reset not requested. Not overwriting.");
                    continue;
                }
            }
        } catch (ObjectNotFoundException ex) {
            Logger.msg("ImportItem.create() - View " + thisOutcome.schema + "/" + thisOutcome.viewname + " not found in " + ns + "/" + name + ". Creating.");
            impView = new Viewpoint(getItemPath(), schema, thisOutcome.viewname, -1);
        }
        // write new view/outcome/event
        Event newEvent = hist.addEvent(agentPath, null, "Admin", "Import", "Import", "Import", schema, Bootstrap.getPredefSM(), PredefinedStep.DONE, thisOutcome.viewname);
        newOutcome.setID(newEvent.getID());
        impView.setEventId(newEvent.getID());
        Gateway.getStorage().put(getItemPath(), newOutcome, null);
        Gateway.getStorage().put(getItemPath(), impView, null);
    }
    // register domain path (before collections in case of recursive collections)
    if (!isDOMPathExists) {
        domainPath.setItemPath(getItemPath());
        Gateway.getLookupManager().add(domainPath);
    }
    return domainPath;
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) CannotManageException(org.cristalise.kernel.common.CannotManageException) Schema(org.cristalise.kernel.persistency.outcome.Schema) History(org.cristalise.kernel.events.History) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) PersistencyException(org.cristalise.kernel.common.PersistencyException) CannotManageException(org.cristalise.kernel.common.CannotManageException) TraceableEntity(org.cristalise.kernel.entity.TraceableEntity) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Event(org.cristalise.kernel.events.Event) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 10 with ObjectAlreadyExistsException

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

the class Dependency method addMember.

/**
 * Add a member to the Dependency
 *
 * @param itemPath the Item to be added as a Member
 * @return DependencyMember the newly created DependencyMember
 * @throws InvalidCollectionModification if Item is null or the Properties of the Item (e.g. Type) does not match the Collection's
 * @throws ObjectAlreadyExistsException Item is already a member
 */
public DependencyMember addMember(ItemPath itemPath) throws InvalidCollectionModification, ObjectAlreadyExistsException {
    if (itemPath == null)
        throw new InvalidCollectionModification("Cannot add empty slot to Dependency collection");
    if (contains(itemPath))
        throw new ObjectAlreadyExistsException("Item " + itemPath + " already exists in Dependency " + getName());
    // create member object
    DependencyMember depMember = new DependencyMember();
    depMember.setID(getCounter());
    depMember.setProperties((CastorHashMap) mProperties.clone());
    depMember.setClassProps(mClassProps);
    // assign entity
    depMember.assignItem(itemPath);
    mMembers.list.add(depMember);
    Logger.msg(8, "Dependency.addMember(" + itemPath + ") added to children.");
    return depMember;
}
Also used : InvalidCollectionModification(org.cristalise.kernel.common.InvalidCollectionModification) 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