summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Terry2013-07-11 10:23:36 (EDT)
committer David Terry2013-07-11 10:23:36 (EDT)
commitef7ebcef9807ac888a5d73866ee6e5cd267f480d (patch)
tree9acecea2af7c3793a5c505b0f53b5465dac09fd0
parentb456d0b7fb4fe487fb30fbefa8f354f1cd35267f (diff)
downloadorg.eclipse.lyo.rio-ef7ebcef9807ac888a5d73866ee6e5cd267f480d.zip
org.eclipse.lyo.rio-ef7ebcef9807ac888a5d73866ee6e5cd267f480d.tar.gz
org.eclipse.lyo.rio-ef7ebcef9807ac888a5d73866ee6e5cd267f480d.tar.bz2
[412691] Use more meaningful about URIs for TRS change eventsrefs/changes/74/14474/1
This fix uses URNs, containing time stamps, for the about URI of change events. These URNs more uniquely identify a given change event. Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=412691 Change-Id: Ibfe36d930fecf00f0545754ad27cf5df882cc685 Signed-off-by: David Terry <dgterry@us.ibm.com>
-rw-r--r--org.eclipse.lyo.rio.trs/pom.xml2
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/ChangeRequestResource.java73
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/TRSResource.java16
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/ChangeLogGeneric.java2
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/TRSGeneric.java2
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/ResponseUtil.java35
6 files changed, 44 insertions, 86 deletions
diff --git a/org.eclipse.lyo.rio.trs/pom.xml b/org.eclipse.lyo.rio.trs/pom.xml
index 873d213..93308a1 100644
--- a/org.eclipse.lyo.rio.trs/pom.xml
+++ b/org.eclipse.lyo.rio.trs/pom.xml
@@ -17,7 +17,7 @@
<dependency>
<groupId>org.eclipse.lyo</groupId>
<artifactId>org.eclipse.lyo.core.utils</artifactId>
- <version>2.0-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
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 a1be423..ce2f60a 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
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
import java.net.URISyntaxException;
+import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.RequestDispatcher;
@@ -69,7 +70,7 @@ import org.eclipse.lyo.rio.trs.util.TRSUtil;
public class ChangeRequestResource
{
@Context ServletContext servletContext;
- static long currentNumber = -1;
+ private static String URN_PREFIX = "urn:urn-3:cm1.example.com:";
// Handle the HTML request from browser.
@POST
@@ -91,7 +92,7 @@ public class ChangeRequestResource
ChangeRequest changeRequest = Persistence.persistChangeRequest(baseURI, cr);
- TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), createRelativeURN());
+ TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), getCurrentTimeStampURN());
// Send back to the form a small JSON response.
httpServletResponse.setContentType("application/json");
@@ -132,7 +133,7 @@ public class ChangeRequestResource
Persistence.updateChangeRequest(changeRequestId, changeRequest);
// TRS - Insert the modification event to the change log
- TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_MODIFICATION, changeRequest.getAbout(), createRelativeURN());
+ TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_MODIFICATION, changeRequest.getAbout(), getCurrentTimeStampURN());
String eTag = getETagFromChangeRequest(changeRequest);
httpServletResponse.setContentType("application/json");
@@ -333,7 +334,7 @@ public class ChangeRequestResource
if (changeRequest != null)
{
// TRS - Insert the deletion event to the change log
- TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_DELETION, changeRequest.getAbout(), createRelativeURN());
+ TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_DELETION, changeRequest.getAbout(), getCurrentTimeStampURN());
return Response.ok().build();
@@ -361,39 +362,39 @@ public class ChangeRequestResource
ChangeRequest changeRequest = null;
changeRequest = Persistence.persistChangeRequest(baseURI, Persistence.createChangeRequest("Unable to execute Apache Tomcat due to missing Java runtime environment (JRE).",
"Apache Tomcat requires JRE", "Server"));
- TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), createRelativeURN());
+ TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), getCurrentTimeStampURN());
changeRequest = Persistence.persistChangeRequest(baseURI, Persistence.createChangeRequest("Operating system password required to be alphanumeric with at least eight characters.",
"Password complexity rules", "Server"));
- TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), createRelativeURN());
+ TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), getCurrentTimeStampURN());
changeRequest = Persistence.persistChangeRequest(baseURI, Persistence.createChangeRequest("Misspelling in error message in XYZZY product.",
"Error message mispelling", "Client"));
- TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), createRelativeURN());
+ TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), getCurrentTimeStampURN());
changeRequest = Persistence.persistChangeRequest(baseURI, Persistence.createChangeRequest("Unable to execute Apache Tomcat due to missing Java runtime environment (JRE).",
"Integer et elementum est. Maecenas bibendum fermentum pharetra.", "Server"));
- TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), createRelativeURN());
+ TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), getCurrentTimeStampURN());
changeRequest = Persistence.persistChangeRequest(baseURI, Persistence.createChangeRequest("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sed pharetra lectus..",
"Password complexity rules", "Client"));
- TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), createRelativeURN());
+ TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), getCurrentTimeStampURN());
changeRequest = Persistence.persistChangeRequest(baseURI, Persistence.createChangeRequest("Vestibulum volutpat, est vehicula tincidunt tincidunt, tortor ipsum consequat ante, sit amet ultricies elit dui ac massa. Nulla facilisi..",
"Fusce dapibus imperdiet porta.", "Server"));
- TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), createRelativeURN());
+ TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), getCurrentTimeStampURN());
changeRequest = Persistence.persistChangeRequest(baseURI, Persistence.createChangeRequest("Nunc aliquet scelerisque leo, eu molestie enim fermentum nec. Nulla lectus dui, dictum non sodales quis, dictum sed ante. Proin quam nulla, euismod ac facilisis eu, rhoncus vel quam. Donec ac ligula ante. Nulla egestas quam sit amet neque placerat quis iaculis risus tincidunt. Mauris a sapien nulla.",
"Suspendisse lobortis nisi nisl, et imperdiet nisl.", "Client"));
- TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), createRelativeURN());
+ TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), getCurrentTimeStampURN());
changeRequest = Persistence.persistChangeRequest(baseURI, Persistence.createChangeRequest("Ut felis risus, blandit eu tristique sed, vulputate non ligula. Donec interdum mi sed odio bibendum eget placerat mi tempus. Pellentesque id erat mauris.",
"Duis placerat scelerisque purus sed tincidunt.", "Server"));
- TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), createRelativeURN());
+ TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), getCurrentTimeStampURN());
changeRequest = Persistence.persistChangeRequest(baseURI, Persistence.createChangeRequest("Etiam lacinia cursus risus at iaculis. Nunc metus nisi, lobortis vitae consequat nec, hendrerit nec augue.",
"Donec sit amet felis purus.", "Client"));
- TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), createRelativeURN());
+ TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), getCurrentTimeStampURN());
return "Success!";
}
@@ -420,24 +421,36 @@ public class ChangeRequestResource
} catch (Exception e) {
throw new WebApplicationException(e);
- }
-
+ }
}
-
- // This method generates a simple unique URN for a change event based on
- // an in-memory counter. This URN identifies a particular change event while
- // the server is running. In a production system it is often useful to persist
- // change logs so that the same change event URN can be used on a restart of
- // the application. This allows consumers of the the feed to know which
- // changes events have already been viewed.
- private static URI createRelativeURN() {
- // Incrementally track change events since the start of the system.
- currentNumber++;
+
+ /**
+ * This method generates a simple unique URN for a change event based on
+ * the current system time. The URN allows consumers of the the feed
+ * to know which changes events have already been viewed.
+ *
+ * @return
+ */
+ private static URI getCurrentTimeStampURN() {
+ URI timestampURI = null;
try {
- return new URI("#" + currentNumber);
- } catch (URISyntaxException e) {
- // TODO Auto-generated catch block
- return null;
- }
+ timestampURI = new URI(URN_PREFIX + getCurrentTimeStamp());
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
+ return timestampURI;
+ }
+
+ /**
+ * Generates a string in the format of yyyy-MM-ddHH:mm:ss.SS which can be
+ * used as part of a unique URN for change events.
+ *
+ * @return
+ */
+ private static String getCurrentTimeStamp() {
+ Date currDate = new Date();
+ SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss.SS");
+ String currDateStr = dateFormatGmt.format(currDate);
+ return currDateStr;
}
}
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/TRSResource.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/TRSResource.java
index 06d127c..bbe1772 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/TRSResource.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/TRSResource.java
@@ -45,7 +45,6 @@ import org.eclipse.lyo.core.trs.TrackedResourceSet;
import org.eclipse.lyo.oslc4j.core.annotation.OslcService;
import org.eclipse.lyo.oslc4j.core.model.OslcMediaType;
import org.eclipse.lyo.rio.trs.cm.PersistenceResourceUtil;
-import org.eclipse.lyo.rio.trs.util.ResponseUtil;
import org.eclipse.lyo.rio.trs.util.TRSObject;
import org.eclipse.lyo.rio.trs.util.TRSUtil;
@@ -107,11 +106,6 @@ public class TRSResource {
URI base = requestBase.resolve("trs/"+TRSConstants.TRS_TERM_BASE+"/");
set.setBase(base);
-
- // Determine the response type and alter the about URIs as appropriate
- // (turtle prefers relative URIs while RDF/XML requires absolute URIs)
- String responseType = ResponseUtil.parseAcceptType(httpServletRequest);
- ResponseUtil.fixRelativeUris(responseType, requestURI.toString(), changeLog);
set.setChangeLog(changeLog);
@@ -133,11 +127,6 @@ public class TRSResource {
TRSObject trsObject = TRSUtil.getTrsObject(PersistenceResourceUtil.instance, requestURI);
AbstractChangeLog changeLog = trsObject.getCurrentChangeLog();
-
- // Determine the response type and alter the about URIs as appropriate
- // (turtle prefers relative URIs while RDF/XML requires absolute URIs)
- String responseType = ResponseUtil.parseAcceptType(httpServletRequest);
- ResponseUtil.fixRelativeUris(responseType, requestURI.toString(), changeLog);
return changeLog;
}
@@ -160,11 +149,6 @@ public class TRSResource {
if (changeLog == null)
throw new WebApplicationException(Status.NOT_FOUND);
-
- // Determine the response type and alter the about URIs as appropriate
- // (turtle prefers relative URIs while RDF/XML requires absolute URIs)
- String responseType = ResponseUtil.parseAcceptType(httpServletRequest);
- ResponseUtil.fixRelativeUris(responseType, requestURI.toString(), changeLog);
return changeLog;
}
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/ChangeLogGeneric.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/ChangeLogGeneric.java
index f8f0b56..e952b05 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/ChangeLogGeneric.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/ChangeLogGeneric.java
@@ -89,8 +89,6 @@ public class ChangeLogGeneric extends HttpServlet {
} else if (responseType.equals(OslcMediaType.APPLICATION_RDF_XML)) {
marshaller.setMediaType(MediaType.APPLICATION_XML_TYPE);
}
-
- ResponseUtil.fixRelativeUris(responseType, requestBase.toString(), changeLog);
ServletOutputStream outputStream = response.getOutputStream();
oArray[0] = changeLog;
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/TRSGeneric.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/TRSGeneric.java
index ba154f8..f1468ed 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/TRSGeneric.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/TRSGeneric.java
@@ -105,8 +105,6 @@ public class TRSGeneric extends HttpServlet {
} else if (responseType.equals(OslcMediaType.APPLICATION_RDF_XML)) {
marshaller.setMediaType(MediaType.APPLICATION_XML_TYPE);
}
-
- ResponseUtil.fixRelativeUris(responseType, requestBase.toString(), changeLog);
ServletOutputStream outputStream = response.getOutputStream();
oArray[0] = set;
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/ResponseUtil.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/ResponseUtil.java
index 1467075..ab21c15 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/ResponseUtil.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/ResponseUtil.java
@@ -16,17 +16,11 @@
package org.eclipse.lyo.rio.trs.util;
import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response.Status;
-import org.eclipse.lyo.core.trs.AbstractChangeLog;
-import org.eclipse.lyo.core.trs.ChangeEvent;
-import org.eclipse.lyo.core.trs.ChangeLog;
import org.eclipse.lyo.oslc4j.core.model.OslcMediaType;
/**
@@ -34,35 +28,6 @@ import org.eclipse.lyo.oslc4j.core.model.OslcMediaType;
* of TRS toolkit resources for the servlet based implementation.
*/
public class ResponseUtil {
-
- /**
- * This method examines the incoming response type and alters the relative
- * about URIs stored on the events of the change log. For turtle output the
- * relative URIs are left alone or restored if necessary. For RDF/XML the
- * requestBase is added to the relative URI to get the appropriate absolute
- * URI (since RDF/XML does not allow relative about URIs).
- *
- * @param responseType
- * @param requestBase
- * @param changeLog
- * @throws URISyntaxException
- */
- public static void fixRelativeUris(String responseType, String requestBase, AbstractChangeLog changeLog) throws URISyntaxException {
- // If this is a populated change log it has relative uris we need to fix
- // or the RDF/XML will be illegal
- if (changeLog instanceof ChangeLog) {
- List<ChangeEvent> events = ((ChangeLog) changeLog).getChange();
-
- for (ChangeEvent event : events) {
- if (!(responseType.equals(OslcMediaType.TEXT_TURTLE))) {
- event.setAbout(new URI(requestBase + "#" + Integer.toString(event.getOrder())));
- } else {
- event.setAbout(new URI("#" + Integer.toString(event.getOrder())));
- }
- }
- }
- }
-
/**
* Return a string representing the requested accept type. Right now we
* support text/turle and application/rdf+xml with text/turtle