Hi I am getting a null pointer exception when running a custom replacingHandler. I will post the code that is using the replacer and the ReplaceHandler code
Here is the handler
public class ReplaceWithBeneTableHandler implements IReplacingCallback {
public PartyRestService partyRestService;
@Override
public int replacing(ReplacingArgs e) throws Exception {
Node currentNode = e.getMatchNode();
DocumentBuilder builder = new DocumentBuilder((Document) e.getMatchNode().getDocument());
builder.moveTo(currentNode);
builder.startTable();
String agreementNumber = e.getReplacement();
List<PartyDto> parties = partyRestService.executePartyGet(agreementNumber);
builder.startTable();
for (PartyDto party : parties) {
if (party.getPartyRoleCode().contains("PRIM_BENE")) {
builder.insertCell();
if (party.getFirstName() != null && party.getLastName() != null) {
builder.write(party.getFirstName() + party.getLastName());
} else if (party.getFirstName() == null && party.getLastName() != null) {
builder.write(party.getLastName());
} else if (party.getFirstName() != null && party.getLastName() == null) {
builder.write(party.getFirstName());
}
builder.insertCell();
builder.write(party.getBeneficiarySplitRate().toString());
builder.endRow();
}
}
builder.endTable();
builder.startTable();
for (PartyDto party : parties) {
if (party.getPartyRoleCode().contains("CON_BENE")) {
builder.insertCell();
if (party.getFirstName() != null && party.getLastName() != null) {
builder.write(party.getFirstName() + party.getLastName());
} else if (party.getFirstName() == null && party.getLastName() != null) {
builder.write(party.getLastName());
} else if (party.getFirstName() != null && party.getLastName() == null) {
builder.write(party.getFirstName());
}
builder.insertCell();
builder.write(party.getBeneficiarySplitRate().toString());
builder.endRow();
}
}
builder.endTable();
currentNode.remove();
return ReplaceAction.SKIP;
}
}
Here is where the code is being called to replace.
public Document replaceBeneTableTags(Document preDoc, String agreementNumber) {
Document updatedDoc = preDoc;
FindReplaceOptions beneTableOpts = new FindReplaceOptions();
beneTableOpts.setReplacingCallback(new ReplaceWithBeneTableHandler());
beneTableOpts.setDirection(FindReplaceDirection.BACKWARD);
try {
if (updatedDoc.getText().contains("+BENE_TABLE+")) {
updatedDoc.getRange().replace("+BENE_TABLE+", agreementNumber, beneTableOpts);
}
} catch (Exception e) {
System.out.println(e);
}
return updatedDoc;
}
Any help would be appreciated. I get the null pointer at the
List<PartyDto> parties = partyRestService.executePartyGet(agreementNumber);
line