Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java @ 809:e9337488bac3
The Collection now knows its already loaded recommendations - the CollectionView will not load recommendations that have already been loaded before.
flys-client/trunk@2397 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 22 Jul 2011 12:23:36 +0000 |
parents | 374712890b94 |
children | 0fe456332785 |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java Thu Jul 21 16:06:29 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java Fri Jul 22 12:23:36 2011 +0000 @@ -14,6 +14,7 @@ import de.intevation.flys.client.shared.model.AttributedTheme; import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.shared.model.Recommendation; import de.intevation.flys.client.shared.model.Theme; import de.intevation.flys.client.shared.model.ThemeList; @@ -40,11 +41,16 @@ Map<String, OutputMode> tmpOuts = collection.getOutputModes(); Element outs = createOutputElements(cr, collection, tmpOuts); + Element recs = createRecommendationsElements(cr, collection); if (outs != null) { attr.appendChild(outs); } + if (recs != null) { + attr.appendChild(recs); + } + return doc; } @@ -166,5 +172,65 @@ return t; } + + + /** + * Creates a whole block with art:loaded-recommendations nodes. + * + * @param cr The ElementCreator used to create new elements. + * @param c The collection. + * + * @return an element with loaded recommendations. + */ + protected static Element createRecommendationsElements( + ElementCreator cr, + Collection c) + { + System.out.println("CollectionHelper.createRecommendationsElements"); + + List<Recommendation> rs = c.getRecommendations(); + + if (rs == null || rs.size() == 0) { + System.err.println("Collection did not load recommendations: " + + c.identifier()); + return null; + } + + Element loaded = cr.create("loaded-recommendations"); + + for (Recommendation r: rs) { + Element recommendation = createRecommendationElement(cr, c, r); + + if (recommendation != null) { + loaded.appendChild(recommendation); + } + } + + return loaded; + } + + + /** + * Create a node art:recommended. + * + * @param cr The ElementCreator used to create new elements. + * @param c The collection. + * @param r The Recommendation. + * + * @return an element that represents an output mode with its themes. + */ + protected static Element createRecommendationElement( + ElementCreator cr, + Collection c, + Recommendation r) + { + System.out.println("CollectionHelper.createRecommendationElement"); + + Element recommendation = cr.create("recommendation"); + cr.addAttr(recommendation, "factory", r.getFactory(), true); + cr.addAttr(recommendation, "db-ids", r.getIDs(), true); + + return recommendation; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :