BrightSide Workbench Full Report + Source Code
org.turro.financials.handshake.HandshakeUtil Class Reference
Inheritance diagram for org.turro.financials.handshake.HandshakeUtil:
Collaboration diagram for org.turro.financials.handshake.HandshakeUtil:

Public Member Functions

boolean itsMe (String id)
 
boolean myTurn (HttpServletRequest request)
 
void execute (ServletContext context, HttpServletRequest request, HttpServletResponse response)
 

Static Public Member Functions

static String getIdentifier ()
 
static ElephantResponse checkStatus (Contract contract)
 
static ElephantResponse sendPetition (Contract contract, String remoteUrl)
 
static ElephantResponse sendAcceptance (Contract contract, String remoteServer, Long remoteId)
 
static ElephantResponse sendDocument (Document document)
 
static ElephantResponse sendProduct (Contract contract, Product product)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 45 of file HandshakeUtil.java.

Member Function Documentation

◆ checkStatus()

static ElephantResponse org.turro.financials.handshake.HandshakeUtil.checkStatus ( Contract  contract)
static

Definition at line 124 of file HandshakeUtil.java.

124  {
125  ContractHandshake handshake = contract.getContractHandshake();
126  if(handshake != null) {
127  try {
128  ElephantPost ep = new ElephantPost(DirectContents.createURL(handshake.getRemoteServer(), getIdentifier()));
129  ep.addParameter("contract", HandshakeContract.createJsonFromContract(contract));
130  ep.addParameter("action", HandshakeAction.HANDSHAKE_STATUS.toString());
131  return ep.doPost();
132  } catch (IOException ex) {
133  Logger.getLogger(HandshakeUtil.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
134  }
135  }
136  return null;
137  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ execute()

void org.turro.financials.handshake.HandshakeUtil.execute ( ServletContext  context,
HttpServletRequest  request,
HttpServletResponse  response 
)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 62 of file HandshakeUtil.java.

62  {
63  try {
64  if(!ElephantPost.isValid(request)) return;
65  Map<String, String[]> pars = request.getParameterMap();
66  HandshakeAction ha = HandshakeAction.getAction(pars.containsKey("action") ? pars.get("action")[0] : null);
67  HandshakeContract hc;
68  switch(ha) {
69  case HANDSHAKE_STATUS:
70  hc = HandshakeContract.createHandshakeFromJson(pars.containsKey("contract") ? pars.get("contract")[0] : null);
71  // check handshake
72  HandshakeStatus status;
73  if(hc == null) {
74  status = HandshakeStatus.HS_NO_HANDSHAKE;
75  } else {
76  ContractHandshake ch = HandshakeContract.getContractHandshakeFromHandshake(hc);
77  if(ch == null) {
78  status = HandshakeStatus.HS_NO_HANDSHAKE;
79  } else if(!ch.getContract().isActive()) {
80  status = HandshakeStatus.HS_BROKEN;
81  } else {
82  status = HandshakeStatus.HS_ESTABLISHED;
83  }
84  }
85  ElephantResponse.writeToResponse(response, ElephantResponseType.RESPONSE_CORRECT, "HANDSHAKE SERVER", status.toString());
86  break;
87  case HANDSHAKE_PETITION:
88  hc = HandshakeContract.createHandshakeFromJson(pars.containsKey("contract") ? pars.get("contract")[0] : null);
89  // save contractxxxx.hs
90  HandshakeContract.saveHandshakePetition(hc);
91  status = HandshakeStatus.HS_NO_HANDSHAKE;
92  ElephantResponse.writeToResponse(response, ElephantResponseType.RESPONSE_CORRECT, "HANDSHAKE SERVER: PETITION SEND", status.toString());
93  break;
94  case HANDSHAKE_ACCEPTANCE:
95  hc = HandshakeContract.createHandshakeFromJson(pars.containsKey("contract") ? pars.get("contract")[0] : null);
96  // update remoteId from handshake
97  if(HandshakeContract.updateRemoteId(
98  pars.containsKey("remoteServer") ? pars.get("remoteServer")[0] : null,
99  pars.containsKey("remoteId") ? pars.get("remoteId")[0] : null,
100  hc.remoteId)) {
101  status = HandshakeStatus.HS_ESTABLISHED;
102  ElephantResponse.writeToResponse(response, ElephantResponseType.RESPONSE_CORRECT, "HANDSHAKE SERVER: PETITION ACCEPTED", status.toString());
103  } else {
104  status = HandshakeStatus.HS_BROKEN;
105  ElephantResponse.writeToResponse(response, ElephantResponseType.RESPONSE_FAILED, "HANDSHAKE SERVER: PETITION FAILED", status.toString());
106  }
107  break;
108  case HANDSHAKE_DOCUMENT:
109  HandshakeDocument hd = HandshakeDocument.createHandshakeFromJson(pars.containsKey("document") ? pars.get("document")[0] : null);
110  if(hd != null) {
111  HandshakeDocument.saveHandshakeDocument(hd);
112  status = HandshakeStatus.HS_ESTABLISHED;
113  ElephantResponse.writeToResponse(response, ElephantResponseType.RESPONSE_CORRECT, "HANDSHAKE SERVER: DOCUMENT ACCEPTED", status.toString());
114  }
115  break;
116  case HANDSHAKE_PRODUCT:
117  break;
118  }
119  } catch (IOException ex) {
120  Logger.getLogger(HandshakeUtil.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
121  }
122  }
Here is the call graph for this function:

◆ getIdentifier()

static String org.turro.financials.handshake.HandshakeUtil.getIdentifier ( )
static

Definition at line 47 of file HandshakeUtil.java.

47  {
48  return HandshakeUtil.class.getAnnotation(DirectContent.class).identifier();
49  }

◆ itsMe()

boolean org.turro.financials.handshake.HandshakeUtil.itsMe ( String  id)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 52 of file HandshakeUtil.java.

52  {
53  return getIdentifier().equals(id);
54  }

◆ myTurn()

boolean org.turro.financials.handshake.HandshakeUtil.myTurn ( HttpServletRequest  request)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 57 of file HandshakeUtil.java.

57  {
58  return DirectContents.isYourTurn(request, getIdentifier());
59  }
Here is the call graph for this function:

◆ sendAcceptance()

static ElephantResponse org.turro.financials.handshake.HandshakeUtil.sendAcceptance ( Contract  contract,
String  remoteServer,
Long  remoteId 
)
static

Definition at line 151 of file HandshakeUtil.java.

151  {
152  ContractHandshake handshake = contract.getContractHandshake();
153  if(handshake != null) {
154  try {
155  ElephantPost ep = new ElephantPost(DirectContents.createURL(handshake.getRemoteServer(), getIdentifier()));
156  ep.addParameter("remoteServer", remoteServer + "");
157  ep.addParameter("remoteId", remoteId + "");
158  ep.addParameter("contract", HandshakeContract.createJsonFromContract(contract));
159  ep.addParameter("action", HandshakeAction.HANDSHAKE_ACCEPTANCE.toString());
160  return ep.doPost();
161  } catch (IOException ex) {
162  Logger.getLogger(HandshakeUtil.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
163  }
164  }
165  return null;
166  }
Here is the call graph for this function:

◆ sendDocument()

static ElephantResponse org.turro.financials.handshake.HandshakeUtil.sendDocument ( Document  document)
static

Definition at line 168 of file HandshakeUtil.java.

168  {
169  Contract contract = document.getContract();
170  ContractHandshake handshake = contract != null ? contract.getContractHandshake() : null;
171  if(handshake != null) {
172  try {
173  ElephantPost ep = new ElephantPost(DirectContents.createURL(handshake.getRemoteServer(), getIdentifier()));
174  ep.addParameter("document", HandshakeDocument.createJsonFromDocument(document));
175  ep.addParameter("action", HandshakeAction.HANDSHAKE_DOCUMENT.toString());
176  return ep.doPost();
177  } catch (IOException ex) {
178  Logger.getLogger(HandshakeUtil.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
179  }
180  }
181  return null;
182  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendPetition()

static ElephantResponse org.turro.financials.handshake.HandshakeUtil.sendPetition ( Contract  contract,
String  remoteUrl 
)
static

Definition at line 139 of file HandshakeUtil.java.

139  {
140  try {
141  ElephantPost ep = new ElephantPost(DirectContents.createURL(remoteUrl, getIdentifier()));
142  ep.addParameter("contract", HandshakeContract.createJsonFromContract(contract));
143  ep.addParameter("action", HandshakeAction.HANDSHAKE_PETITION.toString());
144  return ep.doPost();
145  } catch (IOException ex) {
146  Logger.getLogger(HandshakeUtil.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
147  }
148  return null;
149  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendProduct()

static ElephantResponse org.turro.financials.handshake.HandshakeUtil.sendProduct ( Contract  contract,
Product  product 
)
static

Definition at line 184 of file HandshakeUtil.java.

184  {
185  ContractHandshake handshake = contract != null ? contract.getContractHandshake() : null;
186  if(handshake != null) {
187  try {
188  ElephantPost ep = new ElephantPost(DirectContents.createURL(handshake.getRemoteServer(), getIdentifier()));
189  ep.addParameter("contract", HandshakeContract.createJsonFromContract(contract));
190  ep.addParameter("product", HandshakeProduct.createJsonFromProduct(product));
191  ep.addParameter("action", HandshakeAction.HANDSHAKE_PRODUCT.toString());
192  return ep.doPost();
193  } catch (IOException ex) {
194  Logger.getLogger(HandshakeUtil.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
195  }
196  }
197  return null;
198  }
Here is the call graph for this function:

The documentation for this class was generated from the following file: