Showing posts with label Liferay. Show all posts
Showing posts with label Liferay. Show all posts

Saturday, 22 August 2015

Liferay 6.x cstom plugin or out of box web services consumption via Java program

Required class path dependencies are :


  1. portal-client
  2. axis
  3. axis-jaxrpc
  4. commons-logging
  5. commons-discovery
  6. wsdl4j

Java code:

public class CompetencyRemoteAuth {

                static final Logger LOGGER = LoggerFactory
                                                .getLogger(CompetencyRemoteAuth.class);

                static final String LIFERAY_USER_NAME = "satya.kolliboina@gmail.com";
                static final String LIFERAY_USER_PASSWORD = "test1";

                static final String USER_SERVICE = "Portal_UserService";
                static final String COMPANY_SERVICE = "Portal_CompanyService";
                static final String Competency_AUTHENTICATION_SERVICE = "Plugin_Competency_CompetencyAuthenticationService";
                static final String Competency_REGISTRATION_SERVICE = "Plugin_Competency_RegistrationService";

                /**
                * @param args
                */
                public static void main(String[] args) {
                                try {
                                                System.out.println("UserEmail: " + args[0] + "...user pwd:"+args[1]);
                                                URL CompetencyAuthenticationServiceEndPoint = _getURL(args[0],args[1], Competency_AUTHENTICATION_SERVICE);
                                             
                                                System.out.println("Try lookup CompetencyAuthentication Service by End Point: "         + CompetencyAuthenticationServiceEndPoint + "...");
                                             
                                                URL companyServiceEndPoint = _getURL(args[0],args[1], COMPANY_SERVICE);
                                             
                                                System.out.println("Try lookup company Service by End Point: "               + CompetencyAuthenticationServiceEndPoint + "...");
                                             
                                                CompetencyAuthenticationServiceSoapServiceLocator CompetencyAuthenticationLocator = new CompetencyAuthenticationServiceSoapServiceLocator();
                                                CompetencyAuthenticationServiceSoap CompetencyAuthenticationService = CompetencyAuthenticationLocator.getPlugin_Competency_CompetencyAuthenticationService(CompetencyAuthenticationServiceEndPoint);
                                                                             
                                                ((Plugin_Competency_CompetencyAuthenticationServiceSoapBindingStub) competencyAuthenticationService)
                                                .setUsername(args[0]);
                                                ((Plugin_Competency_CompetencyAuthenticationServiceSoapBindingStub) competencyAuthenticationService)
                                                .setPassword(args[1]);
             
                                             
                                                CompanyServiceSoapServiceLocator locatorCompany = new CompanyServiceSoapServiceLocator();
                                                CompanyServiceSoap companyService = locatorCompany.getPortal_CompanyService(companyServiceEndPoint);
                                                CompanySoap companySoap = companyService.getCompanyByVirtualHost("localhost");

                                                System.out.println("Get UserID" + "...");
                                                long userId = 0;
                                             
                                             
                                                userId = CompetencyAuthenticationService.CompetencyAuthentication(args[0], args[1], args[2]);
                                                System.out.println("UserId for user named " + args[0]   + " is " + userId);

                                             

                                } catch (RemoteException re) {
                                                LOGGER.error(re.getClass().getCanonicalName()
                                                                                + re.getMessage());
                                } catch (ServiceException se) {
                                                LOGGER.error(se.getClass().getCanonicalName()
                                                                                + se.getMessage());
                                }
                }
             
                /**
                * Get the URL Liferay SOAP Service
                *
                 * @param remoteUser
                * @param password
                * @param serviceName
                * @return
                */
                private static URL _getURL(String remoteUser, String password, String serviceName) {
//http://localhost:9090/CompetencyAuthentication-portlet/api/axis/Plugin_Competency_CompetencyAuthenticationService?wsdl
                                final String LIFERAY_PROTOCOL = "http://";
                                final String LIFERAY_TCP_PORT = "9090";
                                final String LIFERAY_FQDN = "127.0.0.1";
                                String LIFERAY_AXIS_PATH = "";
                             
                                try {
                                                if(serviceName.split("_")[0].equalsIgnoreCase("Plugin")){
                                                                LIFERAY_AXIS_PATH = "/CompetencyMobility-portlet/api/secure/axis/";
                                                }else{
                                                                LIFERAY_AXIS_PATH = "/api/secure/axis/";
                                                }
                                                return new URL(LIFERAY_PROTOCOL
                                                                                + URLEncoder.encode(remoteUser, "UTF-8") + ":"
                                                                                + URLEncoder.encode(password, "UTF-8") + "@" + LIFERAY_FQDN
                                                                                + ":" + LIFERAY_TCP_PORT + LIFERAY_AXIS_PATH + serviceName);
                                } catch (Exception e) {
                                                LOGGER.error(e.getMessage());
                                                e.printStackTrace();
                                                return null;
                                }
                }
}

Friday, 31 July 2015

Liferay default role associations via portal-ext.properties

system.roles=Moderator
system.role.Moderator.description=This is Moderator role.

Tuesday, 8 November 2011

Get community level role in Themes

You can write the following code in init_custom.vm

#* Check for Community role for logged in user. *#
#set ($blogEditorCummunityRole = 'Blog Editor')
#set ($userHasBlogEditorRole = 'false')
#* Get Role Local Service *#
#set ($roleLocalService = $serviceLocator.findService("com.liferay.portal.service.RoleLocalService"))
#* Get All community Level Role for current community and Current Logged In User *#
#set ($communityRolesforUser = $roleLocalService.getUserGroupRoles($user_id,$group_id))
#* Iterate through the list of roles and Compare the Blog Editor Role *#
#foreach ($communityRoleforUser in $communityRolesforUser)
         #if ($communityRoleforUser.getName() == $blogEditorCummunityRole)
               #set ($userHasBlogEditorRole= 'true')
          #end
#end

Get community info in theme

#set($currentGroup = $layout.getGroup())
 #set($currentGroupName = $currentGroup.getName())
 #set($currentGroupURL = $currentGroup.getFriendlyURL())

ASSET PUBLISHER FULL CONTENT DISPLAY IN OTHER PAGE


However, it _seems like there is a mechanism in the asset publisher that should handle the situation but may not be implemented fully. In the portlet "Look and Feel" configuration, you can specify an alternate page to send links to. Furthermore, in the asset publisher configuration, the option for "Asset Link Behaviour" shows us "show in a specific portlet".

Now, if these two settings are working together then a user should be able to select a _specific portlet from the page where the look and feel settings are saying to send the links.

Regardless, we did find a workaround using only the UI but it was a bit odd.

1) We created a sub-page of the page that had the asset publisher with the list of abstracts and when that page was created, we made sure to "copy" the parent page. This set us up with a second page that had an asset publisher on it but more importantly, the instanceID of that assets publisher was the same instance ID of the parent page.
2) We reconfigured the asset publisher on the sub page to have "Display style" set to "Full Content"
3) We then set the "Look and Feel" properties of the parent page asset publisher to point the links to the sub page
4) We set the properties of the asset publisher configuration on the parent page to "show in a specific portlet" and viola, it all worked. You can see the result here: