use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class InterceptorManager method loadLocalInterceptors.
private void loadLocalInterceptors(String workgroupJID) throws UserNotFoundException {
Workgroup workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupJID));
int interceptorCount = 0;
String iCount = workgroup.getProperties().getProperty("jive.interceptor." + getPropertySuffix() + ".interceptorCount");
if (iCount != null) {
try {
interceptorCount = Integer.parseInt(iCount);
} catch (NumberFormatException nfe) {
/* ignore */
}
}
// Load up all intercpetors.
List<PacketInterceptor> interceptorList = new ArrayList<PacketInterceptor>(interceptorCount);
for (int i = 0; i < interceptorCount; i++) {
try {
String interceptorContext = "jive.interceptor." + getPropertySuffix() + ".interceptor" + i + ".";
String className = workgroup.getProperties().getProperty(interceptorContext + "className");
Class interceptorClass = loadClass(className);
interceptorList.add((PacketInterceptor) interceptorClass.newInstance());
// Load properties.
Map<String, String> interceptorProps = new HashMap<String, String>();
for (String key : getChildrenPropertyNames(interceptorContext + "properties", workgroup.getProperties().getPropertyNames())) {
String value = workgroup.getProperties().getProperty(key);
// Get the bean property name, which is everything after the last '.' in the
// xml property name.
interceptorProps.put(key.substring(key.lastIndexOf(".") + 1), value);
}
// Set properties on the bean
BeanUtils.setProperties(interceptorList.get(i), interceptorProps);
} catch (Exception e) {
Log.error("Error loading local interceptor " + i, e);
}
}
localInterceptors.put(workgroupJID, new CopyOnWriteArrayList<PacketInterceptor>(interceptorList));
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class IQChatSearchHandler method handleIQ.
public void handleIQ(IQ packet) {
try {
// Check that the sender of this IQ is an agent
workgroupManager.getAgentManager().getAgent(packet.getFrom());
Element iq = packet.getChildElement();
IQ reply = IQ.createResultIQ(packet);
if (iq.elements().isEmpty()) {
reply.setChildElement(iq.createCopy());
// Send the search form to the agent
reply.addExtension(searchForm.createCopy());
workgroupManager.send(reply);
} else {
// Send the result of the search to the agent
Date startDate = null;
Date endDate = null;
Collection<Workgroup> workgroups = WorkgroupManager.getInstance().getWorkgroups();
JID agentJID = null;
String queryString = null;
// Get the search parameters from the completed form
DataForm submitedForm = (DataForm) packet.getExtension(DataForm.ELEMENT_NAME, DataForm.NAMESPACE);
for (FormField field : submitedForm.getFields()) {
if ("date/start".equals(field.getVariable())) {
try {
startDate = DataForm.parseDate(field.getValues().get(0));
} catch (ParseException e) {
Log.debug("Invalid startDate " + field.getValues().get(0), e);
}
} else if ("date/end".equals(field.getVariable())) {
try {
endDate = DataForm.parseDate(field.getValues().get(0));
} catch (ParseException e) {
Log.debug("Invalid endDate " + field.getValues().get(0), e);
}
} else if ("workgroups".equals(field.getVariable())) {
if (!field.getValues().isEmpty()) {
workgroups = new ArrayList<Workgroup>();
for (String value : field.getValues()) {
try {
workgroups.add(WorkgroupManager.getInstance().getWorkgroup(new JID(value)));
} catch (UserNotFoundException e) {
Log.debug("Invalid workgroup JID " + value, e);
}
}
} else {
// Search in all the workgroups since no one was specified
workgroups = WorkgroupManager.getInstance().getWorkgroups();
}
} else if ("agent".equals(field.getVariable())) {
agentJID = new JID(field.getValues().get(0));
} else if ("queryString".equals(field.getVariable())) {
queryString = field.getValues().get(0);
}
}
// Build the response
DataForm searchResults = resultForm.createCopy();
// Perform the search
for (Workgroup workgroup : workgroups) {
ChatSearch search = new ChatSearch(workgroup, startDate, endDate, agentJID, queryString);
for (QueryResult result : search.getResults()) {
Map<String, Object> fields = new LinkedHashMap<String, Object>();
fields.put("workgroup", result.getWorkgroup().getJID().toBareJID());
fields.put("sessionID", result.getSessionID());
fields.put("startDate", result.getStartDate());
fields.put("agentJIDs", result.getAgentJIDs());
fields.put("relevance", result.getRelevance());
// Add Metadata
Map<String, String> metadata = getMetadataMap(result.getSessionID());
if (metadata.containsKey("question")) {
fields.put("question", metadata.get("question"));
}
if (metadata.containsKey("email")) {
fields.put("email", metadata.get("email"));
}
if (metadata.containsKey("username")) {
fields.put("username", metadata.get("username"));
}
searchResults.addItemFields(fields);
}
}
reply.setChildElement(iq.getName(), iq.getNamespaceURI());
reply.addExtension(searchResults);
workgroupManager.send(reply);
}
} catch (AgentNotFoundException e) {
IQ reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.not_authorized));
workgroupManager.send(reply);
}
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class JustMarriedPlugin method copyRoster.
private static void copyRoster(User currentUser, User newUser, String currentUserName) {
Roster newRoster = newUser.getRoster();
Roster currentRoster = currentUser.getRoster();
for (RosterItem item : currentRoster.getRosterItems()) {
try {
List<String> groups = item.getGroups();
RosterItem justCreated = newRoster.createRosterItem(item.getJid(), item.getNickname(), groups, true, true);
justCreated.setAskStatus(item.getAskStatus());
justCreated.setRecvStatus(item.getRecvStatus());
justCreated.setSubStatus(item.getSubStatus());
for (Group gr : item.getSharedGroups()) {
justCreated.addSharedGroup(gr);
}
for (Group gr : item.getInvisibleSharedGroups()) {
justCreated.addInvisibleSharedGroup(gr);
}
newRoster.updateRosterItem(justCreated);
addNewUserToOthersRoster(newUser, item, currentUserName);
} catch (UserAlreadyExistsException e) {
Log.error("Could not create roster item for user " + item.getJid(), e);
} catch (SharedGroupException e) {
Log.error("Could not create roster item for user " + item.getJid() + " because it is a contact from a shared group", e);
} catch (UserNotFoundException e) {
Log.error("Could not update Roster item for user " + newUser.getName() + " because it was not properly created.", e);
}
}
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class BaseTransport method cleanUpRoster.
/**
* Cleans a roster of entries related to this transport.
*
* This function will run through the roster of the specified user and clean up any
* entries that share the domain of this transport. Depending on the removeNonPersistent
* option, it will either leave or keep the non-persistent 'contact' entries.
*
* @param jid JID of the user whose roster we want to clean up.
* @param leaveDomain If set, we do not touch the roster item associated with the domain itself.
* @param removeNonPersistent If set, we will also remove non-persistent items.
* @throws UserNotFoundException if the user is not found.
*/
public void cleanUpRoster(JID jid, Boolean leaveDomain, Boolean removeNonPersistent) throws UserNotFoundException {
try {
Roster roster = rosterManager.getRoster(jid.getNode());
// Lets lock down the roster from update notifications if there's an active session.
try {
TransportSession<B> session = sessionManager.getSession(jid.getNode());
session.lockRoster();
} catch (NotFoundException e) {
// No active session? Then no problem.
}
for (RosterItem ri : roster.getRosterItems()) {
if (ri.getJid().getDomain().equals(this.jid.getDomain())) {
if (ri.isShared()) {
// Is a shared item we can't really touch.
continue;
}
if (!removeNonPersistent && ri.getID() == 0) {
// Is a non-persistent roster item.
continue;
}
if (leaveDomain && ri.getJid().getNode() == null) {
// The actual transport domain item.
continue;
}
try {
Log.debug("Cleaning up roster entry " + ri.getJid().toString());
roster.deleteRosterItem(ri.getJid(), false);
} catch (Exception e) {
Log.debug("Error removing roster item: " + ri.toString(), e);
}
}
}
// All done, lets unlock the roster.
try {
TransportSession<B> session = sessionManager.getSession(jid.getNode());
session.unlockRoster();
} catch (NotFoundException e) {
// No active session? Then no problem.
}
} catch (UserNotFoundException e) {
throw new UserNotFoundException("Unable to find roster.");
}
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class BaseTransport method addOrUpdateRosterItem.
/**
* Either updates or adds a JID to a user's roster.
*
* Tries to only edit the roster if it has to.
*
* @param userjid JID of user to have item added to their roster.
* @param contactjid JID to add to roster.
* @param nickname Nickname of item. (can be null)
* @param groups List of group the item is to be placed in. (can be null)
* @param subtype Specific subscription setting.
* @param asktype Specific ask setting.
* @throws UserNotFoundException if userjid not found.
*/
public void addOrUpdateRosterItem(JID userjid, JID contactjid, String nickname, Collection<String> groups, RosterItem.SubType subtype, RosterItem.AskType asktype) throws UserNotFoundException {
Log.debug("add or update roster item " + contactjid + " for: " + userjid);
try {
final Roster roster = rosterManager.getRoster(userjid.getNode());
try {
RosterItem gwitem = roster.getRosterItem(contactjid);
Log.debug("Found existing roster item " + contactjid + " for: " + userjid + ". We will update if required.");
boolean changed = false;
if (gwitem.getSubStatus() != subtype) {
gwitem.setSubStatus(subtype);
changed = true;
}
if (gwitem.getAskStatus() != asktype) {
gwitem.setAskStatus(asktype);
changed = true;
}
// gnickname is not null, nickname is not null, if different, set gnickname to nickname
if ((gwitem.getNickname() != null && nickname == null) || (gwitem.getNickname() == null && nickname != null) || (gwitem.getNickname() != null && nickname != null && !gwitem.getNickname().equals(nickname))) {
gwitem.setNickname(nickname);
changed = true;
}
List<String> curgroups = gwitem.getGroups();
// curgroups is not null, groups is not null, if their sizes are different or curgroups does not contain all of groups, set curgroups to groups
if (((curgroups != null && curgroups.size() > 0) && (groups == null || groups.size() == 0)) || ((curgroups == null || curgroups.size() == 0) && (groups != null && groups.size() > 0)) || (curgroups != null && groups != null && ((curgroups.size() != groups.size()) || !curgroups.containsAll(groups)))) {
try {
gwitem.setGroups((List<String>) (groups != null ? groups : new ArrayList<String>()));
changed = true;
} catch (Exception ee) {
Log.debug("Exception while setting groups for roster item:", ee);
}
}
if (changed) {
Log.debug("Updating existing roster item " + contactjid + " for: " + userjid);
roster.updateRosterItem(gwitem);
} else {
Log.debug("Update of existing roster item " + contactjid + " for: " + userjid + " can be skipped - nothing changed.");
}
} catch (UserNotFoundException e) {
try {
// Create new roster item for the gateway service or legacy contact. Only
// roster items related to the gateway service will be persistent. Roster
// items of legacy users are never persisted in the DB. (unless tweak enabled)
Log.debug("Creating new roster item " + contactjid + " for: " + userjid + ". No existing item was found.");
final RosterItem gwitem = roster.createRosterItem(contactjid, false, contactjid.getNode() == null || JiveGlobals.getBooleanProperty("plugin.gateway.tweak.persistentroster", false));
gwitem.setSubStatus(subtype);
gwitem.setAskStatus(asktype);
gwitem.setNickname(nickname);
try {
gwitem.setGroups((List<String>) groups);
} catch (Exception ee) {
Log.debug("Exception while setting groups for gateway item:", ee);
}
roster.updateRosterItem(gwitem);
} catch (UserAlreadyExistsException ee) {
Log.debug("getRosterItem claims user exists, but couldn't find via getRosterItem?", ee);
} catch (Exception ee) {
Log.debug("Exception while creating roster item:", ee);
}
}
} catch (UserNotFoundException e) {
throw new UserNotFoundException("Could not find roster for " + userjid.toString());
}
}
Aggregations