use of org.apache.chemistry.opencmis.client.api.ObjectType in project alfresco-remote-api by Alfresco.
the class TestCMIS method testCanConnectCMISUsingDefaultTenantImpl.
private void testCanConnectCMISUsingDefaultTenantImpl(Binding binding, String cmisVersion) {
String url = httpClient.getPublicApiCmisUrl(TenantUtil.DEFAULT_TENANT, binding, cmisVersion, null);
Map<String, String> parameters = new HashMap<String, String>();
// user credentials
parameters.put(SessionParameter.USER, "admin");
parameters.put(SessionParameter.PASSWORD, "admin");
parameters.put(SessionParameter.ATOMPUB_URL, url);
parameters.put(SessionParameter.BROWSER_URL, url);
parameters.put(SessionParameter.BINDING_TYPE, binding.getOpenCmisBinding().value());
SessionFactory factory = SessionFactoryImpl.newInstance();
// perform request : http://host:port/alfresco/api/-default-/public/cmis/versions/${cmisVersion}/${binding}
List<Repository> repositories = factory.getRepositories(parameters);
assertTrue(repositories.size() > 0);
parameters.put(SessionParameter.REPOSITORY_ID, TenantUtil.DEFAULT_TENANT);
Session session = factory.createSession(parameters);
// perform request : http://host:port/alfresco/api/-default-/public/cmis/versions/${cmisVersion}/${binding}/type?id=cmis:document
ObjectType objectType = session.getTypeDefinition("cmis:document");
assertNotNull(objectType);
}
use of org.apache.chemistry.opencmis.client.api.ObjectType in project alfresco-remote-api by Alfresco.
the class TestCMIS method testMNT10430.
@Test
public void testMNT10430() throws Exception {
final TestNetwork network1 = getTestFixture().getRandomNetwork();
String username = "user" + System.currentTimeMillis();
PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
TestPerson person1 = network1.createUser(personInfo);
String person1Id = person1.getId();
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.browser, CMIS_VERSION_11, AlfrescoObjectFactoryImpl.class.getName());
ObjectType objectType = cmisSession.getTypeDefinition("D:testcmis:maDoc");
// try and get the mandatory aspects
List<String> mandatoryAspects = ((AlfrescoType) objectType).getMandatoryAspects();
System.out.println("Mandatory Aspects");
for (String mandatoryAspect : mandatoryAspects) {
System.out.println(mandatoryAspect);
}
assertTrue("The aspects should have P:cm:generalclassifiable", mandatoryAspects.contains("P:cm:generalclassifiable"));
}
use of org.apache.chemistry.opencmis.client.api.ObjectType in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method createItem.
/**
* Creates a item.
*/
protected Item createItem(Session session, Folder parent, String name, String objectTypeId) {
if (parent == null) {
throw new IllegalArgumentException("Parent is not set!");
}
if (name == null) {
throw new IllegalArgumentException("Name is not set!");
}
if (objectTypeId == null) {
throw new IllegalArgumentException("Object Type ID is not set!");
}
// check type
ObjectType type;
try {
type = session.getTypeDefinition(objectTypeId);
} catch (CmisObjectNotFoundException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Item type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
return null;
}
if (Boolean.FALSE.equals(type.isCreatable())) {
addResult(createResult(SKIPPED, "Item type '" + objectTypeId + "' is not creatable!", true));
return null;
}
// create
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
Item result = null;
try {
// create the item
result = parent.createItem(properties, null, null, null, SELECT_ALL_NO_CACHE_OC);
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Item could not be created! Exception: " + e.getMessage(), e, true));
return null;
}
try {
CmisTestResult f;
// check item name
f = createResult(FAILURE, "Item name does not match!", false);
addResult(assertEquals(name, result.getName(), null, f));
addResult(checkObject(session, result, getAllProperties(result), "New item object spec compliance"));
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created item is invalid! Exception: " + e.getMessage(), e, true));
}
// check parents
List<Folder> parents = result.getParents(SELECT_ALL_NO_CACHE_OC);
boolean found = false;
for (Folder folder : parents) {
if (parent.getId().equals(folder.getId())) {
found = true;
break;
}
}
if (!found) {
addResult(createResult(FAILURE, "The folder the item has been created in is not in the list of the item parents!"));
}
return result;
}
use of org.apache.chemistry.opencmis.client.api.ObjectType in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method createRelationship.
/**
* Creates a relationship.
*/
protected Relationship createRelationship(Session session, String name, ObjectId source, ObjectId target, String objectTypeId) {
if (name == null) {
throw new IllegalArgumentException("Name is not set!");
}
if (objectTypeId == null) {
throw new IllegalArgumentException("Object Type ID is not set!");
}
// check type
ObjectType type;
try {
type = session.getTypeDefinition(objectTypeId);
} catch (CmisObjectNotFoundException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Relationship type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
return null;
}
if (Boolean.FALSE.equals(type.isCreatable())) {
addResult(createResult(SKIPPED, "Relationship type '" + objectTypeId + "' is not creatable!", true));
return null;
}
// create
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
properties.put(PropertyIds.SOURCE_ID, source.getId());
properties.put(PropertyIds.TARGET_ID, target.getId());
ObjectId relId;
Relationship result = null;
try {
relId = session.createRelationship(properties);
result = (Relationship) session.getObject(relId, SELECT_ALL_NO_CACHE_OC);
} catch (Exception e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Relationship could not be created! Exception: " + e.getMessage(), e, true));
}
if (result != null) {
try {
// check the new relationship
addResult(checkObject(session, result, getAllProperties(result), "New document object spec compliance"));
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created document is invalid! Exception: " + e.getMessage(), e, true));
}
}
return result;
}
use of org.apache.chemistry.opencmis.client.api.ObjectType in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method createDocument.
/**
* Creates a document.
*/
protected Document createDocument(Session session, Folder parent, String name, String objectTypeId, String[] secondaryTypeIds, String content) {
if (parent == null) {
throw new IllegalArgumentException("Parent is not set!");
}
if (name == null) {
throw new IllegalArgumentException("Name is not set!");
}
if (objectTypeId == null) {
throw new IllegalArgumentException("Object Type ID is not set!");
}
if (content == null) {
content = "";
}
// check type
ObjectType type;
try {
type = session.getTypeDefinition(objectTypeId);
} catch (CmisObjectNotFoundException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Document type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
return null;
}
if (Boolean.FALSE.equals(type.isCreatable())) {
addResult(createResult(SKIPPED, "Document type '" + objectTypeId + "' is not creatable!", true));
return null;
}
// create
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
if (secondaryTypeIds != null) {
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, Arrays.asList(secondaryTypeIds));
}
type = session.getTypeDefinition(objectTypeId);
if (!(type instanceof DocumentTypeDefinition)) {
addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true));
return null;
}
DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
byte[] contentBytes = null;
Document result = null;
try {
contentBytes = IOUtils.toUTF8Bytes(content);
ContentStream contentStream = new ContentStreamImpl(name, BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes));
// create the document
result = parent.createDocument(properties, contentStream, versioningState, null, null, null, SELECT_ALL_NO_CACHE_OC);
contentStream.getStream().close();
} catch (Exception e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Document could not be created! Exception: " + e.getMessage(), e, true));
return null;
}
try {
CmisTestResult f;
// check document name
f = createResult(FAILURE, "Document name does not match!", false);
addResult(assertEquals(name, result.getName(), null, f));
// check content length
f = createResult(WARNING, "Content length does not match!", false);
addResult(assertEquals((long) contentBytes.length, result.getContentStreamLength(), null, f));
// check the new document
addResult(checkObject(session, result, getAllProperties(result), "New document object spec compliance"));
// check content
try {
ContentStream contentStream = result.getContentStream();
f = createResult(WARNING, "Document filename and the filename of the content stream do not match!", false);
addResult(assertEquals(name, contentStream.getFileName(), null, f));
f = createResult(WARNING, "cmis:contentStreamFileName and the filename of the content stream do not match!", false);
addResult(assertEquals(result.getContentStreamFileName(), contentStream.getFileName(), null, f));
String fetchedContent = getStringFromContentStream(result.getContentStream());
if (!content.equals(fetchedContent)) {
addResult(createResult(FAILURE, "Content of newly created document doesn't match the orign content!"));
}
} catch (IOException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Content of newly created document couldn't be read! Exception: " + e.getMessage(), e, true));
}
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created document is invalid! Exception: " + e.getMessage(), e, true));
}
// check parents
List<Folder> parents = result.getParents(SELECT_ALL_NO_CACHE_OC);
boolean found = false;
for (Folder folder : parents) {
if (parent.getId().equals(folder.getId())) {
found = true;
break;
}
}
if (!found) {
addResult(createResult(FAILURE, "The folder the document has been created in is not in the list of the document parents!"));
}
return result;
}
Aggregations