Package org.nasutekds.server.util

Examples of org.nasutekds.server.util.ChangeRecordEntry


                    Utils.getPath(ldifFile));
    LDIFReader ldifReader =
            new LDIFReader(importCfg);
    ArrayList<ChangeRecordEntry> remainingChanges =
      new ArrayList<ChangeRecordEntry>();
    ChangeRecordEntry o = ldifReader.readChangeRecord(false);
    while (o != null)
    {
      remainingChanges.add(o);
      o = ldifReader.readChangeRecord(false);
    }
View Full Code Here


      reader = new LDIFReader(importConfig);
      writer = new LDIFWriter(exportConfig);

      while (true)
      {
        ChangeRecordEntry changeRecord;
        try
        {
          changeRecord = reader.readChangeRecord(false);
          if (debugEnabled())
          {
            TRACER.debugInfo("Read change record entry " +
                             String.valueOf(changeRecord));
          }
        }
        catch (LDIFException le)
        {
          if (debugEnabled())
          {
            TRACER.debugCaught(DebugLogLevel.ERROR, le);
          }

          errorEncountered = true;
          if (le.canContinueReading())
          {
            Message m =
                 ERR_LDIF_CONNHANDLER_CANNOT_READ_CHANGE_RECORD_NONFATAL.get(
                      le.getMessageObject());
            writer.writeComment(m, 78);
            continue;
          }
          else
          {
            Message m =
                 ERR_LDIF_CONNHANDLER_CANNOT_READ_CHANGE_RECORD_FATAL.get(
                      le.getMessageObject());
            writer.writeComment(m, 78);
            DirectoryConfig.sendAlertNotification(this,
                                 ALERT_TYPE_LDIF_CONNHANDLER_PARSE_ERROR, m);
            break;
          }
        }

        Operation operation = null;
        if (changeRecord == null)
        {
          fullyProcessed = true;
          break;
        }

        if (changeRecord instanceof AddChangeRecordEntry)
        {
          operation = conn.processAdd((AddChangeRecordEntry) changeRecord);
        }
        else if (changeRecord instanceof DeleteChangeRecordEntry)
        {
          operation = conn.processDelete(
               (DeleteChangeRecordEntry) changeRecord);
        }
        else if (changeRecord instanceof ModifyChangeRecordEntry)
        {
          operation = conn.processModify(
               (ModifyChangeRecordEntry) changeRecord);
        }
        else if (changeRecord instanceof ModifyDNChangeRecordEntry)
        {
          operation = conn.processModifyDN(
               (ModifyDNChangeRecordEntry) changeRecord);
        }

        if (operation == null)
        {
          Message m = INFO_LDIF_CONNHANDLER_UNKNOWN_CHANGETYPE.get(
               changeRecord.getChangeOperationType().getLDIFChangeType());
          writer.writeComment(m, 78);
        }
        else
        {
          if (debugEnabled())
View Full Code Here

      throw new IOException(message.toString());
    }

    while (true)
    {
      ChangeRecordEntry entry = null;

      try
      {
        entry = reader.readChangeRecord(modifyOptions.getDefaultAdd());
      } catch (LDIFException le)
      {
        if (debugEnabled())
        {
          TRACER.debugCaught(DebugLogLevel.ERROR, le);
        }
        if (!modifyOptions.continueOnError())
        {
          try
          {
            reader.close();
          }
          catch (Exception e)
          {
            if (debugEnabled())
            {
              TRACER.debugCaught(DebugLogLevel.ERROR, e);
            }
          }

          Message message = ERR_LDIF_FILE_INVALID_LDIF_ENTRY.get(
              le.getLineNumber(), fileName, String.valueOf(le));
          throw new IOException(message.toString());
        }
        else
        {
          Message message = ERR_LDIF_FILE_INVALID_LDIF_ENTRY.get(
                  le.getLineNumber(), fileName, String.valueOf(le));
          err.println(wrapText(message, MAX_LINE_WIDTH));
          continue;
        }
      } catch (Exception e)
      {
        if (debugEnabled())
        {
          TRACER.debugCaught(DebugLogLevel.ERROR, e);
        }

        if (!modifyOptions.continueOnError())
        {
          try
          {
            reader.close();
          }
          catch (Exception e2)
          {
            if (debugEnabled())
            {
              TRACER.debugCaught(DebugLogLevel.ERROR, e2);
            }
          }

          Message message =
              ERR_LDIF_FILE_READ_ERROR.get(fileName, String.valueOf(e));
          throw new IOException(message.toString());
        }
        else
        {
          Message message = ERR_LDIF_FILE_READ_ERROR.get(
                  fileName, String.valueOf(e));
          err.println(wrapText(message, MAX_LINE_WIDTH));
          continue;
        }
      }

      // If the entry is null, then we have reached the end of the config file.
      if(entry == null)
      {
        try
        {
          reader.close();
        }
        catch (Exception e)
        {
          if (debugEnabled())
          {
            TRACER.debugCaught(DebugLogLevel.ERROR, e);
          }
        }

        break;
      }

      ProtocolOp protocolOp = null;
      ByteString asn1OctetStr =
          ByteString.valueOf(entry.getDN().toString());

      String operationType = "";
      switch(entry.getChangeOperationType())
      {
        case ADD:
          operationType = "ADD";
          AddChangeRecordEntry addEntry = (AddChangeRecordEntry) entry;
          List<Attribute> attrs = addEntry.getAttributes();
          ArrayList<RawAttribute> attributes =
              new ArrayList<RawAttribute>(attrs.size());
          for(Attribute a : attrs)
          {
            attributes.add(new LDAPAttribute(a));
          }
          protocolOp = new AddRequestProtocolOp(asn1OctetStr, attributes);
          out.println(INFO_PROCESSING_OPERATION.get(
                  operationType, asn1OctetStr.toString()));
          break;
        case DELETE:
          operationType = "DELETE";
          protocolOp = new DeleteRequestProtocolOp(asn1OctetStr);
          out.println(INFO_PROCESSING_OPERATION.get(
                  operationType, asn1OctetStr.toString()));
          break;
        case MODIFY:
          operationType = "MODIFY";
          ModifyChangeRecordEntry modEntry = (ModifyChangeRecordEntry) entry;
          ArrayList<RawModification> mods =
            new ArrayList<RawModification>(modEntry.getModifications());
          protocolOp = new ModifyRequestProtocolOp(asn1OctetStr, mods);
          out.println(INFO_PROCESSING_OPERATION.get(
                  operationType, asn1OctetStr.toString()));
          break;
        case MODIFY_DN:
          operationType = "MODIFY DN";
          ModifyDNChangeRecordEntry modDNEntry =
            (ModifyDNChangeRecordEntry) entry;
          if(modDNEntry.getNewSuperiorDN() != null)
          {
            protocolOp = new ModifyDNRequestProtocolOp(asn1OctetStr,
                ByteString.valueOf(modDNEntry.getNewRDN().toString()),
                 modDNEntry.deleteOldRDN(),
                ByteString.valueOf(
                          modDNEntry.getNewSuperiorDN().toString()));
          } else
          {
            protocolOp = new ModifyDNRequestProtocolOp(asn1OctetStr,
                ByteString.valueOf(modDNEntry.getNewRDN().toString()),
                 modDNEntry.deleteOldRDN());
          }

          out.println(INFO_PROCESSING_OPERATION.get(
                  operationType, asn1OctetStr.toString()));
          break;
        default:
          break;
      }

      if(!modifyOptions.showOperations())
      {
        LDAPMessage responseMessage = null;
        try
        {
          LDAPMessage message =
               new LDAPMessage(nextMessageID.getAndIncrement(), protocolOp,
                               controls);
          connection.getLDAPWriter().writeMessage(message);
          responseMessage = connection.getLDAPReader().readMessage();
        } catch(ASN1Exception ae)
        {
          if (debugEnabled())
          {
            TRACER.debugCaught(DebugLogLevel.ERROR, ae);
          }
          Message message = INFO_OPERATION_FAILED.get(operationType);
          err.println(wrapText(message, MAX_LINE_WIDTH));
          err.println(wrapText(ae.getMessage(), MAX_LINE_WIDTH));
          if (!modifyOptions.continueOnError())
          {
            String msg = LDAPToolUtils.getMessageForConnectionException(ae);
            throw new IOException(msg, ae);
          }
          return;
        }

        int resultCode = 0;
        Message errorMessage = null;
        DN matchedDN = null;
        List<String> referralURLs = null;
        try
        {
          switch(entry.getChangeOperationType())
          {
            case ADD:
              AddResponseProtocolOp addOp =
                responseMessage.getAddResponseProtocolOp();
              resultCode = addOp.getResultCode();
View Full Code Here

    HashMap<DN,LinkedList<Modification>> modifications =
         new HashMap<DN,LinkedList<Modification>>();

    while (true)
    {
      ChangeRecordEntry changeRecord;
      try
      {
        changeRecord = changeReader.readChangeRecord(false);
      }
      catch (LDIFException le)
      {
        if (le.canContinueReading())
        {
          errorList.add(le.getMessageObject());
          continue;
        }
        else
        {
          throw le;
        }
      }

      if (changeRecord == null)
      {
        break;
      }

      DN changeDN = changeRecord.getDN();
      switch (changeRecord.getChangeOperationType())
      {
        case ADD:
          // The entry must not exist in the add list.
          if (adds.containsKey(changeDN))
          {
            errorList.add(ERR_LDIFMODIFY_CANNOT_ADD_ENTRY_TWICE.get(
                    String.valueOf(changeDN)));
            continue;
          }
          else
          {
            adds.put(changeDN, (AddChangeRecordEntry) changeRecord);
          }
          break;

        case DELETE:
          // The entry must not exist in the add list.  If it exists in the
          // modify list, then remove the changes since we won't need to apply
          // them.
          if (adds.containsKey(changeDN))
          {
            errorList.add(ERR_LDIFMODIFY_CANNOT_DELETE_AFTER_ADD.get(
                    String.valueOf(changeDN)));
            continue;
          }
          else
          {
            modifications.remove(changeDN);
            deletes.put(changeDN, (DeleteChangeRecordEntry) changeRecord);
          }
          break;

        case MODIFY:
          // The entry must not exist in the add or delete lists.
          if (adds.containsKey(changeDN) || deletes.containsKey(changeDN))
          {
            errorList.add(ERR_LDIFMODIFY_CANNOT_MODIFY_ADDED_OR_DELETED.get(
                    String.valueOf(changeDN)));
            continue;
          }
          else
          {
            LinkedList<Modification> mods =
                 modifications.get(changeDN);
            if (mods == null)
            {
              mods = new LinkedList<Modification>();
              modifications.put(changeDN, mods);
            }

            for (RawModification mod :
                 ((ModifyChangeRecordEntry) changeRecord).getModifications())
            {
              try
              {
                mods.add(mod.toModification());
              }
              catch (LDAPException le)
              {
                errorList.add(le.getMessageObject());
                continue;
              }
            }
          }
          break;

        case MODIFY_DN:
          errorList.add(ERR_LDIFMODIFY_MODDN_NOT_SUPPORTED.get(
                  String.valueOf(changeDN)));
          continue;

        default:
          errorList.add(ERR_LDIFMODIFY_UNKNOWN_CHANGETYPE.get(
                  String.valueOf(changeDN),
               String.valueOf(changeRecord.getChangeOperationType())));
          continue;
      }
    }

View Full Code Here

TOP

Related Classes of org.nasutekds.server.util.ChangeRecordEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.