Search in sources :

Example 1 with StockTransactionParticipation

use of eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipation in project dwoss by gg-net.

the class StockTransactionEaoIT method testfind.

@Test
public void testfind() throws Exception {
    utx.begin();
    em.joinTransaction();
    Stock s1 = new Stock(0, "TEEEEEEEST");
    Stock s2 = new Stock(1, "TEEEEEEEST");
    em.persist(s1);
    em.persist(s2);
    StockTransaction st1 = new StockTransaction(StockTransactionType.ROLL_IN);
    st1.setDestination(s1);
    st1.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
    st1.addStatus(new StockTransactionStatus(StockTransactionStatusType.COMPLETED, new Date()));
    StockTransaction st2 = new StockTransaction(StockTransactionType.ROLL_IN);
    st2.setDestination(s1);
    st2.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
    StockTransaction st3 = new StockTransaction(StockTransactionType.DESTROY);
    st3.setSource(s1);
    st3.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
    StockTransaction st4 = new StockTransaction(StockTransactionType.ROLL_IN);
    st4.setDestination(s2);
    StockTransactionStatus status = new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date());
    status.addParticipation(new StockTransactionParticipation(StockTransactionParticipationType.PICKER, "Hugo"));
    st4.addStatus(status);
    st4.setComment("Muh");
    em.persist(st1);
    em.persist(st2);
    em.persist(st3);
    em.persist(st4);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    StockTransactionEao stockTransactionEao = new StockTransactionEao(em);
    List<StockTransaction> sts = stockTransactionEao.findByDestination(s1.getId(), StockTransactionType.ROLL_IN, StockTransactionStatusType.PREPARED);
    assertNotNull(sts);
    assertEquals(1, sts.size());
    assertEquals(st2.getId(), sts.get(0).getId());
    sts = stockTransactionEao.findByDestination(s2.getId(), StockTransactionType.ROLL_IN, StockTransactionStatusType.PREPARED, "Hugo", "Muh");
    assertNotNull(sts);
    assertEquals(1, sts.size());
    assertEquals(st4.getId(), sts.get(0).getId());
    utx.commit();
}
Also used : StockTransactionParticipation(eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipation) StockTransactionStatus(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus) StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Date(java.util.Date) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Example 2 with StockTransactionParticipation

use of eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipation in project dwoss by gg-net.

the class StockTransactionEao method findBySource.

/**
 * Returns a List of Transactions matching all supplied parameters
 * <p/>
 * @param sourceId        the destination of the stock
 * @param type            the type of the transaction
 * @param statusType      the status the transaction is in
 * @param participantName the arrangerName
 * @param comment         the comment
 * @return a List of Transactions
 */
public List<StockTransaction> findBySource(int sourceId, StockTransactionType type, StockTransactionStatusType statusType, String participantName, String comment) {
    TypedQuery<StockTransaction> query = em.createNamedQuery("StockTransaction.bySourceTypesComment", StockTransaction.class);
    query.setParameter(1, sourceId);
    query.setParameter(2, type);
    query.setParameter(3, statusType);
    query.setParameter(4, comment);
    List<StockTransaction> queryResult = query.getResultList();
    if (participantName == null)
        return queryResult;
    Set<StockTransaction> result = new HashSet<>();
    for (StockTransaction stockTransaction : queryResult) {
        for (StockTransactionParticipation participation : stockTransaction.getParticipations()) {
            if (participantName.equals(participation.getPraticipantName()))
                result.add(stockTransaction);
        }
    }
    return new ArrayList<>(result);
}
Also used : StockTransactionParticipation(eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipation) ArrayList(java.util.ArrayList) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) HashSet(java.util.HashSet)

Example 3 with StockTransactionParticipation

use of eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipation in project dwoss by gg-net.

the class StockTransactionEao method findByDestination.

/**
 * Returns a List of Transactions matching all supplied parameters
 * <p/>
 * @param destinationId   the destination of the stock
 * @param type            the type of the transaction
 * @param statusType      the status the transaction is in
 * @param participantName the arrangerName
 * @param comment         the comment
 * @return a List of Transactions
 */
public List<StockTransaction> findByDestination(int destinationId, StockTransactionType type, StockTransactionStatusType statusType, String participantName, String comment) {
    TypedQuery<StockTransaction> query = em.createNamedQuery("StockTransaction.byDestinationTypesComment", StockTransaction.class);
    query.setParameter(1, destinationId);
    query.setParameter(2, type);
    query.setParameter(3, statusType);
    query.setParameter(4, comment);
    List<StockTransaction> queryResult = query.getResultList();
    if (participantName == null)
        return queryResult;
    Set<StockTransaction> result = new HashSet<>();
    for (StockTransaction stockTransaction : queryResult) {
        for (StockTransactionParticipation participation : stockTransaction.getParticipations()) {
            if (participantName.equals(participation.getPraticipantName()))
                result.add(stockTransaction);
        }
    }
    return new ArrayList<>(result);
}
Also used : StockTransactionParticipation(eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipation) ArrayList(java.util.ArrayList) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) HashSet(java.util.HashSet)

Example 4 with StockTransactionParticipation

use of eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipation in project dwoss by gg-net.

the class UnitProcessorOperation method transfer.

/**
 * Transfers a UniqueUnits StockUnit to the supplied Stock.
 * <p>
 * <ul>
 * <li>Validate, if a StockUnit for the UniqueUnit exists, and this StockUnit is in Stock</li>
 * <li>Transfer StockUnit via {@link StockTransactionType#EXTERNAL_TRANSFER}</li>
 * <li>Update the SopoUnit</li>
 * </ul>
 * <p/>
 * @param uniqueUnit the uniqueUnit
 * @param stockId    the stockId
 * @param arranger
 * @return
 */
// TODO: Use StockTransactionEmo.resquestExternalTransfer and completeExternalTransfer
@Override
public UniqueUnit transfer(UniqueUnit uniqueUnit, int stockId, String arranger) {
    StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uniqueUnit.getId());
    if (stockUnit == null)
        throw new IllegalArgumentException("No StockUnit for " + uniqueUnit);
    if (stockUnit.isInTransaction())
        throw new IllegalArgumentException(stockUnit + " is on Transaction");
    Stock destination = new DefaultEao<>(Stock.class, stockEm).findById(stockId);
    StockTransaction st = new StockTransaction(StockTransactionType.EXTERNAL_TRANSFER);
    StockTransactionStatus status = new StockTransactionStatus(StockTransactionStatusType.COMPLETED, new Date());
    status.addParticipation(new StockTransactionParticipation(StockTransactionParticipationType.ARRANGER, arranger));
    st.addStatus(status);
    st.setSource(stockUnit.getStock());
    st.setDestination(destination);
    st.addPosition(new StockTransactionPosition(stockUnit));
    stockEm.persist(st);
    stockUnit.setPosition(null);
    new StockLocationDiscoverer(stockEm).discoverAndSetLocation(stockUnit, destination);
    uniqueUnit = new UniqueUnitEao(uuEm).findById(uniqueUnit.getId());
    uniqueUnit.addHistory("External Stock change from " + stockUnit.getStock() + " to " + destination + " by " + arranger);
    uniqueUnit.fetchEager();
    return uniqueUnit;
}
Also used : StockTransactionParticipation(eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipation) StockLocationDiscoverer(eu.ggnet.dwoss.stock.ee.emo.StockLocationDiscoverer) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockTransactionStatus(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus) StockTransactionPosition(eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Date(java.util.Date) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Aggregations

StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)4 StockTransactionParticipation (eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipation)4 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)2 StockTransactionStatus (eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 StockTransactionEao (eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao)1 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)1 StockLocationDiscoverer (eu.ggnet.dwoss.stock.ee.emo.StockLocationDiscoverer)1 StockTransactionPosition (eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition)1 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)1 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)1 Test (org.junit.Test)1