Example usage for java.lang Long decode

List of usage examples for java.lang Long decode

Introduction

In this page you can find the example usage for java.lang Long decode.

Prototype

public static Long decode(String nm) throws NumberFormatException 

Source Link

Document

Decodes a String into a Long .

Usage

From source file:org.jboss.dashboard.ui.components.permissions.PermissionsHandler.java

public void actionSelectObject(CommandRequest request) throws Exception {
    String sid = request.getParameter(PARAM_OBJECT_ID);
    if (!StringUtils.isEmpty(sid)) {
        selectObject(Long.decode(sid));
    }/*w  w w .j a v  a2s . c  om*/
}

From source file:org.rti.zcore.dar.struts.action.ListAction.java

protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    //      Extract attributes we will need
    HttpSession session = request.getSession();
    Principal user = request.getUserPrincipal();
    String username = user.getName();
    Form encounterForm;//from  w w  w. ja  v  a2  s .c  om
    BaseEncounter encounter = null;
    Map encMap = null;
    Long formId = null;
    Long patientId = null;
    Long eventId = null;
    String constraintClause = null;
    Long constraintLong = null;
    String detailName = null;
    BaseSessionSubject sessionPatient = null;
    Integer maxRows = 0;
    Integer offset = 0;
    Integer prevRows = 0;
    Integer nextRows = 0;
    Connection conn = null;
    String className = null;
    try {
        conn = DatabaseUtils.getZEPRSConnection(username);
        if (request.getParameter("formId") != null) {
            formId = Long.decode(request.getParameter("formId"));
        } else if (request.getAttribute("formId") != null) {
            formId = Long.decode(request.getAttribute("formId").toString());
        }
        if (request.getParameter("className") != null) {
            className = request.getParameter("className");
            formId = (Long) DynaSiteObjects.getFormNameMap().get(className);
        } else if (request.getAttribute("className") != null) {
            className = (String) request.getAttribute("className");
            formId = (Long) DynaSiteObjects.getFormNameMap().get(className);
        }
        if (request.getParameter("constraintClause") != null) {
            constraintClause = request.getParameter("constraintClause");
        } else if (request.getAttribute("constraintClause") != null) {
            constraintClause = request.getAttribute("constraintClause").toString();
        }
        if (request.getParameter("constraintLong") != null) {
            constraintLong = Long.decode(request.getParameter("constraintLong"));
        } else if (request.getAttribute("constraintLong") != null) {
            constraintLong = Long.decode(request.getAttribute("constraintLong").toString());
        }
        if (request.getParameter("maxRows") != null) {
            maxRows = Integer.decode(request.getParameter("maxRows"));
        } else if (request.getAttribute("maxRows") != null) {
            maxRows = Integer.decode(request.getAttribute("maxRows").toString());
        } else {
            if (formId != null) {
                switch (formId.intValue()) {
                case 128:
                    maxRows = 0;
                    break;
                case 129:
                    maxRows = 0;
                    break;
                case 130:
                    maxRows = 0;
                    break;
                case 131:
                    maxRows = 0;
                    break;
                case 181:
                    maxRows = 0;
                    break;

                default:
                    maxRows = 20;
                    break;
                }
            } else {
                maxRows = 20;
            }
        }
        if (request.getParameter("offset") != null) {
            offset = Integer.decode(request.getParameter("offset"));
        } else if (request.getAttribute("offset") != null) {
            offset = Integer.decode(request.getAttribute("offset").toString());
        }
        if (request.getParameter("prevRows") != null) {
            prevRows = Integer.decode(request.getParameter("prevRows"));
            offset = prevRows;
        } else if (request.getAttribute("prevRows") != null) {
            prevRows = Integer.decode(request.getAttribute("prevRows").toString());
            offset = prevRows;
        }
        if (request.getParameter("nextRows") != null) {
            nextRows = Integer.decode(request.getParameter("nextRows"));
        } else if (request.getAttribute("nextRows") != null) {
            nextRows = Integer.decode(request.getAttribute("nextRows").toString());
        }
        if (mapping.getParameter() != null && !mapping.getParameter().equals("")) {
            String formName = mapping.getParameter();
            formId = (Long) DynaSiteObjects.getFormNameMap().get(formName);
        }
        // Admin pages usually do not have a sessionPatient. This is a hack to use code that uses sessionPatient.
        sessionPatient = new TimsSessionSubject();
        SessionUtil.getInstance(session).setSessionPatient(sessionPatient);

        encounterForm = ((Form) DynaSiteObjects.getForms().get(new Long(formId)));
        Long formTypeId = encounterForm.getFormTypeId();
        // populate the records for this class
        List items = null;
        if (className != null && className.equals("MenuItem")) {
            items = DynaSiteObjects.getMenuItemList(); //must be sorted
        } else {
            String classname = StringManipulation.fixClassname(encounterForm.getName());
            Class clazz = null;
            try {
                clazz = Class.forName(Constants.getDynasiteFormsPackage() + "." + classname);
            } catch (ClassNotFoundException e1) {
                if (classname.equals("UserInfo")) {
                    clazz = Class.forName("org.rti.zcore." + classname);
                }
            }

            try {
                String orderBy = "id DESC";
                switch (formTypeId.intValue()) {
                case 5: // admin
                    if (constraintLong != null) {
                        /*if (formId == 161) { // stock
                           // Get the item - form 131
                           Class clazz = Class.forName(DynaSiteObjects.getDynasiteFormsPackage() + ".Item");
                           Item stockItem = (Item) EncountersDAO.getOne(conn, constraintLong, "SQL_RETRIEVE_ONE_ADMIN131", clazz);
                           detailName = stockItem.getField2153();
                           request.setAttribute("detailName", detailName);
                        }*/
                        //String orderBy = "id DESC";
                        items = EncountersDAO.getAllConstraintOrderBy(conn, formId,
                                "SQL_RETRIEVE_ALL_ADMIN" + formId, clazz, constraintClause, constraintLong,
                                orderBy);
                    } else {
                        if (formId == 161) { // stock
                            //items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVE_ALL_ADMIN" + formId, clazz, maxRows, offset, "id DESC");
                            if (maxRows == 0) {
                                items = EncountersDAO.getAllOrderBy(conn, formId,
                                        "SQL_RETRIEVE_ALL_ADMIN" + formId, clazz, orderBy);
                            } else {
                                items = EncountersDAO.getAll(conn, formId,
                                        "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset,
                                        orderBy);
                            }
                        } else if (formId == 128) { // regimen groups
                            //items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset, "name ");
                            if (maxRows == 0) {
                                items = EncountersDAO.getAllOrderBy(conn, formId,
                                        "SQL_RETRIEVE_ALL_ADMIN" + formId, clazz, "name ");
                            } else {
                                items = EncountersDAO.getAll(conn, formId,
                                        "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset,
                                        "name ");
                            }
                        } else if (formId == 129) { // regimen
                            //items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset, "code ");
                            if (maxRows == 0) {
                                items = EncountersDAO.getAllOrderBy(conn, formId,
                                        "SQL_RETRIEVE_ALL_ADMIN" + formId, clazz, "code ");
                            } else {
                                items = EncountersDAO.getAll(conn, formId,
                                        "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset,
                                        "code ");
                            }
                        } else if (formId == 130) { // item groups
                            //items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset, "name ");
                            if (maxRows == 0) {
                                items = EncountersDAO.getAllOrderBy(conn, formId,
                                        "SQL_RETRIEVE_ALL_ADMIN" + formId, clazz, "name ");
                            } else {
                                items = EncountersDAO.getAll(conn, formId,
                                        "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset,
                                        "name ");
                            }
                        } else {
                            if (className != null && className.equals("MenuItem")) {
                                items = DynaSiteObjects.getMenuItemList(); //must be sorted
                            } else {
                                if (formId == 181) {
                                    orderBy = "regimen_id DESC";
                                    if (maxRows == 0) {
                                        //items = EncountersDAO.getAllOrderBy(conn, formId, "SQL_RETRIEVE_ALL_ADMIN" + formId, clazz, orderBy);
                                        String sql = "SELECT rb.id, rb.regimen_id AS regimen_id, item_id AS item_id, r.code "
                                                + "FROM regimen_item_bridge rb, regimen r "
                                                + "WHERE rb.regimen_id = r.id ORDER BY r.code ASC";
                                        ArrayList values = new ArrayList();
                                        items = DatabaseUtils.getList(conn, clazz, sql, values);
                                    } else {
                                        items = EncountersDAO.getAll(conn, formId,
                                                "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset,
                                                orderBy);
                                    }
                                } else {
                                    if (maxRows == 0) {
                                        items = EncountersDAO.getAllOrderBy(conn, formId,
                                                "SQL_RETRIEVE_ALL_ADMIN" + formId, clazz, orderBy);
                                    } else {
                                        items = EncountersDAO.getAll(conn, formId,
                                                "SQL_RETRIEVE_ALL_ADMIN_PAGER" + formId, clazz, maxRows, offset,
                                                orderBy);
                                    }
                                }
                            }
                        }
                    }
                    break;
                case 8: // list - for patients
                    items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVEALL" + formId, clazz, maxRows,
                            offset);
                    break;
                default:
                    items = EncountersDAO.getAll(conn, formId, "SQL_RETRIEVE_ALL" + formId, clazz, maxRows,
                            offset);
                    break;
                }
            } catch (IOException e) {
                request.setAttribute("exception", e);
                return mapping.findForward("error");
            } catch (ServletException e) {
                request.setAttribute("exception", e);
                return mapping.findForward("error");
            } catch (SQLException e) {
                request.setAttribute("exception", e);
                return mapping.findForward("error");
            }
        }

        if (maxRows == 0) {
            request.setAttribute("noNavigationWidget", "1");
        } else {
            request.setAttribute("maxRows", maxRows);
            nextRows = offset + maxRows;
            if (items.size() < maxRows) {
                if (offset == 0) {
                    request.setAttribute("noNavigationWidget", "1");
                }
            } else {
                request.setAttribute("offset", nextRows);
            }

            if (offset - maxRows >= 0) {
                prevRows = offset - maxRows;
                request.setAttribute("prevRows", prevRows);
            }
            request.setAttribute("nextRows", nextRows);
        }
        // Attach a map of encounter values that has enumerations already resolved.
        Form encForm = (Form) DynaSiteObjects.getForms().get(encounterForm.getId());
        for (int i = 0; i < items.size(); i++) {
            encounter = (EncounterData) items.get(i);
            // Form encForm = (Form) DynaSiteObjects.getForms().get(encounter.getFormId());
            encMap = PatientRecordUtils.getEncounterMap(encForm, encounter, "fieldId");

            encounter.setEncounterMap(encMap);
        }
        if (items.size() > 0) {
            request.setAttribute("chartItems", items);
            request.setAttribute("formId", encounterForm.getId());
            // loading of body onload DWRUtil.useLoadingMessage()
            request.setAttribute("dwr", 1);
        }

        // Process the dynamic dropdown lists.
        HashMap listMap = new HashMap();
        Form inlineForm = null;
        HashMap<Long, StockReport> balanceMap = null;
        if (DynaSiteObjects.getStatusMap().get("balanceMap") != null) {
            balanceMap = (HashMap<Long, StockReport>) DynaSiteObjects.getStatusMap().get("balanceMap");
        }
        for (Iterator iterator = encounterForm.getPageItems().iterator(); iterator.hasNext();) {
            PageItem pageItem = (PageItem) iterator.next();
            FormField formField = pageItem.getForm_field();
            String identifier = formField.getIdentifier();

            if (pageItem.getInputType().equals("dropdown") || pageItem.getInputType().equals("dropdown-add-one")
                    || pageItem.getInputType().equals("dropdown_site")) {
                String dropdownConstraint = null;
                String pageItemDropdownConstraint = pageItem.getDropdownConstraint();
                if (pageItemDropdownConstraint != null && pageItemDropdownConstraint.endsWith("'siteAbbrev'")) {
                    String siteAbbrev = SessionUtil.getInstance(session).getClientSettings().getSite()
                            .getAbbreviation();
                    dropdownConstraint = pageItemDropdownConstraint.replace("'siteAbbrev'",
                            "'" + siteAbbrev + "'");
                } else {
                    dropdownConstraint = pageItemDropdownConstraint;
                }
                List<DropdownItem> list = WidgetUtils.getList(conn, pageItem.getDropdownTable(),
                        pageItem.getDropdownColumn(), dropdownConstraint, pageItem.getDropdownOrderByClause(),
                        DropdownItem.class, pageItem.getFkIdentifier());
                String formName = encForm.getClassname();
                if (formName.equals("StockControl")) {
                    for (DropdownItem dropdownItem : list) {
                        if (balanceMap != null) {
                            String itemIdStr = dropdownItem.getDropdownId();
                            Long itemId = Long.valueOf(itemIdStr);
                            StockReport stockReport = balanceMap.get(itemId);
                            Integer balance = 0;
                            if (stockReport != null) {
                                balance = stockReport.getBalanceBF();
                                String label = dropdownItem.getDropdownValue();
                                if (balance <= 0) {
                                    String value = dropdownItem.getDropdownValue();
                                    dropdownItem
                                            .setDropdownValue(value + " ** Out of Stock ** Bal: " + balance);
                                } else {
                                    dropdownItem.setDropdownValue(label + " Bal: " + balance);
                                }
                            }
                        }
                    }
                }
                listMap.put(pageItem.getId(), list);
                if (pageItem.getInputType().equals("dropdown-add-one")) {
                    String classNameString = StringManipulation.fixClassname(pageItem.getDropdownTable());
                    Long inlineFormId = (Long) DynaSiteObjects.getFormNameMap().get(classNameString);
                    inlineForm = ((Form) DynaSiteObjects.getForms().get(new Long(inlineFormId)));
                    // Create a list of fieldnames for inline forms.
                    ArrayList<String> inlineFields = new ArrayList<String>();
                    for (Iterator iterator2 = inlineForm.getPageItems().iterator(); iterator2.hasNext();) {
                        PageItem pageItem2 = (PageItem) iterator2.next();
                        if (pageItem2.getForm_field().isEnabled() == true
                                && !pageItem2.getForm_field().getType().equals("Display")) {
                            inlineFields.add(pageItem2.getForm_field().getIdentifier());
                        }
                    }
                    request.setAttribute("inlineForm_" + identifier, inlineForm);
                    request.setAttribute("inlineFields_" + identifier, inlineFields);
                    // loading of body onload DWRUtil.useLoadingMessage()
                    request.setAttribute("dwr", 1);
                }
            }
        }

        request.setAttribute("listMap", listMap);

        request.setAttribute("encounterForm", encounterForm);

        List sites = DynaSiteObjects.getClinics();
        request.setAttribute("sites", sites);

        if (Constants.STOCK_PROBLEMS_ENABLED != null && Constants.STOCK_PROBLEMS_ENABLED.equals("true")) {
            //List<Task> stockAlertList = PatientRecordUtils.getStockAlerts();
            List<Task> stockAlertList = null;
            if (DynaSiteObjects.getStatusMap().get("stockAlertList") != null) {
                stockAlertList = (List<Task>) DynaSiteObjects.getStatusMap().get("stockAlertList");
            }
            request.setAttribute("activeProblems", stockAlertList);
        }

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (conn != null && !conn.isClosed()) {
            conn.close();
        }
    }
    return mapping.findForward("success");
}

From source file:br.ufc.ivela.servlets.ChallengeSolver.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/json");
    ChallengeRemote challRemote = this.getChallengeRemote();
    String challid = request.getParameter("challenge");
    Long unitId = Long.decode(request.getParameter("unitId"));
    Long gradeId = Long.decode(request.getParameter("gradeId"));
    String retrieveAnswers = request.getParameter("answers");
    String dependency = request.getParameter("dependency");
    Boolean checkDependency = Boolean.FALSE;
    if (dependency != null) {
        checkDependency = Boolean.parseBoolean(dependency);
    }//  ww w  . ja  v  a2s  .  co  m

    Long uid = 0L;
    Object obj = SecurityContextHolder.getContext().getAuthentication().getPrincipal();

    if (obj != null && obj instanceof SystemUser) {
        uid = ((SystemUser) obj).getId();
    }

    try {
        if (retrieveAnswers != null && retrieveAnswers.equals("t")) {
            String json = getChallengeRemote().retrieveChallengeAnswers(challid, uid, unitId, gradeId);
            response.getWriter().println(json);
        } else if (!challid.equals("audio")) {
            String json = getChallengeRemote().executeChallenge(challid, uid, unitId, gradeId,
                    request.getParameterMap(), checkDependency);
            response.getWriter().println(json);
        } else if (challid.equals("audio")) {
            challRemote.add(request.getParameter("value"), uid, 100);
            Logger.getLogger(this.getClass().getName()).log(Level.INFO, request.getParameter("value").trim());
        }
    } catch (Exception e) {
        response.getWriter().println(
                "{\"list\":{\"results\":[{\"ret\":\"\"}]},\"name\":\"" + challid + "\", \"status\": \"err\"}");
        log.error("Exception in Challenge solver: " + uid + '|' + challid, e);
    }
}

From source file:org.jboss.dashboard.ui.NavigationPoint.java

protected void init(String url) {
    // Try to interpret current workspace, page, and panel action if any and calculate permissions.
    this.url = url;
    String uri = null;// ww  w  .  j  a va2  s .  c  o m
    String queryString = null;

    // Remove anchor
    int anchorPoint = url.indexOf('#');
    if (anchorPoint != -1) {
        url = url.substring(0, anchorPoint);
    }

    try {
        int dividerPoint = url.indexOf('?');
        uri = dividerPoint == -1 ? url : url.substring(0, dividerPoint);
        uri = uri.substring(URLMarkupGenerator.FRIENDLY_PREFIX.length() + 1);
        queryString = dividerPoint == -1 ? "" : url.substring(dividerPoint + 1);
    } catch (Exception e) {
        //Ignore "parsing" errors
    }

    //Remove language information if any
    LocaleManager localeManager = LocaleManager.lookup();
    String[] possibleLangs = localeManager.getPlatformAvailableLangs();
    for (int i = 0; i < possibleLangs.length; i++) {
        String lang = possibleLangs[i];
        if (uri.startsWith(lang + "/")) {
            uri = uri.substring(lang.length() + 1);
            break;
        }
    }

    try {
        int dividerPoint = uri.indexOf('/');
        workspaceId = dividerPoint == -1 ? null : uri.substring(0, dividerPoint);
        sectionId = dividerPoint == -1 ? null : uri.substring(dividerPoint + 1);
        int sectionDividerPoint = sectionId.indexOf('/');
        if (sectionDividerPoint != -1) {
            sectionId = sectionId.substring(0, sectionDividerPoint);
        }
    } catch (Exception e) {
        //Ignore "parsing" errors
    }

    try {
        Map params = new HashMap();
        StringTokenizer strtk = new StringTokenizer(StringEscapeUtils.UNESCAPE_HTML4.translate(queryString),
                "&");
        while (strtk.hasMoreTokens()) {
            String token = strtk.nextToken();
            int dividerPoint = token.indexOf('=');
            if (dividerPoint != -1) {
                params.put(token.substring(0, dividerPoint), token.substring(1 + dividerPoint));
            }
        }
        String panelIdParam = (String) params.get(Parameters.DISPATCH_IDPANEL);
        if (!StringUtils.isEmpty(panelIdParam)) {
            panelId = Long.decode(panelIdParam);
            actionName = (String) params.get(Parameters.DISPATCH_ACTION);
        }
    } catch (Exception e) {
        //Ignore "parsing" errors
    }
}

From source file:org.rti.zcore.dar.struts.action.PatientItemListAction.java

/**
 * Process the specified HTTP request, and create the corresponding HTTP
 * response (or forward to another web component that will create it).
 * Return an <code>ActionForward</code> instance describing where and how
 * control should be forwarded, or <code>null</code> if the response has
 * already been completed./*from w  ww  . ja va2  s .  c  o m*/
 *
 * @param mapping  The ActionMapping used to select this instance
 * @param form     The optional ActionForm bean for this request (if any)
 * @param request  The HTTP request we are processing
 * @param response The HTTP response we are creating
 * @return Action to forward to
 * @throws Exception if an input/output error or servlet exception occurs
 */
protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    // Extract attributes we will need
    HttpSession session = request.getSession();
    Principal user = request.getUserPrincipal();
    String username = user.getName();
    Connection conn = null;
    try {
        conn = DatabaseUtils.getZEPRSConnection(username);
        SessionSubject sessionPatient = null;
        try {
            sessionPatient = (SessionSubject) SessionUtil.getInstance(session).getSessionPatient();
        } catch (SessionUtil.AttributeNotFoundException e) {
            log.error("Unable to get TimsSessionSubject");
        }

        Long patientId = null;
        //Long eventId = null;
        String eventUuid = null;
        Long currentFlowId = null;
        try {
            assert sessionPatient != null;
            patientId = sessionPatient.getId();
            //eventId = sessionPatient.getCurrentEventId();
            eventUuid = sessionPatient.getCurrentEventUuid();
            currentFlowId = sessionPatient.getCurrentFlowId();
        } catch (Exception e) {
            log.error("Unable to get TimsSessionSubject field" + e);
        }

        if (eventUuid == null) {
            String forwardString = "/listEvents.do?patientId=" + patientId;
            ActionForward forwardForm = new ActionForward(forwardString);
            forwardForm.setRedirect(true);
            return forwardForm;
        }

        Long viewFlowId = null;
        // if flowId is in the request, set sessionPatient's flowId
        if (request.getParameter("flowId") != null) {
            viewFlowId = Long.decode(request.getParameter("flowId"));
        } else if (request.getAttribute("flowId") != null) {
            viewFlowId = Long.decode(request.getAttribute("flowId").toString());
        } else {
            try {
                viewFlowId = currentFlowId;
                assert viewFlowId != null;
                if (viewFlowId.intValue() == 9) { // if it's new patient registration
                    viewFlowId = new Long("132"); // send to history
                }
            } catch (Exception e) {
                // a test user w/ no flo - send to history.
                viewFlowId = new Long("132");
            }
        }
        List items = null;
        Long formId = (Long) DynaSiteObjects.getFormNameMap().get("PatientItem");
        Long flowId = Long.valueOf(2);
        items = PatientItemDAO.getPatientItemList(conn, patientId, eventUuid, flowId, formId);

        request.setAttribute("items", items);

        Boolean status = Boolean.valueOf(true);
        List activeProblems = PatientRecordUtils.assembleProblemTaskList(conn, patientId, eventUuid, status,
                sessionPatient);
        request.setAttribute("activeProblems", activeProblems);
        // now get inactive problems
        status = Boolean.valueOf(false);
        List inactiveProblems = PatientRecordUtils.assembleProblemTaskList(conn, patientId, eventUuid, status,
                sessionPatient);
        request.setAttribute("inactiveProblems", inactiveProblems);
        conn.close();

    } catch (ServletException e) {
        log.error(e);
    } finally {
        if (conn != null && !conn.isClosed()) {
            conn.close();
        }
    }
    return mapping.findForward("success");
}

From source file:pt.webdetails.cda.cache.CacheScheduleManager.java

private void load(IParameterProvider requestParams, OutputStream out) throws Exception {
    Session s = getHibernateSession();// w  w  w. j a  va  2s  . c om
    Long id = Long.decode(requestParams.getParameter("id").toString());
    Query q = (Query) s.load(Query.class, id);
    if (q == null) {
        out.write("{}".getBytes(ENCODING));
        logger.error("Couldn' get Query with id=" + id.toString());
    }
    try {
        JSONObject json = q.toJSON();
        out.write(json.toString(2).getBytes(ENCODING));
    } catch (Exception e) {
        logger.error(e);
    }
    s.close();
}

From source file:NumberUtils.java

/**
 * Parse the given text into a number instance of the given target class,
 * using the corresponding default <code>decode</code> methods. Trims the
 * input <code>String</code> before attempting to parse the number. Supports
 * numbers in hex format (with leading 0x) and in octal format (with leading 0).
 *
 * @param text        the text to convert
 * @param targetClass the target class to parse into
 * @return the parsed number/*w  w w .  ja  v a2  s  .  com*/
 * @throws IllegalArgumentException if the target class is not supported
 *                                  (i.e. not a standard Number subclass as included in the JDK)
 * @see java.lang.Byte#decode
 * @see java.lang.Short#decode
 * @see java.lang.Integer#decode
 * @see java.lang.Long#decode
 * @see #decodeBigInteger(String)
 * @see java.lang.Float#valueOf
 * @see java.lang.Double#valueOf
 * @see java.math.BigDecimal#BigDecimal(String)
 */
public static Number parseNumber(String text, Class targetClass) {
    String trimmed = text.trim();

    if (targetClass.equals(Byte.class)) {
        return Byte.decode(trimmed);
    } else if (targetClass.equals(Short.class)) {
        return Short.decode(trimmed);
    } else if (targetClass.equals(Integer.class)) {
        return Integer.decode(trimmed);
    } else if (targetClass.equals(Long.class)) {
        return Long.decode(trimmed);
    } else if (targetClass.equals(BigInteger.class)) {
        return decodeBigInteger(trimmed);
    } else if (targetClass.equals(Float.class)) {
        return Float.valueOf(trimmed);
    } else if (targetClass.equals(Double.class)) {
        return Double.valueOf(trimmed);
    } else if (targetClass.equals(BigDecimal.class) || targetClass.equals(Number.class)) {
        return new BigDecimal(trimmed);
    } else {
        throw new IllegalArgumentException(
                "Cannot convert String [" + text + "] to target class [" + targetClass.getName() + "]");
    }
}

From source file:org.lieuofs.util.dao.FichierOFSTxtDao.java

protected Mutable creerMutation(String numero, String typeMutation, String date, boolean radiation)
        throws ParseException {
    if (!StringUtils.hasText(numero) || !StringUtils.hasText(typeMutation) || !StringUtils.hasText(date))
        return null;
    Integer num = Integer.decode(numero);
    TypeMutation type = TypeMutation.getParId(Long.decode(typeMutation));
    Date dtSuisse = getDateFmt().parse(date);
    Date dateMutation = radiation ? DateUtil.derniereMillisecondeDeLaJournee(dtSuisse)
            : DateUtil.premierMillisecondeDeLaJournee(dtSuisse);
    return creerMutation(num, type, dateMutation);
}

From source file:org.rti.zcore.dar.struts.action.PatientRecordListAction.java

protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    /*if (SystemStateManager.getCurrentState() != SystemStateManager.STATUS_NORMAL) {
    return mapping.findForward(LOCKED_FORWARD);
    }*//*w ww  . j a  va  2s  .  c o  m*/

    HttpSession session = request.getSession();
    Locale sessionLocale = (Locale) request.getAttribute("sessionLocale");
    String sessionLocaleString = null;
    if ((sessionLocale.getLanguage() != null)
            && ((sessionLocale.getCountry() != null) && (!sessionLocale.getCountry().equals("")))) {
        sessionLocaleString = sessionLocale.getLanguage() + "_" + sessionLocale.getCountry();
    } else if (sessionLocale.getLanguage() != null) {
        sessionLocaleString = sessionLocale.getLanguage();
    }
    Principal user = request.getUserPrincipal();
    String username = user.getName();
    Connection conn = null;
    BaseEncounter encounter = null;
    Map encMap = null;
    Long formId = null;
    SessionSubject sessionPatient = null;
    Long patientId = null;
    //Long eventId = null;
    String eventUuid = null;
    Form encounterForm = null;
    String formName = null;
    if (mapping.getParameter() != null && !mapping.getParameter().equals("")) {
        formName = mapping.getParameter().trim();
        formId = (Long) DynaSiteObjects.getFormNameMap().get(formName);
    } else {
        if (request.getParameter("formId") != null) {
            formId = Long.decode(request.getParameter("formId"));
        } else if (request.getAttribute("formId") != null) {
            formId = Long.decode(request.getAttribute("formId").toString());
        }
        //formId = request.getAttribute("id").toString();
    }

    if (request.getParameter("patientId") != null) {
        patientId = Long.decode(request.getParameter("patientId"));
    } else if (request.getAttribute("patientId") != null) {
        patientId = Long.decode(request.getAttribute("patientId").toString());
    }

    try {
        sessionPatient = (SessionSubject) SessionUtil.getInstance(session).getSessionPatient();
        //eventId = sessionPatient.getCurrentEventId();
        eventUuid = sessionPatient.getCurrentEventUuid();
    } catch (SessionUtil.AttributeNotFoundException e) {
        log.error("Unable to get TimsSessionSubject");
    }

    if (patientId == null) {
        try {
            patientId = sessionPatient.getId();
        } catch (Exception e) {
            log.error("Unable to get TimsSessionSubject field");
        }
    }

    // sometimes the user can click link to create a new event and then click elsewhere.
    if (eventUuid == null) {
        String forwardString = "/listEvents.do?patientId=" + patientId;
        ActionForward forwardForm = new ActionForward(forwardString);
        forwardForm.setRedirect(true);
        return forwardForm;
    }

    encounterForm = ((Form) DynaSiteObjects.getForms().get(formId));
    try {
        conn = DatabaseUtils.getZEPRSConnection(username);

        // populate the records for this class
        List chartItems = new ArrayList();
        String classname = StringManipulation.fixClassname(encounterForm.getName());
        Class clazz = Class.forName(Constants.getDynasiteFormsPackage() + "." + classname);
        try {
            ArrayList moreItems = (ArrayList) EncountersDAO.getAllOrderBy(conn, patientId, eventUuid,
                    "SQL_RETRIEVE_UUID" + formId, clazz, "date_visit DESC");
            chartItems.addAll(moreItems);
        } catch (IOException e) {
            request.setAttribute("exception", e);
            return mapping.findForward("error");
        } catch (ServletException e) {
            request.setAttribute("exception", e);
            return mapping.findForward("error");
        } catch (SQLException e) {
            request.setAttribute("exception", e);
            return mapping.findForward("error");
        }

        // DAR-specific:
        if (formName.equals("PatientCondition")) {
            String bmiCalc = Constants.getProperties("bmi.calculate", Constants.getAPP_PROPERTIES());
            if (bmiCalc != null && bmiCalc.equals("true")) {
                for (int i = 0; i < chartItems.size(); i++) {
                    PatientCondition pc = (PatientCondition) chartItems.get(i);
                    Float weight = pc.getWeight();
                    Float height = pc.getHeight();
                    if ((weight != null) && ((height != null) && (height != 0))) {
                        Float bmi = HealthCalcUtils.bmiCalc(weight, height);
                        pc.setBmi_calculated(bmi);
                    }
                }
            }
        }

        // Attach a map of encounter values that has enumerations already resolved.
        MessageResources messageResources = getResources(request, encounterForm.getClassname() + "Messages");
        String messageKey = encounterForm.getClassname() + "Messages";
        ReloadablePropertyMessageResources messages = (ReloadablePropertyMessageResources) request
                .getAttribute(messageKey);
        //ZcorePropertyMessageResources sMessages = (ZcorePropertyMessageResources) messages;
        HashMap messageResourcesMap = messages.getMessages();
        HashMap localeMap = messages.getLocales();
        if (localeMap.get(sessionLocale.toString()) == null) {
            messages.loadLocale(sessionLocale.toString());
        }

        // Attach a map of encounter values that has enumerations already resolved.
        Form encForm = (Form) DynaSiteObjects.getForms().get(encounterForm.getId());
        for (int i = 0; i < chartItems.size(); i++) {
            encounter = (EncounterData) chartItems.get(i);
            encMap = PatientRecordUtils.getEncounterMap(encForm, encounter, "fieldId");
            encounter.setEncounterMap(encMap);
            if (messageResourcesMap != null) {
                encounter.setMessageResourcesMap(messageResourcesMap);
            }
        }
        if (chartItems.size() > 0) {
            request.setAttribute("chartItems", chartItems);
            request.setAttribute("formId", encounterForm.getId());
            // loading of body onload DWRUtil.useLoadingMessage()
            request.setAttribute("dwr", 1);
        }

        // Process the dynamic dropdown lists.
        HashMap listMap = new HashMap();
        Form inlineForm = null;
        for (Iterator iterator = encounterForm.getPageItems().iterator(); iterator.hasNext();) {
            PageItem pageItem = (PageItem) iterator.next();
            FormField formField = pageItem.getForm_field();
            String identifier = formField.getIdentifier();

            if (pageItem.getInputType().equals("dropdown") || pageItem.getInputType().equals("dropdown-add-one")
                    || pageItem.getInputType().equals("dropdown_site")) {
                List list = WidgetUtils.getList(conn, pageItem.getDropdownTable(), pageItem.getDropdownColumn(),
                        pageItem.getDropdownConstraint(), pageItem.getDropdownOrderByClause(),
                        DropdownItem.class, pageItem.getFkIdentifier());
                listMap.put(pageItem.getId(), list);
                if (pageItem.getInputType().equals("dropdown-add-one")) {
                    String classNameString = StringManipulation.fixClassname(pageItem.getDropdownTable());
                    Long inlineFormId = (Long) DynaSiteObjects.getFormNameMap().get(classNameString);
                    inlineForm = ((Form) DynaSiteObjects.getForms().get(new Long(inlineFormId)));
                    // Create a list of fieldnames for inline forms.
                    ArrayList<String> inlineFields = new ArrayList<String>();
                    for (Iterator iterator2 = inlineForm.getPageItems().iterator(); iterator2.hasNext();) {
                        PageItem pageItem2 = (PageItem) iterator2.next();
                        if (pageItem2.getForm_field().isEnabled() == true
                                && !pageItem2.getForm_field().getType().equals("Display")) {
                            inlineFields.add(pageItem2.getForm_field().getIdentifier());
                        }
                    }
                    request.setAttribute("inlineForm_" + identifier, inlineForm);
                    request.setAttribute("inlineFields_" + identifier, inlineFields);
                    // loading of body onload DWRUtil.useLoadingMessage()
                    request.setAttribute("dwr", 1);
                }
            }
        }
        request.setAttribute("listMap", listMap);
        request.setAttribute("encounterForm", encounterForm);

        // Keep this block at the end - it sets sessionPatient to null in certain circumstances.
        // Set the tasklist for particular circumstances. First check if the form requires a patient or if "id" is in the reqiest.
        if ((encounterForm.isRequirePatient() || ((request.getParameter("id") != null)))) {
            // we don't need the tasklist if we're just editing a form or it's in unassigned flow
            Long unassigned = new Long("100");
            if (request.getParameter("id") == null) {
                if (!encounterForm.getFlow().getId().equals(unassigned)) {
                    // moved code for form 66 below.
                }
            }
            Boolean status = Boolean.valueOf(true);
            List activeProblems = PatientRecordUtils.assembleProblemTaskList(conn, patientId, eventUuid, status,
                    sessionPatient);
            request.setAttribute("activeProblems", activeProblems);
            // now get inactive problems
            status = Boolean.valueOf(false);
            List inactiveProblems = PatientRecordUtils.assembleProblemTaskList(conn, patientId, eventUuid,
                    status, sessionPatient);
            request.setAttribute("inactiveProblems", inactiveProblems);
            // Display task list if editing form 1.
        } else if ((encounterForm.getId().intValue() == 1) & (patientId != null)) {
            Boolean status = Boolean.valueOf(true);
            List activeProblems = PatientRecordUtils.assembleProblemTaskList(conn, patientId, eventUuid, status,
                    sessionPatient);
            request.setAttribute("activeProblems", activeProblems);
            // now get inactive problems
            status = Boolean.valueOf(false);
            List inactiveProblems = PatientRecordUtils.assembleProblemTaskList(conn, patientId, eventUuid,
                    status, sessionPatient);
            request.setAttribute("inactiveProblems", inactiveProblems);
            // otherwise reset sessionPatient
        } else {
            SessionUtil.getInstance(session).setSessionPatient(null);
        }

    } catch (ServletException e) {
        log.error(e);
    } finally {
        if (conn != null && !conn.isClosed()) {
            conn.close();
        }
    }

    encounterForm = null;

    return mapping.findForward("success");

}

From source file:com.emergya.persistenceGeo.web.RestTreeFolderController.java

/**
 * Returns the node types//w w  w  .  j  a  v a  2  s .  co  m
 * 
 * @param parentType
 *            The condition node type the returned nodes has to meet
 * 
 * @return JSON file with success
 */
@RequestMapping(value = "/persistenceGeo/tree/getNodeTypes/{parentType}", produces = {
        MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody List<FolderTypeDto> getNodeTypes(@PathVariable String parentType) {

    Map<String, Object> result = new HashMap<String, Object>();
    List<FolderTypeDto> iptFolderTypes = new LinkedList<FolderTypeDto>();
    try {
        Long parentId = null;
        if (parentType != null && StringUtils.isNumeric(parentType)) {
            parentId = Long.decode(parentType);
        }
        iptFolderTypes = foldersAdminService.getFolderTypes(parentId);
    } catch (Exception e) {
        LOG.error(e);
        result.put(SUCCESS, false);
    }
    return iptFolderTypes;
}