Example usage for com.mongodb BasicDBObject getString

List of usage examples for com.mongodb BasicDBObject getString

Introduction

In this page you can find the example usage for com.mongodb BasicDBObject getString.

Prototype

public String getString(final String key) 

Source Link

Document

Returns the value of a field as a string

Usage

From source file:mx.edu.cide.justiciacotidiana.v1.utils.Utils.java

License:Open Source License

/**
 * Valida una serie de parmetros revisando si existen y no estn vacos.
 * @param tovalidate Objeto a validar./*  w w  w.j  a  v  a2 s.c  o m*/
 * @param params Lista de parmetros a validar en el objeto.
 * @return true si los parmetros existen en el objeto y no estn vacos. false en otro caso.
 */
public static boolean validateEmptyStringFields(BasicDBObject tovalidate, List<String> params) {
    for (String key : params) {
        String val = tovalidate.getString(key);
        if (null == val || val.length() == 0) {
            return false;
        }
    }
    return true;
}

From source file:mx.org.cedn.avisosconagua.engine.processors.CapInfo.java

License:Open Source License

@Override
public void invokeForm(HttpServletRequest request, HttpServletResponse response, BasicDBObject data,
        String[] parts) throws ServletException, IOException {
    HashMap<String, String> datos = new HashMap<>();
    if (null != data) {
        for (String key : data.keySet()) {
            datos.put(key, data.getString(key));
        }//from   ww w .  jav a  2  s  .  c o m
    }

    //Put max sustained winds in map
    BasicDBObject advice = MongoInterface.getInstance()
            .getAdvice((String) request.getSession(true).getAttribute("internalId"));
    if (null != advice) {
        //Get wind speed from init section
        BasicDBObject section = (BasicDBObject) advice.get("init");
        if (null != section) {
            datos.put("eventWindSpeedSust", section.getString("eventWindSpeedSust"));
            datos.put("eventCoastDistance", section.getString("eventCoastDistance"));
        }
    }

    request.setAttribute("data", datos);
    request.setAttribute("bulletinType", parts[2]);
    String url = "/jsp/bulletinInfo.jsp";
    if (parts[2].endsWith("dp")) {
        url = "/jsp/bulletinInfoDp.jsp";
    }

    RequestDispatcher rd = request.getRequestDispatcher(url);
    rd.forward(request, response);
}

From source file:mx.org.cedn.avisosconagua.engine.processors.Generate.java

License:Open Source License

@Override
public void invokeForm(HttpServletRequest request, HttpServletResponse response, BasicDBObject data,
        String[] parts) throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    String adviceID = (String) request.getSession(true).getAttribute(ADVICE_ID);
    CAPFileGenerator capFile = new CAPFileGenerator(adviceID);
    capFile.generate();/*from w w w  .ja  v  a2s.  c om*/
    if (capFile.isOK()) {
        request.setAttribute("capURL", capFile.getLink());
    }
    // MAPS74 - no html generation
    //        HtmlZipGenerator htmlFile = new HtmlZipGenerator(adviceID);
    //        htmlFile.generate();
    //        if (htmlFile.isOK()){
    //            request.setAttribute("htmlUrl",htmlFile.getLink());
    //        }
    BasicDBObject aviso = MongoInterface.getInstance().getAdvice(adviceID);
    BasicDBObject init = (BasicDBObject) aviso.get("init");
    BasicDBObject capInfo = (BasicDBObject) aviso.get("capInfo");
    BasicDBObject precapture = (BasicDBObject) aviso.get("precapture");
    String previous = precapture != null ? precapture.getString("previousIssue") : null;
    String titulo = Utils.getTituloBoletinHtml(aviso.getString(MongoInterface.ADVICE_TYPE),
            init.getString("eventCoastDistance"));
    String title = capInfo.getString("issueDate") + " " + capInfo.getString("issueTime") + " - "
            + capInfo.getString("issueNumber") + " " + titulo;
    //
    request.setAttribute("titulo", Utils.getTituloBoletin(parts[2]));
    MongoInterface.getInstance().setGenerated(adviceID, previous, title, parts[2], capFile.getDate());
    request.setAttribute("isdp", parts[2].endsWith("dp"));
    request.setAttribute("bulletinType", parts[2]);
    request.setAttribute("hasAreas", Utils.canIHasAreaz(aviso));
    RequestDispatcher rd = request.getRequestDispatcher("/jsp/finish.jsp");
    rd.forward(request, response);
}

From source file:mx.org.cedn.avisosconagua.engine.processors.Init.java

License:Open Source License

@Override
public void invokeForm(HttpServletRequest request, HttpServletResponse response, BasicDBObject data,
        String parts[]) throws ServletException, IOException {
    HashMap<String, String> datos = new HashMap<>();
    String prevIssue = null;//from  w w  w.j  a va 2  s . c om

    if (null != data) {
        for (String key : data.keySet()) {
            datos.put(key, data.getString(key));
        }
    }

    //Put nhcLinks in map and get advisory for tracking
    BasicDBObject advice = mi.getAdvice((String) request.getSession(true).getAttribute("internalId"));
    if (null != advice) {
        //Get nhcLinks
        BasicDBObject section = (BasicDBObject) advice.get("precapture");
        if (null != section) {
            datos.put("nhcForecastLink", section.getString("nhcForecastLink"));
            datos.put("nhcPublicLink", section.getString("nhcPublicLink"));
            prevIssue = section.getString("previousIssue");
        }
    }

    //Advice without init saved and for tracking
    if (advice != null && advice.get("init") == null) {
        if (prevIssue != null) {
            BasicDBObject previous = mi.getAdvice(prevIssue);
            if (previous != null) {
                //System.out.println("Putting previous data from "+prevIssue);
                BasicDBObject initSection = (BasicDBObject) previous.get("init");
                if (initSection != null) {
                    //Set current values to previous values
                    datos.put("eventDescriptionHTML", initSection.getString("eventDescriptionHTML", ""));
                    datos.put("areaDescription", initSection.getString("areaDescription", ""));
                    datos.put("eventRisk", initSection.getString("eventRisk", ""));
                    datos.put("eventComments", initSection.getString("eventComments", ""));
                }
            }
        }
    }

    request.setAttribute("data", datos);
    request.setAttribute("bulletinType", parts[2]);
    String url = "/jsp/init.jsp";
    if (parts[2].endsWith("dp")) {
        url = "/jsp/initdp.jsp";
    }
    RequestDispatcher rd = request.getRequestDispatcher(url);
    rd.forward(request, response);
}

From source file:mx.org.cedn.avisosconagua.engine.processors.Init.java

License:Open Source License

/**
 * Updates uploaded images from the web form.
 * @param parametros new advice properties
 * @param anterior previous advice properties
 *//*from w  ww  .j a  v a  2 s  .  co  m*/
private void procesaImagen(HashMap<String, String> parametros, BasicDBObject anterior) {
    if (null == parametros.get("issueSateliteImg") || "".equals(parametros.get("issueSateliteImg").trim())) {
        if (null != anterior && null != anterior.getString("issueSateliteImg")) {
            System.out.println("Arreglando: issueSateliteImg=" + anterior.getString("issueSateliteImg"));
            parametros.put("issueSateliteImg", anterior.getString("issueSateliteImg"));
        }
    }
}

From source file:mx.org.cedn.avisosconagua.engine.processors.Precapture.java

License:Open Source License

@Override
public void invokeForm(HttpServletRequest request, HttpServletResponse response, BasicDBObject data,
        String[] parts) throws ServletException, IOException {
    HashMap<String, String> datos = new HashMap<>();
    if (null != data) {
        for (String key : data.keySet()) {
            datos.put(key, data.getString(key));
            //System.out.println("colocando: "+key+" : "+datos.get(key));
        }//from  w ww  .  j  a va2 s .  c  om
    }
    request.setAttribute("data", datos);
    request.setAttribute("bulletinType", parts[2]);
    request.setAttribute("advicesList", MongoInterface.getInstance().getPublisedAdvicesList(parts[2]));
    String url = "/jsp/precapture.jsp";
    RequestDispatcher rd = request.getRequestDispatcher(url);
    rd.forward(request, response);
}

From source file:mx.org.cedn.avisosconagua.engine.processors.Pronostico.java

License:Open Source License

@Override
public void invokeForm(HttpServletRequest request, HttpServletResponse response, BasicDBObject data,
        String parts[]) throws ServletException, IOException {
    HashMap<String, String> datos = new HashMap<>();
    String prevIssue = null;//from  w w  w . ja v  a2s.c  o  m
    if (null != data) {
        for (String key : data.keySet()) {
            datos.put(key, data.getString(key));
            //System.out.println("colocando: "+key+" : "+datos.get(key));
        }
    }

    //Put nhcLinks in map
    BasicDBObject advice = MongoInterface.getInstance()
            .getAdvice((String) request.getSession(true).getAttribute("internalId"));
    if (null != advice) {
        //Get nhcLinks
        BasicDBObject section = (BasicDBObject) advice.get("precapture");
        if (null != section) {
            datos.put("nhcForecastLink", section.getString("nhcForecastLink"));
            datos.put("nhcPublicLink", section.getString("nhcPublicLink"));
            prevIssue = section.getString("previousIssue");
        }
    }

    //Advice without pronostico saved and for tracking
    if (advice != null && advice.get("pronostico") == null) {
        if (prevIssue != null) {
            BasicDBObject previous = MongoInterface.getInstance().getAdvice(prevIssue);
            if (previous != null) {
                //System.out.println("Putting previous data from "+prevIssue);
                BasicDBObject forecastSection = (BasicDBObject) previous.get("pronostico");
                if (forecastSection != null) {
                    //Set current values to previous values
                    datos.put("issueSateliteLocationImgFooter",
                            forecastSection.getString("issueSateliteLocationImgFooter", ""));
                }
            }
        }
    }

    request.setAttribute("data", datos);
    request.setAttribute("bulletinType", parts[2]);
    String url = "/jsp/forecast.jsp";
    RequestDispatcher rd = request.getRequestDispatcher(url);
    rd.forward(request, response);
}

From source file:mx.org.cedn.avisosconagua.engine.processors.Pronostico.java

License:Open Source License

/**
 * Updates uploaded images from the web form.
 * @param parametros new advice properties
 * @param anterior previous advice properties
 *///from w ww  .  java2s .com
private void procesaImagen(HashMap<String, String> parametros, BasicDBObject anterior) {
    if (null == parametros.get("issueSateliteLocationImg")
            || "".equals(parametros.get("issueSateliteLocationImg").trim())) {
        if (null != anterior && null != anterior.getString("issueSateliteLocationImg")) {
            parametros.put("issueSateliteLocationImg", anterior.getString("issueSateliteLocationImg"));
        }
    }
}

From source file:mx.org.cedn.avisosconagua.engine.processors.Seguimiento.java

License:Open Source License

@Override
public void invokeForm(HttpServletRequest request, HttpServletResponse response, BasicDBObject data,
        String parts[]) throws ServletException, IOException {
    MongoInterface mi = MongoInterface.getInstance();
    HashMap<String, String> datos = new HashMap<>();
    if (null != data) {
        for (String key : data.keySet()) {
            datos.put(key, data.getString(key));
            //System.out.println("colocando: "+key+" : "+datos.get(key));
        }/* ww w  . ja v  a2 s . c  om*/
    }

    //Get previously saved data to populate first row
    HashMap<String, String> seguimiento = new HashMap<>();
    BasicDBObject advice = mi.getAdvice((String) request.getSession(true).getAttribute("internalId"));
    if (null != advice) {
        //Add data from init section
        BasicDBObject section = (BasicDBObject) advice.get("init");
        if (null != section) {
            for (String key : section.keySet()) {
                seguimiento.put(key, section.getString(key));
            }
        }

        //Add data from tracking section
        section = (BasicDBObject) advice.get("seguimiento");
        if (null != section) {
            for (String key : section.keySet()) {
                seguimiento.put(key, section.getString(key));
            }
        }
    }

    request.setAttribute("data", datos);
    request.setAttribute("trackData", seguimiento);
    request.setAttribute("advicesList", mi.getPublisedAdvicesList());
    request.setAttribute("bulletinType", parts[2]);
    String url = "/jsp/tracking.jsp";
    RequestDispatcher rd = request.getRequestDispatcher(url);
    rd.forward(request, response);
}

From source file:mx.org.cedn.avisosconagua.mongo.CAPGenerator.java

License:Open Source License

/**
 * Gets a valid {@link com.google.publicalerts.cap.Alert.Builder} from the Alert object.
 * @return valid {@link com.google.publicalerts.cap.Alert.Builder}
 *//*w w  w .  ja  va2s . com*/
private Alert.Builder getValidAlertBuilder() {

    Alert.Status status = Alert.Status.ACTUAL;
    String updateToId = null;

    if (null != precapture) {
        String capStatus = precapture.getString("capStatus");
        if ("actual".equals(capStatus)) {
            status = Alert.Status.ACTUAL;
        }
        if ("test".equals(capStatus)) {
            status = Alert.Status.TEST;
        }
        if ("excercise".equals(capStatus)) {
            status = Alert.Status.EXERCISE;
        }
        if ("system".equals(capStatus)) {
            status = Alert.Status.SYSTEM;
        }
        if ("draft".equals(capStatus)) {
            status = Alert.Status.DRAFT;
        }

        updateToId = precapture.getString("previousIssue");
    }

    _date = capInfo.getString("issueDate") + " " + capInfo.getString("issueTime");
    String sender = "smn.cna.gob.mx";

    Alert.Builder builder = Alert.newBuilder().setXmlns(CapValidator.CAP12_XMLNS).setIdentifier(currentId)
            .setSender(sender).setSent(Utils.getISODate(_date))//2003-04-02T14:39:01-05:00 2014-04-93T12:58:00-06:00
            .setStatus(status) //Alert.Status.ACTUAL
            .setScope(Alert.Scope.PUBLIC).addCode(capInfo.getString("issueNumber"));
    //                
    //                .setIncidents(Group.newBuilder()
    //                        .addValue("incident1").addValue("incident2").build())

    Alert.MsgType type = Alert.MsgType.ALERT;

    // Definir si ACTUAL o UPDATE

    if (null != updateToId && !"".equals(updateToId.trim())) {
        type = Alert.MsgType.UPDATE;

        BasicDBObject ci = (BasicDBObject) MongoInterface.getInstance().getAdvice(updateToId).get("capInfo");
        String fecha = ci.getString("issueDate") + " " + ci.getString("issueTime");
        String preSent = Utils.getISODate(fecha);
        builder.setReferences(Group.newBuilder().addValue(sender + "," + updateToId + "," + preSent).build());
    }

    builder.setMsgType(type);

    /*
     for (HashMap<String, String> event : listEvents) {
     builder.addInfo(getValidInfoBuilder(event));
     }*/
    HashMap<String, String> areas = new HashMap<String, String>();
    for (String key : init.keySet()) {
        if (key.startsWith("area-")) {
            areas.put(key.substring(5), init.getString(key));
        }
    }
    builder.addInfo(getValidInfoBuilder(areas));
    return builder;
}