Tuesday, September 29, 2015

How to create GWT module using Eclipse

1- Lets first create inbuild plugin GWT Project i.e. CreateGWTModule








2- Click on Project CreateGWTModule in project explore

2.1- Right Click on Project




2.2- Click on other - Go to Google Web tool kit and click on Module


2.3- Click next and fill the information



2.4- Click finish


our Module Project xml will be like below
<-- encoding="”UTF-8″?" version="”1.0″" xml="">
<--!DOCTYPE module PUBLIC “-//Google Inc.//DTD Google Web Toolkit 2.6.0//EN” “http://google-web-toolkit.googlecode.com/svn/tags/2.6.0/distro-source/core/src/gwt-module.dtd”&gt;
<--module>
<--inherits name=”com.google.gwt.user.User” />
<--source path=”client”/>
<--/module>
3- Our project will look like below




4- Create a java class

public class TestMyClass {
private String firstName;

public String getFirstName() {
return firstName;
}


public void setFirstName(String firstName) {
this.firstName = firstName;
}
}




5- In our project GWT make following line changes by importing the newly created project
@Override
public void onModuleLoad() {
TestMyClass p = new TestMyClass();
p.setFirstName("Lars");
Label label = new Label("Hello " + p.getFirstName());
RootPanel.get().add(label);
}

6- Run the project and see the result



Wednesday, September 23, 2015

How to do data analysis from twitter using JAVA Code.

Data mining and analysis is most happening concept right now in the IT market. Company want to first gather the information from social site like Facebook, Twitter etc to do data analysis and get the market trend before developing any software.


In case of Twitter their are ready made API available that help us to do the Data analysis or study the market trand.

We can down load the Twitter api from site

http://twitter4j.org/en/index.html#download



We can us following code to

import java.util.ArrayList;
import java.util.List;

import twitter4j.Query;
import twitter4j.QueryResult;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;

public class TweetManager {

    public static ArrayList getTweets(String topic) {

        Twitter twitter = new TwitterFactory().getInstance();
        ArrayList tweetList = new ArrayList();
        try {
            Query query = new Query(topic);
            QueryResult result;
            do {
                result = twitter.search(query);
                List tweets = result.getTweets();
                for (Status tweet : tweets) {
                    tweetList.add(tweet.getText());
                }
            } while ((query = result.nextQuery()) != null);
        } catch (TwitterException te) {
            te.printStackTrace();
            System.out.println("Failed to search tweets: " + te.getMessage());
        }
        return tweetList;
    }
}



import java.util.ArrayList;
import java.util.Iterator;


public class SiddhuMainClass {

public static void main(String args[])
{
TweetManager obTweetManager = new TweetManager();
ArrayList objArrayResult = obTweetManager.getTweets("dhumale");
Iterator iterator = objArrayResult.iterator();
while (iterator.hasNext()) {
System.out.println(">>>>>>>>>>>>"+iterator.next());
}
}


}


Out put :

>>>>>>>>>>>>Shooting #shotgun #beretta #thuglife #madeindorset #rah @ Axnoller - Dorset https://t.co/tT6l7HlXez
>>>>>>>>>>>>@beetlejuiceltd #looemusicfestival @ Looe Music Festival https://t.co/FpWbkCAd66
>>>>>>>>>>>>View from the queue #looemusicfestival #beetlejuice #cocktails @beetlejuiceltd @ Looe Music Festival https://t.co/IG8jgSHwEq
>>>>>>>>>>>>Crazy weekend at Looe Music Festival! #cocktails #dreamteam #beetlejuice #looemusicfestival… https://t.co/u08MsXnuh5
>>>>>>>>>>>>Fal Week 2014 #throwback #falmouth #summer #beetlejuice #barmen #dreamteam #cocktails https://t.co/IICVhUpOCP
>>>>>>>>>>>>@narendramodi , happy b'day sir....  May god fullfill your all wishesh and ours too..
>>>>>>>>>>>>2nd family #cornwall #friends #squad #rock #jack #goodbyesummer https://t.co/zppUUoIa0e
>>>>>>>>>>>>email reply from staff admin to me..

To Remo Dhumale Sep 15 at 12:41 PM
Dear Sir,
..............

Note: To execute the programe make sure to add all *.jar files that we had downloaded from the above link.

Site also contain some of the inbuild example for
- post a Tweet
- Sending / Receiving Direct Messages
- Pagination control



Understanding UI binder code with plain JAVA code.


  Split Dropdown
 
 
    Item 1
    Item 2
    Item 3
 



//represent
final ButtonGroup obButtonGroup = new ButtonGroup();

//represent
final DropDownMenu objDropDownMenu = new DropDownMenu();

//represent
final AnchorListItem objAnchorListItem1 = new AnchorListItem("Item  One");
final AnchorListItem objAnchorListItem2 = new AnchorListItem("Item  two");
final AnchorListItem objAnchorListItem3 = new AnchorListItem("Item  three");


objDropDownMenu.add(objAnchorListItem1);
objDropDownMenu.add(objAnchorListItem2);
objDropDownMenu.add(objAnchorListItem3);


final Button siddhuButton1 = new Button("Siddhu1");
siddhuButton1.setDataToggle(org.gwtbootstrap3.client.ui.constants.Toggle.DROPDOWN);
//Adding all button in and menu in Group
obButtonGroup.add(objDropDownMenu);
obButtonGroup.add(siddhuButton1);



Tuesday, September 15, 2015

GWT code for printing

Step -1

Add following line in our HTML file

 iframe id="printIT" style="width:0;height:0;border:0"

Step -2
Add following native method in GWT client Entry point class.


public static native void printMethod(String html) /*-{
var frame = $doc.getElementById('printing');
if (!frame) {
$wnd.alert("Error:  Can't find printing frame. Make sure you had added iframe with id=printIT in HTML file");
return;
}
frame = frame.contentWindow;
var doc = frame.document;
doc.open();
doc.write(html);
doc.close();
frame.focus();
frame.print();
}-*/;


Step -3

Add following line of code on click on button or where you want to implement print functionality.

We had selected GWT in build example and try to print the text it is showing on dialogBox. We can use any widget text to print even images.

String printText = dialogBox.asWidget().getElement().getInnerHTML();
printMethod(printText);







Running the soap ui using command prompt

Inside bin folder of SOAPUI we find command mockservicerunner which is used to run the soapui throung command prompt.

mockservicerunner.bat -m "WeatherSoap MockService" "C:\Soap_UI\TestWeatherWSDL-soapui-project.xml"

To cross verify open the SOAPUI and run the request we will get our mock response


Note:To run SOAP UI as a service use nohup command in linux.

Monday, September 14, 2015

Downloading data in PDF, XLS, WORD format in GWT

hree step are needed to perform operation to download the data in PDF, XLS, WORD format in GWT
Step -1 :-
At client side set the url from where we are going to download the data with file name as given below.

String url = GWT.getModuleBaseURL() + "downloadService?fileInfo1=" + "SiddhuFile";
Window.open( url, "_blank", "status=0,toolbar=0,menubar=0,location=0");


Step -2 :-

Make sure to enter the servlet mapping in web.xml


downloadService
com.test.pdf.server.DownloadServlet


downloadService
/testpdffileproject/downloadService


Step -3 :- Create a servlet that will do the functinality of downloading the data from server side to client side.

protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException
{

String fileName = req.getParameter( "fileInfo1" );
ServletOutputStream out = resp.getOutputStream(); 
int BUFFER = 1024 * 100;
String reportContents = getServletContext().getServerInfo();
//for PDF
resp.setContentType("application/pdf");
resp.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".pdf");

//for CVS files
//resp.setContentType("text/csv"); 
//resp.setHeader("Content-Disposition", "attachment; filename="+ fileName + ".csv"); 
   
//for Word Document
//resp.setContentType("text/doc"); 
//resp.setHeader("Content-Disposition", "attachment; filename="+ fileName + ".doc"); 

resp.setContentLength( Long.valueOf( reportContents.length() ).intValue()); 
resp.setBufferSize(BUFFER);
out.write(reportContents.getBytes()); 
out.flush(); 
out.close(); 


}

Note:- Code to download the data in xls and word is also attached. Please uncomment it if you want to download the data in specific format.


Thursday, September 10, 2015

Oracle SQL Statment to create user, grant permission , Creating Table, views, Trigger and Procedure

Reference:- http://www.techonthenet.com/oracle/schemas/create_schema.php

=======Table Space
#1 - PERMANENT TABLESPACE
CREATE BIGFILE TABLESPACE tbs_perm_siddhu_01
  DATAFILE 'tbs_perm_siddhu_01.dat'
    SIZE 10M
    AUTOEXTEND ON;

===DROP TABLESPACE tbs_01 
INCLUDING CONTENTS 
CASCADE CONSTRAINTS; 

#2 - TEMPORARY TABLESPACE

CREATE TEMPORARY TABLESPACE tbs_temp_siddhu_01
  TEMPFILE 'tbs_temp_siddhu_01.dbf'
    SIZE 5M
    AUTOEXTEND ON;

#3 Creating User called siddhu/siddhu

CREATE USER siddhu
  IDENTIFIED BY siddhu
  DEFAULT TABLESPACE tbs_perm_siddhu_01
  TEMPORARY TABLESPACE tbs_temp_siddhu_01
  QUOTA 20M on tbs_perm_siddhu_01;

#4 Assigning Role to the user siddhu

GRANT create session TO siddhu;
GRANT create table TO siddhu;
GRANT create view TO siddhu;
GRANT create any trigger TO siddhu;
GRANT create any procedure TO siddhu;
GRANT create sequence TO siddhu;
GRANT create synonym TO siddhu;  


--From here we can login to the oracle db with user siddhu


#5 Create Table
CREATE TABLE customers
( customer_id number(10) NOT NULL,
  customer_name varchar2(50) NOT NULL,
  address varchar2(50),
  city varchar2(50),
  state varchar2(25),
  zip_code varchar2(10),
  CONSTRAINT customers_pk PRIMARY KEY (customer_id)
);

#6 Create View

CREATE VIEW view_customers AS
  SELECT customers.customer_id, customers.customer_name, customers.city
  FROM customers
  WHERE customers.customer_name like '%siddhu%';


#7 Grant Object Privilage

GRANT ALL ON  customers TO siddhu;  

#7 CREATE SYNONYMS FOR OBJECTS

CREATE PUBLIC SYNONYM customers
FOR siddhu.customers;

-- Now we can execute select queries direcly on customers i.e. SELECT * FROM customers; without giving schema names.



#8 Delete all rows of the Table
DELETE FROM customers;

#8 Alter table
alter table
   customers
add
   salary  NUMBER NOT NULL;

#8 Trigger

CREATE OR REPLACE TRIGGER trigger_siddhu
BEFORE DELETE OR INSERT OR UPDATE ON customers
FOR EACH ROW
WHEN (NEW.CUSTOMER_ID > 0)
DECLARE
   sal_diff NUMBER;
BEGIN
   sal_diff := :NEW.salary  - :OLD.salary;
   dbms_output.put_line('Old salary: ' || :OLD.salary);
   dbms_output.put_line('New salary: ' || :NEW.salary);
   dbms_output.put_line('Salary difference: ' || sal_diff);
END;
/


#10 Procedure
CREATE OR REPLACE PROCEDURE adjust_salary(
    new_customer_id IN NUMBER,
    salary IN NUMBER
) IS
BEGIN
 IF salary > 7000 
THEN 
UPDATE customers
   SET salary = '7007'
   WHERE customer_id = new_customer_id;
END IF;
END;

How to run Video file in GWT project


Use following belwo given code to execute file bbb_trailer_360p.webm of type webm to run on the screen using GWT application.

Video videoPlayer = Video.createIfSupported();
if (videoPlayer == null) {
RootPanel.get().add(new Label("Your browser doesn't support HTML5 Video"));
return;
}
//Video videoPlayer = new Video("siddhugwtvideoexample/videos/bbb_trailer_3601p.webm");

videoPlayer.addSource("siddhugwtvideoexample/videos/bbb_trailer_360p.webm", VideoElement.TYPE_WEBM);
videoPlayer.setControls(true);
videoPlayer.setPoster("siddhugwtvideoexample/videos/bbb480.jpg");
videoPlayer.setPixelSize(960, 640);
RootPanel.get().add(videoPlayer);



There is also another method which gives you addition control to run the file on the screen for that we need follwing jar files

https://code.google.com/p/gwt-html5-video/downloads/list

VideoWidget videoPlayer = new VideoWidget(true, false, null);

List sources = new ArrayList();
sources.add(new VideoSource("siddhugwtvideoexample/videos/bbb_trailer_3601p.webm", VideoType.WEBM));

videoPlayer.setSources(sources);
videoPlayer.setControls(true);
videoPlayer.setAutoPlay(false);
videoPlayer.setPoster("siddhugwtvideoexample/videos/bbb480.jpg");
videoPlayer.setPixelSize(960, 640);
RootPanel.get().add(videoPlayer);