comparison flys-client/src/main/java/de/intevation/flys/client/server/LoadArtifactServiceImpl.java @ 1307:489e6a82fe84

Partial fix for flys/issue304 (Erweiterte Funktionen W-Differenzen). flys-client/trunk@2941 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 12 Oct 2011 06:59:42 +0000
parents 2ce5d7ac9e60
children a3c04eb326f3
comparison
equal deleted inserted replaced
1306:2e57776f77b5 1307:489e6a82fe84
1 package de.intevation.flys.client.server; 1 package de.intevation.flys.client.server;
2 2
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 import java.util.HashMap;
4 5
5 import de.intevation.flys.client.shared.exceptions.ServerException; 6 import de.intevation.flys.client.shared.exceptions.ServerException;
6 import de.intevation.flys.client.shared.model.Artifact; 7 import de.intevation.flys.client.shared.model.Artifact;
7 import de.intevation.flys.client.shared.model.Collection; 8 import de.intevation.flys.client.shared.model.Collection;
8 import de.intevation.flys.client.shared.model.Recommendation; 9 import de.intevation.flys.client.shared.model.Recommendation;
51 throw new ServerException(ERROR_LOAD_ARTIFACT); 52 throw new ServerException(ERROR_LOAD_ARTIFACT);
52 } 53 }
53 54
54 55
55 /** 56 /**
56 * Clone one or more artifacts and add it to a collection. 57 * Clone one or more artifacts and add it to a collection, avoid duplicates.
57 * 58 *
58 * @param parent Collection where clones will be added to. 59 * @param parent Collection where clones will be added to.
59 * @param recommendations definitions of source of clone. 60 * @param recommendations definitions of source of clone.
60 * @param factory name of factory to use when cloning artifacts. 61 * @param factory name of factory to use when cloning artifacts.
62 * @return cloned artifacts (same artifact might be contained multiple
63 * times).
61 */ 64 */
62 public Artifact[] loadMany( 65 public Artifact[] loadMany(
63 Collection parent, 66 Collection parent,
64 Recommendation[] recoms, 67 Recommendation[] recoms,
65 String factory, 68 String factory,
66 String url, 69 String url,
67 String locale 70 String locale
68 ) 71 )
69 throws ServerException { 72 throws ServerException {
70 System.out.println("LoadArtifactServiceImpl.loadMany: " 73 System.out.println("LoadArtifactServiceImpl.loadMany");
71 + recoms[0].getMasterArtifact());
72 ArrayList<Artifact> artifacts = new ArrayList<Artifact>(); 74 ArrayList<Artifact> artifacts = new ArrayList<Artifact>();
75 HashMap<Recommendation, Artifact> cloneMap =
76 new HashMap<Recommendation, Artifact>();
73 77
74 // TODO Respect the index of what to clone. 78 // TODO Respect the index of what to clone.
75 79
76 // 1) Clone the Artifacts specified in >>recom<< 80 // 1) Clone the Artifacts specified in >>recoms<<
77 for (Recommendation recom : recoms) { 81 for (Recommendation recom : recoms) {
78 Artifact clone = ArtifactHelper.createArtifact( 82 // Do not do two clones of two identical recommendations.
79 url, locale, factory, recom); 83 Artifact prevClone = cloneMap.get(recom);
80 84 if (prevClone != null) {
81 if (clone != null) { 85 // Already cloned a recommendation like this.
82 System.out.println("Successfully create Artifact Clone. Add now!"); 86 System.out.println("LoadArtifactServiceImpl: Avoid reclones, "
83 Collection c = CollectionHelper.addArtifact( 87 + "clone already exists.");
84 parent, clone, url, locale); 88 artifacts.add(prevClone);
85 89 }
86 if (c != null) { 90 else {
87 System.out.println("Successfully added Clone to Collection."); 91 // Not already cloned.
88 92 Artifact clone = ArtifactHelper.createArtifact(
89 artifacts.add(clone); 93 url, locale, factory, recom);
94
95 if (clone != null) {
96 System.out.println("LoadArtifactServiceImple: Successfully "
97 + "loaded Artifact Clone.");
98 Collection c = CollectionHelper.addArtifact(
99 parent, clone, url, locale);
100
101 if (c != null) {
102 artifacts.add(clone);
103 // Remember we cloned a recommendation like this.
104 cloneMap.put(recom, clone);
105 }
106 else {
107 throw new ServerException(ERROR_LOAD_ARTIFACT);
108 }
90 } 109 }
91 } 110 }
92 } 111 }
93 return artifacts.toArray(new Artifact[artifacts.size()]); 112 return artifacts.toArray(new Artifact[artifacts.size()]);
94
95 //throw new ServerException(ERROR_LOAD_ARTIFACT);
96 } 113 }
97 } 114 }
98 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 115 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org