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   
22  package org.miloss.fgsms.sla.rules;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  import java.util.concurrent.atomic.AtomicReference;
27  import org.miloss.fgsms.common.Utility;
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 ConsumerContainsIgnoreCase 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          for (int i=0; i <req.getIdentity().size(); i++){
71              if (req.getIdentity().get(i).toLowerCase().contains(item.toLowerCase())) {
72              nullableFaultMsg.set("Consumer Identity Contains Ignoring Case " + item + ", " + nullableFaultMsg.get());
73          }
74          }
75          
76          return false;
77      }
78  
79      @Override
80      public boolean CheckTransactionalRule(String url, List<BrokerData> data, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
81          return false;
82      }
83  
84      @Override
85      public boolean CheckNonTransactionalRule(ServicePolicy pol, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg, boolean pooled) {
86          return false;
87      }
88  
89      @Override
90      public String GetDisplayName() {
91          return "Consumer Identity Contains (value), case insensitive";
92      }
93  
94      @Override
95      public String GetHtmlFormattedHelp() {
96          return "If the identity of the consumer of a transactional service contains (value), case insensitive, then this rule will trigger. Consumer identity "
97                  + "can either be IP addresses, usernames, or the result of an XPath expression.<Br>"
98                  + "Applies to transactional service policies only.<br><br>"
99                  + "Required parameters:"
100                 + "<ul>"
101                 + "<li>value - the string to compare against</li>"
102                 + "</ul>";
103     }
104 
105     @Override
106     public List<NameValuePair> GetRequiredParameters() {
107         ArrayList<NameValuePair> arrayList = new ArrayList<NameValuePair>();
108         arrayList.add(Utility.newNameValuePair("value", null, false, false));
109         return arrayList;
110     }
111 
112     @Override
113     public List<NameValuePair> GetOptionalParameters() {
114         return new ArrayList<NameValuePair>();
115     }
116 
117     @Override
118     public boolean ValidateConfiguration(List<NameValuePair> params, AtomicReference<String> outError,ServicePolicy policy) {
119         if (outError == null) {
120             outError = new AtomicReference<String>();
121         }
122         if (params == null || params.isEmpty()) {
123             outError.set("The parameter 'value' is required. " + outError.get());
124         }
125                    if (!(policy instanceof TransactionalWebServicePolicy)) {
126             outError.set("This rule only applies to Transactional Service Policies. " + outError.get());
127         }
128         boolean foundLogger = false;
129         for (int i = 0; i < params.size(); i++) {
130             if (params.get(i).getName().equals("value")) {
131                 foundLogger = true;
132                 if (Utility.stringIsNullOrEmpty(params.get(i).getValue())) {
133                     outError.set("A value must be specified for the parameter 'value'. " + outError.get());
134                 }
135             }
136         }
137         if (!foundLogger) {
138             outError.set("The parameter 'value' is required. " + outError.get());
139         }
140         if (Utility.stringIsNullOrEmpty(outError.get())) {
141             return true;
142         } else {
143             return false;
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 }