Mercurial > dive4elements > river
diff gwt-client/src/test/java/test/SimpleRecommendation.java @ 9148:48d87af1243e
Unit testing flowdepthdevelopment added
author | gernotbelger |
---|---|
date | Tue, 12 Jun 2018 15:04:40 +0200 |
parents | dbb26bc81843 |
children | 83aee0942eae |
line wrap: on
line diff
--- a/gwt-client/src/test/java/test/SimpleRecommendation.java Tue Jun 12 10:40:33 2018 +0200 +++ b/gwt-client/src/test/java/test/SimpleRecommendation.java Tue Jun 12 15:04:40 2018 +0200 @@ -9,6 +9,20 @@ */ package test; +import java.util.ArrayList; +import java.util.HashMap; + +import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException; +import org.dive4elements.river.client.client.ui.NilDatacageTwinPanelInfo; +import org.dive4elements.river.client.client.ui.RecommandationUtils; +import org.dive4elements.river.client.server.ArtifactHelper; +import org.dive4elements.river.client.server.CollectionHelper; +import org.dive4elements.river.client.server.LoadArtifactServiceImpl; +import org.dive4elements.river.client.shared.exceptions.ServerException; +import org.dive4elements.river.client.shared.model.Artifact; +import org.dive4elements.river.client.shared.model.Collection; +import org.dive4elements.river.client.shared.model.Recommendation; + /** * @author Domenico Nardi Tironi * @@ -19,6 +33,7 @@ private final String factory; private final String ids; private final String target; + private String displayName; public SimpleRecommendation(final String factory, final String ids, final String target) { this.factory = factory; @@ -26,6 +41,11 @@ this.target = target; } + public SimpleRecommendation(final String factory, final String ids, final String target, final String displayName) { + this(factory, ids, target); + this.displayName = displayName; + } + public String getIds() { return this.ids; } @@ -38,4 +58,56 @@ return this.factory; } + private String getDisplayName() { + return this.displayName; + } + + public final String getRecommendationPairString(final SimpleRecommendation rec2, final Collection collection, final String serverUrl, final String locale) + throws ConnectionException, ServerException { + final Recommendation recom1 = new Recommendation(this.getFactory(), this.getIds(), this.getTarget()); + recom1.setDisplayName(this.displayName); + final Recommendation recom2 = new Recommendation(rec2.getFactory(), rec2.getIds(), rec2.getTarget()); + recom2.setDisplayName(rec2.getDisplayName()); + final Artifact[] artifacts = loadMany(new Recommendation[] { recom1, recom2 }, null, collection, serverUrl, locale); + final String rec1String = RecommandationUtils.createDataString(artifacts[0].getUuid(), recom1, new NilDatacageTwinPanelInfo("xxxx")); + final String rec2String = RecommandationUtils.createDataString(artifacts[1].getUuid(), recom2, new NilDatacageTwinPanelInfo("xxxx")); + final String combinedIdNeu = rec1String + "#" + rec2String; + return combinedIdNeu; + + } + + private final Artifact[] loadMany(final Recommendation[] recoms, final String factory, final Collection collection, final String serverUrl, + final String locale) throws ServerException, ConnectionException { + final ArrayList<Artifact> artifacts = new ArrayList<Artifact>(); + final HashMap<Recommendation, Artifact> cloneMap = new HashMap<Recommendation, Artifact>(); + + for (final Recommendation recom : recoms) { + + final Artifact prevClone = cloneMap.get(recom); + if (prevClone != null) { + + artifacts.add(prevClone); + } else { + // Not already cloned. + final String realFactory = factory != null ? factory : recom.getFactory(); + + final Artifact clone = ArtifactHelper.createArtifact(serverUrl, locale, realFactory, recom); + + if (clone != null) { + final Collection c = CollectionHelper.addArtifact(collection, clone, serverUrl, locale); + + if (c != null) { + artifacts.add(clone); + // Remember we cloned a recommendation like this. + cloneMap.put(recom, clone); + } else { + throw new ServerException(LoadArtifactServiceImpl.ERROR_LOAD_ARTIFACT); + } + } + } + } + return artifacts.toArray(new Artifact[artifacts.size()]); + + } + }