Search in sources :

Example 6 with PropertyArrayList

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

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

the class Dependency method convertToItemPropertyByScript.

/**
 * Executes Script if it was defined in the Member properties
 *
 * @param props the current list of ItemProperties
 * @param member the current DependencyMember
 * @return true when Script was executed
 * @throws InvalidDataException
 * @throws ObjectNotFoundException
 */
private boolean convertToItemPropertyByScript(PropertyArrayList props, DependencyMember member) throws InvalidDataException, ObjectNotFoundException {
    Logger.msg(5, "Dependency.convertToItemPropertyByScript() - Dependency:" + getName() + " memberUUID:" + member.getChildUUID());
    String scriptName = (String) member.getBuiltInProperty(SCRIPT_NAME);
    if (scriptName != null && scriptName.length() > 0) {
        PropertyArrayList newProps = (PropertyArrayList) member.evaluateScript();
        props.merge(newProps);
        return true;
    }
    return false;
}
Also used : PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList)

Example 8 with PropertyArrayList

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

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

the class CreateItemFromDescription method initialiseItem.

/**
 * @param agent
 * @param descItemPath
 * @param locker
 * @param input
 * @param newName
 * @param descVer
 * @param context
 * @param newItemPath
 * @param newItem
 * @throws ObjectCannotBeUpdated
 * @throws CannotManageException
 * @throws InvalidDataException
 * @throws ObjectAlreadyExistsException
 * @throws PersistencyException
 * @throws ObjectNotFoundException
 */
protected void initialiseItem(ItemOperations newItem, AgentPath agent, ItemPath descItemPath, PropertyArrayList initProps, String newName, String descVer, DomainPath context, ItemPath newItemPath, Object locker) throws ObjectCannotBeUpdated, CannotManageException, InvalidDataException, ObjectAlreadyExistsException, PersistencyException, ObjectNotFoundException {
    // initialise it with its properties and workflow
    Logger.msg(3, "CreateItemFromDescription.initialiseItem() - Initializing Item:" + newName);
    try {
        PropertyArrayList newProps = instantiateProperties(descItemPath, descVer, initProps, newName, agent, locker);
        CollectionArrayList newColls = instantiateCollections(descItemPath, descVer, newProps, locker);
        CompositeActivity newWorkflow = instantiateWorkflow(descItemPath, descVer, locker);
        newItem.initialise(agent.getSystemKey(), Gateway.getMarshaller().marshall(newProps), Gateway.getMarshaller().marshall(newWorkflow), Gateway.getMarshaller().marshall(newColls));
    } catch (MarshalException | ValidationException | AccessRightsException | IOException | MappingException | InvalidCollectionModification e) {
        Logger.error(e);
        Gateway.getLookupManager().delete(newItemPath);
        throw new InvalidDataException("CreateItemFromDescription: Problem initializing new Item. See log: " + e.getMessage());
    } catch (InvalidDataException | ObjectNotFoundException | PersistencyException e) {
        Logger.error(e);
        Gateway.getLookupManager().delete(newItemPath);
        throw e;
    }
    // add its domain path
    Logger.msg(3, "CreateItemFromDescription - Creating " + context);
    context.setItemPath(newItemPath);
    Gateway.getLookupManager().add(context);
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) ValidationException(org.exolab.castor.xml.ValidationException) InvalidCollectionModification(org.cristalise.kernel.common.InvalidCollectionModification) IOException(java.io.IOException) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList) MappingException(org.exolab.castor.mapping.MappingException) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Example 10 with PropertyArrayList

use of org.cristalise.kernel.property.PropertyArrayList 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)

Aggregations

PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)10 Property (org.cristalise.kernel.property.Property)6 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)4 DomainPath (org.cristalise.kernel.lookup.DomainPath)4 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)3 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)3 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)3 AgentPath (org.cristalise.kernel.lookup.AgentPath)3 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)2 CannotManageException (org.cristalise.kernel.common.CannotManageException)2 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)2 PersistencyException (org.cristalise.kernel.common.PersistencyException)2 TraceableEntity (org.cristalise.kernel.entity.TraceableEntity)2 ActiveEntity (org.cristalise.kernel.entity.agent.ActiveEntity)2 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)2 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)2 ItemPath (org.cristalise.kernel.lookup.ItemPath)2 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)2 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)2 PropertyDescriptionList (org.cristalise.kernel.property.PropertyDescriptionList)2