use of eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao in project dwoss by gg-net.
the class StockTransactionEmo method request.
/**
* Request a StockTransaction with the selected parameters.
*
* @param transactionType the type
* @param statusType the status
* @param sourceId the source, if null only the destination is used.
* @param destinationId the destination, if null only the source is used
* @param arrangerName the arranger
* @param comment the comment
* @return always a persisted transactions with the supplied parameters
*/
// TODO: Still not implemented to findByTypeAndStatus a transaction with source an destination. (For Transfer)
private StockTransaction request(StockTransactionType transactionType, StockTransactionStatusType statusType, Integer sourceId, Integer destinationId, String arrangerName, String comment) {
StockTransactionEao stockTransactionEao = new StockTransactionEao(em);
List<StockTransaction> stockTransactions;
if (sourceId != null)
stockTransactions = stockTransactionEao.findBySource(sourceId, transactionType, statusType, arrangerName, comment);
else
stockTransactions = stockTransactionEao.findByDestination(destinationId, transactionType, statusType, arrangerName, comment);
if (!stockTransactions.isEmpty())
return stockTransactions.get(0);
DefaultEao<Stock> stockEao = new DefaultEao<>(Stock.class, em);
StockTransaction st = new StockTransaction(transactionType);
st.setComment(comment);
StockTransactionStatus status = new StockTransactionStatus(statusType, new Date());
status.addParticipation(new StockTransactionParticipation(StockTransactionParticipationType.ARRANGER, arrangerName));
st.addStatus(status);
if (sourceId != null)
st.setSource(stockEao.findById(sourceId));
if (destinationId != null)
st.setDestination(stockEao.findById(destinationId));
em.persist(st);
return st;
}
Aggregations