Skip to content

Commit

Permalink
issue #9
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoika committed Nov 1, 2017
1 parent f875a80 commit 3f9f10d
Show file tree
Hide file tree
Showing 13 changed files with 509 additions and 38 deletions.
13 changes: 13 additions & 0 deletions imixs-archive-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,16 @@ that these ejbs are accessable from the workflow engine:
# Testing

The imixs-archive-api module includes jUnit tests. The jUnit test class _org.imixs.archive.api.TestSnaptshotService_ mocks the EJB _SnapshotService_ and simulates the processing of a workitem within the [Imixs WorkflowMockEnvironment](http://www.imixs.org/doc/testing.html#WorkflowMockEnvironment). The test BPMN model '_TestSnapshotService.bpmn_' is used to simulate a workflow.


# Migration

The SnapshotService replaces the now deprecated DMSPlugin. For a migration only the DMSPlugin need to be removed from the Models.
No further migration step is necessary.

The Item 'dms' with the file meta information will be handled by the SnapshotService.





12 changes: 6 additions & 6 deletions imixs-archive-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@


<!-- https://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox -->
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>${apache.pdfbox.version}</version>
</dependency>

<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>${apache.pdfbox.version}</version>
</dependency>

<!-- JSON Parser -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
* Ralph Soika - Software Developer
*******************************************************************************/

package org.imixs.archive.api;
package org.imixs.archive.core;

/**
* An SnapshotException is a runtime exception which is thrown by a
* SnapshotService if data is not read or writable.
*
* @see org.imixs.archive.api.SnapshotService
* @see org.imixs.archive.core.SnapshotService
* @author rsoika
*
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.imixs.archive.api;
package org.imixs.archive.core;

import java.util.Collection;
import java.util.List;
Expand All @@ -12,12 +12,11 @@
import javax.ejb.Stateless;
import javax.enterprise.event.Observes;

import org.imixs.archive.lucene.FileParserService;
import org.imixs.archive.dms.FileParserService;
import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.WorkflowKernel;
import org.imixs.workflow.engine.DocumentEvent;
import org.imixs.workflow.engine.DocumentService;
import org.imixs.workflow.exceptions.InvalidAccessException;
import org.imixs.workflow.exceptions.QueryException;

/**
Expand Down Expand Up @@ -78,7 +77,7 @@ public class SnapshotService {
private static Logger logger = Logger.getLogger(SnapshotService.class.getName());

public static String SNAPSHOTID = "$snapshotID";
private static String TYPE_PRAFIX = "snapshot-";
public static String TYPE_PRAFIX = "snapshot-";

/**
* The snapshot-workitem is created immediately after the workitem was processed
Expand Down Expand Up @@ -136,18 +135,18 @@ public void onSave(@Observes DocumentEvent documentEvent) {
}

// 5. remove file content form the origin-workitem
Map<String, List<Object>> files = snapshot.getFiles();
Map<String, List<Object>> files = documentEvent.getDocument().getFiles();
if (files != null) {
// empty data...
byte[] empty = { 0 };
byte[] empty = { };
for (Entry<String, List<Object>> entry : files.entrySet()) {
String aFilename = entry.getKey();
List<?> file = entry.getValue();
// remove content....
// remove content if size > 1....
String contentType = (String) file.get(0);
byte[] fileContent = (byte[]) file.get(1);
if (fileContent != null && fileContent.length > 1) {
// add the file name (with empty data)
if (fileContent != null && fileContent.length > 0) {
// update the file name with empty data
logger.fine("drop content for file '" + aFilename + "'");
documentEvent.getDocument().addFile(empty, aFilename, contentType);
}
Expand All @@ -165,28 +164,24 @@ public void onSave(@Observes DocumentEvent documentEvent) {
snapshot.replaceItemValue(DocumentService.NOINDEX, true);
snapshot.replaceItemValue(DocumentService.IMMUTABLE, true);

// lucene: indexing file content... (experimental)
// fileParserService.parse(snapshot);

// so nochmal ein kleiner test ob wir überhaupt daten haben.....
// Map<String, List<Object>> testfiles = snapshot.getFiles();



documentService.save(snapshot);
}

/**
* This method returns the latest Snapshot-workitem for a given $UNIQUEID, or
* null if no snapshot-workitem exists.
*
* The method queries the possible snapshot id-range for a given $UniqueId sorted
* by creation date descending and returns the first match.
* The method queries the possible snapshot id-range for a given $UniqueId
* sorted by creation date descending and returns the first match.
*
* @param uniqueid
* @return
*/
ItemCollection findLastSnapshot(String uniqueid) {
if (uniqueid == null || uniqueid.isEmpty()) {
throw new InvalidAccessException(DocumentService.INVALID_UNIQUEID, "undefined $uniqueid");
throw new SnapshotException(DocumentService.INVALID_UNIQUEID, "undefined $uniqueid");
}

String query = "SELECT document FROM Document AS document ";
Expand All @@ -206,7 +201,7 @@ ItemCollection findLastSnapshot(String uniqueid) {
void removeDeprecatedSnaphosts(String snapshotID) {

if (snapshotID == null || snapshotID.isEmpty()) {
throw new InvalidAccessException(DocumentService.INVALID_UNIQUEID, "undefined $snapshotID");
throw new SnapshotException(DocumentService.INVALID_UNIQUEID, "undefined $snapshotID");
}

String snapshtIDPfafix = snapshotID.substring(0, snapshotID.lastIndexOf('-'));
Expand All @@ -215,7 +210,7 @@ void removeDeprecatedSnaphosts(String snapshotID) {
List<ItemCollection> result = documentService.getDocumentsByQuery(query);

if (result.size() > 0) {
logger.fine("remove deprecated snapshots before snapshot: '" + snapshotID + "'....");
logger.fine("searching deprecated snapshots before snapshot: '" + snapshotID + "'....");
for (ItemCollection oldSnapshot : result) {
logger.fine("remove deprecated snapshot: " + oldSnapshot.getUniqueID());
documentService.remove(oldSnapshot);
Expand Down Expand Up @@ -245,11 +240,11 @@ private boolean copyFilesFromItemCollection(ItemCollection source, ItemCollectio
// test if the content of the file is empty. In this case it makes sense to copy
// the already archived conent from the last snapshot
byte[] content = (byte[]) file.get(1);
if (content.length <= 1) {
if (content.length == 0) {
// fetch the old content from the last snapshot...
List<Object> oldFile = source.getFile(fileName);
if (oldFile != null) {
logger.fine("copy file content from last snapshot: " + source.getUniqueID());
logger.fine("copy file content '" + fileName +"' from snapshot: " + source.getUniqueID());
target.addFile((byte[]) oldFile.get(1), fileName, (String) oldFile.get(0));
} else {
missingContent = true;
Expand Down
Loading

0 comments on commit 3f9f10d

Please sign in to comment.