use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class RemoveAgent method runActivityLogic.
@Override
protected String runActivityLogic(AgentPath agent, ItemPath itemPath, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, PersistencyException {
Logger.msg(1, "RemoveAgent::request() - Starting.");
AgentPath targetAgent;
try {
targetAgent = new AgentPath(itemPath);
} catch (InvalidAgentPathException ex) {
throw new InvalidDataException("Could not resolve " + itemPath + " as an Agent.");
}
String agentName = targetAgent.getAgentName();
// remove from roles
for (RolePath role : targetAgent.getRoles()) {
try {
Gateway.getLookupManager().removeRole(targetAgent, role);
} catch (ObjectCannotBeUpdated | ObjectNotFoundException | CannotManageException e) {
Logger.error(e);
throw new InvalidDataException("Error removing " + agentName + " from Role " + role.getName() + " exceptoin message:" + e.getMessage());
}
}
return super.runActivityLogic(agent, itemPath, transitionID, requestData, locker);
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class SetAgentRoles method runActivityLogic.
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException {
String[] params = getDataList(requestData);
Logger.msg(3, "SetAgentRoles: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
AgentPath targetAgent;
try {
targetAgent = new AgentPath(item);
} catch (InvalidItemPathException ex) {
throw new InvalidDataException("Could not resolve syskey " + item + " as an Agent.");
}
RolePath[] currentRoles = targetAgent.getRoles();
ArrayList<RolePath> requestedRoles = new ArrayList<RolePath>();
for (int i = 0; i < params.length; i++) {
try {
requestedRoles.add(Gateway.getLookup().getRolePath(params[i]));
} catch (ObjectNotFoundException e) {
throw new InvalidDataException("Role " + params[i] + " not found");
}
}
ArrayList<RolePath> rolesToRemove = new ArrayList<RolePath>();
for (RolePath existingRole : currentRoles) {
//
if (// if we have it, and it's requested, then it will be kept
requestedRoles.contains(existingRole))
// so remove it from request - this will be left with roles to be added
requestedRoles.remove(existingRole);
else
// else this role will be removed
rolesToRemove.add(existingRole);
}
// remove roles not in new list
for (RolePath roleToRemove : rolesToRemove) try {
Gateway.getLookupManager().removeRole(targetAgent, roleToRemove);
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException("Error removing role " + roleToRemove.getName());
}
// add requested roles we don't already have
for (RolePath roleToAdd : requestedRoles) {
try {
Gateway.getLookupManager().addRole(targetAgent, roleToAdd);
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException("Error adding role " + roleToAdd.getName());
}
}
return requestData;
}
use of org.cristalise.kernel.common.InvalidDataException 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;
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class ActivitySlotDef method getTheActivityDef.
public ActivityDef getTheActivityDef() throws ObjectNotFoundException, InvalidDataException {
if (theActivityDef == null) {
try {
Logger.msg(5, "ActivitySlotDef.getTheActivityDef() - try to load from item desc collection of ActSlotDef:" + getName());
DescriptionObject[] parentActDefs = ((CompositeActivityDef) getParent()).getBuiltInCollectionResource(ACTIVITY);
for (DescriptionObject thisActDef : parentActDefs) {
String childUUID = thisActDef.getItemID();
Logger.msg(5, "ActivitySlotDef.getTheActivityDef() - Collection childUUID:" + childUUID + " of ActSlotDef:" + getName());
if (childUUID.equals(getActivityDef()) || thisActDef.getName().equals(getActivityDef())) {
ActivityDef currentActDef = (ActivityDef) thisActDef;
Integer requiredVersion = deriveVersionNumber(getBuiltInProperty(VERSION));
if (// collection indicated a different version - get the right one
currentActDef.getVersion() != requiredVersion)
setTheActivityDef(LocalObjectLoader.getActDef(childUUID, requiredVersion));
else
// use the existing one
setTheActivityDef(currentActDef);
break;
}
}
}// old def with no collection
catch (ObjectNotFoundException ex) {
}
if (theActivityDef == null) {
// try to load from property
Logger.msg(5, "ActivitySlotDef.getTheActivityDef() - try to load from property of ActSlotDef:" + getName());
Integer version = deriveVersionNumber(getBuiltInProperty(VERSION));
if (version == null)
throw new InvalidDataException("No version defined in ActivityDefSlot " + getName());
setTheActivityDef(LocalObjectLoader.getActDef(getActivityDef(), version));
}
}
return theActivityDef;
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class CompositeActivityDef method export.
@Override
public void export(Writer imports, File dir) throws InvalidDataException, ObjectNotFoundException, IOException {
// rebuild the child refs in case any slots have been removed
setRefChildActDef(findRefActDefs(getChildrenGraphModel()));
// export child activitz defs, routing scripts and schemas
for (GraphableVertex vert : getChildren()) {
if (vert instanceof AndSplitDef) {
try {
((AndSplitDef) vert).getRoutingScript().export(imports, dir);
} catch (ObjectNotFoundException ex) {
}
} else if (vert instanceof ActivitySlotDef) {
ActivityDef refAct = ((ActivitySlotDef) vert).getTheActivityDef();
refAct.export(imports, dir);
}
}
String tc = COMP_ACT_DESC_RESOURCE.getTypeCode();
try {
// export marshalled compAct
String compactXML = Gateway.getMarshaller().marshall(this);
FileStringUtility.string2File(new File(new File(dir, tc), getActName() + (getVersion() == null ? "" : "_" + getVersion()) + ".xml"), compactXML);
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException("Couldn't marshall composite activity def " + getActName());
}
if (imports != null) {
imports.write("<Workflow " + getExportAttributes(tc) + ">" + getExportCollections());
for (ActivityDef childActDef : refChildActDef) {
imports.write("<Activity name=\"" + childActDef.getActName() + "\" id=\"" + childActDef.getItemID() + "\" version=\"" + childActDef.getVersion() + "\"/>");
}
imports.write("</Workflow>\n");
}
}
Aggregations