Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ingest reporting feature - Mint #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.the-fascinator.plugins</groupId>
<artifactId>plugin-harvester-csv</artifactId>
<version>1.1.3-SNAPSHOT</version>
<version>1.1.3-UWS-1-SNAPSHOT</version>
<name>Fascinator - Plugin - Harvester - CSV</name>
<parent>
<artifactId>organisation</artifactId>
<groupId>com.googlecode.the-fascinator</groupId>
<version>1.0.3</version>
</parent>
<properties>
<fascinator.version>1.1.2</fascinator.version>
<fascinator.version>1.1.3-UWS-1-SNAPSHOT</fascinator.version>
</properties>
<dependencies>
<dependency>
<groupId>com.googlecode.the-fascinator</groupId>
<artifactId>fascinator-common</artifactId>
<version>1.1.2</version>
<version>1.1.3-UWS-1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.googlecode.the-fascinator.plugins</groupId>
<artifactId>plugin-storage-ram</artifactId>
<version>1.1.2</version>
<version>1.1.3-UWS-1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public String toString() {

/** Current row */
private long currentRow;

/** Whether or not there are more files to harvest */
private boolean hasMore;

Expand Down Expand Up @@ -388,7 +388,7 @@ public void shutdown() throws HarvesterException {
public boolean hasMoreObjects() {
return hasMore;
}

/**
* Harvest the next batch of rows and return their object IDs.
*
Expand Down Expand Up @@ -523,13 +523,17 @@ private void storeJsonInObject(JsonObject dataJson, JsonObject metaJson,
DigitalObject object = null;
try {
object = getStorage().getObject(oid);
boolean isModified = isModifiedRecord(oid, dataJson);
storeJsonInPayload(dataJson, metaJson, object);
object.getMetadata().setProperty("isModified", Boolean.toString(isModified));

} catch (StorageException ex) {
// This is going to be brand new
try {
object = StorageUtils.getDigitalObject(getStorage(), oid);
storeJsonInPayload(dataJson, metaJson, object);
// newRecordCount++;
object.getMetadata().setProperty("isNew", "true");
} catch (StorageException ex2) {
throw new HarvesterException(
"Error creating new digital object: ", ex2);
Expand All @@ -546,6 +550,33 @@ private void storeJsonInObject(JsonObject dataJson, JsonObject metaJson,
}
}
}

/**
* Check if this record is going to be modified.
*
* @param oid an object id to check
* @param dataJson an instantiated JSON object containing data to store
* @returns true if modifies, false otherwise
*/
private boolean isModifiedRecord(String oid, JsonObject dataJson)
{
DigitalObject object = null;
JsonObject jo = null;
try {
object = getStorage().getObject(oid);
Payload p = object.getPayload(payloadId);
jo = new JsonSimple(p.open()).getObject("data");
return !jo.equals(dataJson);

} catch (StorageException e) {
log.error("Error retrieving object from storage: ", e);
} catch (HarvesterException e) {
log.error("Error getting harvested object' flag: ", e);
} catch (IOException e) {
log.error("Error accessing the storage' flag: ", e);
}
return false;
}

/**
* Store the processed data and metadata in a payload
Expand Down