newFolderProps.put(PropertyIds.NAME, "ADGFolderPaging");
Folder folderPaging = root.createFolder(newFolderProps);
createFolders(folderPaging, 10);
System.out.println("Getting page of length 3 from item 5");
OperationContext operationContext = new OperationContextImpl();
operationContext.setMaxItemsPerPage(3);
ItemIterable<CmisObject> children1 = folderPaging.getChildren(operationContext);
int count = 0;
for (CmisObject child : children1.skipTo(5).getPage()) {
System.out.println("object " + count + " in page of " + children1.getPageNumItems()
+ " is " + child.getName());
count++;
}
// operationContext = new OperationContextImpl();
// operationContext.setMaxItemsPerPage(3);
// children1 = folderPaging.getChildren(operationContext);
// int pageNumber = 0;
// count = 1;
// while (count > 0) {
// count = 0;
// for (CmisObject child : children1.skipTo(
// pageNumber * operationContext.getMaxItemsPerPage()).getPage()) {
// System.out.println("object " + count + " in page" + pageNumber +
// " is "
// + child.getName());
// count++;
// }
// pageNumber++;
// }
System.out.println("Getting complete result set in pages of 3");
operationContext = new OperationContextImpl();
operationContext.setMaxItemsPerPage(3);
children1 = folderPaging.getChildren(operationContext);
int pageNumber = 0;
boolean finished = false;
while (!finished) {
count = 0;
ItemIterable<CmisObject> currentPage = children1.skipTo(
pageNumber * operationContext.getMaxItemsPerPage()).getPage();
for (CmisObject item : currentPage) {
System.out.println("object " + count + " in page" + pageNumber + " is "
+ item.getName());
count++;
}
pageNumber++;
if (!currentPage.getHasMoreItems())
finished = true;
}
// Types
System.out.println("\nTypes...");
System.out.println("--------");
// Look at the type definition
System.out.println("Getting type definition for doc");
ObjectType objectType = session.getTypeDefinition(doc.getType().getId());
System.out.println("doc is of type " + objectType.getDisplayName());
System.out.println("isBaseType() returns " + (objectType.isBaseType() ? "true" : "false"));
ObjectType baseType = objectType.getBaseType();
if (baseType == null) {
System.out.println("getBaseType() returns null");
} else {
System.out.println("getBaseType() returns " + baseType.getDisplayName());
}
ObjectType parentType = objectType.getParentType();
if (parentType == null) {
System.out.println("getParentType() returns null");
} else {
System.out.println("getParentType() returns " + parentType.getDisplayName());
}
System.out.println("Listing child types of " + objectType.getDisplayName());
for (ObjectType o : objectType.getChildren()) {
System.out.println("\t" + o.getDisplayName());
}
System.out.println("Getting immediate descendant types of " + objectType.getDisplayName());
for (Tree<ObjectType> o : objectType.getDescendants(1)) {
System.out.println("\t" + o.getItem().getDisplayName());
}
System.out.println("\nProperties...");
System.out.println("-------------");
// Look at all the properties of the document
System.out.println(doc.getName() + " properties start");
List<Property<?>> props = doc.getProperties();
for (Property<?> p : props) {
System.out.println(p.getDefinition().getDisplayName() + "=" + p.getValuesAsString());
}
System.out.println(doc.getName() + " properties end");
// Get some document properties explicitly
System.out.println("VersionLabel property on " + doc.getName() + " is "
+ doc.getVersionLabel());
// System.out.println("Is this the latest version of " + doc.getName() +
// " ?: "
// + (doc.isLatestVersion() ? "yes" : "no"));
// get a property by id
System.out.println("get property by property id");
Property<?> someProperty = props.get(0);
System.out.println(someProperty.getDisplayName() + " property on " + doc.getName()
+ " (by getPropertValue()) is " + doc.getPropertyValue(someProperty.getId()));
// get a property by query name
System.out.println("get property by query name");
if (session.getRepositoryInfo().getCapabilities().getQueryCapability()
.equals(CapabilityQuery.METADATAONLY)) {
System.out.println("Full search not supported");
} else {
String query = "SELECT * FROM cmis:document WHERE cmis:name = 'test.txt'";
ItemIterable<QueryResult> queryResult = session.query(query, false);
for (QueryResult item : queryResult) {
System.out.println("property cmis:createdBy on test.txt is "
+ item.getPropertyByQueryName("cmis:createdBy").getFirstValue());
}
}
GregorianCalendar calendar = doc.getCreationDate();
String DATE_FORMAT = "yyyyMMdd";
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
System.out.println("Creation date of " + doc.getName() + " is "
+ sdf.format(calendar.getTime()));
System.out.println("\nQuery...");
System.out.println("--------");
// Query 1 - need full query capability for this
if (session.getRepositoryInfo().getCapabilities().getQueryCapability()
.equals(CapabilityQuery.METADATAONLY)) {
System.out.println("Full search not supported");
} else {
String query = "SELECT * FROM cmis:document WHERE cmis:name LIKE 'test%'";
ItemIterable<QueryResult> q = session.query(query, false);
// Did it work?
System.out.println("***results from query " + query);
int i = 1;
for (QueryResult qr : q) {
System.out.println("--------------------------------------------\n" + i + " , "
+ qr.getPropertyByQueryName("cmis:objectTypeId").getFirstValue() + " , "
+ qr.getPropertyByQueryName("cmis:name").getFirstValue() + " , "
+ qr.getPropertyByQueryName("cmis:createdBy").getFirstValue() + " , "
+ qr.getPropertyByQueryName("cmis:objectId").getFirstValue() + " , "
+ qr.getPropertyByQueryName("cmis:contentStreamFileName").getFirstValue()
+ " , "
+ qr.getPropertyByQueryName("cmis:contentStreamMimeType").getFirstValue()
+ " , "
+ qr.getPropertyByQueryName("cmis:contentStreamLength").getFirstValue());
i++;
}
// Query 2
query = "SELECT * FROM cmis:document WHERE cmis:name LIKE 'test%.txt' AND CONTAINS('test')";
q = session.query(query, false);
System.out.println("***results from query " + query);
i = 1;
for (QueryResult qr : q) {
System.out.println("--------------------------------------------\n" + i + " , "
+ qr.getPropertyByQueryName("cmis:objectTypeId").getFirstValue() + " , "
+ qr.getPropertyByQueryName("cmis:name").getFirstValue() + " , "
+ qr.getPropertyByQueryName("cmis:createdBy").getFirstValue() + " , "
+ qr.getPropertyByQueryName("cmis:objectId").getFirstValue() + " , "
+ qr.getPropertyByQueryName("cmis:contentStreamFileName").getFirstValue()
+ " , "
+ qr.getPropertyByQueryName("cmis:contentStreamMimeType").getFirstValue()
+ " , "
+ qr.getPropertyByQueryName("cmis:contentStreamLength").getFirstValue());
i++;
}
}
System.out.println("\nCapabilities...");
System.out.println("---------------");
// Check what capabilities our repository supports
System.out.println("Printing repository capabilities...");
final RepositoryInfo repInfo = session.getRepositoryInfo();
RepositoryCapabilities cap = repInfo.getCapabilities();
System.out.println("\nNavigation Capabilities");
System.out.println("-----------------------");
System.out.println("Get descendants supported: "
+ (cap.isGetDescendantsSupported() ? "true" : "false"));
System.out.println("Get folder tree supported: "
+ (cap.isGetFolderTreeSupported() ? "true" : "false"));
System.out.println("\nObject Capabilities");
System.out.println("-----------------------");
System.out.println("Content Stream: " + cap.getContentStreamUpdatesCapability().value());
System.out.println("Changes: " + cap.getChangesCapability().value());
System.out.println("Renditions: " + cap.getRenditionsCapability().value());
System.out.println("\nFiling Capabilities");
System.out.println("-----------------------");
System.out.println("Multifiling supported: "
+ (cap.isMultifilingSupported() ? "true" : "false"));
System.out.println("Unfiling supported: " + (cap.isUnfilingSupported() ? "true" : "false"));
System.out.println("Version specific filing supported: "
+ (cap.isVersionSpecificFilingSupported() ? "true" : "false"));
System.out.println("\nVersioning Capabilities");
System.out.println("-----------------------");
System.out
.println("PWC searchable: " + (cap.isPwcSearchableSupported() ? "true" : "false"));
System.out.println("PWC Updatable: " + (cap.isPwcUpdatableSupported() ? "true" : "false"));
System.out.println("All versions searchable: "
+ (cap.isAllVersionsSearchableSupported() ? "true" : "false"));
System.out.println("\nQuery Capabilities");
System.out.println("-----------------------");
System.out.println("Query: " + cap.getQueryCapability().value());
System.out.println("Join: " + cap.getJoinCapability().value());
System.out.println("\nACL Capabilities");
System.out.println("-----------------------");
System.out.println("ACL: " + cap.getAclCapability().value());
System.out.println("End of repository capabilities");
System.out.println("\nAllowable actions...");
System.out.println("--------------------");
// find the current allowable actions for the test.txt document
System.out.println("Getting the current allowable actions for the " + doc.getName()
+ " document object...");
for (Action a : doc.getAllowableActions().getAllowableActions()) {
System.out.println("\t" + a.value());
}
// find out if we can currently check out test.txt
if (doc.getAllowableActions().getAllowableActions().contains(Action.CAN_CHECK_OUT)) {
System.out.println("can check out " + doc.getName());
} else {
System.out.println("can not check out " + doc.getName());
}
System.out.println("\nMultifiling and Unfiling...");
System.out.println("---------------------------");
// Try out multifiling if it is supported
System.out.println("Trying out multifiling");
Folder newFolder2 = null;
if (!(cap.isMultifilingSupported())) {
System.out.println("Multifiling not supported by this repository");
} else {
// Add a new folder to the root folder
System.out.println("Creating 'ADGNewFolder 2' in the root folder");
newFolderProps = new HashMap<String, String>();
newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
newFolderProps.put(PropertyIds.NAME, "ADGNewFolder 2");
newFolder2 = root.createFolder(newFolderProps, null, null, null,
session.getDefaultContext());
System.out.println("Adding " + textFileName + "to 'ADGNewFolder 2' in the root folder");
doc.addToFolder(newFolder2, true);
// Did it work?
children = newFolder.getChildren();
System.out.println("Now finding the following objects in the 'ADGNewFolder' folder:-");
for (CmisObject o : children) {
System.out.println(o.getName());
}
children = newFolder2.getChildren();
System.out
.println("Now finding the following objects in the 'ADGNewFolder 2' folder:-");
for (CmisObject o : children) {
System.out.println(o.getName());
}
}
// Try out unfiling if it is supported
System.out.println("Trying out unfiling");
if (!(cap.isUnfilingSupported())) {
System.out.println("Unfiling not supported by this repository");
} else {
// remove our document from both folders
System.out.println("removing :" + doc.getName() + "from 'ADGNewFolder':-");
doc.removeFromFolder(newFolder);
System.out.println("removing :" + doc.getName() + "from 'ADGNewFolder 2':-");
doc.removeFromFolder(newFolder2);
// Did it work?
Document docTest = (Document) session.getObject(id);
if (docTest != null) {
System.out.println(docTest.getName() + " still exists");
}
}
System.out.println("\nVersioning...");
System.out.println("-------------");
// Check whether a document is versionable
boolean versionable = false;
if (((DocumentType) (doc.getType())).isVersionable()) {
System.out.println(doc.getName() + " is versionable");
versionable = true;
} else {
System.out.println(doc.getName() + " is NOT versionable");
}
// check out the latest version of test.txt, make some changes to the
// PWC, and
// check in the new version
if (versionable) {
Document pwc = (Document) session.getObject(doc.checkOut());
try {
content = getContentAsString(pwc.getContentStream());
} catch (IOException e) {
e.printStackTrace();
}
String updatedContents = content + "\nLine added in new version";
try {
buf = updatedContents.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
contentStream = session.getObjectFactory().createContentStream(
doc.getContentStream().getFileName(), buf.length,
doc.getContentStream().getMimeType(), new ByteArrayInputStream(buf));
// Check in the pwc
try {
pwc.checkIn(false, null, contentStream, "minor version");
} catch (Exception e) {
e.printStackTrace();
System.out.println("checkin failed, trying to cancel the checkout");
pwc.cancelCheckOut();
}
System.out.println("Document version history");
{
List<Document> versions = doc.getAllVersions();
for (Document version : versions) {
System.out.println("\tname: " + version.getName());
System.out.println("\tversion label: " + version.getVersionLabel());
System.out.println("\tversion series id: " + version.getVersionSeriesId());
System.out.println("\tchecked out by: "
+ version.getVersionSeriesCheckedOutBy());
System.out.println("\tchecked out id: "
+ version.getVersionSeriesCheckedOutId());
System.out.println("\tmajor version: " + version.isMajorVersion());
System.out.println("\tlatest version: " + version.isLatestVersion());
System.out.println("\tlatest major version: " + version.isLatestMajorVersion());
System.out.println("\tcheckin comment: " + version.getCheckinComment());
System.out.println("\tcontent length: " + version.getContentStreamLength()
+ "\n");
}
}
}
System.out.println("\nRenditions...");
System.out.println("-------------");
// Renditions - find all objects and check for renditions
if (session.getRepositoryInfo().getCapabilities().getRenditionsCapability()
.equals(CapabilityRenditions.NONE)) {
System.out.println("Repository does not support renditions");
} else {
System.out
.println("Finding first object in repository with thumbnail renditions - start");
Folder node = root;
Stack<Folder> stack = new Stack<Folder>();
while (node != null) {
children = node.getChildren();
for (CmisObject o : children) {
if ((o.getType().isBaseType() && o.getType().getId().equals("cmis:folder"))
|| o.getBaseType().getId().equals("cmis:folder")) {
stack.push((Folder) o);
} else {
OperationContext context = session.createOperationContext();
context.setRenditionFilterString("cmis:thumbnail");
CmisObject oo = session.getObject(o.getId(), context);
List<Rendition> rl = oo.getRenditions();
if (!rl.isEmpty()) {
System.out.println("found " + o.getName() + " of type "
+ o.getType().getDisplayName() + "that has renditions...");