View Javadoc
1   /**
2    * This Source Code Form is subject to the terms of the Mozilla Public
3    * License, v. 2.0. If a copy of the MPL was not distributed with this
4    * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5    *
6    * If it is not possible or desirable to put the notice in a particular
7    * file, then You may include the notice in a location (such as a LICENSE
8    * file in a relevant directory) where a recipient would be likely to look
9    * for such a notice.
10  
11   * 
12   */
13   
14  /*  ---------------------------------------------------------------------------
15   *  U.S. Government, Department of the Army
16   *  Army Materiel Command
17   *  Research Development Engineering Command
18   *  Communications Electronics Research Development and Engineering Center
19   *  ---------------------------------------------------------------------------
20   */
21  package org.miloss.fgsms.sla.rules;
22  
23  import java.util.ArrayList;
24  import java.util.List;
25  import java.util.concurrent.atomic.AtomicReference;
26  import org.miloss.fgsms.common.Utility;
27  import org.miloss.fgsms.plugins.sla.AlertType;
28  import org.miloss.fgsms.plugins.sla.SLARuleInterface;
29  import org.miloss.fgsms.services.interfaces.common.MachinePerformanceData;
30  import org.miloss.fgsms.services.interfaces.common.NameValuePair;
31  import org.miloss.fgsms.services.interfaces.common.PolicyType;
32  import org.miloss.fgsms.services.interfaces.common.ProcessPerformanceData;
33  import org.miloss.fgsms.services.interfaces.datacollector.AddDataRequestMsg;
34  import org.miloss.fgsms.services.interfaces.datacollector.BrokerData;
35  import org.miloss.fgsms.services.interfaces.policyconfiguration.ServicePolicy;
36  import org.miloss.fgsms.services.interfaces.policyconfiguration.TransactionalWebServicePolicy;
37  import org.miloss.fgsms.services.interfaces.status.SetStatusRequestMsg;
38  
39  /**
40   *
41   * @author AO
42   */
43  public class ActionContainsIgnoreCase implements SLARuleInterface {
44  
45      @Override
46      public boolean CheckTransactionalRule(SetStatusRequestMsg req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
47          return false;
48      }
49  
50      @Override
51      public boolean CheckTransactionalRule(ProcessPerformanceData req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
52          return false;
53      }
54  
55      @Override
56      public boolean CheckTransactionalRule(MachinePerformanceData req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
57          return false;
58      }
59  
60      @Override
61      public boolean CheckTransactionalRule(AddDataRequestMsg req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
62          if (nullableFaultMsg == null) {
63              nullableFaultMsg = new AtomicReference<String>();
64          }
65          NameValuePair GetNameValuePairByName = Utility.getNameValuePairByName(params, "value");
66          String item = GetNameValuePairByName.getValue();
67          if (GetNameValuePairByName.isEncrypted()) {
68              item = Utility.DE(GetNameValuePairByName.getValue());
69          }
70          if (req.getAction().toLowerCase().contains(item.toLowerCase())) {
71              nullableFaultMsg.set("Action Contains Ignore Case " + item + ", " + nullableFaultMsg.get());
72          }
73          return false;
74      }
75  
76      @Override
77      public boolean CheckTransactionalRule(String url, List<BrokerData> data, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
78          return false;
79      }
80  
81      @Override
82      public boolean CheckNonTransactionalRule(ServicePolicy pol, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg, boolean pooled) {
83          return false;
84      }
85  
86      @Override
87      public String GetDisplayName() {
88          return "Action or Method contains (value), case insensitive";
89      }
90  
91      @Override
92      public String GetHtmlFormattedHelp() {
93          return "If the SOAP Action or Method contains (value), case insensitive, then this rule will trigger.<Br>"
94                  + "Applies to transactional service policies only.<br><br>"
95                  + "Required parameters:"
96                  + "<ul>"
97                  + "<li>value - the string to compare against</li>"
98                  + "</ul>";
99      }
100 
101     @Override
102     public List<NameValuePair> GetRequiredParameters() {
103         ArrayList<NameValuePair> arrayList = new ArrayList<NameValuePair>();
104         arrayList.add(Utility.newNameValuePair("value", null, false, false));
105         return arrayList;
106     }
107 
108     @Override
109     public List<NameValuePair> GetOptionalParameters() {
110         return new ArrayList<NameValuePair>();
111     }
112 
113     @Override
114     public boolean ValidateConfiguration(List<NameValuePair> params, AtomicReference<String> outError, ServicePolicy policy) {
115         if (outError == null) {
116             outError = new AtomicReference<String>();
117         }
118         if (params == null || params.isEmpty()) {
119             outError.set("The parameter 'value' is required for rule " + this.GetDisplayName() +". " + outError.get());
120         }
121         if (!(policy instanceof TransactionalWebServicePolicy)) {
122             outError.set("This rule only applies to Transactional Service Policies. " + outError.get());
123         }
124         boolean foundLogger = false;
125         for (int i = 0; i < params.size(); i++) {
126             if (params.get(i).getName().equals("value")) {
127                 foundLogger = true;
128                 if (Utility.stringIsNullOrEmpty(params.get(i).getValue())) {
129                     outError.set("A value must be specified for the parameter 'value' for rule " + this.GetDisplayName() +". " + outError.get());
130                 }
131             }
132         }
133         if (!foundLogger) {
134             outError.set("The parameter 'value' is required " + this.GetDisplayName() +". "  + outError.get());
135         }
136         if (Utility.stringIsNullOrEmpty(outError.get())) {
137             return true;
138         } else {
139             return false;
140         }
141 
142     }
143 
144     @Override
145     public AlertType GetType() {
146         return AlertType.Performance;
147     }
148 
149     @Override
150     public String GetHtmlFormattedDisplay(List<NameValuePair> params) {
151         NameValuePair mc = Utility.getNameValuePairByName(params, "value");
152         String item = UNDEFINED_VALUE;
153         if (mc != null) {
154             item = mc.getValue();
155             if (mc.isEncrypted() || mc.isEncryptOnSave()) {
156                 item = ENCRYPTED_MASK;
157             }
158         }
159         return Utility.encodeHTML(GetDisplayName() + " " + item);
160     }
161 
162     @Override
163     public List<PolicyType> GetAppliesTo() {
164         List<PolicyType> ret = new ArrayList<PolicyType>();
165         ret.add(PolicyType.TRANSACTIONAL);
166         return ret;
167     }
168 }