Search in sources :

Example 1 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef 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 2 with StoreRef

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

the class NodeArchiveServiceRestApiTest method testPurgeDeletedItems.

/**
 * This test method purges some deleted nodes from the archive store.
 */
public void testPurgeDeletedItems() throws Exception {
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    JSONObject archivedNodesJson = getArchivedNodes();
    JSONObject dataJsonObj = archivedNodesJson.getJSONObject("data");
    JSONArray archivedNodesArray = dataJsonObj.getJSONArray(AbstractArchivedNodeWebScript.DELETED_NODES);
    int archivedNodesLength = archivedNodesArray.length();
    assertTrue("Insufficient archived nodes for test to run.", archivedNodesLength > 1);
    // Take a specific archived node and purge it.
    JSONObject requiredNodeInArchive = null;
    for (int i = 0; i < archivedNodesLength; i++) {
        JSONObject archivedNode = archivedNodesArray.getJSONObject(i);
        // We ensure in #setUp() that this NodeRef will be in the archive store.
        if (archivedNode.getString(AbstractArchivedNodeWebScript.NODEREF).equals(adminDeletedTestNode.toString())) {
            requiredNodeInArchive = archivedNode;
            break;
        } else if (archivedNode.getString(AbstractArchivedNodeWebScript.NODEREF).equals(user1_DeletedTestNode.toString())) {
            requiredNodeInArchive = archivedNode;
            break;
        } else if (archivedNode.getString(AbstractArchivedNodeWebScript.NODEREF).equals(user2_DeletedTestNode.toString())) {
            requiredNodeInArchive = archivedNode;
            break;
        }
    }
    assertNotNull("Expected node not found in archive", requiredNodeInArchive);
    // So we have identified a specific Node in the archive that we want to delete permanently (purge).
    String nodeRefString = requiredNodeInArchive.getString(AbstractArchivedNodeWebScript.NODEREF);
    assertTrue("nodeRef string is invalid", NodeRef.isNodeRef(nodeRefString));
    NodeRef nodeRef = new NodeRef(nodeRefString);
    // This is not the StoreRef where the node originally lived e.g. workspace://SpacesStore
    // This is its current StoreRef i.e. archive://SpacesStore
    final StoreRef currentStoreRef = nodeRef.getStoreRef();
    String deleteUrl = getArchiveUrl(currentStoreRef) + "/" + nodeRef.getId();
    // Send the DELETE REST call.
    Response rsp = sendRequest(new DeleteRequest(deleteUrl), 200);
    JSONObject jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    JSONObject dataObj = jsonRsp.getJSONObject("data");
    JSONArray purgedNodesArray = dataObj.getJSONArray(ArchivedNodesDelete.PURGED_NODES);
    assertEquals("Only expected one NodeRef to have been purged.", 1, purgedNodesArray.length());
    // Now we'll purge all the other nodes in the archive that came from the same StoreRef.
    String deleteAllUrl = getArchiveUrl(this.nodesOriginalStoreRef);
    rsp = sendRequest(new DeleteRequest(deleteAllUrl), 200);
    jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    dataObj = jsonRsp.getJSONObject("data");
    purgedNodesArray = dataObj.getJSONArray(ArchivedNodesDelete.PURGED_NODES);
    // Now retrieve all items from the archive store. There should be none.
    assertEquals("Archive store was unexpectedly not empty", 0, getArchivedNodesCount());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) NodeRef(org.alfresco.service.cmr.repository.NodeRef) StoreRef(org.alfresco.service.cmr.repository.StoreRef) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 3 with StoreRef

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

the class NodeArchiveServiceRestApiTest method testRestoreDeletedItems.

/**
 * This test method restores some deleted nodes from the archive store.
 */
public void testRestoreDeletedItems() throws Exception {
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    JSONObject archivedNodesJson = getArchivedNodes();
    JSONObject dataJsonObj = archivedNodesJson.getJSONObject("data");
    JSONArray archivedNodesArray = dataJsonObj.getJSONArray(AbstractArchivedNodeWebScript.DELETED_NODES);
    int archivedNodesLength = archivedNodesArray.length();
    assertTrue("Insufficient archived nodes for test to run.", archivedNodesLength > 1);
    // Take a specific archived node and restore it.
    JSONObject firstArchivedNode = archivedNodesArray.getJSONObject(0);
    // So we have identified a specific Node in the archive that we want to restore.
    String nodeRefString = firstArchivedNode.getString(AbstractArchivedNodeWebScript.NODEREF);
    assertTrue("nodeRef string is invalid", NodeRef.isNodeRef(nodeRefString));
    NodeRef nodeRef = new NodeRef(nodeRefString);
    // This is not the StoreRef where the node originally lived e.g. workspace://SpacesStore
    // This is its current StoreRef i.e. archive://SpacesStore
    final StoreRef currentStoreRef = nodeRef.getStoreRef();
    String restoreUrl = getArchiveUrl(currentStoreRef) + "/" + nodeRef.getId();
    int archivedNodesCountBeforeRestore = getArchivedNodesCount();
    // Send the PUT REST call.
    String jsonString = new JSONStringer().object().key("restoreLocation").value("").endObject().toString();
    Response rsp = sendRequest(new PutRequest(restoreUrl, jsonString, "application/json"), 200);
    assertEquals("Expected archive to shrink by one", archivedNodesCountBeforeRestore - 1, getArchivedNodesCount());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) NodeRef(org.alfresco.service.cmr.repository.NodeRef) StoreRef(org.alfresco.service.cmr.repository.StoreRef) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest) JSONStringer(org.json.JSONStringer)

Example 4 with StoreRef

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

the class TaggingServiceTest method tearDown.

@Override
protected void tearDown() throws Exception {
    super.tearDown();
    this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
    this.taggingService.deleteTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_1);
    this.taggingService.deleteTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_2);
    this.taggingService.deleteTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_3);
    this.taggingService.deleteTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_4);
    this.taggingService.deleteTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_5);
    this.nodeService.deleteNode(this.nodeOne);
    this.nodeService.deleteNode(this.nodeTwo);
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef)

Example 5 with StoreRef

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

the class TaggingServiceTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
    this.authenticationComponent = (AuthenticationComponent) getServer().getApplicationContext().getBean("authenticationComponent");
    this.personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
    this.taggingService = (TaggingService) getServer().getApplicationContext().getBean("TaggingService");
    this.fileFolderService = (FileFolderService) getServer().getApplicationContext().getBean("FileFolderService");
    this.repositoryHelper = (Repository) getServer().getApplicationContext().getBean("repositoryHelper");
    this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
    this.authenticationComponent.setSystemUserAsCurrentUser();
    // Add a load of tags ready to use
    this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_1);
    this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_2);
    this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_3);
    this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_4);
    this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_5);
    // Create test node's
    NodeRef testRoot = this.repositoryHelper.getCompanyHome();
    String guid = GUID.generate();
    this.nodeOne = this.fileFolderService.create(testRoot, "test_doc1" + guid + ".txt", ContentModel.TYPE_CONTENT).getNodeRef();
    this.nodeTwo = this.fileFolderService.create(testRoot, "test_dco2" + guid + ".txt", ContentModel.TYPE_CONTENT).getNodeRef();
    // Add tags to test nodes
    this.taggingService.addTag(nodeOne, TAG_1);
    this.taggingService.addTag(nodeOne, TAG_2);
    this.taggingService.addTag(nodeTwo, TAG_2);
    // Create users
    createUser(TEST_USER);
    // Do tests as user one
    this.authenticationComponent.setCurrentUser(TEST_USER);
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Aggregations

StoreRef (org.alfresco.service.cmr.repository.StoreRef)67 NodeRef (org.alfresco.service.cmr.repository.NodeRef)50 HashMap (java.util.HashMap)18 QName (org.alfresco.service.namespace.QName)17 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)13 StringPropertyValue (org.alfresco.solr.client.StringPropertyValue)13 PropertyValue (org.alfresco.solr.client.PropertyValue)11 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)10 ArrayList (java.util.ArrayList)9 ContentPropertyValue (org.alfresco.solr.client.ContentPropertyValue)9 MLTextPropertyValue (org.alfresco.solr.client.MLTextPropertyValue)9 IOException (java.io.IOException)7 Date (java.util.Date)6 MultiPropertyValue (org.alfresco.solr.client.MultiPropertyValue)6 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)5 PermissionService (org.alfresco.service.cmr.security.PermissionService)5 SolrCore (org.apache.solr.core.SolrCore)5 StringTokenizer (java.util.StringTokenizer)4 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)4 ServiceRegistry (org.alfresco.service.ServiceRegistry)4