예제 #1
0
  @SuppressWarnings("unchecked")
  @Override
  protected void parseFile(String[] argFileString, IMetadataFieldSet argDefaultFields)
      throws InvalidDendroFileException {
    defaults = (TrimsToTridasDefaults) argDefaultFields;
    // TODO run the 'metadata' through the defaults, as
    // the user may have specified his own metadata
    // Extract 'metadata' ;-)
    String userid = argFileString[0].trim();
    SafeIntYear startYear = null;

    try {
      startYear = new SafeIntYear(argFileString[2].trim());
    } catch (NumberFormatException e) {
    }

    // Extract data
    ArrayList<TridasValue> ringWidthValues = new ArrayList<TridasValue>();
    for (int i = 3; i < argFileString.length; i++) {
      TridasValue v = new TridasValue();

      if (argFileString[i].startsWith(" ")) {
        if (argFileString[i].trim().equals("999")) {
          break;
        }
        v.setValue(argFileString[i].trim());
        ringWidthValues.add(v);
        log.debug("value = " + String.valueOf(argFileString[i]));
      } else {
        throw new InvalidDendroFileException(I18n.getText("trims.expectingSpace"), i);
      }
    }

    // Now build up our measurementSeries

    TridasMeasurementSeries series = defaults.getMeasurementSeriesWithDefaults();
    TridasUnit units = new TridasUnit();

    // Set units to 1/100th mm. Is this always the case?
    units.setNormalTridas(NormalTridasUnit.HUNDREDTH_MM);

    // Build identifier for series
    TridasIdentifier seriesId = new ObjectFactory().createTridasIdentifier();
    seriesId.setValue(UUID.randomUUID().toString());
    seriesId.setDomain(
        defaults.getDefaultValue(TridasMandatoryField.IDENTIFIER_DOMAIN).getStringValue());

    // Build interpretation group for series
    TridasInterpretation interp = new TridasInterpretation();
    interp.setFirstYear(startYear.toTridasYear(DatingSuffix.AD));
    interp.setLastYear(startYear.add(ringWidthValues.size() - 1).toTridasYear(DatingSuffix.AD));

    // Add values to nested value(s) tags
    TridasValues valuesGroup = new TridasValues();
    valuesGroup.setValues(ringWidthValues);
    valuesGroup.setUnit(units);
    GenericDefaultValue<TridasVariable> variable =
        (GenericDefaultValue<TridasVariable>)
            defaults.getDefaultValue(TridasMandatoryField.MEASUREMENTSERIES_VARIABLE);
    valuesGroup.setVariable(variable.getValue());
    ArrayList<TridasValues> valuesGroupList = new ArrayList<TridasValues>();
    valuesGroupList.add(valuesGroup);

    // Add all the data to the series
    series.setValues(valuesGroupList);
    series.setInterpretation(interp);
    series.setIdentifier(seriesId);
    series.setLastModifiedTimestamp(DateUtils.getTodaysDateTime());
    series.setDendrochronologist(userid);

    // Add series to our list
    mseriesList.add(series);
  }
예제 #2
0
  @Override
  public String[] saveToString() {

    ArrayList<String> file = new ArrayList<String>();

    String line = "'" + defaults.getStringDefaultValue(OxDefaultFields.SERIESCODE).getStringValue();
    line += "  <" + defaults.getIntegerDefaultValue(OxDefaultFields.FIRSTYEAR).getStringValue();
    line += "-" + defaults.getIntegerDefaultValue(OxDefaultFields.LASTYEAR).getStringValue() + "> ";
    line += defaults.getStringDefaultValue(OxDefaultFields.DESCRIPTION).getStringValue() + "'";

    file.add(line);

    line = defaults.getIntegerDefaultValue(OxDefaultFields.SERIESLENGTH).getStringValue() + ",";
    line += defaults.getIntegerDefaultValue(OxDefaultFields.STARTYEAR).getStringValue();

    file.add(line);

    // Data
    Integer col = 0;
    line = "";
    Boolean hasCounts = false;
    for (TridasValue val : valuesGroup.getValues()) {
      col++;

      if (col > 10) {
        file.add(line.substring(0, line.length() - 1));
        line = "";
        col = 1;
      }

      line += StringUtils.leftPad(val.getValue(), 3) + " ";

      if (val.isSetCount()) hasCounts = true;
    }

    if (line.length() > 0) {
      file.add(line.substring(0, line.length() - 1));
    }

    file.add("");

    // Add counts section if applicable
    if (hasCounts) {
      col = 0;
      line = "";
      for (TridasValue val : valuesGroup.getValues()) {
        col++;

        if (col > 10) {
          file.add(line.substring(0, line.length() - 1));
          line = "";
          col = 1;
        }

        if (val.isSetCount()) {
          line += StringUtils.leftPad(val.getCount().toString(), 3) + " ";
        } else {
          line += StringUtils.leftPad("0".toString(), 3) + " ";
          defaults.addConversionWarning(
              new ConversionWarning(WarningType.INVALID, I18n.getText("oxford.countsEmpty")));
        }
      }
      if (line.length() > 0) {
        file.add(line.substring(0, line.length() - 1));
      }
    }

    // Comments
    if (defaults.getStringDefaultValue(OxDefaultFields.COMMENTS).getValue() != null) {
      file.add(defaults.getStringDefaultValue(OxDefaultFields.COMMENTS).getStringValue());
    }

    // Return file
    return file.toArray(new String[0]);
  }