Drop Down

Saturday, September 21, 2019

Spring_App_5

package com.amitsoft.start;

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

import com.amitsoft.beans.WelcomeBean;

public class Test {

public static void main(String[] args)
{
  ApplicationContext context = new ClassPathXmlApplicationContext("applicationconfig.xml");
  WelcomeBean bean = (WelcomeBean)context.getBean("welbean");
  String name = bean.getName();
  System.out.println("WELCOME "+name);
}

}

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

public class WelcomeBean 
{
String name;

public String getName() {
return name;
}

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

}

========================================================================
<?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="welbean" class="com.amitsoft.beans.WelcomeBean">
<property name="name" value="AMIT"></property>
</bean>
</beans>
========================================================================

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.



Java 8 Notes Pics