use of org.jivesoftware.xmpp.workgroup.WorkgroupManager in project Openfire by igniterealtime.
the class SearchProvider method executeGet.
public void executeGet(IQ packet, Workgroup workgroup) {
IQ reply = IQ.createResultIQ(packet);
// Retrieve the web chat setting.
String kbURL = workgroup.getProperties().getProperty("kb");
String forumURL = workgroup.getProperties().getProperty("forums");
// Check that the sender of this IQ is an agent
WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
try {
workgroupManager.getAgentManager().getAgent(packet.getFrom());
} catch (AgentNotFoundException e) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
workgroup.send(reply);
return;
}
Element searchSetting = reply.setChildElement("search-settings", "http://jivesoftware.com/protocol/workgroup");
if (forumURL != null) {
searchSetting.addElement("forums").setText(forumURL);
}
if (kbURL != null) {
searchSetting.addElement("kb").setText(kbURL);
}
workgroup.send(reply);
}
use of org.jivesoftware.xmpp.workgroup.WorkgroupManager in project Openfire by igniterealtime.
the class FormManager method loadWebForms.
private void loadWebForms() {
final WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
for (Workgroup workgroup : workgroupManager.getWorkgroups()) {
DbProperties props = workgroup.getProperties();
String context = "jive.webform.wg";
String form = props.getProperty(context);
if (form != null) {
XStream xstream = new XStream();
xstream.setClassLoader(this.getClass().getClassLoader());
try {
Object object = xstream.fromXML(form);
WorkgroupForm workgroupForm = (WorkgroupForm) object;
if (workgroupForm != null) {
addWorkgroupForm(workgroup, workgroupForm);
}
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
} else {
// Create a default Web Form
createGenericForm(workgroup);
}
}
}
use of org.jivesoftware.xmpp.workgroup.WorkgroupManager in project Openfire by igniterealtime.
the class WorkgroupUtils method createWorkgroup.
/**
* Create a new Workgroup.
*
* @param workgroupName the name of the workgroup.
* @param description the description of the workgroup.
* @param agents the agents, in a comma delimited string.
* @return a map of errors (if any)
*/
public static Map<String, String> createWorkgroup(String workgroupName, String description, String agents) {
Map<String, String> errors = new HashMap<String, String>();
// Get a workgroup manager
WorkgroupManager wgManager = WorkgroupManager.getInstance();
if (wgManager == null) {
errors.put("general_error", "The server is down");
return errors;
}
String defaultQueueName = "Default Queue";
// Validate
if (workgroupName == null) {
errors.put("wgName", "");
} else {
try {
workgroupName = workgroupName.trim().toLowerCase();
workgroupName = Stringprep.nodeprep(workgroupName);
} catch (StringprepException se) {
errors.put("wgName", "");
}
}
// do a create if there were no errors
RequestQueue queue = null;
if (errors.size() == 0) {
try {
// Create new workgroup
Workgroup workgroup = wgManager.createWorkgroup(workgroupName);
workgroup.setDescription(description);
// Create a default workgroup queue
queue = workgroup.createRequestQueue(defaultQueueName);
//workgroup.setMaxChats(maxChats);
//workgroup.setMinChats(minChats);
// Make the workgroup ready by default:
workgroup.setStatus(Workgroup.Status.READY);
// Create default messages and images for the new workgroup
ChatSettingsCreator.getInstance().createDefaultSettings(workgroup.getJID());
// Add generic web form
FormManager formManager = FormManager.getInstance();
formManager.createGenericForm(workgroup);
} catch (UserAlreadyExistsException uaee) {
errors.put("exists", "");
} catch (Exception e) {
Log.error(e.getMessage(), e);
errors.put("general", "");
}
}
if (ModelUtil.hasLength(agents)) {
addAgents(queue, agents);
}
return errors;
}
use of org.jivesoftware.xmpp.workgroup.WorkgroupManager in project Openfire by igniterealtime.
the class MetadataProvider method executeGet.
/**
* Executed if #handleGet returned true. This is responsible for sending
* information back to the client.
*
* @param packet the IQ GET packet sent to the server.
* @param workgroup the Workgroup the packet was sent to.
*/
public void executeGet(IQ packet, Workgroup workgroup) {
// Create the generic reply packet.
IQ reply = IQ.createResultIQ(packet);
// Check that the sender of this IQ is an agent. If so
// we throw an item not found exception.
WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
try {
workgroupManager.getAgentManager().getAgent(packet.getFrom());
} catch (AgentNotFoundException e) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
workgroup.send(reply);
return;
}
// If the sender of the packet is an agent, send back name-value pairs
// of all properties files specified.
final Map<String, String> map = new HashMap<String, String>();
final List<String> configFiles = JiveGlobals.getProperties("config");
for (String fileName : configFiles) {
File file = new File(fileName);
if (file.exists()) {
// load properties file.
Properties props = new Properties();
try {
props.load(new FileInputStream(file));
Enumeration<?> properties = props.propertyNames();
while (properties.hasMoreElements()) {
String key = (String) properties.nextElement();
String value = props.getProperty(key);
map.put(key, value);
}
} catch (IOException e) {
Log.error(e.getMessage(), e);
}
}
}
// It is VERY IMPORTANT that you use the same name and namespace as the sending packet. Otherwise,
// it would never be mapped correctly.
final Element genericSetting = reply.setChildElement("generic-metadata", "http://jivesoftware.com/protocol/workgroup");
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
// Create a name-value element
Element element = genericSetting.addElement("entry");
element.addElement("name").setText(key);
element.addElement("value").setText(value);
}
// Send back new packet with requested information.
workgroup.send(reply);
}
use of org.jivesoftware.xmpp.workgroup.WorkgroupManager in project Openfire by igniterealtime.
the class WorkgroupUtils method toggleStatus.
public static void toggleStatus(String workgroupName) {
final WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
Workgroup workgroup;
try {
workgroup = workgroupManager.getWorkgroup(new JID(workgroupName));
} catch (UserNotFoundException e) {
return;
}
Workgroup.Status status = workgroup.getStatus();
if (status == Workgroup.Status.READY) {
workgroup.setStatus(Workgroup.Status.CLOSED);
} else {
workgroup.setStatus(Workgroup.Status.READY);
}
}
Aggregations