11 August 2015

Videos on design patternsDesign Patterns


Run mysql as a service in windows

Type cmd in start and right click and Run as administrator,
then paste the below text in your command prompt,
"C:\Program Files (x86)\MySQL\MySQL Server 5.1\bin\mysqld" --install

f u want to uninstall the service do the following, copy paste the following in command prompt(again elevated command prompt) run this,
sc delete MySQL

23 October 2012

Dynamic Query examples

 DynamicQuery query = DynamicQueryFactoryUtil.forClass(Subcription.class);
                    query.addOrder(OrderFactoryUtil.desc("createDate"));
                    query.add(RestrictionsFactoryUtil.eq("companyId", themeDisplay.getCompanyId()));
                    query.add(RestrictionsFactoryUtil.eq("groupId", themeDisplay.getScopeGroupId()));
                    query.add(RestrictionsFactoryUtil.eq("mdn", MDN));
                results=SubcriptionLocalServiceUtil.dynamicQuery(query);


DynamicQuery query = DynamicQueryFactoryUtil.forClass(Subcription.class);

                query.add(RestrictionsFactoryUtil.between("crdDate", fromDate, toDate));
                if(packtype!=-1 && packtype!=0)
                {
                query.add(RestrictionsFactoryUtil.eq("packageId", packtype));
                }
                if(!subscriptiontype.equals("") && !subscriptiontype.equals("ALL"))
                {
                DynamicQuery CustomerQuery = DynamicQueryFactoryUtil.forClass(Customer.class, "cus").setProjection(ProjectionFactoryUtil.property("cus.userId")).add(PropertyFactoryUtil.forName("cus.subscriptionType").eq(subscriptiontype));
                query.add(PropertyFactoryUtil.forName("userId").in(CustomerQuery));
                }

AlloyUI datepicker

    <aui:column columnwidth="50" first="true" >
        <label><liferay-ui:message key="from"/> </label>
        <div class="aui-datepicker-example aui-helper-clearfix" id="staticDatePicker">
            <div class="aui-datepicker aui-datepicker-display aui-helper-clearfix" id="datePickerBB">
                <div class="aui-datepicker-content" id="srcNode">
                    <div class="aui-datepicker-select-wrapper">
                        <select id="yearNode" class="custom-field aui-datepicker-year">
                            <option value="2010">2010</option>
                        </select>
                        <select id="monthNode" class="custom-field aui-datepicker-month">
                            <option value="0">January</option>
                            <option value="1">February</option>
                            <option value="2">March</option>
                            <option value="3">April</option>
                            <option value="4">May</option>
                            <option value="5" >June</option>
                            <option value="6">July</option>
                            <option value="7">August</option>
                            <option value="8">September</option>
                            <option value="9">October</option>
                            <option value="10">November</option>
                            <option value="11">December</option>
                        </select>
                        <select id="dayNode" class="custom-field aui-datepicker-day">
                            <option value="9">9</option>
                        </select>
                    </div>
                    <div class="aui-datepicker-button-wrapper">
                        <button type="button" id="buttonTest" class="aui-buttonitem-content aui-widget aui-component aui-buttonitem aui-state-default aui-buttonitem-icon-only">
                            <span class="aui-buttonitem-icon aui-icon aui-icon-calendar"></span>
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </aui:column>
    <aui:column columnwidth="50" first="true" >
        <label>To: </label>
        <div class="aui-datepicker-example aui-helper-clearfix" id="staticDatePicker1">
            <div class="aui-datepicker aui-datepicker-display aui-helper-clearfix" id="datePickerBB1">
                <div class="aui-datepicker-content" id="srcNode1">
                    <div class="aui-datepicker-select-wrapper">
                        <select id="yearNode1" class="custom-field aui-datepicker-year">
                            <option value="2012">2012</option>
                        </select>
                        <select id="monthNode1" class="custom-field aui-datepicker-month">
                            <option value="0">January</option>
                            <option value="1">February</option>
                            <option value="2">March</option>
                            <option value="3">April</option>
                            <option value="4">May</option>
                            <option value="5" >June</option>
                            <option value="6">July</option>
                            <option value="7">August</option>
                            <option value="8">September</option>
                            <option value="9">October</option>
                            <option value="10">November</option>
                            <option value="11">December</option>
                        </select>
                        <select id="dayNode1" class="custom-field aui-datepicker-day">
                            <option value="9">9</option>
                        </select>
                    </div>
                    <div class="aui-datepicker-button-wrapper">
                        <button type="button" id="buttonTest" class="aui-buttonitem-content aui-widget aui-component aui-buttonitem aui-state-default aui-buttonitem-icon-only">
                            <span class="aui-buttonitem-icon aui-icon aui-icon-calendar"></span>
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </aui:column>


AUI().ready( 'aui-autocomplete', 'aui-io-request','aui-datepicker', function(A){

var resourceUrl = "<portlet:resourceURL />";
var datepicker2 = new A.DatePickerSelect({
        srcNode: '#srcNode',
        contentBox: '#srcNode',
        boundingBox: '#datePickerBB',

        calendar: {
            selectedDates: [new Date(2011, 2, 20)],
            dateFormat: '%m/%d/%y'
        },

        // dayNode: '#dayNode',
        // monthNode: '#monthNode',
        // yearNode: '#yearNode',

         dayNodeName: 'fromDay',
         monthNodeName: 'fromMonth',
         yearNodeName: 'fromYear',

        nullableDay: true,
        nullableMonth: true,
        nullableYear: true,

        // populateMonth: false,
        // populateDay: false,
        // populateYear: false,
        yearRange: [ 1980, 2020 ]
    }).render('#staticDatePicker');

    var datepicker3 = new A.DatePickerSelect({
        srcNode: '#srcNode1',
        contentBox: '#srcNode1',
        boundingBox: '#datePickerBB1',

        calendar: {
            selectedDates: [new Date(2011, 2, 20)],
            dateFormat: '%m/%d/%y'
        },

         dayNode: '#dayNode1',
         monthNode: '#monthNode1',
         yearNode: '#yearNode1',

         dayNodeName: 'toDay',
         monthNodeName: 'toMonth',
         yearNodeName: 'toYear',

        nullableDay: true,
        nullableMonth: true,
        nullableYear: true,

        // populateMonth: false,
        // populateDay: false,
        // populateYear: false,
        yearRange: [ 1980, 2020 ]
    }).render('#staticDatePicker1');


validate=function() {
    var date1;
    var date2;

        datepicker2.calendar.eachSelectedDate(function(date) {
              date1= date.getTime();

                        });
                        datepicker3.calendar.eachSelectedDate(function(date) {
                            date2= date.getTime();

                        });


           if(date1 > date2 )
               {
               alert("Please select valid Date");
               return false;
               }else
                   {
                   return true;
                   }

           };







}
);

Alloy UI Autocomplete

Here is the example for Alloy UI autocomplete

first we need to construct json array


                try
                {
                      JSONObject jsonObj;
                List<Customer> customer = CustomerLocalServiceUtil.getCustomers(0, CustomerLocalServiceUtil.getCustomersCount());
                 jsonObj = JSONFactoryUtil.createJSONObject();
                 jsonObj.put("customerId"  , "ALL");
                 jsonObj.put("fsIdentifier", "ALL");
                 jsonObj.put("vfIdentifier", "ALL");
                 jsonObj.put("Company", "ALL");
                 jsonObj.put("email", "ALL");
                 jsonArray.put(jsonObj);
                for(Customer cust:customer)
                {
                     jsonObj = JSONFactoryUtil.createJSONObject();
                     jsonObj.put("customerId"  , cust.getCustomerId());
                     jsonObj.put("fsIdentifier", cust.getFsIdentifier());
                     jsonObj.put("Company", cust.getCompanyName());
                     jsonObj.put("vfIdentifier", cust.getVfIdentifier());
                     jsonObj.put("email", cust.getEmail());
                     jsonArray.put(jsonObj);
                }

                }catch(Exception e)
                {
                  e.printStackTrace();
                }

                 returnJSONArray(resourceResponse, jsonArray);

AUI().ready('aui-autocomplete', 'aui-io-request', function(A) {


        var resourceUrl = "<portlet:resourceURL />";
        getCustomers = function() {
            var url = resourceUrl;
            A.io.request(url, {
                method : "GET",
                data : {
                    "cmd" : "get-customers"
                },
                dataType : 'json',
                on : {
                    success : function() {
                        autoComplete(this.get('responseData'));
                        autoCompletecompany(this.get('responseData'));
                        autoCompletevfidentifier(this.get('responseData'));
                        autoCompleteemail(this.get('responseData'));

                    },
                    failure : function(xhr, ajaxOptions, thrownError) {
                        displayError("Error getting the list of products");
                    }
                }
            });
        };

    autoComplete = function(data) {
            var autoComplete = new A.AutoComplete({
                dataSource : data,
                forceSelection : true,
                maxResultsDisplayed : data.length,
                schema : {
                    resultFields : [ 'customerId', 'fsIdentifier' ]
                },
                matchKey : 'fsIdentifier',

                typeAhead : true,
                input : '#<portlet:namespace/>customerSelected',
                contentBox : '#cutomersId'
            }).render();
            autoComplete.on('itemSelect', function(event, item) {
                A.one("#customerSelectedid").val(item.customerId);
                A.one("#companyvalueselectid").val(item.fsIdentifier);

            });


        };


           

Download Excel or Pdf Example in liferay 6

Here is the example of downloading xls and pdf in liferay6

String cmd = resourceRequest.getParameter(Constants.CMD);
             PortletSession session= resourceRequest.getPortletSession();
                List<Subcription> subscription    = (List<Subcription>)session.getAttribute("resultscustomer");
              if(subscription!=null)
              {
             try
             {
             resourceResponse.setContentType("application/vnd.ms-excel");
             resourceResponse.addProperty(
                    HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=Marketing.xls"
                );
             Workbook wb = new HSSFWorkbook();
             OutputStream fileOut = resourceResponse.getPortletOutputStream();
             CreationHelper createHelper = wb.getCreationHelper();
             Sheet sheet = wb.createSheet("MTS Requirement");
           // Sheet Subscriber = wb.createSheet("Subscriber");
           //Sheet Content = wb.createSheet("Content");
          //Sheet KPI = wb.createSheet("KPI");
          CellStyle style;
         Font headerFont = wb.createFont();
         headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
         style = createBorderedStyle(wb);
         style.setAlignment(CellStyle.ALIGN_CENTER);
         style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
         style.setFillPattern(CellStyle.SOLID_FOREGROUND);
         style.setFont(headerFont);
             Row row = sheet.createRow((short)0);
            // Row subscriberrow = Subscriber.createRow((short)0);
             // Create a cell and put a value in it.


             // Or do it on one line.
             row.createCell(0).setCellValue("MDN");
             row.createCell(1).setCellValue("Subscription Type");
             row.createCell(2).setCellValue("Product & Pack");
             row.createCell(3).setCellValue("Subscription Status");
             row.createCell(4).setCellValue("Customer Name");
             row.createCell(5).setCellValue("Subscription Date");
             row.createCell(6).setCellValue("Renewal Due Date");
            int i=1;
            for(Subcription sub:subscription)
            {
               Row datarow = sheet.createRow(i);
              datarow.createCell(0).setCellValue(sub.getMdn());
               datarow.createCell(1).setCellValue(sub.getType());
              String productpack=
               datarow.createCell(2).setCellValue(productpack);
             String status="";
            if(sub.getActive())
                {
                status="Active";
                }
                else
                {
                status="Inactive";
                }
               datarow.createCell(3).setCellValue(status);
               datarow.createCell(4).setCellValue(com.liferay.portal.service.UserLocalServiceUtil.getUser(sub.getUserId()).getFullName() );
               datarow.createCell(5).setCellValue(sdf.format(sub.getCrdDate()));
               datarow.createCell(6).setCellValue(sdf.format(sub.getNextCrdDate()));


              i++;



            }


           /* subscriberrow.createCell(0).setCellValue("Date");
           subscriberrow.createCell(1).setCellValue("MDN");
          subscriberrow.createCell(2).setCellValue("Subscriber Profile");
         subscriberrow.createCell(3).setCellValue("Download History");
         subscriberrow.createCell(4).setCellValue("Plan");*/


            wb.write(fileOut);
           // wb.write(fileOut);
            fileOut.close();



             }catch(Exception e)
             {
                 e.printStackTrace();
             }
              }

For Pdf using Itext










             PortletSession session= resourceRequest.getPortletSession();
               List<Subcription> subscription    = (List<Subcription>)session.getAttribute("resultscustomer");
             try
             {
                 PdfPTable table = new PdfPTable(7);
                 // Code 1
                 table.setWidths(new int[]{2,4,4,4,4,4,4});

                    // Code 2
                    table.addCell("MDN");
                    table.addCell("Subscription Type");

                    // Code 3
                    table.addCell("Product & Pack");
                    table.addCell("Subscription Status");

                    // Code 4
                    table.addCell("Customer Name");
                    table.addCell("Subscription Date");
                    table.addCell("Renewal Due Date");
                      for(Subcription sub:subscription)
                        {


                          String productpack=
                         String status="";
                        if(sub.getActive())
                            {
                            status="Active";
                            }
                            else
                            {
                            status="Inactive";
                            }


                          table.addCell(sub.getMdn());
                            table.addCell(sub.getType());

                            // Code 3
                            table.addCell(productpack);
                            table.addCell(status);

                            // Code 4
                            table.addCell(com.liferay.portal.service.UserLocalServiceUtil.getUser(sub.getUserId()).getFullName());
                            table.addCell(sdf.format(sub.getCrdDate()));
                            table.addCell(sdf.format(sub.getNextCrdDate()));



                        }


                    // Code 5




                    Document document = new Document();
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    PdfWriter.getInstance(document, baos);
                    document.open();
                    document.add(table);
                    document.close();



                    resourceResponse.setContentType("application/pdf");
                    resourceResponse.addProperty(
                            HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=Marketingreport.pdf"
                        );

                    //resourceResponse.setContentLength(baos.size());

                    OutputStream out = resourceResponse.getPortletOutputStream();
                    baos.writeTo(out);

                    out.flush();
                    out.close();

             }catch(Exception e)
             {
                 e.printStackTrace();
             }

In your Jsp

<a class="view-in-excel" title="View in Excel" href="<portlet:resourceURL><portlet:param name="<%= Constants.CMD %>" value="export_csd" /></portlet:resourceURL>"><span
                class="link-to-download">Excel<%-- <img src="<%=themeDisplay.getPathThemeImages().toString()%>"/> --%></span></a>
                <a class="view-in-excel" title="View in Excel" href="<portlet:resourceURL><portlet:param name="<%= Constants.CMD %>" value="export_csd_pdf" /></portlet:resourceURL>"><span
                class="link-to-download">PDF<%-- <img src="<%=themeDisplay.getPathThemeImages().toString()%>/> --%></span></a>
            </div>

        


        

13 September 2012

Imprt CSV into MYSQL


LOAD DATA  LOCAL INFILE 'D:\\srikanth\\CustomerConnections2.csv' INTO TABLE tables_portal COLUMNS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;

12 September 2012

JAVA VM Error while build-service

We need to decrease the jvm arg values in SDK in file build-common-plugin.xml

<jvmarg value="-Xms128m" />
            <jvmarg value="-Xmx512m" />

Post

Auto complete off in aui form

To disable auto complete off in aui:form  is to  add a attribute autocomplete attribute off

29 August 2012

Liferay Ad integration

Windows Mobile

Alfresco

Android Tutorial

Objective-C

XML

XPL http://www.w3.org/Submission/xpl/

Exist DB http://exist-db.org/exist/index.xml

XPath  http://www.w3.org/TR/xpath20/

Xquery  http://www.w3.org/TR/xquery/

XSLT   http://www.w3.org/TR/xslt

Orbeon Xforms

http://www.orbeon.com/

Installsield

http://www.flexerasoftware.com/products/installshield.htm

Install4j

http://www.ej-technologies.com/products/install4j/overview.html

Working with alloyui events and elements

http://www.liferay.com/web/nathan.cavanaugh/blog/-/blogs/alloyui-working-with-elements-and-events

Alloy UI Loading Mask

AlloyUI Loading mask

if (A.one('#wrapper').loadingmask == null)
            A.one('#wrapper').plug(A.LoadingMask, { background: '#000' });
        A.one('#wrapper').loadingmask.toggle();