use of org.apache.chemistry.opencmis.client.api.Session in project SearchServices by Alfresco.
the class CMISDataCreatorTest method getSession.
private static Session getSession(String user, String pwd) {
String url = "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom";
SessionFactory factory = SessionFactoryImpl.newInstance();
Map<String, String> parameter = new HashMap<String, String>();
parameter.put(SessionParameter.USER, user);
parameter.put(SessionParameter.PASSWORD, pwd);
parameter.put(SessionParameter.ATOMPUB_URL, url);
parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
List<Repository> repositories = factory.getRepositories(parameter);
Session session = repositories.get(0).createSession();
return session;
}
use of org.apache.chemistry.opencmis.client.api.Session in project SearchServices by Alfresco.
the class CMISDataCreatorTest method testQueryDocumentProperties.
public void testQueryDocumentProperties() throws Exception {
Session session = getSession("admin", "admin");
String folderName = getRootFolderName();
Folder root = session.getRootFolder();
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
properties.put(PropertyIds.NAME, folderName);
// create the folder
Folder newFolder = root.createFolder(properties);
ItemIterable<QueryResult> result = session.query("select * from cmis:folder where cmis:name = '" + folderName + "'", false);
assertEquals(1, result.getTotalNumItems());
Document uniqueDocument = createUniqueDocument(newFolder);
result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "'", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND IN_FOLDER('" + newFolder.getId() + "')", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:document where IN_FOLDER('" + newFolder.getId() + "')", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:createdBy = '" + uniqueDocument.getCreatedBy() + "'", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:objectId = '" + uniqueDocument.getId() + "'", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:lastModifiedBy = '" + uniqueDocument.getLastModifiedBy() + "'", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "'", false);
assertEquals(1, result.getTotalNumItems());
String creationDate = ISO8601DateFormat.format(uniqueDocument.getCreationDate().getTime());
result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:creationDate = '" + creationDate + "'", false);
assertEquals(1, result.getTotalNumItems());
String modificationDate = ISO8601DateFormat.format(uniqueDocument.getLastModificationDate().getTime());
result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:lastModificationDate = '" + modificationDate + "'", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:objectTypeId = '" + uniqueDocument.getType().getQueryName() + "'", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:baseTypeId = '" + uniqueDocument.getBaseType().getQueryName() + "'", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:contentStreamFileName = '" + uniqueDocument.getContentStreamFileName() + "'", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:contentStreamLength = '" + uniqueDocument.getContentStreamLength() + "'", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:contentStreamMimeType = '" + uniqueDocument.getContentStreamMimeType() + "'", false);
assertEquals(1, result.getTotalNumItems());
}
use of org.apache.chemistry.opencmis.client.api.Session in project alfresco-remote-api by Alfresco.
the class TestRemovePermissions method testRemoveAllPermissions_WEBSERVICE_10.
/**
* cmisws?wsdl is not available using jetty in automated test suite should
* be runned using an external alfresco server
*/
// @Test
public void testRemoveAllPermissions_WEBSERVICE_10() {
Folder testFolder = null;
try {
Session session = getWEBSERVICE_10_Session();
if (session == null) {
fail("WEBSERVICE 1.0 session cannot be null");
}
testFolder = createFolder(session, "testRemoveAllPermissions_WEBSERVICE_10");
List<Ace> acl = create2TestACLs(session);
// adding new ACE
testFolder.addAcl(acl, AclPropagation.PROPAGATE);
Acl allacl = session.getAcl(session.createObjectId(testFolder.getId()), false);
int oldSize = allacl.getAces().size();
// Removing ALL ACEs
Acl newAcl = testFolder.removeAcl(allacl.getAces(), AclPropagation.PROPAGATE);
int newsize = newAcl.getAces().size();
System.out.println("Old ace size -->" + oldSize);
System.out.println("New ace size --> " + newsize);
assertTrue(newsize == oldSize - acl.size());
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
if (testFolder != null) {
testFolder.delete();
}
}
}
use of org.apache.chemistry.opencmis.client.api.Session in project alfresco-remote-api by Alfresco.
the class TestRemovePermissions method testRemoveAllPermissions_ATOMPUB_10.
@Test
public void testRemoveAllPermissions_ATOMPUB_10() {
Folder testFolder = null;
try {
Session session = getATOMPUB_10_Session();
if (session == null) {
fail("ATOMPUB 1.0 session cannot be null");
}
testFolder = createFolder(session, "testRemoveAllPermissions_ATOMPUB_10");
List<Ace> acl = create2TestACLs(session);
// adding new ACE
testFolder.addAcl(acl, AclPropagation.PROPAGATE);
Acl allacl = session.getAcl(session.createObjectId(testFolder.getId()), false);
int oldSize = allacl.getAces().size();
// Removing ALL ACEs
Acl newAcl = testFolder.removeAcl(allacl.getAces(), AclPropagation.PROPAGATE);
int newsize = newAcl.getAces().size();
System.out.println("Old ace size -->" + oldSize);
System.out.println("New ace size --> " + newsize);
assertTrue(newsize == oldSize - acl.size());
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
if (testFolder != null) {
testFolder.delete();
}
}
}
use of org.apache.chemistry.opencmis.client.api.Session in project alfresco-remote-api by Alfresco.
the class TestRemovePermissions method testRemoveAllPermissions_BROWSER_11.
@Test
public void testRemoveAllPermissions_BROWSER_11() {
Folder testFolder = null;
try {
Session session = getBROWSER_11_Session();
if (session == null) {
fail("ATOMPUB 1.1 session cannot be null");
}
testFolder = createFolder(session, "testRemoveAllPermissions_BROWSER_11");
List<Ace> acl = create2TestACLs(session);
// adding new ACE
testFolder.addAcl(acl, AclPropagation.PROPAGATE);
Acl allacl = session.getAcl(session.createObjectId(testFolder.getId()), false);
int oldSize = allacl.getAces().size();
// Removing ALL ACEs
Acl newAcl = testFolder.removeAcl(allacl.getAces(), AclPropagation.PROPAGATE);
int newsize = newAcl.getAces().size();
System.out.println("Old ace size -->" + oldSize);
System.out.println("New ace size --> " + newsize);
assertTrue(newsize == oldSize - acl.size());
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
if (testFolder != null) {
testFolder.delete();
}
}
}
Aggregations