Mercurial > dive4elements > framework
changeset 275:e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
artifacts/trunk@2074 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 08 Jun 2011 07:36:43 +0000 |
parents | 92166f7c3842 |
children | 8b58259d3dd3 |
files | ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java artifact-database/src/main/resources/sql/org-h2-driver.properties artifact-database/src/main/resources/sql/org-postgresql-driver.properties artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java |
diffstat | 7 files changed, 82 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue Jun 07 17:09:25 2011 +0000 +++ b/ChangeLog Wed Jun 08 07:36:43 2011 +0000 @@ -1,3 +1,18 @@ +2011-06-07 Ingo Weinzierl <ingo@intevation.de> + + * artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java, + artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java, + artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java: + New methods to set the name of a collection. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java: + Dispatch the "setname" action. + + * artifact-database/src/main/resources/sql/org-h2-driver.properties, + artifact-database/src/main/resources/sql/org-postgresql-driver.properties: + Added sql statements to update the name of a collection specified by its + gid. + 2011-06-07 Ingo Weinzierl <ingo@intevation.de> flys/issue50 (Markierung von "Master-Artefakten" ermöglichen)
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java Tue Jun 07 17:09:25 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java Wed Jun 08 07:36:43 2011 +0000 @@ -1544,6 +1544,37 @@ return result; } + + public Document setCollectionName(String uuid, Document doc, CallMeta meta) + throws ArtifactDatabaseException + { + Document result = XMLUtils.newDocument(); + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + result, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element root = ec.create("result"); + result.appendChild(root); + + String name = XMLUtils.xpathString( + doc, XPATH_COLLECTION_NAME, ArtifactNamespaceContext.INSTANCE); + + logger.info("Set name of collection '" + uuid + "' to: " + name); + + if (name == null || name.length() == 0) { + logger.warn("The new name is emtpy. No new name set!"); + root.setTextContent(OPERATION_FAILURE); + return result; + } + + boolean success = backend.setCollectionName(uuid, name); + root.setTextContent(success ? OPERATION_SUCCESSFUL: OPERATION_FAILURE); + + return result; + } + + public DeferredOutput outCollection( String collectionId, Document format,
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Tue Jun 07 17:09:25 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Wed Jun 08 07:36:43 2011 +0000 @@ -129,6 +129,9 @@ public static final String SQL_UPDATE_COLLECTION_TTL = SQL.get("collections.update.ttl"); + public static final String SQL_UPDATE_COLLECTION_NAME = + SQL.get("collections.update.name"); + public static final String SQL_OUTDATE_ARTIFACTS_USER = SQL.get("outdate.artifacts.user"); @@ -1541,5 +1544,25 @@ } }.runWrite(); } + + + public boolean setCollectionName(final String uuid, final String name) { + if (!isValidIdentifier(uuid)) { + logger.debug("Invalid collection id: '" + uuid + "'"); + return false; + } + + return new SQLExecutor() { + public boolean doIt() throws SQLException { + prepareStatement(SQL_UPDATE_COLLECTION_NAME); + stmnt.setString(1, name); + stmnt.setString(2, uuid); + stmnt.execute(); + conn.commit(); + + return true; + } + }.runWrite(); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java Tue Jun 07 17:09:25 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java Wed Jun 08 07:36:43 2011 +0000 @@ -97,6 +97,9 @@ /** Action name for setting the ttl of a collection.*/ public static final String ACTION_SET_TTL = "settimetolive"; + /** Action name for setting the name of a collection.*/ + public static final String ACTION_SET_NAME = "setname"; + /** * Method to figure out which POST action was triggered and perform this @@ -176,6 +179,9 @@ else if (action.equals(ACTION_SET_TTL)) { out = db.setCollectionTTL(identifier, source, meta); } + else if (action.equals(ACTION_SET_NAME)) { + out = db.setCollectionName(identifier, source, meta); + } else { throw new ArtifactDatabaseException(NO_SUCH_ACTION_MSG); }
--- a/artifact-database/src/main/resources/sql/org-h2-driver.properties Tue Jun 07 17:09:25 2011 +0000 +++ b/artifact-database/src/main/resources/sql/org-h2-driver.properties Wed Jun 08 07:36:43 2011 +0000 @@ -100,6 +100,8 @@ collections.update.ttl=UPDATE collections SET ttl = ? WHERE id = ? +collections.update.name=UPDATE collections SET name = ? WHERE gid = ? + collections.touch.trigger.function = \ UPDATE collections SET last_access = current_timestamp \ WHERE id IN \
--- a/artifact-database/src/main/resources/sql/org-postgresql-driver.properties Tue Jun 07 17:09:25 2011 +0000 +++ b/artifact-database/src/main/resources/sql/org-postgresql-driver.properties Wed Jun 08 07:36:43 2011 +0000 @@ -100,6 +100,8 @@ collections.update.ttl=UPDATE collections SET ttl = ? WHERE gid = ?::uuid +collections.update.name=UPDATE collections SET name = ? WHERE gid = ?::uuid + collections.touch.by.gid =\ UPDATE collections SET last_access = CURRENT_TIMESTAMP \ WHERE gid = ?::uuid
--- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java Tue Jun 07 17:09:25 2011 +0000 +++ b/artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java Wed Jun 08 07:36:43 2011 +0000 @@ -262,5 +262,8 @@ Document setCollectionTTL(String collectionId, Document doc, CallMeta meta) throws ArtifactDatabaseException; + + Document setCollectionName(String collectionId, Document doc, CallMeta meta) + throws ArtifactDatabaseException; } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :