PageRenderTime 24ms CodeModel.GetById 16ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Prototipo/wsConsume/src/wsconsume/Main.java

http://prototipomemoria.googlecode.com/
Java | 145 lines | 86 code | 27 blank | 32 comment | 3 complexity | 8c5f3695e15597ae54a3927e31728dd4 MD5 | raw file
  1/*
  2 * To change this template, choose Tools | Templates
  3 * and open the template in the editor.
  4 */
  5
  6package wsconsume;
  7
  8import java.io.BufferedWriter;
  9import java.io.FileWriter;
 10import java.io.IOException;
 11import java.util.Date;
 12import java.util.logging.Level;
 13import java.util.logging.Logger;
 14import javax.xml.namespace.QName;
 15import javax.xml.transform.Source;
 16import javax.xml.ws.Dispatch;
 17import javax.xml.transform.stream.StreamSource;
 18import javax.xml.ws.Service;
 19import java.io.StringReader;
 20import java.util.ArrayList;
 21import java.util.List;
 22import memoria.commons.dataAccess.RepoConfig;
 23import memoria.commons.dataAccess.RepositoriesMetadata;
 24import memoria.commons.dataAccess.query.VisualQuery;
 25import memoria.commons.dataAccess.query.filtro.RectangleFilter;
 26import memoria.commons.entities.Escuela;
 27import memoria.commons.structures.GeoReferenced;
 28import memoria.commons.structures.Point;
 29import memoria.commons.structures.coordinates.LatLonCoordinate;
 30import memoria.commons.xml.XStreamInstance;
 31
 32
 33
 34/**
 35 *
 36 * @author diego
 37 */
 38public class Main {
 39
 40    /**
 41     * @param args the command line arguments
 42     */
 43    public static void main(String[] args) {
 44
 45        long sum = 0;
 46        int times = 100;
 47        for (int i = 0; i <times; i++) {
 48            long uno = new Date().getTime();
 49
 50            getData(args);
 51            long dos = new Date().getTime();
 52            System.out.println(dos - uno);
 53            sum+= dos - uno;
 54            //System.out.println(da.getDataAccessPort().getData(null));
 55        }
 56        System.out.println("Suma: "+sum);
 57        System.out.println("Ejecuciones: "+times);
 58        System.out.println("Promedio: "+sum/times);
 59        
 60    }
 61
 62
 63    public static void getData(String[] args){
 64        WsTransformadorService servicio = new WsTransformadorService();
 65
 66        String capa = "Industria";
 67
 68//        double SWlat = Double.valueOf(args[0]);
 69//        double SWlon = Double.valueOf(args[1]);
 70//        double NElat = Double.valueOf(args[2]);
 71//        double NElon = Double.valueOf(args[3]);
 72
 73//        double SWlat = -34.92577121781642;
 74//        double SWlon = -56.204938888549805;
 75//        double NElat = -34.89057762229523;
 76//        double NElon = -56.1276912689209;
 77        
 78        double SWlat = -36.92577121781642;
 79        double SWlon = -58.204938888549805;
 80        double NElat = -30.89057762229523;
 81        double NElon = -50.1276912689209;
 82
 83
 84//        RepositoriesMetadata meta = new RepositoriesMetadata();
 85//        meta.setEntity("Escuela");
 86//        RepoConfig config = new RepoConfig("memoria.dataAccess.dao.ExcelDao");
 87//        config.getAttributes().put("URL", "D:/facu/Memoria/prototipo-googlecode/Prototipo/PrototipoMemoria/src/java/memoria/resources/industri.xls");
 88//        meta.getRepositories().add(config);
 89//        List<RepositoriesMetadata> repositoriesMetadata = new ArrayList<RepositoriesMetadata>();
 90//        repositoriesMetadata.add(meta);
 91//        System.out.println(XStreamInstance.toXml(repositoriesMetadata));
 92
 93        VisualQuery consulta = new VisualQuery(capa);
 94
 95         String xmlResponse = servicio.getWsTransformadorPort().getDataFiltro
 96                (capa,SWlat,SWlon,NElat,NElon);
 97
 98         //String xmlResponse = servicio.getWsTransformadorPort().getData(consulta.toXml());
 99         //createMap(xmlResponse);
100    }
101
102    public static void createMap(String xml){
103        writeToFile(xml);
104        try {
105            Process p = Runtime.getRuntime().exec("python pymap.py");
106            //Process p2 = Runtime.getRuntime().exec("C:/Program Files (x86)/SlikSvn/bin/svn commit MyFirstMap.html -m=\"Subo mapa generado\"");
107        } catch (IOException ex) {
108            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
109        }
110    }
111
112    public static void writeToFile(String xml){
113        try{
114          // Create file
115          List<GeoReferenced> data = (List<GeoReferenced>) XStreamInstance.toObject(xml);
116
117          
118
119          FileWriter fstream = new FileWriter("data.csv");
120          BufferedWriter out = new BufferedWriter(fstream);
121          int i = 0;
122            for (GeoReferenced geoReferenced : data) {
123                for (Point punto : geoReferenced.getSpatialRepresentation().getPoints()){
124                    out.write(punto.getCoordiante().getX());
125                    out.write(" ; ");
126                    out.write(punto.getCoordiante().getY());
127                    out.write(" ; ");
128                    out.write(geoReferenced.getNombre());
129                    out.write(" ; ");
130                    out.write(geoReferenced.getDescripcion());
131                    out.write(" ; ");
132                    out.write(geoReferenced.getIconName());
133                    out.write("\n");
134                    i+=1;
135                }
136                
137            }
138
139          System.out.println("Procesando mapa para "+i+ " puntos");
140          out.close();
141          }catch (Exception e){//Catch exception if any
142          System.err.println("Error: " + e.getMessage());
143          }
144    }
145}