Example usage for java.util LinkedHashMap put

List of usage examples for java.util LinkedHashMap put

Introduction

In this page you can find the example usage for java.util LinkedHashMap put.

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:admin.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  w  w w. j  a  v a2  s  .  c om*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession session = request.getSession();
    response.setContentType("application/json;charset=UTF-8");
    String id = "";
    String nama = "";
    String email = "";
    String link = "";
    String admin = "";
    String icw = "";
    try {
        JSONObject userAccount = (JSONObject) session.getAttribute("userAccount");
        id = userAccount.get("id").toString();
        nama = userAccount.get("name").toString();
        email = userAccount.get("email").toString();
        link = userAccount.get("link").toString();
        admin = userAccount.get("admin").toString();
        icw = userAccount.get("icw").toString();
    } catch (Exception ex1) {
    }
    if (admin.equalsIgnoreCase("Y")) {
        try (PrintWriter out = response.getWriter()) {
            Vector dataPosisi = new Vector();
            dataPosisi.addElement("Menteri");
            dataPosisi.addElement("Pejabat Setingkat Menteri");
            dataPosisi.addElement("Duta Besar");
            JSONArray obj1 = new JSONArray();
            for (int i = 0; i < dataPosisi.size(); i++) {
                String FilterKey = "", FilterValue = "";
                String key = "posisi",
                        keyValue = dataPosisi.get(i).toString().toLowerCase().replaceAll(" ", "");
                String table = "posisi";
                DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
                //Filter linkFilter = new FilterPredicate(FilterKey, FilterOperator.EQUAL, FilterValue);
                Key AlasanStarCalonKey = KeyFactory.createKey(key, keyValue);
                Query query = new Query(table, AlasanStarCalonKey);
                PreparedQuery pq = datastore.prepare(query);
                JSONArray obj11 = new JSONArray();
                getData(obj11, table, key, keyValue, dataPosisi.get(i).toString(),
                        Query.SortDirection.ASCENDING);
                LinkedHashMap record = new LinkedHashMap();
                record.put("posisi", keyValue);
                record.put("nama", dataPosisi.get(i).toString());
                record.put("child", obj11);
                obj1.add(record);
            }
            out.print(JSONValue.toJSONString(obj1));
            out.flush();
        }
    }
}

From source file:com.itemanalysis.jmetrik.file.JmetrikOutputWriter.java

public void saveJmetrikFile(File outputFile, Outputter outputter) throws IOException {

    ArrayList<VariableAttributes> variables = outputter.getColumnAttributes();
    LinkedHashMap<VariableName, VariableAttributes> variableAttributeMap = new LinkedHashMap<VariableName, VariableAttributes>();
    for (VariableAttributes v : variables) {
        variableAttributeMap.put(v.getName(), v);
    }//from ww  w.  j a va 2  s  . co m

    //Ensure that file is a jMetrik file.
    String fname = FilenameUtils.removeExtension(outputFile.getAbsolutePath());
    outputFile = new File(fname + ".jmetrik");

    JmetrikFileWriter writer = new JmetrikFileWriter(outputFile, variableAttributeMap);

    try {
        writer.openConnection();
        writer.writeHeader(outputter.getNumberOfOutputRows());

        Iterator<Object[][]> iter = outputter.iterator();
        Object[][] outputChunk = null;

        while (iter.hasNext()) {
            outputChunk = iter.next();
            for (int i = 0; i < outputChunk.length; i++) {
                for (int j = 0; j < outputChunk[0].length; j++) {
                    VariableAttributes v = variables.get(j);
                    if (outputChunk[i][j] != null) {
                        writer.writeValue(v.getName(), outputChunk[i][j].toString());
                    }

                }
                writer.updateRow();
            }

        }

    } catch (IOException ex) {
        throw ex;
    } finally {
        writer.close();
    }

}

From source file:hydrograph.ui.propertywindow.widgets.customwidgets.TextBoxWithLabelWidget.java

@Override
public LinkedHashMap<String, Object> getProperties() {
    LinkedHashMap<String, Object> property = new LinkedHashMap<>();
    property.put(propertyName, textBox.getText());
    setToolTipErrorMessage();/*from w  ww . j a  v a  2  s  . c o m*/
    showHideErrorSymbol(widgets);
    return property;
}

From source file:com.streamsets.pipeline.stage.destination.hive.HiveMetastoreTargetIT.java

@Test
public void testPartitionLocationMismatch() throws Exception {
    HiveMetastoreTarget hiveTarget = new HiveMetastoreTargetBuilder().build();

    TargetRunner runner = new TargetRunner.Builder(HiveMetastoreTarget.class, hiveTarget)
            .setOnRecordError(OnRecordError.TO_ERROR).build();
    runner.runInit();/* ww  w  . ja va 2  s .  c o m*/

    LinkedHashMap<String, HiveTypeInfo> columns = new LinkedHashMap<>();
    columns.put("name", HiveType.STRING.getSupport().generateHiveTypeInfoFromResultSet("STRING"));

    LinkedHashMap<String, HiveTypeInfo> partitions = new LinkedHashMap<>();
    partitions.put("dt", HiveType.STRING.getSupport().generateHiveTypeInfoFromResultSet("STRING"));

    Field newTableField = HiveMetastoreUtil.newSchemaMetadataFieldBuilder("default", "tbl", columns, partitions,
            true, BaseHiveIT.getDefaultWareHouseDir(), HiveMetastoreUtil.generateAvroSchema(columns, "tbl"));

    Record record = RecordCreator.create();
    record.set(newTableField);
    Assert.assertTrue(HiveMetastoreUtil.isSchemaChangeRecord(record));

    runner.runWrite(ImmutableList.of(record));

    Assert.assertEquals("There should be no error records", 0, runner.getErrorRecords().size());

    LinkedHashMap<String, String> partitionVals = new LinkedHashMap<>();
    partitionVals.put("dt", "2016");

    Field newPartitionField1 = HiveMetastoreUtil.newPartitionMetadataFieldBuilder("default", "tbl",
            partitionVals, "/user/hive/external/tbl/location1");
    record = RecordCreator.create();
    record.set(newPartitionField1);
    runner.runWrite(ImmutableList.of(record));
    Assert.assertEquals("There should be no error records", 0, runner.getErrorRecords().size());

    Field newPartitionField2 = HiveMetastoreUtil.newPartitionMetadataFieldBuilder("default", "tbl",
            partitionVals, "/user/hive/external/tbl/location2");

    record = RecordCreator.create();
    record.set(newPartitionField2);
    runner.runWrite(ImmutableList.of(record));
    Assert.assertEquals("There should be no error records", 1, runner.getErrorRecords().size());
    Record errorRecord = runner.getErrorRecords().get(0);
    Assert.assertEquals("Error codes mismatch", Errors.HIVE_31.name(), errorRecord.getHeader().getErrorCode());
}

From source file:com.intel.iotkitlib.ComponentCatalogManagement.java

/**
 * Get a complete description of a component type for a specific component.
 * @param componentId the identifier for the component to get information for.
 * @return For async model, return CloudResponse which wraps true if the request of REST
 * call is valid; otherwise false. The actual result from
 * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}.
 * For synch model, return CloudResponse which wraps HTTP return code and response.
 *//*from w w w.  j a va  2s. co  m*/
public CloudResponse listComponentTypeDetails(String componentId) {
    //initiating get for component type details
    HttpGetTask componentTypeDetails = new HttpGetTask();
    componentTypeDetails.setHeaders(basicHeaderList);
    LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap<String, String>();
    linkedHashMap.put("cmp_catalog_id", componentId);
    String url = objIotKit.prepareUrl(objIotKit.componentTypeCatalogDetails, linkedHashMap);
    return super.invokeHttpExecuteOnURL(url, componentTypeDetails);
}

From source file:com.intel.iotkitlib.DataManagement.java

/**
 * Submit data for specific device and it's component. Device and component have to be
 * registered in the cloud before sending observations.
 *
 * @param deviceId       the identifier for the device to submit the data for.
 * @param componentName  the name of the component to look up the component id.
 * @param componentValue the value to set for the component.
 * @param latitude       lat location for the device in decimal
 * @param longitude      lon location for the device in decimal
 * @param height         altitude value in meters
 * @return For async model, return CloudResponse which wraps true if the request of REST
 * call is valid; otherwise false. The actual result from
 * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}.
 * For synch model, return CloudResponse which wraps HTTP return code and response.
 * @throws JSONException// w  w  w  . j a  v  a2 s .  c  om
 */
public CloudResponse submitData(String deviceId, String componentName, String componentValue, Double latitude,
        Double longitude, Double height) throws JSONException {
    String componentId = validateRequestBodyParametersAndGetcomponentId(componentName, componentValue);
    if (componentId == null) {
        Log.d(TAG, ERR_SUBMIT_DATA);
        return new CloudResponse(false, ERR_SUBMIT_DATA);
    }
    String body = createHttpBodyToSubmitData(componentId, componentValue, latitude, longitude, height);
    //initiating post for data submission
    HttpPostTask submitDeviceData = new HttpPostTask();
    List<NameValuePair> submitDataHeaders = Utilities.createBasicHeadersWithDeviceToken();
    if (submitDataHeaders == null) {
        Log.d(TAG, ERR_CREATE_DATA);
        return new CloudResponse(false, ERR_CREATE_DATA);
    }

    LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap<String, String>();
    linkedHashMap.put("device_id", deviceId);
    submitDeviceData.setHeaders(submitDataHeaders);
    submitDeviceData.setRequestBody(body);
    String url = objIotKit.prepareUrl(objIotKit.submitData, linkedHashMap);
    return super.invokeHttpExecuteOnURL(url, submitDeviceData);

}

From source file:com.intel.iotkitlib.LibModules.RuleManagement.RuleManagement.java

public boolean getInformationOnRule(String ruleId) {
    if (ruleId == null) {
        Log.d(TAG, "rule id cannot be null");
        return false;
    }//  w w w  .j a va2s .  c  o m
    //initiating get for rule info
    HttpGetTask infoOnRule = new HttpGetTask(new HttpTaskHandler() {
        @Override
        public void taskResponse(int responseCode, String response) {
            Log.d(TAG, String.valueOf(responseCode));
            Log.d(TAG, response);
            statusHandler.readResponse(responseCode, response);
        }
    });
    infoOnRule.setHeaders(basicHeaderList);
    LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap<String, String>();
    linkedHashMap.put("rule_id", ruleId);
    String url = objIotKit.prepareUrl(objIotKit.getInfoOfRule, linkedHashMap);
    return super.invokeHttpExecuteOnURL(url, infoOnRule, "info on one rule");
}

From source file:com.intel.iotkitlib.LibModules.RuleManagement.RuleManagement.java

public boolean deleteADraftRule(String ruleId) {
    if (ruleId == null) {
        Log.d(TAG, "rule id cannot be null");
        return false;
    }/* ww  w.  j  av a2 s  .c  o m*/
    //initiating delete for draft rule
    HttpDeleteTask deleteDraftRule = new HttpDeleteTask(new HttpTaskHandler() {
        @Override
        public void taskResponse(int responseCode, String response) {
            Log.d(TAG, String.valueOf(responseCode));
            Log.d(TAG, response);
            statusHandler.readResponse(responseCode, response);
        }
    });
    deleteDraftRule.setHeaders(basicHeaderList);
    LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap<String, String>();
    linkedHashMap.put("rule_id", ruleId);
    String url = objIotKit.prepareUrl(objIotKit.deleteDraftRule, linkedHashMap);
    return super.invokeHttpExecuteOnURL(url, deleteDraftRule, "delete draft rule");
}

From source file:com.tesora.dve.sql.StrictForeignKeyTest.java

public static void testAlterFKs(TestConnections conns) throws Throwable {
    String[] rhsTabNames = new String[] { "RB", "RRa" };
    String[] rhsDists = new String[] { "broadcast distribute", "range distribute on (`id`) using ra" };
    String[] lhsTabNames = new String[] { "LB", "LRa", "LA" };
    String[] lhsDists = new String[] { "broadcast distribute", "range distribute on (`fid`) using ra",
            "random distribute" };
    conns.getRootConnection()//  ww w .j av  a2s  .  c  om
            .execute("create range ra (int) persistent group " + conns.getDDL().getPersistentGroup().getName());
    String rbody = "(`id` int, `junk` varchar(32), primary key (`id`)) ";
    // create the rhs tables
    for (int i = 0; i < rhsTabNames.length; i++)
        conns.getTestConnection().execute("create table " + rhsTabNames[i] + rbody + rhsDists[i]);
    // create the lhs tables - but not the fks yet
    // create the lhs tables
    String lbody = " (`id` int, `fid` int)";
    LinkedHashMap<String, Pair<String, String>> alters = new LinkedHashMap<String, Pair<String, String>>();
    int counter = 0;
    for (int li = 0; li < lhsTabNames.length; li++) {
        if (li == 0) {
            conns.getTestConnection().execute("create table " + lhsTabNames[li] + lbody + lhsDists[li]);
            String fkName = "pefkt" + counter++;
            alters.put(fkName, new Pair<String, String>(lhsTabNames[li], "alter table " + lhsTabNames[li]
                    + " add constraint " + fkName + " foreign key (fid) references RB (`id`)"));
        }
        // LRa - can target bcast and RRa
        // LA - can target bcast
        else if (li == 1) {
            for (int ri = 0; ri < rhsTabNames.length; ri++) {
                conns.getTestConnection()
                        .execute("create table " + lhsTabNames[li] + rhsTabNames[ri] + lbody + lhsDists[li]);
                String fkName = "pefkt" + counter++;
                String tn = lhsTabNames[li] + rhsTabNames[ri];
                alters.put(fkName, new Pair<String, String>(tn, "alter table " + tn + " add constraint "
                        + fkName + " foreign key (fid) references " + rhsTabNames[ri] + "(id)"));
            }
        } else if (li == 2) {
            conns.getTestConnection().execute("create table " + lhsTabNames[li] + lbody + lhsDists[li]);
            String fkName = "pefkt" + counter++;
            alters.put(fkName, new Pair<String, String>(lhsTabNames[li], "alter table " + lhsTabNames[li]
                    + " add constraint " + fkName + " foreign key (fid) references RB (id)"));
        }
    }
    String consql = "select table_name, column_name, referenced_table_name, referenced_column_name from information_schema.key_column_usage where referenced_column_name is not null and table_schema = '"
            + checkDDL.getDatabaseName() + "'";
    conns.getTestConnection().assertResults(consql, br());
    // these all should work
    for (Map.Entry<String, Pair<String, String>> me : alters.entrySet()) {
        conns.getTestConnection().execute(me.getValue().getSecond());
    }
    Object[] cols = br(nr, "LB", "fid", "RB", "id", nr, "LRaRB", "fid", "RB", "id", nr, "LRaRRa", "fid", "RRa",
            "id", nr, "LA", "fid", "RB", "id");
    conns.getTestConnection().assertResults(consql, cols);
    for (Map.Entry<String, Pair<String, String>> me : alters.entrySet()) {
        conns.getTestConnection()
                .execute("alter table " + me.getValue().getFirst() + " drop foreign key " + me.getKey());
    }
    conns.getTestConnection().assertResults(consql, br());
    // test foreign_key_check=0
    for (String tn : rhsTabNames)
        conns.getTestConnection().execute("drop table " + tn);
    conns.getTestConnection().execute("set foreign_key_checks=0");
    // these all should work
    for (Map.Entry<String, Pair<String, String>> me : alters.entrySet()) {
        conns.getTestConnection().execute(me.getValue().getSecond());
    }
    conns.getTestConnection().assertResults(consql, cols);
    // even after we add the tables again
    for (int i = 0; i < rhsTabNames.length; i++)
        conns.getTestConnection().execute("create table " + rhsTabNames[i] + rbody + rhsDists[i]);
    conns.getTestConnection().assertResults(consql, cols);

}

From source file:com.intel.iotkitlib.ComponentCatalogManagement.java

/**
 * Update a component type definition by creating a brand new component which definition is
 * composed by the origin component data plus the requested changes having in mind that minor
 * version info (version attribute) is incremented by 1.
 * @param componentCatalog the component type to be updated in the catalog.
 * @param componentId the identifier for the component to be updated.
 * @return For async model, return CloudResponse which wraps true if the request of REST
 * call is valid; otherwise false. The actual result from
 * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}.
 * For synch model, return CloudResponse which wraps HTTP return code and response.
 * @throws JSONException//from   w  w  w  . j  a  v a 2 s.co  m
 */
public CloudResponse updateAComponent(ComponentCatalog componentCatalog, String componentId)
        throws JSONException {
    if (!validateActuatorCommand(componentCatalog)) {
        return new CloudResponse(false, ERR_INVALID_COMMAND);
    }
    String body;
    if ((body = createBodyForComponentUpdate(componentCatalog)) == null) {
        return new CloudResponse(false, ERR_INVALID_BODY);
    }
    //initiating put for component updation
    HttpPutTask updateComponent = new HttpPutTask();
    updateComponent.setHeaders(basicHeaderList);
    LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap<String, String>();
    linkedHashMap.put("cmp_catalog_id", componentId);
    updateComponent.setRequestBody(body);
    String url = objIotKit.prepareUrl(objIotKit.updateComponent, linkedHashMap);
    return super.invokeHttpExecuteOnURL(url, updateComponent);
}