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;
}
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;
}
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);
}
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);
}
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;
}
Aggregations