Tuesday, February 18, 2014

Show list in groups using JS

<div id="data"></div>

var ar = new Array();
ar.push({F: "A", L: "C"});
ar.push({F: "B", L: "D"});
ar.push({F: "C", L: "E"});
ar.push({F: "C", L: "X"});
ar.push({F: "A", L: "Z"});

var c = $(ar).sort(function(a,b) {
   var f1 = a.F;
    var f2 = b.F;
    return f1 > f2;
});
var oldHeader = "";
$.each(c,function() {
    if (oldHeader != this.F) {
        $("#data").append($("<p>").css({"font-weight": "bold", "margin-top" : "30px"})
                        .append("(Header " + this.F + ")"));
        oldHeader = this.F;
    }
    $("#data").append($("<p>").append(this.F + " " + this.L));
})



http://jsfiddle.net/Q7cpm/2/

Wednesday, February 12, 2014

Pc setup ubuntu

apt-get update
apt-get install openjdk-7-jdk
apt-get install git

chmod +x xampp.....
./xamppp.run
run>> /opt/lampp/lampp start

apt-get install nginx
pico /etc/nginx/site-enabled/default

change >> port 8081 in the server block

Tuesday, February 11, 2014

Spring Image Upload

+public String pictureUpload(MultipartFile mpfGet,String userName,int x1,int y1,int w,int h) {
 +
 +// getting image and seeing output
 +MultipartFile mpf = mpfGet;
 +String extension = ".png";
 +// inserting image to the server
 +Rectangle rect = new Rectangle();
 +rect.height = h;
 +rect.width = w;
 +try {
 +BufferedImage src = ImageIO.read(mpf.getInputStream());
 +BufferedImage dest = src.getSubimage(x1, y1, rect.width, rect.height);
 +String rootPath = "/usr/local/var/www/";
 +File outputPath = new File(rootPath + "abc"+ extension);
 +ImageIO.write(dest, "png", outputPath);
 +} catch (IOException e) {
 +
 +}
 +return pictureName;
 +}



+ Dependencys
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>

</dependency>

Spring Send mail

//Dependencys

<dependency>

<groupId>javax.mail</groupId>

   <artifactId>mail</artifactId>

 <version>1.4</version>
</dependency>

// controller method 

@RequestMapping(value = "sendEmail/mailAddress/{mailAddress}", method = RequestMethod.POST )
 + public String sendEmail(Model model, @PathVariable String mailAddress) {
 +
 + SimpleMailMessage email = new SimpleMailMessage();
 + email.setTo("mail@gmail.com");
 + email.setSubject("Hello");
 + email.setText("Mail Testing....");
 +
 + // sends the e-mail
 + mailSender.send(email);
 + System.out.println("Mail sent...");
 + System.out.println("Mail sent..."+mailAddress);
 + return "regsuccess";
 + }




there is a servlet setting


<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="smtp.gmail.com"/>
        <property name="port" value="25"/>
        <property name="username" value="mail@gmail.com"/>
        <property name="password" value="your password"/>
        <property name="javaMailProperties">
            <props>
                <!-- Use SMTP transport protocol -->
                <prop key="mail.transport.protocol">smtp</prop>
                <!-- Use SMTP-AUTH to authenticate to SMTP server -->
                <prop key="mail.smtp.auth">true</prop>
                <!-- Use TLS to encrypt communication with SMTP server -->
                <prop key="mail.smtp.starttls.enable">true</prop>
                <prop key="mail.debug">true</prop>
            </props>
        </property>
    </bean>

Spring how to make a class a Controller and different method type in controller

package com.lynas.controller;
@Controller
@RequestMapping("/product")
public class ProductController {
@Autowired
private EUserService userDao; //for Service
//This is a normal method not a controller method
private String getCurrentUser(){
return "MyString";
}
//controller method for dealing with form post method
@RequestMapping(value="/registeruser", method = RequestMethod.POST)
public ModelAndView registerUser(HttpServletRequest request,@RequestParam String username,@RequestParam String password,@RequestParam String email){
 
return new ModelAndView(forwardPage); // this is for forwarding to a new model view
}
//controller method that just show the view
@RequestMapping(value="/home")
public ModelAndView home(){
return "home"; //home is the jsp page for view
}

@RequestMapping(value = "/addnewproduct", method = RequestMethod.POST)
@PreAuthorize("hasAnyRole('ROLE_USER')") // this is for defining which type of user can access this method
public String addNewProduct() {
 
return "myproduct";
}
@RequestMapping(value = "/getsubcategory")
@ResponseBody // this is a controller method for dealing with ajax call
public String approveOneUser(@RequestParam String category) {
return stringBuilder.toString();
}
@RequestMapping(value = "/addToWishlist/{itemId}") // this is for grabbing path variable
@PreAuthorize("hasAnyRole('ROLE_USER','ROLE_ADMIN')")
public String wishListAdd(@PathVariable int itemId) {
return "updated";
}
}

Google shortcut for I'm Feeling lucky

in the manage search add the following url


{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}{google:originalQueryForSuggestion}sourceid=chrome&ie={inputEncoding}&q=%s&btnI

Sunday, February 9, 2014

Hibernate Criteria

Criteria criteria = session.getCurrentSession().createCriteria(
Item.class);




criteria.addOrder(Order.desc("dateCreated"));

criteria.setMaxResults(1);

criteria.add(Restrictions.eq("email", email));

criteria.add(Restrictions.isNotNull("approvedBy"));

criteria.add(Restrictions.not(Restrictions.eq("empSal", 6700.0)));







return criteria.list();

return (Item) criteria.uniqueResult();




Hibernate by example

User user = new User();
user.setName("name"); //it does not take primary key e.g user.setId() wont consider for showing result

//

Example example = Example.create(user);


Criteria criteria = session.createCriteria(User.class).add(example)


//for ignoring
Example example = Example.create(user).excludeProperty("userName");

//for like property
user.setName("name %");
Example example = Example.create(user).enableLike()