Wednesday 23 May 2018

Birthday Portlet

<%
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd");
List<EmployeeDetails> list = EmployeeDetailsLocalServiceUtil.getEmployeeDetailses(-1, -1);
List<EmployeeDetails> blist = new ArrayList<>();
Date date = new Date();
for(EmployeeDetails e : list){
Date dob = e.getDob();
if( dob.getDate() == date.getDate() && dob.getMonth() == date.getMonth()){
blist.add(e);
}
}
%>
<%if(blist.isEmpty()){%>
<b>There is no B day</b>
<%}else if(!list.isEmpty()){
for(EmployeeDetails emp : blist){%>
<%

FileEntry dlfileentry = DLAppServiceUtil.getFileEntry(emp.getFileEntryId());
String imageURL ="/documents/" + dlfileentry.getGroupId() + "/"
+ dlfileentry.getFolderId() + "/" + dlfileentry.getTitle()
+ "/" + dlfileentry.getUuid();
%>
<a href="<%=imageURL%>"><img src="<%=imageURL%>" alt="image" class="mmm"/></a>

<p class="bday nomargin"><%=emp.getEmployeename() %></p>
<b class="wish">Wish you happy B day</b>

<%String dates=formatter.format(emp.getDob()); %>

<p class="bday"><%=dates%></p>
<%} }%>


Search By User Name

In jsp

<%PortletURL userNameURL = renderResponse.createActionURL();
userNameURL.setParameter(ActionRequest.ACTION_NAME, "userfilter");%>
<%
List<Billclaim> bill = null;
if(request.getAttribute("fn") != null){
bill = (List<Billclaim>) request.getAttribute("fn");
}else{
bill = BillclaimLocalServiceUtil.getBillclaims(-1, -1);
}
%>
<aui:form method="POST" name="fm" action="<%=userNameURL.toString() %>" >
<aui:input type="text" label="" name="userName" placeholder="Search By User Name">
</aui:input>
<aui:button type="submit" value="Search"/>
</aui:form>

BillclaimLocalServiceImpl.java
public List<Billclaim> getUserName(String userName){
   return billclaimPersistence.findByuserName(userName);
}

Controller
 public void userfilter(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException, SystemException, PortalException {
  String userName = ParamUtil.getString(actionRequest, "userName");
  List<Billclaim> fn = BillclaimLocalServiceUtil.getUserName(userName);
  actionRequest.setAttribute("fn", fn);
  actionResponse.setRenderParameter("jspPage", "/billView.jsp");
  SessionMessages.add(actionRequest, "searched");
  }

Service.xml
<finder name="userName" return-type="Collection">
<finder-column name="userName"></finder-column>
 </finder>


Wednesday 25 April 2018

Status Pending & Approved using action

JSP:

<aui:option value="<%=billClaimPortletKeys.pending %>">Pending for approval</aui:option><aui:option value="<%=billClaimPortletKeys.approved%>">Approved</aui:option>

Constants file

public class billClaimPortletKeys {
    public static final String billClaim = "BillClaim";
    public static final String approved = "Approved";
    public static final String pending = "Pending For Approval";
    public static final String medical = "Medical";
    public static final String travel = "Travel";
    public static final String food = "Food";
    public static final String variablepay = "Variablepay";
    public static final String teamouting = "Team Outing";
    public static final String others = "Others";
}


 action.jsp

<%
    ResultRow row = (ResultRow) request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
    Billclaim bill = (Billclaim) row.getObject();
   
    long fooId = ParamUtil.getLong(request, "fooId");
    PortletURL approvedURL = renderResponse.createActionURL();
    approvedURL.setParameter(ActionRequest.ACTION_NAME, "approved");
    approvedURL.setParameter("fooId", String.valueOf(bill.getFooId()));
%>

<liferay-ui:icon-menu>

<%{ %>
<liferay-ui:icon  image="delete" message="Delete" url="<%= deleteBillURL.toString()%>" />
<liferay-ui:icon  image="check" message="Approved" url="<%=approvedURL.toString() %>" />
<%} %>

</liferay-ui:icon-menu> 



 Controller

 public void approved(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException, SystemException, PortalException {
          Billclaim billclaim =null;
          String approved = billClaimPortletKeys.approved;
          long fooId = ParamUtil.getLong(actionRequest, "fooId");
          System.out.println("FooooID##################" +fooId);
          billclaim = BillclaimLocalServiceUtil.fetchBillclaim(fooId);
          billclaim.setStatus(approved);
          BillclaimLocalServiceUtil.updateBillclaim(billclaim);
      }


 

Thursday 19 April 2018

SMS Configuration using sms horizon API

Step 1 - Login Sms horizon & get username & API key (http://smshorizon.co.in/api/sendsms.php?user=Mufas&apikey=LPDkKtHkmkRk8XEtbjrt&mobile=9620367054&message=welcome&senderid=saleem&type=txt)

Step 2 - Create Portet.properties inside resources folder

This is my user name & my api

smsuserid=mufas
password=LPDkKtHkmkRk8XEtbjrt
message= Thank you for submitting you feedback.
smsapi=http://smshorizon.co.in/api/sendsms.php?

Step 3 - Call sendsms() method in controller.

  public void sendMsg() throws UnsupportedEncodingException {
  System.out.println("SMS Working complaint #########################");
  Configuration configuration = ConfigurationFactoryUtil.getConfiguration(PortalClassLoaderUtil.getClassLoader(), "portlet");
 
  String userName = configuration.get("smsuserid");
  String password = configuration.get("password");
  String textMessage = configuration.get("message");
  String smsapi = configuration.get("smsapi");
  StringBuilder smsSenderURLQueryString = new StringBuilder();
  smsSenderURLQueryString.append("user="
+ URLEncoder.encode(userName, "UTF-8"));
smsSenderURLQueryString.append("&apikey="
+ URLEncoder.encode(password,
"UTF-8"));
smsSenderURLQueryString.append("&mobile="
+ URLEncoder.encode("9620367054", "UTF-8"));
smsSenderURLQueryString.append("&message="
+ URLEncoder.encode(textMessage, "UTF-8"));
smsSenderURLQueryString.append("&senderid="
+ URLEncoder.encode("MYTEXT", "UTF-8"));
smsSenderURLQueryString.append("&type=" + "TXT");
String completeSenderURLString = smsapi +smsSenderURLQueryString.toString();
HttpURLConnection connection = null;
URL completeSenderURL = null;
String conncetionResponse = null;
try{
completeSenderURL = new URL(completeSenderURLString);
connection = (HttpURLConnection) completeSenderURL.openConnection();
connection.setDoOutput(false);
connection.setDoInput(true);
conncetionResponse = connection.getResponseMessage();
int responseCode = connection.getResponseCode();
String responseMessage = connection.getResponseMessage();
}catch(Exception e){

}
  }

Wednesday 18 April 2018

SMTP CONFIGURATION USING EXT PROPERTIES

Step 1 - Inside server portal-ext.properties add this

mail.session.mail.imap.host=192.99.42.143
mail.session.mail.pop3.host=192.99.42.143
mail.session.mail.smtp.auth=true
mail.session.mail.smtp.host=smtp.gmail.com
mail.session.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
mail.session.mail.smtp.socketFactory.fallback=false
mail.session.mail.smtp.socketFactory.port=465
mail.session.mail.smtp.starttls.enable=true
mail.session.mail.smtp.password=muhammedsaleem
mail.session.mail.smtp.port=465
mail.session.mail.smtp.user=callsaleem@gmail.com
mail.session.mail.store.protocol=imap
mail.session.mail.transport.protocol=smtp


Step 2 - Restart the server

Step 3 - Open build.gradle

Add this line:  compile 'javax.mail:mail:1.4.7'


Step - 4 Create Send mail method in controller

public void sendMailWithPlainText() {
InternetAddress fromAddress = null;
InternetAddress toAddress = null;
try {
    fromAddress = new InternetAddress("xyz@gmail.com");
    toAddress = new InternetAddress("abc@gmail.com");
    MailMessage mailMessage = new MailMessage();
    mailMessage.setTo(toAddress);
    mailMessage.setFrom(fromAddress);
    mailMessage.setSubject("Your Bill is claimed successfully");
    mailMessage.setBody("Hi,<br>Your content<br><br>Best Regards,<br>Mufas");
    mailMessage.setHTMLFormat(true);
    MailServiceUtil.sendEmail(mailMessage);
    System.out.println("Send mail with Plain Text");
} catch (AddressException e) {
    e.printStackTrace();
}
}

Step -5 : Call the send mail method 

sendMailWithPlainText()

Friday 13 April 2018

Aui Auto Field

<aui:input name="skills" type="textarea" label="skills" >
                <aui:validator name="required" />
            </aui:input>

<aui:script use="autocomplete-list,aui-base,autocomplete-filters,autocomplete-highlighters">

   var skills = [
           {"name":"Java"},
          {"name":"Alfresco"},
           {"name":"HTML"},
           {"name":"C++"},
           {"name":"Liferay"},
           {"name":"Python"},
           {"name":"C"},
           {"name":"SQL"},
           {"name":"JavaScript"},
           {"name":"C#"},
           {"name":"PHP"},
           {"name":"CSS"},
           {"name":"Bootstrap"},
           {"name":"jQuery"},
           {"name":"AngularJS"},
           {"name":"AJAX"}
         ];
   new A.AutoCompleteList(
       {
        allowBrowserAutocomplete: 'false',
        activateFirstItem: 'true',
        inputNode: '#<portlet:namespace/>skills',
        resultTextLocator: 'name',
        resultHighlighter:'phraseMatch',
        resultFilters: ['startsWith'],
        minQueryLength: 1,
        maxResults: 10,
        queryDelimiter : ',',
        render: 'true',
        source:skills
   }); 
</aui:script>

Monday 26 March 2018

Aui validation for Pancard & Passport & Aadhar Validations

1] Remove Aui type submit
2] Inside input Add Class
<p id="id"></p>

<aui:button value="Save"  onClick="submitFormsss();"/>

<script type="text/javascript">
   function submitFormsss() {
   var panVal = $('.panNumber').val();
   var passVal = $('.passNumber').val();
   var aadharVal = $('.aadhar').val();
   var regpan = /^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/;
   var regpassport = /^([a-zA-Z]){1}([0-9]){7}?$/;
   var regaadhar = /^([0-9]){12}?$/;
 
   if(regpan.test(panVal) && regpassport.test(passVal) && regaadhar.test(aadharVal)){
       document.<portlet:namespace />fm.submit();
   }else if(!regpan.test(panVal)){
       alert("Please enter valid Pan number")
       document.getElementById("pan").innerHTML = "Please Provide Valid Pan Number";
   }else if(!regpassport.test(passVal)){
   document.getElementById("pass").innerHTML = "Please Provide Valid Passport Number";
   }else if(!regaadhar.test(aadharVal)){
   document.getElementById("aadhar").innerHTML = "Please Provide Valid Aadhar Number";
   }
   }
</script>

Monday 12 March 2018

How to Embed portlet in liferay theme

Liferay 7

<@liferay_portlet["runtime"]
portletName="my_custom_portlet_WAR_mycustomportlet"
/> 



Liferay 6.2

$theme.runtime("bottomlink_WAR_EKHUBportlet")

Sunday 11 March 2018

Adding a Plugins Portlet to the Control Panel

Step 1:Specify where the portlet will appear in Control Panel
Open your liferay-portlet.xml. Add the below tags after <icon> tag

<control-panel-entry-category>apps</control-panel-entry-category>
<control-panel-entry-weight>0</control-panel-entry-weight>
 
 
Note 1: In the above code the line <control-panel-entry-category>apps</control-panel-entry-category> says where our portlet will appear in the Control Panel.  
 
Note 2: The Tag <control-panel-entry-weight> represents location vertically in the given category. According to our code Book Portlet will appear at first position in apps category. 
 
Step 2:Make the portlet hidden
In this step we put the portlet in hidden category so that it's not available anywhere other than Control Panel. This is done by modifying liferay-display.xml. For example.
 
<display>
<category name="category.hidden">
<portlet id="book-portlet" />
</category>
</display>
 
That's it. Now your portlet available in Control Panel