Page History
...
Code Block | ||
---|---|---|
| ||
InputStream stream = new ByteArrayInputStream(contentString.getBytes("UTF-8")); CustomContentProperties properties = new CustomContentProperties(); properties.setProperty("customProperty", new StringValue("value")); String contentName = "content name"; String contentType = "text/plain"; Long processId = null; String caseId = null; if(contentManager instanceof IChannelContentManager channelContentManager) { // Using the Java NIO-based API introduced in Blueriq 17.4 GUID contentId = channelContentManager.create(Channels.newChannel(stream), contentName, contentType, nullprocessId, nullcaseId, properties, context.getSessionScope().getActiveUser()); } else { // Using the stream-based API that was deprecated in Blueriq 17.4 and might be released in a future release GUID contentId = contentManager.create(stream, contentName, contentType, nullprocessId, nullcaseId, properties, context.getSessionScope().getActiveUser()); } |
The properties object may be used to store additional properties with the content. The contentId will be required to read, update or delete this content at a later time.
Read metadata
To retrieve file metadata, including custom properties, you may use the readMetadata method, for example:
Code Block | ||
---|---|---|
| ||
IContentMetadata metadata = contentManager.readMetadata(contentId, context.getSessionScope().getActiveUser(), true); IValue propertyValue = metadata.getProperties().getProperty("customProperty"); |
Read content
The following code snippet shows how to retrieve the string that was created in the previous example.
Code Block | ||
---|---|---|
| ||
IContentMetadata metadata = contentManager.readMetadata(contentId, context.getSessionScope().getActiveUser(), true); String contentString; if(contentManager instanceof IChannelContentManager channelContentManager) { // Using the Java NIO-based API introduced in Blueriq 17.4 } else { // Using the stream-based API that was deprecated in Blueriq 17.4 and might be released in a future releaserelease InputStreambyte[] streamcontent = contentManager.readData(contentId, context.getSessionScope().getActiveUser())new byte[(int) metadata.getSize()]; String contentString = new String(StreamUtil.getBytes(stream), "UTF-8"); } |
To retrieve the custom property you may use the readMetadata method, for example:
Code Block | ||
---|---|---|
| ||
IContentMetadata metadata = contentManager.readMetadata(contentIdcontentManager.readBytes(contentId, 0, content, 0, (int) metadata.getSize(), context.getSessionScope().getActiveUser()); StringValue propertyValuecontentString = metadata.getProperties().getProperty("customProperty");new String(content, StandardCharsets.UTF_8); } |
Update existing content
It is possible to update only the data, only properties or both. The following code snippet shows how to update all at once, overloads exists which do not require all arguments:
Code Block | ||
---|---|---|
| ||
InputStream stream = new ByteArrayInputStream(newContentString.getBytes("UTF-8")); CustomContentProperties properties = new CustomContentProperties(); properties.setProperty("customProperty", new StringValue("newValue")); String contentName = "new content name"; String contentType = "text/plain"; Long processId = null; String caseId = null; if(contentManager instanceof IChannelContentManager channelContentManager) { // Using the Java NIO-based API introduced in Blueriq 17.4 contentManager.update(contentId, Channels.newChannel(stream), contentName, contentType, processId, caseId, properties, context.getSessionScope().getActiveUser()); } else { // Using the stream-based API that was deprecated in Blueriq 17.4 and might be released in a future release contentManager.update(contentId, stream, contentName, contentType, processId, caseId, properties, context.getSessionScope().getActiveUser()); } |
Delete content
The following example shows how to delete the content made in the previous example:
...
Overview
Content Tools