Search in sources :

Example 51 with EntityNotFoundException

use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.

the class ActionsImpl method executeAction.

@Override
public Action executeAction(Action action, Parameters parameters) {
    if (action == null) {
        throw new InvalidArgumentException("action is null");
    }
    if (action.getActionDefinitionId() == null || action.getActionDefinitionId().isEmpty()) {
        throw new InvalidArgumentException("action.actionDefinitionId is null or empty");
    }
    org.alfresco.service.cmr.action.ActionDefinition actionDef = null;
    try {
        actionDef = actionService.getActionDefinition(action.getActionDefinitionId());
    } catch (NoSuchBeanDefinitionException nsbdx) {
    // Intentionally empty.
    }
    // the result of getActionDefinition can be null and not throw the exception.
    if (actionDef == null) {
        throw new EntityNotFoundException(action.getActionDefinitionId());
    }
    // targetId is optional, however, currently targetId must be a valid node ID.
    NodeRef actionedUponNodeRef = null;
    if (action.getTargetId() != null && !action.getTargetId().isEmpty()) {
        // Does it exist in the repo?
        actionedUponNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, action.getTargetId());
        if (!nodeService.exists(actionedUponNodeRef)) {
            throw new EntityNotFoundException(action.getTargetId());
        }
    }
    org.alfresco.service.cmr.action.Action cmrAction;
    if (action.getParams() != null && !action.getParams().isEmpty()) {
        cmrAction = actionService.createAction(action.getActionDefinitionId(), extractActionParams(actionDef, action.getParams()));
    } else {
        cmrAction = actionService.createAction(action.getActionDefinitionId());
    }
    actionService.executeAction(cmrAction, actionedUponNodeRef, true, true);
    // Create user result.
    Action result = new Action();
    result.setId(cmrAction.getId());
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Action(org.alfresco.rest.api.model.Action) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Example 52 with EntityNotFoundException

use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.

the class ActivitiesImpl method getUserActivities.

public CollectionWithPagingInfo<Activity> getUserActivities(String personId, final Parameters parameters) {
    personId = people.validatePerson(personId);
    Paging paging = parameters.getPaging();
    String siteId = parameters.getParameter("siteId");
    String who = parameters.getParameter("who");
    ActivityWho activityWho = null;
    if (who != null) {
        try {
            activityWho = ActivityWho.valueOf(who);
        } catch (IllegalArgumentException e) {
            throw new InvalidArgumentException("Parameter who should be one of " + Arrays.toString(ActivityWho.values()));
        }
    }
    if (siteId != null && !siteId.equals("")) {
        SiteInfo siteInfo = sites.validateSite(siteId);
        if (siteInfo == null) {
            // site does not exist
            throw new EntityNotFoundException(siteId);
        }
        // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
        siteId = siteInfo.getShortName();
    }
    try {
        PagingResults<ActivityFeedEntity> activities = null;
        if (activityWho == null) {
            activities = activityService.getPagedUserFeedEntries(personId, siteId, false, false, -1, Util.getPagingRequest(paging));
        } else if (activityWho.equals(ActivityWho.me)) {
            activities = activityService.getPagedUserFeedEntries(personId, siteId, false, true, -1, Util.getPagingRequest(paging));
        } else if (activityWho.equals(ActivityWho.others)) {
            activities = activityService.getPagedUserFeedEntries(personId, siteId, true, false, -1, Util.getPagingRequest(paging));
        } else {
            throw new InvalidArgumentException("Who argument is invalid.");
        }
        List<ActivityFeedEntity> feedEntities = activities.getPage();
        List<Activity> ret = new ArrayList<Activity>(feedEntities.size());
        for (ActivityFeedEntity entity : feedEntities) {
            String feedSiteId = getSiteId(entity.getSiteNetwork());
            String networkId = tenantService.getDomain(entity.getSiteNetwork());
            Activity activity = new Activity(entity.getId(), networkId, feedSiteId, entity.getFeedUserId(), entity.getPostUserId(), entity.getPostDate(), entity.getActivityType(), getActivitySummary(entity));
            ret.add(activity);
        }
        return CollectionWithPagingInfo.asPaged(paging, ret, activities.hasMoreItems(), activities.getTotalResultCount().getFirst());
    } catch (JSONException e) {
        throw new AlfrescoRuntimeException("", e);
    }
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) Activity(org.alfresco.rest.api.model.Activity) JSONException(org.json.JSONException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ActivityFeedEntity(org.alfresco.repo.domain.activities.ActivityFeedEntity) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 53 with EntityNotFoundException

use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.

the class AuditImpl method getAuditEntry.

@Override
public AuditEntry getAuditEntry(String auditAppId, long auditEntryId, Parameters parameters) {
    checkEnabled();
    AuditService.AuditApplication auditApplication = findAuditAppByIdOr404(auditAppId);
    // Execute the query
    AuditQueryParameters params = new AuditQueryParameters();
    params.setApplicationName(auditApplication.getName());
    params.setFromId(auditEntryId);
    params.setToId(auditEntryId + 1);
    List<String> includeParam = new ArrayList<>();
    if (parameters != null) {
        includeParam.addAll(parameters.getInclude());
    }
    // Add values for single get
    includeParam.add(PARAM_INCLUDE_VALUES);
    final List<AuditEntry> results = new ArrayList<>();
    // create the callback for auditQuery method
    final AuditQueryCallback callback = new AuditQueryCallback() {

        public boolean valuesRequired() {
            return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES)));
        }

        public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error) {
            throw new AlfrescoRuntimeException("Failed to retrieve audit data.", error);
        }

        public boolean handleAuditEntry(Long entryId, String applicationName, String userName, long time, Map<String, Serializable> values) {
            UserInfo userInfo = Node.lookupUserInfo(userName, new HashMap<>(0), personService);
            AuditEntry auditEntry = new AuditEntry(entryId, auditAppId, userInfo, new Date(time), values);
            results.add(auditEntry);
            return true;
        }
    };
    auditService.auditQuery(callback, params, 1);
    if (results.size() != 1) {
        throw new EntityNotFoundException("" + auditEntryId);
    }
    return results.get(0);
}
Also used : AuditQueryParameters(org.alfresco.service.cmr.audit.AuditQueryParameters) ArrayList(java.util.ArrayList) UserInfo(org.alfresco.rest.api.model.UserInfo) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) Date(java.util.Date) AuditApplication(org.alfresco.service.cmr.audit.AuditService.AuditApplication) AuditEntry(org.alfresco.rest.api.model.AuditEntry) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) AuditQueryCallback(org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback) AuditService(org.alfresco.service.cmr.audit.AuditService) HashMap(java.util.HashMap) Map(java.util.Map)

Example 54 with EntityNotFoundException

use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.

the class DeploymentsImpl method getDeployment.

@Override
public Deployment getDeployment(String deploymentId) {
    // Only admin-user is allowed to get deployments
    if (!authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser())) {
        throw new PermissionDeniedException();
    }
    RepositoryService repositoryService = activitiProcessEngine.getRepositoryService();
    DeploymentQuery query = repositoryService.createDeploymentQuery().deploymentId(deploymentId);
    if (tenantService.isEnabled() && deployWorkflowsInTenant) {
        query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
    }
    org.activiti.engine.repository.Deployment deployment = null;
    try {
        deployment = query.singleResult();
    } catch (ActivitiException e) {
        // The next exception will cause a response status 400: Bad request
        throw new InvalidArgumentException("Invalid deployment id: " + deploymentId);
    }
    if (deployment == null) {
        // The next exception will cause a response status 404: Not found
        throw new EntityNotFoundException(deploymentId);
    }
    Deployment deploymentRest = new Deployment(deployment);
    return deploymentRest;
}
Also used : DeploymentQuery(org.activiti.engine.repository.DeploymentQuery) ActivitiException(org.activiti.engine.ActivitiException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Deployment(org.alfresco.rest.workflow.api.model.Deployment) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) RepositoryService(org.activiti.engine.RepositoryService)

Example 55 with EntityNotFoundException

use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.

the class ProcessDefinitionsImpl method getProcessDefinitionImage.

@Override
public BinaryResource getProcessDefinitionImage(String definitionId) {
    ProcessDefinitionQuery query = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionId(definitionId);
    if (tenantService.isEnabled() && deployWorkflowsInTenant) {
        query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
    }
    org.activiti.engine.repository.ProcessDefinition processDefinition = query.singleResult();
    if (processDefinition == null) {
        throw new EntityNotFoundException(definitionId);
    }
    try {
        InputStream processDiagram = activitiProcessEngine.getRepositoryService().getProcessDiagram(definitionId);
        if (processDiagram != null) {
            File file = TempFileProvider.createTempFile(definitionId + UUID.randomUUID(), ".png");
            FileOutputStream fos = new FileOutputStream(file);
            IOUtils.copy(processDiagram, fos);
            fos.close();
            return new FileBinaryResource(file);
        } else {
            throw new ApiException("No image available for definitionId " + definitionId);
        }
    } catch (IOException error) {
        throw new ApiException("Error while getting process definition image.");
    }
}
Also used : InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) IOException(java.io.IOException) File(java.io.File) FileBinaryResource(org.alfresco.rest.framework.resource.content.FileBinaryResource) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Aggregations

EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)66 NodeRef (org.alfresco.service.cmr.repository.NodeRef)28 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)24 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)16 QName (org.alfresco.service.namespace.QName)15 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)12 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)12 HashMap (java.util.HashMap)11 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)11 ArrayList (java.util.ArrayList)9 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)8 InvalidSharedIdException (org.alfresco.service.cmr.quickshare.InvalidSharedIdException)7 Serializable (java.io.Serializable)6 FileInfo (org.alfresco.service.cmr.model.FileInfo)6 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)5 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)5 ActivitiScriptNode (org.alfresco.repo.workflow.activiti.ActivitiScriptNode)5 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)5 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)4 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)4