# HG changeset patch # User Raimund Renkert # Date 1326384415 0 # Node ID 298a4ce64c2e046521bfd0e6e94bf466ed681cd0 # Parent b6af10d5f3da83f818d0d98efc93cba843b8238f Issue451. Load and add all recommendations together in one async request using the LoadArtifactService. flys-client/trunk@3666 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r b6af10d5f3da -r 298a4ce64c2e flys-client/ChangeLog --- a/flys-client/ChangeLog Thu Jan 12 12:33:25 2012 +0000 +++ b/flys-client/ChangeLog Thu Jan 12 16:06:55 2012 +0000 @@ -1,3 +1,12 @@ +2012-01-12 Raimund Renkert + + Issue451. + + * src/main/java/de/intevation/flys/client/client/ui/CollectionView.java: + Load and add all recommendations together in one async request using + the LoadArtifactService. This is a better way to avoid loading + multiple map tabs and reduces the amount of async requests. + 2012-01-12 Felix Wolfsteller Partial flys/issue441 (Fläche über HSQ (zweite Achse) verkehrt). diff -r b6af10d5f3da -r 298a4ce64c2e flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java Thu Jan 12 12:33:25 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java Thu Jan 12 16:06:55 2012 +0000 @@ -49,6 +49,8 @@ import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; import de.intevation.flys.client.client.services.DescribeCollectionService; import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync; +import de.intevation.flys.client.client.services.LoadArtifactService; +import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; /** @@ -79,6 +81,10 @@ protected CollectionAttributeServiceAsync updater = GWT.create(CollectionAttributeService.class); + /** The LoadArtifactService used to load recommendations*/ + protected LoadArtifactServiceAsync loadArtifactService = + GWT.create(LoadArtifactService.class); + /** The message class that provides i18n strings. */ protected FLYSConstants messages = GWT.create(FLYSConstants.class); @@ -361,14 +367,10 @@ protected void artifactChanged() { ArtifactDescription desc = getArtifact().getArtifactDescription(); OutputMode[] outs = desc.getOutputModes(); - Recommendation[] recom = desc.getRecommendations(); + final Recommendation[] recom = desc.getRecommendations(); Collection c = getCollection(); - if (recom != null && collection != null) { - loadRecommendedArtifacts(recom); - } - if (c != null) { Config config = Config.getInstance(); String locale = config.getLocale(); @@ -383,13 +385,14 @@ public void onSuccess(Collection newCollection) { GWT.log("Successfully DESCRIBED collection."); - boolean loaded = false; - List r = newCollection.getRecommendations(); - for (Recommendation rec: r) { - loaded = newCollection.loadedRecommendation(rec); + boolean loaded = true; + for (Recommendation r: recom) { + if(!newCollection.loadedRecommendation(r)) { + loaded = false; + } } - if (loaded) { - setCollection(newCollection); + if (!loaded) { + loadRecommendedArtifacts(recom); } } } @@ -575,29 +578,22 @@ } - public void addArtifactToCollection(final Artifact artifact) { + public void addArtifactToCollection(Artifact artifact) { Config config = Config.getInstance(); final String locale = config.getLocale(); final Collection collection = getCollection(); - artifactsQueue++; - addArtifactService.add( collection, artifact, locale, new AsyncCallback() { public void onFailure(Throwable caught) { GWT.log("An error occured while adding artifact."); - artifactsQueue--; SC.warn(messages.getString(caught.getMessage())); } public void onSuccess(Collection newCollection) { - GWT.log("Successfully added artifact."); + GWT.log("Successfully added artifacts."); setCollection(newCollection); - - artifactsQueue--; - addRecommendationsToCollection(); - recommendationQueue++; } } ); @@ -624,10 +620,7 @@ public void onSuccess(Collection newCol) { GWT.log("Successfully saved recommendations."); newRecommendations.removeAllElements(); - recommendationQueue--; - if(recommendationQueue == 0) { - setCollection(newCol); - } + setCollection(newCol); } } ); @@ -639,10 +632,8 @@ final String locale = config.getLocale(); final Collection collection = getCollection(); - Artifact masterArtifact = getArtifact(); - if (recommendations == null) { GWT.log("WARNING: Currently no recommendations."); return; @@ -652,6 +643,7 @@ if (collection.loadedRecommendation(recommendation)) { continue; } + newRecommendations.push(recommendation); // XXX: UGLY! If no reference artifact given use uuid of // current artifact as reference. @@ -659,25 +651,24 @@ recommendation.setMasterArtifact(masterArtifact.getUuid()); } - final String factory = recommendation.getFactory(); - - GWT.log("Load recommended artifact with factory: " + factory); + } - createArtifactService.create( - locale, factory, recommendation, - new AsyncCallback() { - public void onFailure(Throwable caught) { - GWT.log("Error loading recommendations: " + - caught.getMessage()); - } + loadArtifactService.loadMany( + collection, + recommendations, + null, + locale, + new AsyncCallback() { + public void onFailure(Throwable caught) { + GWT.log("Error loading recommendations: " + + caught.getMessage()); + } - public void onSuccess(Artifact artifact) { - GWT.log("Created new artifact: " + artifact.getUuid()); - addArtifactToCollection(artifact); - newRecommendations.push(recommendation); - } - }); - } + public void onSuccess(Artifact[] artifacts) { + GWT.log("Loaded artifacts: " + artifacts.length); + addRecommendationsToCollection(); + } + }); }