-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomTrigger.java
More file actions
97 lines (81 loc) · 2.38 KB
/
CustomTrigger.java
File metadata and controls
97 lines (81 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//$Id$
package com.zoho.abtest.report;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.zoho.abtest.webhook.Webhook;
import com.zoho.abtest.common.ZABModel;
/**
* @Base class for trigger
*
*/
public abstract class CustomTrigger extends ZABModel {
private Object obj;
private static final Logger LOGGER = Logger.getLogger(CustomTrigger.class.getName());
public Object getObj() {
return obj;
}
public void setObj(Object obj) {
this.obj = obj;
}
/**
* Please provide details for validation and variables
*/
//Add default implementation
/**
* @param wrapper
* @return list of webhooks for a given trigger type
* @throws Exception
*/
public ArrayList<Webhook> getWebhooks(WebhookWrapper wrapper) throws Exception{
ArrayList<Webhook> al=new ArrayList();
try{
String type=wrapper.getType().getCode().toString();
if(CustomMapping.getTrigger().containsKey(type)){
for(int i=0;i<CustomMapping.getTrigger().get(type).size();i++){
Webhook webhook=new Webhook();
webhook=(Webhook) CustomMapping.getTrigger().get(type).get(i).clone();
al.add(webhook);
}
}
else{
al=null;
}
}
catch(Exception e){
LOGGER.log(Level.SEVERE, e.getMessage(),e);
}
return al;
}
/**
* @param object
* @return key and value pairs for different variables
* @throws Exception
*/
public abstract HashMap<String ,String> getVariables(WebhookWrapper object) throws Exception;
public String trigger(WebhookWrapper wrapper){
try{
HashMap<String,String> hs=null;
hs = getVariables(wrapper);
ArrayList<Webhook> al=getWebhooks(wrapper);
if(al!=null){
for(int i=0;i<al.size();i++)
{
String customclass=CustomMapping.getAuthtype().get(String.valueOf(al.get(i).getAuthType()));
Class cls = Class.forName(customclass);
Object obj = cls.newInstance();
if(((CustomAuth) obj).authentication(al.get(i))!=null)
{
al.set(i, ((CustomAuth) obj).authentication(al.get(i)));
}
WebhookBody.call(hs, al.get(i));
}
}
}
catch(Exception e){
LOGGER.log(Level.SEVERE, e.getMessage(),e);
}
return null;
}
}