comparison flys-client/src/main/java/de/intevation/flys/client/server/LoadArtifactServiceImpl.java @ 1346:a3c04eb326f3

Allowed to load Artifacts with different factories in one go. flys-client/trunk@3009 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 18 Oct 2011 14:08:36 +0000
parents 489e6a82fe84
children ab8eb2f544f2
comparison
equal deleted inserted replaced
1345:92074508a387 1346:a3c04eb326f3
20 extends ArtifactServiceImpl 20 extends ArtifactServiceImpl
21 implements LoadArtifactService 21 implements LoadArtifactService
22 { 22 {
23 public static final String ERROR_LOAD_ARTIFACT = "error_load_artifact"; 23 public static final String ERROR_LOAD_ARTIFACT = "error_load_artifact";
24 24
25
26 /**
27 * Clones or creates a single artifact and adds it to a collection.
28 *
29 * Note that in contrast to loadMany, always the given factory is used
30 * to clone the artifact.
31 *
32 * @param parent collection to add recommendation to.
33 * @param recom recommendation to create clone for.
34 * @param factory factory to use.
35 * @param url servers url.
36 * @param locale the locale to translate messages.
37 */
25 public Artifact load( 38 public Artifact load(
26 Collection parent, 39 Collection parent,
27 Recommendation recom, 40 Recommendation recom,
28 String factory, 41 String factory,
29 String url, 42 String url,
52 throw new ServerException(ERROR_LOAD_ARTIFACT); 65 throw new ServerException(ERROR_LOAD_ARTIFACT);
53 } 66 }
54 67
55 68
56 /** 69 /**
57 * Clone one or more artifacts and add it to a collection, avoid duplicates. 70 * Clone/create one or more artifacts and add it to a collection, avoiding
71 * duplicates.
58 * 72 *
59 * @param parent Collection where clones will be added to. 73 * @param parent Collection where clones will be added to.
60 * @param recommendations definitions of source of clone. 74 * @param recoms definitions of source of clone.
61 * @param factory name of factory to use when cloning artifacts. 75 * @param factory name of factory to use when cloning artifacts (can be
76 * null in which case the recommendations getFactory() will
77 * be used.
78 * @param url servers url.
79 * @param locale the locale to translate messages.
80 *
62 * @return cloned artifacts (same artifact might be contained multiple 81 * @return cloned artifacts (same artifact might be contained multiple
63 * times). 82 * times).
64 */ 83 */
65 public Artifact[] loadMany( 84 public Artifact[] loadMany(
66 Collection parent, 85 Collection parent,
69 String url, 88 String url,
70 String locale 89 String locale
71 ) 90 )
72 throws ServerException { 91 throws ServerException {
73 System.out.println("LoadArtifactServiceImpl.loadMany"); 92 System.out.println("LoadArtifactServiceImpl.loadMany");
93
74 ArrayList<Artifact> artifacts = new ArrayList<Artifact>(); 94 ArrayList<Artifact> artifacts = new ArrayList<Artifact>();
75 HashMap<Recommendation, Artifact> cloneMap = 95 HashMap<Recommendation, Artifact> cloneMap =
76 new HashMap<Recommendation, Artifact>(); 96 new HashMap<Recommendation, Artifact>();
77 97
78 // TODO Respect the index of what to clone. 98 // TODO Respect the index of what to clone.
87 + "clone already exists."); 107 + "clone already exists.");
88 artifacts.add(prevClone); 108 artifacts.add(prevClone);
89 } 109 }
90 else { 110 else {
91 // Not already cloned. 111 // Not already cloned.
112 String realFactory = factory != null
113 ? factory
114 : recom.getFactory();
115
116 System.out.println("One will be cloned with : " + realFactory);
117
92 Artifact clone = ArtifactHelper.createArtifact( 118 Artifact clone = ArtifactHelper.createArtifact(
93 url, locale, factory, recom); 119 url, locale, realFactory, recom);
94 120
95 if (clone != null) { 121 if (clone != null) {
96 System.out.println("LoadArtifactServiceImple: Successfully " 122 System.out.println("LoadArtifactServiceImple: Successfully "
97 + "loaded Artifact Clone."); 123 + "loaded Artifact Clone.");
98 Collection c = CollectionHelper.addArtifact( 124 Collection c = CollectionHelper.addArtifact(

http://dive4elements.wald.intevation.org