comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 3554:9b356ed24411

FLYSArtifact: Lowered logging output level from info to debug. Made some more debug outputs conditional. flys-artifacts/trunk@5148 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 28 Jul 2012 20:58:42 +0000
parents 5da58c5c1517
children b1912514e0f5
comparison
equal deleted inserted replaced
3553:5da58c5c1517 3554:9b356ed24411
56 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 56 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
57 */ 57 */
58 public abstract class FLYSArtifact extends DefaultArtifact { 58 public abstract class FLYSArtifact extends DefaultArtifact {
59 59
60 /** The logger that is used in this artifact. */ 60 /** The logger that is used in this artifact. */
61 private static Logger logger = Logger.getLogger(FLYSArtifact.class); 61 private static Logger log = Logger.getLogger(FLYSArtifact.class);
62 62
63 public static final String COMPUTING_CACHE = "computed.values"; 63 public static final String COMPUTING_CACHE = "computed.values";
64 64
65 /** The XPath that points to the input data elements of the FEED document. */ 65 /** The XPath that points to the input data elements of the FEED document. */
66 public static final String XPATH_FEED_INPUT = 66 public static final String XPATH_FEED_INPUT =
132 132
133 FLYSContext flysContext = FLYSUtils.getFlysContext(context); 133 FLYSContext flysContext = FLYSUtils.getFlysContext(context);
134 StateEngine engine = (StateEngine) flysContext.get( 134 StateEngine engine = (StateEngine) flysContext.get(
135 FLYSContext.STATE_ENGINE_KEY); 135 FLYSContext.STATE_ENGINE_KEY);
136 136
137 boolean debug = log.isDebugEnabled();
138
137 for (String stateId: stateIds) { 139 for (String stateId: stateIds) {
138 logger.debug("Append static data for state: " + stateId); 140 if (debug) {
141 log.debug("Append static data for state: " + stateId);
142 }
139 DefaultState state = (DefaultState) engine.getState(stateId); 143 DefaultState state = (DefaultState) engine.getState(stateId);
140 144
141 ui.appendChild(state.describeStatic(this, doc, ui, context, uuid)); 145 ui.appendChild(state.describeStatic(this, doc, ui, context, uuid));
142 } 146 }
143 } 147 }
168 ArtifactFactory factory, 172 ArtifactFactory factory,
169 Object context, 173 Object context,
170 CallMeta callMeta, 174 CallMeta callMeta,
171 Document data) 175 Document data)
172 { 176 {
173 logger.debug("Setup this artifact with the uuid: " + identifier); 177 boolean debug = log.isDebugEnabled();
178
179 if (debug) {
180 log.debug("Setup this artifact with the uuid: " + identifier);
181 }
174 182
175 super.setup(identifier, factory, context, callMeta, data); 183 super.setup(identifier, factory, context, callMeta, data);
176 184
177 FLYSContext flysContext = FLYSUtils.getFlysContext(context); 185 FLYSContext flysContext = FLYSUtils.getFlysContext(context);
178 186
179 List<State> states = getStates(context); 187 List<State> states = getStates(context);
180 188
181 String name = getName(); 189 String name = getName();
182 logger.debug("Set initial state for artifact '" + name + "'"); 190
191 if (debug) {
192 log.debug("Set initial state for artifact '" + name + "'");
193 }
183 194
184 if (states == null) { 195 if (states == null) {
185 logger.error("No states found from which an initial " 196 log.error("No states found from which an initial "
186 + "state could be picked."); 197 + "state could be picked.");
187 } 198 }
188 setCurrentState(states.get(0)); 199 setCurrentState(states.get(0));
189 200
190 String model = XMLUtils.xpathString( 201 String model = XMLUtils.xpathString(
198 209
199 try { 210 try {
200 initialize(db.getRawArtifact(model), context, callMeta); 211 initialize(db.getRawArtifact(model), context, callMeta);
201 } 212 }
202 catch (ArtifactDatabaseException adbe) { 213 catch (ArtifactDatabaseException adbe) {
203 logger.error(adbe, adbe); 214 log.error(adbe, adbe);
204 } 215 }
205 } 216 }
206 217
207 filterFacets = buildFilterFacets(data); 218 filterFacets = buildFilterFacets(data);
208 } 219 }
220 * @param other Artifact from which to get data. 231 * @param other Artifact from which to get data.
221 * @param name Name of data. 232 * @param name Name of data.
222 */ 233 */
223 protected void importData(FLYSArtifact other, final String name) { 234 protected void importData(FLYSArtifact other, final String name) {
224 if (other == null) { 235 if (other == null) {
225 logger.error("No other art. to import data " + name + " from."); 236 log.error("No other art. to import data " + name + " from.");
226 return; 237 return;
227 } 238 }
228 239
229 StateData sd = other.getData(name); 240 StateData sd = other.getData(name);
230 241
231 if (sd == null) { 242 if (sd == null) {
232 logger.warn("Other artifact has no data " + name + "."); 243 log.warn("Other artifact has no data " + name + ".");
233 return; 244 return;
234 } 245 }
235 246
236 this.addData(name, sd); 247 this.addData(name, sd);
237 } 248 }
343 int index; 354 int index;
344 try { 355 try {
345 index = Integer.parseInt(facetElement.getAttribute("index")); 356 index = Integer.parseInt(facetElement.getAttribute("index"));
346 } 357 }
347 catch (NumberFormatException nfe) { 358 catch (NumberFormatException nfe) {
348 logger.warn(nfe); 359 log.warn(nfe);
349 index = 0; 360 index = 0;
350 } 361 }
351 facets.add(new DefaultFacet(index, fName, "")); 362 facets.add(new DefaultFacet(index, fName, ""));
352 } 363 }
353 364
368 * 379 *
369 * @return a document that contains a SUCCESS or FAILURE message. 380 * @return a document that contains a SUCCESS or FAILURE message.
370 */ 381 */
371 @Override 382 @Override
372 public Document feed(Document target, CallContext context) { 383 public Document feed(Document target, CallContext context) {
373 logger.info("FLYSArtifact.feed()"); 384 log.debug("FLYSArtifact.feed()");
374 385
375 Document doc = XMLUtils.newDocument(); 386 Document doc = XMLUtils.newDocument();
376 387
377 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( 388 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
378 doc, 389 doc,
408 * 419 *
409 * @return the description of this artifact. 420 * @return the description of this artifact.
410 */ 421 */
411 @Override 422 @Override
412 public Document describe(Document data, CallContext context) { 423 public Document describe(Document data, CallContext context) {
413 logger.debug("Describe: the current state is: " + getCurrentStateId()); 424
414 425 if (log.isDebugEnabled()) {
415 if (logger.isDebugEnabled()) { 426 log.debug(
427 "Describe: the current state is: " + getCurrentStateId());
416 dumpArtifact(); 428 dumpArtifact();
417 } 429 }
418 430
419 FLYSContext flysContext = FLYSUtils.getFlysContext(context); 431 FLYSContext flysContext = FLYSUtils.getFlysContext(context);
420 432
527 Element outs, 539 Element outs,
528 CallContext context, 540 CallContext context,
529 String uuid) 541 String uuid)
530 { 542 {
531 List<Output> generated = getOutputs(context); 543 List<Output> generated = getOutputs(context);
532 logger.debug("This Artifact has " + generated.size() + " Outputs."); 544
545 if (log.isDebugEnabled()) {
546 log.debug("This Artifact has " + generated.size() + " Outputs.");
547 }
533 548
534 ProtocolUtils.appendOutputModes(doc, outs, generated); 549 ProtocolUtils.appendOutputModes(doc, outs, generated);
535 } 550 }
536 551
537 552
544 * 559 *
545 * @return a document that contains a SUCCESS or FAILURE message. 560 * @return a document that contains a SUCCESS or FAILURE message.
546 */ 561 */
547 @Override 562 @Override
548 public Document advance(Document target, CallContext context) { 563 public Document advance(Document target, CallContext context) {
564
565 boolean debug = log.isDebugEnabled();
566
549 Document doc = XMLUtils.newDocument(); 567 Document doc = XMLUtils.newDocument();
550 568
551 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( 569 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
552 doc, 570 doc,
553 ArtifactNamespaceContext.NAMESPACE_URI, 571 ArtifactNamespaceContext.NAMESPACE_URI,
557 575
558 String currentStateId = getCurrentStateId(); 576 String currentStateId = getCurrentStateId();
559 String targetState = XMLUtils.xpathString( 577 String targetState = XMLUtils.xpathString(
560 target, XPATH_ADVANCE_TARGET, ArtifactNamespaceContext.INSTANCE); 578 target, XPATH_ADVANCE_TARGET, ArtifactNamespaceContext.INSTANCE);
561 579
562 logger.info("FLYSArtifact.advance() to '" + targetState + "'"); 580 if (debug) {
581 log.debug("FLYSArtifact.advance() to '" + targetState + "'");
582 }
563 583
564 if (!currentStateId.equals(targetState) 584 if (!currentStateId.equals(targetState)
565 && isStateReachable(targetState, context)) 585 && isStateReachable(targetState, context))
566 { 586 {
567 logger.info("Advance: Step forward"); 587 if (debug) {
588 log.debug("Advance: Step forward");
589 }
568 590
569 List<String> prev = getPreviousStateIds(); 591 List<String> prev = getPreviousStateIds();
570 prev.add(currentStateId); 592 prev.add(currentStateId);
571 593
572 setCurrentStateId(targetState); 594 setCurrentStateId(targetState);
573 595
574 logger.debug("Compute data for state: " + targetState); 596 if (debug) {
597 log.debug("Compute data for state: " + targetState);
598 }
575 compute(context, ComputeType.ADVANCE, true); 599 compute(context, ComputeType.ADVANCE, true);
576 600
577 return describe(target, context); 601 return describe(target, context);
578 } 602 }
579 else if (isPreviousState(targetState, context)) { 603 else if (isPreviousState(targetState, context)) {
580 logger.info("Advance: Step back to"); 604 if (debug) {
605 log.debug("Advance: Step back to");
606 }
581 607
582 List<String> prevs = getPreviousStateIds(); 608 List<String> prevs = getPreviousStateIds();
583 int targetIdx = prevs.indexOf(targetState); 609 int targetIdx = prevs.indexOf(targetState);
584 int start = prevs.size() - 1; 610 int start = prevs.size() - 1;
585 611
586 destroyStates(prevs, context); 612 destroyStates(prevs, context);
587 613
588 for (int i = start; i >= targetIdx; i--) { 614 for (int i = start; i >= targetIdx; i--) {
589 String prev = prevs.get(i); 615 String prev = prevs.get(i);
590 logger.debug("Remove state id '" + prev + "'"); 616 if (debug) {
617 log.debug("Remove state id '" + prev + "'");
618 }
591 619
592 prevs.remove(prev); 620 prevs.remove(prev);
593 facets.remove(prev); 621 facets.remove(prev);
594 } 622 }
595 623
597 setCurrentStateId(targetState); 625 setCurrentStateId(targetState);
598 626
599 return describe(target, context); 627 return describe(target, context);
600 } 628 }
601 629
602 logger.warn("Advance: Cannot advance to '" + targetState + "'"); 630 log.warn("Advance: Cannot advance to '" + targetState + "'");
603 ec.addAttr(result, "type", OPERATION_FAILED, true); 631 ec.addAttr(result, "type", OPERATION_FAILED, true);
604 632
605 doc.appendChild(result); 633 doc.appendChild(result);
606 634
607 return doc; 635 return doc;
874 return f; 902 return f;
875 } 903 }
876 } 904 }
877 } 905 }
878 906
879 logger.warn("Could not find facet: " + name + " at " + index); 907 log.warn("Could not find facet: " + name + " at " + index);
880 return null; 908 return null;
881 } 909 }
882 910
883 911
884 /** 912 /**
902 930
903 if (nodes == null || nodes.getLength() == 0) { 931 if (nodes == null || nodes.getLength() == 0) {
904 throw new IllegalArgumentException("error_feed_no_data"); 932 throw new IllegalArgumentException("error_feed_no_data");
905 } 933 }
906 934
935 boolean debug = log.isDebugEnabled();
936
907 int count = nodes.getLength(); 937 int count = nodes.getLength();
908 logger.debug("Try to save " + count + " data items."); 938
939 if (debug) {
940 log.debug("Try to save " + count + " data items.");
941 }
909 942
910 String uri = ArtifactNamespaceContext.NAMESPACE_URI; 943 String uri = ArtifactNamespaceContext.NAMESPACE_URI;
911 944
912 DefaultState current = (DefaultState) getCurrentState(context); 945 DefaultState current = (DefaultState) getCurrentState(context);
913 946
920 953
921 String name = node.getAttributeNS(uri, "name"); 954 String name = node.getAttributeNS(uri, "name");
922 String value = node.getAttributeNS(uri, "value"); 955 String value = node.getAttributeNS(uri, "value");
923 956
924 if (name.length() > 0 && value.length() > 0) { 957 if (name.length() > 0 && value.length() > 0) {
925 logger.debug("Save data item for '" + name + "' : " + value); 958 if (debug) {
959 log.debug("Save data item for '" + name + "' : " + value);
960 }
926 961
927 StateData model = engine.getStateData(getName(), name); 962 StateData model = engine.getStateData(getName(), name);
928 963
929 StateData sd = model != null 964 StateData sd = model != null
930 ? model.deepCopy() 965 ? model.deepCopy()
932 967
933 addData( 968 addData(
934 name, current.transform(this, context, sd, name, value)); 969 name, current.transform(this, context, sd, name, value));
935 } 970 }
936 else if (name.length() > 0 && value.length() == 0) { 971 else if (name.length() > 0 && value.length() == 0) {
937 if (removeData(name) != null) { 972 if (removeData(name) != null && debug) {
938 logger.debug("Removed data '" + name + "' successfully."); 973 log.debug("Removed data '" + name + "' successfully.");
939 } 974 }
940 } 975 }
941 } 976 }
942 977
943 current.validate(this); 978 current.validate(this);
954 * 989 *
955 * @return true, if the state specified by <i>stateId</i> is reacahble, 990 * @return true, if the state specified by <i>stateId</i> is reacahble,
956 * otherwise false. 991 * otherwise false.
957 */ 992 */
958 protected boolean isStateReachable(String stateId, Object context) { 993 protected boolean isStateReachable(String stateId, Object context) {
959 logger.debug("Determine if the state '" + stateId + "' is reachable."); 994
995 if (log.isDebugEnabled()) {
996 log.debug("Determine if the state '" + stateId + "' is reachable.");
997 }
960 998
961 FLYSContext flysContext = FLYSUtils.getFlysContext(context); 999 FLYSContext flysContext = FLYSUtils.getFlysContext(context);
962 1000
963 State currentState = getCurrentState(context); 1001 State currentState = getCurrentState(context);
964 StateEngine sEngine = (StateEngine) flysContext.get( 1002 StateEngine sEngine = (StateEngine) flysContext.get(
977 * 1015 *
978 * @param stateId The target state identifier. 1016 * @param stateId The target state identifier.
979 * @param context The context object. 1017 * @param context The context object.
980 */ 1018 */
981 protected boolean isPreviousState(String stateId, Object context) { 1019 protected boolean isPreviousState(String stateId, Object context) {
982 logger.debug("Determine if the state '" + stateId + "' is old."); 1020 if (log.isDebugEnabled()) {
1021 log.debug("Determine if the state '" + stateId + "' is old.");
1022 }
983 1023
984 return getPreviousStateIds().contains(stateId); 1024 return getPreviousStateIds().contains(stateId);
985 } 1025 }
986 1026
987 1027
1015 * that match content in filterFacets is left out. 1055 * that match content in filterFacets is left out.
1016 * @return filtered Outputlist. 1056 * @return filtered Outputlist.
1017 */ 1057 */
1018 protected List<Output> filterOutputs(List<Output> outs) { 1058 protected List<Output> filterOutputs(List<Output> outs) {
1019 if (filterFacets == null || filterFacets.isEmpty()) { 1059 if (filterFacets == null || filterFacets.isEmpty()) {
1020 logger.debug("No filter for Outputs."); 1060 log.debug("No filter for Outputs.");
1021 return outs; 1061 return outs;
1022 } 1062 }
1023 1063
1024 boolean debug = logger.isDebugEnabled(); 1064 boolean debug = log.isDebugEnabled();
1025 1065
1026 if (debug) { 1066 if (debug) {
1027 logger.debug( 1067 log.debug(
1028 "Filter Facets with " + filterFacets.size() + " filters."); 1068 "Filter Facets with " + filterFacets.size() + " filters.");
1029 } 1069 }
1030 1070
1031 List<Output> filtered = new ArrayList<Output>(); 1071 List<Output> filtered = new ArrayList<Output>();
1032 1072
1033 for (Output out: outs) { 1073 for (Output out: outs) {
1034 String outName = out.getName(); 1074 String outName = out.getName();
1035 1075
1036 if (debug) { 1076 if (debug) {
1037 logger.debug(" filter Facets for Output: " + outName); 1077 log.debug(" filter Facets for Output: " + outName);
1038 } 1078 }
1039 1079
1040 List<Facet> fFacets = filterFacets.get(outName); 1080 List<Facet> fFacets = filterFacets.get(outName);
1041 if (fFacets != null) { 1081 if (fFacets != null) {
1042 if (debug) { 1082 if (debug) {
1043 logger.debug("" + fFacets.size() + " filters for: " + outName); 1083 log.debug("" + fFacets.size() + " filters for: " + outName);
1044 for (Facet tmp: fFacets) { 1084 for (Facet tmp: fFacets) {
1045 logger.debug(" filter = '" + tmp.getName() + "'"); 1085 log.debug(" filter = '" + tmp.getName() + "'");
1046 } 1086 }
1047 } 1087 }
1048 1088
1049 List<Facet> resultFacets = new ArrayList<Facet>(); 1089 List<Facet> resultFacets = new ArrayList<Facet>();
1050 1090
1057 } 1097 }
1058 } 1098 }
1059 } 1099 }
1060 1100
1061 if (debug) { 1101 if (debug) {
1062 logger.debug( 1102 log.debug(
1063 "Facets after filtering = " + resultFacets.size()); 1103 "Facets after filtering = " + resultFacets.size());
1064 } 1104 }
1065 1105
1066 if (!resultFacets.isEmpty()) { 1106 if (!resultFacets.isEmpty()) {
1067 DefaultOutput nout = new DefaultOutput( 1107 DefaultOutput nout = new DefaultOutput(
1073 } 1113 }
1074 } 1114 }
1075 } 1115 }
1076 1116
1077 if (debug) { 1117 if (debug) {
1078 logger.debug("All Facets after filtering = " + filtered.size()); 1118 log.debug("All Facets after filtering = " + filtered.size());
1079 } 1119 }
1080 1120
1081 return filtered; 1121 return filtered;
1082 } 1122 }
1083 1123
1087 * all previous states). 1127 * all previous states).
1088 * 1128 *
1089 * @return list of outputs 1129 * @return list of outputs
1090 */ 1130 */
1091 public List<Output> getOutputs(Object context) { 1131 public List<Output> getOutputs(Object context) {
1092 if (logger.isDebugEnabled()) { 1132 if (log.isDebugEnabled()) {
1093 logger.debug("##### Get Outputs for: " + identifier() + " #####"); 1133 log.debug("##### Get Outputs for: " + identifier() + " #####");
1094 } 1134 dumpArtifact();
1095 1135 }
1096 dumpArtifact();
1097 1136
1098 List<String> stateIds = getPreviousStateIds(); 1137 List<String> stateIds = getPreviousStateIds();
1099 List<Output> generated = new ArrayList<Output>(); 1138 List<Output> generated = new ArrayList<Output>();
1100 1139
1101 for (String stateId: stateIds) { 1140 for (String stateId: stateIds) {
1133 * @return list of output(s) for given state. 1172 * @return list of output(s) for given state.
1134 */ 1173 */
1135 protected List<Output> getOutputForState(DefaultState state) { 1174 protected List<Output> getOutputForState(DefaultState state) {
1136 1175
1137 if (state == null) { 1176 if (state == null) {
1138 logger.error("state == null: This should not happen!"); 1177 log.error("state == null: This should not happen!");
1139 return new ArrayList<Output>(); 1178 return new ArrayList<Output>();
1140 } 1179 }
1141 1180
1142 boolean debug = logger.isDebugEnabled(); 1181 boolean debug = log.isDebugEnabled();
1143 1182
1144 if (debug) { 1183 if (debug) {
1145 logger.debug("Find Outputs for State: " + state.getID()); 1184 log.debug("Find Outputs for State: " + state.getID());
1146 } 1185 }
1147 1186
1148 List<Output> list = state.getOutputs(); 1187 List<Output> list = state.getOutputs();
1149 if (list == null || list.size() == 0) { 1188 if (list == null || list.size() == 0) {
1150 if (debug) { 1189 if (debug) {
1151 logger.debug("-> No output modes for this state."); 1190 log.debug("-> No output modes for this state.");
1152 } 1191 }
1153 return new ArrayList<Output>(); 1192 return new ArrayList<Output>();
1154 } 1193 }
1155 1194
1156 String stateId = state.getID(); 1195 String stateId = state.getID();
1157 1196
1158 List<Facet> fs = facets.get(stateId); 1197 List<Facet> fs = facets.get(stateId);
1159 1198
1160 if (fs == null || fs.size() == 0) { 1199 if (fs == null || fs.size() == 0) {
1161 if (debug) { 1200 if (debug) {
1162 logger.debug("No facets found."); 1201 log.debug("No facets found.");
1163 } 1202 }
1164 return new ArrayList<Output>(); 1203 return new ArrayList<Output>();
1165 } 1204 }
1166 1205
1167 List<Output> gen = generateOutputs(list, fs); 1206 List<Output> gen = generateOutputs(list, fs);
1168 1207
1169 if (debug) { 1208 if (debug) {
1170 logger.debug("State '" + stateId + "' has " + gen.size() + " outs"); 1209 log.debug("State '" + stateId + "' has " + gen.size() + " outs");
1171 } 1210 }
1172 1211
1173 return gen; 1212 return gen;
1174 } 1213 }
1175 1214
1182 * @param fs List of facets 1221 * @param fs List of facets
1183 */ 1222 */
1184 protected List<Output> generateOutputs(List<Output> list, List<Facet> fs) { 1223 protected List<Output> generateOutputs(List<Output> list, List<Facet> fs) {
1185 List<Output> generated = new ArrayList<Output>(); 1224 List<Output> generated = new ArrayList<Output>();
1186 1225
1187 boolean debug = logger.isDebugEnabled(); 1226 boolean debug = log.isDebugEnabled();
1188 1227
1189 for (Output out: list) { 1228 for (Output out: list) {
1190 Output o = new DefaultOutput( 1229 Output o = new DefaultOutput(
1191 out.getName(), 1230 out.getName(),
1192 out.getDescription(), 1231 out.getDescription(),
1195 1234
1196 Set<String> outTypes = new HashSet<String>(); 1235 Set<String> outTypes = new HashSet<String>();
1197 1236
1198 for (Facet f: out.getFacets()) { 1237 for (Facet f: out.getFacets()) {
1199 if (outTypes.add(f.getName()) && debug) { 1238 if (outTypes.add(f.getName()) && debug) {
1200 logger.debug("configured facet " + f); 1239 log.debug("configured facet " + f);
1201 } 1240 }
1202 } 1241 }
1203 1242
1204 boolean facetAdded = false; 1243 boolean facetAdded = false;
1205 for (Facet f: fs) { 1244 for (Facet f: fs) {
1206 String type = f.getName(); 1245 String type = f.getName();
1207 1246
1208 if (outTypes.contains(type)) { 1247 if (outTypes.contains(type)) {
1209 if (debug) { 1248 if (debug) {
1210 logger.debug("Add facet " + f); 1249 log.debug("Add facet " + f);
1211 } 1250 }
1212 facetAdded = true; 1251 facetAdded = true;
1213 o.addFacet(f); 1252 o.addFacet(f);
1214 } 1253 }
1215 } 1254 }
1309 Object old = null; 1348 Object old = null;
1310 1349
1311 if (cache != null) { 1350 if (cache != null) {
1312 net.sf.ehcache.Element element = cache.get(key); 1351 net.sf.ehcache.Element element = cache.get(key);
1313 if (element != null) { 1352 if (element != null) {
1314 logger.debug("Got computation result from cache."); 1353 log.debug("Got computation result from cache.");
1315 old = element.getValue(); 1354 old = element.getValue();
1316 } 1355 }
1317 } 1356 }
1318 else { 1357 else {
1319 logger.debug("cache not configured."); 1358 log.debug("cache not configured.");
1320 } 1359 }
1321 1360
1322 Object res; 1361 Object res;
1323 switch (type) { 1362 switch (type) {
1324 case FEED: 1363 case FEED:
1332 default: 1371 default:
1333 res = null; 1372 res = null;
1334 } 1373 }
1335 1374
1336 if (cache != null && old != res && res != null) { 1375 if (cache != null && old != res && res != null) {
1337 logger.debug("Store computation result to cache."); 1376 log.debug("Store computation result to cache.");
1338 net.sf.ehcache.Element element = 1377 net.sf.ehcache.Element element =
1339 new net.sf.ehcache.Element(key, res); 1378 new net.sf.ehcache.Element(key, res);
1340 cache.put(element); 1379 cache.put(element);
1341 } 1380 }
1342 1381
1357 1396
1358 /** 1397 /**
1359 * Method to dump the artifacts state/data. 1398 * Method to dump the artifacts state/data.
1360 */ 1399 */
1361 protected void dumpArtifact() { 1400 protected void dumpArtifact() {
1362 if (logger.isDebugEnabled()) { 1401 log.debug("++++++++++++++ DUMP ARTIFACT DATA +++++++++++++++++");
1363 logger.debug("++++++++++++++ DUMP ARTIFACT DATA +++++++++++++++++"); 1402 // Include uuid, type, name
1364 // Include uuid, type, name 1403
1365 1404 log.debug("------ DUMP DATA ------");
1366 logger.debug("------ DUMP DATA ------"); 1405 Collection<StateData> allData = data.values();
1367 Collection<StateData> allData = data.values(); 1406
1368 1407 for (StateData d: allData) {
1369 for (StateData d: allData) { 1408 String name = d.getName();
1370 String name = d.getName(); 1409 String value = (String) d.getValue();
1371 String value = (String) d.getValue(); 1410
1372 1411 log.debug("- " + name + ": " + value);
1373 logger.debug("- " + name + ": " + value); 1412 }
1374 } 1413
1375 1414 log.debug("------ DUMP PREVIOUS STATES ------");
1376 logger.debug("------ DUMP PREVIOUS STATES ------"); 1415 List<String> stateIds = getPreviousStateIds();
1377 List<String> stateIds = getPreviousStateIds(); 1416
1378 1417 for (String id: stateIds) {
1379 for (String id: stateIds) { 1418 log.debug("- State: " + id);
1380 logger.debug("- State: " + id); 1419 }
1381 } 1420
1382 1421 log.debug("CURRENT STATE: " + getCurrentStateId());
1383 logger.debug("CURRENT STATE: " + getCurrentStateId()); 1422
1384 1423 debugFacets();
1385 debugFacets(); 1424 dumpFilterFacets();
1386 dumpFilterFacets(); 1425
1387 1426 log.debug("++++++++++++++ END ARTIFACT DUMP +++++++++++++++++");
1388 logger.debug("++++++++++++++ END ARTIFACT DUMP +++++++++++++++++");
1389 }
1390 } 1427 }
1391 1428
1392 1429
1393 protected void debugFacets() { 1430 protected void debugFacets() {
1394 logger.debug("######### FACETS #########"); 1431 log.debug("######### FACETS #########");
1395 Set<Map.Entry<String, List<Facet>>> entries = facets.entrySet(); 1432 Set<Map.Entry<String, List<Facet>>> entries = facets.entrySet();
1396 1433
1397 for (Map.Entry<String, List<Facet>> entry: entries) { 1434 for (Map.Entry<String, List<Facet>> entry: entries) {
1398 String out = entry.getKey(); 1435 String out = entry.getKey();
1399 List<Facet> fs = entry.getValue(); 1436 List<Facet> fs = entry.getValue();
1400 for (Facet f: fs) { 1437 for (Facet f: fs) {
1401 logger.debug(" # " + out + " : " + f.getName()); 1438 log.debug(" # " + out + " : " + f.getName());
1402 } 1439 }
1403 } 1440 }
1404 1441
1405 logger.debug("######## FACETS END ########"); 1442 log.debug("######## FACETS END ########");
1406 } 1443 }
1407 1444
1408 1445
1409 protected void dumpFilterFacets() { 1446 protected void dumpFilterFacets() {
1410 logger.debug("######## FILTER FACETS ########"); 1447 log.debug("######## FILTER FACETS ########");
1411 1448
1412 if (filterFacets == null || filterFacets.isEmpty()) { 1449 if (filterFacets == null || filterFacets.isEmpty()) {
1413 logger.debug("No Filter Facets defined."); 1450 log.debug("No Filter Facets defined.");
1414 return; 1451 return;
1415 } 1452 }
1416 1453
1417 Set<Map.Entry<String, List<Facet>>> entries = filterFacets.entrySet(); 1454 Set<Map.Entry<String, List<Facet>>> entries = filterFacets.entrySet();
1418 for (Map.Entry<String, List<Facet>> entry: entries) { 1455 for (Map.Entry<String, List<Facet>> entry: entries) {
1419 String out = entry.getKey(); 1456 String out = entry.getKey();
1420 List<Facet> filters = entry.getValue(); 1457 List<Facet> filters = entry.getValue();
1421 1458
1422 logger.debug("There are " + filters.size() + " filters for: " +out); 1459 log.debug("There are " + filters.size() + " filters for: " +out);
1423 1460
1424 for (Facet filter: filters) { 1461 for (Facet filter: filters) {
1425 logger.debug(" filter: " + filter.getName()); 1462 log.debug(" filter: " + filter.getName());
1426 } 1463 }
1427 } 1464 }
1428 1465
1429 logger.debug("######## FILTER FACETS END ########"); 1466 log.debug("######## FILTER FACETS END ########");
1430 } 1467 }
1431 1468
1432 1469
1433 protected void destroyState(String id, Object context) { 1470 protected void destroyState(String id, Object context) {
1434 State s = getState(context, id); 1471 State s = getState(context, id);
1452 /** 1489 /**
1453 * Destroy the states. 1490 * Destroy the states.
1454 */ 1491 */
1455 @Override 1492 @Override
1456 public void endOfLife(Object context) { 1493 public void endOfLife(Object context) {
1457 if (logger.isDebugEnabled()) { 1494 if (log.isDebugEnabled()) {
1458 logger.debug("FLYSArtifact.endOfLife: " + identifier()); 1495 log.debug("FLYSArtifact.endOfLife: " + identifier());
1459 } 1496 }
1460 1497
1461 ArrayList<String> ids = (ArrayList<String>) getPreviousStateIds(); 1498 ArrayList<String> ids = (ArrayList<String>) getPreviousStateIds();
1462 ArrayList<String> toDestroy = (ArrayList<String>) ids.clone(); 1499 ArrayList<String> toDestroy = (ArrayList<String>) ids.clone();
1463 1500

http://dive4elements.wald.intevation.org