}
@Override
public void addContact(Entity jid, RosterItem rosterItem) throws RosterException {
if (jid == null)
throw new RosterException("jid not provided");
if (rosterItem.getJid() == null)
throw new RosterException("contact jid not provided");
// TODO think about concurrent updates
Entity contactJid = rosterItem.getJid().getBareJID();
Node contactNode = getOrCreateContactNode(jid, contactJid);
try {
setOrRemoveAttribute(contactNode, "name", rosterItem.getName());
String subscriptionTypeValue = rosterItem.getSubscriptionType() == null ? null : rosterItem
.getSubscriptionType().value();
setOrRemoveAttribute(contactNode, "type", subscriptionTypeValue);
String askSubscriptionTypeValue = null;
if (rosterItem.getAskSubscriptionType() != null
&& rosterItem.getAskSubscriptionType() != AskSubscriptionType.NOT_SET) {
askSubscriptionTypeValue = rosterItem.getAskSubscriptionType().value();
}
setOrRemoveAttribute(contactNode, "askType", askSubscriptionTypeValue);
contactNode.save();
logger.info("JCR node created/updated: " + contactNode);
} catch (RepositoryException e) {
throw new RosterException("failed to add contact node to roster for user = " + jid.getFullQualifiedName()
+ " and contact jid = " + rosterItem.getJid().getFullQualifiedName(), e);
}
}