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