
org.beigesoft.ws.hnd.HnTrVs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of beige-acc Show documentation
Show all versions of beige-acc Show documentation
It consists of double entry accounting and trading (web-store) business logic.
It's based on previous beigesoft-accounting and beigesoft-webstore projects.
The newest version!
/*
BSD 2-Clause License
Copyright (c) 2019, Beigesoft™
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.beigesoft.ws.hnd;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import org.beigesoft.mdl.IReqDt;
import org.beigesoft.log.ILog;
import org.beigesoft.hnd.IHndRq;
import org.beigesoft.rdb.IRdb;
import org.beigesoft.rdb.IOrm;
import org.beigesoft.acc.mdlp.AcStg;
import org.beigesoft.acc.mdlp.Curr;
import org.beigesoft.ws.mdlp.Deliv;
import org.beigesoft.ws.mdlp.I18Trd;
import org.beigesoft.ws.mdlp.I18CatGs;
import org.beigesoft.ws.mdlp.I18ChoSp;
import org.beigesoft.ws.mdlp.I18ItmSp;
import org.beigesoft.ws.mdlp.CurrRt;
import org.beigesoft.ws.srv.ISrTrStg;
import org.beigesoft.ws.srv.ISrAdStg;
import org.beigesoft.ws.srv.UtlTrJsp;
import org.beigesoft.ws.srv.ILsCatlChg;
/**
* It puts web-store variables into request data.
*
* @param platform dependent record set type
* @author Yury Demidenko
*/
public class HnTrVs implements IHndRq, ILsCatlChg {
/**
* Logger.
**/
private ILog log;
/**
* Database service.
*/
private IRdb rdb;
/**
* ORM service.
**/
private IOrm orm;
/**
* Trade additional settings service.
**/
private ISrAdStg srAdStg;
/**
* Trade settings service.
**/
private ISrTrStg srTrStg;
/**
* Trade JSP service.
**/
private UtlTrJsp utlTrJsp;
//Cached data:
/**
* Cached common trading I18N parameters.
*/
private List i18TrdLs;
/**
* Cached I18N catalogs.
*/
private List i18CatGsLs;
/**
* Cached foreign currency rates.
*/
private List currRtLs;
/**
* Delivering methods.
*/
private List dlvMts;
/**
* Cached I18N chooseable specifics.
*/
private List i18ChoSpLs;
/**
* Cached I18N specifics.
*/
private List i18ItmSpLs;
/**
* Handle request.
* @param pRvs Request scoped variables
* @param pRqDt Request Data
* @throws Exception - an exception
*/
@Override
public final void handle(final Map pRvs,
final IReqDt pRqDt) throws Exception {
Map vs = new HashMap();
List i18ChoSpLst = null;
List i18ItmSpLst = null;
List i18TrdLst = null;
List i18CatGsLst = null;
List currRtLst = null;
List dlvMtst = null;
synchronized (this) {
if (this.srTrStg.getTrStg() == null || this.srAdStg.getAdStg() == null
|| this.i18TrdLs == null) {
try {
this.rdb.setAcmt(false);
this.rdb.setTrIsl(IRdb.TRRUC);
this.rdb.begin();
this.srTrStg.lazTrStg(pRvs);
this.srAdStg.lazAdStg(pRvs);
if (this.i18TrdLs == null) {
i18TrdLst = this.orm.retLst(pRvs, vs, I18Trd.class);
i18CatGsLst = this.orm.retLst(pRvs, vs, I18CatGs.class);
i18ChoSpLst = this.orm.retLst(pRvs, vs, I18ChoSp.class);
i18ItmSpLst = this.orm.retLst(pRvs, vs, I18ItmSp.class);
currRtLst = this.orm.retLst(pRvs, vs, CurrRt.class);
dlvMtst = this.orm.retLst(pRvs, vs, Deliv.class);
this.i18TrdLs = i18TrdLst;
this.i18ItmSpLs = i18ItmSpLst;
this.i18ChoSpLs = i18ChoSpLst;
this.i18CatGsLs = i18CatGsLst;
this.currRtLs = currRtLst;
this.dlvMts = dlvMtst;
}
this.rdb.commit();
} catch (Exception ex) {
this.srTrStg.hndRlBk(pRvs);
if (!this.rdb.getAcmt()) {
this.rdb.rollBack();
}
throw ex;
} finally {
this.rdb.release();
}
} else { //lazTrStg and saveTrStg will put tstg into pRvs!
this.srTrStg.lazTrStg(pRvs); // rvs.tstg
this.srAdStg.lazAdStg(pRvs); // rvs.tastg
i18TrdLst = this.i18TrdLs;
i18ItmSpLst = this.i18ItmSpLs;
i18ChoSpLst = this.i18ChoSpLs;
i18CatGsLst = this.i18CatGsLs;
currRtLst = this.currRtLs;
dlvMtst = this.dlvMts;
}
}
pRvs.put("i18ItmSps", i18ItmSpLst);
pRvs.put("i18ChoSps", i18ChoSpLst);
pRvs.put("i18Trds", i18TrdLst);
pRvs.put("i18Cats", i18CatGsLst);
pRvs.put("currRts", currRtLst);
pRvs.put("dlvMts", dlvMtst);
Curr wscurr = null;
if (currRtLst.size() > 0) {
String wscurrs = pRqDt.getParam("wscurr");
if (wscurrs != null) {
Long wscurrl = Long.parseLong(wscurrs);
for (CurrRt cr : currRtLst) {
if (cr.getCurr().getIid().equals(wscurrl)) {
wscurr = cr.getCurr();
pRqDt.setCookVl("wscurr", wscurr.getIid().toString());
break;
}
}
} else {
String wscurrsc = pRqDt.getCookVl("wscurr");
if (wscurrsc != null) {
Long wscurrl = Long.parseLong(wscurrsc);
for (CurrRt cr : currRtLst) {
if (cr.getCurr().getIid().equals(wscurrl)) {
wscurr = cr.getCurr();
break;
}
}
}
}
}
if (wscurr == null) {
AcStg as = (AcStg) pRvs.get("astg");
wscurr = as.getCurr();
pRqDt.setCookVl("wscurr", wscurr.getIid().toString());
}
pRvs.put("wscurr", wscurr);
Boolean shTxDet;
String shTxDets = pRqDt.getParam("shTxDet");
if (shTxDets == null) {
String shTxDetsc = pRqDt.getCookVl("shTxDet");
if (shTxDetsc == null) {
shTxDet = Boolean.FALSE;
pRqDt.setCookVl("shTxDet", shTxDet.toString());
} else {
shTxDet = Boolean.valueOf(shTxDetsc);
}
} else {
shTxDet = Boolean.valueOf(shTxDets);
pRqDt.setCookVl("shTxDet", shTxDet.toString());
}
pRvs.put("shTxDet", shTxDet);
pRqDt.setAttr("utlTrJsp", this.utlTrJsp);
}
/**
* Handle catl changed event.
* @throws Exception an Exception
**/
@Override
public final synchronized void hndCatlChg() throws Exception {
this.i18TrdLs = null;
this.i18ItmSpLs = null;
this.i18ChoSpLs = null;
this.i18CatGsLs = null;
this.currRtLs = null;
this.dlvMts = null;
}
//Simple getters and setters:
/**
* Getter for rdb.
* @return IRdb
**/
public final synchronized IRdb getRdb() {
return this.rdb;
}
/**
* Setter for rdb.
* @param pRdb reference
**/
public final synchronized void setRdb(final IRdb pRdb) {
this.rdb = pRdb;
}
/**
* Geter for orm.
* @return IOrm
**/
public final synchronized IOrm getOrm() {
return this.orm;
}
/**
* Setter for orm.
* @param pOrm reference
**/
public final synchronized void setOrm(final IOrm pOrm) {
this.orm = pOrm;
}
/**
* Getter for log.
* @return ILog
**/
public final ILog getLog() {
return this.log;
}
/**
* Setter for log.
* @param pLog reference
**/
public final void setLog(final ILog pLog) {
this.log = pLog;
}
/**
* Getter for srAdStg.
* @return ISrAdStg
**/
public final synchronized ISrAdStg getSrAdStg() {
return this.srAdStg;
}
/**
* Setter for srAdStg.
* @param pSrAdStg reference
**/
public final synchronized void setSrAdStg(final ISrAdStg pSrAdStg) {
this.srAdStg = pSrAdStg;
}
/**
* Getter for srTrStg.
* @return ISrTrStg
**/
public final synchronized ISrTrStg getSrTrStg() {
return this.srTrStg;
}
/**
* Setter for srTrStg.
* @param pSrTrStg reference
**/
public final synchronized void setSrTrStg(final ISrTrStg pSrTrStg) {
this.srTrStg = pSrTrStg;
}
/**
* Getter for utlTrJsp.
* @return UtlTrJsp
**/
public final UtlTrJsp getUtlTrJsp() {
return this.utlTrJsp;
}
/**
* Setter for utlTrJsp.
* @param pUtlTrJsp reference
**/
public final void setUtlTrJsp(final UtlTrJsp pUtlTrJsp) {
this.utlTrJsp = pUtlTrJsp;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy