Search in sources :

Example 6 with AccessRightsException

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

the class ItemProxy method setProperty.

/**
 * Sets the vlaue of the given Property
 *
 * @param agent the Agent who is setting the Property
 * @param name the name of the Property
 * @param value the value of the Property
 * @throws AccessRightsException Agent does not the rights to execute this operation
 * @throws PersistencyException there was a database problems during this operations
 * @throws InvalidDataException data was invalid
 */
public void setProperty(AgentProxy agent, String name, String value) throws AccessRightsException, PersistencyException, InvalidDataException {
    try {
        String[] params = { name, value };
        agent.execute(this, "WriteProperty", params);
    } catch (AccessRightsException | PersistencyException | InvalidDataException e) {
        throw (e);
    } catch (Exception e) {
        Logger.error(e);
        throw new PersistencyException("Could not store property:" + e.getMessage());
    }
}
Also used : AccessRightsException(org.cristalise.kernel.common.AccessRightsException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) MappingException(org.exolab.castor.mapping.MappingException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ValidationException(org.exolab.castor.xml.ValidationException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) MarshalException(org.exolab.castor.xml.MarshalException) InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) IOException(java.io.IOException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Example 7 with AccessRightsException

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

the class Transition method getPerformingRole.

public String getPerformingRole(Activity act, AgentPath agent) throws ObjectNotFoundException, AccessRightsException {
    // check available
    if (!isEnabled(act))
        throw new AccessRightsException("Trans:" + toString() + " is disabled by the '" + enabledProp + "' property.");
    // check active
    if (isRequiresActive() && !act.getActive())
        throw new AccessRightsException("Activity must be active to perform trans:" + toString());
    String overridingRole = getRoleOverride(act.getProperties());
    boolean override = overridingRole != null;
    boolean isOwner = false, isOwned = true;
    // Check agent name
    String agentName = act.getCurrentAgentName();
    if (StringUtils.isNotBlank(agentName)) {
        if (agent.getAgentName().equals(agentName))
            isOwner = true;
    } else
        isOwned = false;
    List<RolePath> roles = new ArrayList<RolePath>();
    // determine transition role
    if (override) {
        roles.add(Gateway.getLookup().getRolePath(overridingRole));
    } else {
        String actRole = act.getCurrentAgentRole();
        if (StringUtils.isNotBlank(actRole)) {
            for (String role : actRole.split(",")) {
                roles.add(Gateway.getLookup().getRolePath(role.trim()));
            }
        }
    }
    // Decide the access
    if (isOwned && !override && !isOwner)
        throw new AccessRightsException("Agent '" + agent.getAgentName() + "' cannot perform this trans:" + toString() + " because the activity '" + act.getName() + "' is currently owned by " + agentName);
    if (roles.size() != 0) {
        RolePath matchingRole = agent.getFirstMatchingRole(roles);
        if (matchingRole != null)
            return matchingRole.getName();
        else if (agent.hasRole("Admin"))
            return "Admin";
        else
            throw new AccessRightsException("Agent '" + agent.getAgentName() + "' does not hold a suitable role '" + act.getCurrentAgentRole() + "' for the activity " + act.getName());
    } else
        return null;
}
Also used : AccessRightsException(org.cristalise.kernel.common.AccessRightsException) ArrayList(java.util.ArrayList) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 8 with AccessRightsException

use of org.cristalise.kernel.common.AccessRightsException 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)

Aggregations

AccessRightsException (org.cristalise.kernel.common.AccessRightsException)8 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)7 PersistencyException (org.cristalise.kernel.common.PersistencyException)7 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)6 IOException (java.io.IOException)5 InvalidTransitionException (org.cristalise.kernel.common.InvalidTransitionException)5 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)5 MappingException (org.exolab.castor.mapping.MappingException)5 MarshalException (org.exolab.castor.xml.MarshalException)5 ValidationException (org.exolab.castor.xml.ValidationException)5 CannotManageException (org.cristalise.kernel.common.CannotManageException)3 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)3 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)3 AgentPath (org.cristalise.kernel.lookup.AgentPath)3 InvalidAgentPathException (org.cristalise.kernel.lookup.InvalidAgentPathException)3 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)3 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)2 InvalidCollectionModification (org.cristalise.kernel.common.InvalidCollectionModification)2 JobArrayList (org.cristalise.kernel.entity.agent.JobArrayList)2 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)2