public VersionizedDataChangeValidityDialog(
     JDialog parent, int version, DataRecord rCurrent, DataRecord rPrev, DataRecord rNext) {
   super(
       parent,
       International.getString("Gültigkeitszeitraum ändern"),
       International.getStringWithMnemonic("Ändern"));
   this.version = version;
   this.rCurrent = rCurrent;
   this.rPrev = rPrev;
   this.rNext = rNext;
 }
예제 #2
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);
    }
  }
예제 #3
0
  public void run() {
    setRunning(true);
    this.logInfo(International.getString("Importiere Datensätze ..."));
    if (isXmlFile(filename)) {
      runXmlImport();
    } else {
      runCsvImport();
    }
    this.logInfo(
        "\n\n"
            + International.getMessage("{count} Datensätze erfolgreich importiert.", importCount));
    this.logInfo("\n" + International.getMessage("{count} Fehler.", errorCount));
    this.logInfo("\n" + International.getMessage("{count} Warnungen.", warningCount));

    // Start the Audit in the background to find any eventual inconsistencies
    (new Audit(Daten.project)).start();

    setDone();
  }
예제 #4
0
 private void logImportFailed(DataRecord r, String msg, Exception e) {
   if (e != null) {
     Logger.logdebug(e);
   }
   logInfo(
       "\nERROR: "
           + LogString.operationFailed(
               International.getMessage("Import von Datensatz {record}", r.toString()), msg));
   errorCount++;
 }
예제 #5
0
 public String getSuccessfullyDoneMessage() {
   return International.getMessage("{count} Datensätze erfolgreich importiert.", importCount);
 }
예제 #6
0
  private boolean importRecord(DataRecord r, ArrayList<String> fieldsInInport) {
    try {
      if (Logger.isDebugLogging()) {
        Logger.log(Logger.DEBUG, Logger.MSG_DEBUG_DATA, "importing " + r.toString());
      }
      DataRecord[] otherVersions = null;

      if (importMode.equals(IMPORTMODE_ADD)
          && logbookEntryNoHandling != null
          && logbookEntryNoHandling.equals(ENTRYNO_ALWAYS_ADDEND)) {
        // determine new EntryId for logbook
        r.set(keyFields[0], ((Logbook) storageObject).getNextEntryNo());
      }

      if (isLogbook
          && (importMode.equals(IMPORTMODE_ADD) || importMode.equals(IMPORTMODE_ADDUPD))) {
        LogbookRecord lr = ((LogbookRecord) r);
        if (lr.getEntryId() == null
            || !lr.getEntryId().isSet()
            || lr.getEntryId().toString().length() == 0) {
          r.set(keyFields[0], ((Logbook) storageObject).getNextEntryNo());
        }
      }

      DataKey key = r.getKey();
      if (key.getKeyPart1() == null || overrideKeyField != null) {
        // first key field is *not* set, or we're overriding the default key field
        DataKey[] keys = null;
        if (overrideKeyField == null) {
          // -> search for record by QualifiedName
          keys =
              dataAccess.getByFields(
                  r.getQualifiedNameFields(),
                  r.getQualifiedNameValues(r.getQualifiedName()),
                  (versionized ? validAt : -1));
        } else {
          // -> search for record by user-specified key field
          keys =
              dataAccess.getByFields(
                  new String[] {overrideKeyField},
                  new String[] {r.getAsString(overrideKeyField)},
                  (versionized ? validAt : -1));
        }
        if (keys != null && keys.length > 0) {
          for (int i = 0; i < keyFields.length; i++) {
            if (!keyFields[i].equals(DataRecord.VALIDFROM)) {
              r.set(keyFields[i], keys[0].getKeyPart(i));
            }
          }
        } else {
          for (int i = 0; i < keyFields.length; i++) {
            if (!keyFields[i].equals(DataRecord.VALIDFROM) && r.get(keyFields[i]) == null) {
              if (dataAccess.getMetaData().getFieldType(keyFields[i]) == IDataAccess.DATA_UUID) {
                r.set(keyFields[i], UUID.randomUUID());
              } else {
                logImportFailed(r, "KeyField(s) not set", null);
                return false;
              }
            }
          }
        }
      }
      key = r.getKey();

      if (versionized) {
        otherVersions = dataAccess.getValidAny(key);
      } else {
        DataRecord r1 = dataAccess.get(key);
        otherVersions = (r1 != null ? new DataRecord[] {r1} : null);
      }

      if (importMode.equals(IMPORTMODE_ADD)
          && otherVersions != null
          && otherVersions.length > 0
          && logbookEntryNoHandling != null
          && logbookEntryNoHandling.equals(ENTRYNO_DUPLICATE_ADDEND)) {
        r.set(keyFields[0], ((Logbook) storageObject).getNextEntryNo());
        otherVersions = null;
      }

      if (importMode.equals(IMPORTMODE_ADD)) {
        if (otherVersions != null && otherVersions.length > 0) {
          logImportFailed(r, International.getString("Datensatz existiert bereits"), null);
          return false;
        } else {
          addRecord(r);
          return true;
        }
      }
      if (importMode.equals(IMPORTMODE_UPD)) {
        if (otherVersions == null || otherVersions.length == 0) {
          logImportFailed(r, International.getString("Datensatz nicht gefunden"), null);
          return false;
        } else {
          updateRecord(r, fieldsInInport);
          return true;
        }
      }
      if (importMode.equals(IMPORTMODE_ADDUPD)) {
        if (otherVersions != null && otherVersions.length > 0) {
          updateRecord(r, fieldsInInport);
        } else {
          addRecord(r);
        }
        return true;
      }
    } catch (Exception e) {
      logImportFailed(r, e.getMessage(), e);
    }
    return false;
  }
  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);
  }