Mostrando entradas con la etiqueta Java. Mostrar todas las entradas
Mostrando entradas con la etiqueta Java. Mostrar todas las entradas

jueves, 11 de febrero de 2021

Consuming API REST services from Java applications

 

// Download library here.

 
package demo;

//import java.io.BufferedReader;
import java.util.Iterator;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

//import java.io.File;  // Import the File class
//import java.io.FileNotFoundException;  // Import this class to handle errors
//import java.util.Scanner; // Import the Scanner class to read text files

public class Book
{
    public static void main(String[] args)
    {
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target("https://localhost:8090/webservice.php?opcion=get");
               
        Invocation.Builder invoBuilder = target.request(MediaType.APPLICATION_JSON);
        Response response = invoBuilder.get();
       
        //int k = 0;
        //String data = "";
       
        try
        {
        if(Response.Status.OK.getStatusCode() == response.getStatus())
        {
            //k++;
           
            String json = response.readEntity(String.class);
            //jsonPlanet = jsonPlanet.replace("[", "").replace("]", "");
            //json = json.replace("{\"" + String.valueOf(k) + "\":", "");
           
            System.out.println(json);
           
            /*try {
                File myObj = new File("D:\\Resultado.txt");
                Scanner myReader = new Scanner(myObj);
                while (myReader.hasNextLine()) {
                  data = myReader.nextLine();
                  System.out.println(data);
                }
                myReader.close();
              } catch (FileNotFoundException e) {
                System.out.println("An error occurred.");
                e.printStackTrace();
              }*/
           
            // JSONObject obj = new JSONObject(json);
           
            JSONObject obj = new JSONObject(json);
           
            //JSONObject songs= json.getJSONObject("songs");
            Iterator x = obj.keys();
            JSONArray jsonArray = new JSONArray();
           
            int y = 0;

            while (x.hasNext()){
                String key = (String) x.next();
                jsonArray.put(obj.get(key));
                System.out.println(jsonArray.getJSONObject(y));
                LeerCamposJSON(jsonArray.getJSONObject(y).toString());
                y++;
            }
           
            /*for(int i=0; i<arr.length(); i++){  
                  JSONObject o = arr.getJSONObject(i); 
                  System.out.println(o); 
                }*/  
        }
        /*else
        {
            System.out.println("Error contacting the web service! " + response.getStatus());
        }*/

        }
        catch(JSONException e)
        {
            e.printStackTrace();
        }
    }
    
    public static void LeerCamposJSON(String json)
    {
        try
        {
            JSONObject obj = new JSONObject(json);
           
            int counter_id = obj.getInt("Counter_id");
            String name = obj.getString("name");
            String birthday = obj.getString("birthday");
            String gender = obj.getString("gender");
            String nationality = obj.getString("nationality");
            String residencectry = obj.getString("residencectry");
            String crraddress = obj.getString("crrAddress");
            String occupation = obj.getString("occupation");
            String maritalsts = obj.getString("maritalsts");
            String homeph = obj.getString("homeph");
            String movilph = obj.getString("movilph");
            String email = obj.getString("email");
            String idtype = obj.getString("idtype");
            String idnumber = obj.getString("idnumber");
            String idexp = obj.getString("idexp");
            String crremployer = obj.getString("crremployer");
            String workph = obj.getString("workph");
            String companyaddr = obj.getString("companyaddr");
            String companyemail = obj.getString("companyemail");
            String website = obj.getString("website");
            String mthincome = obj.getString("mthincome");
            String procedenceincome = obj.getString("procedenceincome");
            String actingas = obj.getString("actingas");
            String servicetype = obj.getString("servicetype");
            String moreinfo = obj.getString("moreinfo");
            String wheredidufindus = obj.getString("wheredidufindus");
            String created_at = obj.getString("created_at");
           
            System.out.println("Counter ID: " + counter_id);
            System.out.println("Name: "   + name);
            System.out.println("BirthDay: "   + birthday);
            System.out.println("Gender: " + gender);
            System.out.println("Nationality: " + nationality);
            System.out.println("residencectry: " + residencectry);
            System.out.println("crraddress: " + crraddress);
            System.out.println("occupation: " + occupation);
            System.out.println("maritalsts: " + maritalsts);
            System.out.println("homeph: " + homeph);
            System.out.println("movilph: " + movilph);
            System.out.println("email: " + email);
            System.out.println("idtype: " + idtype);
            System.out.println("idnumber: " + idnumber);
            System.out.println("idexp: " + idexp);
            System.out.println("crremployer: " + crremployer);
            System.out.println("workph: " + workph);
            System.out.println("companyaddr: " + companyaddr);
            System.out.println("companyemail: " + companyemail);
            System.out.println("website: " + website);
            System.out.println("mthincome: " + mthincome);
            System.out.println("procedenceincome: " + procedenceincome);
            System.out.println("actingas: " + actingas);
            System.out.println("servicetype: " + servicetype);
            System.out.println("moreinfo: " + moreinfo);
            System.out.println("wheredidufindus: " + wheredidufindus);
            System.out.println("created_at: " + created_at);
        }
        catch(JSONException e)
        {
            e.printStackTrace();
        }
    }
    
}

viernes, 23 de marzo de 2018

Don't let select a paid invoice on another payment #3


/***
    @author: José Francisco Rodríguez Chávez
    @email: jfrodriguez.idempiere@gmail.com
    @created: 20/03/2018 10:45 am
    @lastupdated: 20/03/2018 10:45 am
    @version: 1.0
    @description: Don't let duplicated invoices on payment allocate
    @name: beanshell:ValidarFacturaVariosPagos
***/

import org.compiere.util.DB;
import org.compiere.util.Env;
import org.adempiere.webui.window.FDialog;

v_id_factura = A_PO.get_Value("C_Invoice_ID");

pcheck = (v_id_factura == null || v_id_factura == VOID);

if(!pcheck)
{
    String sql = "SELECT * FROM adempiere.fnt_validar_factura_varios_pagos(" + v_id_factura + ");";
    String sql2 = "SELECT * FROM adempiere.fnt_obtener_vpagos_factura(" + v_id_factura + ");";

    rows = DB.getRowSet(sql.toString());
    rows2 = DB.getRowSet(sql2.toString());

    if(rows.next())
    {
        if(rows.getBoolean(1) == false)
        {
            if(rows2.next())
            {
                String pagos = rows2.getString(1);

                return "La factura seleccionada ya esta en uso en el pago: " + pagos;
            }
        }
    }
}

sábado, 16 de julio de 2016

Install OpenJDK 8 in Ubuntu 14.04

As a workaround, you can install OpenJDK 8 from a PPA repository:

1. Open terminal from the Dash or by pressing Ctrl+Alt+T. When it opens, run the command below to add PPA:

sudo add-apt-repository ppa:openjdk-r/ppa
 
Type in user password when it asks and hit Enter to continue.

2. After that, update system package cache and install OpenJDK 8:

sudo apt-get update sudo apt-get install openjdk-8-jdk

3. If you have more than one Java versions installed on your system. Run below command set the default Java:

sudo update-alternatives --config java

Type in a number to select a Java version.

And set default Java Compiler by running:

sudo update-alternatives --config javac

4. Finally check out current Java version by running:

java -version

It outputs something like this:

openjdk version "1.8.0_01-internal" OpenJDK Runtime Environment (build 1.8.0_01-internal-b04) OpenJDK 64-Bit Server VM (build 25.40-b08, mixed mode)

viernes, 29 de abril de 2016

Get Current Timestamp in Java

Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy h:mm:ss a");
String formattedDate = sdf.format(date);
System.out.println(formattedDate); // 12/01/2011 4:48:16 PM

jueves, 28 de mayo de 2015

Spanish Format Date

A continuación la instrucción para mantener la fecha en idioma español utilizada en el diseñador del iReport:

"Managua," + new SimpleDateFormat("dd MMMM yyyy",new Locale("ES")).format($F{fecha})

Fuente aportada por:

Lic. Douglas Javier Sotelo Obando
<douglassotelo@gmail.com>

miércoles, 27 de mayo de 2015

Arial in Ubuntu with Java Zulu

Descarga el siguiente paquete:

JVMFonts.7z

Copia todos los archivos de la carpeta en la siguiente dirección:

/usr/share/fonts/JVMFonts/

Abrir el archivo fontconfig.Ubuntu.properties.src ubicado en usr/lib/jvm/zulu-6-amd64/jre/lib

 sudo nano fontconfig.Ubuntu.properties.src

Ir a la ultima linea del "#Font File Names" y agregar las lineas de las fuentes a ocupar:

filename.Arial=/usr/share/fonts/JVMFonts/Arial.ttf
filename.ArialNarrow=/usr/share/fonts/JVMFonts/ARIALN.TTF
...
filename.Fuente=/usr/share/fonts/JVMFonts/Fuente.TTF


Si estamos usando ADempiere, para que haga efecto en los reportes hay que detener el servicio

sudo service adempiere stop

Una vez detenido el servicio, se debe hacer una instalación silenciosa

usuario@MiPC:~/$ADEMPIERE_HOME$ ./RUN_silentsetup.sh

Y por último iniciar el servicio

sudo service adempiere start

Fuente brindada por el compañero:

Juan Bautista Josses Corrales
<guitarjosses@gmail.com>

Dejar un comentario es una forma de agradecimiento.