Monday, 30 September 2019

HTML:JAVASCRIPT : Call command prompt

HTML:JAVASCRIPT : Call command prompt 


###################################################################
Requirement:

1. We have jar file -> Test.jar -> which internally calls RESt service and get the result

 Eg: java -jar Test.jar submit -input-file "C:\Users\pamr\Desktop\Files\STD_IMPORT\AccountCreateUpdate_139_12Rows.csv" -import-name "DLAccJob" -mapping-number 300100179141400 -object Account -u mhoope -target-url https://ABC.com -wallet -encoding UTF8

2. Instead of user remember and typing each and every command this will give UI (html + javascript) and when user click on "Submit Job" button internally it invokes BAT file and open the command prompt.

Flow is :
              HTML + Javascript -> Click on button
              Javascript calls BAT file by passing all user entered parameter
              BAT file open up the command prompt and execute the command

###################################################################










##########################CallCommandPrompt.html#################################

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {font-family: Arial;}

.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 12px 26px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 3px 2px;
cursor: pointer;
}

.button2 {background-color: #008CBA;} /* Blue */
.button3 {background-color: #f44336;} /* Red */
.button4 {background-color: #e7e7e7; color: black;} /* Gray */
.button5 {background-color: #555555;} /* Black */

::placeholder { /* Chrome, Firefox, Opera, Safari 10.1+ */
color: grey;
opacity: 1; /* Firefox */
}

:-ms-input-placeholder { /* Internet Explorer 10-11 */
color: grey;
}

::-ms-input-placeholder { /* Microsoft Edge */
color: grey;
}

table {
border-collapse: collapse;
width: 100%;
}

th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}

tr:hover {background-color:#f5f5f5;}

/* Style the tab */
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}

/* Style the buttons inside the tab */
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
}

/* Change background color of buttons on hover */
.tab button:hover {
background-color: #ddd;
}

/* Create an active/current tablink class */
.tab button.active {
background-color: #ccc;
}

/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
</style>
<script language="javascript" type="text/javascript">
function submitImportJob()
{
//alert('coming111');
var loc = window.location.pathname;
var dirLoc = loc.substring(1, loc.lastIndexOf('/'))+'/';
//alert('jar location is : '+dirLoc);

var infile = document.getElementById("infile").value;
var jobname = document.getElementById("jobname").value
var mapNumber = document.getElementById("mapNumber").value
var objectCode = document.getElementById("objectCode").value
var username = document.getElementById("username").value
var targetURL = document.getElementById("targetURL").value
var highVolumeChecked = document.getElementById("highvolume").checked
var highVolume= '';
if(highVolumeChecked == true){
    highVolume = '-high-volume';
}
else{
    highVolume= '';
}
//alert('highVolume : '+highVolume);
var parameters = '"'+infile+'" "'+jobname+'" "'+mapNumber+'" "'+objectCode+'" "'+username+'" "'+targetURL+'" "'+dirLoc+'" "'+highVolume+'"';

//alert('Parameters are : '+infile+' : '+jobname+' : '+mapNumber+' : '+objectCode+' : '+username+' : '+targetURL);
//alert('Parameters are : '+parameters);
var shell = new ActiveXObject("WScript.Shell");
//alert('coming3333333 : going to run bat file.. ');
shell.run( '"C:\\Users\\pamr\\Desktop\\CustBugs2019\\EDLC_HTML\\submit.bat" ' + parameters, 1, true );
//shell.Run("C:\\Users\\pamr\\Desktop\\CustBugs2019\\EDLC_HTML\\submit.bat");
}

function getJobStatus()
{
//alert('coming111');
var loc = window.location.pathname;
var dirLoc = loc.substring(1, loc.lastIndexOf('/'))+'/';
//alert('jar location is : '+dirLoc);


var jobid = document.getElementById("jobid").value
var username = document.getElementById("username").value
var targetURL = document.getElementById("targetURL").value
var parameters = '"'+jobid+'" "'+username+'" "'+targetURL+'" "'+dirLoc+'"';

//alert('Parameters are : '+infile+' : '+jobname+' : '+mapNumber+' : '+objectCode+' : '+username+' : '+targetURL);
//alert('Parameters are : '+parameters);
var shell = new ActiveXObject("WScript.Shell");
//alert('coming3333333 : going to run bat file.. ');
shell.run( '"C:\\Users\\pamr\\Desktop\\CustBugs2019\\EDLC_HTML\\status.bat" ' + parameters, 1, true );
//shell.Run("C:\\Users\\pamr\\Desktop\\CustBugs2019\\EDLC_HTML\\status.bat");
}

function getLogs()
{

}
</script>
</head>
<body>
<img src="LOGO-Oracle-Sales-Cloud.png" alt="Smiley face" height="80" width="120">


<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')" id="defaultOpen">Submit Job</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">Get Status</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">Get Logs</button>
</div>

<div id="London" class="tabcontent">
<h2 align="center"> Job Details:</h2>
<table id="table1"; cellspacing="5px" cellpadding="5%"; align="center" border="1">

<tr>
<td bgcolor="#EBEBEC" align="right" class="style1">Input File</td>
<td class="style1"><input id="infile" type="file" size="36" /> &nbsp;&nbsp;<font style="color:#CFD0D0;font-size:1vw;">Eg : C:\TestFolder\InputFile.csv</font></td>
</tr>
<tr>
<td bgcolor="#EBEBEC" align="right">Job Name:</td>
<td><input type="text" id="jobname" name="Job Name" maxlength="50" size="50" value="Test_EDLC_Job"/> &nbsp;&nbsp;<font style="color:#CFD0D0;font-size:1vw;">Eg : Test_Job</font></td>
</tr>
<tr>
<td bgcolor="#EBEBEC" align="right">Map number:</td>
<td><input type="text" id="mapNumber" name="Map number" size="50" value="300100228574876"/> &nbsp;&nbsp;<font style="color:#CFD0D0;font-size:1vw;">Eg : 3000003012345</font></td>
</tr>
<tr>
<td bgcolor="#EBEBEC" align="right">Object Code</td>
<td><input type="text" id="objectCode" name="Object Code" size="50" value="Account"/> &nbsp;&nbsp;<font style="color:#CFD0D0;font-size:1vw;">Eg : Account</font></td>
</tr>
<tr>
<td bgcolor="#EBEBEC" valign="top" align="right">Usser name:</td>
<td><input type="text" id="username" name="Usser name" size="50" value="Mhoope"/> &nbsp;&nbsp;<font style="color:#CFD0D0;font-size:1vw;">Eg : MHoope</font></td>
</tr>
        <tr>
<td bgcolor="#EBEBEC" valign="top" align="right">Target URL:</td>
<td><input type="text" id="targetURL" name="Target URL" size="50" value="https://fuscdrmsmc139-fa-ext.us.oracle.com"/> &nbsp;&nbsp;<font style="color:#CFD0D0;font-size:1vw;">Eg : https://fuscdrmsmc139-fa-ext.us.oracle.com</font></td>
</tr>   
<tr>
<td bgcolor="#EBEBEC" align="right">High Volume</td>
<td><input type="checkbox" name="highvolume" id="highvolume" /></td>
</tr>

</table>
<!--    <p align="center"><input type="button" onclick="submitImportJob();" value="Submit EDLC Job"/></p> -->
    <p align="center"><button onclick="submitImportJob();" class="button button2">Submit EDLC Job</button></p>
</div>

<div id="Paris" class="tabcontent">
<h2 align="center">Get Job Status:</h2>
    
<table id="table1"; cellspacing="5px" cellpadding="5%"; align="center" border="1">

<tr>
<td bgcolor="#EBEBEC" align="right">Job Id:</td>
<td><input type="text" id="jobid" name="Job Id" maxlength="50" size="50" value="300100229316412"/> &nbsp;&nbsp;<font style="color:#CFD0D0;font-size:1vw;">Eg : 3000003012998</font></td>
</tr>
<tr>
<td bgcolor="#EBEBEC" valign="top" align="right">Usser name:</td>
<td><input type="text" id="username2" name="Usser name" maxlength="50" size="50" value="Mhoope"/> &nbsp;&nbsp;<font style="color:#CFD0D0;font-size:1vw;">Eg : MHoope</font></td>
</tr>
        <tr>
<td bgcolor="#EBEBEC" valign="top" align="right">Target URL:</td>
<td><input type="text" id="targetURL2" name="Target URL" maxlength="50" size="50" value="https://fuscdrmsmc139-fa-ext.us.oracle.com"/> &nbsp;&nbsp;<font style="color:#CFD0D0;font-size:1vw;">Eg : https://fuscdrmsmc139-fa-ext.us.oracle.com</font></td>
</tr>

</table>
<!-- <p align="center"><input type="button" onclick="getJobStatus();" value="Get Job Status"/></p> -->
<p align="center"><button onclick="getJobStatus();" class="button button2">Get Job Status</button></p>
</div>

<div id="Tokyo" class="tabcontent">
<h2 align="center">Get Logs:</h2>
    
<table id="table1"; cellspacing="5px" cellpadding="5%"; align="center" border="1">

<tr>
<td bgcolor="#EBEBEC" align="right">Job Id:</td>
<td><input type="text" name="Map number" maxlength="50" size="50"/> &nbsp;&nbsp;<font style="color:#CFD0D0;font-size:1vw;">Eg : 3000003012998</font></td>
</tr>
<tr>
<td bgcolor="#EBEBEC" valign="top" align="right">Usser name:</td>
<td><input type="text" name="Usser name" maxlength="50" size="50"/> &nbsp;&nbsp;<font style="color:#CFD0D0;font-size:1vw;">Eg : MHoope</font></td>
</tr>
        <tr>
<td bgcolor="#EBEBEC" valign="top" align="right">Target URL:</td>
<td><input type="text" name="Target URL" maxlength="50" size="50"/> &nbsp;&nbsp;<font style="color:#CFD0D0;font-size:1vw;">Eg : https://fuscdrmsmc139-fa-ext.us.oracle.com</font></td>
</tr>
     <tr>
     <td bgcolor="#EBEBEC" align="right">Log Type:</td>
     <td>
<select name="drop1" size="4" id="Qualifiation" size="4" multiple="multiple" >
<option value="1" >All</option>
<option value="2">Success Log</option>
<option value="3">Error Log</option>
<option value="4">Rejected Log</option>
</select>
</td>
</tr>
        <tr>
<td bgcolor="#EBEBEC" valign="top" align="right">Output path:</td>
<td><input type="text" name="Output path" maxlength="50" size="50"/> &nbsp;&nbsp;<font style="color:#CFD0D0;font-size:1vw;">Eg : C:\</font></td>
</tr>        

</table>
<!-- <p align="center"><input type="button" onclick="getLogs();" value="Get Logs"/></p> -->
<p align="center"><button onclick="getLogs();" class="button button2">Get Logs</button></p>
</div>

<script>
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}

// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();

</script>
<br>
<br>
<p style="color:#CFD0D0;font-size:1vw;">EDLC Action, fill the details and submit, command prompt will open to check the output</p>
</body>
</html>

#####################submit.bat ############################################

ECHO OFF
set infile=%1
set jobname=%2
set mapNumber=%3
set objectCode=%4
set username=%5
set targetURL=%6
set dirLocation=%7
set highVolume=%8
REM cd C:\\EDLC_HTML\\
cd
echo ####################################################################################################
echo java -jar Test.jar submit -input-file %infile% -import-name %jobname% -mapping-number %mapNumber% -object %objectCode% -u %username% -target-url %targetURL% %highVolume% -wallet -encoding UTF8
echo ####################################################################################################
java -jar Test.jar savepassword -username %username%
java -jar Test.jar submit -input-file %infile% -import-name %jobname% -mapping-number %mapNumber% -object %objectCode% -u %username% -target-url %targetURL% %highVolume% -wallet -encoding UTF8

echo Completed successfully
PAUSE

#####################status.bat ############################################

ECHO OFF
set jobid=%1
set username=%2
set targetURL=%3
set dirLocation=%4
REM cd C:\\EDLC_HTML\\

echo ####################################################################################################
echo java -jar Test.jar status -import-activity %jobid% -u %username% -target-url %targetURL% -wallet
echo ####################################################################################################
java -jar Test.jar savepassword -username %username%
java -jar Test.jar status -import-activity %jobid% -u %username% -target-url %targetURL% -wallet

PAUSE

Tuesday, 28 November 2017

JAVA : Take Screenshot, Schedule Program, Send Mail.

JAVA : Take Screenshot, Schedule Program, Send Mail.


1. Take Screenshot:


##############################################################################

import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Date;

import javax.imageio.ImageIO;

public class RobotExp {
  
    public static void main(String[] args) {
      
        try {
            Date a = new Date();
            Robot robot = new Robot();
            // Capture the screen shot of the area of the screen defined by the rectangle
            BufferedImage bi=robot.createScreenCapture(new Rectangle(1000,1000));
            ImageIO.write(bi, "jpg", new File("D:/tt/imageTest.jpg"));
          
        } catch (AWTException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
##############################################################################

2. Schedule Program

##############################################################################

 import java.awt.Toolkit;
import java.util.Timer;
import java.util.TimerTask;
/**
 * Simple demo that uses java.util.Timer to schedule a task to execute once 5
 * seconds have passed.
 */
public class ReminderBeep {
  Toolkit toolkit;
  Timer timer;
  public ReminderBeep(int seconds) {
    toolkit = Toolkit.getDefaultToolkit();
    timer = new Timer();
    timer.schedule(new RemindTask(), seconds * 1000);
  }
  class RemindTask extends TimerTask {
    public void run() {
      System.out.println("Time's up!");
      toolkit.beep();
      String args[] = new String[3];
      main(args);
      //timer.cancel(); //Not necessary because we call System.exit
      //System.exit(0); //Stops the AWT thread (and everything else)
    }
  }
  public static void main(String args[]) {
    System.out.println("About to schedule task.");
    new ReminderBeep(5);
    System.out.println("Task scheduled.");
  }
}

    

##############################################################################

3. Send Mail

For this we need 2 Jars:
   a. javax.mail.jar
   b. activation-1.0.2.jar

Then we need: SMTP host, port

############################################################################## 

 

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SendFileEmail
{
   public static void main(String [] args)
   {
      
      // Recipient's email ID needs to be mentioned.
      String to = "pavan.x.mr@oracle.com";

      // Sender's email ID needs to be mentioned
      String from = "web@gmail.com";

      // Assuming you are sending email from localhost
      String host = "localhost";

      // Get system properties
      Properties properties = System.getProperties();

      // Setup mail server
      properties.setProperty("mail.smtp.host", host);
      properties.setProperty("mail.smtp.port", "465");

      // Get the default Session object.
      Session session = Session.getDefaultInstance(properties);

      try{
         // Create a default MimeMessage object.
         MimeMessage message = new MimeMessage(session);

         // Set From: header field of the header.
         message.setFrom(new InternetAddress(from));

         // Set To: header field of the header.
         message.addRecipient(Message.RecipientType.TO,
                                  new InternetAddress(to));

         // Set Subject: header field
         message.setSubject("This is the Subject Line!");

         // Create the message part
         BodyPart messageBodyPart = new MimeBodyPart();

         // Fill the message
         messageBodyPart.setText("This is message body");
         
         // Create a multipar message
         Multipart multipart = new MimeMultipart();

         // Set text message part
         multipart.addBodyPart(messageBodyPart);

         // Part two is attachment
         messageBodyPart = new MimeBodyPart();
         String filename = "file.txt";
         DataSource source = new FileDataSource(filename);
         messageBodyPart.setDataHandler(new DataHandler(source));
         messageBodyPart.setFileName(filename);
         multipart.addBodyPart(messageBodyPart);

         // Send the complete message parts
         message.setContent(multipart );

         // Send message
         Transport.send(message);
         System.out.println("Sent message successfully....");
      }catch (MessagingException mex) {
         mex.printStackTrace();
      }
   }
}

##############################################################################

 

JAVASCRIPT : Increase youtube views

JAVASCRIPT : Increase youtube views



Test.html
###########################################################

<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
  for (i = 0; i < 5; i++) {
       window.open("https://www.youtube.com/watch?v=IFm2p_T48qM");
  }
 
}
</script>

</head>
<body>

<p>Click the button to open a new browser window.</p>

<button onclick="myFunction()">Try it</button>



</body>
</html>