<p>Retrieve/get Trading settings.</p>
@param pAddParam additional param
@return Trading settings
@throws Exception - an exception
323383
@Override
  public final synchronized TradingSettings lazyGetTradingSettings(
    final Map<String, Object> pAddParam) throws Exception {
    if (this.tradingSettings == null) {
      this.tradingSettings = getSrvOrm()
        .retrieveEntityById(pAddParam, TradingSettings.class, 1L);
      if (this.tradingSettings == null) {
        throw new ExceptionWithCode(ExceptionWithCode.CONFIGURATION_MISTAKE,
          "There is no trading settings!!!");
      }
    }
    return this.tradingSettings;
  }
1241795
@Override
  public final synchronized void saveAccSettings(
    final Map<String, Object> pAddParam,
      final AccSettings pEntity) throws Exception {
    if (pEntity.getIsNew()) {
      throw new ExceptionWithCode(ExceptionWithCode.FORBIDDEN,
        "Attempt to insert accounting settings by " + pAddParam.get("user"));
    } else {
      if (pEntity.getCostPrecision() < 0 || pEntity.getCostPrecision() > 4) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "precision_must_be_from_0_to_4");
      }
      if (pEntity.getPricePrecision() < 0 || pEntity.getPricePrecision() > 4) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "precision_must_be_from_0_to_4");
      }
      if (pEntity.getQuantityPrecision() < 0
        || pEntity.getQuantityPrecision() > 4) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "precision_must_be_from_0_to_4");
      }
      if (pEntity.getBalancePrecision() < 0
        || pEntity.getBalancePrecision() > 4) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "precision_must_be_from_0_to_4");
      }
      getSrvOrm().updateEntity(pAddParam, pEntity);
      retrieveAccSettings(pAddParam);
    }
  }
1141471
protected final PrcBankStatementLineGfe<RS> lazyGetPrcBankStatementLineGfe(
    final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcBankStatementLineGfe<RS> proc = (PrcBankStatementLineGfe<RS>)
      this.processorsMap.get(PrcBankStatementLineGfe.class.getSimpleName());
    if (proc == null) {
      proc = new PrcBankStatementLineGfe<RS>();
      proc.setSrvOrm(getSrvOrm());
      proc.setSrvTypeCode(getSrvTypeCode());
      @SuppressWarnings("unchecked")
      PrcEntityPbEditDelete<RS, BankStatementLine> procDlg =
    (PrcEntityPbEditDelete<RS, BankStatementLine>) this.fctBnEntitiesProcessors
  .lazyGet(pAddParam, PrcEntityPbEditDelete.class.getSimpleName());
      proc.setPrcEntityPbEditDelete(procDlg);
      //assigning fully initialized object:
      this.processorsMap
        .put(PrcBankStatementLineGfe.class.getSimpleName(), proc);
    }
    return proc;
  }
758745
@Override
  public final List<? extends ADrawItemSourcesLine>
    getDrawItemSources(
      final Map<String, Object> pAddParam) throws Exception {
    return getSrvAccSettings().lazyGetAccSettings(pAddParam)
      .getDrawMaterialSources();
  }
158008
@Override
  public final IProcessor lazyGet(
    final Map<String, Object> pAddParam,
      final String pBeanName) throws Exception {
    IProcessor proc =
      this.processorsMap.get(pBeanName);
    if (proc == null) {
      // locking:
      synchronized (this.processorsMap) {
        // make sure again whether it's null after locking:
        proc = this.processorsMap.get(pBeanName);
        if (proc == null) {
          if (pBeanName.equals(PrcEntitiesPage.class.getSimpleName())) {
            proc = createPutPrcEntitiesPage();
          } else if (pBeanName.equals(PrcRefreshHndlI18n
            .class.getSimpleName())) {
            proc = lazyGetPrcRefreshHndlI18n(pAddParam);
          } else if (pBeanName.equals(PrcAbout.class.getSimpleName())) {
            proc = lazyGetPrcAbout(pAddParam);
          }
        }
      }
    }
    if (proc == null && !this.isItSubfactory) {
      throw new ExceptionWithCode(ExceptionWithCode.CONFIGURATION_MISTAKE,
        "There is no processor with name " + pBeanName);
    }
    return proc;
  }
813741
protected final PrCart<RS> lazyGetPrCart(
    final Map<String, Object> pAddParam) throws Exception {
    String beanName = PrCart.class.getSimpleName();
    @SuppressWarnings("unchecked")
    PrCart<RS> proc = (PrCart<RS>)
      this.processorsMap.get(beanName);
    if (proc == null) {
      proc = new PrCart<RS>();
      proc.setSrvOrm(getSrvOrm());
      proc.setSrvCart(getSrvShoppingCart());
      proc.setProcessorsFactory(this);
      //assigning fully initialized object:
      this.processorsMap.put(beanName, proc);
      this.logger.info(null, FctBnPublicTradeProcessors.class,
        beanName + " has been created.");
    }
    return proc;
  }
1014201
protected final PrcBankStatementSave<RS> lazyGetPrcBankStatementSave(
    final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcBankStatementSave<RS> proc = (PrcBankStatementSave<RS>)
      this.processorsMap.get(PrcBankStatementSave.class.getSimpleName());
    if (proc == null) {
      proc = new PrcBankStatementSave<RS>();
      proc.setSrvOrm(getSrvOrm());
      proc.setCsvReader(getCsvReader());
      //assigning fully initialized object:
      this.processorsMap.put(PrcBankStatementSave.class.getSimpleName(), proc);
    }
    return proc;
  }
184592
@Override
  public final void process(final Map<String, Object> pAddParam,
    final IRequestData pRequestData) throws Exception {
    String retrieverName = pRequestData.getParameter("nmRet");
    ICsvDataRetriever ret = this.retrievers.get(retrieverName);
    if (ret == null) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "Can't find retriever " + retrieverName);
    }
    pRequestData.setAttribute("dataTree", ret.getSampleDataRow(pAddParam));
  }
493239
@Override
  public final synchronized void recalculateAllIfNeed(
    final Map<String, Object> pAddParam, final Date pDateFor) throws Exception {
    //must be before evalDateBalanceStoreStart!!!
    evalBalanceStorePeriod(pAddParam);
    evalDateBalanceStoreStart(pAddParam);
    Date datePeriodStartFor = evalDatePeriodStartFor(pAddParam, pDateFor);
    Calendar calCurrYear = Calendar.getInstance(new Locale("en", "US"));
    calCurrYear.setTime(getSrvAccSettings().lazyGetAccSettings(pAddParam)
      .getCurrentAccYear());
    calCurrYear.set(Calendar.MONTH, 0);
    calCurrYear.set(Calendar.DAY_OF_MONTH, 1);
    calCurrYear.set(Calendar.HOUR_OF_DAY, 0);
    calCurrYear.set(Calendar.MINUTE, 0);
    calCurrYear.set(Calendar.SECOND, 0);
    calCurrYear.set(Calendar.MILLISECOND, 0);
    Calendar calStBl = Calendar.getInstance(new Locale("en", "US"));
    calStBl.setTime(this.balanceAtAllDirtyCheck.getDateBalanceStoreStart());
    calStBl.set(Calendar.MONTH, 0);
    calStBl.set(Calendar.DAY_OF_MONTH, 1);
    calStBl.set(Calendar.HOUR_OF_DAY, 0);
    calStBl.set(Calendar.MINUTE, 0);
    calStBl.set(Calendar.SECOND, 0);
    calStBl.set(Calendar.MILLISECOND, 0);
    if (calCurrYear.getTime().getTime() < calStBl.getTime().getTime()
      || this.balanceAtAllDirtyCheck
          .getLeastAccountingEntryDate()
            .getTime() < this.balanceAtAllDirtyCheck
              .getDateBalanceStoreStart().getTime()) {
      this.balanceAtAllDirtyCheck
        .setCurrentBalanceDate(initDate);
      this.balanceAtAllDirtyCheck
        .setDateBalanceStoreStart(initDate);
      evalDateBalanceStoreStart(pAddParam);
      recalculateAll(pAddParam, pDateFor, false);
    } else if (datePeriodStartFor.getTime() > this.balanceAtAllDirtyCheck
      .getCurrentBalanceDate().getTime()
        || this.balanceAtAllDirtyCheck
          .getLeastAccountingEntryDate()
            .getTime() < this.balanceAtAllDirtyCheck
              .getCurrentBalanceDate().getTime()) {
      recalculateAll(pAddParam, pDateFor, false);
    }
  }
62731
protected final PrCuOrSeSv<RS> lazyGetPrCuOrSeSv(
      final Map<String, Object> pAddParam) throws Exception {
    String beanName = PrCuOrSeSv.class.getSimpleName();
    @SuppressWarnings("unchecked")
    PrCuOrSeSv<RS> proc = (PrCuOrSeSv<RS>) this.processorsMap.get(beanName);
    if (proc == null) {
      proc = new PrCuOrSeSv<RS>();
      proc.setSrvOrm(getSrvOrm());
      proc.setCncOrd(getCncOrd());
      //assigning fully initialized object:
      this.processorsMap.put(beanName, proc);
      this.logger.info(null, FctBnSeSelEntityProcs.class,
        beanName + " has been created.");
    }
    return proc;
  }
814925
public final synchronized Date evalDateBalanceStoreStart(
    final Map<String, Object> pAddParam) throws Exception {
    Date dateBalanceStoreStart = lazyGetBalanceAtAllDirtyCheck(pAddParam)
      .getDateBalanceStoreStart();
    Date leastAccountingEntryDate = this.balanceAtAllDirtyCheck
      .getLeastAccountingEntryDate();
    if (dateBalanceStoreStart.getTime() == this.initDateLong
      && leastAccountingEntryDate.getTime() == this.initDateLong) {
      //the first time with no acc-entries, it's start of current ACC year:
      Calendar cal = Calendar.getInstance(new Locale("en", "US"));
      cal.setTime(getSrvAccSettings().lazyGetAccSettings(pAddParam)
        .getCurrentAccYear());
      cal.set(Calendar.MONTH, 0);
      cal.set(Calendar.DAY_OF_MONTH, 1);
      cal.set(Calendar.HOUR_OF_DAY, 0);
      cal.set(Calendar.MINUTE, 0);
      cal.set(Calendar.SECOND, 0);
      cal.set(Calendar.MILLISECOND, 0);
      this.balanceAtAllDirtyCheck
        .setDateBalanceStoreStart(cal.getTime());
      getSrvOrm()
        .updateEntity(pAddParam, this.balanceAtAllDirtyCheck);
    } else if (dateBalanceStoreStart.getTime() == this.initDateLong
      && leastAccountingEntryDate.getTime() > this.initDateLong) {
      //there is at least 1 acc entry
      //the start is start of nearest period to the first acc entry:
      Long dateFirstEntryLong = this.srvDatabase
        .evalLongResult("select min(ITSDATE) as MINIMUMDATE "
          + "from ACCOUNTINGENTRY where REVERSEDID is null;", "MINIMUMDATE");
      if (dateFirstEntryLong == null) {
        //e.g. dirty reversed acc entry
        getLogger().info(null, SrvBalanceStd.class,
    "There is no single acc entry, so use current acc year for start balance!");
        Calendar cal = Calendar.getInstance(new Locale("en", "US"));
        cal.setTime(getSrvAccSettings().lazyGetAccSettings(pAddParam)
          .getCurrentAccYear());
        cal.set(Calendar.MONTH, 0);
        cal.set(Calendar.DAY_OF_MONTH, 1);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        this.balanceAtAllDirtyCheck
          .setDateBalanceStoreStart(cal.getTime());
      } else {
        this.balanceAtAllDirtyCheck.setDateBalanceStoreStart(
          evalDatePeriodStartFor(pAddParam, new Date(dateFirstEntryLong)));
      }
      getSrvOrm()
        .updateEntity(pAddParam, this.balanceAtAllDirtyCheck);
    }
    return this.balanceAtAllDirtyCheck.getDateBalanceStoreStart();
   }
1294399
protected final PrcBeginningInventoryLineGfr
    lazyGetPrcBeginningInventoryLineGfr(
      final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcBeginningInventoryLineGfr<RS> proc =
      (PrcBeginningInventoryLineGfr<RS>) this.processorsMap
        .get(PrcBeginningInventoryLineGfr.class.getSimpleName());
    if (proc == null) {
      proc = new PrcBeginningInventoryLineGfr<RS>();
      @SuppressWarnings("unchecked")
      PrcEntityPbCopy<RS, BeginningInventoryLine> procDlg =
        (PrcEntityPbCopy<RS, BeginningInventoryLine>)
          this.fctBnEntitiesProcessors
            .lazyGet(pAddParam, PrcEntityPbCopy.class.getSimpleName());
      proc.setPrcAccEntityPbCopy(procDlg);
      //assigning fully initialized object:
      this.processorsMap
        .put(PrcBeginningInventoryLineGfr.class.getSimpleName(), proc);
    }
    return proc;
  }
673141
protected final PrcPurchaseInvoiceLineGfr lazyGetPrcPurchaseInvoiceLineGfr(
    final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcPurchaseInvoiceLineGfr<RS> proc = (PrcPurchaseInvoiceLineGfr<RS>)
      this.processorsMap.get(PrcPurchaseInvoiceLineGfr.class.getSimpleName());
    if (proc == null) {
      proc = new PrcPurchaseInvoiceLineGfr<RS>();
      @SuppressWarnings("unchecked")
      PrcEntityPbCopy<RS, PurchaseInvoiceLine> procDlg =
        (PrcEntityPbCopy<RS, PurchaseInvoiceLine>)
          this.fctBnEntitiesProcessors
            .lazyGet(pAddParam, PrcEntityPbCopy.class.getSimpleName());
      proc.setPrcAccEntityPbCopy(procDlg);
      //assigning fully initialized object:
      this.processorsMap
        .put(PrcPurchaseInvoiceLineGfr.class.getSimpleName(), proc);
    }
    return proc;
  }
1272718
protected final InvoiceReportPdf<RS, WI>
    lazyGetInvoiceReportPdf(
      final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    InvoiceReportPdf<RS, WI> rep =
      (InvoiceReportPdf<RS, WI>)
        this.reportersMap
          .get(InvoiceReportPdf.class.getSimpleName());
    if (rep == null) {
      rep = new InvoiceReportPdf<RS, WI>();
      rep.setSrvAccSettings(getSrvAccSettings());
      rep.setSrvNumberToString(getSrvNumberToString());
      rep.setSrvI18n(getSrvI18n());
      rep.setSrvOrm(getSrvOrm());
      rep.setPdfFactory(this.pdfFactory);
      //assigning fully initialized object:
      this.reportersMap.put(InvoiceReportPdf.class.getSimpleName(), rep);
    }
    return rep;
  }
684328
@Override
  public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    int pageNumber = ((TradeHistoryParamPaging) params).getPageNumber() + 1;
    return IndependentReserveAdapters.adaptTradeHistory(
        getIndependentReserveTradeHistory(pageNumber));
  }
527414
public final synchronized BalanceAtAllDirtyCheck
    lazyGetBalanceAtAllDirtyCheck(
      final Map<String, Object> pAddParam) throws Exception {
    if (this.balanceAtAllDirtyCheck == null) {
      BalanceAtAllDirtyCheck balLoc = new BalanceAtAllDirtyCheck();
      balLoc.setItsId(1L);
      this.balanceAtAllDirtyCheck = getSrvOrm()
        .retrieveEntity(pAddParam, balLoc);
      if (this.balanceAtAllDirtyCheck == null) {
        getSrvOrm().insertEntity(pAddParam, balLoc);
        balLoc.setIsNew(false);
        this.balanceAtAllDirtyCheck = getSrvOrm()
          .retrieveEntity(pAddParam, balLoc);
      }
    }
    return this.balanceAtAllDirtyCheck;
  }
279603
protected final PrcCsvSampleDataRow
    lazyGetPrcCsvSampleDataRow(
      final Map<String, Object> pAddParam) throws Exception {
    String beanName = PrcCsvSampleDataRow.class.getSimpleName();
    @SuppressWarnings("unchecked")
    PrcCsvSampleDataRow proc = (PrcCsvSampleDataRow)
      this.processorsMap.get(beanName);
    if (proc == null) {
      proc = new PrcCsvSampleDataRow();
      lazyInitRetrievers(pAddParam);
      proc.setRetrievers(this.retrievers);
      //assigning fully initialized object:
      this.processorsMap.put(beanName, proc);
      this.logger.info(null, FctBnTradeProcessors.class,
        beanName + " has been created.");
    }
    return proc;
  }