Mercurial > dive4elements > river
changeset 1030:c586b6220f35
Datacage: Added a development mode for recommendations
flys-artifacts/trunk@2490 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 11 Aug 2011 15:08:24 +0000 |
parents | 3f3988bb6284 |
children | bcef54a563ea |
files | flys-artifacts/ChangeLog flys-artifacts/doc/conf/meta-data-user.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java |
diffstat | 3 files changed, 97 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Thu Aug 11 13:03:41 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Aug 11 15:08:24 2011 +0000 @@ -1,3 +1,13 @@ +2011-08-11 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java: + Added a development mode for recommendations. Enabled with + stetting system property 'flys.datacage.recommendations.development' to true. + When set the XML template are re-read if the timestamps of the + files have changed so you do not have to restart the server again and again. + + * doc/conf/meta-data-user.xml: Sort collections by creation time in descending order. + 2011-08-11 Felix Wolfsteller <felix.wolfsteller@intevation.de> Rather picky cosmetics only.
--- a/flys-artifacts/doc/conf/meta-data-user.xml Thu Aug 11 13:03:41 2011 +0000 +++ b/flys-artifacts/doc/conf/meta-data-user.xml Thu Aug 11 15:08:24 2011 +0000 @@ -14,10 +14,11 @@ <dc:statement>SELECT id AS collection_id FROM collections WHERE user_id = ${user_id}</dc:statement> <dc:elements> <dc:context> - <dc:statement>SELECT a.id AS a_id, a.state AS a_state, a.gid as a_gid FROM + <dc:statement>SELECT a.id AS a_id, a.state AS a_state, a.gid AS a_gid, a.creation AS a_creation FROM collection_items ci JOIN artifacts a ON ci.artifact_id = a.id WHERE collection_id = ${collection_id} AND a.state = ${current-state-id} AND a.gid <> CAST(${artifact-id} AS uuid) AND EXISTS (SELECT id FROM artifact_data WHERE artifact_id = a.id AND k = 'river' AND v = ${river}) + ORDER BY a.creation DESC </dc:statement> <dc:comment> --- TODO: We only need the 'master' artifacts! --- </dc:comment> <dc:elements> @@ -31,7 +32,7 @@ FROM facets WHERE out_id = ${out_id} ORDER BY num ASC, name DESC </dc:statement> <longitudinal_section_columns> - <dc:attribute name="description" value="${river} TODO: More infos about parameters!"/> + <dc:attribute name="description" value="${river} ${a_creation}"/> <dc:elements> <dc:element name="${facet_name}"> <dc:attribute name="description" value="${facet_description}"/>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java Thu Aug 11 13:03:41 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java Thu Aug 11 15:08:24 2011 +0000 @@ -40,6 +40,9 @@ { private static Logger log = Logger.getLogger(Recommendations.class); + private static final boolean DEVELOPMENT_MODE = + Boolean.getBoolean("flys.datacage.recommendations.development"); + public static final String XPATH_SYSTEM_TEMPLATE = "/artifact-database/metadata/system/@template"; @@ -48,23 +51,76 @@ private static Recommendations INSTANCE; - protected Builder systemBuilder; - protected Builder userBuilder; + public static class BuilderProvider + { + protected Builder builder; + + public BuilderProvider() { + } + + public BuilderProvider(Builder builder) { + this.builder = builder; + } + + public Builder getBuilder() { + return builder; + } + } // class BuilderProvider + + public static class FileBuilderProvider + extends BuilderProvider + { + protected File file; + protected long lastModified; + + public FileBuilderProvider() { + } + + public FileBuilderProvider(File file) { + this.file = file; + lastModified = Long.MIN_VALUE; + } + + @Override + public synchronized Builder getBuilder() { + long modified = file.lastModified(); + if (modified > lastModified) { + lastModified = modified; + try { + Document template = loadTemplate(file); + builder = new Builder(template); + } + catch (IOException ioe) { + log.error(ioe); + } + } + return builder; + } + + public BuilderProvider toStaticProvider() { + return new BuilderProvider(builder); + } + } // class BuilderProvider + + protected BuilderProvider systemBuilderProvider; + protected BuilderProvider userBuilderProvider; public Recommendations() { } - public Recommendations(Builder systemBuilder, Builder userBuilder) { - this.systemBuilder = systemBuilder; - this.userBuilder = userBuilder; + public Recommendations( + BuilderProvider systemBuilderProvider, + BuilderProvider userBuilderProvider) { + this.systemBuilderProvider = systemBuilderProvider; + this.userBuilderProvider = userBuilderProvider; } public Builder getUserBuilder() { - return userBuilder; + return userBuilderProvider.getBuilder(); } public Builder getSystemBuilder() { - return systemBuilder; + return systemBuilderProvider.getBuilder(); } protected static void artifactToParameters( @@ -126,11 +182,6 @@ final Node result, Session session ) { - if (systemBuilder == null || userBuilder == null) { - log.error("builder not configured properly."); - return; - } - session.doWork(new Work() { @Override public void execute(Connection systemConnection) @@ -154,7 +205,7 @@ connections.add(new Builder.NamedConnection( Builder.CONNECTION_SYSTEM, systemConnection, true)); - userBuilder.build(connections, result, parameters); + getUserBuilder().build(connections, result, parameters); } finally { userConnection.close(); @@ -164,7 +215,7 @@ connections.add(new Builder.NamedConnection( Builder.CONNECTION_SYSTEM, systemConnection, true)); - systemBuilder.build(connections, result, parameters); + getSystemBuilder().build(connections, result, parameters); } } }); @@ -218,17 +269,27 @@ return null; } - try { - Document systemTemplate = loadTemplate(systemFile); - Document userTemplate = loadTemplate(userFile); - return new Recommendations( - new Builder(systemTemplate), - new Builder(userTemplate)); - } - catch (IOException ioe) { - log.error(ioe); + FileBuilderProvider ufbp = new FileBuilderProvider(userFile); + FileBuilderProvider sfbp = new FileBuilderProvider(systemFile); + + if (ufbp.getBuilder() == null || sfbp.getBuilder() == null) { + log.error("failed loading builder"); return null; } + + BuilderProvider ubp; + BuilderProvider sbp; + + if (DEVELOPMENT_MODE) { + ubp = ufbp; + sbp = sfbp; + } + else { + ubp = ufbp.toStaticProvider(); + sbp = sfbp.toStaticProvider(); + } + + return new Recommendations(sbp, ubp); } protected static Recommendations createRecommendations() {