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.SLARuleInterface;
28  import org.miloss.fgsms.services.interfaces.common.MachinePerformanceData;
29  import org.miloss.fgsms.services.interfaces.common.NameValuePair;
30  import org.miloss.fgsms.services.interfaces.common.PolicyType;
31  import org.miloss.fgsms.services.interfaces.common.ProcessPerformanceData;
32  import org.miloss.fgsms.services.interfaces.datacollector.AddDataRequestMsg;
33  import org.miloss.fgsms.services.interfaces.datacollector.BrokerData;
34  import org.miloss.fgsms.services.interfaces.policyconfiguration.ServicePolicy;
35  import org.miloss.fgsms.services.interfaces.policyconfiguration.TransactionalWebServicePolicy;
36  import org.miloss.fgsms.services.interfaces.status.SetStatusRequestMsg;
37  
38  /**
39   *
40   * @author AO
41   */
42  public class ConsumerEqualsIgnoreCase implements SLARuleInterface {
43  
44      @Override
45      public boolean CheckTransactionalRule(SetStatusRequestMsg req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
46          return false;
47      }
48  
49      @Override
50      public boolean CheckTransactionalRule(ProcessPerformanceData req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
51          return false;
52      }
53  
54      @Override
55      public boolean CheckTransactionalRule(MachinePerformanceData req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
56          return false;
57      }
58  
59      @Override
60      public boolean CheckTransactionalRule(AddDataRequestMsg req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
61          if (nullableFaultMsg == null) {
62              nullableFaultMsg = new AtomicReference<String>();
63          }
64          NameValuePair GetNameValuePairByName = Utility.getNameValuePairByName(params, "value");
65          String item = GetNameValuePairByName.getValue();
66          if (GetNameValuePairByName.isEncrypted()) {
67              item = Utility.DE(GetNameValuePairByName.getValue());
68          }
69          for (int i = 0; i < req.getIdentity().size(); i++) {
70              if (req.getIdentity().get(i).toLowerCase().contains(item.toLowerCase())) {
71                  nullableFaultMsg.set("Consumer Identity Equals Ignoring Case " + item + ", " + nullableFaultMsg.get());
72              }
73          }
74  
75          return false;
76      }
77  
78      @Override
79      public boolean CheckTransactionalRule(String url, List<BrokerData> data, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
80          return false;
81      }
82  
83      @Override
84      public boolean CheckNonTransactionalRule(ServicePolicy pol, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg, boolean pooled) {
85          return false;
86      }
87  
88      @Override
89      public String GetDisplayName() {
90          return "Consumer Identity Equals (value), case insensitive";
91      }
92  
93      @Override
94      public String GetHtmlFormattedHelp() {
95          return "If the identity of the consumer of a transactional service contains (value), case insensitive, then this rule will trigger.Consumer identity "
96                  + "can either be IP addresses, usernames, or the result of an XPath expression.<Br>"
97                  + "Applies to transactional service policies only.<br><br>"
98                  + "Required parameters:"
99                  + "<ul>"
100                 + "<li>value - the string to compare against</li>"
101                 + "</ul>";
102     }
103 
104     @Override
105     public List<NameValuePair> GetRequiredParameters() {
106         ArrayList<NameValuePair> arrayList = new ArrayList<NameValuePair>();
107         arrayList.add(Utility.newNameValuePair("value", null, false, false));
108         return arrayList;
109     }
110 
111     @Override
112     public List<NameValuePair> GetOptionalParameters() {
113         return new ArrayList<NameValuePair>();
114     }
115 
116     @Override
117     public boolean ValidateConfiguration(List<NameValuePair> params, AtomicReference<String> outError, ServicePolicy policy) {
118         if (outError == null) {
119             outError = new AtomicReference<String>();
120         }
121         if (params == null || params.isEmpty()) {
122             outError.set("The parameter 'value' is required. " + outError.get());
123         }
124         if (!(policy instanceof TransactionalWebServicePolicy)) {
125             outError.set("This rule only applies to Transactional Service Policies. " + outError.get());
126         }
127         boolean foundLogger = false;
128         for (int i = 0; i < params.size(); i++) {
129             if (params.get(i).getName().equals("value")) {
130                 foundLogger = true;
131                 if (Utility.stringIsNullOrEmpty(params.get(i).getValue())) {
132                     outError.set("A value must be specified for the parameter 'value'. " + outError.get());
133                 }
134             }
135         }
136         if (!foundLogger) {
137             outError.set("The parameter 'value' is required. " + outError.get());
138         }
139         if (Utility.stringIsNullOrEmpty(outError.get())) {
140             return true;
141         } else {
142             return false;
143         }
144 
145     }
146 
147     @Override
148     public org.miloss.fgsms.plugins.sla.AlertType GetType() {
149         return org.miloss.fgsms.plugins.sla.AlertType.Performance;
150     }
151 
152     @Override
153     public String GetHtmlFormattedDisplay(List<NameValuePair> params) {
154         NameValuePair mc = Utility.getNameValuePairByName(params, "value");
155         String item = UNDEFINED_VALUE;
156         if (mc != null) {
157             item = mc.getValue();
158             if (mc.isEncrypted() || mc.isEncryptOnSave()) {
159                 item = ENCRYPTED_MASK;
160             }
161         }
162         return Utility.encodeHTML(GetDisplayName() + " " + item);
163     }
164     
165     @Override
166     public List<PolicyType> GetAppliesTo() {
167         List<PolicyType> ret = new ArrayList<PolicyType>();
168         ret.add(PolicyType.TRANSACTIONAL);
169         return ret;
170     }
171 }