Trouble with DxlImporter.DXLIMPORTOPTION_UPDATE_ELSE_CREATE

Hi

I’m trying to import some DXL into a notes database using a java agent. Basically I have a database that contains documents. I export the documents to a file and then want to import them. I want to be able to change the contents in the file and re-import the dxl data with the changes

The trouble is the DxlImporter.DXLIMPORTOPTION_UPDATE_ELSE_CREATE is not working as exptected. When running the agent on my client I keep on getting the following stack trace:

NotesException: DXL importer operation failed

at lotus.domino.local.DxlImporter.NimportDxlString(Native Method)

at lotus.domino.local.DxlImporter.importDxl(Unknown Source)

at JavaAgent.NotesMain(JavaAgent.java:36)

at lotus.domino.AgentBase.runNotes(Unknown Source)

at lotus.domino.NotesThread.run(NotesThread.java:208)

Not much to go on as you can see. When I remove the DXLIMPORTOPTION_UPDATE_ELSE_CREATE code the agent works fine, but creates a new document in the database which isn’t what I wanted. I’ve tried to fiddle around with the DXL and have more or less removed all of the exported nodes, but still it won’t import with the flag set. Am I missing something here?

This is the agent I’ve created:

Session session = getSession();

AgentContext agentContext = session.getAgentContext();

Database db = agentContext.getCurrentDatabase();

FileInputStream input = new FileInputStream(“c:/dxl.xml”);

BufferedReader reader = new BufferedReader(new InputStreamReader(input));

StringBuffer buffer = new StringBuffer();

String line;

while ((line = reader.readLine()) != null) {

buffer.append(line);

}

reader.close();

input.close();

DxlImporter importer = session.createDxlImporter();

importer.setDocumentImportOption(DxlImporter.DxlImporter.DXLIMPORTOPTION_UPDATE_ELSE_CREATE);

importer.importDxl(buffer.toString(), db);

session.recycle();

Any ideas?

Subject: Trouble with DxlImporter.DXLIMPORTOPTION_UPDATE_ELSE_CREATE

Similar-sounding problem (and fix) described here

Subject: RE: Trouble with DxlImporter.DXLIMPORTOPTION_UPDATE_ELSE_CREATE

Well I tried to replace the DXLIMPORTOPTION_UPDATE_ELSE_IGNORE with DXLIMPORTOPTION_REPLACE_ELSE_CREATE, but nothing changed. Still got the same error.

Subject: Trouble with DxlImporter.DXLIMPORTOPTION_UPDATE_ELSE_CREATE

After an error getLog() should tell you more about what happened. Update requires a matching replicaid and unid in the DXL – perhaps you removed too much.

Subject: RE: Trouble with DxlImporter.DXLIMPORTOPTION_UPDATE_ELSE_CREATE

What is too much? Surly if you remove the repid and unid then a new document should be added to the database?

Here’s an example:

<?xml version="1.0" encoding="UTF-8"?>
<document form='Person'>

    <item name='Name'><text>John Doe</text></item>

</document>

Subject: RE: Trouble with DxlImporter.DXLIMPORTOPTION_UPDATE_ELSE_CREATE

If you post an example of the DXL that you are really importing to update the document, and also what you see in the log when it fails, I will try to reproduce the error.

Subject: RE: Trouble with DxlImporter.DXLIMPORTOPTION_UPDATE_ELSE_CREATE

The dxl I am trying to import is exactly the same dxl created from exporting with DxlExporter. Nothing special as I’m only testing the technology.

It wasn’t until now that I understood what log you were refering to. Here’s the log message I receive.

<?xml version='1.0'?>Could not replace/update a matching 'document' note

because the ReplicaRequiredForReplaceUpdate property is true and the DXL and database are not replicas

DXL importer operation failed

Looking at the setReplicaRequiredForReplaceOrUpdate() method it seems it only affects the logging. So how can you get around this?

Subject: RE: Trouble with DxlImporter.DXLIMPORTOPTION_UPDATE_ELSE_CREATE

According to the message you get in the log, the replicaid attribute in your DXL is different from the real replica ID of the database you are importing it into. Have you verified this by looking at the database properties and in the DXL file? (In the database properties there is a colon in the middle, but in the DXL attribute there must not be.)Also, you referred to repid earlier, instead of replicaid – could that be the problem?

Subject: RE: Trouble with DxlImporter.DXLIMPORTOPTION_UPDATE_ELSE_CREATE

Yes, the replica id’s are identical apart from the seperating colon not used in the DXL attributes. The mention of repid instead of replicaid was a mistake on my part. There is no repid attribute, just me being quick and dirty.

This is a rather strange error message. It states that it won’t perform an replace/update because the replica ids are the same yet the documentation (DocumentImportOption) says:

For purposes of replacement, two documents match if:

  • The replica ID of the output database matches the replica ID of the incoming DXL.

  • The universal IDs of the two documents match.

In my case the DXL is created from the same database that I’m trying to import back into. The replica id and the document’s universal id’s are identical to the original. Just what am I missing? Has anyone got this working?

I read somewhere else that only the replicator task is allowed to “replicate” so just how are you supposed to update a document from DXL?

Subject: RE: Trouble with DxlImporter.DXLIMPORTOPTION_UPDATE_ELSE_CREATE

It works when I do it. For example, I can export a document to an XML file, manually change an item value, and reimport the file, updating the document with the new value.When the error message says “the DXL and database are not replicas”, it means that it thinks the replica IDs do not match.

If you think it might help, I will try to reproduce the problem by importing your DXL. Post it here, or send it to me using the address in my profile.

Subject: Trouble with DxlImporter.DXLIMPORTOPTION_UPDATE_ELSE_CREATE

I think I know what this is. I ran into the same thing while putting together a demo for Lotusphere, and I have to 'fess up: it was a bug that I fixed locally to fix my demo, but hasn’t been checked into a real release yet (it is on my todo list).

If it is the same problem, it is as follows.

A document with a unid attribute will be processed correctly, but a document with no or no unid attribute will cause an error in UPDATE_ELSE_CREATE mode. It is a bug in the DXL Importer. So a simple document like this one posted earlier is enough to cause the problem:

<?xml version="1.0" encoding="UTF-8"?>
<document form='Person'>

    <item name='Name'><text>John Doe</text></item>

</document>

Here is what I think should be a valid workaround but I haven’t explicitly tested it.

<?xml version="1.0" encoding="UTF-8"?>
<document form='Person'>

    <noteinfo unid="77777777777777777777777777777777"/>

    <item name='Name'><text>John Doe</text></item>

</document>

What the workaround does is specify an unid that is syntactically valid but is a dummy value that is pretty much guaranteed not to match an existing document in the db. So it should cause a new document to be created. I believe that this dummy value could be used any number of times in the same DXL and would never be construed as the same document because it would never match an existing document in the db. If anyone tries this workaround please post here whether it worked.