Search in sources :

Example 81 with NodeRef

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

the class WebDAVMethodTest method expiryLockTest.

/* MNT-10555 Test */
@Test
public void expiryLockTest() {
    // ACE-4347 extra debug logging just for this test so we can see what's going on when it next fails
    Level repoWebdavSaveLogLevel = Logger.getLogger("org.alfresco.repo.webdav").getLevel();
    Logger.getLogger("org.alfresco.repo.webdav").setLevel(Level.ALL);
    Level webdavProtocolSaveLogLevel = Logger.getLogger("org.alfresco.webdav.protocol").getLevel();
    Logger.getLogger("org.alfresco.webdav.protocol").setLevel(Level.ALL);
    try {
        setUpApplicationContext();
        req = new MockHttpServletRequest();
        resp = new MockHttpServletResponse();
        String rootPath = "/app:company_home";
        StoreRef storeRef = new StoreRef("workspace://SpacesStore");
        NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
        List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, rootPath, null, namespaceService, false);
        NodeRef defaultRootNode = nodeRefs.get(0);
        NodeRef rootNodeRef = tenantService.getRootNode(nodeService, searchService, namespaceService, rootPath, defaultRootNode);
        // Create test folder.
        NodeRef folderNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("test"), ContentModel.TYPE_FOLDER, Collections.<QName, Serializable>singletonMap(ContentModel.PROP_NAME, "WebDavMethodExpiryLockTest" + System.currentTimeMillis())).getChildRef();
        // Create test document.
        NodeRef nodeRef = nodeService.createNode(folderNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("test"), ContentModel.TYPE_CONTENT, Collections.<QName, Serializable>singletonMap(ContentModel.PROP_NAME, "text.txt")).getChildRef();
        lockMethod = new LockMethod();
        lockMethod.createExclusive = true;
        lockMethod.m_timeoutDuration = 1;
        lockMethod.setDetails(req, resp, webDAVHelper, nodeRef);
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Object>() {

            @Override
            public Object execute() throws Throwable {
                try {
                    // LOCK document.
                    lockMethod.executeImpl();
                    // wait for the lock to expire up to 5 seconds
                    int timeout = 5;
                    while (timeout > 0 && !lockMethod.lockInfo.isExpired()) {
                        Thread.sleep(1000);
                        timeout--;
                    }
                    // LOCK against an expired lock.
                    lockMethod.executeImpl();
                } catch (WebDAVServerException e) {
                    logger.debug(e);
                    Assert.fail("Document was not locked again, when lock has expired.");
                }
                return null;
            }
        });
        // Remove test folder.
        nodeService.deleteNode(folderNodeRef);
    } finally {
        Logger.getLogger("org.alfresco.webdav.protocol").setLevel(webdavProtocolSaveLogLevel);
        Logger.getLogger("org.alfresco.repo.webdav").setLevel(repoWebdavSaveLogLevel);
    }
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) Serializable(java.io.Serializable) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) QName(org.alfresco.service.namespace.QName) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Level(org.apache.log4j.Level) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 82 with NodeRef

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

the class ResultMapperTests method mockResultset.

private ResultSet mockResultset(List<Long> archivedNodes, List<Long> versionNodes) throws JSONException {
    NodeService nodeService = mock(NodeService.class);
    when(nodeService.getNodeRef(any())).thenAnswer(new Answer<NodeRef>() {

        @Override
        public NodeRef answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            // If the DBID is in the list archivedNodes, instead of returning a noderef return achivestore noderef
            if (archivedNodes.contains(args[0]))
                return new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, GUID.generate());
            if (versionNodes.contains(args[0]))
                return new NodeRef(StoreMapper.STORE_REF_VERSION2_SPACESSTORE, GUID.generate() + args[0]);
            return new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate());
        }
    });
    SearchParameters sp = new SearchParameters();
    sp.setBulkFetchEnabled(false);
    JSONObject json = new JSONObject(new JSONTokener(JSON_REPONSE));
    ResultSet results = new SolrJSONResultSet(json, sp, nodeService, null, LimitBy.FINAL_SIZE, 10);
    return results;
}
Also used : JSONTokener(org.json.JSONTokener) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) JSONObject(org.json.JSONObject) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NodeService(org.alfresco.service.cmr.repository.NodeService) ResultSet(org.alfresco.service.cmr.search.ResultSet) EmptyResultSet(org.alfresco.repo.search.EmptyResultSet) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)

Example 83 with NodeRef

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

the class ResultMapperTests method setupTests.

@BeforeClass
public static void setupTests() throws Exception {
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    mapUserInfo.put(AuthenticationUtil.getSystemUserName(), new UserInfo(AuthenticationUtil.getSystemUserName(), "sys", "sys"));
    Map<QName, Serializable> nodeProps = new HashMap<>();
    NodesImpl nodes = mock(NodesImpl.class);
    ServiceRegistry sr = mock(ServiceRegistry.class);
    DeletedNodes deletedNodes = mock(DeletedNodes.class);
    nodes.setServiceRegistry(sr);
    VersionService versionService = mock(VersionService.class);
    VersionHistory versionHistory = mock(VersionHistory.class);
    Map<String, Serializable> versionProperties = new HashMap<>();
    versionProperties.put(Version.PROP_DESCRIPTION, "ver desc");
    versionProperties.put(Version2Model.PROP_VERSION_TYPE, "v type");
    when(versionHistory.getVersion(anyString())).thenAnswer(invocation -> {
        return new VersionImpl(versionProperties, new NodeRef(StoreMapper.STORE_REF_VERSION2_SPACESSTORE, GUID.generate()));
    });
    NodeService nodeService = mock(NodeService.class);
    when(versionService.getVersionHistory(notNull(NodeRef.class))).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        NodeRef aNode = (NodeRef) args[0];
        return versionHistory;
    });
    when(nodeService.getProperties(notNull(NodeRef.class))).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        NodeRef aNode = (NodeRef) args[0];
        if (StoreMapper.STORE_REF_VERSION2_SPACESSTORE.equals(aNode.getStoreRef())) {
            nodeProps.put(Version2Model.PROP_QNAME_FROZEN_NODE_REF, new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, FROZEN_ID + aNode.getId()));
            nodeProps.put(Version2Model.PROP_QNAME_VERSION_LABEL, FROZEN_VER);
        }
        return nodeProps;
    });
    when(sr.getVersionService()).thenReturn(versionService);
    when(sr.getNodeService()).thenReturn(nodeService);
    when(nodes.validateOrLookupNode(notNull(String.class), anyString())).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        String aNode = (String) args[0];
        if (aNode.endsWith("" + VERSIONED_ID)) {
            throw new EntityNotFoundException("" + VERSIONED_ID);
        } else {
            return new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, aNode);
        }
    });
    // // NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
    when(nodes.getFolderOrDocument(notNull(NodeRef.class), any(), any(), any(), any())).thenAnswer(new Answer<Node>() {

        @Override
        public Node answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            NodeRef aNode = (NodeRef) args[0];
            if (StoreRef.STORE_REF_ARCHIVE_SPACESSTORE.equals(aNode.getStoreRef())) {
                // Return NULL if its from the archive store.
                return null;
            }
            return new Node(aNode, (NodeRef) args[1], nodeProps, mapUserInfo, sr);
        }
    });
    when(deletedNodes.getDeletedNode(notNull(String.class), any(), anyBoolean(), any())).thenAnswer(new Answer<Node>() {

        @Override
        public Node answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            String nodeId = (String) args[0];
            if (FROZEN_ID.equals(nodeId))
                throw new EntityNotFoundException(nodeId);
            NodeRef aNode = new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, nodeId);
            return new Node(aNode, new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, "unknown"), nodeProps, mapUserInfo, sr);
        }
    });
    PersonPropertyLookup propertyLookups = mock(PersonPropertyLookup.class);
    when(propertyLookups.supports()).thenReturn(Stream.of("creator", "modifier").collect(Collectors.toSet()));
    when(propertyLookups.lookup(notNull(String.class))).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        String value = (String) args[0];
        if ("mjackson".equals(value))
            return "Michael Jackson";
        return null;
    });
    PropertyLookupRegistry propertyLookupRegistry = new PropertyLookupRegistry();
    propertyLookupRegistry.setLookups(Arrays.asList(propertyLookups));
    mapper = new ResultMapper();
    mapper.setNodes(nodes);
    mapper.setStoreMapper(new StoreMapper());
    mapper.setPropertyLookup(propertyLookupRegistry);
    mapper.setDeletedNodes(deletedNodes);
    mapper.setServiceRegistry(sr);
    NodeVersionsRelation nodeVersionsRelation = new NodeVersionsRelation();
    nodeVersionsRelation.setNodes(nodes);
    nodeVersionsRelation.setServiceRegistry(sr);
    nodeVersionsRelation.afterPropertiesSet();
    mapper.setNodeVersions(nodeVersionsRelation);
    helper = new SerializerTestHelper();
    searchMapper.setStoreMapper(new StoreMapper());
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) Node(org.alfresco.rest.api.model.Node) StoreMapper(org.alfresco.rest.api.search.impl.StoreMapper) VersionService(org.alfresco.service.cmr.version.VersionService) UserInfo(org.alfresco.rest.api.model.UserInfo) Matchers.anyString(org.mockito.Matchers.anyString) VersionImpl(org.alfresco.repo.version.common.VersionImpl) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DeletedNodes(org.alfresco.rest.api.DeletedNodes) QName(org.alfresco.service.namespace.QName) PersonPropertyLookup(org.alfresco.rest.api.lookups.PersonPropertyLookup) NodeService(org.alfresco.service.cmr.repository.NodeService) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) NodesImpl(org.alfresco.rest.api.impl.NodesImpl) PropertyLookupRegistry(org.alfresco.rest.api.lookups.PropertyLookupRegistry) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResultMapper(org.alfresco.rest.api.search.impl.ResultMapper) JSONObject(org.json.JSONObject) ServiceRegistry(org.alfresco.service.ServiceRegistry) NodeVersionsRelation(org.alfresco.rest.api.nodes.NodeVersionsRelation) BeforeClass(org.junit.BeforeClass)

Example 84 with NodeRef

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

the class ReplicationRestApiTest method testReplicationDefinitionGet.

public void testReplicationDefinitionGet() throws Exception {
    Response response;
    // Not allowed if you're not an admin
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
    response = sendRequest(new GetRequest(URL_DEFINITION + "madeup"), Status.STATUS_UNAUTHORIZED);
    assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
    AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
    response = sendRequest(new GetRequest(URL_DEFINITION + "madeup"), Status.STATUS_UNAUTHORIZED);
    assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
    // If an invalid name is given, you get a 404
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    response = sendRequest(new GetRequest(URL_DEFINITION + "madeup"), 404);
    assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
    // Add a definition, it should show up
    ReplicationDefinition rd = replicationService.createReplicationDefinition("Test1", "Testing");
    replicationService.saveReplicationDefinition(rd);
    response = sendRequest(new GetRequest(URL_DEFINITION + "Test1"), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    String jsonStr = response.getContentAsString();
    JSONObject json = new JSONObject(jsonStr).getJSONObject("data");
    assertNotNull(json);
    // Check
    assertEquals("Test1", json.get("name"));
    assertEquals("Testing", json.get("description"));
    assertEquals("New", json.get("status"));
    assertEquals(JSONObject.NULL, json.get("startedAt"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals(JSONObject.NULL, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(true, json.get("enabled"));
    assertEquals(JSONObject.NULL, json.get("targetName"));
    // Payload is empty
    assertEquals(0, json.getJSONArray("payload").length());
    // Ensure we didn't get any unexpected data back
    JSONArray keys = json.names();
    for (int i = 0; i < keys.length(); i++) {
        String key = keys.getString(0);
        if (key.equals("name") || key.equals("description") || key.equals("status") || key.equals("startedAt") || key.equals("endedAt") || key.equals("failureMessage") || key.equals("executionDetails") || key.equals("payload") || key.equals("transferLocalReport") || key.equals("transferRemoteReport") || key.equals("enabled") || key.equals("targetName") || key.equals("schedule")) {
        // All good
        } else {
            fail("Unexpected key '" + key + "' found in json, raw json is\n" + jsonStr);
        }
    }
    // Mark it as pending, and check
    actionTrackingService.recordActionPending(rd);
    String actionId = rd.getId();
    int instanceId = ((ActionImpl) rd).getExecutionInstance();
    response = sendRequest(new GetRequest(URL_DEFINITION + "Test1"), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    assertEquals("Test1", json.get("name"));
    assertEquals("Testing", json.get("description"));
    assertEquals("Pending", json.get("status"));
    assertEquals(JSONObject.NULL, json.get("startedAt"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(true, json.get("enabled"));
    assertEquals(JSONObject.NULL, json.get("targetName"));
    // Payload is empty
    assertEquals(0, json.getJSONArray("payload").length());
    // Change the status to running, and re-check
    actionTrackingService.recordActionExecuting(rd);
    assertEquals(actionId, rd.getId());
    assertEquals(instanceId, ((ActionImpl) rd).getExecutionInstance());
    String startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
    response = sendRequest(new GetRequest(URL_DEFINITION + "Test1"), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    assertEquals("Test1", json.get("name"));
    assertEquals("Testing", json.get("description"));
    assertEquals("Running", json.get("status"));
    assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(true, json.get("enabled"));
    assertEquals(JSONObject.NULL, json.get("targetName"));
    // Payload is empty
    assertEquals(0, json.getJSONArray("payload").length());
    // Cancel it
    actionTrackingService.requestActionCancellation(rd);
    response = sendRequest(new GetRequest(URL_DEFINITION + "Test1"), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    assertEquals("Test1", json.get("name"));
    assertEquals("Testing", json.get("description"));
    assertEquals("CancelRequested", json.get("status"));
    assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(true, json.get("enabled"));
    assertEquals(JSONObject.NULL, json.get("targetName"));
    // Payload is empty
    assertEquals(0, json.getJSONArray("payload").length());
    // Add some payload details, ensure that they get expanded
    // as they should be
    rd.getPayload().add(repositoryHelper.getCompanyHome());
    rd.getPayload().add(dataDictionary);
    replicationService.saveReplicationDefinition(rd);
    response = sendRequest(new GetRequest(URL_DEFINITION + "Test1"), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    assertEquals("Test1", json.get("name"));
    assertEquals("Testing", json.get("description"));
    assertEquals("CancelRequested", json.get("status"));
    assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(true, json.get("enabled"));
    assertEquals(JSONObject.NULL, json.get("targetName"));
    // Check Payload
    assertEquals(2, json.getJSONArray("payload").length());
    JSONObject payload = json.getJSONArray("payload").getJSONObject(0);
    assertEquals(repositoryHelper.getCompanyHome().toString(), payload.get("nodeRef"));
    assertEquals(true, payload.get("isFolder"));
    assertEquals("Company Home", payload.get("name"));
    assertEquals("/Company Home", payload.get("path"));
    payload = json.getJSONArray("payload").getJSONObject(1);
    assertEquals(dataDictionary.toString(), payload.get("nodeRef"));
    assertEquals(true, payload.get("isFolder"));
    assertEquals("Data Dictionary", payload.get("name"));
    assertEquals("/Company Home/Data Dictionary", payload.get("path"));
    // Add a deleted NodeRef too, will be silently ignored
    // by the webscript layer
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    NodeRef deleted = nodeService.createNode(dataDictionary, ContentModel.ASSOC_CONTAINS, QName.createQName("IwillBEdeleted"), ContentModel.TYPE_CONTENT).getChildRef();
    nodeService.deleteNode(deleted);
    txn.commit();
    rd.getPayload().add(deleted);
    replicationService.saveReplicationDefinition(rd);
    response = sendRequest(new GetRequest(URL_DEFINITION + "Test1"), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    assertEquals("Test1", json.get("name"));
    assertEquals("Testing", json.get("description"));
    assertEquals("CancelRequested", json.get("status"));
    assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(true, json.get("enabled"));
    assertEquals(JSONObject.NULL, json.get("targetName"));
    // Check Payload
    assertEquals(2, json.getJSONArray("payload").length());
    payload = json.getJSONArray("payload").getJSONObject(0);
    assertEquals("Company Home", payload.get("name"));
    payload = json.getJSONArray("payload").getJSONObject(1);
    assertEquals("Data Dictionary", payload.get("name"));
    // Add a 2nd and 3rd definition
    rd = replicationService.createReplicationDefinition("Test2", "2nd Testing");
    replicationService.saveReplicationDefinition(rd);
    rd = replicationService.createReplicationDefinition("Test3", "3rd Testing");
    rd.setLocalTransferReport(repositoryHelper.getRootHome());
    rd.setRemoteTransferReport(repositoryHelper.getCompanyHome());
    rd.setEnabled(false);
    // Have the 3rd one flagged as having failed
    txn = transactionService.getUserTransaction();
    txn.begin();
    replicationService.saveReplicationDefinition(rd);
    actionTrackingService.recordActionExecuting(rd);
    actionTrackingService.recordActionFailure(rd, new Exception("Test Failure"));
    txn.commit();
    Thread.sleep(50);
    replicationService.saveReplicationDefinition(rd);
    // Original one comes back unchanged
    response = sendRequest(new GetRequest(URL_DEFINITION + "Test1"), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    assertEquals("Test1", json.get("name"));
    assertEquals("Testing", json.get("description"));
    assertEquals("CancelRequested", json.get("status"));
    assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(true, json.get("enabled"));
    assertEquals(JSONObject.NULL, json.get("targetName"));
    // Check Payload
    assertEquals(2, json.getJSONArray("payload").length());
    payload = json.getJSONArray("payload").getJSONObject(0);
    assertEquals(repositoryHelper.getCompanyHome().toString(), payload.get("nodeRef"));
    assertEquals(true, payload.get("isFolder"));
    assertEquals("Company Home", payload.get("name"));
    assertEquals("/Company Home", payload.get("path"));
    payload = json.getJSONArray("payload").getJSONObject(1);
    assertEquals(dataDictionary.toString(), payload.get("nodeRef"));
    assertEquals(true, payload.get("isFolder"));
    assertEquals("Data Dictionary", payload.get("name"));
    assertEquals("/Company Home/Data Dictionary", payload.get("path"));
    // They show up things as expected
    response = sendRequest(new GetRequest(URL_DEFINITION + "Test2"), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    assertEquals("Test2", json.get("name"));
    assertEquals("2nd Testing", json.get("description"));
    assertEquals("New", json.get("status"));
    assertEquals(JSONObject.NULL, json.get("startedAt"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals(JSONObject.NULL, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(true, json.get("enabled"));
    assertEquals(JSONObject.NULL, json.get("targetName"));
    assertEquals(0, json.getJSONArray("payload").length());
    // And the 3rd one, which is failed
    response = sendRequest(new GetRequest(URL_DEFINITION + "Test3"), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
    String endedAt = ISO8601DateFormat.format(rd.getExecutionEndDate());
    assertEquals("Test3", json.get("name"));
    assertEquals("3rd Testing", json.get("description"));
    assertEquals("Failed", json.get("status"));
    assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
    assertEquals(endedAt, json.getJSONObject("endedAt").get("iso8601"));
    assertEquals("Test Failure", json.get("failureMessage"));
    assertEquals(JSONObject.NULL, json.get("executionDetails"));
    assertEquals(repositoryHelper.getRootHome().toString(), json.get("transferLocalReport"));
    assertEquals(repositoryHelper.getCompanyHome().toString(), json.get("transferRemoteReport"));
    assertEquals(false, json.get("enabled"));
    assertEquals(JSONObject.NULL, json.get("targetName"));
    assertEquals(0, json.getJSONArray("payload").length());
    // When pending/running, the previous end time, transfer reports and
    // failure details are hidden
    rd = replicationService.loadReplicationDefinition("Test3");
    assertEquals(0, actionTrackingService.getExecutingActions(rd).size());
    actionTrackingService.recordActionPending(rd);
    assertEquals(1, actionTrackingService.getExecutingActions(rd).size());
    instanceId = ((ActionImpl) rd).getExecutionInstance();
    actionId = rd.getId();
    response = sendRequest(new GetRequest(URL_DEFINITION + "Test3"), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    assertEquals("Test3", json.get("name"));
    assertEquals("3rd Testing", json.get("description"));
    assertEquals("Pending", json.get("status"));
    assertEquals(JSONObject.NULL, json.get("startedAt"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(false, json.get("enabled"));
    assertEquals(JSONObject.NULL, json.get("targetName"));
    assertEquals(0, json.getJSONArray("payload").length());
    actionTrackingService.recordActionExecuting(rd);
    response = sendRequest(new GetRequest(URL_DEFINITION + "Test3"), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
    assertEquals("Test3", json.get("name"));
    assertEquals("3rd Testing", json.get("description"));
    assertEquals("Running", json.get("status"));
    assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(false, json.get("enabled"));
    assertEquals(JSONObject.NULL, json.get("targetName"));
    assertEquals(0, json.getJSONArray("payload").length());
    actionTrackingService.requestActionCancellation(rd);
    response = sendRequest(new GetRequest(URL_DEFINITION + "Test3"), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
    assertEquals("Test3", json.get("name"));
    assertEquals("3rd Testing", json.get("description"));
    assertEquals("CancelRequested", json.get("status"));
    assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(false, json.get("enabled"));
    assertEquals(JSONObject.NULL, json.get("targetName"));
    assertEquals(0, json.getJSONArray("payload").length());
    // These show up again when no longer running
    txn = transactionService.getUserTransaction();
    txn.begin();
    actionTrackingService.recordActionComplete(rd);
    txn.commit();
    response = sendRequest(new GetRequest(URL_DEFINITION + "Test3"), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
    endedAt = ISO8601DateFormat.format(rd.getExecutionEndDate());
    assertEquals("Test3", json.get("name"));
    assertEquals("3rd Testing", json.get("description"));
    assertEquals("Completed", json.get("status"));
    assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
    assertEquals(endedAt, json.getJSONObject("endedAt").get("iso8601"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals(JSONObject.NULL, json.get("executionDetails"));
    assertEquals(repositoryHelper.getRootHome().toString(), json.get("transferLocalReport"));
    assertEquals(repositoryHelper.getCompanyHome().toString(), json.get("transferRemoteReport"));
    assertEquals(false, json.get("enabled"));
    assertEquals(JSONObject.NULL, json.get("targetName"));
    assertEquals(0, json.getJSONArray("payload").length());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) UserTransaction(javax.transaction.UserTransaction) NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.JSONObject) ReplicationDefinition(org.alfresco.service.cmr.replication.ReplicationDefinition) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray) ActionImpl(org.alfresco.repo.action.ActionImpl)

Example 85 with NodeRef

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

the class RuleServiceTest method createTestFolders.

private void createTestFolders() {
    StoreRef testStore = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
    if (!nodeService.exists(testStore)) {
        testStore = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
    }
    NodeRef rootNodeRef = nodeService.getRootNode(testStore);
    testWorkNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}testnode"), ContentModel.TYPE_FOLDER).getChildRef();
    testNodeRef = fileFolderService.create(testWorkNodeRef, TEST_FOLDER, ContentModel.TYPE_FOLDER).getNodeRef();
    testNodeRef2 = fileFolderService.create(testWorkNodeRef, TEST_FOLDER_2, ContentModel.TYPE_FOLDER).getNodeRef();
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

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