use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao 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;
}
use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao in project dwoss by gg-net.
the class RedTapeWorkerOperation method toDetailedHtml.
/**
* Create a HTML formated String representing the detailed information from a {@link Dossier}.
* <p/>
* @param dossierId The Dossier
* @return a HTML formated String representing the detailed information from a {@link Dossier}.
*/
@Override
public String toDetailedHtml(long dossierId) {
Dossier dos = redTapeEm.find(Dossier.class, dossierId);
if (dos == null)
return "<strong>No Dossier with Id: " + dossierId + " found</strong>";
String detailedHtmlCustomer = customerService.asHtmlHighDetailed(dos.getCustomerId());
String stockInfo = "StockUnits:<ul>";
for (StockUnit stockUnit : new StockUnitEao(stockEm).findByUniqueUnitIds(dos.getRelevantUniqueUnitIds())) stockInfo += "<li>" + stockUnit + "</li>";
stockInfo += "</ul>";
return "<html>" + detailedHtmlCustomer + "<br />" + DossierFormater.toHtmlDetailed(dos) + "<br />" + stockInfo + "</html>";
}
use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao in project dwoss by gg-net.
the class UnitOverseerBean method internalFind.
private UnitShard internalFind(String refurbishId) {
L.debug("find({})", refurbishId);
UniqueUnitEao uuEao = new UniqueUnitEao(uuEm);
UniqueUnit uu = uuEao.findByIdentifier(Identifier.REFURBISHED_ID, refurbishId);
String oldRefurbishedOd = null;
L.debug("find({}) uniqueUnit={}", refurbishId, uu);
if (uu == null) {
uu = uuEao.findByRefurbishedIdInHistory(refurbishId);
if (uu == null) {
if (!bridgeInstance.isUnsatisfied() && !bridgeInstance.get().isUnitIdentifierAvailable(refurbishId)) {
return new UnitShard(refurbishId, 0, toHtmlDescription(refurbishId, null, "Nicht Verfügbar", "", "(Auskunft aus Sopo)"), false, null);
} else {
return new UnitShard(refurbishId, 0, "<html>SopoNr.:<b>" + refurbishId + "<u> existiert nicht.</u><br /><br /></b></html>", null, null);
}
} else {
oldRefurbishedOd = "(Frühere SopoNr: " + refurbishId + ")";
refurbishId = uu.getIdentifier(REFURBISHED_ID);
}
}
StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uu.getId());
L.debug("find({}) stockUnit={}", refurbishId, stockUnit);
Integer stockId = null;
if (stockUnit != null && stockUnit.isInStock())
stockId = stockUnit.getStock().getId();
if (stockUnit == null) {
return new UnitShard(refurbishId, uu.getId(), toHtmlDescription(refurbishId, oldRefurbishedOd, "Nicht Verfügbar", "", null), false, null);
}
if (stockUnit.getLogicTransaction() != null) {
return new UnitShard(refurbishId, uu.getId(), toHtmlDescription(refurbishId, oldRefurbishedOd, "Nicht Verfügbar", stockUnit, null), false, stockId);
}
// If the Database is clean, the Unit is available, but we make some safty checks here.
if (new DossierEao(redTapeEm).isUnitBlocked(uu.getId())) {
L.warn("find({}) Database Error RedTape sanity check", refurbishId);
return new UnitShard(refurbishId, uu.getId(), toHtmlDescription(refurbishId, oldRefurbishedOd, "Nicht Verfügbar", stockUnit, "(Datenbankfehler, RedTape sanity check!)"), false, stockId);
}
// Now we are shure.
return new UnitShard(refurbishId, uu.getId(), toHtmlDescription(refurbishId, oldRefurbishedOd, "Verfügbar", stockUnit, null), true, stockId);
}
use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao in project dwoss by gg-net.
the class UnitOverseerBean method throwNotAvailable.
/**
* Build and throw an exception for a not available unit.
* <p>
* @param refurbishId the refurbished id of the unit
* @param us the unit shard
* @throws UserInfoException
*/
private void throwNotAvailable(String refurbishId, UnitShard us) throws UserInfoException {
// <- auch in di auslagerung...
if (us.getAvailable() == null)
throw new UserInfoException("SopoNr " + refurbishId + " existiert nicht");
StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(us.getUniqueUnitId());
if (stockUnit != null && stockUnit.getLogicTransaction() != null) {
Dossier dos = new DossierEao(redTapeEm).findById(stockUnit.getLogicTransaction().getDossierId());
if (dos == null)
throw new UserInfoException("SopoNr " + refurbishId + " is on a LogicTransaction, but there is no Dossier, inform Team Software");
UiCustomer customer = customerService.asUiCustomer(dos.getCustomerId());
if (customer == null)
throw new UserInfoException("SopoNr " + refurbishId + " is on Dossier " + dos.getIdentifier() + ", but Customer " + dos.getCustomerId() + " does not exist.");
throw new UserInfoException("SopoNr " + refurbishId + " ist schon vergeben" + "\nKID = " + customer.getId() + "\nKunde = " + customer.toTitleNameLine() + "\n\nVorgang = " + dos.getIdentifier());
}
}
use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao in project dwoss by gg-net.
the class UnitSupporterOperation method isSerialAvailable.
@Override
public boolean isSerialAvailable(String serial) {
UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
UniqueUnit uu = uniqueUnitEao.findByIdentifier(UniqueUnit.Identifier.SERIAL, serial);
if (uu != null) {
StockUnit stockUnit = stockUnitEao.findByUniqueUnitId(uu.getId());
if (stockUnit != null) {
return false;
}
}
return true;
}
Aggregations