Example usage for java.util Map toString

List of usage examples for java.util Map toString

Introduction

In this page you can find the example usage for java.util Map toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.streak.logging.analysis.LogExportDirectToBigqueryTask.java

public void streamToBigquery(long logRangeStartMs, long logRangeEndMs, LogsExportConfiguration exportConfig,
        LogsFieldExporterSet exporterSet, List<LogsFieldExporter> exporters, Iterable<RequestLogs> logs)
        throws UnsupportedEncodingException, IOException, GoogleJsonResponseException {
    List<Map<String, Object>> rows = new ArrayList<>();
    List<String> insertIds = new ArrayList<>();

    int resultsCount = 0;
    long singleExportBytes = 2;

    for (RequestLogs log : logs) {

        Map<String, Object> row = new HashMap<>();
        if (exporterSet.skipLog(log)) {
            continue;
        }/*from w w  w.  j a  v a  2s. c  o  m*/

        for (LogsFieldExporter exporter : exporters) {
            exporter.processLog(log);

            for (int fieldIndex = 0; fieldIndex < exporter.getFieldCount(); fieldIndex++) {
                String fieldName = exporter.getFieldName(fieldIndex);
                String fieldType = exporter.getFieldType(fieldIndex);
                Object fieldValue = exporter.getField(fieldName);

                if (fieldValue == null && !exporter.getFieldNullable(fieldIndex)) {
                    throw new InvalidFieldException("Exporter " + exporter.getClass().getCanonicalName()
                            + " didn't return field for " + fieldName);
                }
                try {
                    AnalysisUtility.putJsonValueFormatted(row, fieldName, fieldValue, fieldType);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
        long rowBytes = row.toString().getBytes("UTF-8").length + 1; // Assumes a comma for every array item but w/e, conservative is fine

        if (singleExportBytes + rowBytes > MAX_BYTES_PER_POST) {
            BigqueryIngester.streamingRowIngestion(rows, insertIds,
                    exportConfig.getBigqueryTableId(logRangeStartMs, logRangeEndMs),
                    exportConfig.getBigqueryDatasetId(), exportConfig.getBigqueryProjectId(),
                    exportConfig.getBigquery());
            rows = new ArrayList<Map<String, Object>>();
            insertIds = new ArrayList<>();
            singleExportBytes = 0;
        }

        singleExportBytes += rowBytes;
        rows.add(row);
        insertIds.add(log.getRequestId());

        resultsCount++;
        if (resultsCount == 19 && AnalysisUtility.isDev()) {
            break; // stupid dev server bug: https://code.google.com/p/googleappengine/issues/detail?id=8987
        }
    }

    if (!rows.isEmpty()) {
        BigqueryIngester.streamingRowIngestion(rows, insertIds,
                exportConfig.getBigqueryTableId(logRangeStartMs, logRangeEndMs),
                exportConfig.getBigqueryDatasetId(), exportConfig.getBigqueryProjectId(),
                exportConfig.getBigquery());
    }
    log.warning(resultsCount + " rows exported");
}

From source file:com.oneops.controller.cms.DeploymentNotifier.java

protected void sendDpmtNotification(CmsDeployment dpmt) {
    try {//  ww  w.  ja v a  2s.c  om
        if (dpmt.getDeploymentState().equalsIgnoreCase(CMSClient.FAILED)) {
            Map<String, Object> payloadEntries = new HashMap<>();
            try {
                CmsDpmtRecord[] drs = restTemplate.getForObject(
                        serviceUrl + "/dj/simple/deployments/{deploymentId}/cis?state=failed",
                        CmsDpmtRecord[].class, dpmt.getDeploymentId());
                if (drs != null) {
                    for (CmsDpmtRecord dr : drs) {
                        CmsRfcCISimple rfc = restTemplate.getForObject(
                                serviceUrl + "/dj/simple/rfc/cis/{rfcId}", CmsRfcCISimple.class, dr.getRfcId());
                        if (rfc != null) {
                            payloadEntries.put(rfc.getCiClassName() + "::" + rfc.getCiName(), dr.getComments());
                        }
                    }
                }
            } catch (HttpClientErrorException e) {
                logger.error("HttpClientErrorException in sendDpmtNotification", e);
            }
            sendDeploymentNotification(dpmt, "Deployment failed.",
                    payloadEntries.toString() + createDeploymentNotificationText(dpmt),
                    NotificationSeverity.critical, payloadEntries);
        } else if (dpmt.getDeploymentState().equalsIgnoreCase(CMSClient.COMPLETE)) {
            sendDeploymentNotification(dpmt, "Deployment completed successfully.",
                    createDeploymentNotificationText(dpmt), NotificationSeverity.info, null);
        } else if (dpmt.getDeploymentState().equalsIgnoreCase("active")) {
            sendDeploymentNotification(dpmt, "Deployment started by "
                    + (StringUtils.isBlank(dpmt.getUpdatedBy()) ? dpmt.getCreatedBy() : dpmt.getUpdatedBy()),
                    createDeploymentNotificationText(dpmt), NotificationSeverity.info, null);
        }
    } catch (Exception e) {
        //we don't want to end-up with stuck deployment if the issue with sending notification, just log it and move on
        logger.error("Exception in sendDpmtNotification", e);
    }
}

From source file:org.geoserver.gwc.GWCTest.java

private void testParameterFilter(GetMapRequest request, Map<String, String> rawKvp, String rawKvpParamName,
        String rawKvpParamValue) {

    // set up raw kvp
    rawKvp.put(rawKvpParamName, rawKvpParamValue);

    StringBuilder errors = new StringBuilder();
    ConveyorTile tileRequest = mediator.prepareRequest(tileLayer, request, errors);
    assertTrue(errors.toString(), errors.length() == 0);

    Map<String, String> fullParameters = tileRequest.getFullParameters();
    assertEquals(fullParameters.toString(), rawKvpParamValue,
            fullParameters.get(rawKvpParamName.toUpperCase()));
}

From source file:com.streamsets.pipeline.stage.processor.hbase.HBaseProcessorIT.java

@Test(timeout = 60000)
public void testGetRow() throws Exception {
    Map<String, Field> expectedMap = new HashMap<>();
    expectedMap.put("cf:column1", Field.create("value1"));
    expectedMap.put("cf:column2", Field.create("value2"));

    HBaseLookupConfig config = getDefaultConfig();
    config.lookups.get(0).columnExpr = "";
    Processor processor = new HBaseLookupProcessor(config);

    List<Record> records = new ArrayList<>();
    Record record = RecordCreator.create();

    Map<String, Field> fields = new HashMap<>();
    fields.put("keyField", Field.create("row1"));
    record.set(Field.create(fields));
    records.add(record);//  w  w w  . j a  va  2  s. c om

    ProcessorRunner runner = new ProcessorRunner.Builder(HBaseLookupDProcessor.class, processor)
            .addOutputLane("lane").setOnRecordError(OnRecordError.TO_ERROR).build();
    runner.runInit();
    runner.runProcess(records);

    assertTrue(runner.getErrorRecords().isEmpty());

    Map<String, Field> value = (Map<String, Field>) record.get(config.lookups.get(0).outputFieldPath)
            .getValue();
    assertEquals(expectedMap.toString(), value.toString());
}

From source file:com.stvn.nscreen.my.MyPurchaseListFragment.java

/**
 * ?  //from   w  w  w  .  j a v  a 2  s  . c  o  m
 */
public void requestGetBundleProductInfo(final HashMap<String, Boolean> mapProductId) {
    String terminalKey = mPref.getWebhasTerminalKey();

    final Date compareDate = new Date();

    for (String productID : mapProductId.keySet()) {
        String url = mPref.getWebhasServerUrl() + "/getBundleProductInfo.json?version=1&terminalKey="
                + terminalKey + "&productId=" + productID;

        JYStringRequest request = new JYStringRequest(mPref, Request.Method.GET, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject responseObject = new JSONObject(response);
                            JSONObject bundleObject = responseObject.getJSONObject("bundleProduct");
                            String licenseStart = bundleObject.getString("licenseStart");
                            String licenseEnd = bundleObject.getString("licenseEnd");
                            String externalProductId = bundleObject.getString("externalProductId");
                            String productId = bundleObject.getString("productId");

                            for (ListViewDataObject dataObject : mResponseList) {
                                JSONObject obj = new JSONObject(dataObject.sJson);
                                String listProductId = obj.getString("productId");
                                if (productId.equals(listProductId)) {
                                    obj.put("licenseStart", licenseStart);
                                    obj.put("licenseEnd", licenseEnd);
                                    obj.put("externalProductId", externalProductId);
                                    dataObject.sJson = obj.toString();
                                }
                            }
                            mapProductId.put(productId, true);

                            Boolean isResponsed = false;
                            for (String key : mapProductId.keySet()) {
                                isResponsed = mapProductId.get(key);
                                if (isResponsed == false) {
                                    break;
                                }
                            }

                            if (isResponsed == true) {
                                // 
                                ArrayList<ListViewDataObject> moblieList_1 = new ArrayList<>();
                                ArrayList<ListViewDataObject> tvList_1 = new ArrayList<>();
                                //  
                                ArrayList<ListViewDataObject> moblieList_2 = new ArrayList<>();
                                ArrayList<ListViewDataObject> tvList_2 = new ArrayList<>();
                                //  
                                ArrayList<ListViewDataObject> moblieList_3 = new ArrayList<>();
                                ArrayList<ListViewDataObject> tvList_3 = new ArrayList<>();

                                for (ListViewDataObject dataObject : mResponseList) {
                                    JSONObject obj = new JSONObject(dataObject.sJson);
                                    String purchaseDeviceType = obj.getString("purchaseDeviceType"); // 1:TV, 2:MOBILE
                                    String purchasedTime = obj.getString("purchasedTime");
                                    String viewablePeriod = obj.getString("viewablePeriod");

                                    dataObject.puchaseSecond = CMDateUtil.changeSecondToDate(purchasedTime);
                                    dataObject.viewablePeriodState = obj.getString("viewablePeriodState");

                                    if ("1".equals(dataObject.viewablePeriodState) == false) {
                                        dataObject.remainTime = CMDateUtil.getRemainWatchingTime(viewablePeriod,
                                                purchasedTime, compareDate);

                                        if (dataObject.remainTime < 0) {
                                            if ("1".equals(purchaseDeviceType)) {
                                                tvList_3.add(dataObject);
                                            } else if ("2".equals(purchaseDeviceType)) {
                                                moblieList_3.add(dataObject);
                                            }
                                        } else {
                                            if ("1".equals(purchaseDeviceType)) {
                                                tvList_2.add(dataObject);
                                            } else if ("2".equals(purchaseDeviceType)) {
                                                moblieList_2.add(dataObject);
                                            }
                                        }
                                    } else {
                                        if ("1".equals(purchaseDeviceType)) {
                                            tvList_1.add(dataObject);
                                        } else if ("2".equals(purchaseDeviceType)) {
                                            moblieList_1.add(dataObject);
                                        }
                                    }
                                }
                                //   .
                                sortPurchaseList_1(moblieList_1);
                                sortPurchaseList_2(moblieList_2);
                                sortPurchaseList_3(moblieList_3);

                                sortPurchaseList_1(tvList_1);
                                sortPurchaseList_2(tvList_2);
                                sortPurchaseList_3(tvList_3);

                                mMoblieList.addAll(moblieList_1);
                                mMoblieList.addAll(moblieList_2);
                                mMoblieList.addAll(moblieList_3);

                                mTVList.addAll(tvList_1);
                                mTVList.addAll(tvList_2);
                                mTVList.addAll(tvList_3);

                                ((MyMainActivity) getActivity()).hideProgressDialog();
                                changeListData();
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ((MyMainActivity) getActivity()).hideProgressDialog();
                        if (mPref.isLogging()) {
                            VolleyLog.d("", "onErrorResponse(): " + error.getMessage());
                        }
                    }
                }) {
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<String, String>();
                params.put("version", String.valueOf(1));
                if (mPref.isLogging()) {
                    Log.d("", "getParams()" + params.toString());
                }
                return params;
            }
        };
        mRequestQueue.add(request);
    }
}

From source file:org.cloudfoundry.identity.uaa.oauth.UaaAuthenticationKeyGenerator.java

@Override
public String extractKey(OAuth2Authentication authentication) {
    Map<String, Object> values = new LinkedHashMap<String, Object>();
    AuthorizationRequest authorizationRequest = authentication.getAuthorizationRequest();
    if (!authentication.isClientOnly()) {
        values.putAll(userTokenConverter.convertUserAuthentication(authentication.getUserAuthentication()));
    }//from w w w.j  a  v  a  2  s .c o m
    ClientDetails client = clientDetailsService.loadClientByClientId(authorizationRequest.getClientId());
    values.put(CLIENT_ID, client.getClientId());
    if (authorizationRequest.getScope() != null) {
        values.put(SCOPE, OAuth2Utils.formatParameterList(authorizationRequest.getScope()));
    }
    Integer validity = client.getAccessTokenValiditySeconds();
    if (validity != null) {
        values.put(ACCESS_TOKEN_VALIDITY, validity);
    }
    validity = client.getRefreshTokenValiditySeconds();
    if (validity != null && client.getAuthorizedGrantTypes().contains("refresh_token")) {
        values.put(REFRESH_TOKEN_VALIDITY, validity);
    }
    MessageDigest digest;
    try {
        digest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException("MD5 algorithm not available.  Fatal (should be in the JDK).");
    }

    try {
        byte[] bytes = digest.digest(values.toString().getBytes("UTF-8"));
        return String.format("%032x", new BigInteger(1, bytes));
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException("UTF-8 encoding not available.  Fatal (should be in the JDK).");
    }
}

From source file:com.stvn.nscreen.my.MyPurchaseListFragment.java

public void requestGetAssetInfoWithBundleAssetId(String primaryAssetId) {
    ((MyMainActivity) getActivity()).showProgressDialog("", getString(R.string.wait_a_moment));

    String terminalKey = mPref.getWebhasTerminalKey();
    String encAssetId = null;// ww w.  j  av  a2  s .c om
    try {
        encAssetId = URLDecoder.decode(primaryAssetId, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    String url = mPref.getWebhasServerUrl() + "/getAssetInfo.json?version=1&terminalKey=" + terminalKey
            + "&assetProfile=9&assetId=" + encAssetId;
    JYStringRequest request = new JYStringRequest(mPref, Request.Method.GET, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    ((MyMainActivity) getActivity()).hideProgressDialog();

                    boolean needJumpAsset = true;
                    try {
                        JSONObject jo = new JSONObject(response);
                        JSONObject asset = jo.getJSONObject("asset");
                        JSONArray productList = asset.getJSONArray("productList");
                        for (int i = 0; i < productList.length(); i++) {
                            JSONObject product = (JSONObject) productList.get(i);
                            String productType = product.getString("productType");
                            if ("Bundle".equals(productType)) {
                                String assetId = asset.getString("assetId");
                                startActivityAssetOrBundle(assetId, product);
                                needJumpAsset = false;
                                break;
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    if (needJumpAsset == true) {
                        //  . ? (?)?,   ? ? startActivityAssetOrBundle() ?.
                        // ???, ??? ?     ?   .
                        try {
                            JSONObject jo = new JSONObject(response);
                            JSONObject asset = jo.getJSONObject("asset");
                            String assetId = asset.getString("assetId");
                            Intent intent = new Intent(getActivity(), VodDetailActivity.class);
                            intent.putExtra("assetId", assetId);
                            getActivity().startActivity(intent);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    ((MyMainActivity) getActivity()).hideProgressDialog();
                    if (mPref.isLogging()) {
                        VolleyLog.d("MyPurchaseListFragment", "onErrorResponse(): " + error.getMessage());
                    }
                }
            }) {
        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<String, String>();
            params.put("version", String.valueOf(1));
            params.put("areaCode", String.valueOf(0));
            if (mPref.isLogging()) {
                Log.d("MyPurchaseListFragment", "getParams()" + params.toString());
            }
            return params;
        }
    };
    mRequestQueue.add(request);
}

From source file:com.newrelic.agent.transport.DataSenderImpl.java

private Exception parseException(Map<?, ?> responseMap)/* :17:    */ throws Exception
/* :18:    */ {/*from  ww w.j a v  a2  s .co m*/
    /* :19:823 */ Object exception = responseMap.get("exception");
    /* :20:824 */ if (exception == null) {
        /* :21:825 */ return null;
        /* :22:    */ }
    /* :23:827 */ Map<?, ?> exceptionMap = (Map) Map.class.cast(exception);
    /* :24:    */ String message;
    /* :25:    */ try
    /* :26:    */ {
        /* :27:830 */ message = (String) exceptionMap.get("message");
        /* :28:    */ }
    /* :29:    */ catch (Exception e)
    /* :30:    */ {
        /* :31:832 */ message = exceptionMap.toString();
        /* :32:    */ }
    /* :33:834 */ String type = (String) exceptionMap.get("error_type");
    /* :34:835 */ Class<Exception> clazz = RubyConversion.rubyClassToJavaClass(type);
    /* :35:836 */ Constructor<Exception> constructor = clazz.getConstructor(new Class[] { String.class });
    /* :36:837 */ return (Exception) constructor.newInstance(new Object[] { message });
    /* :37:    */ }

From source file:org.fusesource.restygwt.client.codec.EncoderDecoderTestGwt.java

public void testTypeMapDecode() {
    Map<String, Integer> map = new HashMap<String, Integer>();
    map.put("123", 321);
    AbstractJsonEncoderDecoder<Integer> encoder = AbstractJsonEncoderDecoder.INT;
    assertEquals(map.toString(),
            AbstractJsonEncoderDecoder/*w  w w  . ja  v  a 2  s.com*/
                    .toMap(AbstractJsonEncoderDecoder.toJSON(map, encoder, Json.Style.DEFAULT), encoder,
                            Json.Style.DEFAULT)
                    .toString());
    assertEquals(map.toString(),
            AbstractJsonEncoderDecoder
                    .toMap(AbstractJsonEncoderDecoder.toJSON(map, encoder, Json.Style.JETTISON_NATURAL),
                            encoder, Json.Style.JETTISON_NATURAL)
                    .toString());
}

From source file:org.codice.alliance.nsili.source.NsiliSource.java

@Override
public ResourceResponse retrieveResource(URI resourceUri, Map<String, Serializable> requestProperties)
        throws IOException, ResourceNotFoundException, ResourceNotSupportedException {
    LOGGER.debug("{}, {}, {}, {}", resourceUri.getHost(), resourceUri.getPath(), resourceUri.getPort(),
            requestProperties.toString());
    return resourceReader.retrieveResource(resourceUri, requestProperties);
}