MultiUserChat get chat room user? - asmack

I am working on ASmack.
Is it workable to get chat room user list using asmack?
http://www.igniterealtime.org/builds/smack/docs/latest/documentation/extensions/muc.html
This list have not shown. Please give me some idea.

Which list?
You can only call getOccupants() if you are an occupant of the MUC or, in other words, if have joined the MUC.

getOccupants() doesnt work for me. So you can try the code below:
try {
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(xmppConn);
DiscoverItems discoItems = discoManager.discoverItems(roomJID);
Iterator<DiscoverItems.Item> occupants = discoItems.getItems();
} catch (XMPPException e) {
e.printStackTrace();
}

i was able to get the List Of user's available in the Chat Room Of XMPP by the Simple Following Method passing the Parameter as MultiUserChat Object.
public static List<String> findMulitUser(MultiUserChat muc) {
List<String> listUser = new ArrayList<String>();
Iterator<String> it = muc.getOccupants();
// Traverse the chat room name
while (it.hasNext()) {
// Chat room members name
String name = StringUtils.parseResource(it.next());
System.out.println("Name Of Occupants------>" + name);
listUser.add(name);
}
return listUser;
}

Related

How to call some Controller's method and pass a parameters from a query string

in my app I've generated an url like this:
http://www.test.com/?mail=test%40gmail.ba&code=71147ff9-87ae-41fc-b53f-5ecb3dbe5a01
The way how I generated Url is posted below:
private string GenerateUrl(string longUrl, string email, string confirmCode)
{
try
{
// By the way this is not working (Home/MailConfirmed) I'm getting message
// Requested URL: /Home/MailConfirmed
// The resource cannot be found.
string url = longUrl + "/Home/MailConfirmed";
var uriBuilder = new UriBuilder(url);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
query["mail"] = email;
query["code"] = confirmCode;
uriBuilder.Query = query.ToString();
uriBuilder.Port = -1;
url = uriBuilder.ToString();
return url;
}
catch (Exception ex)
{
return "Error happened: " + ex.Message;
}
}
In longUrl I'm passing www.test.com, in email I'm passing
test#gmail.com and so on..
There are informations about my website:
www.test.com
mail:test#gmail.com
confirmcode:71147ff9-87ae-41fc-b53f-5ecb3dbe5a01
And in my HomeController.cs there is a method which should took parameters out of query string - url and pass it to the method which should activate users account by getting user by mail (mail is unique) and comparing this guid with guid in database. So I'm wondering how can I call this method?
So my method looks like this:
public JsonResult MailConfirmed(string mail, string confirmCode)
{
try
{
// Here I will get user and update it in DB
return Json("success", JsonRequestBehavior.AllowGet);
}
catch(Exception ex)
{
return Json("fail", JsonRequestBehavior.AllowGet);
}
}
So my question is how is possiblee for user to click on following link and to get an my method invoked.. ?
Thanks a lot
Cheers
In order to navigate to your MailConfirmed(), your url would need to be
http://www.test.com/Home/MailConfirmed?mail=test%40gmail.ba&confirmcode=71147ff9-87ae-41fc-b53f-5ecb3dbe5a01
Note the segments for the controller and action names, and code=xxx should be confirmcode=xxx to match the name of the parameter in the method.
You can simplify your code (and delete your GenerateUrl() method) by making use of UrlHelper methods to generate the url).
To generate the above url, all you need in your controller method is
string url = Url.Action("MailConfirmed", "Home",
new { mail = email, confirmcode = confirmCode },
this.Request.Url.Scheme);

abas-ERP: Copy TN field into another TN field with edp/epi

I want to create an invoice and fill the field pftext (TN2) with the content of another TN2 field called ytdescription.
My problem is, that I always have the path of my textfield in pftext but not the content of my textfield.
1st try of edp header:
kunde;artex;pftext;mge
'M|ytkdnr';'M|ytartnr';'M|ytdescription';'M|ytmge'
2nd try:
kunde;artex;*pftext;mge;
'M|ytkdnr';'M|ytartnr';'M|ytdescription';'M|ytmge'
Of course I could create a T254 field and store the content of M|ytdescription in the new field, but then I am stuck to max 3000 chars for the content.
Many other tries followed but with no success :-(
Any help is highly appreciated!
I Don't know the options to do this per EDP, but there is a solution to do this per AJO:
public int run(DbContext dbContext, String[] args) {
/*
* Get the object to copy data from, in this case a customer with idno 70001
*/
String idno = "70001";
SelectionBuilder<Customer> selectionBuilder = SelectionBuilder.create(Customer.class);
selectionBuilder.add(Conditions.eq(Customer.META.idno, idno));
Customer customer = QueryUtil.getFirst(dbContext, selectionBuilder.build());
VendorEditor vendorEditor = null;
// Read the original content to a StringWriter
StringWriter originalFreeText = new StringWriter();
try {
customer.getFreeText(originalFreeText);
// Create a new object to write the values to. In example a Supplier
vendorEditor = dbContext.newObject(VendorEditor.class);
vendorEditor.setSwd("Searchword");
vendorEditor.setAddr("Vendor Name");
if (!originalFreeText.toString().equals("")) {
vendorEditor.setFreeText(new StringReader(originalFreeText.toString()));
}
vendorEditor.commit();
} catch (IOException e) {
dbContext.out().println(e.getMessage());
} finally {
if (vendorEditor != null) {
if (vendorEditor.active()) {
vendorEditor.abort();
}
}
}
return 0;
}

How to do WaitAll with Akka.Net?

I have a hierarchy of actors in Akka.Net and am wondering whether I've chosen the right way to do something, or if there are better/simpler ways to achieve what I want.
My specific example is that I'm constructing a User actor in response to a user logging into the system, and when constructing this actor there are two pieces of data I need in order to complete the construction of the actor.
If this were regular .NET code I might have something like the following...
public Task<User> LoadUserAsync (string username)
{
IProfileService profileService = ...;
IMessageService messageService = ...;
var loadProfileTask = profileService.GetUserProfileAsync(username);
var loadMessagesTask = messageService.GetMessagesAsync(username);
Task.WaitAll(loadProfileTask, loadMessagesTask);
// Now construct the user from the result of both tasks
var user = new User
{
Profile = loadProfileTask.Result,
Messages = loadMessagesTask.Result
}
return Task.FromResult(user);
}
Here I use WaitAll to wait for the subordinate tasks to complete, and let them run concurrently.
My question is - if I wanted to do the same in Akka.Net, would the following be the most regular way to do this? Pictorially I've created the following...
When I create my User actor, I then construct a (temporary) User Loader Actor, whose job it is to get the full user details by calling to the Profile actor and the Messages actor. The leaf actors that get the data are as follows...
public class UserProfileLoader : ReceiveActor
{
public UserProfileLoader()
{
Receive<LoadUserRequest>(msg =>
{
// Load the user profile from somewhere
var profile = new UserProfile();
// And respond to the Sender
Sender.Tell(profile);
Self.Tell(PoisonPill.Instance);
});
}
}
public class UserMessagesLoader : ReceiveActor
{
public UserMessagesLoader()
{
Receive<LoadUserRequest>(msg =>
{
// Load the messages from somewhere
var messages = new List<Message>();
// And respond to the Sender
Sender.Tell(messages);
Self.Tell(PoisonPill.Instance);
});
}
}
It doesn't really matter where they get the data from for this discussion, but both simply respond to a request by returning some data.
Then I have the actor that coordinates the two data gathering actors...
public class UserLoaderActor : ReceiveActor
{
public UserLoaderActor()
{
Receive<LoadUserRequest>(msg => LoadProfileAndMessages(msg));
Receive<UserProfile>(msg =>
{
_profile = msg;
FinishIfPossible();
});
Receive<List<Message>>(msg =>
{
_messages = msg;
FinishIfPossible();
});
}
private void LoadProfileAndMessages(LoadUserRequest msg)
{
_originalSender = Sender;
Context.ActorOf<UserProfileLoader>().Tell(msg);
Context.ActorOf<UserMessagesLoader>().Tell(msg);
}
private void FinishIfPossible()
{
if ((null != _messages) && (null != _profile))
{
_originalSender.Tell(new LoadUserResponse(_profile, _messages));
Self.Tell(PoisonPill.Instance);
}
}
private IActorRef _originalSender;
private UserProfile _profile;
private List<Message> _messages;
}
This just creates the two subordinate actors, sends them a message to get cracking, and then waits for both to respond before sending back all the data that's been gathered to the original requestor.
So, does this seem like a reasonable way to coordinate two disparate responses, in order to combine them? Is there an easier way to do this than craft it up myself?
Thanks in advance for your responses!
Thanks folks, so I've now simplified the actor significantly into the following, based on both Roger and Jeff's suggestions...
public class TaskBasedUserLoader : ReceiveActor
{
public TaskBasedUserLoader()
{
Receive<LoadUserRequest>(msg => LoadProfileAndMessages(msg));
}
private void LoadProfileAndMessages(LoadUserRequest msg)
{
var originalSender = Sender;
var loadPreferences = this.LoadProfile(msg.UserId);
var loadMessages = this.LoadMessages(msg.UserId);
Task.WhenAll(loadPreferences, loadMessages)
.ContinueWith(t => new UserLoadedResponse(loadPreferences.Result, loadMessages.Result),
TaskContinuationOptions.AttachedToParent & TaskContinuationOptions.ExecuteSynchronously)
.PipeTo(originalSender);
}
private Task<UserProfile> LoadProfile(string userId)
{
return Task.FromResult(new UserProfile { UserId = userId });
}
private Task<List<Message>> LoadMessages(string userId)
{
return Task.FromResult(new List<Message>());
}
}
The LoadProfile and LoadMessages methods will ultimately call a repository to get the data, but for now I have a succinct way to do what I wanted.
Thanks again!
IMHO that's a valid process, as you fork action and then join it.
BTW you could use this.Self.GracefulStop(new TimeSpan(1)); instead of sending poison pill.
You could use a combination of Ask, WhenAll and PipeTo:
var task1 = actor1.Ask<Result1>(request1);
var task2 = actor2.Ask<Result2>(request2);
Task.WhenAll(task1, task2)
.ContinueWith(_ => new Result3(task1.Result, task2.Result))
.PipeTo(Self);
...
Receive<Result3>(msg => { ... });

Hippo CMS 7.9 Facets

I'm trying to implement facets and also create a catalog component.
My original approach was to use the:
org.onehippo.cms7.essentials.components.EssentialsContentComponent
However it doesn't seem like it's available for 7.9.
My next approach is to extend the PresentationList Component however the documentation isn't that clear of creating the values for the main and sub categories.
I would like to use this code for my component I'm just not sure once again where to place my Category (values).
try {
HstRequestContext requestContext = request.getRequestContext();
HippoBean scope = requestContext.getSiteContentBaseBean();
PresentationPageableListInfo info = getComponentParametersInfo(request);
LandingPage presentationPage = null;
String resolvedContentPath = PathUtils.normalizePath(requestContext
.getResolvedSiteMapItem().getRelativeContentPath());
createAndExecuteSearch(request, info, scope, (BaseFilter) null,
null, resolvedContentPath);
if (scope instanceof HippoFolderBean) {
presentationPage = getFirstLandingPageInFolder(request,
(HippoFolderBean) scope);
}
if (presentationPage != null) {
request.setAttribute("document", presentationPage);
}
if (request.getPathInfo().toLowerCase().contains("facet/")) {
request.setAttribute("faceted", true);
}
} catch (Exception e) {
throw new HstComponentException("Failed to query presentations.", e);
}
have you tried these pages :
http://www.onehippo.org/7_9/library/concepts/faceted-navigation/faceted-navigation-configuration.html
http://www.onehippo.org/7_9/library/setup/hst-components/facets-component.html

Combining two different jTables and adding button into jTable

I try to do for forum using java swing. Here are my codes for table :
public void SetUpJTable() {
DefaultTableModel tableModel = (DefaultTableModel) jTable.getModel();
String[] data = new String[4];
db.setUp("IT Innovation Project");
String sql = "Select topic_title,topic_description,topic_by from forumTopics WHERE topic_id = "
+ topicId + "";
ResultSet resultSet = null;
resultSet = db.readRequest(sql);
try {
while (resultSet.next()) {
data[0] = resultSet.getString("topic_title");
data[1] = resultSet.getString("topic_description");
data[2] = resultSet.getString("topic_by");
tableModel.addRow(data);
}
resultSet.close();
} catch (Exception e) {
System.out.println(e);
}
}
I set up this table to retrieve the topic details which user select certain thread from main page. And I set up another table to store for the replies by users. Here is it :
public void SetUpJTableComment() {
DefaultTableModel tableModel1 = (DefaultTableModel) jTableComment
.getModel();
String[] data = new String[3];
db.setUp("IT Innovation Project");
String sql = "Select reply_content,reply_by from forumReplies WHERE reply_topic = "
+ topicId + "";
ResultSet resultSet = null;
resultSet = db.readRequest(sql);
try {
while (resultSet.next()) {
data[0] = resultSet.getString("reply_content");
data[1] = resultSet.getString("reply_by");
tableModel1.addRow(data);
}
resultSet.close();
} catch (Exception e) {
System.out.println(e);
}
}
And this is how I set up the table :
private JTable getJTableComment() {
String header[] = { "Comment", "Reply By" };
if (jTableComment == null) {
jTableComment = new JTable() {
public boolean isCellEditable(int nRow, int nCol) {
return false;
}
};
}
DefaultTableModel tableModel1 = (DefaultTableModel) jTableComment
.getModel();
tableModel1.setColumnIdentifiers(header);
jTableComment.getColumnModel().getColumn(0).setMinWidth(700);
jTableComment.getColumnModel().getColumn(0).setMaxWidth(800);
jTableComment.getColumnModel().getColumn(1).setMinWidth(97);
jTableComment.getColumnModel().getColumn(1).setMaxWidth(100);
jTableComment.getTableHeader().setFont(
new Font("Dialog", Font.PLAIN, 20));
jTableComment.getTableHeader().setForeground(Color.white);
jTableComment.getTableHeader().setBackground(new Color(102, 102, 102));
jTableComment.setRowHeight(50);
jTableComment.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
jTableComment.setFont(new Font("Dialog", Font.PLAIN, 18));
return jTableComment;
}
It works perfectly with two separating tables. I wonder if there is some way to combine both of these tables into one table? And how can I customize the table to make it look less-liked a table because my current one is just .. solid-table and my teacher asked me to improve it but I have no idea to do so. And I tried to add button into the table but I realized that I cannot add it from the try statement because that is is retrieve data from database directly. Any guides? Thanks in advance.
You can use SQL join construct and have one table with more columns:
select topic_title,topic_description,topic_by,
reply_content,reply_by
from forumTopics join forumReplies
on (forumTopics.topic_id=forumReplies.topic_id) WHERE topic_id = 1234
then build the model from the five column result set as you are already doing.
But surely if there is more than one reply to a forum topic, the topic part will be repeated in the table.
To make a table not to look like a table, try JTreeTable from Swing Labs maybe, it allows to have tree-like subsections, exactly that is required. It is not part of the system library however, you will need to download it. Some source code on how to just JTreeTable can be found here.
On how JTreeTable looks is Swing Labs, you can see in they web-startable demo. It also shows the code sample automatically.