Пример #1
0
    public void endElement(String uri, String localName, String qname) {
      super.endElement(uri, localName, qname);

      if (record != null && localName.equals(DataRecord.ENCODING_RECORD)) {
        // end of record
        if (dataImport.importRecord(record, fieldsInImport)) {
          count++;
        }
        record = null;
        fieldsInImport = null;
      }
      String fieldValue = getFieldValue();
      if (record != null && fieldValue != null) {
        // end of field
        try {
          if (textImport) {
            if (!record.setFromText(fieldName, fieldValue.trim())) {
              dataImport.logImportWarning(
                  record,
                  "Value '"
                      + fieldValue
                      + "' for Field '"
                      + fieldName
                      + "' corrected to '"
                      + record.getAsText(fieldName)
                      + "'");
            }
          } else {
            record.set(fieldName, fieldValue.trim());
          }
          String[] equivFields = record.getEquivalentFields(fieldName);
          for (String f : equivFields) {
            fieldsInImport.add(f);
          }
        } catch (Exception esetvalue) {
          dataImport.logImportWarning(
              record,
              "Cannot set value '"
                  + fieldValue
                  + "' for Field '"
                  + fieldName
                  + "': "
                  + esetvalue.toString());
        }
      }
    }
Пример #2
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++;
 }
Пример #3
0
 protected static Object fieldValue(DapSequence seq, DataRecord record, String field)
     throws DapException {
   DapVariable dapv = seq.findByName(field);
   if (dapv == null) throw new DapException("Unknown variable in filter: " + field);
   if (dapv.getSort() != DapSort.ATOMICVARIABLE)
     throw new DapException("Non-atomic variable in filter: " + field);
   if (dapv.getRank() > 0) throw new DapException("Non-scalar variable in filter: " + field);
   DataAtomic da = (DataAtomic) (record.readfield(field));
   if (da == null) throw new DapException("No such field: " + field);
   return da.read(0);
 }
Пример #4
0
  // TODO: Implement replace / addNew / replaceAll functionality
  public void addDataRecord(DataRecord nRecord, boolean bAddNew, boolean bReplaceAll) {
    // ISISAPI.IsisRecFieldUpdate(spaceHandler, 0, "a" );
    String[] irComponents = nRecord.getIDRecord().split(Pattern.quote(DataRecord.getIDSeperator()));
    String fieldCode = irComponents[0];

    char subfieldCode = ' ';
    if (irComponents.length > 1) {
      subfieldCode = irComponents[1].charAt(0);
    }

    HashMap<Character, String> subfields = null;

    if (this.writeBuffer.containsKey(fieldCode)) {
      subfields = this.writeBuffer.get(fieldCode);
    } else {
      subfields = new HashMap<Character, String>();
    }
    subfields.put(subfieldCode, nRecord.getRecordContent());

    this.writeBuffer.put(fieldCode, subfields);
  }
Пример #5
0
  /**
   * Return a data record for a given IDRecord in the current entry
   *
   * @param IDRecord ID of record to return
   * @return DataRecord with empty content if nothing found
   */
  public DataRecord getDataRecord(String IDRecord) {
    DataRecord rRecord = new DataRecord();
    rRecord.setIDRecord(IDRecord);
    rRecord.setRecordContent("");

    String[] irComponents = IDRecord.split(Pattern.quote(DataRecord.getIDSeperator()));
    String fieldCode = irComponents[0];

    char subfieldCode = ' ';
    if (irComponents.length > 1) {
      subfieldCode = irComponents[1].charAt(0);
    }

    HashMap<Character, String> subfields = null;
    if (this.writeBuffer.containsKey(fieldCode)) {
      subfields = this.writeBuffer.get(fieldCode);

      if (subfields.containsKey(subfieldCode)) {
        rRecord.setRecordContent(subfields.get(subfieldCode));
      }
    }

    return rRecord;
  }
Пример #6
0
 public int runCsvImport() {
   int count = 0;
   try {
     int linecnt = 0;
     String[] header = null;
     ArrayList<String> fieldsInImport = new ArrayList<String>();
     BufferedReader f =
         new BufferedReader(new InputStreamReader(new FileInputStream(filename), encoding));
     String s;
     DataRecord dummyRecord = storageObject.createNewRecord();
     while ((s = f.readLine()) != null) {
       s = s.trim();
       if (s.length() == 0) {
         continue;
       }
       Vector<String> fields = splitFields(s);
       if (fields.size() > 0) {
         if (linecnt == 0) {
           // header
           header = new String[fields.size()];
           for (int i = 0; i < fields.size(); i++) {
             header[i] = fields.get(i);
             if (header[i].startsWith("#") && header[i].endsWith("#") && header.length > 2) {
               header[i] = header[i].substring(1, header[i].length() - 1).trim();
               overrideKeyField = header[i];
             }
             String[] equivFields = dummyRecord.getEquivalentFields(header[i]);
             for (String ef : equivFields) {
               fieldsInImport.add(ef);
             }
           }
         } else {
           // fields
           DataRecord r = storageObject.createNewRecord();
           for (int i = 0; i < header.length; i++) {
             String value = (fields.size() > i ? fields.get(i) : null);
             if (value != null && value.length() > 0) {
               try {
                 if (!r.setFromText(header[i], value.trim())) {
                   logImportWarning(
                       r,
                       "Value '"
                           + value
                           + "' for Field '"
                           + header[i]
                           + "' corrected to '"
                           + r.getAsText(header[i])
                           + "'");
                 }
               } catch (Exception esetvalue) {
                 logImportWarning(
                     r,
                     "Cannot set value '"
                         + value
                         + "' for Field '"
                         + header[i]
                         + "': "
                         + esetvalue.toString());
               }
             }
           }
           if (importRecord(r, fieldsInImport)) {
             count++;
           }
         }
       }
       linecnt++;
     }
     f.close();
   } catch (Exception e) {
     logInfo(e.toString());
     errorCount++;
     Logger.log(e);
     if (Daten.isGuiAppl()) {
       Dialog.error(e.toString());
     }
   }
   return count;
 }
Пример #7
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;
  }
Пример #8
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);
    }
  }
Пример #9
0
 private long getInvalidFrom(DataRecord r) {
   long rv = r.getInvalidFrom();
   return (rv > 0 && rv < Long.MAX_VALUE ? rv : -1);
 }
Пример #10
0
 private long getValidFrom(DataRecord r) {
   long rv = r.getValidFrom();
   return (rv > 0 ? rv : validAt);
 }
Пример #11
0
 private void logImportWarning(DataRecord r, String msg) {
   logInfo("\nWARNING: " + msg + ": " + r.toString());
   warningCount++;
 }
Пример #12
0
  public void nextEntry() {
    // Check if we are in read mode
    if (this.controlStruct != null) {
      String[] nextRecord = new String[1];

      // System.out.println( "Reading Next Record: " + currIndex );

      returnCode = ErrorCodes.ERR_RECPHYSDEL;
      while (returnCode != ErrorCodes.ZERO) {
        returnCode = ISISAPI.IsisRecRead(spaceHandler, 0, currIndex);

        if (returnCode != ErrorCodes.ZERO) System.out.println("\nSkipping Record " + currIndex);

        currIndex++;
      }
      returnCode = ISISAPI.IsisRecDump(spaceHandler, 0, nextRecord, Constants.MAXMFRL);

      // Looks complicated, but we have to do it that way, because in Java we have no chance to
      // convert a String object from a given encoding
      // That's because the ISISAPI fills the string, and in java we can only convert encodings
      // while filling the string object
      byte[] rawData = new byte[nextRecord[0].length()];
      for (int i = 0; i < nextRecord[0].length(); i++) {
        rawData[i] = (byte) nextRecord[0].charAt(i);
      }

      String recordContent = "";
      try {
        recordContent = new String(rawData, this.fileEncoding);
      } catch (Exception e) {
        e.printStackTrace();
      }

      // Add the MFN-Number to the stack
      // TODO Replace IDRecord once custom field adding is supported
      DataRecord nRecord = new DataRecord();
      nRecord.setIDRecord("001");
      nRecord.setRecordContent(String.valueOf(currIndex - 1));
      this.recordsStack.add(nRecord);

      // this.charDecoder.decode( ByteBuffer.wrap( nextRecord[0] ) );

      // String recordContent = new String( nextRecord[0].getBytes( this.fileEncoding ),
      // this.fileEncoding );

      Pattern p = Pattern.compile("<(\\d+)>(.*)</\\1>");
      Matcher m = p.matcher(recordContent);

      // temporary stack used for sorting
      TreeMap<String, ArrayList<ArrayList<DataRecord>>> currRecordsStack =
          new TreeMap<String, ArrayList<ArrayList<DataRecord>>>();

      // parse & add all fields
      while (m.find()) {
        ArrayList<DataRecord> currFieldRecords = new ArrayList<DataRecord>();
        // System.out.println( "Found: " + m.group(1) + " / Content: " + m.group(2) + " / " + (int)
        // m.group(2).charAt(3) );

        /*if( m.group(1).equals( "260$a" ) ) {
            System.out.println( "DEBUG: " + m.group(1) + " Char: '" + m.group(1).charAt(3) + "'" );
        }*/
        // Convert to 3 digit code (required)
        String fieldCode = String.format("%03d", Integer.valueOf(m.group(1)));
        // String fieldCode = m.group(1);

        // Add an entry for the whole record
        nRecord = new DataRecord();
        nRecord.setIDRecord(fieldCode);
        nRecord.setRecordContent(m.group(2));

        // this.recordsStack.add(nRecord);
        currFieldRecords.add(nRecord);

        // Find the sub-fields and add them to the stack
        String[] subFields = m.group(2).split("\\^");
        if (subFields.length > 1) {
          for (int i = 1; i < subFields.length; i++) {
            if (subFields[i].length() <= 0) continue;
            nRecord = new DataRecord();
            nRecord.setIDRecord(fieldCode + DataRecord.getIDSeperator() + subFields[i].charAt(0));
            nRecord.setRecordContent(subFields[i].substring(1));

            // this.recordsStack.add(nRecord);
            currFieldRecords.add(nRecord);
          }
        }
        Collections.sort(currFieldRecords);

        // fetch fitting entry from temporary stack
        ArrayList<ArrayList<DataRecord>> currRecordsStackEntry = currRecordsStack.get(fieldCode);
        if (currRecordsStackEntry == null) {
          currRecordsStackEntry = new ArrayList<ArrayList<DataRecord>>();
        }
        // add the new (sorted) record to the stack
        currRecordsStackEntry.add(currFieldRecords);
        currRecordsStack.put(fieldCode, currRecordsStackEntry);
      }

      // add the temporary stack to the internal recordsStack
      // we use this as the entries are now correctly sorted
      Iterator<Map.Entry<String, ArrayList<ArrayList<DataRecord>>>> crs_It =
          currRecordsStack.entrySet().iterator();
      while (crs_It.hasNext()) {
        Map.Entry<String, ArrayList<ArrayList<DataRecord>>> currEntry = crs_It.next();
        Iterator<ArrayList<DataRecord>> ce_It = currEntry.getValue().iterator();
        while (ce_It.hasNext()) {
          Iterator<DataRecord> dr_it = ce_It.next().iterator();
          while (dr_it.hasNext()) {
            this.recordsStack.add(dr_it.next());
          }
        }
      }

      // Sort collection by fieldID (refer to the compareTo implementation in DataRecord class)
      // Collections.sort( this.recordsStack );
    }
    // Check if we are in write mode
    else if (this.writeBuffer != null) {
      String recordString = "";
      Iterator<Map.Entry<String, HashMap<Character, String>>> wbIt =
          this.writeBuffer.entrySet().iterator();
      while (wbIt.hasNext()) {
        Map.Entry<String, HashMap<Character, String>> currEntry = wbIt.next();
        String fieldCode = currEntry.getKey();
        HashMap<Character, String> subfields = currEntry.getValue();

        String fieldString = "<" + fieldCode + ">";

        Iterator<Map.Entry<Character, String>> sfIt = subfields.entrySet().iterator();
        while (sfIt.hasNext()) {
          Map.Entry<Character, String> currSfEntry = sfIt.next();
          Character subfieldCode = currSfEntry.getKey();
          String content = currSfEntry.getValue();

          if (subfieldCode.equals(' ')) {
            fieldString += content;
            break;
          } else {
            fieldString += "^" + subfieldCode + content;
          }
        }

        fieldString += "</" + fieldCode + ">\n";
        recordString += fieldString;
      }

      returnCode = ISISAPI.IsisRecNew(spaceHandler, 0);
      ISISAPI.IsisRecUpdate(spaceHandler, 0, recordString);
      ISISAPI.IsisRecWrite(spaceHandler, 0);

      this.writeBuffer = new HashMap<String, HashMap<Character, String>>();
    }
  }
  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);
  }