Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
9147:28fe5e654495 | 9148:48d87af1243e |
---|---|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | 7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
8 * documentation coming with Dive4Elements River for details. | 8 * documentation coming with Dive4Elements River for details. |
9 */ | 9 */ |
10 package test; | 10 package test; |
11 | 11 |
12 import java.util.ArrayList; | |
13 import java.util.HashMap; | |
14 | |
15 import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException; | |
16 import org.dive4elements.river.client.client.ui.NilDatacageTwinPanelInfo; | |
17 import org.dive4elements.river.client.client.ui.RecommandationUtils; | |
18 import org.dive4elements.river.client.server.ArtifactHelper; | |
19 import org.dive4elements.river.client.server.CollectionHelper; | |
20 import org.dive4elements.river.client.server.LoadArtifactServiceImpl; | |
21 import org.dive4elements.river.client.shared.exceptions.ServerException; | |
22 import org.dive4elements.river.client.shared.model.Artifact; | |
23 import org.dive4elements.river.client.shared.model.Collection; | |
24 import org.dive4elements.river.client.shared.model.Recommendation; | |
25 | |
12 /** | 26 /** |
13 * @author Domenico Nardi Tironi | 27 * @author Domenico Nardi Tironi |
14 * | 28 * |
15 */ | 29 */ |
16 public class SimpleRecommendation { | 30 public class SimpleRecommendation { |
17 | 31 |
18 // entspricht den Bezeichnungen im Datacage-Export | 32 // entspricht den Bezeichnungen im Datacage-Export |
19 private final String factory; | 33 private final String factory; |
20 private final String ids; | 34 private final String ids; |
21 private final String target; | 35 private final String target; |
36 private String displayName; | |
22 | 37 |
23 public SimpleRecommendation(final String factory, final String ids, final String target) { | 38 public SimpleRecommendation(final String factory, final String ids, final String target) { |
24 this.factory = factory; | 39 this.factory = factory; |
25 this.ids = ids; | 40 this.ids = ids; |
26 this.target = target; | 41 this.target = target; |
42 } | |
43 | |
44 public SimpleRecommendation(final String factory, final String ids, final String target, final String displayName) { | |
45 this(factory, ids, target); | |
46 this.displayName = displayName; | |
27 } | 47 } |
28 | 48 |
29 public String getIds() { | 49 public String getIds() { |
30 return this.ids; | 50 return this.ids; |
31 } | 51 } |
36 | 56 |
37 public String getFactory() { | 57 public String getFactory() { |
38 return this.factory; | 58 return this.factory; |
39 } | 59 } |
40 | 60 |
61 private String getDisplayName() { | |
62 return this.displayName; | |
63 } | |
64 | |
65 public final String getRecommendationPairString(final SimpleRecommendation rec2, final Collection collection, final String serverUrl, final String locale) | |
66 throws ConnectionException, ServerException { | |
67 final Recommendation recom1 = new Recommendation(this.getFactory(), this.getIds(), this.getTarget()); | |
68 recom1.setDisplayName(this.displayName); | |
69 final Recommendation recom2 = new Recommendation(rec2.getFactory(), rec2.getIds(), rec2.getTarget()); | |
70 recom2.setDisplayName(rec2.getDisplayName()); | |
71 final Artifact[] artifacts = loadMany(new Recommendation[] { recom1, recom2 }, null, collection, serverUrl, locale); | |
72 final String rec1String = RecommandationUtils.createDataString(artifacts[0].getUuid(), recom1, new NilDatacageTwinPanelInfo("xxxx")); | |
73 final String rec2String = RecommandationUtils.createDataString(artifacts[1].getUuid(), recom2, new NilDatacageTwinPanelInfo("xxxx")); | |
74 final String combinedIdNeu = rec1String + "#" + rec2String; | |
75 return combinedIdNeu; | |
76 | |
77 } | |
78 | |
79 private final Artifact[] loadMany(final Recommendation[] recoms, final String factory, final Collection collection, final String serverUrl, | |
80 final String locale) throws ServerException, ConnectionException { | |
81 final ArrayList<Artifact> artifacts = new ArrayList<Artifact>(); | |
82 final HashMap<Recommendation, Artifact> cloneMap = new HashMap<Recommendation, Artifact>(); | |
83 | |
84 for (final Recommendation recom : recoms) { | |
85 | |
86 final Artifact prevClone = cloneMap.get(recom); | |
87 if (prevClone != null) { | |
88 | |
89 artifacts.add(prevClone); | |
90 } else { | |
91 // Not already cloned. | |
92 final String realFactory = factory != null ? factory : recom.getFactory(); | |
93 | |
94 final Artifact clone = ArtifactHelper.createArtifact(serverUrl, locale, realFactory, recom); | |
95 | |
96 if (clone != null) { | |
97 final Collection c = CollectionHelper.addArtifact(collection, clone, serverUrl, locale); | |
98 | |
99 if (c != null) { | |
100 artifacts.add(clone); | |
101 // Remember we cloned a recommendation like this. | |
102 cloneMap.put(recom, clone); | |
103 } else { | |
104 throw new ServerException(LoadArtifactServiceImpl.ERROR_LOAD_ARTIFACT); | |
105 } | |
106 } | |
107 } | |
108 } | |
109 return artifacts.toArray(new Artifact[artifacts.size()]); | |
110 | |
111 } | |
112 | |
41 } | 113 } |