Thursday, 1 November 2018

Build WSDD and configuration

1> Add this in build.gradle of service module


buildscript {
    dependencies {
        classpath group: "com.liferay", name: "com.liferay.gradle.plugins.wsdd.builder", version: "1.0.10"
    }

    repositories {
        maven {
            url "https://repository-cdn.liferay.com/nexus/content/groups/public"
        }
    }
}




apply plugin: "com.liferay.portal.tools.wsdd.builder"



2> Add below dependancy in both build.gradle(api and servcie)


compileOnly group: 'com.liferay', name: 'com.liferay.osgi.util', version: '4.1.0'



with above configuration you will get buildWSDD goal and you will be able to build genrate file by doing this.


Ref :

https://dev.liferay.com/develop/reference/-/knowledge_base/7-0/wsdd-builder-gradle-plugin

Saturday, 24 February 2018

NOT IN operator in Liferay DXP

NOT IN Operator in Liferay DXP

For Ex.

select userId from user_ where userId  NOT IN select userId from organization_


        List<User> us = UserLocalServiceUtil.getUsers(-1, -1);
System.out.println("total records " + us.size());
  
        Projection pr = ProjectionFactoryUtil.property("userId");

DynamicQuery dq = OrganizationLocalServiceUtil.dynamicQuery();
dq.setProjection(pr);
dq.setProjection(ProjectionFactoryUtil.distinct(pr));
        List<Long> orgUserId = OrganizationLocalServiceUtil.dynamicQuery(dq);
        System.out.println("Dinstinct UserId From  Organization Table : - " + orgUserId.size());

DynamicQuery dynamicQuery = UserLocalServiceUtil.dynamicQuery();
dynamicQuery.add(PropertyFactoryUtil.forName("userId").notIn(dq));
dynamicQuery.setProjection(pr);
dynamicQuery.setProjection(ProjectionFactoryUtil.distinct(pr));
List<Long> userIdlist = UserLocalServiceUtil.dynamicQuery(dynamicQuery);


System.out.println("Actual Result = total-from org table " + userIdlist.size());


Here column data type should be NOT NULL.

Tuesday, 13 February 2018

Embed Webcontent using Title using Freemarker template in liferay dxp

<#assign VOID = freeMarkerPortletPreferences.setValue("portletSetupPortletDecoratorId", "barebone") />
<#assign theme_groupID = htmlUtil.escape(theme_display.getCompanyGroupId()?string) />
<#assign VOID = freeMarkerPortletPreferences.setValue("groupId", '${group_id}') />
<#assign journalArticleLocalService =          serviceLocator.findService("com.liferay.journal.service.JournalArticleLocalService") />
<#assign footercontentarticle = journalArticleLocalService.getArticleByUrlTitle(group_id,"footercontent")/>
<#assign VOID = freeMarkerPortletPreferences.setValue("articleId", footercontentarticle.getArticleId()) />

        <@liferay_portlet["runtime"]
        defaultPreferences="${freeMarkerPortletPreferences}"
        portletProviderAction=portletProviderAction.VIEW
        instanceId="footercontent"
        portletName="com_liferay_journal_content_web_portlet_JournalContentPortlet" />
        ${freeMarkerPortletPreferences.reset()}


Setting ===>
  For embedding WebContent in Liferay 7, first of all, you have to enable serviceLocator in Control Panel -> Configuration -> System Settings -> Foundation -> FreeMarker Engine -> Restricted Variables. There you can remove serviceLocator


References 
1> https://stackoverflow.com/questions/38227528/how-to-embed-webcontent-in-freemarker-liferay-7-theme

Sunday, 11 February 2018

Embed Web content using Article ID in Liferay DXP

<#assign VOID = freeMarkerPortletPreferences.setValue("portletSetupPortletDecoratorId", "barebone") />
<#assign theme_groupID = htmlUtil.escape(theme_display.getCompanyGroupId()?string) />
<#assign VOID = freeMarkerPortletPreferences.setValue("groupId", '${group_id}') />
<#assign VOID = freeMarkerPortletPreferences.setValue("articleId", "yourarticleid") />



        <@liferay_portlet["runtime"]
        defaultPreferences="${freeMarkerPortletPreferences}"
        portletProviderAction=portletProviderAction.VIEW
        instanceId="footercontent"
        portletName="com_liferay_journal_content_web_portlet_JournalContentPortlet" />
        ${freeMarkerPortletPreferences.reset()}
yourarticleid --> Create web content and mention web content ID

Monday, 15 January 2018

Dropdown values from liferay DB table

1>
<%
List<Organization> org = OrganizationLocalServiceUtil.getOrganizations(-1, -1);

List<Country> country = CountryServiceUtil.getCountries();

%>


2> 
<select>
  <option value="-1">Select</option>
  <%for (Organization organization : org) { %>
  <option value=<%=organization.getOrganizationId() %>><%=organization.getName()%></option>
  <%} %>
</select>

<select>
  <option value="-1">Select</option>
  <%for (Country cn : country) { %>
  <option value=<%=cn.getCountryId() %>><%=cn.getName()%></option>
  <%} %>
</select>

External Properties in Liferay DXP

1> Add below entry in portal-ext.properties
    PropertiesLocation=D:/liferay-dxp-digital-enterprise-7.0-sp3/external.properties

2> Now you can add keys in external properties file.
    Example:-
    key1 = external_Id

3> Use above key using below java code..


         /**
 * Getting the location holding file containing data 
 *
 * @param queryString
 * @return
 */
public static String getPropertiesContent(final String queryString) {
final Properties properties = new Properties();
try {
final FileReader reader = new FileReader(
        PropsUtil.get("PropertiesLocation"));
properties.load(reader);
} catch (final IOException e) {
return "File path not found";
}
return properties.getProperty(queryString, "");
}

4> Now you can use like below
keyName=<ClassName>.getPropertiesContent(
        "key1" );