List of usage examples for java.util Map getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.apache.shindig.social.opensocial.util.BeanJsonLibConverterTest.java
@SuppressWarnings("unchecked") public void testJsonToMap() throws Exception { String jsonActivity = "{count : 0, favoriteColor : 'yellow'}"; Map<String, Object> data = Maps.newHashMap(); data = beanJsonConverter.convertToObject(jsonActivity, (Class<Map<String, Object>>) data.getClass()); assertEquals(2, data.size());/*from w w w .j av a2 s . c o m*/ for (Entry<String, Object> entry : data.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (key.equals("count")) { assertEquals(0, value); } else if (key.equals("favoriteColor")) { assertEquals("yellow", value); } } }
From source file:com.impetus.kundera.rest.resources.PolyglotQueryTest.java
@Test public void testUserCRUD() throws JsonParseException, JsonMappingException, IOException { WebResource webResource = resource(); restClient = new RESTClientImpl(); restClient.initialize(webResource, mediaType); buildUser1Str();//w ww .j a v a2 s . com // Get Application Token applicationToken = restClient.getApplicationToken(_PU, null); Assert.assertNotNull(applicationToken); applicationToken = applicationToken.replaceAll("^\"|\"$", ""); Assert.assertTrue(applicationToken.startsWith("AT_")); // Get Session Token sessionToken = restClient.getSessionToken(applicationToken); Assert.assertNotNull(sessionToken); sessionToken = sessionToken.replaceAll("^\"|\"$", ""); Assert.assertTrue(sessionToken.startsWith("ST_")); // Insert Record String insertResponse1 = restClient.insertEntity(sessionToken, userString, UserCassandra.class.getSimpleName()); Assert.assertNotNull(insertResponse1); Assert.assertTrue(insertResponse1.indexOf("200") > 0); // Find Record String foundUser = restClient.findEntity(sessionToken, "0001", UserCassandra.class.getSimpleName()); Assert.assertNotNull(foundUser); Assert.assertTrue(foundUser.indexOf("0001") > 0); foundUser = foundUser.substring(1, foundUser.length() - 1); Map<String, Object> userDetails = new HashMap<String, Object>(); ObjectMapper mapper = new ObjectMapper(); userDetails = mapper.readValue(foundUser, userDetails.getClass()); foundUser = mapper.writeValueAsString(userDetails.get("usercassandra")); // Update Record foundUser = foundUser.replaceAll("163.12", "165.21"); String updatedUser = restClient.updateEntity(sessionToken, foundUser, UserCassandra.class.getSimpleName()); Assert.assertNotNull(updatedUser); Assert.assertTrue(updatedUser.indexOf("165.21") > 0); /** JPA Query - Select */ // Get All Professionals String jpaQuery = "select p from " + UserCassandra.class.getSimpleName() + " p"; String queryResult = restClient.runJPAQuery(sessionToken, jpaQuery, new HashMap<String, Object>()); log.debug("Query Result:" + queryResult); Assert.assertNotNull(queryResult); Assert.assertFalse(StringUtils.isEmpty(queryResult)); Assert.assertTrue(queryResult.indexOf("usercassandra") > 0); Assert.assertTrue(queryResult.indexOf("0001") > 0); Assert.assertTrue(queryResult.indexOf("0002") > 0); Assert.assertTrue(queryResult.indexOf("0003") > 0); Assert.assertTrue(queryResult.indexOf("Motif") < 0); jpaQuery = "select p from " + UserCassandra.class.getSimpleName() + " p WHERE p.userId = :userId"; Map<String, Object> params = new HashMap<String, Object>(); params.put("userId", "0001"); queryResult = restClient.runObjectJPAQuery(sessionToken, jpaQuery, params); log.debug("Query Result:" + queryResult); Assert.assertNotNull(queryResult); Assert.assertFalse(StringUtils.isEmpty(queryResult)); Assert.assertTrue(queryResult.indexOf("usercassandra") > 0); Assert.assertTrue(queryResult.indexOf("0001") > 0); Assert.assertTrue(queryResult.indexOf("Motif") < 0); /** JPA Query - Select All */ // Get All Professionals String allUsers = restClient.getAllEntities(sessionToken, UserCassandra.class.getSimpleName()); log.debug(allUsers); Assert.assertNotNull(allUsers); // Close Session restClient.closeSession(sessionToken); // Close Application restClient.closeApplication(applicationToken); }
From source file:org.apache.click.util.ContainerUtils.java
/** * Populate the given map from the values of the specified fieldList. The * map's key/value pairs are populated from the fields name/value. The keys * of the map are matched against each field name. If a key matches a field * name, the value of the field will be copied to the map. * * @param fieldList the forms list of fields to obtain field values from * @param map the map to populate with field values *//*ww w . jav a 2 s .c om*/ private static void copyFieldsToMap(List<Field> fieldList, Map<String, Object> map) { LogService logService = ClickUtils.getLogService(); String objectClassname = map.getClass().getName(); objectClassname = objectClassname.substring(objectClassname.lastIndexOf(".") + 1); for (Field field : fieldList) { // Check if the map contains the fields name. The fields name can // also be a path for example 'foo.bar' String fieldName = field.getName(); if (map.containsKey(fieldName)) { map.put(fieldName, field.getValueObject()); if (logService.isDebugEnabled()) { String msg = " Form -> " + objectClassname + "." + fieldName + " : " + field.getValueObject(); logService.debug(msg); } } } }
From source file:org.apache.click.util.ContainerUtils.java
/** * Copy the map values to the specified fieldList. For every field in the * field list, a lookup is done in the map for a matching value. A match is * found if a field name matches against a key in the map. The matching * value is then copied to the field./*from w ww . j a v a 2s .co m*/ * * @param map the map containing values to populate the fields with * @param fieldList the forms list of fields to be populated */ private static void copyMapToFields(Map<String, Object> map, List<Field> fieldList) { LogService logService = ClickUtils.getLogService(); String objectClassname = map.getClass().getName(); objectClassname = objectClassname.substring(objectClassname.lastIndexOf(".") + 1); for (Field field : fieldList) { String fieldName = field.getName(); // Check if the fieldName is contained in the map. For // example if a field has the name 'user.address', check if // 'user.address' is contained in the map. if (map.containsKey(fieldName)) { Object result = map.get(fieldName); field.setValueObject(result); if (logService.isDebugEnabled()) { String msg = " Form <- " + objectClassname + "." + fieldName + " : " + result; logService.debug(msg); } } } }
From source file:org.betaconceptframework.astroboa.model.impl.definition.ComplexPropertyDefinitionHelper.java
public void setChildPropertyDefinitions(Map<String, CmsPropertyDefinition> propertyDefinitions) { //We must have a LinkedHashMap to ensure insertion order. //So if parameter is a HashMap, create a new LinkedHashMap //and copy all entries if (propertyDefinitions != null && propertyDefinitions.getClass() == HashMap.class) { this.childPropertyDefinitions = new LinkedHashMap<String, CmsPropertyDefinition>(); this.childPropertyDefinitions.putAll(propertyDefinitions); } else {// w ww . j a va 2 s . c o m this.childPropertyDefinitions = propertyDefinitions; } if (sortedPropertyDefinitions != null) { sortedPropertyDefinitions.clear(); } resetDepth(); }
From source file:org.openadaptor.auxil.processor.map.AttributeMapProcessor.java
protected Object cloneMap(Map incoming) { if (incoming instanceof IOrderedMap) { return ((IOrderedMap) incoming).clone(); }//from w w w. ja v a 2s .c o m if (incoming instanceof MapFacade) { return ((MapFacade) incoming).clone(); } if (incoming instanceof HashMap) { return ((HashMap) incoming).clone(); } try { Method cloneMethod = incoming.getClass().getMethod(mapCloneMethod, (Class[]) null); return (cloneMethod.invoke(incoming, (Object[]) null)); } catch (NoSuchMethodException nsme) { log.warn("Unable to find clone method " + mapCloneMethod + "(). " + nsme.getMessage()); } catch (InvocationTargetException ite) { log.warn("Unable to invoke clone method " + mapCloneMethod + "(). " + ite.getMessage()); } catch (IllegalAccessException iae) { log.warn("Failed to invoke clone method " + mapCloneMethod + "(). " + iae.getMessage()); } log.warn("Unable to clone incoming map - the original might get modified!"); return incoming; }
From source file:io.dockstore.webservice.helpers.BitBucketSourceCodeRepo.java
@Override public FileResponse readFile(String fileName, String reference, String gitUrl) { String repositoryId = this.getRepositoryId(gitUrl); if (fileName.startsWith("/")) { fileName = fileName.substring(1); }//from w w w. j av a 2 s .c o m FileResponse fileResponse = new FileResponse(); String content; String branch = null; if (reference == null) { String mainBranchUrl = BITBUCKET_API_URL + "repositories/" + repositoryId + "/main-branch"; Optional<String> asString = ResourceUtilities.asString(mainBranchUrl, bitbucketTokenContent, client); LOG.info(gitUsername + ": RESOURCE CALL: {}", mainBranchUrl); if (asString.isPresent()) { String branchJson = asString.get(); Gson gson = new Gson(); Map<String, String> map = new HashMap<>(); map = (Map<String, String>) gson.fromJson(branchJson, map.getClass()); branch = map.get("name"); if (branch == null) { LOG.info(gitUsername + ": Could NOT find bitbucket default branch!"); return null; // throw new CustomWebApplicationException(HttpStatus.SC_INTERNAL_SERVER_ERROR); } else { LOG.info(gitUsername + ": Default branch: {}", branch); } } } else { branch = reference; } String url = BITBUCKET_API_URL + "repositories/" + repositoryId + "/raw/" + branch + '/' + fileName; Optional<String> asString = ResourceUtilities.asString(url, bitbucketTokenContent, client); LOG.info(gitUsername + ": RESOURCE CALL: {}", url); if (asString.isPresent()) { LOG.info(gitUsername + ": FOUND: {}", fileName); content = asString.get(); } else { LOG.info(gitUsername + ": Branch: {} has no {}", branch, fileName); return null; } if (content != null && !content.isEmpty()) { fileResponse.setContent(content); } else { return null; } return fileResponse; }
From source file:com.impetus.kundera.rest.resources.MongoQueryTest.java
@Test public void testCompositeUserCRUD() throws JsonParseException, JsonMappingException, IOException { WebResource webResource = resource(); restClient = new RESTClientImpl(); restClient.initialize(webResource, mediaType); // Get Application Token applicationToken = restClient.getApplicationToken(_PU, null); Assert.assertNotNull(applicationToken); applicationToken = applicationToken.replaceAll("^\"|\"$", ""); Assert.assertTrue(applicationToken.startsWith("AT_")); // Get Session Token sessionToken = restClient.getSessionToken(applicationToken); Assert.assertNotNull(sessionToken);/*from w w w . j a va2 s .c o m*/ sessionToken = sessionToken.replaceAll("^\"|\"$", ""); Assert.assertTrue(sessionToken.startsWith("ST_")); UUID timeLineId = UUID.randomUUID(); Date currentDate = new Date(); MongoCompoundKey key = new MongoCompoundKey("mevivs", 1, timeLineId); MongoPrimeUser timeLine = new MongoPrimeUser(key); timeLine.setKey(key); timeLine.setTweetBody("my first tweet"); timeLine.setTweetDate(currentDate); MongoCompoundKey key1 = new MongoCompoundKey("john", 2, timeLineId); MongoPrimeUser timeLine2 = new MongoPrimeUser(key1); timeLine2.setKey(key1); timeLine2.setTweetBody("my second tweet"); timeLine2.setTweetDate(currentDate); String mongoUser = JAXBUtils.toString(timeLine, MediaType.APPLICATION_JSON); Assert.assertNotNull(mongoUser); String mongoUser1 = JAXBUtils.toString(timeLine2, MediaType.APPLICATION_JSON); Assert.assertNotNull(mongoUser1); // Insert Record String insertResponse1 = restClient.insertEntity(sessionToken, mongoUser, "MongoPrimeUser"); String insertResponse2 = restClient.insertEntity(sessionToken, mongoUser1, "MongoPrimeUser"); Assert.assertNotNull(insertResponse1); Assert.assertNotNull(insertResponse2); Assert.assertTrue(insertResponse1.indexOf("200") > 0); Assert.assertTrue(insertResponse2.indexOf("200") > 0); String encodepk1 = null; pk1 = JAXBUtils.toString(key, MediaType.APPLICATION_JSON); pk2 = JAXBUtils.toString(key1, MediaType.APPLICATION_JSON); try { encodepk1 = java.net.URLEncoder.encode(pk1, "UTF-8"); } catch (UnsupportedEncodingException e) { log.error(e.getMessage()); } // Find Record String foundUser = restClient.findEntity(sessionToken, encodepk1, "MongoPrimeUser"); Assert.assertNotNull(foundUser); Assert.assertNotNull(foundUser); Assert.assertTrue(foundUser.indexOf("mevivs") > 0); foundUser = foundUser.substring(1, foundUser.length() - 1); Map<String, Object> userDetails = new HashMap<String, Object>(); ObjectMapper mapper = new ObjectMapper(); userDetails = mapper.readValue(foundUser, userDetails.getClass()); foundUser = mapper.writeValueAsString(userDetails.get("mongoprimeuser")); // Update Record foundUser = foundUser.replaceAll("first", "hundreth"); String updatedUser = restClient.updateEntity(sessionToken, foundUser, MongoPrimeUser.class.getSimpleName()); Assert.assertNotNull(updatedUser); Assert.assertTrue(updatedUser.indexOf("hundreth") > 0); /** JPA Query - Select */ // Get All users String jpaQuery = "select p from " + MongoPrimeUser.class.getSimpleName() + " p"; String queryResult = restClient.runJPAQuery(sessionToken, jpaQuery, new HashMap<String, Object>()); log.debug("Query Result:" + queryResult); Assert.assertNotNull(queryResult); Assert.assertFalse(StringUtils.isEmpty(queryResult)); Assert.assertTrue(queryResult.indexOf("mongoprimeuser") > 0); Assert.assertTrue(queryResult.indexOf(pk1) > 0); Assert.assertTrue(queryResult.indexOf(pk2) > 0); Assert.assertTrue(queryResult.indexOf("Motif") < 0); jpaQuery = "select p from " + MongoPrimeUser.class.getSimpleName() + " p WHERE p.key = :key"; Map<String, Object> params = new HashMap<String, Object>(); params.put("key", pk1); queryResult = restClient.runObjectJPAQuery(sessionToken, jpaQuery, params); log.debug("Query Result:" + queryResult); Assert.assertNotNull(queryResult); Assert.assertFalse(StringUtils.isEmpty(queryResult)); Assert.assertTrue(queryResult.indexOf("mongoprimeuser") > 0); Assert.assertTrue(queryResult.indexOf(timeLineId.toString()) > 0); Assert.assertTrue(queryResult.indexOf(pk2) < 0); Assert.assertTrue(queryResult.indexOf("Motif") < 0); jpaQuery = "select p from " + MongoPrimeUser.class.getSimpleName() + " p"; params = new HashMap<String, Object>(); params.put("firstResult", 0); params.put("maxResult", 1); queryResult = restClient.runObjectJPAQuery(sessionToken, jpaQuery, params); log.debug("Query Result:" + queryResult); String userList = queryResult.substring(1, queryResult.length() - 1); mapper = new ObjectMapper(); userDetails = new HashMap<String, Object>(); userDetails = mapper.readValue(userList, userDetails.getClass()); userList = mapper.writeValueAsString(userDetails.get("mongoprimeuser")); List<MongoPrimeUser> navigation = mapper.readValue(userList, mapper.getTypeFactory().constructCollectionType(List.class, MongoPrimeUser.class)); Assert.assertNotNull(queryResult); Assert.assertFalse(StringUtils.isEmpty(queryResult)); Assert.assertTrue(queryResult.indexOf("mongoprimeuser") > 0); Assert.assertTrue(queryResult.indexOf(timeLineId.toString()) > 0); Assert.assertEquals(1, navigation.size()); /** JPA Query - Select All */ // Get All Users String allUsers = restClient.getAllEntities(sessionToken, MongoPrimeUser.class.getSimpleName()); log.debug(allUsers); Assert.assertNotNull(allUsers); // Close Session restClient.closeSession(sessionToken); // Close Application restClient.closeApplication(applicationToken); }
From source file:io.dockstore.webservice.helpers.BitBucketSourceCodeRepo.java
@Override public Tool findDescriptor(Tool tool, String fileName) { String descriptorType = FilenameUtils.getExtension(fileName); if (fileName.startsWith("/")) { fileName = fileName.substring(1); }/*ww w .ja v a2s . c om*/ String giturl = tool.getGitUrl(); if (giturl != null && !giturl.isEmpty()) { Pattern p = Pattern.compile("git\\@bitbucket.org:(\\S+)/(\\S+)\\.git"); Matcher m = p.matcher(giturl); LOG.info(gitUsername + ": " + giturl); if (!m.find()) { LOG.info(gitUsername + ": Namespace and/or repository name could not be found from tool's giturl"); return tool; } String url = BITBUCKET_API_URL + "repositories/" + m.group(1) + '/' + m.group(2) + "/main-branch"; Optional<String> asString = ResourceUtilities.asString(url, bitbucketTokenContent, client); LOG.info(gitUsername + ": RESOURCE CALL: {}", url); if (asString.isPresent()) { String branchJson = asString.get(); Gson gson = new Gson(); Map<String, String> map = new HashMap<>(); map = (Map<String, String>) gson.fromJson(branchJson, map.getClass()); String branch = map.get("name"); if (branch == null) { LOG.info(gitUsername + ": Could NOT find bitbucket default branch!"); return null; } else { LOG.info(gitUsername + ": Default branch: {}", branch); } // String response = asString.get(); // // Gson gson = new Gson(); // Map<String, Object> branchMap = new HashMap<>(); // // branchMap = (Map<String, Object>) gson.fromJson(response, branchMap.getClass()); // Set<String> branches = branchMap.keySet(); // // for (String branch : branches) { LOG.info(gitUsername + ": Checking {} branch for {} file", branch, descriptorType); String content = ""; url = BITBUCKET_API_URL + "repositories/" + m.group(1) + '/' + m.group(2) + "/raw/" + branch + '/' + fileName; asString = ResourceUtilities.asString(url, bitbucketTokenContent, client); LOG.info(gitUsername + ": RESOURCE CALL: {}", url); if (asString.isPresent()) { LOG.info(gitUsername + ": {} FOUND", descriptorType); content = asString.get(); } else { LOG.info(gitUsername + ": Branch: {} has no {}", branch, fileName); } // Add for new descriptor types // expects file to have .cwl extension if (descriptorType.equals("cwl")) { tool = parseCWLContent(tool, content); } if (descriptorType.equals("wdl")) { tool = parseWDLContent(tool, content); } // if (tool.getHasCollab()) { // break; // } // } } } return tool; }
From source file:org.shept.org.springframework.web.servlet.mvc.delegation.DelegatingController.java
/** * //from w w w .j av a 2 s . c o m * put a colon '.' at the end of non empty pathNames * @param * @return * * @param componentPathName * @param pathNames */ @SuppressWarnings("unchecked") private Map<String, Object> prepareComponentPathForLookup(Map<String, Object> components) { Map<String, Object> copy = BeanUtils.instantiate(components.getClass()); for (String pathName : components.keySet()) { Object object = components.get(pathName); pathName = ComponentUtils.getPropertyPathPrefix(pathName); copy.put(pathName, object); } return copy; }