Java getFormula() not returning correct value

Hi There

I am having trouble using getFormula() in the domino java package. Below is the code i am using. It runs ok but always returns

@All

but i know that the database has a replication formula on it, can anyone help me out; point me in a direction, thanks heaps

import lotus.domino.*;

import javax.swing.*;

public class JavaAgent extends AgentBase {

public void NotesMain() {

try {

	Session session = getSession();

	AgentContext agentContext = session.getAgentContext();



  	Database db = agentContext.getCurrentDatabase();

  	Replication replication = db.getReplicationInfo();

	if (db.isOpen()) {

		ReplicationEntry re = replication.getEntry("-", "-", false);

  		if (re != null) {

      		System.out.println(re.getFormula());

  		}

    		else

     		System.out.println("No entry for ");

     	}



} catch(Exception e) {

		e.printStackTrace();

}

}

}

Subject: java getFormula() not returning correct value

Alan -A couple of suggestions:

Try using the destination machine name as the destination instead of the “-” entry. This would be your name if, for instance, the database is a local replica on your laptop. See example below.

There could be more than one replication note in the database if, for instance, the source database resides on more than one server. You could still accommodate this scenario by getting a complete list of server names from all replication notes and using them as a source server name to get a ReplicationEntry.

public class JavaAgent extends AgentBase {

private static final String SRC_SERVER_ANY = “-”;

public void NotesMain() {

Session session = null;

try {

session = super.getSession();

AgentContext agentContext = session.getAgentContext();

String astrReplicaID = agentContext.getCurrentDatabase().getReplicaID();

DbDirectory dbDir = session.getDbDirectory(“”);

Database db = dbDir.openDatabaseByReplicaID(astrReplicaID); // try to open a local replica

String astrDestName = session.getUserName();

if (db != null && db.isOpen()) {

Replication replication = db.getReplicationInfo();

ReplicationEntry re = replication.getEntry(JavaAgent.SRC_SERVER_ANY, astrDestName, false);

if (re != null) {

System.out.println("Formula is: " + re.getFormula());

} else {

System.out.println(“Entry not found w/ destination of "” + astrDestName + “" . . .”);

}

} else {

System.out.println(“Failed to open a local replica of the database . . .”);

}

} catch (Throwable th) {

th.printStackTrace();

} finally {

try {

session.recycle();

} catch (Exception e) {

}

}

}

}

Subject: RE: java getFormula() not returning correct value

Thanks Dallas

The first one worked good!

But when i changed the source server getEntry() fails returning null, any ideas??

Not sure if its failing becuase its thinks there is no replica on the server or someother strange reason

Thanks again

Subject: RE: java getFormula() not returning correct value

It’s just failing because there is no replication note for that server . . . no big deal. If you want to see if there are any server-specific replication notes in the database, you could:build a NoteCollection,

select only replication notes, and

run through the NoteCollection adding the value of the $ReplSrcServers item to a HashSet.

This will give you a unique collection of server names for which you can access replication notes. If you end up with only the “any server” entry (i.e., “-”), there’s no need to check for ReplicationEntries for any other servers.

dgg

Subject: RE: java getFormula() not returning correct value

Thanks again Dallas

I created the NoteCollection and ran through all the $ReplSrcServers and they all come out as “-” which i know is incorrect as two out of my nine test servers have a replication formula on them.

I outputed the NoteCollection to a DXL file and the third note shows the correct replication formula but when i try to read that field it returns a empty string

See below, I tried to get information for the $ReplFormula item in many ways but they always return empty string. I even tried to see if this was a multi value item but it was not.

Thanks again

String id = nc.getFirstNoteID();

if (nc.getCount() > 0)

{

int i = 1;

while (id.length() > 0)

{

  System.out.println("Note Number: " + i);

  i++;

  Document doc = db.getDocumentByID(id);

  Vector items = doc.getItems();

  for (int j=0; j<items.size(); j++) 

  {

     Item item = (Item)items.elementAt(j);

     System.out.println("\t" + item.getName() + " = \"" + item.getValueString() + "\"");

  if(item.getType() == Item.FORMULA)

  {

      //do stuff to try and get a value of the item

  }

}

id = nc.getNextNoteID(id);

}

This is part of the output of the code

Notes Number: 3

$TITLE = "CN=shb1ln08/OU=a/O=qdot/C=au"



$UpdatedBy = "CN=Alan D Ryan/OU=cp1/O=qdot/C=au"



$ReplVersion = "2"



$ReplSrcServers = "-"



$ReplClassMasks = "2047"



$ReplFormula = ""



$ReplForm = "0"



$ReplView = ""



$ReplPrivateFolder = ""



$ReplFields = ""

This is the third entry in the DXL file

20070209T160606,97+10

20070323T111646,12+10

20070323T111646,11+10

20070323T111646,11+10

20070209T160606,98+10

CN=Alan D Ryan/OU=cp1/O=qdot/C=au

CN=shb1ln08/OU=a/O=qdot/C=au

2

-

2047

form != “Draft” & form != “Document” & form != “Email” & form != “MyFile” & form != “image” & form != “Email Form” & form != “ForFiling”

0

Subject: RE: java getFormula() not returning correct value

My suggestion was really just to use the NoteCollection to obtain a unique collection (i.e., a Set) of server names to use in conjunction with the code you had posted.Set asetServers = new HashSet();

String id = nc.getFirstNoteID();

int iNoteCount = nc.getCount();

if (iNoteCount > 0) {

for (int i = 1; i <= iNoteCount; i++);

Document doc = db.getDocumentByID(id);

String astrServerName = doc.getItemValueString(“$ReplSrcServers”);

System.out.println("Note " + i + ": Server is " + astrServerName);

asetServers.add(astrServerName);

doc.recycle();

}

id = nc.getNextNoteID(id);

}

Then loop through the Set to access a ReplicationEntry for each server so that you can read its replication formula. Does that make sense?

Although I would expect it might be a bit slower, you could certainly export the NoteCollection and parse it to get what you need (as evidenced by the XML you posted). But I don’t believe you’ll be able to get the formula directly from the design note itself because it’s compiled.

dgg