Original User: santos.r09This is the App.xtend:package mx.com.flint.flintstack
import flexjson.JSONSerializer
import java.io.*;
import java.net.*;
import java.text.DecimalFormat
import java.util.Calendar
import java.util.Date
import java.util.Scanner;
import mx.com.flint.flintstack.controller.*
import mx.gob.sfp.model.*
import org.apache.commons.fileupload.FileItem
import org.apache.commons.fileupload.FileItemFactory
import org.apache.commons.fileupload.FileUploadException
import org.apache.commons.fileupload.disk.DiskFileItemFactory
import org.apache.commons.fileupload.servlet.ServletFileUpload
import org.apache.poi.hssf.usermodel.*
import org.apache.shiro.SecurityUtils
import spark.Request
import spark.Response
import spark.servlet.SparkApplication
import static extension mx.com.flint.flintstack.Util.*
import static spark.Spark.*
import sun.misc.BASE64Decoder;
class App implements SparkApplication {
def static geometryFromInputStream(InputStream inputStream){
val frm = new DecimalFormat("#.000000")
val frm2 = new DecimalFormat("##")
var s=""
val wb = new HSSFWorkbook(inputStream)
val sheet = wb.getSheetAt(0)
var renglon=3
var row = sheet.getRow(2)
var x = row.getCell(8).numericCellValue
var y = row.getCell(9).numericCellValue
var wkid= row.getCell(10).numericCellValue
s = s + frm.format(x) + "%2C" + frm.format(y)
while((row = sheet.getRow(renglon))!=null && !row.getCell(3).toString().trim().isEmpty())
{
var direccion = row.getCell(3).toString()
var a = switch direccion{
case "SE": -1
case "NW": -1
default: 1
}
var b = switch direccion{
case "S": 180
case "SW": 180
case "SE": 180
case "W": -90
case "E": 90
default: 0
}
var grados = row.getCell(4).numericCellValue + (row.getCell(5).numericCellValue/60) + (row.getCell(6).numericCellValue/3600)
var gradosDireccion = (grados*a)+b
var radianes = (gradosDireccion * Math::PI)/180
var dX = row.getCell(7).numericCellValue*Math::sin(radianes)
var dY = row.getCell(7).numericCellValue*Math::cos(radianes)
x = x + dX
y = y + dY
s = s + "," + frm.format(x) + "%2C" + frm.format(y)
renglon = renglon + 1
}
var r=""
val strUrl="http://200.77.231.25/ArcGIS/rest/services/Geometry/GeometryServer/project?geometries="+s+"&inSR=269"+frm2.format(wkid)+"&outSR=102100&f=json"
val url = new URL(strUrl)
val i = new Scanner(url.openStream())
while (i.hasNextLine()) {r = r+i.nextLine()}
r}
override init() {
before(new NoCacheFilter())
get(FlintRoute::getRoute
("/logout",
[Request req, Response response |
response.redirect("/")
null]))
get(FlintRoute::getRoute
("/version", [Request req, Response response | "r01"]))
get(FlintRoute::getRoute
("/from_file",
[Request req, Response response |
geometryFromInputStream(
new URL(new String((new BASE64Decoder).
decodeBuffer(req.S("file")))).
openStream())
]))
post(FlintRoute::getRoute
("/xls2webmercator",
[Request req, Response response |
response.type("text/html")
val factory = new DiskFileItemFactory()
val upload = new ServletFileUpload(factory)
upload.parseRequest(req.raw()).map
[FileItem fi | geometryFromInputStream(fi.inputStream)].last()
]))
}
}