Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/transition/PresettingsValueCompareTransition.java @ 875:5e9efdda6894
merged gnv-artifacts/1.0
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:56 +0200 |
parents | 2423cefe7d39 |
children | f953c9a559d8 |
comparison
equal
deleted
inserted
replaced
722:bb3ffe7d719e | 875:5e9efdda6894 |
---|---|
1 package de.intevation.gnv.transition; | |
2 | |
3 import java.util.Map; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 import org.w3c.dom.Node; | |
7 | |
8 import de.intevation.artifactdatabase.Config; | |
9 import de.intevation.gnv.state.InputData; | |
10 import de.intevation.gnv.state.State; | |
11 | |
12 /** | |
13 * Class which supports the possibility to validate if a | |
14 * Transition could be done using simple Valuecompare Operations. | |
15 * The Compareoperations will use the preSettings of an Artifact. | |
16 * At this Time equal and notequal-operations are supported. | |
17 * The Comparation is casesensitive. | |
18 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> | |
19 * | |
20 */ | |
21 public class PresettingsValueCompareTransition extends TransitionBase { | |
22 | |
23 /** | |
24 * the logger, used to log exceptions and additonaly information | |
25 */ | |
26 private static Logger log = Logger.getLogger(PresettingsValueCompareTransition.class); | |
27 | |
28 /** | |
29 * The Name of the Datafield the Value that should be compared | |
30 * should be fetched from. | |
31 */ | |
32 private String dataName = null; | |
33 /** | |
34 * The Value that should be set to the State. | |
35 */ | |
36 private String dataValue = null; | |
37 /** | |
38 * The Operation that should be used (equal notequal) | |
39 */ | |
40 private String operator = null; | |
41 | |
42 /** | |
43 * The UID of this Class. | |
44 */ | |
45 private static final long serialVersionUID = -7846722158776823205L; | |
46 | |
47 /** | |
48 * Constructor | |
49 */ | |
50 public PresettingsValueCompareTransition() { | |
51 super(); | |
52 } | |
53 | |
54 | |
55 public boolean isValid(State state) { | |
56 Map<String, InputData> preSettings = state.getPreSettings(); | |
57 if (preSettings != null){ | |
58 boolean dataAvailable = preSettings.containsKey(dataName); | |
59 if (dataAvailable){ | |
60 if (operator.equals("equal")){ | |
61 return preSettings.get(dataName).getValue().startsWith(dataValue); | |
62 }else if (operator.equals("notequal")){ | |
63 return !preSettings.get(dataName).getValue().startsWith(dataValue); | |
64 } | |
65 } | |
66 } | |
67 if (operator.equals("notequal")){ | |
68 return true; | |
69 } | |
70 return false; | |
71 } | |
72 | |
73 | |
74 @Override | |
75 public void setup(Node configuration) { | |
76 super.setup(configuration); | |
77 this.dataName = Config.getStringXPath(configuration,"condition/@inputvalue"); | |
78 this.dataValue = Config.getStringXPath(configuration,"condition/@value"); | |
79 this.operator = Config.getStringXPath(configuration,"condition/@operator"); | |
80 } | |
81 } | |
82 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |