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++; }
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; }
private void logImportWarning(DataRecord r, String msg) { logInfo("\nWARNING: " + msg + ": " + r.toString()); warningCount++; }