Skip to content

Instantly share code, notes, and snippets.

@jpotts
Created November 25, 2014 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpotts/56838b3c310bd5f470d3 to your computer and use it in GitHub Desktop.
Save jpotts/56838b3c310bd5f470d3 to your computer and use it in GitHub Desktop.
Showing how to grab a document, either by ID or by path, from an Alfresco 5.0.a repository, even when the user does not have access to the enclosing folders

Setup

  1. Create a folder called "test1" in Company Home.
  2. Modify its permissions to turn off inheritance.
  3. Create a sub-folder called "test2" under "test1".
  4. Modify its permissions to turn off inheritance.
  5. Create a plain text file in test2 called test.txt.
  6. Modify its permissions to turn off inheritance and add a single user with Consumer access (tuser1).
  7. You can still get to the document via CMIS, which is the expected behavior.

This Java class inherits from BaseOnPremExample which can be found here: https://code.google.com/p/alfresco-api-java-examples/source/browse/alfresco-api-examples/src/main/java/com/alfresco/api/example/BaseOnPremExample.java

package com.alfresco.api.example;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.client.api.Session;
public class GetDocumentExample extends BaseOnPremExample {
public static void main(String[] args) {
GetDocumentExample gde = new GetDocumentExample();
gde.doExample();
}
public void doExample() {
Session cmisSession = getCmisSession();
System.out.println("Version: " + cmisSession.getRepositoryInfo().getProductVersion());
System.out.println("User: " + getUsername());
// This works
//Document doc = (Document) cmisSession.getObject("workspace://SpacesStore/fd05d750-1083-4e46-9507-566bc7b7712f");
// This works as well
Document doc = (Document) cmisSession.getObjectByPath("/test1/test2/test.txt");
System.out.println("Name: " + doc.getPropertyValue("cmis:name"));
try {
BufferedReader in = new BufferedReader(new InputStreamReader(doc.getContentStream().getStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
Found 1 networks.
Your home network appears to be: -default-
Version: 5.0.0 (r75118-b23)
User: tuser1
Name: test.txt
This is some test content.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment