Search in sources :

Example 16 with Property

use of org.cristalise.kernel.property.Property in project kernel by cristal-ise.

the class Bootstrap method checkAgent.

/**
 * Checks for the existence of a agents so it can be used
 *
 * @param name
 * @param pass
 * @param rolePath
 * @param uuid
 * @return the Proxy representing the Agent
 * @throws Exception
 */
private static AgentProxy checkAgent(String name, String pass, RolePath rolePath, String uuid) throws Exception {
    Logger.msg(1, "Bootstrap.checkAgent() - Checking for existence of '" + name + "' agent.");
    LookupManager lookup = Gateway.getLookupManager();
    try {
        AgentProxy agentProxy = Gateway.getProxyManager().getAgentProxy(lookup.getAgentPath(name));
        systemAgents.put(name, agentProxy);
        Logger.msg(3, "Bootstrap.checkAgent() - Agent '" + name + "' found.");
        return agentProxy;
    } catch (ObjectNotFoundException ex) {
    }
    Logger.msg("Bootstrap.checkAgent() - Agent '" + name + "' not found. Creating.");
    try {
        AgentPath agentPath = new AgentPath(new ItemPath(uuid), name);
        Gateway.getCorbaServer().createAgent(agentPath);
        lookup.add(agentPath);
        if (StringUtils.isNotBlank(pass))
            lookup.setAgentPassword(agentPath, pass);
        // assign admin role
        Logger.msg("Bootstrap.checkAgent() - Assigning role '" + rolePath.getName() + "'");
        Gateway.getLookupManager().addRole(agentPath, rolePath);
        Gateway.getStorage().put(agentPath, new Property(NAME, name, true), null);
        Gateway.getStorage().put(agentPath, new Property(TYPE, "Agent", false), null);
        AgentProxy agentProxy = Gateway.getProxyManager().getAgentProxy(agentPath);
        // TODO: properly init agent here with wf, props and colls
        // agentProxy.initialise(agentId, itemProps, workflow, colls);
        systemAgents.put(name, agentProxy);
        return agentProxy;
    } catch (Exception ex) {
        Logger.error("Unable to create '" + name + "' Agent.");
        throw ex;
    }
}
Also used : AgentPath(org.cristalise.kernel.lookup.AgentPath) LookupManager(org.cristalise.kernel.lookup.LookupManager) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) AgentProxy(org.cristalise.kernel.entity.proxy.AgentProxy) Property(org.cristalise.kernel.property.Property) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 17 with Property

use of org.cristalise.kernel.property.Property 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 18 with Property

use of org.cristalise.kernel.property.Property in project kernel by cristal-ise.

the class Module method replaceProp.

private void replaceProp(Property newProp) {
    for (Property prop : properties) {
        if (prop.getName().equals(newProp.getName())) {
            prop.setMutable(newProp.isMutable());
            prop.setValue(newProp.getValue());
            return;
        }
    }
    properties.add(newProp);
}
Also used : Property(org.cristalise.kernel.property.Property)

Example 19 with Property

use of org.cristalise.kernel.property.Property in project kernel by cristal-ise.

the class DescriptionObjectCache method findItem.

public ItemPath findItem(String name) throws ObjectNotFoundException, InvalidDataException {
    if (Gateway.getLookup() == null)
        throw new ObjectNotFoundException("Cannot find Items without a Lookup");
    // first check for a UUID name
    try {
        ItemPath resItem = new ItemPath(name);
        if (resItem.exists())
            return resItem;
    } catch (InvalidItemPathException ex) {
    }
    // then check for a direct path
    DomainPath directPath = new DomainPath(name);
    if (directPath.exists() && directPath.getItemPath() != null) {
        return directPath.getItemPath();
    }
    // else search for it in the whole tree using property description
    Property[] searchProps = new Property[classIdProps.length + 1];
    searchProps[0] = new Property(NAME, name);
    System.arraycopy(classIdProps, 0, searchProps, 1, classIdProps.length);
    Iterator<Path> e = Gateway.getLookup().search(new DomainPath(), searchProps);
    if (e.hasNext()) {
        Path defPath = e.next();
        if (e.hasNext())
            throw new ObjectNotFoundException("Too many matches for " + getTypeCode() + " " + name);
        if (defPath.getItemPath() == null)
            throw new InvalidDataException(getTypeCode() + " " + name + " was found, but was not an Item");
        return defPath.getItemPath();
    } else {
        throw new ObjectNotFoundException("No match for " + getTypeCode() + " " + name);
    }
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) ItemPath(org.cristalise.kernel.lookup.ItemPath) Path(org.cristalise.kernel.lookup.Path) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Property(org.cristalise.kernel.property.Property) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Aggregations

Property (org.cristalise.kernel.property.Property)19 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)10 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)6 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)6 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)6 DomainPath (org.cristalise.kernel.lookup.DomainPath)4 ItemPath (org.cristalise.kernel.lookup.ItemPath)4 PersistencyException (org.cristalise.kernel.common.PersistencyException)3 AgentPath (org.cristalise.kernel.lookup.AgentPath)3 LookupManager (org.cristalise.kernel.lookup.LookupManager)3 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)3 StringTokenizer (java.util.StringTokenizer)2 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)2 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)2 CannotManageException (org.cristalise.kernel.common.CannotManageException)2 InvalidCollectionModification (org.cristalise.kernel.common.InvalidCollectionModification)2 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)2 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)2 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)2 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)2