summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Terry2013-07-29 12:07:51 (EDT)
committer Gerrit Code Review @ Eclipse.org2013-07-29 14:44:47 (EDT)
commitf68494565f0d7378492f4b6a464499dcc02ce44b (patch)
treef42292b84480602dace2d42d3ceef8a9f6fad3a5
parent9a88f284e6e6dd5d21668c465454601f5e65570f (diff)
downloadorg.eclipse.lyo.rio-f68494565f0d7378492f4b6a464499dcc02ce44b.zip
org.eclipse.lyo.rio-f68494565f0d7378492f4b6a464499dcc02ce44b.tar.gz
org.eclipse.lyo.rio-f68494565f0d7378492f4b6a464499dcc02ce44b.tar.bz2
[413933] Unique URNs should be generated by the TRS referencerefs/changes/27/14927/2
application in all cases Change-Id: If079929ff0d849b0489695a6e319eb9b1a8ad248 Signed-off-by: David Terry <dgterry@us.ibm.com>
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/ChangeRequestResource.java2
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSObject.java32
2 files changed, 29 insertions, 5 deletions
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/ChangeRequestResource.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/ChangeRequestResource.java
index ce2f60a..6eb50a4 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/ChangeRequestResource.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/ChangeRequestResource.java
@@ -449,7 +449,7 @@ public class ChangeRequestResource
*/
private static String getCurrentTimeStamp() {
Date currDate = new Date();
- SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss.SS");
+ SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-ddHHmmss.SS");
String currDateStr = dateFormatGmt.format(currDate);
return currDateStr;
}
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSObject.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSObject.java
index dfc2827..5385343 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSObject.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSObject.java
@@ -159,7 +159,9 @@ public class TRSObject {
// Event in the corresponding Change Log that is already
// reflected in the Base. So set the cutoff to the URI of the
// last event.
- setCutOffEventInner(last_change_event);
+ if (last_change_event != null) {
+ setCutOffEventInner(last_change_event);
+ }
}
/**
@@ -276,6 +278,19 @@ public class TRSObject {
ChangeEvent event = null;
// increment the event number to maintain event order
int eventNumber = (last_change_event != null) ? last_change_event.getOrder() + 1 : 0;
+
+ // Append the eventNumber to the end of the changeURN to ensure it is
+ // unique. In this case of the reference application the timestamp
+ // contained in the URN might not be unique on fast servers.
+ // NOTE: if you change the way this URN is constructed you should also
+ // change the way it is parsed in the this.isPrunningNecessary() method.
+ try {
+ changeURN = new URI(changeURN.toString() + ":" + eventNumber);
+ } catch (URISyntaxException e) {
+ // Unable to create a URN with the order appended. Log the error
+ // and continue on using the old style URN
+ e.printStackTrace();
+ }
if (trsEvent.equals(TRSConstants.TRS_TYPE_CREATION)) {
event = new Creation(changeURN, resource,
@@ -525,10 +540,19 @@ public class TRSObject {
*/
private boolean isPrunningNecessary(URI urn) throws ParseException {
// Get the time of the event in milliseconds
- String urnWithTime = urn.toString();
- String eventTime = urnWithTime.split(URN_PREFIX)[1];
+ String eventTime = urn.toString();
+
+ try {
+ // This should be URN_PREFIX + timestamp + : + order number. Based
+ // on the number of : in this string we want the 4th element of the
+ // array which counting from 0 is 3.
+ eventTime = eventTime.split(":")[3];
+ } catch (NullPointerException e) {
+ // Unexpected URN format do not prune this event
+ return false;
+ }
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss.SS");
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-ddHHmmss.SS");
Date eventDate = formatter.parse(eventTime);
long eventMilliseconds = eventDate.getTime();