use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testMove.
/**
* Tests move (file or folder)
* <p>POST:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/move}
*/
@Test
public void testMove() throws Exception {
setRequestContext(user1);
// create folder f0
String folder0Name = "f0-testMove-" + RUNID;
String f0Id = createFolder(Nodes.PATH_MY, folder0Name).getId();
// create folder f1
Folder folderResp = createFolder(f0Id, "f1");
String f1Id = folderResp.getId();
// create folder f2
folderResp = createFolder(f0Id, "f2");
String f2Id = folderResp.getId();
// create doc d1
String d1Name = "content" + RUNID + "_1";
String d1Id = createTextFile(f1Id, d1Name, "The quick brown fox jumps over the lazy dog 1.").getId();
// create doc d2
String d2Name = "content" + RUNID + "_2";
String d2Id = createTextFile(f2Id, d2Name, "The quick brown fox jumps over the lazy dog 2.").getId();
// move file (without rename)
NodeTarget tgt = new NodeTarget();
tgt.setTargetParentId(f2Id);
HttpResponse response = post("nodes/" + d1Id + "/move", toJsonAsStringNonNull(tgt), null, 200);
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals(d1Name, documentResp.getName());
assertEquals(f2Id, documentResp.getParentId());
// move file (with rename)
String d1NewName = d1Name + " updated !!";
tgt = new NodeTarget();
tgt.setName(d1NewName);
tgt.setTargetParentId(f1Id);
response = post("nodes/" + d1Id + "/move", toJsonAsStringNonNull(tgt), null, 200);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals(d1NewName, documentResp.getName());
assertEquals(f1Id, documentResp.getParentId());
// -ve tests
// missing target
tgt = new NodeTarget();
tgt.setName("new name");
post("nodes/" + d1Id + "/move", toJsonAsStringNonNull(tgt), null, 400);
// name already exists
tgt = new NodeTarget();
tgt.setName(d2Name);
tgt.setTargetParentId(f2Id);
post("nodes/" + d1Id + "/move", toJsonAsStringNonNull(tgt), null, 409);
// unknown source nodeId
tgt = new NodeTarget();
tgt.setTargetParentId(f2Id);
post("nodes/" + UUID.randomUUID().toString() + "/move", toJsonAsStringNonNull(tgt), null, 404);
// unknown target nodeId
tgt = new NodeTarget();
tgt.setTargetParentId(UUID.randomUUID().toString());
post("nodes/" + d1Id + "/move", toJsonAsStringNonNull(tgt), null, 404);
// target is not a folder
tgt = new NodeTarget();
tgt.setTargetParentId(d2Id);
post("nodes/" + d1Id + "/move", toJsonAsStringNonNull(tgt), null, 400);
String rootNodeId = getRootNodeId();
// create folder f3 (sub-folder of f2)
folderResp = createFolder(f2Id, "f3");
String f3Id = folderResp.getId();
// can't create cycle (move into own subtree)
tgt = new NodeTarget();
tgt.setTargetParentId(f3Id);
post("nodes/" + f2Id + "/move", toJsonAsStringNonNull(tgt), null, 400);
// no (write/create) permissions to move to target
tgt = new NodeTarget();
tgt.setTargetParentId(rootNodeId);
post("nodes/" + d1Id + "/move", toJsonAsStringNonNull(tgt), null, 403);
setRequestContext(user2);
String my2NodeId = getMyNodeId();
// no (write/delete) permissions to move source
tgt = new NodeTarget();
tgt.setTargetParentId(my2NodeId);
post("nodes/" + f1Id + "/move", toJsonAsStringNonNull(tgt), null, 403);
// -ve - cannot move (delete) Company Home root node
setRequestContext(networkAdmin);
post("nodes/" + rootNodeId + "/move", toJsonAsStringNonNull(tgt), null, 403);
setRequestContext(user1);
Map params = new HashMap<>();
params.put(Nodes.PARAM_RELATIVE_PATH, "/Sites");
response = getSingle(NodesEntityResource.class, rootNodeId, params, 200);
Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String sitesNodeId = nodeResp.getId();
// -ve - cannot move (delete) Sites node
setRequestContext(networkAdmin);
post("nodes/" + sitesNodeId + "/move", toJsonAsStringNonNull(tgt), null, 403);
setRequestContext(user1);
params = new HashMap<>();
params.put(Nodes.PARAM_RELATIVE_PATH, "/Data Dictionary");
response = getSingle(NodesEntityResource.class, rootNodeId, params, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String ddNodeId = nodeResp.getId();
// -ve - cannot move (delete) Data Dictionary node
setRequestContext(networkAdmin);
post("nodes/" + ddNodeId + "/move", toJsonAsStringNonNull(tgt), null, 403);
// -ve test - cannot move to multiple destinations in single POST call (unsupported)
List<NodeTarget> nodeDestinations = new ArrayList<>(2);
NodeTarget nodeTarget = new NodeTarget();
nodeTarget.setTargetParentId(f1Id);
nodeDestinations.add(nodeTarget);
nodeTarget = new NodeTarget();
nodeTarget.setTargetParentId(f2Id);
nodeDestinations.add(nodeTarget);
post("nodes/" + d1Id + "/move", toJsonAsStringNonNull(nodeDestinations), null, 405);
}
use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.
the class NodeAssociationsApiTest method testListChildrenConsistentParentIdWithSecondaryAssociations.
/**
* Regardless of which parent is used to list children of a node, the node information
* should consistently present the primary parent as a node's {@code parentId}.
* <p>
* See REPO-1780
*/
@Test
public void testListChildrenConsistentParentIdWithSecondaryAssociations() throws Exception {
setRequestContext(user1);
String myNodeId = getMyNodeId();
// Create primary folder
String primaryFolderName = "primary folder " + RUNID;
String primaryFolderId = createFolder(myNodeId, primaryFolderName, null).getId();
// Create content file
String contentFileName = "content" + RUNID + " in folder";
String contentId = createTextFile(primaryFolderId, contentFileName, "The quick brown fox jumps over the lazy dog.").getId();
// Add a secondary parent for content file
Node n = new Node();
n.setName("secondary folder " + RUNID);
n.setNodeType(TYPE_CM_FOLDER);
n.setAspectNames(Arrays.asList(ASPECT_CM_PREFERENCES));
HttpResponse response = post(getNodeChildrenUrl(myNodeId), toJsonAsStringNonNull(n), 201);
String secondaryFolderId = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
AssocChild secChild = new AssocChild(contentId, ASSOC_TYPE_CM_CONTAINS);
post(getNodeSecondaryChildrenUrl(secondaryFolderId), toJsonAsStringNonNull(secChild), 201);
Paging paging = getPaging(0, 100);
// Order by folders and modified date first
Map<String, String> orderBy = Collections.singletonMap("orderBy", "isFolder DESC,modifiedAt DESC");
// Retrieve the node via the primary parent
String primaryChildrenUrl = getNodeChildrenUrl(primaryFolderId);
response = getAll(primaryChildrenUrl, paging, orderBy, 200);
List<Document> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
Document node = nodes.get(0);
assertEquals(contentId, node.getId());
assertEquals(primaryFolderId, node.getParentId());
// Retrieve the node via the secondary parent
String secondaryChildrenUrl = getNodeChildrenUrl(secondaryFolderId);
response = getAll(secondaryChildrenUrl, paging, orderBy, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
node = nodes.get(0);
assertEquals(contentId, node.getId());
// The parent ID must STILL be the primary parent, even when the info
// is retrieved via the secondary parent.
assertEquals(primaryFolderId, node.getParentId());
}
use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.
the class NodeVersionsApiTest method testUploadFileVersionCreateWithOverwrite.
/**
* Test version creation when uploading files (via multi-part/form-data with overwrite=true)
*
* <p>POST:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/children}
*
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/versions}
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/versions/<versionId>}
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/versions/<versionId>/content}
*/
@Test
public void testUploadFileVersionCreateWithOverwrite() throws Exception {
setRequestContext(user1);
String myFolderNodeId = getMyNodeId();
// create folder
String f1Id = createFolder(myFolderNodeId, "f1").getId();
try {
int verCnt = 1;
String versionLabel = "1.0";
// upload text file - versioning is currently auto enabled on upload (create file via multi-part/form-data)
String textContentSuffix = "The quick brown fox jumps over the lazy dog ";
String contentName = "content-1-" + System.currentTimeMillis();
String content = textContentSuffix + verCnt;
// create first version (ie. 1.0)
Document documentResp = createTextFile(f1Id, contentName, content, "UTF-8", null);
String docId = documentResp.getId();
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
assertEquals(versionLabel, documentResp.getProperties().get("cm:versionLabel"));
Map<String, String> params = null;
// create some minor versions (note: majorVersion=null) (ie. 1.1, 1.2, 1.3)
int cnt = 3;
versionLabel = uploadTextFileVersions(user1, f1Id, contentName, cnt, textContentSuffix, verCnt, null, versionLabel).getFirst();
verCnt = verCnt + cnt;
// create some major versions (ie. 2.0, 3.0)
cnt = 2;
versionLabel = uploadTextFileVersions(user1, f1Id, contentName, cnt, textContentSuffix, verCnt, true, versionLabel).getFirst();
verCnt = verCnt + cnt;
// create some more minor versions (ie. 3.1, 3.2, 3.3)
cnt = 3;
versionLabel = uploadTextFileVersions(user1, f1Id, contentName, cnt, textContentSuffix, verCnt, false, versionLabel).getFirst();
verCnt = verCnt + cnt;
assertEquals("3.3", versionLabel);
assertEquals(9, verCnt);
{
// -ve test
params = new HashMap<>();
params.put(Nodes.PARAM_OVERWRITE, "true");
params.put(Nodes.PARAM_AUTO_RENAME, "true");
createTextFile(myFolderNodeId, contentName, content, "UTF-8", params, 400);
}
// remove versionable aspect
List<String> aspectNames = documentResp.getAspectNames();
aspectNames.remove("cm:versionable");
Document dUpdate = new Document();
dUpdate.setAspectNames(aspectNames);
HttpResponse response = put(URL_NODES, docId, toJsonAsStringNonNull(dUpdate), null, 200);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertFalse(documentResp.getAspectNames().contains("cm:versionable"));
// no properties (ie. no "cm:versionLabel")
assertNull(documentResp.getProperties());
// check no version history
response = getAll(getNodeVersionsUrl(docId), null, null, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(0, nodes.size());
{
// -ve test - do not allow overwrite (using POST upload) if the file is not versionable
cnt++;
content = textContentSuffix + cnt;
params = new HashMap<>();
params.put(Nodes.PARAM_OVERWRITE, "true");
createTextFile(f1Id, contentName, content, "UTF-8", params, 409);
}
// we do allow update of binary content with no versioning (after removing versionable)
textContentSuffix = "Amazingly few discotheques provide jukeboxes ";
for (int i = 1; i <= 4; i++) {
content = textContentSuffix + i;
ByteArrayInputStream inputStream = new ByteArrayInputStream(content.getBytes());
File txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt");
PublicApiHttpClient.BinaryPayload payload = new PublicApiHttpClient.BinaryPayload(txtFile);
putBinary(getNodeContentUrl(docId), payload, null, null, 200);
}
// check no version history
response = getAll(getNodeVersionsUrl(docId), null, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(0, nodes.size());
} finally {
// some cleanup
setRequestContext(user1);
deleteNode(f1Id, true, 204);
}
}
use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.
the class NodeVersionsApiTest method uploadTextFileVersions.
/**
* This test helper method uses "overwrite=true" to create one or more new versions, including the initial create if needed.
*
* If the file does not already exist (currentVersionLabel should be null) and majorVersionIn is also null
* then the first version is created as MAJOR (1.0) and subsequent versions are created as MINOR.
*
* @param userId
* @param parentFolderNodeId - parent folder
* @param fileName - file name
* @param cnt - number of new versions (>= 1)
* @param textContentPrefix - prefix for text content
* @param currentVersionCounter - overall version counter, used as a suffix in text content and version comment
* @param majorVersionIn - if null then false, if true then create MAJOR versions else if false create MINOR versions
* @param currentVersionLabel - the current version label (if file already exists)
* @return
* @throws Exception
*/
private Pair<String, String> uploadTextFileVersions(String userId, String parentFolderNodeId, String fileName, int cnt, String textContentPrefix, int currentVersionCounter, final Boolean majorVersionIn, String currentVersionLabel) throws Exception {
Map<String, String> params = new HashMap<>();
params.put(Nodes.PARAM_OVERWRITE, "true");
if (majorVersionIn != null) {
params.put(Nodes.PARAM_VERSION_MAJOR, majorVersionIn.toString());
}
String docId = null;
for (int i = 1; i <= cnt; i++) {
boolean expectedMajorVersion = (majorVersionIn != null ? majorVersionIn : false);
if (currentVersionLabel == null) {
currentVersionLabel = "0.0";
// special case - 1st version is major (if not specified otherwise)
if (majorVersionIn == null) {
expectedMajorVersion = true;
}
}
String[] parts = currentVersionLabel.split("\\.");
int majorVer = new Integer(parts[0]).intValue();
int minorVer = new Integer(parts[1]).intValue();
if (expectedMajorVersion) {
majorVer++;
minorVer = 0;
} else {
minorVer++;
}
currentVersionLabel = majorVer + "." + minorVer;
currentVersionCounter++;
params.put("comment", "my version " + currentVersionCounter);
String textContent = textContentPrefix + currentVersionCounter;
// uses upload with overwrite here ...
Document documentResp = createTextFile(parentFolderNodeId, fileName, textContent, "UTF-8", params);
docId = documentResp.getId();
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
assertEquals(currentVersionLabel, documentResp.getProperties().get("cm:versionLabel"));
// double-check - get version node info
HttpResponse response = getSingle(getNodeVersionsUrl(docId), currentVersionLabel, null, 200);
Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertEquals(currentVersionLabel, nodeResp.getProperties().get("cm:versionLabel"));
assertEquals((expectedMajorVersion ? "MAJOR" : "MINOR"), nodeResp.getProperties().get("cm:versionType"));
}
return new Pair<String, String>(currentVersionLabel, docId);
}
use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.
the class QueriesNodesApiTest method testLiveSearchNodes_Tags.
@Test
@Category(RedundantTests.class)
public void testLiveSearchNodes_Tags() throws Exception {
setRequestContext(user1);
PublicApiClient.Nodes nodesProxy = publicApiClient.nodes();
int f1Count = 5;
List<String> f1NodeIds = new ArrayList<>(f1Count);
int f2Count = 3;
List<String> f2NodeIds = new ArrayList<>(f2Count);
int totalCount = f1Count + f2Count;
List<String> allIds = new ArrayList<>(totalCount);
String testTag = "ghi789tag";
String testFileTag = "ghi789file";
String testFolderTag = "ghi789folder";
try {
// As user 1 ...
Paging paging = getPaging(0, 100);
String f1Id = createFolder(Nodes.PATH_MY, "folder tag 1").getId();
String f2Id = createFolder(Nodes.PATH_MY, "folder tag 2").getId();
String name = "name";
for (int i = 1; i <= f1Count; i++) {
// create doc - in folder 1
String contentText = "f1 test document " + user1 + " document " + i;
String docName = name + i;
Document doc = createTextFile(f1Id, docName, contentText, "UTF-8", null);
publicApiClient.setRequestContext(new RequestContext("", user1));
// ignore result
nodesProxy.createNodeTag(doc.getId(), new Tag(testTag));
// ignore result
nodesProxy.createNodeTag(doc.getId(), new Tag(testFileTag));
f1NodeIds.add(doc.getId());
}
for (int i = 1; i <= f2Count; i++) {
// create folder - in folder 2
String folderName = name + i;
Folder folder = createFolder(f2Id, folderName, null);
publicApiClient.setRequestContext(new RequestContext("", user1));
// ignore result
nodesProxy.createNodeTag(folder.getId(), new Tag(testTag));
// ignore result
nodesProxy.createNodeTag(folder.getId(), new Tag(testFolderTag));
f2NodeIds.add(folder.getId());
}
allIds.addAll(f1NodeIds);
allIds.addAll(f2NodeIds);
// Search hits based on tag
Map<String, String> params = new HashMap<>(1);
params.put(Queries.PARAM_TERM, testTag);
HttpResponse response = getAll(URL_QUERIES_LSN, paging, params, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
checkNodeIds(nodes, allIds, null);
params = new HashMap<>(1);
params.put(Queries.PARAM_TERM, testFileTag);
response = getAll(URL_QUERIES_LSN, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
checkNodeIds(nodes, f1NodeIds, null);
params = new HashMap<>(1);
params.put(Queries.PARAM_TERM, testFolderTag);
response = getAll(URL_QUERIES_LSN, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
checkNodeIds(nodes, f2NodeIds, null);
} finally {
// some cleanup
setRequestContext(user1);
for (String nodeId : allIds) {
deleteNode(nodeId, true, 204);
}
}
}
Aggregations