use of org.jbpm.document.Document in project jbpm by kiegroup.
the class DocumentMarshallingStrategy method unmarshal.
@SuppressWarnings({ "resource", "unused" })
@Override
public Object unmarshal(Context context, ObjectInputStream objectInputStream, byte[] object, ClassLoader classLoader) throws IOException, ClassNotFoundException {
DroolsObjectInputStream is = new DroolsObjectInputStream(new ByteArrayInputStream(object), classLoader);
// first we read out the object id and class name we stored during marshaling
String objectId = is.readUTF();
String canonicalName = is.readUTF();
String link = is.readUTF();
Document storedDoc = null;
try {
storedDoc = documentStorageService.getDocument(objectId);
storedDoc.setLink(link);
// when loaded, mark it as not updated to avoid not needed marshalling
storedDoc.addAttribute(Document.UPDATED_ATTRIBUTE, "false");
} catch (Exception e) {
throw new RuntimeException("Cannot read document from storage service", e);
}
return storedDoc;
}
use of org.jbpm.document.Document in project jbpm by kiegroup.
the class DocumentMarshallingStrategy method marshal.
@Override
public byte[] marshal(Context context, ObjectOutputStream objectOutputStream, Object o) throws IOException {
Document document = (Document) o;
String updatedAttribute = document.getAttribute(Document.UPDATED_ATTRIBUTE);
if (Boolean.parseBoolean(updatedAttribute)) {
// store via service only when it was actually updated
documentStorageService.saveDocument(document, document.getContent());
document.addAttribute(Document.UPDATED_ATTRIBUTE, "false");
}
ByteArrayOutputStream buff = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(buff);
oos.writeUTF(document.getIdentifier());
oos.writeUTF(document.getClass().getCanonicalName());
oos.writeUTF(document.getLink());
oos.close();
return buff.toByteArray();
}
use of org.jbpm.document.Document in project jbpm by kiegroup.
the class DocumentsMarshallingStrategy method marshal.
public byte[] marshal(Context ctx, ObjectOutputStream objectOutputStream, Object o) throws IOException {
ByteArrayOutputStream buff = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new ObjectOutputStream(buff)) {
Documents documents = (Documents) o;
// Write the number of documents in the list.
oos.writeInt(documents.getDocuments().size());
for (Document nextDocument : documents.getDocuments()) {
// Use the DocumentMarshallingStrategy to marshal individual documents.
byte[] nextMarshalledDocument = docMarshallingStrategy.marshal(ctx, objectOutputStream, nextDocument);
oos.writeInt(nextMarshalledDocument.length);
oos.write(nextMarshalledDocument);
// Need to call reset on the stream in order for the Document bytes to be written correctly.
oos.reset();
}
}
return buff.toByteArray();
}
use of org.jbpm.document.Document in project jbpm by kiegroup.
the class DocumentsMarshallingStrategy method unmarshal.
public Object unmarshal(Context ctx, ObjectInputStream objectInputStream, byte[] object, ClassLoader classLoader) throws IOException, ClassNotFoundException {
Documents documents = new Documents();
try (DroolsObjectInputStream is = new DroolsObjectInputStream(new ByteArrayInputStream(object), classLoader)) {
// first we read the size of the list we've stored.
int size = is.readInt();
for (int i = 0; i < size; i++) {
// Use the DocumentMarshallingStrategy to unmarshal the individual documents.
int length = is.readInt();
byte[] marshalledDocument = new byte[length];
is.readFully(marshalledDocument);
Document nextDocument = (Document) docMarshallingStrategy.unmarshal(ctx, objectInputStream, marshalledDocument, classLoader);
documents.addDocument(nextDocument);
}
}
return documents;
}
use of org.jbpm.document.Document in project jbpm by kiegroup.
the class DocumentStorageServiceImpl method listDocuments.
@Override
public List<Document> listDocuments(Integer page, Integer pageSize) {
List<Document> listOfDocs = new ArrayList<Document>();
int startIndex = page * pageSize;
int endIndex = startIndex + pageSize;
File[] documents = storageFile.listFiles();
if (documents == null) {
// happens when the docs folder doesn't exist
return Collections.emptyList();
}
// make sure the endIndex is not bigger then amount of files
if (documents.length < endIndex) {
endIndex = documents.length;
}
Arrays.sort(documents, Comparator.comparingLong(File::lastModified));
for (int i = startIndex; i < endIndex; i++) {
Document doc = getDocument(documents[i].getName());
listOfDocs.add(doc);
}
return listOfDocs;
}
Aggregations