Search in sources :

Example 51 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class NodeBrowserPost method getPrimaryParent.

/**
 * Gets the current node primary parent reference
 *
 * @return primary parent ref
 */
public NodeRef getPrimaryParent(NodeRef nodeRef) {
    Path primaryPath = getNodeService().getPath(nodeRef);
    Path.Element element = primaryPath.last();
    NodeRef parentRef = ((Path.ChildAssocElement) element).getRef().getParentRef();
    return parentRef;
}
Also used : Path(org.alfresco.service.cmr.repository.Path) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Example 52 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class ArchivedNodesDelete method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    // Current user
    String userID = AuthenticationUtil.getFullyAuthenticatedUser();
    if (userID == null) {
        throw new WebScriptException(HttpServletResponse.SC_UNAUTHORIZED, "Web Script [" + req.getServiceMatch().getWebScript().getDescription() + "] requires user authentication.");
    }
    StoreRef storeRef = parseRequestForStoreRef(req);
    NodeRef nodeRef = parseRequestForNodeRef(req);
    List<NodeRef> nodesToBePurged = new ArrayList<NodeRef>();
    if (nodeRef != null) {
        // check if the current user has the permission to purge the node
        validatePermission(nodeRef, userID);
        // If there is a specific NodeRef, then that is the only Node that should be purged.
        // In this case, the NodeRef points to the actual node to be purged i.e. the node in
        // the archive store.
        nodesToBePurged.add(nodeRef);
    } else {
        // But if there is no specific NodeRef and instead there is only a StoreRef, then
        // all nodes which were originally in that StoreRef should be purged.
        // Create paging
        ScriptPagingDetails paging = new ScriptPagingDetails(maxSizeView, 0);
        PagingResults<NodeRef> result = getArchivedNodesFrom(storeRef, paging, null);
        nodesToBePurged.addAll(result.getPage());
    }
    if (log.isDebugEnabled()) {
        log.debug("Purging " + nodesToBePurged.size() + " nodes");
    }
    // Now having identified the nodes to be purged, we simply have to do it.
    nodeArchiveService.purgeArchivedNodes(nodesToBePurged);
    model.put(PURGED_NODES, nodesToBePurged);
    return model;
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ScriptPagingDetails(org.alfresco.util.ScriptPagingDetails)

Example 53 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class WorkflowRestImpl method getItemFromProcess.

/**
 * Get an item from the process package variable
 */
public Item getItemFromProcess(String itemId, String processId) {
    NodeRef nodeRef = getNodeRef(itemId);
    ActivitiScriptNode packageScriptNode = null;
    try {
        HistoricVariableInstance variableInstance = activitiProcessEngine.getHistoryService().createHistoricVariableInstanceQuery().processInstanceId(processId).variableName(BPM_PACKAGE).singleResult();
        if (variableInstance != null) {
            packageScriptNode = (ActivitiScriptNode) variableInstance.getValue();
        } else {
            throw new EntityNotFoundException(processId);
        }
    } catch (ActivitiObjectNotFoundException e) {
        throw new EntityNotFoundException(processId);
    }
    Item item = null;
    if (packageScriptNode != null) {
        List<ChildAssociationRef> documentList = nodeService.getChildAssocs(packageScriptNode.getNodeRef());
        for (ChildAssociationRef childAssociationRef : documentList) {
            if (childAssociationRef.getChildRef().equals(nodeRef)) {
                item = createItemForNodeRef(childAssociationRef.getChildRef());
                break;
            }
        }
    }
    if (item == null) {
        throw new EntityNotFoundException(itemId);
    }
    return item;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Item(org.alfresco.rest.workflow.api.model.Item) ActivitiScriptNode(org.alfresco.repo.workflow.activiti.ActivitiScriptNode) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 54 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class WorkflowRestImpl method validateIfUserAllowedToWorkWithProcess.

/**
 * Validates if the logged in user is allowed to get information about a specific process instance.
 * If the user is not allowed an exception is thrown.
 *
 * @param processId identifier of the process instance
 */
protected List<HistoricVariableInstance> validateIfUserAllowedToWorkWithProcess(String processId) {
    List<HistoricVariableInstance> variableInstances = activitiProcessEngine.getHistoryService().createHistoricVariableInstanceQuery().processInstanceId(processId).list();
    Map<String, Object> variableMap = new HashMap<String, Object>();
    if (variableInstances != null && variableInstances.size() > 0) {
        for (HistoricVariableInstance variableInstance : variableInstances) {
            variableMap.put(variableInstance.getVariableName(), variableInstance.getValue());
        }
    } else {
        throw new EntityNotFoundException(processId);
    }
    if (tenantService.isEnabled()) {
        String tenantDomain = (String) variableMap.get(ActivitiConstants.VAR_TENANT_DOMAIN);
        if (TenantUtil.getCurrentDomain().equals(tenantDomain) == false) {
            throw new PermissionDeniedException("Process is running in another tenant");
        }
    }
    // MNT-17918 - required for initiator variable already updated as NodeRef type
    Object initiator = variableMap.get(WorkflowConstants.PROP_INITIATOR);
    String nodeId = ((initiator instanceof ActivitiScriptNode) ? ((ActivitiScriptNode) initiator).getNodeRef().getId() : ((NodeRef) initiator).getId());
    if (initiator != null && AuthenticationUtil.getRunAsUser().equals(nodeId)) {
        // user is allowed
        return variableInstances;
    }
    String username = AuthenticationUtil.getRunAsUser();
    if (authorityService.isAdminAuthority(username)) {
        // Admin is allowed to read all processes in the current tenant
        return variableInstances;
    } else {
        // MNT-12382 check for membership in the assigned group
        ActivitiScriptNode group = (ActivitiScriptNode) variableMap.get("bpm_groupAssignee");
        if (group != null) {
            // check that the process is unclaimed
            Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processId).singleResult();
            if ((task != null) && (task.getAssignee() == null) && isUserInGroup(username, group.getNodeRef())) {
                return variableInstances;
            }
        }
        // If non-admin user, involvement in the task is required (either owner, assignee or externally involved).
        HistoricTaskInstanceQuery query = activitiProcessEngine.getHistoryService().createHistoricTaskInstanceQuery().processInstanceId(processId).taskInvolvedUser(AuthenticationUtil.getRunAsUser());
        List<HistoricTaskInstance> taskList = query.list();
        if (org.apache.commons.collections.CollectionUtils.isEmpty(taskList)) {
            throw new PermissionDeniedException("user is not allowed to access information about process " + processId);
        }
    }
    return variableInstances;
}
Also used : Task(org.activiti.engine.task.Task) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HashMap(java.util.HashMap) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ActivitiScriptNode(org.alfresco.repo.workflow.activiti.ActivitiScriptNode) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)

Example 55 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class RemoteFileFolderLoaderTest method testLoad_15_16bytes.

/**
 * Load 15 files; 1K size; 1 document sample; force binary storage
 */
@SuppressWarnings("unchecked")
public void testLoad_15_16bytes() throws Exception {
    JSONObject body = new JSONObject();
    body.put(FileFolderLoaderPost.KEY_FOLDER_PATH, loadHomePath);
    body.put(FileFolderLoaderPost.KEY_MIN_FILE_SIZE, 16L);
    body.put(FileFolderLoaderPost.KEY_MAX_FILE_SIZE, 16L);
    body.put(FileFolderLoaderPost.KEY_MAX_UNIQUE_DOCUMENTS, 1L);
    body.put(FileFolderLoaderPost.KEY_FORCE_BINARY_STORAGE, Boolean.TRUE);
    Response response = null;
    try {
        AuthenticationUtil.pushAuthentication();
        AuthenticationUtil.setFullyAuthenticatedUser("maggi");
        response = sendRequest(new PostRequest(URL, body.toString(), "application/json"), Status.STATUS_OK, "maggi");
    } finally {
        AuthenticationUtil.popAuthentication();
    }
    assertEquals("{\"count\":100}", response.getContentAsString());
    // Check file(s)
    assertEquals(100, nodeService.countChildAssocs(loadHomeNodeRef, true));
    // Consistent binary text
    String contentUrlCheck = SpoofedTextContentReader.createContentUrl(Locale.ENGLISH, 0L, 16L);
    ContentReader readerCheck = new SpoofedTextContentReader(contentUrlCheck);
    String textCheck = readerCheck.getContentString();
    // Size should be default
    List<FileInfo> fileInfos = fileFolderService.list(loadHomeNodeRef);
    for (FileInfo fileInfo : fileInfos) {
        NodeRef fileNodeRef = fileInfo.getNodeRef();
        ContentReader reader = fileFolderService.getReader(fileNodeRef);
        // Expect storage in store
        assertTrue(reader.getContentUrl().startsWith(FileContentStore.STORE_PROTOCOL));
        // Check text
        String text = reader.getContentString();
        assertEquals("Text not the same.", textCheck, text);
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.simple.JSONObject) FileInfo(org.alfresco.service.cmr.model.FileInfo) SpoofedTextContentReader(org.alfresco.repo.content.filestore.SpoofedTextContentReader) SpoofedTextContentReader(org.alfresco.repo.content.filestore.SpoofedTextContentReader) ContentReader(org.alfresco.service.cmr.repository.ContentReader)

Aggregations

NodeRef (org.alfresco.service.cmr.repository.NodeRef)1239 HashMap (java.util.HashMap)244 QName (org.alfresco.service.namespace.QName)242 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)209 Test (org.junit.Test)195 ArrayList (java.util.ArrayList)159 Serializable (java.io.Serializable)136 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)104 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)101 FileInfo (org.alfresco.service.cmr.model.FileInfo)82 Map (java.util.Map)81 Node (org.alfresco.web.bean.repository.Node)81 JSONObject (org.json.JSONObject)80 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)74 FacesContext (javax.faces.context.FacesContext)61 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)59 List (java.util.List)58 IOException (java.io.IOException)55 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)52 Date (java.util.Date)51