Exemplo n.º 1
0
  private void updateRecord(DataRecord r, ArrayList<String> fieldsInInport) {
    try {
      DataRecord rorig =
          (versionized ? dataAccess.getValidAt(r.getKey(), validAt) : dataAccess.get(r.getKey()));
      if (rorig == null) {
        logImportFailed(
            r, International.getString("Keine gültige Version des Datensatzes gefunden."), null);
        return;
      }

      // has the import record an InvalidFrom field?
      long invalidFrom = (versionized ? getInvalidFrom(r) : -1);
      if (invalidFrom <= rorig.getValidFrom()) {
        invalidFrom = -1;
      }
      boolean changed = false;

      for (int i = 0; i < fields.length; i++) {
        Object o = r.get(fields[i]);
        if ((o != null || fieldsInInport.contains(fields[i]))
            && !r.isKeyField(fields[i])
            && !fields[i].equals(DataRecord.LASTMODIFIED)
            && !fields[i].equals(DataRecord.VALIDFROM)
            && !fields[i].equals(DataRecord.INVALIDFROM)
            && !fields[i].equals(DataRecord.INVISIBLE)
            && !fields[i].equals(DataRecord.DELETED)) {
          Object obefore = rorig.get(fields[i]);
          rorig.set(fields[i], o);
          if ((o != null && !o.equals(obefore)) || (o == null && obefore != null)) {
            changed = true;
          }
        }
      }

      if (invalidFrom <= 0) {
        long myValidAt = getValidFrom(r);
        if (!versionized
            || updMode.equals(UPDMODE_UPDATEVALIDVERSION)
            || rorig.getValidFrom() == myValidAt) {
          if (changed) {
            dataAccess.update(rorig);
          }
          setCurrentWorkDone(++importCount);
        }
        if (versionized
            && updMode.equals(UPPMODE_CREATENEWVERSION)
            && rorig.getValidFrom() != myValidAt) {
          if (changed) {
            dataAccess.addValidAt(rorig, myValidAt);
          }
          setCurrentWorkDone(++importCount);
        }
      } else {
        dataAccess.changeValidity(rorig, rorig.getValidFrom(), invalidFrom);
        setCurrentWorkDone(++importCount);
      }
    } catch (Exception e) {
      logImportFailed(r, e.toString(), e);
    }
  }
Exemplo n.º 2
0
 private long getValidFrom(DataRecord r) {
   long rv = r.getValidFrom();
   return (rv > 0 ? rv : validAt);
 }
  protected void iniDialog() throws Exception {
    // create GUI items
    mainPanel.setLayout(new GridBagLayout());

    ItemTypeLabel label1 =
        new ItemTypeLabel(
            "LABEL1",
            IItemType.TYPE_PUBLIC,
            "",
            International.getMessage(
                "Gültigkeitszeitraum von Version {version} ändern", version + 1));
    label1.setPadding(0, 0, 0, 10);
    label1.displayOnGui(this, mainPanel, 0, 0);

    validFrom =
        new ItemTypeDateTime(
            "VALID_FROM",
            (rCurrent.getValidFrom() == 0 ? null : new DataTypeDate(rCurrent.getValidFrom())),
            (rCurrent.getValidFrom() == 0 ? null : new DataTypeTime(rCurrent.getValidFrom())),
            IItemType.TYPE_PUBLIC,
            "",
            International.getString("gültig ab"));
    validFrom.registerItemListener(this);
    if (rPrev != null && rPrev.getValidFrom() != 0) {
      validFrom.setMustBeAfter(
          new ItemTypeDateTime(
              "PREVRECORD_VALID_FROM",
              new DataTypeDate(rPrev.getValidFrom()),
              new DataTypeTime(rPrev.getValidFrom()),
              IItemType.TYPE_INTERNAL,
              "",
              ""),
          false);
    }
    validFrom.setNotNull(rPrev != null);
    validFrom.displayOnGui(this, mainPanel, 0, 1);
    validFrom.requestFocus();
    validUntil =
        new ItemTypeDateTime(
            "VALID_UNTIL",
            (rCurrent.getInvalidFrom() == Long.MAX_VALUE
                ? null
                : new DataTypeDate(rCurrent.getInvalidFrom() - 1)),
            (rCurrent.getInvalidFrom() == Long.MAX_VALUE
                ? null
                : new DataTypeTime(rCurrent.getInvalidFrom() - 1)),
            IItemType.TYPE_PUBLIC,
            "",
            International.getString("gültig bis"));
    validUntil.registerItemListener(this);
    validUntil.setMustBeAfter(validFrom, true);
    if (rNext != null && rNext.getInvalidFrom() != Long.MAX_VALUE) {
      validUntil.setMustBeBefore(
          new ItemTypeDateTime(
              "NEXTRECORD_VALID_UNTIL",
              new DataTypeDate(rNext.getInvalidFrom() - 1),
              new DataTypeTime(rNext.getInvalidFrom() - 1),
              IItemType.TYPE_INTERNAL,
              "",
              ""),
          false);
    }
    validUntil.setNotNull(rNext != null);

    validUntil.displayOnGui(this, mainPanel, 0, 2);

    closeButton.setIcon(getIcon(BaseDialog.IMAGE_ACCEPT));
    closeButton.setIconTextGap(10);
  }