use of org.apache.chemistry.opencmis.client.api.ObjectId in project alfresco-remote-api by Alfresco.
the class TestCMIS method testMnt11631.
@Test
public void testMnt11631() throws Exception {
final TestNetwork network = getTestFixture().getRandomNetwork();
String username = String.format(TEST_USER_NAME_PATTERN, System.currentTimeMillis());
PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
TestPerson person = network.createUser(personInfo);
String personId = person.getId();
final String siteName = String.format(TEST_SITE_NAME_PATTERN, System.currentTimeMillis());
TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {
@Override
public NodeRef doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
TestSite site = repoService.createSite(null, siteInfo);
String name = GUID.generate();
NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), name);
return folderNodeRef;
}
}, personId, network.getId());
publicApiClient.setRequestContext(new RequestContext(network.getId(), personId));
CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
Folder docLibrary = (Folder) cmisSession.getObjectByPath(String.format(DOCUMENT_LIBRARY_PATH_PATTERN, siteName));
String name = String.format(TEST_DOCUMENT_NAME_PATTERN, GUID.generate());
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
properties.put(PropertyIds.NAME, name);
ContentStreamImpl fileContent = new ContentStreamImpl();
ByteArrayInputStream stream = new ByteArrayInputStream(GUID.generate().getBytes());
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(stream);
Document doc = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
ObjectId pwcId = doc.checkOut();
Document pwc = (Document) cmisSession.getObject(pwcId.getId());
assertIsPwcProperty(pwc, false);
cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10);
CmisObject pwc10 = cmisSession.getObject(pwc.getId());
assertIsPwcProperty(pwc10, true);
}
use of org.apache.chemistry.opencmis.client.api.ObjectId in project alfresco-remote-api by Alfresco.
the class TestCMIS method testCreationDate.
/**
* MNT-12680
* The creation date of version should be the same as creation date of the original node
* @throws Exception
*/
@Test
public void testCreationDate() throws Exception {
// create a site
final TestNetwork network1 = getTestFixture().getRandomNetwork();
String username = "user" + System.currentTimeMillis();
PersonInfo personInfo = new PersonInfo(username, username, username, "password", null, null, null, null, null, null, null);
TestPerson person1 = network1.createUser(personInfo);
String person1Id = person1.getId();
final String siteName = "site" + System.currentTimeMillis();
TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {
@Override
public NodeRef doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
final TestSite site = network1.createSite(siteInfo);
final NodeRef resNode = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "testdoc.txt", "Test Doc1 Title", "Test Doc1 Description", "Test Content");
return resNode;
}
}, person1Id, network1.getId());
// create a document
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
AlfrescoFolder docLibrary = (AlfrescoFolder) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary");
Map<String, String> properties = new HashMap<String, String>();
{
properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
properties.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
}
ContentStreamImpl fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent("some content");
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
Document autoVersionedDoc = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
String objectId = autoVersionedDoc.getId();
String bareObjectId = stripCMISSuffix(objectId);
// create versions
for (int i = 0; i < 3; i++) {
Document doc1 = (Document) cmisSession.getObject(bareObjectId);
ObjectId pwcId = doc1.checkOut();
Document pwc = (Document) cmisSession.getObject(pwcId.getId());
ContentStreamImpl contentStream = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent(GUID.generate());
ContentReader reader = writer.getReader();
contentStream.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
contentStream.setStream(reader.getContentInputStream());
}
pwc.checkIn(true, Collections.EMPTY_MAP, contentStream, "checkin " + i);
}
GregorianCalendar cDateFirst = cmisSession.getAllVersions(bareObjectId).get(0).getCreationDate();
GregorianCalendar cDateSecond = cmisSession.getAllVersions(bareObjectId).get(2).getCreationDate();
if (cDateFirst.before(cDateSecond) || cDateFirst.after(cDateSecond)) {
fail("The creation date of version should be the same as creation date of the original node");
}
}
use of org.apache.chemistry.opencmis.client.api.ObjectId in project iaf by ibissource.
the class CmisSender method sendMessageForActionFetch.
private String sendMessageForActionFetch(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
Element queryElement = null;
try {
if (XmlUtils.isWellFormed(message, "cmis")) {
queryElement = XmlUtils.buildElement(message);
} else {
queryElement = XmlUtils.buildElement("<cmis/>");
}
} catch (DomBuilderException e) {
throw new SenderException(e);
}
String objectIdstr = XmlUtils.getChildTagAsString(queryElement, "objectId");
String filter = XmlUtils.getChildTagAsString(queryElement, "filter");
boolean includeAllowableActions = XmlUtils.getChildTagAsBoolean(queryElement, "includeAllowableActions");
boolean includePolicies = XmlUtils.getChildTagAsBoolean(queryElement, "includePolicies");
boolean includeAcl = XmlUtils.getChildTagAsBoolean(queryElement, "includeAcl");
OperationContext operationContext = session.createOperationContext();
if (StringUtils.isNotEmpty(filter))
operationContext.setFilterString(filter);
operationContext.setIncludeAllowableActions(includeAllowableActions);
operationContext.setIncludePolicies(includePolicies);
operationContext.setIncludeAcls(includeAcl);
CmisObject object = null;
try {
object = session.getObject(session.createObjectId(objectIdstr), operationContext);
} catch (CmisObjectNotFoundException e) {
if (StringUtils.isNotEmpty(getResultOnNotFound())) {
log.info(getLogPrefix() + "document with id [" + message + "] not found", e);
return getResultOnNotFound();
} else {
throw new SenderException(e);
}
}
XmlBuilder cmisXml = new XmlBuilder("cmis");
XmlBuilder propertiesXml = new XmlBuilder("properties");
for (Iterator it = object.getProperties().iterator(); it.hasNext(); ) {
Property property = (Property) it.next();
propertiesXml.addSubElement(getPropertyXml(property));
}
cmisXml.addSubElement(propertiesXml);
XmlBuilder allowableActionsXml = new XmlBuilder("allowableActions");
Set<Action> actions = object.getAllowableActions().getAllowableActions();
for (Action action : actions) {
XmlBuilder actionXml = new XmlBuilder("action");
actionXml.setValue(action.value());
allowableActionsXml.addSubElement(actionXml);
}
cmisXml.addSubElement(allowableActionsXml);
XmlBuilder isExactAclXml = new XmlBuilder("isExactAcl");
if (object.getAcl() != null)
isExactAclXml.setValue(object.getAcl().isExact().toString());
cmisXml.addSubElement(isExactAclXml);
XmlBuilder policiesXml = new XmlBuilder("policyIds");
List<ObjectId> policies = object.getPolicyIds();
if (policies != null) {
for (ObjectId objectId : policies) {
XmlBuilder policyXml = new XmlBuilder("policyId");
policyXml.setValue(objectId.getId());
policiesXml.addSubElement(policyXml);
}
}
cmisXml.addSubElement(policiesXml);
XmlBuilder relationshipsXml = new XmlBuilder("relationships");
List<Relationship> relationships = object.getRelationships();
if (relationships != null) {
for (Relationship relation : relationships) {
XmlBuilder policyXml = new XmlBuilder("relation");
policyXml.setValue(relation.getId());
relationshipsXml.addSubElement(policyXml);
}
}
cmisXml.addSubElement(relationshipsXml);
return cmisXml.toXML();
}
use of org.apache.chemistry.opencmis.client.api.ObjectId 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.ObjectId in project copper-cms by PogeyanOSS.
the class ChangeTokenTest method runUpdateDocumentTest.
private void runUpdateDocumentTest(Session session, Folder testFolder) {
Document doc = createDocument(session, testFolder, "update1.txt", "Hello World!");
try {
if (doc.getChangeToken() == null) {
addResult(createResult(SKIPPED, "Repository does not provide change tokens for documents. Test skipped!"));
return;
}
DocumentTypeDefinition type = (DocumentTypeDefinition) doc.getType();
PropertyDefinition<?> namePropDef = type.getPropertyDefinitions().get(PropertyIds.NAME);
if (namePropDef.getUpdatability() == Updatability.WHENCHECKEDOUT || !doc.getAllowableActions().getAllowableActions().contains(Action.CAN_UPDATE_PROPERTIES)) {
addResult(createResult(SKIPPED, "Document name can't be changed. Test skipped!"));
return;
}
// the first update should succeed
Map<String, Object> properties2 = new HashMap<String, Object>();
properties2.put(PropertyIds.NAME, "update2.txt");
ObjectId newId = doc.updateProperties(properties2, false);
if (!doc.getId().equals(newId.getId())) {
// the repository created a new version
// -> a change token test does not make sense
addResult(createResult(INFO, "The repository created a new version. Change tokens are not relevant here."));
} else {
try {
Map<String, Object> properties3 = new HashMap<String, Object>();
properties3.put(PropertyIds.NAME, "update3.txt");
doc.updateProperties(properties3, false);
addResult(createResult(FAILURE, "Updating properties a second time with the same change token " + "should result in an UpdateConflict exception!"));
// } catch (CmisUpdateConflictException e) {
} catch (CmisConstraintException e) {
// expected exception
}
}
} finally {
deleteObject(doc);
}
}
Aggregations