Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Richard Oliver Legendi
How to access ScreenNameGeneratorFactory?
February 9, 2013 7:02 AM
Answer

Richard Oliver Legendi

Rank: Junior Member

Posts: 35

Join Date: November 30, 2009

Recent Posts

Is it possible to access ScreenNameGeneratorFactory? I have to migrate a few userrs from a different environment and would like to generate screen names in case of duplications.

Thanks in advance.
Jonathan McCann
RE: How to access ScreenNameGeneratorFactory?
February 5, 2013 4:42 PM
Answer

Jonathan McCann

LIFERAY STAFF

Rank: New Member

Posts: 2

Join Date: May 15, 2012

Recent Posts

This would probably do what you're looking for:

import com.liferay.portal.security.auth.ScreenNameGenerator;
import com.liferay.portal.security.auth.ScreenNameGeneratorFactory;

ScreenNameGenerator screenNameGenerator =
ScreenNameGeneratorFactory.getInstance();

try {
screenName = screenNameGenerator.generate(
companyId, userId, emailAddress);
}
catch (Exception e) {
throw new SystemException(e);
}
Hitoshi Ozawa
RE: How to access ScreenNameGeneratorFactory?
February 5, 2013 7:23 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

As Jonathan replied, you'll not be able to access the ScreenNameGeneratorFactory class directly because it's in the portal-impl.jar but you'll be able to access ScreenNameGenerator because that's in the portal-service.jar in the application server lib. Liferay allows methods in portal-service.jar (i.e. in portal-service folder in the source file) to be accessed from other portlets.
Richard Oliver Legendi
RE: How to access ScreenNameGeneratorFactory?
February 9, 2013 7:11 AM
Answer

Richard Oliver Legendi

Rank: Junior Member

Posts: 35

Join Date: November 30, 2009

Recent Posts

Thanks for the code Jonathan, I was doing exactly the same thing. My problem was that in a simple portlet project ScreenNameGenerator is accessible, but ScreenNameGeneratorFactory cannot be imported because (as Hitoshi pointed out) it is in portal-impl.jar, which isn't available for the portlets.

So the conclusion is that there's no easy way of doing it?
dominick campbell
RE: How to access ScreenNameGeneratorFactory?
June 12, 2013 6:02 AM
Answer

dominick campbell

Rank: Junior Member

Posts: 60

Join Date: August 15, 2012

Recent Posts

Ever have any luck on this issue? I am stuck on the same thing in 6.1.1 ... I need to auto generate screen names only for some users

Thanks
Richard Oliver Legendi
RE: How to access ScreenNameGeneratorFactory?
June 20, 2013 2:59 AM
Answer

Richard Oliver Legendi

Rank: Junior Member

Posts: 35

Join Date: November 30, 2009

Recent Posts

Well, I ended up dropping the idea :-)

But since the issue my LR understanding grew a bit, so here're two options I can suggest:

1) Create a utility in ext: there you see the classes of portal-impl.
2) There is an ugly hack my colleague found in the LR codebase for such issues (i.e., to access classes, functions in portal-impl):

1MethodKey methodKey = new MethodKey("com.liferay.portal.SomeClass", "someMethod", parameterClasses...);
2
3try {
4   PortalClassInvoker.invoke(false, methodKey, parameters...);
5} catch (Exception e) {
6   log.error(e.getMessage());
7}


Hope that helps, guys!

(And sorry for the late answer, I was at a conference in DC.)