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