Package net.sf.chellow.monad

Examples of net.sf.chellow.monad.UserException


    if (extension.equals("zip")) {
      try {
        is = new ZipInputStream(new BufferedInputStream(is));
        ZipEntry entry = ((ZipInputStream) is).getNextEntry();
        if (entry == null) {
          throw new UserException(null,
              "Can't find an entry within the zip file.");
        }
        String name = entry.getName();
        extension = name.substring(name.length() - 3);
      } catch (IOException e) {
View Full Code Here


    try {
      String[] allValues = digester.getLine();
      List<HhDatumRaw> hhData = new ArrayList<HhDatumRaw>();
      while (allValues != null && !shouldHalt()) {
        if (allValues.length < 2) {
          throw new UserException(
              "There must be an 'Action' field followed "
                  + "by a 'Type' field.");
        }
        Hiber.setReadWrite();
        String action = allValues[0].trim().toLowerCase();
        String type = allValues[1].trim().toLowerCase();
        if (type.equals("hh-datum")) {
          try {
            long startProchh = System.currentTimeMillis();
            if (action.equals("insert")) {
              String mpanCore = allValues[2];
              boolean isImport = Boolean
                  .parseBoolean(allValues[4]);
              boolean isKwh = Boolean.parseBoolean(allValues[5]);
              HhStartDate startDate = new HhStartDate(
                  allValues[3]);
              String hhString = allValues[6].trim();
              if (hhString.endsWith(",")) {
                hhString = hhString + " ";
              }
              String[] vals = hhString.split(",");
              if (vals.length % 2 != 0) {
                StringBuilder valsBuilder = new StringBuilder();
                for (String val : vals) {
                  valsBuilder.append(val + " ");
                }
                throw new UserException(
                    "There must be an even number of values in the list of hh data. This list is "
                        + valsBuilder + ".");
              }
              for (int i = 0; i < vals.length; i += 2) {
                String bigDecimal = vals[i];
                if (bigDecimal.length() > 0) {
                  Character status = null;
                  String statusString = vals[i + 1].trim();
                  if (statusString.length() > 0) {
                    status = statusString.charAt(0);
                  }
                  hhData.add(new HhDatumRaw(mpanCore,
                      isImport, isKwh, startDate,
                      new BigDecimal(bigDecimal), status));
                }
                startDate = startDate.getNext();
              }
              HhDatum.insert(hhData.iterator(), halt);
              hhData.clear();
            }
            totalHhTime = totalHhTime + System.currentTimeMillis()
                - startProchh;
          } catch (UserException e) {
            StringBuilder message = new StringBuilder(
                "Problem loading a HH datum with values: ");
            for (String value : allValues) {
              message.append(value + ", ");
            }
            throw new UserException(message + ". Message: "
                + e.getMessage());
          }
        } else {
          csvElement = doc.createElement("csvLine");
          // try {
          addField(csvElement, "Action", allValues, 0);
          addField(csvElement, "Type", allValues, 1);
          if (!action.equals("insert") && !action.equals("update")
              && !action.equals("delete")) {
            throw new UserException("The 'Action' field can "
                + "only be 'insert', 'update', 'delete'.");
          }
          String[] values = Arrays.copyOfRange(allValues, 2,
              allValues.length);

          if (type.equals("site")) {
            Site.generalImport(action, values, csvElement);
          } else if (type.equals("site-supply-generation")) {
            SiteSupplyGeneration.generalImport(action, values,
                csvElement);
          } else if (type.equals("supply")) {
            Supply.generalImport(action, values, csvElement);
          } else if (type.equals("supply-generation")) {
            SupplyGeneration.generalImport(action, values,
                csvElement);
          } else if (type.equals("report")) {
            Report.generalImport(action, values, csvElement);
          } else if (type.equals("hhdc-contract-rate-script")) {
            RateScript
                .generalImportHhdc(action, values, csvElement);
          } else if (type.equals("non-core-contract")) {
            NonCoreContract.generalImport(action, values,
                csvElement);
          } else if (type.equals("non-core-contract-rate-script")) {
            RateScript.generalImportNonCore(action, values,
                csvElement);
          } else if (type.equals("supplier-contract")) {
            SupplierContract.generalImport(action, values,
                csvElement);
          } else if (type.equals("supplier-contract-rate-script")) {
            RateScript.generalImportSupplier(action, values,
                csvElement);
          } else if (type.equals("user")) {
            User.generalImport(action, values, csvElement);
          } else if (type.equals("dno-contract")) {
            DnoContract.generalImport(action, values, csvElement);
          } else if (type.equals("dno-contract-rate-script")) {
            RateScript.generalImportDno(action, values, csvElement);
          } else if (type.equals("configuration")) {
            Configuration.generalImport(action, values, csvElement);
          } else if (type.equals("channel-snag-ignore")) {
            ChannelSnag.generalImport(action, values, csvElement);
          } else if (type.equals("site-snag-ignore")) {
            SiteSnag.generalImport(action, values, csvElement);
          } else if (type.equals("batch")) {
            Batch.generalImport(action, values, csvElement);
          } else if (type.equals("bill")) {
            Bill.generalImport(action, values, csvElement);
          } else if (type.equals("register-read")) {
            RegisterRead.generalImport(action, values, csvElement);
          } else if (type.equals("mop-contract")) {
            MopContract.generalImport(action, values, csvElement);
          } else if (type.equals("mop-contract-rate-script")) {
            RateScript.generalImportMop(action, values, csvElement);
          } else {
            throw new UserException("The type " + type
                + " isn't recognized.");
          }
          csvElement = null;
        }
        Hiber.commit();
View Full Code Here

  }

  public static String addField(Element csvElement, String name,
      String[] values, int index) throws HttpException {
    if (index > values.length - 1) {
      throw new UserException("Another field called " + name
          + " needs to be added on the end.");
    }
    String value = values[index].trim();
    Document doc = csvElement.getOwnerDocument();
    Element field = doc.createElement("Field");
View Full Code Here

  public void initialize(Long batchId, Long id, InputStream is,
      String fileName, long size) throws HttpException {
    this.batchId = batchId;
    this.id = id;
    if (size == 0) {
      throw new UserException(null, "File has zero length");
    }
    fileName = fileName.toLowerCase();
    if (fileName.endsWith(".zip")) {
      try {
        is = new ZipInputStream(new BufferedInputStream(is));
        ZipEntry entry = ((ZipInputStream) is).getNextEntry();
        if (entry == null) {
          throw new UserException(null,
              "Can't find an entry within the zip file.");
        }
        fileName = entry.getName();

        // extract data
        // open output streams
      } catch (IOException e) {
        throw new InternalException(e);
      }
    }
    int locationOfDot = fileName.lastIndexOf(".");
    if (locationOfDot == -1 || locationOfDot == fileName.length() - 1) {
      throw new UserException(
          "The file name must have an extension (eg. '.zip')");
    }
    int location2Dot = fileName.lastIndexOf(".", locationOfDot - 1);
    if (location2Dot != -1) {
      locationOfDot = location2Dot;
View Full Code Here

      successfulBills = Collections
          .synchronizedList(new ArrayList<RawBill>());
      for (RawBill rawBill : rawBills) {
        Hiber.flush();
        if (shouldHalt()) {
          throw new UserException(
              "The import has been halted by the user, some bills may have been imported though.");
        }
        try {
          Hiber.flush();
          Hiber.setReadWrite();
View Full Code Here

          r = factory.createXMLEventReader(reader);
        } catch (XMLStreamException e) {
          throw new InternalException(e);
        }
      } else {
        throw new UserException("The file extension was '" + extension
            + "' but only csv or xml is recognized.");
      }
    }
View Full Code Here

  public static SupplierContract getSupplierContract(Long id)
      throws HttpException {
    SupplierContract contract = findSupplierContract(id);
    if (contract == null) {
      throw new UserException(
          "There isn't a supplier contract with that id.");
    }
    return contract;
  }
View Full Code Here

        .session()
        .createQuery(
            "from SupplierContract contract where contract.name = :name")
        .setString("name", getName()).uniqueResult();
    if (existing != null && getId() != existing.getId()) {
      throw new UserException(
          "There's already a supplier contract called " + getName());
    }
  }
View Full Code Here

      String chargeScript = inv.getString("charge-script");
      String name = inv.getString("name");
      Long participantId = inv.getLong("participant-id");

      if (!inv.isValid()) {
        throw new UserException(document());
      }
      chargeScript = chargeScript.replace("\r", "").replace("\t", "    ");

      try {
        update(Participant.getParticipant(participantId), name,
View Full Code Here

          .setTimestamp("finishDate", getFinishDate().getDate());
    }
    List<Mpan> mpansOutside = query.setEntity("contract", this)
        .setTimestamp("startDate", getStartDate().getDate()).list();
    if (!mpansOutside.isEmpty()) {
      throw new UserException(document(),
          mpansOutside.size() > 1 ? "The MPANs with cores "
              + mpansOutside.get(0).getCore()
              + " and "
              + mpansOutside.get(mpansOutside.size() - 1)
                  .getCore() + " use this contract"
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.