Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java @ 845:4db672cdacb2
Added outs/facet filters when creation new artifacts.
flys-client/trunk@2569 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 24 Aug 2011 16:06:48 +0000 |
parents | 78ef14dc1877 |
children | 478a571f1f94 |
comparison
equal
deleted
inserted
replaced
844:ac70261bb3f8 | 845:4db672cdacb2 |
---|---|
1 package de.intevation.flys.client.server; | 1 package de.intevation.flys.client.server; |
2 | 2 |
3 import org.w3c.dom.Document; | 3 import org.w3c.dom.Document; |
4 | 4 |
5 import java.util.ArrayList; | |
6 import java.util.List; | |
7 import java.util.Map; | |
5 | 8 |
6 import com.google.gwt.user.server.rpc.RemoteServiceServlet; | 9 import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
7 | 10 |
8 import de.intevation.artifacts.common.utils.ClientProtocolUtils; | 11 import de.intevation.artifacts.common.utils.ClientProtocolUtils; |
12 import de.intevation.artifacts.common.utils.CreationFilter; | |
9 | 13 |
10 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; | 14 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; |
11 import de.intevation.artifacts.httpclient.http.HttpClient; | 15 import de.intevation.artifacts.httpclient.http.HttpClient; |
12 import de.intevation.artifacts.httpclient.http.HttpClientImpl; | 16 import de.intevation.artifacts.httpclient.http.HttpClientImpl; |
13 | 17 |
34 | 38 |
35 public Artifact create( | 39 public Artifact create( |
36 String serverUrl, | 40 String serverUrl, |
37 String locale, | 41 String locale, |
38 String factory, | 42 String factory, |
39 String uuid, | |
40 Recommendation recommendation | 43 Recommendation recommendation |
41 ) | 44 ) |
42 throws ServerException | 45 throws ServerException |
43 { | 46 { |
44 System.out.println("ArtifactServiceImpl.create"); | 47 System.out.println("ArtifactServiceImpl.create"); |
45 | 48 |
46 Document create = null; | 49 String uuid; |
50 String ids; | |
51 CreationFilter filter; | |
47 | 52 |
48 if (uuid != null && uuid.length() > 0) { | 53 if (recommendation != null) { |
49 String ids = recommendation != null | 54 uuid = recommendation.getMasterArtifact(); |
50 ? recommendation.getIDs() | 55 ids = recommendation.getIDs(); |
51 : null; | 56 filter = convertFilter(recommendation.getFilter()); |
52 | |
53 create = ClientProtocolUtils.newCreateDocument( | |
54 factory, uuid, ids); | |
55 } | 57 } |
56 else { | 58 else { |
57 create = ClientProtocolUtils.newCreateDocument(factory); | 59 uuid = null; |
60 ids = null; | |
61 filter = null; | |
58 } | 62 } |
63 | |
64 Document create = ClientProtocolUtils.newCreateDocument( | |
65 factory, uuid, ids, filter); | |
59 | 66 |
60 HttpClient client = new HttpClientImpl(serverUrl, locale); | 67 HttpClient client = new HttpClientImpl(serverUrl, locale); |
61 | 68 |
62 try { | 69 try { |
63 return (Artifact) client.create(create, new FLYSArtifactCreator()); | 70 return (Artifact) client.create(create, new FLYSArtifactCreator()); |
66 System.err.println(ce.getLocalizedMessage()); | 73 System.err.println(ce.getLocalizedMessage()); |
67 } | 74 } |
68 | 75 |
69 throw new ServerException(ERROR_CREATE_ARTIFACT); | 76 throw new ServerException(ERROR_CREATE_ARTIFACT); |
70 } | 77 } |
78 | |
79 public static CreationFilter convertFilter(Recommendation.Filter filter) { | |
80 | |
81 if (filter == null) { | |
82 return null; | |
83 } | |
84 | |
85 CreationFilter cf = new CreationFilter(); | |
86 | |
87 Map<String, List<Recommendation.Facet>> outs = filter.getOuts(); | |
88 | |
89 for (Map.Entry<String, List<Recommendation.Facet>> entry: | |
90 outs.entrySet()) { | |
91 List<Recommendation.Facet> rfs = entry.getValue(); | |
92 List<CreationFilter.Facet> cfs = | |
93 new ArrayList<CreationFilter.Facet>(rfs.size()); | |
94 for (Recommendation.Facet rf: rfs) { | |
95 cfs.add(new CreationFilter.Facet(rf.getName(), rf.getIndex())); | |
96 } | |
97 cf.add(entry.getKey(), cfs); | |
98 } | |
99 | |
100 return cf; | |
101 } | |
71 } | 102 } |
72 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 103 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |