Sure. The StoreRpay method is part of GatewaySessionBean class, which along with ieb field, is declared like this:
Code:
]
@Stateless(name = "GatewaySessionBean")
public class GatewaySessionBean implements GatewaySessionBeanLocal {
@EJB
InteractionExtBeanLocal ieb;
...
Here is StoreRpay method, which is the place where actual storing happens. After this method, rpay instance is returned to client by means of a caller. No calls to database made that I know of, but obviously there are some, that I dont.
Code:
public StoreRpayResponseData StoreRpay(SessionContext sessionContext, StoreRpayRequestData requestData) {
try {
Client client = (Client) ieb.findById(requestData.getClientId(), Client.class);
if (null == client) {
StoreRpayResponseData rd = new StoreRpayResponseData(ResponseResult.RR_ERROR_BL,
"Cannot find Client with id#" + requestData.getClientId());
return rd;
}
FirmAccount firmAccount = (FirmAccount) ieb.findById(requestData.getFirmAccountId(), FirmAccount.class);
if (null == firmAccount) {
StoreRpayResponseData rd = new StoreRpayResponseData(ResponseResult.RR_ERROR_BL,
"Cannot find FirmAccount with id#" + requestData.getFirmAccountId());
return rd;
}
ContragentAccount contragentAccount = (ContragentAccount) ieb.findById(requestData.getContragentAccountId(), ContragentAccount.class);
if (null == contragentAccount) {
StoreRpayResponseData rd = new StoreRpayResponseData(ResponseResult.RR_ERROR_BL,
"Cannot find ContragentAccount with id#" + requestData.getContragentAccountId());
return rd;
}
Asset asset = (Asset) ieb.findById(requestData.getAssetId(), Asset.class);
if (null == asset) {
StoreRpayResponseData rd = new StoreRpayResponseData(ResponseResult.RR_ERROR_BL,
"Cannot find Asset with id#" + requestData.getAssetId());
return rd;
}
Vat vat = (Vat) ieb.findById(requestData.getVatId(), Vat.class);
if (null == vat) {
StoreRpayResponseData rd = new StoreRpayResponseData(ResponseResult.RR_ERROR_BL,
"Cannot find Vat with id#" + requestData.getVatId());
return rd;
}
Rpay rpay = new Rpay();
Integer id = Math.abs(new Random().nextInt());
rpay.setId(id);
rpay.setClientId(client);
rpay.setFirmAccountId(firmAccount);
rpay.setContragentAccountId(contragentAccount);
rpay.setAssetId(asset);
rpay.setVatId(vat);
rpay.setAmount(BigDecimal.valueOf(requestData.getAmount()));
rpay.setPurpose(requestData.getPurpose());
rpay.setComment(requestData.getComment());
rpay.setExternal(Rpay.EXTERNAL);
rpay.setStatus(Rpay.Status.CREATED.value());
rpay.setExternalId(id);
if (!ieb.persist(rpay)) {
StoreRpayResponseData rd = new StoreRpayResponseData(ResponseResult.RR_ERROR_BL, "Cannot persist Rpay");
return rd;
} else {
StoreRpayResponseData rd = new StoreRpayResponseData(ResponseResult.RR_SUCCESS, "Accomplished");
rd.setRpay(rpay);
return rd;
}
} catch (Exception e) {
logger.log(Level.SEVERE, null, e);
StoreRpayResponseData rd = new StoreRpayResponseData(ResponseResult.RR_ERROR_PROCESS, e.getMessage());
return rd;
}
}
This is calling web service method. Setting some collections to null required for SAX parser, complaining on cycle in XML graph.
Code:
@WebMethod(operationName = "StoreRpay")
public StoreRpayResponseData StoreRpay(@WebParam(name = "sessionId") String sessionId,
@WebParam(name = "clientId") Integer clientId,
@WebParam(name = "firmAccountId") Integer firmAccountId,
@WebParam(name = "contragentAccountId") Integer contragentAccountId,
@WebParam(name = "assetId") Integer assetId,
@WebParam(name = "vatId") Integer vatId,
@WebParam(name = "amount") Double amount,
@WebParam(name = "purpose") String purpose,
@WebParam(name = "comment") String comment) {
try {
StoreRpayRequestData requestData = new StoreRpayRequestData(clientId, firmAccountId, contragentAccountId,
assetId, vatId, amount, purpose, comment);
if (!requestData.validate()) {
StoreRpayResponseData responseData = new StoreRpayResponseData(ResponseResult.RR_ERROR_VALIDATE, "Invalid request parameters");
//TODO: requestData.getErrors();
Logger.getLogger(WsFrontend.class.getName()).log(Level.WARNING, "StoreRpay validation failed");
return responseData;
}
if (!CheckSession(sessionId)) {
StoreRpayResponseData responseData = new StoreRpayResponseData(ResponseResult.RR_NOT_AUTHORISED, "Not authorised");
Logger.getLogger(WsFrontend.class.getName()).log(Level.WARNING, "Unauthorized call to StoreRpay");
return responseData;
}
SessionContext sessionContext = new SessionContext();
StoreRpayResponseData responseData = gwBean.StoreRpay(sessionContext, requestData);
Logger.getLogger(WsFrontend.class.getName()).log(Level.INFO, "StoreRpay request processed");
if (responseData.getResponseResult() == ResponseResult.RR_SUCCESS) {
Rpay rpay = responseData.getRpay();
rpay.getClientId().setUserCollection(null);
rpay.getClientId().setFirmCollection(null);
rpay.getClientId().setContragentCollection(null);
//rpay.getClientId().setRpayCollection(null);
rpay.getFirmAccountId().getBankId().setContragentAccountCollection(null);
rpay.getFirmAccountId().getBankId().setFirmAccountCollection(null);
rpay.getFirmAccountId().getFirmLegalId().setClientCollection(null);
rpay.getFirmAccountId().getFirmLegalId().setFirmAccountCollection(null);
rpay.getContragentAccountId().getBankId().setContragentAccountCollection(null);
rpay.getContragentAccountId().getBankId().setFirmAccountCollection(null);
rpay.getContragentAccountId().getBankId().setName("ัะตัั");
rpay.getContragentAccountId().getContragentLegalId().setClientCollection(null);
rpay.getContragentAccountId().getContragentLegalId().setContragentAccountCollection(null);
}
return responseData;
} catch (Exception ex) {
Logger.getLogger(WsFrontend.class.getName()).log(Level.SEVERE, null, ex);
StoreRpayResponseData responseData = new StoreRpayResponseData(ResponseResult.RR_ERROR_PROCESS, ex.getMessage());
return responseData;
}
}
This is the findById method:
Code:
public Object findById(Integer id, Class clazz) {
Object result = null;
NamedQueries queriesList = (NamedQueries) clazz.getAnnotation(NamedQueries.class);
if (queriesList == null) {
logger.severe("No named queries found for entity + " + clazz.getName());
return null;
}
NamedQuery[] queries = queriesList.value();
for (NamedQuery query : queries) {
if (query.name().endsWith("findById")) {
try {
Query namedquery = em.createNamedQuery(query.name());
namedquery.setParameter("id", id);
result = namedquery.getSingleResult();
} catch (NoResultException ex) {
return null;
} catch (NonUniqueResultException ex) {
logger.warning("Non-unique result in findById: " + clazz.getName() + " id " + id.toString());
return null;
} catch (Exception ex) {
logger.severe("Exception in findById " + ex.toString() + " " + clazz.getName() + " id " + id.toString());
ex.printStackTrace();
}
return result;
}
}
logger.severe("No findById query found for entity + " + clazz.getName());
return null;
}
This is the persist method:
Code:
public boolean persist(Object object) {
em.getTransaction().begin();
try {
em.persist(object);
em.getTransaction().commit();
return true;
} catch (Exception e) {
e.printStackTrace();
try {
em.getTransaction().rollback();
} catch (Exception ex) {
}
}
return false;
}
Rpay class described in previous message. Here is Client class:
Code:
@Entity
@Table(name = "client")
@NamedQueries({@NamedQuery(name = "Client.findAll", query = "SELECT c FROM Client c"), @NamedQuery(name = "Client.findById", query = "SELECT c FROM Client c WHERE c.id = :id"), @NamedQuery(name = "Client.findByName", query = "SELECT c FROM Client c WHERE c.name = :name")})
public class Client implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Column(name = "name")
private String name;
@JoinTable(name = "client_contragent", joinColumns = {@JoinColumn(name = "client_id", referencedColumnName = "id", updatable = false)}, inverseJoinColumns = {@JoinColumn(name = "contragent_id", referencedColumnName = "id", updatable = false)})
@ManyToMany
private List<Contragent> contragentCollection;
@JoinTable(name = "user_client", joinColumns = {@JoinColumn(name = "client_id", referencedColumnName = "id", updatable = false)}, inverseJoinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id", updatable = false)})
@ManyToMany
private List<User> userCollection;
@JoinTable(name = "client_firm", joinColumns = {@JoinColumn(name = "client_id", referencedColumnName = "id", updatable = false)}, inverseJoinColumns = {@JoinColumn(name = "firm_id", referencedColumnName = "id", updatable = false)})
@ManyToMany
private List<Firm> firmCollection;
...