Package net.sf.chellow.monad

Examples of net.sf.chellow.monad.UserException


        .session()
        .createQuery(
            "from RateScript script where script.contract = :contract order by script.startDate.date")
        .setEntity("contract", this).list();
    if (rateScriptList.size() < 2) {
      throw new UserException("You can't delete the last rate script.");
    }
    rateScripts.remove(rateScript);
    if (rateScriptList.get(0).equals(rateScript)) {
      setStartRateScript(rateScriptList.get(1));
      Hiber.flush();
View Full Code Here


    try {
      scriptEngine.eval(chargeScript);
      scriptEngine.put("contract", this);
      invocableEngine = (Invocable) scriptEngine;
    } catch (ScriptException e) {
      throw new UserException(e.getMessage());
    }
    return invocableEngine;
    // return invocableEngine(getChargeScript());
  }
View Full Code Here

        .setEntity("contract", this);
    List<RateScript> rateScripts = (List<RateScript>) rateScriptQuery
        .list();
    RateScript lastRateScript = rateScripts.get(rateScripts.size() - 1);
    if (HhStartDate.isAfter(startDate, lastRateScript.getFinishDate())) {
      throw new UserException("For the contract " + getId() + " called "
          + getName() + ", the start date " + startDate
          + " is after the last rate script.");
    }

    RateScript coveredRateScript = (RateScript) Hiber
        .session()
        .createQuery(
            "from RateScript script where script.contract = :contract and script.startDate.date <= :startDate and (script.finishDate is null or script.finishDate.date >= :startDate)")
        .setEntity("contract", this)
        .setTimestamp("startDate", startDate.getDate()).uniqueResult();
    HhStartDate finishDate = null;
    if (coveredRateScript == null) {
      finishDate = rateScripts.get(0).getStartDate().getPrevious();
    } else {
      if (coveredRateScript.getStartDate().equals(
          coveredRateScript.getFinishDate())) {
        throw new UserException(
            "The start date falls on a rate script which is only half an hour in length, and so cannot be subdivided further.");
      }
      if (startDate.equals(coveredRateScript.getStartDate())) {
        throw new UserException(
            "The start date is the same as the start date of an existing rate script.");
      }
      finishDate = coveredRateScript.getFinishDate();
      coveredRateScript.setFinishDate(startDate.getPrevious());
    }
View Full Code Here

    try {
      interp.set("contract", this);
      interp.exec(chargeScript);
      PyObject function = interp.get(name);
      if (function == null) {
        throw new UserException("There isn't a function called " + name);
      }
      result = function.__call__(Py.javas2pys(args)).__tojava__(
          Object.class);
    } catch (Throwable e) {
      throw new UserException(HttpException.getStackTraceString(e));
    } finally {
      interp.cleanup();
    }
    return result;
  }
View Full Code Here

  }

  public static Contract getContract(Long id) throws HttpException {
    Contract contract = (Contract) Hiber.session().get(Contract.class, id);
    if (contract == null) {
      throw new UserException("There isn't a contract with that id.");
    }
    return contract;
  }
View Full Code Here

        .createQuery(
            "from Batch batch where batch.contract.id = :contractId and batch.reference = :reference")
        .setLong("contractId", getId())
        .setString("reference", reference).uniqueResult();
    if (batch == null) {
      throw new UserException("There isn't a batch attached to contract "
          + getId() + " with reference " + reference + ".");
    }
    return batch;
  }
View Full Code Here

    Batch batch = new Batch(this, reference, description);
    try {
      Hiber.session().save(batch);
      Hiber.flush();
    } catch (ConstraintViolationException e) {
      throw new UserException("There's already a batch with that reference.");
    }
    return batch;
  }
View Full Code Here

  public static RegisterRead getRegisterRead(Long id) throws HttpException {
    RegisterRead read = (RegisterRead) Hiber.session().get(
        RegisterRead.class, id);
    if (read == null) {
      throw new UserException("There isn't a register read with that id.");
    }
    return read;
  }
View Full Code Here

      String meterSerialNumber, String mpanStr, HhStartDate previousDate,
      BigDecimal previousValue, ReadType previousType,
      HhStartDate presentDate, BigDecimal presentValue,
      ReadType presentType) throws HttpException {
    if (tpr == null && units.equals(Units.KWH)) {
      throw new UserException(
          "If a register read is measuring kWh, there must be a TPR.");
    }
    setTpr(tpr);
    setCoefficient(coefficient);
    setUnits(units);
View Full Code Here

      Date presentDate = inv.getDateTime("present");
      BigDecimal presentValue = inv.getBigDecimal("present-value");
      Long presentTypeId = inv.getLong("present-type-id");

      if (!inv.isValid()) {
        throw new UserException(document());
      }
      update(Tpr.getTpr(tprCode), coefficient, Units.getUnits(units),
          meterSerialNumber, mpanStr, new HhStartDate(previousDate),
          previousValue, ReadType.getReadType(previousTypeId),
          new HhStartDate(presentDate), presentValue,
View Full Code Here

TOP

Related Classes of net.sf.chellow.monad.UserException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.