comparison artifacts/src/main/java/org/dive4elements/river/artifacts/D4EArtifact.java @ 6140:60b94dec104b

Add handling of bound artifacts. When an artifact is bound to an out its facets will only be shown in that Out. They will be removed in the blackboard pass and marked as incompatible by the AttributeWriter
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 31 May 2013 15:29:30 +0200
parents af13ceeba52a
children cc7df824d5c4
comparison
equal deleted inserted replaced
6139:7c2a30198592 6140:60b94dec104b
84 "/art:action/art:template/@uuid"; 84 "/art:action/art:template/@uuid";
85 85
86 public static final String XPATH_FILTER = 86 public static final String XPATH_FILTER =
87 "/art:action/art:filter/art:out"; 87 "/art:action/art:filter/art:out";
88 88
89 public static final Pattern CONTAINS_OUT =
90 Pattern.compile( "^(.*):OUT=(.+)$");
91
92 /** Path to 'ids' (data) in doc that comes from datacage. */ 89 /** Path to 'ids' (data) in doc that comes from datacage. */
93 public static final String XPATH_IDS = "/art:action/art:ids/@value"; 90 public static final String XPATH_IDS = "/art:action/art:ids/@value";
94 91
92 /** Path to 'target_out' (data) in doc that comes from datacage. */
93 public static final String XPATH_TARGET_OUT = "/art:action/art:target_out/@value";
95 94
96 /** The constant string that shows that an operation was successful. */ 95 /** The constant string that shows that an operation was successful. */
97 public static final String OPERATION_SUCCESSFUL = "SUCCESS"; 96 public static final String OPERATION_SUCCESSFUL = "SUCCESS";
98 97
99 /** The constant string that shows that an operation failed. */ 98 /** The constant string that shows that an operation failed. */
118 * Used to generates "view" on the facets (hides facets not matching the 117 * Used to generates "view" on the facets (hides facets not matching the
119 * filter in output of collection); out -&gt; facets. 118 * filter in output of collection); out -&gt; facets.
120 */ 119 */
121 protected Map<String, List<Facet>> filterFacets; 120 protected Map<String, List<Facet>> filterFacets;
122 121
123 protected String boundToOut; 122 private String boundToOut;
124 123
125 124
126 /** 125 /**
127 * The default constructor that creates an empty D4EArtifact. 126 * The default constructor that creates an empty D4EArtifact.
128 */ 127 */
192 ArtifactFactory factory, 191 ArtifactFactory factory,
193 Object context, 192 Object context,
194 CallMeta callMeta, 193 CallMeta callMeta,
195 Document data) 194 Document data)
196 { 195 {
197 boolean debug = log.isDebugEnabled(); 196 log.debug("Setup this artifact with the uuid: " + identifier);
198
199 if (debug) {
200 log.debug("Setup this artifact with the uuid: " + identifier);
201 }
202 197
203 super.setup(identifier, factory, context, callMeta, data); 198 super.setup(identifier, factory, context, callMeta, data);
204 199
205 RiverContext flysContext = RiverUtils.getFlysContext(context); 200 RiverContext flysContext = RiverUtils.getFlysContext(context);
206 201
207 List<State> states = getStates(context); 202 List<State> states = getStates(context);
208 203
209 String name = getName(); 204 String name = getName();
210 205
211 if (debug) { 206 log.debug("setup(): Set initial state for artifact '" + name + "'");
212 log.debug("setup(): Set initial state for artifact '" + name + "'");
213 }
214 207
215 if (states == null) { 208 if (states == null) {
216 log.error("No states found from which an initial " 209 log.error("No states found from which an initial "
217 + "state could be picked."); 210 + "state could be picked.");
218 } 211 }
239 232
240 extractOut(data); 233 extractOut(data);
241 } 234 }
242 235
243 protected void extractOut(Document data) { 236 protected void extractOut(Document data) {
244 log.debug("extractOut"); 237 String targetOut = XMLUtils.xpathString(data, XPATH_TARGET_OUT,
245 String ids = XMLUtils.xpathString(data, XPATH_IDS,
246 ArtifactNamespaceContext.INSTANCE); 238 ArtifactNamespaceContext.INSTANCE);
247 239 if (targetOut.isEmpty()) {
248 log.debug("ids: '" + ids + "'"); 240 targetOut = null;
249 if (ids != null) { 241 }
250 Matcher m = CONTAINS_OUT.matcher(ids); 242
251 if (m.matches()) { 243 setBoundToOut(targetOut);
252 boundToOut = m.group(2);
253 log.debug("Bound to out :'" + boundToOut + "'");
254 }
255 else {
256 log.debug("does not match");
257 }
258 }
259 } 244 }
260 245
261 /** 246 /**
262 * Return the value of id element in Datacage data document. 247 * Return the value of id element in Datacage data document.
263 * @param data Document as passed by datacage. 248 * @param data Document as passed by datacage.
264 * @return the id element value of data document. 249 * @return the id element value of data document.
265 */ 250 */
266 public static String getDatacageIDValue(Document data) { 251 public static String getDatacageIDValue(Document data) {
267
268 String ids = XMLUtils.xpathString(data, XPATH_IDS, 252 String ids = XMLUtils.xpathString(data, XPATH_IDS,
269 ArtifactNamespaceContext.INSTANCE); 253 ArtifactNamespaceContext.INSTANCE);
270
271 if (ids != null) {
272 Matcher m = CONTAINS_OUT.matcher(ids);
273 if (m.matches()) {
274 ids = m.group(1);
275 }
276 }
277 254
278 return ids; 255 return ids;
279 } 256 }
280 257
281 258
975 * Get facet as stored internally, with equalling name and index than given 952 * Get facet as stored internally, with equalling name and index than given
976 * facet. 953 * facet.
977 * @param facet that defines index and name of facet searched. 954 * @param facet that defines index and name of facet searched.
978 * @return facet instance or null if not found. 955 * @return facet instance or null if not found.
979 */ 956 */
980 public Facet getNativeFacet(Facet facet) { 957 public Facet getNativeFacet(Facet facet, String outName) {
981 String name = facet.getName(); 958 String name = facet.getName();
982 int index = facet.getIndex(); 959 int index = facet.getIndex();
960 if (getBoundToOut() != null && !getBoundToOut().isEmpty() &&
961 !getBoundToOut().equals(outName)) {
962 log.debug(name + ": not returning facets for " + outName +
963 " because bound to " + getBoundToOut());
964 return null;
965 }
966 log.debug("Facet: " + facet.getName());
967 log.debug("Bound to out: " + getBoundToOut());
968 log.debug("OutName: " + outName);
983 969
984 for (List<Facet> fs: facets.values()) { 970 for (List<Facet> fs: facets.values()) {
985 for (Facet f: fs) { 971 for (Facet f: fs) {
986 if (f.getIndex() == index && f.getName().equals(name)) { 972 if (f.getIndex() == index && f.getName().equals(name)) {
987 return f; 973 return f;
1495 * 1481 *
1496 * @param id ID to map the facets to 1482 * @param id ID to map the facets to
1497 * @param facets List of facets to be stored 1483 * @param facets List of facets to be stored
1498 */ 1484 */
1499 protected void addFacets(String id, List<Facet> facets) { 1485 protected void addFacets(String id, List<Facet> facets) {
1486 for (Facet fac : facets) {
1487 fac.setBoundToOut(getBoundToOut());
1488 }
1500 this.facets.put(id, facets); 1489 this.facets.put(id, facets);
1501 } 1490 }
1502 1491
1503 1492
1504 /** 1493 /**
1507 protected void dumpArtifact() { 1496 protected void dumpArtifact() {
1508 log.debug("++++++++++++++ DUMP ARTIFACT DATA +++++++++++++++++"); 1497 log.debug("++++++++++++++ DUMP ARTIFACT DATA +++++++++++++++++");
1509 // Include uuid, type, name 1498 // Include uuid, type, name
1510 log.debug(" - Name: " + getName()); 1499 log.debug(" - Name: " + getName());
1511 log.debug(" - UUID: " + identifier()); 1500 log.debug(" - UUID: " + identifier());
1512 log.debug(" - Class: " + this.getClass().getName()); 1501 log.debug(" - Class: " + getClass().getName());
1502 log.debug(" - BoundToOut: " + getBoundToOut());
1513 1503
1514 log.debug("------ DUMP DATA ------"); 1504 log.debug("------ DUMP DATA ------");
1515 Collection<StateData> allData = data.values(); 1505 Collection<StateData> allData = data.values();
1516 1506
1517 for (StateData d: allData) { 1507 for (StateData d: allData) {
1543 for (Map.Entry<String, List<Facet>> entry: facets.entrySet()) { 1533 for (Map.Entry<String, List<Facet>> entry: facets.entrySet()) {
1544 String out = entry.getKey(); 1534 String out = entry.getKey();
1545 List<Facet> fs = entry.getValue(); 1535 List<Facet> fs = entry.getValue();
1546 for (Facet f: fs) { 1536 for (Facet f: fs) {
1547 log.debug(" # " + out + " : " + f.getName()); 1537 log.debug(" # " + out + " : " + f.getName());
1538 log.debug(" # boundToOut : " + f.getBoundToOut());
1548 } 1539 }
1549 } 1540 }
1550 1541
1551 log.debug("######## FACETS END ########"); 1542 log.debug("######## FACETS END ########");
1552 } 1543 }
1616 * Return the Facets which a state provides 1607 * Return the Facets which a state provides
1617 * @param stateid String that identifies the state 1608 * @param stateid String that identifies the state
1618 * @return List of Facets belonging to the state identifier 1609 * @return List of Facets belonging to the state identifier
1619 */ 1610 */
1620 protected List<Facet> getFacets(String stateid) { 1611 protected List<Facet> getFacets(String stateid) {
1621 return this.facets.get(stateid); 1612 return facets.get(stateid);
1622 } 1613 }
1623 1614
1624 public String getBoundToOut() { 1615 public String getBoundToOut() {
1625 return boundToOut; 1616 return boundToOut;
1626 } 1617 }
1618
1619 /**
1620 * Binds this artifact and all its facet to an out
1621 */
1622 public void setBoundToOut(String out) {
1623 boundToOut = out;
1624 for (List<Facet> stateFacets: facets.values()) {
1625 for (Facet fac: stateFacets) {
1626 fac.setBoundToOut(out);
1627 }
1628 }
1629 }
1627 } 1630 }
1628 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 1631 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org