use of org.apache.chemistry.opencmis.client.api.Document in project iaf by ibissource.
the class CmisSender method sendMessageForActionCreate.
private String sendMessageForActionCreate(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
String fileName = (String) prc.getSession().get(getFileNameSessionKey());
InputStream inputStream = null;
if (StringUtils.isNotEmpty(fileInputStreamSessionKey)) {
inputStream = (FileInputStream) prc.getSession().get(getFileInputStreamSessionKey());
} else {
String fileContent = (String) prc.getSession().get(getFileContentSessionKey());
byte[] bytes = Base64.decodeBase64((String) fileContent);
inputStream = new ByteArrayInputStream(bytes);
}
long fileLength = 0;
try {
fileLength = inputStream.available();
} catch (IOException e) {
log.warn(getLogPrefix() + "could not determine file size", e);
}
String mediaType;
Map props = new HashMap();
Element cmisElement;
try {
if (XmlUtils.isWellFormed(message, "cmis")) {
cmisElement = XmlUtils.buildElement(message);
} else {
cmisElement = XmlUtils.buildElement("<cmis/>");
}
String objectTypeId = XmlUtils.getChildTagAsString(cmisElement, "objectTypeId");
if (StringUtils.isNotEmpty(objectTypeId)) {
props.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
} else {
props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
}
String name = XmlUtils.getChildTagAsString(cmisElement, "name");
if (StringUtils.isEmpty(fileName)) {
fileName = XmlUtils.getChildTagAsString(cmisElement, "fileName");
}
mediaType = XmlUtils.getChildTagAsString(cmisElement, "mediaType");
if (StringUtils.isNotEmpty(name)) {
props.put(PropertyIds.NAME, name);
} else if (StringUtils.isNotEmpty(fileName)) {
props.put(PropertyIds.NAME, fileName);
} else {
props.put(PropertyIds.NAME, "[unknown]");
}
Element propertiesElement = XmlUtils.getFirstChildTag(cmisElement, "properties");
if (propertiesElement != null) {
processProperties(propertiesElement, props);
}
} catch (DomBuilderException e) {
throw new SenderException(getLogPrefix() + "exception parsing [" + message + "]", e);
}
if (StringUtils.isEmpty(mediaType)) {
mediaType = getDefaultMediaType();
}
if (isUseRootFolder()) {
Folder folder = session.getRootFolder();
ContentStream contentStream = session.getObjectFactory().createContentStream(fileName, fileLength, mediaType, inputStream);
Document document = folder.createDocument(props, contentStream, null);
log.debug(getLogPrefix() + "created new document [ " + document.getId() + "]");
return document.getId();
} else {
ContentStream contentStream = session.getObjectFactory().createContentStream(fileName, fileLength, mediaType, inputStream);
ObjectId objectId = session.createDocument(props, null, contentStream, null);
log.debug(getLogPrefix() + "created new document [ " + objectId.getId() + "]");
return objectId.getId();
}
}
use of org.apache.chemistry.opencmis.client.api.Document in project alfresco-repository by Alfresco.
the class OpenCmisLocalTest method testALF10085.
public void testALF10085() throws InterruptedException {
Repository repository = getRepository("admin", "admin");
Session session = repository.createSession();
Folder rootFolder = session.getRootFolder();
Map<String, String> props = new HashMap<String, String>();
{
props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document");
props.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
}
Document doc1 = rootFolder.createDocument(props, null, null);
props = new HashMap<String, String>();
{
props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document");
props.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
}
Document doc2 = rootFolder.createDocument(props, null, null);
Thread.sleep(6000);
session.getObject(doc1);
doc1.refresh();
Calendar doc1LastModifiedBefore = (Calendar) doc1.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
assertNotNull(doc1LastModifiedBefore);
doc2.refresh();
Calendar doc2LastModifiedBefore = (Calendar) doc2.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
assertNotNull(doc2LastModifiedBefore);
// Add relationship A to B
props = new HashMap<String, String>();
{
props.put(PropertyIds.OBJECT_TYPE_ID, "R:cmiscustom:assoc");
props.put(PropertyIds.NAME, "A Relationship");
props.put(PropertyIds.SOURCE_ID, doc1.getId());
props.put(PropertyIds.TARGET_ID, doc2.getId());
}
session.createRelationship(props);
doc1.refresh();
Calendar doc1LastModifiedAfter = (Calendar) doc1.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
assertNotNull(doc1LastModifiedAfter);
doc2.refresh();
Calendar doc2LastModifiedAfter = (Calendar) doc2.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
assertNotNull(doc2LastModifiedAfter);
assertEquals(doc1LastModifiedBefore, doc1LastModifiedAfter);
assertEquals(doc2LastModifiedBefore, doc2LastModifiedAfter);
}
use of org.apache.chemistry.opencmis.client.api.Document in project alfresco-repository by Alfresco.
the class OpenCmisLocalTest method testDownloadEvent.
public void testDownloadEvent() throws InterruptedException {
Repository repository = getRepository("admin", "admin");
Session session = repository.createSession();
Folder rootFolder = session.getRootFolder();
String docname = "mydoc-" + GUID.generate() + ".txt";
Map<String, String> props = new HashMap<String, String>();
{
props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document");
props.put(PropertyIds.NAME, docname);
}
// content
byte[] byteContent = "Hello from Download testing class".getBytes();
InputStream stream = new ByteArrayInputStream(byteContent);
ContentStream contentStream = new ContentStreamImpl(docname, BigInteger.valueOf(byteContent.length), "text/plain", stream);
Document doc1 = rootFolder.createDocument(props, contentStream, VersioningState.MAJOR);
NodeRef doc1NodeRef = cmisIdToNodeRef(doc1.getId());
ContentStream content = doc1.getContentStream();
assertNotNull(content);
// range request
content = doc1.getContentStream(BigInteger.valueOf(2), BigInteger.valueOf(4));
assertNotNull(content);
}
use of org.apache.chemistry.opencmis.client.api.Document in project alfresco-repository by Alfresco.
the class OpenCmisLocalTest method testEncodingForCreateContentStream.
public void testEncodingForCreateContentStream() {
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
FileFolderService ffs = serviceRegistry.getFileFolderService();
// Authenticate as system
AuthenticationComponent authenticationComponent = (AuthenticationComponent) ctx.getBean(BEAN_NAME_AUTHENTICATION_COMPONENT);
authenticationComponent.setSystemUserAsCurrentUser();
try {
/* Create the document using openCmis services */
Repository repository = getRepository("admin", "admin");
Session session = repository.createSession();
Folder rootFolder = session.getRootFolder();
Document document = createDocument(rootFolder, "test_file_" + GUID.generate() + ".txt", session);
ContentStream content = document.getContentStream();
assertNotNull(content);
content = document.getContentStream(BigInteger.valueOf(2), BigInteger.valueOf(4));
assertNotNull(content);
NodeRef doc1NodeRef = cmisIdToNodeRef(document.getId());
FileInfo fileInfo = ffs.getFileInfo(doc1NodeRef);
Map<QName, Serializable> properties = fileInfo.getProperties();
ContentDataWithId contentData = (ContentDataWithId) properties.get(QName.createQName("{http://www.alfresco.org/model/content/1.0}content"));
String encoding = contentData.getEncoding();
assertEquals("ISO-8859-1", encoding);
} finally {
authenticationComponent.clearCurrentSecurityContext();
}
}
use of org.apache.chemistry.opencmis.client.api.Document in project wildfly-camel by wildfly-extras.
the class CmisIntegrationTest method getDocumentContentAsString.
private String getDocumentContentAsString(String nodeId) throws Exception {
CmisObject cmisObject = retrieveCMISObjectByIdFromServer(nodeId);
Document doc = (Document) cmisObject;
InputStream inputStream = doc.getContentStream().getStream();
return readFromStream(inputStream);
}
Aggregations