# HG changeset patch # User Ingo Weinzierl # Date 1306853616 0 # Node ID d9a99b28a8473d8a928bc24320eba185979c6a13 # Parent 4edaf307310957fd250047638745ee9e33d06346 Added support for the 'type' parameter of artifacts and collections out() call. artifacts/trunk@2030 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 4edaf3073109 -r d9a99b28a847 ChangeLog --- a/ChangeLog Fri May 27 08:47:31 2011 +0000 +++ b/ChangeLog Tue May 31 14:53:36 2011 +0000 @@ -1,3 +1,24 @@ +2011-05-31 Ingo Weinzierl + + * artifact-database/src/main/java/de/intevation/artifactdatabase/rest/BaseOutResource.java, + artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionOutResource.java, + artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ArtifactOutResource.java: + The 'type' part of the url is extracted and used while dispatching the + call to the artifact database. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java, + artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java: + The deferred output got a new out() method that takes the 'type' + parameter specified in the url part. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactCollection.java, + artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifact.java, + artifacts/src/main/java/de/intevation/artifacts/ArtifactCollection.java, + artifacts/src/main/java/de/intevation/artifacts/Artifact.java: + Artifacts and ArtifactCollections have two out() operations to support + the output type parameter now. I did not remove the out() without the + 'type' parameter to keep compatible with older versions. + 2011-05-27 Ingo Weinzierl * artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java: diff -r 4edaf3073109 -r d9a99b28a847 artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java --- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java Fri May 27 08:47:31 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java Tue May 31 14:53:36 2011 +0000 @@ -235,6 +235,10 @@ */ protected PersistentArtifact artifact; /** + * The output type. + */ + protected String type; + /** * The input document for the artifact's out() call. */ protected Document format; @@ -259,10 +263,12 @@ */ public DeferredOutputImpl( PersistentArtifact artifact, + String type, Document format, CallMeta callMeta ) { this.artifact = artifact; + this.type = type; this.format = format; this.callMeta = callMeta; } @@ -276,7 +282,7 @@ artifact); try { - artifact.getArtifact().out(format, output, cc); + artifact.getArtifact().out(type, format, output, cc); } finally { cc.postCall(); @@ -297,6 +303,10 @@ */ protected ArtifactCollection collection; /** + * The output type. + */ + protected String type; + /** * The input document for the collection's out() call. */ protected Document format; @@ -321,10 +331,12 @@ */ public DeferredCollectionOutputImpl( ArtifactCollection collection, + String type, Document format, CallMeta callMeta ) { this.collection = collection; + this.type = type; this.format = format; this.callMeta = callMeta; } @@ -338,7 +350,7 @@ collection); try { - collection.out(format, output, cc); + collection.out(type, format, output, cc); } finally { cc.postCall(); @@ -750,6 +762,16 @@ public DeferredOutput out( String identifier, Document format, + CallMeta callMeta) + throws ArtifactDatabaseException + { + return out(identifier, null, format, callMeta); + } + + public DeferredOutput out( + String identifier, + String type, + Document format, CallMeta callMeta ) throws ArtifactDatabaseException @@ -761,7 +783,7 @@ throw new ArtifactDatabaseException(NO_SUCH_ARTIFACT); } - return new DeferredOutputImpl(artifact, format, callMeta); + return new DeferredOutputImpl(artifact, type, format, callMeta); } public Document exportArtifact(String artifact, CallMeta callMeta) @@ -1463,9 +1485,21 @@ return result; } - public DeferredOutput outCollection(String collectionId, - Document format, CallMeta callMeta) - throws ArtifactDatabaseException + public DeferredOutput outCollection( + String collectionId, + Document format, + CallMeta callMeta) + throws ArtifactDatabaseException + { + return outCollection(collectionId, null, format, callMeta); + } + + public DeferredOutput outCollection( + String collectionId, + String type, + Document format, + CallMeta callMeta) + throws ArtifactDatabaseException { ArtifactCollectionFactory acf = getArtifactCollectionFactory(); @@ -1493,7 +1527,7 @@ c); try { - return new DeferredCollectionOutputImpl(c, format, callMeta); + return new DeferredCollectionOutputImpl(c, type, format, callMeta); } finally { cc.postCall(); diff -r 4edaf3073109 -r d9a99b28a847 artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifact.java --- a/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifact.java Fri May 27 08:47:31 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifact.java Tue May 31 14:53:36 2011 +0000 @@ -99,6 +99,19 @@ } } + public void out( + String type, + Document format, + OutputStream out, + CallContext context + ) + throws IOException + { + if (logger.isDebugEnabled()) { + logger.debug("DefaultArtifact.out: " + identifier); + } + } + public void setup(String identifier, ArtifactFactory factory, Object context, Document data) { if (logger.isDebugEnabled()) { diff -r 4edaf3073109 -r d9a99b28a847 artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactCollection.java --- a/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactCollection.java Fri May 27 08:47:31 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactCollection.java Tue May 31 14:53:36 2011 +0000 @@ -330,12 +330,17 @@ /** * Produce output for this collection. + * @param type Specifies the output type. * @param format Specifies the format of the output. * @param out Stream to write the result data to. * @param context The global context of the runtime system. * @throws IOException Thrown if an I/O occurs. */ - public void out(Document format, OutputStream out, CallContext context) + public void out( + String type, + Document format, + OutputStream out, + CallContext context) throws IOException { logger.debug("DefaultArtifactCollection.out"); diff -r 4edaf3073109 -r d9a99b28a847 artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ArtifactOutResource.java --- a/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ArtifactOutResource.java Fri May 27 08:47:31 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ArtifactOutResource.java Tue May 31 14:53:36 2011 +0000 @@ -46,11 +46,19 @@ } + protected String getType() { + Request request = getRequest(); + + return (String) request.getAttributes().get("type"); + } + + /** * Call the ArtifactDatabase.out method. */ protected ArtifactDatabase.DeferredOutput doOut( String identifier, + String type, Document input, ArtifactDatabase db, CallMeta meta) @@ -58,7 +66,7 @@ { logger.debug("ArtifactOutResource.doOut"); - return db.out(identifier, input, meta); + return db.out(identifier, type, input, meta); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 4edaf3073109 -r d9a99b28a847 artifact-database/src/main/java/de/intevation/artifactdatabase/rest/BaseOutResource.java --- a/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/BaseOutResource.java Fri May 27 08:47:31 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/BaseOutResource.java Tue May 31 14:53:36 2011 +0000 @@ -77,6 +77,7 @@ Request request = getRequest(); String identifier = getIdentifier(); + String outType = getType(); if (logger.isDebugEnabled()) { logger.debug("looking for artifact id '" + identifier + "'"); @@ -101,7 +102,7 @@ try { return new OutRepresentation( mimeType, - doOut(identifier, inputDocument, db, getCallMeta())); + doOut(identifier, outType, inputDocument, db, getCallMeta())); } catch (ArtifactDatabaseException adbe) { Response response = getResponse(); @@ -118,11 +119,20 @@ */ protected abstract String getIdentifier(); + + /** + * Returns the concrete output type of the artifact or collection. + * + * @return the output type. + */ + protected abstract String getType(); + /** * This method is called to process the operation on artifacts or * collections. * * @param identifier The identifier of the artifact or collection. + * @param type The output type. * @param input The input document of the request. * @param db The artifact database. * @param meta The CallMeta object. @@ -131,6 +141,7 @@ */ protected abstract ArtifactDatabase.DeferredOutput doOut( String identifier, + String type, Document input, ArtifactDatabase db, CallMeta meta) diff -r 4edaf3073109 -r d9a99b28a847 artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionOutResource.java --- a/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionOutResource.java Fri May 27 08:47:31 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionOutResource.java Tue May 31 14:53:36 2011 +0000 @@ -45,11 +45,19 @@ } + protected String getType() { + Request request = getRequest(); + + return (String) request.getAttributes().get("type"); + } + + /** * Call the ArtifactDatabase.outCollection method. */ protected ArtifactDatabase.DeferredOutput doOut( String identifier, + String type, Document input, ArtifactDatabase db, CallMeta meta) @@ -57,7 +65,7 @@ { logger.debug("CollectionOutResource.doOut"); - return db.outCollection(identifier, input, meta); + return db.outCollection(identifier, type, input, meta); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 4edaf3073109 -r d9a99b28a847 artifacts/src/main/java/de/intevation/artifacts/Artifact.java --- a/artifacts/src/main/java/de/intevation/artifacts/Artifact.java Fri May 27 08:47:31 2011 +0000 +++ b/artifacts/src/main/java/de/intevation/artifacts/Artifact.java Tue May 31 14:53:36 2011 +0000 @@ -104,6 +104,21 @@ throws IOException; /** + * Produce output for this artifact. + * @param type Specifies the type of the output. + * @param format Specifies the format of the output. + * @param out Stream to write the result data to. + * @param context The global context of the runtime system. + * @throws IOException Thrown if an I/O occurs. + */ + void out( + String type, + Document format, + OutputStream out, + CallContext context) + throws IOException; + + /** * When created by a factory this method is called to * initialize the artifact. * @param identifier The identifier from artifact database diff -r 4edaf3073109 -r d9a99b28a847 artifacts/src/main/java/de/intevation/artifacts/ArtifactCollection.java --- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactCollection.java Fri May 27 08:47:31 2011 +0000 +++ b/artifacts/src/main/java/de/intevation/artifacts/ArtifactCollection.java Tue May 31 14:53:36 2011 +0000 @@ -110,12 +110,14 @@ /** * Produce output for this collection. + * @param type Specifies the output type of the action. * @param format Specifies the format of the output. * @param out Stream to write the result data to. * @param context The global context of the runtime system. * @throws IOException Thrown if an I/O occurs. */ void out( + String type, Document format, OutputStream out, CallContext context) diff -r 4edaf3073109 -r d9a99b28a847 artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java --- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java Fri May 27 08:47:31 2011 +0000 +++ b/artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java Tue May 31 14:53:36 2011 +0000 @@ -129,6 +129,27 @@ DeferredOutput out(String artifact, Document format, CallMeta callMeta) throws ArtifactDatabaseException; + + /** + * Produces output for a given artifact identified by 'artifact' in + * a requested format 'format'. The writing of the data is done when + * the write() method of the returned DeferredOutput is called. This + * optimizes the out streaming of the data because the call can be + * deferred into to the calling context. + * @param artifact The identifier of the artifact. + * @param format The request format of the output. + * @param callMeta The meta information (language et. al.) of the output. + * @return The deferred output to be written later in the calling context. + * @throws ArtifactDatabaseException Thrown if something went wrong during + * producing the output. + */ + DeferredOutput out( + String artifact, + String type, + Document format, + CallMeta callMeta) + throws ArtifactDatabaseException; + /** * Produces an extenal represention of the artifact identified by * 'artifact' to be re-imported by #importArtifact(Document, CallMeta) @@ -234,5 +255,9 @@ DeferredOutput outCollection(String collectionId, Document format, CallMeta callMeta) throws ArtifactDatabaseException; + + DeferredOutput outCollection(String collectionId, String type, + Document format, CallMeta callMeta) + throws ArtifactDatabaseException; } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :