
org.beigesoft.ws.prc.PrBuOr 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.prc;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import org.beigesoft.exc.ExcCode;
import org.beigesoft.mdl.IReqDt;
import org.beigesoft.mdl.CmnPrf;
import org.beigesoft.mdl.Page;
import org.beigesoft.hld.UvdVar;
import org.beigesoft.log.ILog;
import org.beigesoft.prc.IPrc;
import org.beigesoft.prc.PrcEntRt;
import org.beigesoft.rdb.IRdb;
import org.beigesoft.rdb.IOrm;
import org.beigesoft.srv.ISrvPg;
import org.beigesoft.ws.mdlp.CuOrSe;
import org.beigesoft.ws.mdlp.CuOr;
import org.beigesoft.ws.mdlp.Buyer;
import org.beigesoft.ws.fct.FcPrWs;
import org.beigesoft.ws.srv.IBuySr;
/**
* Service that retrieve buyer's orders to print.
*
* @param platform dependent record set type
* @author Yury Demidenko
*/
public class PrBuOr implements IPrc {
/**
* Logger.
**/
private ILog log;
/**
* ORM service.
**/
private IOrm orm;
/**
* Database service.
**/
private IRdb rdb;
/**
* Page service.
*/
private ISrvPg srvPg;
/**
* Buyer service.
**/
private IBuySr buySr;
/**
* Processors factory.
**/
private FcPrWs fcPrWs;
/**
* Base retriever.
**/
private PrcEntRt retrv;
/**
* Transaction isolation.
**/
private Integer trIsl;
/**
* Process entity request.
* @param pRvs request scoped vars
* @param pRqDt Request Data
* @throws Exception - an exception
**/
@Override
public final void process(final Map pRvs,
final IReqDt pRqDt) throws Exception {
Buyer buyer = null;
try {
this.rdb.setAcmt(false);
this.rdb.setTrIsl(this.trIsl);
this.rdb.begin();
buyer = this.buySr.getAuthBuyr(pRvs, pRqDt);
if (buyer != null) {
Map vs = new HashMap();
String orIdSt = pRqDt.getParam("orId");
String sorIdSt = pRqDt.getParam("sorId");
UvdVar uvs = new UvdVar();
pRvs.put("uvs", uvs);
if (orIdSt != null || sorIdSt != null) { //print:
if (orIdSt != null) { //order
Long orId = Long.valueOf(orIdSt);
CuOr or = new CuOr();
or.setIid(orId);
this.orm.refrEnt(pRvs, vs, or);
this.retrv.process(pRvs, or, pRqDt);
} else { //S.E. order:
Long orId = Long.valueOf(sorIdSt);
CuOrSe or = new CuOrSe();
or.setIid(orId);
this.orm.refrEnt(pRvs, vs, or);
this.retrv.process(pRvs, or, pRqDt);
}
pRqDt.setAttr("rnd", "prn");
} else { //page:
page(pRvs, pRqDt, buyer);
pRqDt.setAttr("rnd", "wors");
}
}
this.rdb.commit();
} catch (Exception ex) {
if (!this.rdb.getAcmt()) {
this.rdb.rollBack();
}
throw ex;
} finally {
this.rdb.release();
}
if (buyer == null) {
this.log.warn(pRvs, getClass(), "Trying to retrieve orders without buyer!");
redir(pRvs, pRqDt);
}
}
/**
* Retrieve page.
* @param pRvs request scoped vars
* @param pRqDt Request Data
* @param pBuyr buyer
* @throws Exception - an exception
**/
public final void page(final Map pRvs,
final IReqDt pRqDt, final Buyer pBuyr) throws Exception {
//orders:
int page;
CmnPrf cpf = (CmnPrf) pRvs.get("cpf");
String pgSt = pRqDt.getParam("pg");
if (pgSt != null) {
page = Integer.parseInt(pgSt);
} else {
page = 1;
}
Map vs = new HashMap();
String wheBr = "BUYR=" + pBuyr.getIid();
Integer rowCount = this.orm.evRowCntWhe(pRvs, vs, CuOr.class, wheBr);
int totalPages = this.srvPg.evPgCnt(rowCount, cpf.getPgSz());
if (page > totalPages) {
page = totalPages;
}
int firstResult = (page - 1) * cpf.getPgSz(); //0-20,20-40
List pages = this.srvPg.evPgs(page, totalPages,
cpf.getPgTl());
pRvs.put("pgs", pages);
String[] fnm = new String[] {"nme"};
vs.put("PicPlcndFds", fnm);
vs.put("BuyerdpLv", 1);
List orders = getOrm().retPgCnd(pRvs, vs, CuOr.class,
"where " + wheBr, firstResult, cpf.getPgSz()); vs.clear();
pRvs.put("ords", orders);
//S.E. orders:
pgSt = pRqDt.getParam("spg");
if (pgSt != null) {
page = Integer.parseInt(pgSt);
} else {
page = 1;
}
rowCount = this.orm.evRowCntWhe(pRvs, vs, CuOrSe.class, wheBr);
totalPages = this.srvPg.evPgCnt(rowCount, cpf.getPgSz());
if (page > totalPages) {
page = totalPages;
}
firstResult = (page - 1) * cpf.getPgSz(); //0-20,20-40
pages = this.srvPg.evPgs(1, totalPages, cpf.getPgTl());
pRvs.put("spgs", pages);
vs.put("DbCrndFds", fnm);
vs.put("SeSelndFds", new String[] {"dbcr"});
vs.put("SeSeldpLv", 2);
vs.put("BuyerdpLv", 0);
List sorders = getOrm().retPgCnd(pRvs, vs, CuOrSe.class,
"where " + wheBr, firstResult, cpf.getPgSz()); vs.clear();
pRvs.put("sords", sorders);
}
/**
* Redirect.
* @param pRvs request scoped vars
* @param pRqDt Request Data
* @throws Exception - an exception
**/
public final void redir(final Map pRvs,
final IReqDt pRqDt) throws Exception {
String procNm = pRqDt.getParam("prcRed");
if (getClass().getSimpleName().equals(procNm)) {
throw new ExcCode(ExcCode.SPAM, "Danger! Stupid scam!!!");
}
IPrc proc = this.fcPrWs.laz(pRvs, procNm);
proc.process(pRvs, pRqDt);
}
//Simple getters and setters:
/**
* 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 rdb.
* @return IRdb
**/
public final IRdb getRdb() {
return this.rdb;
}
/**
* Setter for rdb.
* @param pRdb reference
**/
public final void setRdb(final IRdb pRdb) {
this.rdb = pRdb;
}
/**
* Getter for trIsl.
* @return Integer
**/
public final Integer getTrIsl() {
return this.trIsl;
}
/**
* Setter for trIsl.
* @param pTrIsl reference
**/
public final void setTrIsl(final Integer pTrIsl) {
this.trIsl = pTrIsl;
}
/**
* Geter for orm.
* @return IOrm
**/
public final IOrm getOrm() {
return this.orm;
}
/**
* Setter for orm.
* @param pOrm reference
**/
public final void setOrm(final IOrm pOrm) {
this.orm = pOrm;
}
/**
* Getter for srvPg.
* @return ISrvPg
**/
public final ISrvPg getSrvPg() {
return this.srvPg;
}
/**
* Setter for srvPg.
* @param pSrvPg reference
**/
public final void setSrvPg(final ISrvPg pSrvPg) {
this.srvPg = pSrvPg;
}
/**
* Getter for retrv.
* @return PrcEntRt
**/
public final PrcEntRt getRetrv() {
return this.retrv;
}
/**
* Setter for retrv.
* @param pRetrv reference
**/
public final void setRetrv(final PrcEntRt pRetrv) {
this.retrv = pRetrv;
}
/**
* Getter for buySr.
* @return IBuySr
**/
public final IBuySr getBuySr() {
return this.buySr;
}
/**
* Setter for buySr.
* @param pBuySr reference
**/
public final void setBuySr(final IBuySr pBuySr) {
this.buySr = pBuySr;
}
/**
* Getter for fcPrWs.
* @return FcPrWs
**/
public final FcPrWs getFcPrWs() {
return this.fcPrWs;
}
/**
* Setter for fcPrWs.
* @param pFcPrWs reference
**/
public final void setFcPrWs(final FcPrWs pFcPrWs) {
this.fcPrWs = pFcPrWs;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy