View Javadoc
1   package com.jsql.view.swing.list;
2   
3   import com.jsql.model.injection.method.AbstractMethodInjection;
4   import com.jsql.model.injection.vendor.model.Vendor;
5   import com.jsql.util.StringUtil;
6   import com.jsql.view.swing.util.MediatorHelper;
7   import org.apache.commons.lang3.StringUtils;
8   
9   import java.util.NoSuchElementException;
10  
11  public class BeanInjection {
12      
13      private final String url;
14      private String request = StringUtils.EMPTY;
15      private String header = StringUtils.EMPTY;
16      private String requestType;
17      
18      private AbstractMethodInjection method;
19      private Vendor vendor;
20  
21      public BeanInjection(String url) {
22          this.url = url;
23          this.method = MediatorHelper.model().getMediatorMethod().getQuery();
24          this.vendor = MediatorHelper.model().getMediatorVendor().getAuto();
25          this.requestType = StringUtil.GET;
26      }
27      
28      public BeanInjection(String url, String request, String header, String nameMethod, String vendor, String requestType) {
29          this(url);
30          this.request = request;
31          this.header = header;
32          
33          try {
34              this.method = MediatorHelper.model().getMediatorMethod().getMethods().stream()
35                  .filter(m -> m.name().equalsIgnoreCase(nameMethod))
36                  .findAny()
37                  .orElse(MediatorHelper.model().getMediatorMethod().getQuery());
38          } catch (IllegalArgumentException | NoSuchElementException e) {
39              this.method = MediatorHelper.model().getMediatorMethod().getQuery();
40          }
41          
42          try {
43              this.vendor = MediatorHelper.model().getMediatorVendor().getVendors().stream()
44                  .filter(v -> v.toString().equals(vendor))
45                  .findAny()
46                  .orElse(MediatorHelper.model().getMediatorVendor().getAuto());
47          } catch (IllegalArgumentException | NoSuchElementException e) {
48              this.vendor = MediatorHelper.model().getMediatorVendor().getAuto();
49          }
50          
51          this.requestType = requestType.isEmpty() ? StringUtil.GET : requestType;
52      }
53      
54      
55      // Json getter for serialization
56      
57      public String getMethod() {
58          return this.method.name();
59      }
60      
61      public String getVendor() {
62          return this.vendor.toString();
63      }
64      
65      
66      // Getter and setter
67  
68      public String getUrl() {
69          return this.url;
70      }
71  
72      public String getRequest() {
73          return this.request;
74      }
75  
76      public String getHeader() {
77          return this.header;
78      }
79      
80      public String getRequestType() {
81          return this.requestType;
82      }
83  
84      public AbstractMethodInjection getMethodInstance() {
85          return this.method;
86      }
87  }