Liferay: how to save to portlet user information? - preferences

I have at the welcome page a weather portlet, and user can configure the portlet and select his city. Is it possible to store user information in the portlet preferences, so that every user has his one stored city? Or what is the standard workflow to store user-portlet information without to develop own (persist) service?
thx

The portlet-preferences are in liferay per default not user specific. That can be modified in liferay-portlet.xml with next lines:
<liferay-portlet-app>
<portlet>
<portlet-name>ThePortletWitchUserSpecificPreferences</portlet-name>
<icon>/icon.png</icon>
<preferences-unique-per-layout>false</preferences-unique-per-layout>
<preferences-owned-by-group>false</preferences-owned-by-group>
</portlet>
...
</liferay-portlet-app>
the two lines <preferences-... and the order are abbreviated.
for more information see:
http://rutvijshah.wordpress.com/2009/12/06/user-specific-preferences-in-liferay/

It's not a native function of the PortletPreference : the setValue method allow only a String, unfortunately you can't pass a Map.
However, i see a solution to hardcode it, but it's a little bit ugly...
Long userId = ...... ;
String userValue = ..... ;
PortletPreferences prefs = request.getPreferences();
prefs.setValue("myConfig-"+userId, myUserVal);
prefs.store();
And for retrieve the data :
String userValue = prefs.getValue("myConfig-"+userId, defaultValue);
This solution will work, but don't do that is you have a big numbers of users.
Portlet Preferences are save in xml in your database, if you have 100k+ users, it will explode :)
If you think this solution is not enough clean, you will have to create your own persistence method with the ServiceBuilder.

Related

How to remove presentity users entry in kamailio server?

I found that in:
kamctl db show presentity
Is the presence information of the users, but how can I errase such entry? of a user?
And how can I define only one entry in that database by user?
I use this code, when I receive a publish but this adds a new entry every time.
if(is_method("PUBLISH"))
{
if($hdr(Sender)!= NULL)
handle_publish("$hdr(Sender)");
else
handle_publish();
t_release();
}
The idea is have the possibility of a user publish multiple times, but have just one entry.
You can use this: https://www.kamailio.org/docs/modules/stable/modules/presence.html#presence.p.xavp_cfg
To order by timestamp you just need this line modparam("presence", "xavp_cfg", "pres").
This way, I think that your problem is solved.
Let me know if it's result.

Django Tastypie, Remove Elements From ManyToMany Fields

I am using Tastypie, Django for my project.
To Update a many to many field I have used save_m2m hook.
def save_m2m(self, bundle):
for field_name, field_object in self.fields.items():
if not getattr(field_object, 'is_m2m', False):
continue
if not field_object.attribute:
continue
if field_object.readonly:
continue
related_mngr = getattr(bundle.obj, field_object.attribute)
related_objs = []
print bundle.data[field_name]
for related_bundle in bundle.data[field_name]:
try:
stock = Stock.objects.get(nse_symbol = related_bundle.obj.nse_symbol)
print stock.__dict__
except Stock.DoesNotExist as e:
dataa = {"error_message": e}
raise ImmediateHttpResponse(response=HttpBadRequest(content=json.dumps(dataa), content_type="application/json; charset=UTF-8"))
related_objs.append(stock)
related_mngr.add(*related_objs)
Now I want to remove elements from the same many to many field.
How should I achieve this. Do I have to send a patch request or delete request and how to handle this.
I am begineer in tastypie. I googled it some time and I couldn't find a proper way. Please guide me how to complete this.
Thanks.
I've thought a lot about handing m2m relationships, since most of our app depends on m2m links.
I've settled for the approach of an update method. Pass in the all the references of the relationships you want changed (add and remove), then update the db accordingly. We only pass in the changed values, since if you have a paginated list, you only want to update the items the user has identified. Generally I use a custom hook for this defined in override_urls.
I used to have a separate add and remove method, which worked well until we changed the gui and allowed users simply to change checkboxes. In that approach having an update method was much more useful. You'll have to decide on which method suits your application the best.

Customizing Surf Platform Root-Scoped API

I want to customize Surf Platform Root-Scoped API specifically user object. That means add new property or method to user object to check the user is in certain group in header.inc.ftl [in share] like `<#if user.isAdmin>
How can I implement this?
Is Alfresco Root Scoped Objects can be used as Surf Platform Root-Scoped object?
I have no idea of customizing surf platform root object. Can anyone help me???
Not quite sure what you are trying to accomplish, but the role security model is hardcoded in spring-surf/spring webscripts. There is guest, user and admin. If what you want is another analogous role you'll have to hack the spring-surf libaries, namely:
org/springframework/extensions/surf/mvc/PageView.java
org/springframework/extensions/webscripts/ScriptUser.java
org/springframework/extensions/webscripts/Description.java
org/springframework/extensions/webscripts/connector/User.java
This is what I had to do to implement user.isEmployee. This approach allows you to literally treat your new role just as the others.
you can use
<authentication>employee</authentication>
in page descriptors or
<item type="link" permission="employee" id="people">/people-finder</item>
on the navigation.
Just checking whether the user is in a certain group in a certain webscript is a whole diffrent story and does not provide the same functionality.
If what you want is the latter, you should make a call to
/alfresco/service/api/groups/{shortName}
miss
and works through the response.
Update: The item permission attribute requires a little more tweaking.
In header.get.js, propagate the new role to it gets processed properly in header.inc.ftl:
model.permissions =
{
guest: user.isGuest,
admin: user.isAdmin,
employee : user.isEmployee
};
you could try (in JavaScript I managed something like) this:
user = Application.getCurrentUser(context);
String userName = user.getUserName();
user.isAdmin() >>> result return true if user logining is admin
or in JSP:
#{NavigationBean.currentUser.admin == true}
Sorry, i noticed now you was talking about Surf Platform root objects, but the link you put there, is deprecated for Alfresco versions above 3.3. You still use something so old?
If you manage to use JavaScript API's you could use "person" root object, with boolean isAdmin().

How to add some extra parameter in the airbrake parameters for JS errors

When we are sending the airbrake error to the airbrake server, by default it includes the controller name and action name.
But the question is that I want to add some extra parameters like username, email of the current user. If anyone has any idea please suggest how to do that?
In my layout application.html:
- if ['development'].include?(Rails.env)
= airbrake_javascript_notifier
= render :partial => 'layouts/airbrake_notifier'
and in the partial I have written:
Airbrake.errorDefaults['name'] = "#{current_user.name}";<br/>
Airbrake.errorDefaults['email'] = "#{current_user.email}";<br/>
Airbrake.errorDefaults['phone'] = "#{current_user.phone}";<br/>
Airbrake.errorDefaults['title'] = "#{current_user.title;<br/>
Not a great solution, but the Airbrake Knowledge Base recommends essentially patching the airbrake gem source of the lib/airbrake/notice.rb file.
def initialize(args)
...
self.parameters = args[:parameters] ||
action_dispatch_params ||
rack_env(:params) ||
{'username' => current_user.name}
It would certainly be better to have this be configurable without patching source.
What I've done instead is simply add a few pieces of data to the session (current_user.name mainly), since session data is sent with the request. I wouldn't do this for more than a few little pieces of data.
We've just added getting current users into the Airbrake Gem.
https://github.com/airbrake/airbrake/wiki/Sending-current-user-information
You'll soon be able to sort by current user in an upcoming redesign of the UI.

Using "seen" on a trail in KRL

I want to have a trail that helps keep track of values I want to persist for users. If a user has not entered their name, I want to display a form for them to enter their name to use for lookups.
I want to be able to check if the name is on the trail. If the name is on the trail then display the data for that user. If the name is not on the trail then I want to display a form for them to enter their name.
I am looking for some help on how I would accomplish this. It was suggested to encode a struct as json and pushing that on to a trail and then search for it. Some direction on how this would be done would be helpful. Would I use the following?
if seen ent:user_data with <regexp> then {
<get and show data>
} else {
<show form to user>
}
If you just want to save a simple string for later then you can do something like the following using an entity variable
in the pre block retrieve saved name from entity variable:
savedName = ent:userName || "";
in the postlude save or clear the entity variable:
set ent:userName userName;
clear ent:userName;
Example app => https://gist.github.com/722849
Example bookmarklet => http://mikegrace.s3.amazonaws.com/forums/stack-overflow/example-persistant-trail-bookmarklet.html
Example run on http://example.com results
first run on example.com
after clicking submit
reloading the page and running the app again
clearing trail by running on yahoo.com
running app on yahoo.com before saving name or after clearing
Note: When you want to save something else like an age, you can just use a different entity variable like
ent:userAge
The sky is the limit. ; )