List of usage examples for org.springframework.util MultiValueMap containsKey
boolean containsKey(Object key);
From source file:de.interseroh.report.controller.ParameterFormBinder.java
private MutablePropertyValues createPropertyValues(ParameterForm parameterForm, final MultiValueMap<String, String> requestParameters) { final MutablePropertyValues mpvs = new MutablePropertyValues(); parameterForm.accept(new AbstractParameterVisitor() { @Override//www . j av a 2s. c om public <V, T> void visit(ScalarParameter<V, T> parameter) { String name = parameter.getName(); String propertyPath = ParameterUtils.nameToTextPath(name); Class<T> textType = parameter.getTextType(); if (requestParameters.containsKey(name)) { addText(name, propertyPath, textType); } else if (requestParameters.containsKey('_' + name)) { addText('_' + name, propertyPath, textType); } } private <T> void addText(String name, String propertyPath, Class<T> textType) { List<String> values = requestParameters.get(name); if (textType.isArray()) { mpvs.add(propertyPath, values.toArray()); } else { for (String requestValue : values) { mpvs.add(propertyPath, requestValue); } } } }); return mpvs; }
From source file:com.gvmax.web.api.WebAppAPI.java
private void extractUserFromForm(User user, MultiValueMap<String, String> form) { if (form.containsKey("wc")) { ensureExists("sendGTalk", form); ensureExists("sendProwl", form); ensureExists("sendEmail", form); ensureExists("sendPost", form); ensureExists("sendTwitter", form); ensureExists("sendSMS", form); ensureExists("sendHowl", form); ensureExists("sendAutoResponse", form); }/*from w w w .ja va 2s.c o m*/ // GTALK if (form.containsKey("sendGTalk")) { user.setSendGTalk(getBoolean("sendGTalk", form)); user.setgTalkEmail(form.getFirst("gTalkEmail")); String gTalkPassword = form.getFirst("gTalkPassword"); if (!HIDDEN_PASSWORD.equals(gTalkPassword)) { user.setgTalkPassword(gTalkPassword); } user.setgTalkGroup(form.getFirst("gTalkGroup")); } if (form.containsKey("sendProwl")) { user.setSendProwl(getBoolean("sendProwl", form)); user.setProwlApiKeys(form.getFirst("prowlApiKeys")); user.setProwlSMSPriority(getInt("prowlSMSPriority", form)); user.setProwlVMPriority(getInt("prowlVMPriority", form)); user.setProwlMCPriority(getInt("prowlMCPriority", form)); } if (form.containsKey("sendEmail")) { user.setSendEmail(getBoolean("sendEmail", form)); user.setEmailAddresses(form.getFirst("emailAddresses")); } if (form.containsKey("sendPost")) { user.setSendPost(getBoolean("sendPost", form)); user.setPostURLs(form.getFirst("postURLs")); } if (form.containsKey("sendTwitter")) { user.setSendTwitter(getBoolean("sendTwitter", form)); user.setTwitterScreenName(form.getFirst("twitterScreenName")); } if (form.containsKey("sendSMS")) { user.setSendSMS(getBoolean("sendSMS", form)); user.setSmsGroup(form.getFirst("smsGroup")); } if (form.containsKey("sendHowl")) { user.setSendHowl(getBoolean("sendHowl", form)); user.setHowlUsername(form.getFirst("howlUsername")); String howlPassword = form.getFirst("howlPassword"); if (!HIDDEN_PASSWORD.equals(howlPassword)) { user.setHowlPassword(howlPassword); } } if (form.containsKey("sendAutoResponse")) { user.setSendAutoResponse(getBoolean("sendAutoResponse", form)); user.setAutoResponse(form.getFirst("autoResponse")); } }
From source file:com.svds.resttest.services.GenericDataService.java
/** * Build and run a SELECT query/*from w ww . ja v a 2 s.c om*/ * * @param databaseEngine Database engine to query (hive or impala) * @param tableName Table name to query * @param requestParams Parameters for WHERE clause * @return Output of select query */ public GenericResultsOutput runQueryResults(String databaseEngine, String tableName, MultiValueMap<String, String> requestParams) { GenericResultsOutput genericResultsOutput = new GenericResultsOutput(); genericResultsOutput.setName("GenericDataService.runQueryCount"); genericResultsOutput.setRequestParams(requestParams); genericResultsOutput.setDatabaseEngine(databaseEngine); genericResultsOutput.setTableName(tableName); Connection connection = null; PreparedStatement pstmt = null; ResultSet rs = null; int limit = ROW_LIMIT; if (requestParams.containsKey("limit")) { limit = new Integer(requestParams.getFirst("limit")); } StringBuilder connectionURL = new StringBuilder(); connectionURL.append(DATABASES_BUNDLE.getString(databaseEngine)); LOG.info("connectionURL: " + connectionURL.toString()); StringBuilder sql = new StringBuilder(); sql.append("SELECT * FROM "); sql.append(TABLES_BUNDLE.getString(tableName)); try { LOG.info("RequestParams: " + requestParams.size()); if (requestParams.size() > 0) { sql.append(" WHERE "); sql.append(BuildWhereClause.buildWhereClause(requestParams)); } sql.append(" limit ").append(limit); LOG.info("sql: " + sql.toString()); genericResultsOutput.setSql(sql.toString()); Class.forName("org.apache.hive.jdbc.HiveDriver"); connection = DriverManager.getConnection(connectionURL.toString(), "hadoop", ""); pstmt = connection.prepareStatement(sql.toString()); rs = pstmt.executeQuery(); int rowCount = 0; while (rs.next()) { if (genericResultsOutput.getMetaData().size() > 0) { //Got it!! } else { Map<String, Integer> metaDataSet = new HashMap<>(); this.getMetaData(rs, metaDataSet, genericResultsOutput); } List<Object> resultsArrayList = new ArrayList<>(); this.resultsWithoutMetaData(rs, genericResultsOutput, resultsArrayList); genericResultsOutput.getResults().add(resultsArrayList); rowCount++; } genericResultsOutput.setCount(rowCount); genericResultsOutput.setStatus("OK"); } catch (Exception e) { LOG.error("GenericDataService.runQueryResults(): " + e.getMessage(), e); genericResultsOutput.setMessage(e.getMessage()); genericResultsOutput.setStatus("ERROR"); } finally { try { rs.close(); } catch (Exception e) { LOG.error("GenericDataService.runQueryResults() Close result set: " + e.getMessage(), e); } try { pstmt.close(); } catch (Exception e) { LOG.error("GenericDataService.runQueryResults() Close prepared statement: " + e.getMessage(), e); } try { connection.close(); } catch (Exception e) { LOG.error("GenericDataService.runQueryResults() Close connection: " + e.getMessage(), e); } } return genericResultsOutput; }
From source file:eionet.webq.web.controller.cdr.IntegrationWithCDRControllerIntegrationTest.java
@SuppressWarnings("unchecked") @Test/*www . j a va 2s.co m*/ public void expectXmlFilesSetForMenu() throws Exception { saveAvailableWebFormWithSchema(XML_SCHEMA); saveAvailableWebFormWithSchema(XML_SCHEMA); rpcClientWillReturnFileForSchema(XML_SCHEMA); MultiValueMap<String, XmlFile> files = (MultiValueMap<String, XmlFile>) requestToWebQMenuAndGetModelAttribute( "xmlFiles"); assertThat(files.size(), equalTo(1)); assertTrue(files.containsKey(XML_SCHEMA)); }
From source file:org.broadleafcommerce.openadmin.web.controller.entity.AdminBasicEntityController.java
/** * Renders the main entity listing for the specified class, which is based on the current sectionKey with some optional * criteria.// w w w. j av a 2 s . c o m * * @param request * @param response * @param model * @param pathVars * @param requestParams a Map of property name -> list critiera values * @return the return view path * @throws Exception */ @RequestMapping(value = "", method = RequestMethod.GET) public String viewEntityList(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @RequestParam MultiValueMap<String, String> requestParams) throws Exception { String sectionKey = getSectionKey(pathVars); String sectionClassName = getClassNameForSection(sectionKey); List<SectionCrumb> crumbs = getSectionCrumbs(request, null, null); PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, requestParams, crumbs, pathVars); ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData(); DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet(); ListGrid listGrid = formService.buildMainListGrid(drs, cmd, sectionKey, crumbs); List<EntityFormAction> mainActions = new ArrayList<EntityFormAction>(); addAddActionIfAllowed(sectionClassName, cmd, mainActions); extensionManager.getProxy().addAdditionalMainActions(sectionClassName, mainActions); extensionManager.getProxy().modifyMainActions(cmd, mainActions); Field firstField = listGrid.getHeaderFields().iterator().next(); if (requestParams.containsKey(firstField.getName())) { model.addAttribute("mainSearchTerm", requestParams.get(firstField.getName()).get(0)); } // If this came from a delete save, we'll have a headerFlash request parameter to take care of if (requestParams.containsKey("headerFlash")) { model.addAttribute("headerFlash", requestParams.get("headerFlash").get(0)); } model.addAttribute("entityFriendlyName", cmd.getPolymorphicEntities().getFriendlyName()); model.addAttribute("currentUrl", request.getRequestURL().toString()); model.addAttribute("listGrid", listGrid); model.addAttribute("mainActions", mainActions); model.addAttribute("viewType", "entityList"); setModelAttributes(model, sectionKey); return "modules/defaultContainer"; }
From source file:org.broadleafcommerce.openadmin.web.controller.entity.AdminBasicEntityController.java
/** * Shows the modal dialog that is used to add an item to a given collection. There are several possible outcomes * of this call depending on the type of the specified collection field. * //from w w w .j a v a2 s. c o m * <ul> * <li> * <b>Basic Collection (Persist)</b> - Renders a blank form for the specified target entity so that the user may * enter information and associate the record with this collection. Used by fields such as ProductAttribute. * </li> * <li> * <b>Basic Collection (Lookup)</b> - Renders a list grid that allows the user to click on an entity and select it. * Used by fields such as "allParentCategories". * </li> * <li> * <b>Adorned Collection (without form)</b> - Renders a list grid that allows the user to click on an entity and * select it. The view rendered by this is identical to basic collection (lookup), but will perform the operation * on an adorned field, which may carry extra meta-information about the created relationship, such as order. * </li> * <li> * <b>Adorned Collection (with form)</b> - Renders a list grid that allows the user to click on an entity and * select it. Once the user selects the entity, he will be presented with an empty form based on the specified * "maintainedAdornedTargetFields" for this field. Used by fields such as "crossSellProducts", which in addition * to linking an entity, provide extra fields, such as a promotional message. * </li> * <li> * <b>Map Collection</b> - Renders a form for the target entity that has an additional key field. This field is * populated either from the configured map keys, or as a result of a lookup in the case of a key based on another * entity. Used by fields such as the mediaMap on a Sku. * </li> * * @param request * @param response * @param model * @param pathVars * @param id * @param collectionField * @param requestParams * @return the return view path * @throws Exception */ @RequestMapping(value = "/{id}/{collectionField:.*}/add", method = RequestMethod.GET) public String showAddCollectionItem(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @PathVariable(value = "collectionField") String collectionField, @RequestParam MultiValueMap<String, String> requestParams) throws Exception { String sectionKey = getSectionKey(pathVars); String mainClassName = getClassNameForSection(sectionKey); List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, sectionKey, id); ClassMetadata mainMetadata = service .getClassMetadata(getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars)) .getDynamicResultSet().getClassMetaData(); Property collectionProperty = mainMetadata.getPMap().get(collectionField); FieldMetadata md = collectionProperty.getMetadata(); PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs) .withFilterAndSortCriteria(getCriteria(requestParams)).withStartIndex(getStartIndex(requestParams)) .withMaxIndex(getMaxIndex(requestParams)); if (md instanceof BasicCollectionMetadata) { BasicCollectionMetadata fmd = (BasicCollectionMetadata) md; if (fmd.getAddMethodType().equals(AddMethodType.PERSIST)) { ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData(); // If the entity type isn't specified, we need to determine if there are various polymorphic types // for this entity. String entityType = null; if (requestParams.containsKey("entityType")) { entityType = requestParams.get("entityType").get(0); } if (StringUtils.isBlank(entityType)) { if (cmd.getPolymorphicEntities().getChildren().length == 0) { entityType = cmd.getPolymorphicEntities().getFullyQualifiedClassname(); } else { entityType = getDefaultEntityType(); } } else { entityType = URLDecoder.decode(entityType, "UTF-8"); } if (StringUtils.isBlank(entityType)) { List<ClassTree> entityTypes = getAddEntityTypes(cmd.getPolymorphicEntities()); model.addAttribute("entityTypes", entityTypes); model.addAttribute("viewType", "modal/entityTypeSelection"); model.addAttribute("entityFriendlyName", cmd.getPolymorphicEntities().getFriendlyName()); String requestUri = request.getRequestURI(); if (!request.getContextPath().equals("/") && requestUri.startsWith(request.getContextPath())) { requestUri = requestUri.substring(request.getContextPath().length() + 1, requestUri.length()); } model.addAttribute("currentUri", requestUri); model.addAttribute("modalHeaderType", "addEntity"); setModelAttributes(model, sectionKey); return "modules/modalContainer"; } else { ppr = ppr.withCeilingEntityClassname(entityType); } } } //service.getContextSpecificRelationshipId(mainMetadata, entity, prefix); model.addAttribute("currentParams", new ObjectMapper().writeValueAsString(requestParams)); return buildAddCollectionItemModel(request, response, model, id, collectionField, sectionKey, collectionProperty, md, ppr, null, null); }
From source file:org.cloudfoundry.identity.uaa.mock.token.TokenMvcMockTests.java
@Test public void invalidScopeErrorMessageIsNotShowingAllClientScopes() throws Exception { String clientId = "testclient" + generator.generate(); String scopes = "openid"; setUpClients(clientId, scopes, scopes, "authorization_code", true); String username = "testuser" + generator.generate(); ScimUser developer = setUpUser(username, "scim.write", OriginKeys.UAA, IdentityZoneHolder.getUaaZone().getId()); MockHttpSession session = getAuthenticatedSession(developer); String basicDigestHeaderValue = "Basic " + new String( org.apache.commons.codec.binary.Base64.encodeBase64((clientId + ":" + SECRET).getBytes())); String state = generator.generate(); MockHttpServletRequestBuilder authRequest = get("/oauth/authorize") .header("Authorization", basicDigestHeaderValue).session(session) .param(OAuth2Utils.RESPONSE_TYPE, "code").param(OAuth2Utils.SCOPE, "scim.write") .param(OAuth2Utils.STATE, state).param(OAuth2Utils.CLIENT_ID, clientId) .param(OAuth2Utils.REDIRECT_URI, TEST_REDIRECT_URI); MvcResult mvcResult = getMockMvc().perform(authRequest).andExpect(status().is3xxRedirection()).andReturn(); UriComponents locationComponents = UriComponentsBuilder .fromUri(URI.create(mvcResult.getResponse().getHeader("Location"))).build(); MultiValueMap<String, String> queryParams = locationComponents.getQueryParams(); String errorMessage = URIUtil .encodeQuery("scim.write is invalid. Please use a valid scope name in the request"); assertTrue(!queryParams.containsKey("scope")); assertEquals(errorMessage, queryParams.getFirst("error_description")); }
From source file:org.cloudfoundry.identity.uaa.mock.token.TokenMvcMockTests.java
@Test public void invalidScopeErrorMessageIsNotShowingAllUserScopes() throws Exception { String clientId = "testclient" + generator.generate(); String scopes = "openid,password.write,cloud_controller.read,scim.userids,password.write,something.else"; setUpClients(clientId, scopes, scopes, "authorization_code", true); String username = "testuser" + generator.generate(); ScimUser developer = setUpUser(username, "openid", OriginKeys.UAA, IdentityZoneHolder.getUaaZone().getId()); MockHttpSession session = getAuthenticatedSession(developer); String basicDigestHeaderValue = "Basic " + new String( org.apache.commons.codec.binary.Base64.encodeBase64((clientId + ":" + SECRET).getBytes())); String state = generator.generate(); MockHttpServletRequestBuilder authRequest = get("/oauth/authorize") .header("Authorization", basicDigestHeaderValue).session(session) .param(OAuth2Utils.RESPONSE_TYPE, "code").param(OAuth2Utils.SCOPE, "something.else") .param(OAuth2Utils.STATE, state).param(OAuth2Utils.CLIENT_ID, clientId) .param(OAuth2Utils.REDIRECT_URI, TEST_REDIRECT_URI); MvcResult mvcResult = getMockMvc().perform(authRequest).andExpect(status().is3xxRedirection()).andReturn(); UriComponents locationComponents = UriComponentsBuilder .fromUri(URI.create(mvcResult.getResponse().getHeader("Location"))).build(); MultiValueMap<String, String> queryParams = locationComponents.getQueryParams(); String errorMessage = URIUtil .encodeQuery("[something.else] is invalid. This user is not allowed any of the requested scopes"); assertTrue(!queryParams.containsKey("scope")); assertEquals(errorMessage, queryParams.getFirst("error_description")); }
From source file:org.ednovo.gooru.domain.service.ScollectionServiceImpl.java
@Override public Collection updateCollectionMetadata(final String collectionId, final String creatorUId, String ownerUId, final boolean hasUnrestrictedContentAccess, final MultiValueMap<String, String> data, final User apiCallerUser) { final Collection collection = this.getCollectionByGooruOid(collectionId, null); rejectIfNull(collection, GL0056, _COLLECTION); Boolean taxonomyByCode = false; final String taxonomyCode = data.getFirst(TAXONOMY_CODE); final String title = data.getFirst(TITLE); final String description = data.getFirst(DESCRIPTION); final String grade = data.getFirst(GRADE); final String sharing = data.getFirst(SHARING); final String narrationLink = data.getFirst(NARRATION_LINK); final String updateTaxonomyByCode = data.getFirst(UPDATE_TAXONOMY_BY_CODE); final String action = data.getFirst(ACTION); final String buildType = data.getFirst(BUILD_TYPE); if (isNotEmptyString(updateTaxonomyByCode) && updateTaxonomyByCode.equalsIgnoreCase(TRUE)) { taxonomyByCode = true;/*from w w w .j av a2 s. c o m*/ } if (isNotEmptyString(taxonomyCode)) { if (isNotEmptyString(action) && action.equalsIgnoreCase(DELETE)) { deleteCollectionTaxonomy(collection, taxonomyCode, taxonomyByCode); } else { addCollectionTaxonomy(collection, taxonomyCode, taxonomyByCode); } this.getCollectionRepository().save(collection); } /* * if (isNotEmptyString(buildType)) { if * (buildType.equalsIgnoreCase(WEB) || buildType.equalsIgnoreCase(IPAD)) * { collection.setBuildType(this.getCustomTableRepository(). * getCustomTableValue(CustomProperties.Table.BUILD_TYPE.getTable(), * buildType)); } } */ if (isNotEmptyString(title)) { collection.setTitle(title); } collection.setLastUpdatedUserUid(apiCallerUser.getPartyUid()); if (isNotEmptyString(sharing)) { collection.setSharing(sharing); this.getCollectionRepository().save(collection); resetFolderVisibility(collection.getGooruOid(), apiCallerUser.getPartyUid()); updateResourceSharing(sharing, collection); } if (data.containsKey(GRADE)) { saveOrUpdateCollectionGrade(grade, collection, false); } if (isNotEmptyString(narrationLink)) { collection.setNarrationLink(narrationLink); } if (hasUnrestrictedContentAccess) { if (creatorUId != null) { User user = getUserService().findByGooruId(creatorUId); collection.setCreator(user); } if (ownerUId != null) { final User user = getUserService().findByGooruId(ownerUId); collection.setUser(user); } } this.setCollectionMetaData(collection, null, null, true, null, false, false, false); this.getCollectionRepository().save(collection); try { indexHandler.setReIndexRequest(collection.getGooruOid(), IndexProcessor.INDEX, SCOLLECTION, null, false, false); } catch (Exception e) { LOGGER.error(_ERROR, e); } getAsyncExecutor().deleteFromCache(V2_ORGANIZE_DATA + collection.getUser().getPartyUid() + "*"); return collection; }
From source file:org.ednovo.gooru.domain.service.ScollectionServiceImpl.java
@Override public CollectionItem updateCollectionItemMetadata(final String collectionItemId, final MultiValueMap<String, String> data, final User apiCaller) { final CollectionItem collectionItem = this.getCollectionItemById(collectionItemId); rejectIfNull(collectionItem, GL0056, _COLLECTION_ITEM); ServerValidationUtils.rejectIfMaxLimitExceed(8, data.getFirst(NARRATION_TYPE), "GL0014", NARRATION_TYPE, "8"); ServerValidationUtils.rejectIfMaxLimitExceed(8, data.getFirst(START), "GL0014", START, "8"); ServerValidationUtils.rejectIfMaxLimitExceed(8, data.getFirst(STOP), "GL0014", STOP, "8"); final String narration = data.getFirst(NARRATION); final String narrationType = data.getFirst(NARRATION_TYPE); final String start = data.getFirst(START); final String stop = data.getFirst(STOP); if (data.containsKey(NARRATION)) { collectionItem.setNarration(narration); }/*from w w w . j av a2s . c om*/ if (isNotEmptyString(narrationType)) { collectionItem.setNarrationType(narrationType); } if (data.containsKey(START)) { collectionItem.setStart(start); } if (data.containsKey(STOP)) { collectionItem.setStop(stop); } this.getCollectionRepository().save(collectionItem); try { indexHandler.setReIndexRequest(collectionItem.getContent().getGooruOid(), IndexProcessor.INDEX, RESOURCE, null, false, false); indexHandler.setReIndexRequest(collectionItem.getCollection().getGooruOid(), IndexProcessor.INDEX, SCOLLECTION, null, false, false); } catch (Exception e) { LOGGER.error(_ERROR, e); } getAsyncExecutor() .deleteFromCache(V2_ORGANIZE_DATA + collectionItem.getCollection().getUser().getPartyUid() + "*"); return collectionItem; }