Skip to main content


Showing posts from June 8, 2016

Create Empty tag in Jaxb2 javax.xml.bind.context.factory = org.eclipse.persistence.jaxb.JAXBContextFactory

package com.infodart.central.integration.demo.entity; import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType; import org.eclipse.persistence.oxm.annotations.XmlMarshalNullRepresentation;
import org.eclipse.persistence.oxm.annotations.XmlNullPolicy; import com.infodart.central.integration.demo.util.Constants;
@XmlRootElement(name = "WHDEO")
@XmlType(propOrder = { "state", "currencyCode", "email", "country", "orgUnitId", "warehouseId", "warehouseN…

Writing List as CSV

import org.supercsv.cellprocessor.Optional;
import org.supercsv.cellprocessor.ift.CellProcessor;
import org.supercsv.prefs.CsvPreference;

private static void writeWithCsvBeanWriter(
ArrayList<ExportScreenDTO> lstExport) throws Exception { String currentTime = new SimpleDateFormat("ddMMyy_HHmmss")
.format(new Date());

String newFileName = currentTime + "_DashboardExport.csv";
ICsvBeanWriter beanWriter = null;
try {
beanWriter = new CsvBeanWriter(new FileWriter(
"D:\\Shoppers_Dashboard\\" + newFileName),
CsvPreference.STANDARD_PREFERENCE); // the header elements are used to map the bean values to each
// column (names must match)
final String[] header = new String[] { "storeId",
"masterInterface", "group", "startTime", "endTime",
"totalTime", "finalStatus", "staging", "oraposPull",

Save jsp/list/hashmap/table data to Excel with help of apache poi

Sample Method to writing Excel with apache POI.

private void exportDetailSuccessReport(HttpServletRequest request, HttpServletResponse response,
List<HashMap<String, MasterListSuccessStoresDTO>> successStoreListOfList, ArrayList<FailedStoresDTO> lstScreen) { response.setContentType("application/");
HSSFWorkbook wb = new HSSFWorkbook();
ConfigurationBean configBean = (ConfigurationBean) BeanLocator.getServiceBean(ConfigurationBean.IMPORT_CONFIGURATION_BEAN);
String tempPath = configBean.getImportFilesPath();
File folder = new File(tempPath + File.separator + "Shoppers_Dashboard");
if (!folder.exists()) {
} File fl = new File(folder + File.separator + "Detail_report.xls"); List<HashMap<String, MasterListSuccessStoresDTO>> lstHmapOfMasterDto = successStoreListOfList;
if ((null != lstHmapOfMasterDto) && lstHmapOfMasterDto.size() > 0) {
HSSFSheet …

Equals & Hashcode Concepts

package org;
import java.util.HashSet;
import java.util.Set;
public class TestClass {
public static void main(String args[]){

Emp emp1 = new Emp("Amit","Gupta"); 
Emp emp2 = new Emp("Gupta","Amit"); 
Set s = new HashSet();


String fName="Amit" ;
String lName = "Gupta" ; 
int hashcode = fName.hashCode()+lName.hashCode();

System.out.println("Hahcode of class = "+emp1.hashCode());
System.out.println("Hahcode of f and l Name = "+hashcode);



package org;
import java.util.HashSet;
import java.util.Set;
public class Emp {
String fName ;
String lName;

Emp(String s, String p){
this.fName = s;
this.lName =p;


public String getfName() {
return fName;

public void setfName(String fName) {
this.fName = fName;

public String getlName() {
return lName;

public void setlName(Str…

Timer class to call class on set time and after certain interval.... like cron

**************************object to call****************************** package com.infodart.timer;

import java.util.Date;

public class Target {

public java.util.Date callTargetMethod(){

Date d = new Date();
return d;

package com.infodart.timer;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Timer;
import java.util.TimerTask;

public class MyTimerTask extends TimerTask {
private final static long ONCE_PER_DAY = 1000*60*60*24;

//private final static int ONE_DAY = 1;
private final static int TWO_AM = 2;
private final static int ZERO_MINUTES = 0;

public void run() {

Target target = new Target();
Date result = target.callTargetMethod();
System.out.println("result is "+result);

private static Date ScheduleTimerStart(){

Calendar cal = Calendar.getInstance();

Unix Vi Editor commands

To Start vi
1. vi filename Create or Edit filename starting at line 1
2. vi -r filename Recover filename that was being edited
when system crashed

To Exit vi
1. :x<return> Quit vi, writing out modified file to file
named in original invocation
2. :wq<return> Quit vi, writing out modified file to file
named in original invocation
3. :q<return> Quit or exit vi
4. :q!<return> Quit vi even though latest changes have not
been saved for this vi call

 cursor Movment
1. j or <return>
[or down-arrow]
Move cursor down one line
2. k[or up-arrow] Move cursor up one line
3. h or<backspace>
[or left-arrow]
Move cursor left one line
l or<space>[or right-arrow] Move cursor right one line
4. 0(zero) Move cursor to start of current line(the one
with the arrow)
5. $ Move cursor to end of the current line
6. w Move cursor to beginning of next word
Basic vi commands7. b Move cursor back to beginning of preceding
8. :0<return> or 1G Move cursor to first line in file
9. :n<return…

Groovy Elvis Operator

Groovy Elvis Operator
In Java we do  so many null checks  If (somevalue != null) {
    val = somevalue
} else { 
    val = defaultValue 
} Instead of writing if (something != null) { ... }  we write if (something) { ... } Well this type of branching logic is precisely why we have the ternary operator in both Java and Groovy.  It turns our 4 lines of if/else logic into a single line like: val = something ? something : defaultValue The syntax and logic for the ternary operator is the same in Groovy as it is in Java; (Condition) ? Value-If-True : Value-If-False Instead of writing:  val = something ? something : defaultValue
We could write:  val = something ?: defaultValue A more clear example would be as follows: def actor
def defaultactor = actor?: "Ven Diesel"
assert defaultrockstar == "Ven Diesel"
Elvis operator useful but repetition is still around it so it could be like  ef actor
def defaultactor = actor?: "Ven Diesel" further we can simplify like  def actor
actor?= "Ven…

Git command handout

Rebase from master $ gitk --simplify-by-decoration refload_1_0_1_0 refload_1_0_3_0 refload_1_0_2_0 refload_1_0_1_0
Get remote repositry git remote -v
If needed  a copy of code to work in that (similar svn checkout) clone:  git clone git@yourserver:repository/abc.git
if want to switch to create new branch of git ( first clone complete repository as above then checkout) checkout: git checkout -b abc_9_18_0_0 checkout: git checkout  abc_9_18_0_0  (if want to checkout to existing git branch)
if want to add files to index add:  git add -A   (for adding all files)
want to check status of repository ( if any non traced file is  present) status : git status -s
want to commit  commit: git commit -m 'message for commit for tracking purpose'
want to push code to branch push: git push origin abc_9_18_0_0  (don't put semicolon otherwise whole branch will get delete instead)