Drop Down

Saturday, September 21, 2019

Spring_App_4

package amit.softwares.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import amit.softwares.beans.Company;

public class Test {

public static void main(String[] args)
{
ApplicationContext context = new ClassPathXmlApplicationContext("applicationcontext.xml");
Company com = (Company)context.getBean("com");
com.companydetails();
}

}

========================================================================
package amit.softwares.beans;

public class Company 
{
private String name;
private String headquater;
private String ceo;
private int numberofbranches;
private String networth;
public Company() 
{
System.out.println("---------Company Object Created---------");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getHeadquater() {
return headquater;
}
public void setHeadquater(String headquater) {
this.headquater = headquater;
}
public String getCeo() {
return ceo;
}
public void setCeo(String ceo) {
this.ceo = ceo;
}
public int getNumberofbranches() {
return numberofbranches;
}
public void setNumberofbranches(int numberofbranches) {
this.numberofbranches = numberofbranches;
}
public String getNetworth() {
return networth;
}
public void setNetworth(String networth) {
this.networth = networth;
}
public void companydetails()
{
System.out.println("------COMPANY DETAILS------");
System.out.println("NAME : "+getName());
System.out.println("HEADQUATER : "+getHeadquater());
System.out.println("CEO : "+getCeo());
System.out.println("NO. OF BRANCHES : "+getNumberofbranches());
System.out.println("NET WORTH : "+getNetworth());
System.out.println("---------------------------");
}

}

========================================================================
package amit.softwares.beans;

public class ShareMarket 
{
 public ShareMarket()
 {
System.out.println("------ShareMarket Objet Created-----");
 }
}

========================================================================
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="com" class= "amit.softwares.beans.Company">
<property name="name" value="AmitSoft"></property>
<property name="headquater" value="Ranchi"></property>
<property name="ceo" value="Amit Manjhi"></property>
<property name="numberofbranches" value="250"></property>
<property name="networth" value="500 Billion Dollors"></property>
</bean>  
<bean id="share" class= "amit.softwares.beans.ShareMarket">
</bean>      
</beans>        
=========================================================================

Spring_App_3

package com.amitsoft.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.amitsoft.beans.EmployeeBean;

public class Test {

public static void main(String[] args)
{
ApplicationContext context = new ClassPathXmlApplicationContext("applicationcontext.xml"); //created container and linked to xml
EmployeeBean emp = (EmployeeBean)context.getBean("empbean"); // it returns Object--so typecast to respective class
//emp.setName(name);  -- do these in xml <property>
        //emp.setCity(city);
        //emp.setSalary(salary);
String city = emp.getCity();
String name = emp.getName();
double sal = emp.getSalary();
System.out.println("Name: "+name+" || City: "+city+" || Salary: "+sal);
}

}
======================================================================
package com.amitsoft.beans;

public class EmployeeBean 
{
private String name;
private String city;
private double salary;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
  
}
=======================================================================
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id ="empbean" class="com.amitsoft.beans.EmployeeBean">
<property name="name" value="Amit"></property>
<property name="city" value="Ranchi"></property>
<property name="salary" value="500000"></property>
</bean>        
</beans>

Spring_App_2

package com.amitsoft.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.amitsoft.beans.HelloBean;

public class Test {

public static void main(String[] args)
{
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
HelloBean bean = (HelloBean)context.getBean("helloBean");
//bean.setName("Amit"); //---> use xml to set values
String msg = bean.sayhello();
System.out.println(msg);
}

}


========================================================================

package com.amitsoft.beans;

public class HelloBean 
{
private String name;
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String sayhello()
{
return "Hello "+getName()+" !";
}
}

========================================================================

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id= "helloBean" class = "com.amitsoft.beans.HelloBean">
<property name="name" value="Amit"></property>
</bean>
</beans>

========================================================================

Spring_App_1

package com.durgasoft.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.durgasoft.beans.HelloBean;

/*
2 types of container
---------------------
bean factory
application context
*/

public class Test {

public static void main(String[] args)
{
ApplicationContext context = new ClassPathXmlApplicationContext("appplicationContext.xml"); //container created
HelloBean bean = (HelloBean)context.getBean("helloBean");
String message = bean.sayHello();
System.out.println(message);


}

}

======================================================================
package com.durgasoft.beans;

public class HelloBean
{
public String sayHello()
{
return "Hello User!";
}

}

=====================================================================
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="helloBean" class="com.durgasoft.beans.HelloBean"/>        
</beans>

Code to Move log dump to another location

package com.amit.model;

import java.io.File;
import java.io.FileInputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

public class ScanToMoveFolder
{
static File source1 = null;
static File dest1 = null;
public static void main(String[] args)
{
//***************************READING PROPERTIES FILE*****************
try
{
  FileInputStream ip = new FileInputStream("config.properties");
  Properties prop = new Properties();
  prop.load(ip);
  source1 = new File(prop.getProperty("fromPath_1"));
  dest1 = new File(prop.getProperty("toPath_1"));
 
  ProcessData p1 = new ProcessData();
  Thread t1 = new Thread(p1);
  t1.start();  
 
}
catch(Exception e)
{
e.printStackTrace();
}

}


}



=====================================================================

package com.amit.model;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.io.FileUtils;

public class ProcessData implements Runnable
{
private boolean keepRunning = true;
private File source1 = ScanToMoveFolder.source1;
private File dest1 = ScanToMoveFolder.dest1;
ProcessData pro;
public String timestamp = null;
public void stop()
{
keepRunning = false;
}
private  String gettime()
{
DateFormat dateFormat = new SimpleDateFormat("dd-M-yyyy");
Date date = new Date();
return dateFormat.format(date);
}
private  String getDatetime()
{
DateFormat dateFormat = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
Date date = new Date();
return dateFormat.format(date);
}

public void run()
{
while(keepRunning)
{
try
{
timestamp = gettime();
System.out.println("TIMESTAMP::>> "+timestamp);
copyFolder(source1,dest1);
deleteFiles(source1);
System.out.println("*********************************************************");
System.out.println("************UTILITY IS SLEEPING FOR  24 HR***************");
System.out.println("*********************************************************");
System.out.println("*****Utility started to sleep at :"+getDatetime()+"******");
System.out.println("*********************************************************");
Thread.sleep(1000*60*60*24);
}
catch(Exception e)
{
e.printStackTrace();
}
}

}

private void copyFolder(File sourceFolder, File destinationFolder)
{
try
{
System.out.println("source folder "+sourceFolder);
System.out.println("destination folder "+destinationFolder);
if(sourceFolder.isDirectory())
{
if(!destinationFolder.exists())
{
destinationFolder.mkdir();
System.out.println("Directory Created :: "+destinationFolder);
}
String path = check_if_leaf_directory(sourceFolder,destinationFolder); //$$$$$$$$$$$$$$$$$$$$$$$$
System.out.println("Path::"+path);
File path_file = new File(path);
destinationFolder = path_file;
String files[] = sourceFolder.list();
for(String file : files)
{
//boolean dir_flag = false;
File srcFile = new File(sourceFolder,file);
File destFile = new File(destinationFolder,file);
copyFolder(srcFile,destFile);
}
}
else
{
//Files.copy(sourceFolder.toPath(), destinationFolder.toPath(), StandardCopyOption.REPLACE_EXISTING); //---> for java 7 and above
FileUtils.copyFile(sourceFolder, destinationFolder);  //----> for java 1.6 and lower
System.out.println("File copied :: "+destinationFolder);
}

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

}

private String check_if_leaf_directory(File dir, File destination)
{
String path = destination.toString();
System.out.println("path********* "+path);
try
{
File[] files = dir.listFiles();
for(File file : files)
{
if(!file.isDirectory())
{
String destination_appended_path_str = (destination + File.separator +timestamp);
File destination_appended_path_file = new File(destination_appended_path_str);
destination_appended_path_file.mkdir();

path = destination_appended_path_file.toString();
System.out.println("<<path>>"+path);
}
else
{

}

}

}
catch(Exception e)
{
e.printStackTrace();
}
return path;
}
private void deleteFiles(File dir)
{
try
{
  File[] files = dir.listFiles();
  for(File file1 : files)
  {
  if(file1.isDirectory())
  {
  System.out.println("Directory: "+file1.getCanonicalPath());
  deleteFiles(file1);
  }
  else
  {
  file1.delete();
  System.out.println("inside else..."+file1.getAbsolutePath());
  }
 
  }
}
catch(Exception e)
{
e.printStackTrace();
}

}

}



============================config.properties==========================

fromPath_1 = D:\\\\work\\TestEnv\\source
toPath_1 = D:\\\\work\\TestEnv\\destination







Sunday, July 28, 2019

Form Development by using Bootstrap elements:

<form>
<!-- EMAIL SUBMISSION -->
<div class="form-group"> <label for="exampleInputEmail1">Email address</label> <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email"> <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small> </div>

<!-- PASSWORD -->
<div class="form-group"> <label for="exampleInputPassword1">Password</label> <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password"> </div>

<!-- DROPDOWN SELECT -->
<div class="form-group"> <label for="exampleSelect1">Example select</label> <select class="form-control" id="exampleSelect1"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> </div>

<!-- MULTIPLE SELECT OPTIONS -->
<div class="form-group"> <label for="exampleSelect2">Example multiple select</label> <select multiple class="form-control" id="exampleSelect2"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> </div>

<!-- TEXT AREA -->
<div class="form-group"> <label for="exampleTextarea">Example textarea</label> <textarea class="form-control" id="exampleTextarea" rows="3"></textarea> </div>

<!-- FILE UPLOAD INPUT -->
<div class="form-group"> <label for="exampleInputFile">File input</label> <input type="file" class="form-control-file" id="exampleInputFile" aria-describedby="fileHelp"> <small id="fileHelp" class="form-text text-muted">This is some placeholder block-level help text for the above input. It's a bit lighter and easily wraps to a new line.</small> </div>

<!-- RADIO BUTTONS -->
<fieldset class="form-group"> <legend>Radio buttons</legend> <div class="form-check"> <label class="form-check-label"> <input type="radio" class="form-check-input" name="optionsRadios" id="optionsRadios1" value="option1" checked> Option one is this and that&mdash;be sure to include why it's great </label> </div>

<div class="form-check"> <label class="form-check-label"> <input type="radio" class="form-check-input" name="optionsRadios" id="optionsRadios2" value="option2"> Option two can be something else and selecting it will deselect option one
</label> </div>
<div class="form-check disabled"> <label class="form-check-label"> <input type="radio" class="form-check-input" name="optionsRadios" id="optionsRadios3" value="option3" disabled> Option three is disabled </label> </div>
</fieldset>

<!-- CHECK BUTTON -->
<div class="form-check"> <label class="form-check-label"> <input type="checkbox" class="form-check-input"> Check me out </label> </div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
Note: The <fieldset> tag is used to group related elements in a form.



Wednesday, June 5, 2019

Create Excel :- Header/color/columns etc...

package Excel_create_style;

import org.apache.poi.*;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.PatternFormatting;

import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class Test2 {

public static void main(String[] args)
{
  //Workbook workbook = new XSSFWorkbook();
  Workbook workbook = new HSSFWorkbook();  
  Sheet sheet1 = workbook.createSheet("sheet1");
  Sheet sheet2 = workbook.createSheet("sheet 2");
  HSSFRow row;
 
  Row header = (HSSFRow) sheet1.createRow(0);
  sheet1.addMergedRegion(new CellRangeAddress(0,0,1,7)); //--Merge
  header.createCell(1).setCellValue("Output Structure"); //
  //Heder style
  Font font_h = workbook.createFont();
  font_h.setBold(true);
  font_h.setFontHeightInPoints((short)12);
  CellStyle Styleheader = workbook.createCellStyle();
  Styleheader.setAlignment(HorizontalAlignment.CENTER);  
  Styleheader.setFont(font_h);
  Styleheader.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
  Styleheader.setFillPattern(FillPatternType.SOLID_FOREGROUND);
 
  header.getCell(1).setCellStyle(Styleheader);
 
  //************************************
 
     
  //************************************
 
  //--- Row 2 me ye headers aaega
  row = (HSSFRow) sheet1.createRow(2);
  row.setHeight((short) 500);

  row.createCell(1).setCellValue("Segment");
  row.createCell(2).setCellValue("Region");
  row.createCell(3).setCellValue("Borrower Name");
  row.createCell(4).setCellValue("RM Name");
  row.createCell(5).setCellValue("Date Full Information received");
  row.createCell(6).setCellValue("Date Letter Issued");
  row.createCell(7).setCellValue("Date RM Letter Requested");
 
 
  //---
  //----Font Formatting
 
  for(int i =1;i<=7;i++) {
  CellStyle stylerowHeading = workbook.createCellStyle();
  Font font = workbook.createFont();
  font.setBold(true);
  font.setFontHeightInPoints((short)10);
  stylerowHeading.setFont(font);
  stylerowHeading.setAlignment(HorizontalAlignment.CENTER);
  stylerowHeading.setVerticalAlignment(VerticalAlignment.CENTER);
  stylerowHeading.setFillForegroundColor(IndexedColors.TURQUOISE.getIndex());
  stylerowHeading.setFillPattern(FillPatternType.SOLID_FOREGROUND);
 
  stylerowHeading.setBorderLeft(BorderStyle.MEDIUM);
  stylerowHeading.setBorderRight(BorderStyle.MEDIUM);
  stylerowHeading.setBorderTop(BorderStyle.MEDIUM);
  stylerowHeading.setBorderBottom(BorderStyle.MEDIUM);
 
  row.getCell(i).setCellStyle(stylerowHeading);
  }
 
  //------Auto Fit
  for(int i =1;i<=7;i++)
  {
  sheet1.autoSizeColumn(i);
  }
 
 
  //*****************
  //CellStyle dynamic_rows = workbook.createCellStyle();
  //dynamic_rows.setBorderLeft(BorderStyle.THIN);
  //dynamic_rows.setBorderRight(BorderStyle.THIN);
  //dynamic_rows.setBorderBottom(BorderStyle.THIN);
 
  //******************
 
  String[] rowVal = new String[7];
  insertrowVal(rowVal);  
  Map < String, String[]> m = new LinkedHashMap < String, String[] >();
  //m.put( "1", rowVal);
  m.put( "1", rowVal);
  m.put( "2", rowVal);
  m.put( "3", rowVal);
  m.put( "4", rowVal);
  m.put( "5", rowVal);
   
//Iterate over data and write to sheet
      Set <String> keyid = m.keySet();
      int rowid = 3;

      for (String key : keyid) {
    row = (HSSFRow) sheet1.createRow(rowid++);
         String [] str = m.get(key);
         int cellid = 1;
     
         for (String obj : str)
         {
        //row.getCell(cellid).setCellStyle(dynamic_rows);
            Cell cell = row.createCell(cellid++);
            cell.setCellValue((String)obj);
           
         }
      }
     
  try
  {
  FileOutputStream output = new FileOutputStream("D:\\work\\newgen2.xls");
  workbook.write(output);
  output.close();
  System.out.println("File created ....");

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

private static void insertrowVal(String[] rowVal)
{
rowVal[0]="apple";
rowVal[1]="Orange";
rowVal[2]="Banana";
rowVal[3]="Mango";
rowVal[4]="Papaya";
rowVal[5]="Lichy";
rowVal[6]="Grapes";

}

}

----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
JARS :- poi-bin-4.1.0-20190412.tar





Java 8 Notes Pics