List of usage examples for java.util Map clear
void clear();
From source file:com.esd.ps.AdministratorController.java
@RequestMapping(value = "/updatePW", method = RequestMethod.POST) @ResponseBody/*from www . j a v a 2 s.c om*/ public Map<String, Object> updatePWPOST(String newPW, int userId, String userName, HttpSession session) { Map<String, Object> map = new HashMap<String, Object>(); user user = new user(); UsernameAndPasswordMd5 md5 = new UsernameAndPasswordMd5(); String md5Password = md5.getMd5(userName, newPW); user.setPassword(md5Password); user.setUserId(userId); StackTraceElement[] items = Thread.currentThread().getStackTrace(); user.setUpdateMethod(items[1].toString()); userService.updateByPrimaryKeySelective(user); map.clear(); map.put(Constants.MESSAGE, MSG_UPDATE_SUCCESS); map.put(Constants.REPLAY, 1); return map; }
From source file:info.rmapproject.webapp.service.DataDisplayServiceImpl.java
@Override public List<ResourceDescription> getDiSCOTableData(DiSCODTO discoDTO, Integer offset) throws Exception { List<ResourceDescription> resourceDescriptions = new ArrayList<ResourceDescription>(); List<URI> aggregatedResources = discoDTO.getAggregatedResources(); List<RMapTriple> triples = discoDTO.getRelatedStatements(); //first put other resources into an ordered sets (TreeSet) Set<String> nonAggregatedResourcesDescribed = new TreeSet<String>(); for (RMapTriple stmt : triples) { nonAggregatedResourcesDescribed.add(stmt.getSubject().toString()); }/*from ww w . ja v a 2s. c o m*/ Set<String> aggregatedResourcesDescribed = new TreeSet<String>(); for (URI aggregate : aggregatedResources) { aggregatedResourcesDescribed.add(aggregate.toString()); } //Now put into a list that will maintain ordering (LinkedHashSet). //we want the aggregates list first then other resources Set<String> resourcesDescribed = new LinkedHashSet<String>(); resourcesDescribed.addAll(aggregatedResourcesDescribed); resourcesDescribed.addAll(nonAggregatedResourcesDescribed); int position = 0; int count = 0; int remainingRows = maxTableRows; //now get resource description for each resource, truncate according to offset and max rows for (String resource : resourcesDescribed) { ResourceDescription resDescrip = getResourceTableDataInContext(resource, triples, discoDTO.getUri().toString(), false); Map<String, TripleDisplayFormat> tripleMap = resDescrip.getPropertyValues(); //keep getting new resource descriptions til we hit the offset if (position < offset) { if (tripleMap.size() <= offset) { position = position + tripleMap.size(); tripleMap.clear(); } else { position = offset; tripleMap.keySet() .removeAll(Arrays.asList(tripleMap.keySet().toArray()).subList(0, offset - 1)); } } //once we're at offset, keep adding resdes until we reach max if (position >= offset) { if (tripleMap.size() > remainingRows) { Map<String, TripleDisplayFormat> truncatedMap = new HashMap<String, TripleDisplayFormat>(); for (Map.Entry<String, TripleDisplayFormat> entry : tripleMap.entrySet()) { if (count >= remainingRows) break; truncatedMap.put(entry.getKey(), entry.getValue()); count++; } resDescrip.setPropertyValues(truncatedMap); remainingRows = 0; } else { remainingRows = remainingRows - tripleMap.size(); } resourceDescriptions.add(resDescrip); } if (remainingRows == 0) { break; } } return resourceDescriptions; }
From source file:com.esd.ps.AdministratorController.java
/** * ??//www.j a v a 2 s. c om * @param userId * @param newPassWord * @param username * @return */ @RequestMapping(value = "/updateAllPassWord", method = RequestMethod.POST) @ResponseBody public Map<String, Object> updateAllPassWordPOST(int userId, String newPassWord, String username) { Map<String, Object> map = new HashMap<String, Object>(); user user = new user(); UsernameAndPasswordMd5 md5 = new UsernameAndPasswordMd5(); String md5Password = md5.getMd5(username, newPassWord); user.setPassword(md5Password); user.setUserId(userId); StackTraceElement[] items = Thread.currentThread().getStackTrace(); user.setUpdateMethod(items[1].toString()); userService.updateByPrimaryKeySelective(user); map.clear(); map.put(Constants.MESSAGE, MSG_UPDATE_SUCCESS); map.put(Constants.REPLAY, 1); return map; }
From source file:edu.utah.further.ds.impl.service.query.logic.ExecutorQuestImpl.java
/** * @param <T>// ww w. ja v a 2 s .co m * @param queryContext * @param attributes * @return * @see edu.utah.further.ds.api.service.query.logic.Executor#execute(edu.utah.further.fqe.ds.api.domain.QueryContext, * java.util.Map) */ @Override public <T> T execute(final QueryContext queryContext, final Map<String, Object> attributes) { // Utilize the execution factory to retrieve our execution type final DatasourceType dsType = (DatasourceType) attributes.get(DS_TYPE.getLabel()); Validate.notNull(dsType, "A data source type is required for query execution, ensure one is set under attribute " + DS_TYPE.getLabel()); // All query executions will need the search query, inject it by default attributes.put(SEARCH_QUERY.getLabel(), queryContext.getQuery()); // Get the execution type final QueryExecution execution = executionFactory.getInstance(dsType); // Might need a factory for the type of QueryPlanOrchestrator, using simple for // now final QueryPlanOrchestrator orchestrator = new SimpleQueryPlanOrchestrator(); final ChainRequest request = new ChainRequestImpl(new AttributeContainerImpl(attributes)); final T result = orchestrator.<T>execute(execution.getQueryPlan(attributes), request); // Clean up temporary attribute used to store result so their is no dependency on // QueryContext request.setAttribute(AttributeName.QUERY_RESULT, null); attributes.clear(); attributes.putAll(request.getAttributes()); // Get the plan and the request from the execution type and execute it. return result; }
From source file:com.flexive.core.storage.genericSQL.GenericEnvironmentLoader.java
/** * {@inheritDoc}//from w w w .j a v a2s . c om */ @Override public List<FxDataType> loadDataTypes(Connection con) throws FxLoadException { Statement stmt = null; ArrayList<FxDataType> alRet = new ArrayList<FxDataType>(20); try { String sql = "SELECT d.TYPECODE, d.NAME, t.LANG, t.DESCRIPTION FROM " + TBL_STRUCT_DATATYPES + " d LEFT JOIN " + TBL_STRUCT_DATATYPES + ML + " t ON t.ID=d.TYPECODE ORDER BY d.TYPECODE, t.LANG ASC"; stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(sql); FxDataType dtCurr = null; Map<Long, String> hmDesc = new HashMap<Long, String>(5); String name = null; while (rs != null && rs.next()) { if (dtCurr != null && rs.getLong(1) != dtCurr.getId()) { dtCurr.initialize(name, new FxString(FxLanguage.DEFAULT_ID, hmDesc)); alRet.add(dtCurr); hmDesc.clear(); dtCurr = null; } if (dtCurr == null) for (FxDataType dt : FxDataType.values()) { if (dt.getId() == rs.getInt(1)) { dtCurr = dt; break; } } if (dtCurr == null) throw new FxLoadException(LOG, "ex.structure.dataType.unknownId", rs.getInt(1)); hmDesc.put(rs.getLong(3), rs.getString(4)); name = rs.getString(2); } if (dtCurr != null) { dtCurr.initialize(name, new FxString(FxLanguage.DEFAULT_ID, hmDesc)); alRet.add(dtCurr); } return alRet; } catch (SQLException e) { throw new FxLoadException(LOG, e, "ex.db.sqlError", e.getMessage()); } finally { Database.closeObjects(GenericEnvironmentLoader.class, null, stmt); } }
From source file:org.toobsframework.pres.doit.DoItRunner.java
/** * Called upon receipt of a validation error. Iterates over all the * actions for this DoIt, retrieving an object of appropriate type out * of the posted request. All such objects are put in the response parameter * mapping under the "ValidationErrorObjects" key. *///w w w . ja va 2s .com @SuppressWarnings("unchecked") private void pullErrorObjectsIntoRequest(IRequest request, DoIt doIt, Map<String, Object> paramMap, Map<String, Object> responseMap, String multipleActionsKey, String[] multipleActionsAry, ValidationException ve) throws Exception { if (log.isDebugEnabled()) { log.debug("ENTER pullErrorObjectsIntoRequest"); } Action thisAction = null; Collection globalErrorObjects = new ArrayList(); Collection<String> globalErrorMessages = new ArrayList<String>(); BeanFactory beanFactory = BeanMonkey.getBeanFactoryInstance(); if (doIt.getActions() != null) { paramMap.remove("guid"); //Actions actionsObj = doIt.getActions(); for (int i = 0; i < multipleActionsAry.length; i++) { HashMap actionParams = new HashMap(paramMap); responseMap.clear(); actionParams.put(multipleActionsKey, multipleActionsAry[i]); actionParams.put(PlatformConstants.MULTI_ACTION_INSTANCE, new Integer(i)); Collection instanceErrorObjects = new ArrayList(); Collection instanceErrorMessages = new ArrayList(); if (ve != null) { Iterator errIter = ve.getErrors().iterator(); while (errIter.hasNext()) { Errors err = (Errors) errIter.next(); instanceErrorMessages.addAll(err.getAllErrors()); } } // iterate over the create and update actions Enumeration actions = doIt.getActions().enumerateAction(); while (actions.hasMoreElements()) { // for each, retrieve the object of appropriate type thisAction = (Action) actions.nextElement(); // get parameters from action object String actionStr = thisAction.getAction(); // for now, only do error object handling for creates and updates.. if (!actionStr.startsWith("create") && !actionStr.startsWith("update")) { continue; } //retrieve the input object for this action Object inputObject = constructInputObjectFromAction(request, thisAction, actionParams); //if there's an input object if (inputObject != null || actionStr.endsWith("Collection")) { if (thisAction.getNamespace() != null && !"".equals(thisAction.getNamespace())) { actionParams.put("namespace", thisAction.getNamespace()); } // before calling the getSafeBean method, have to // stick this action's returnObjectType in the paramMap String objectReturnType = ((String[]) ParameterUtil.resolveParam(request, thisAction.getReturnObjectType(), actionParams))[0]; actionParams.put("returnObjectType", objectReturnType); // use the bean monkey to populate that object // (pass false in as last arg to block validation) boolean collection = false; String className = null; if (actionStr.endsWith("Collection")) { String beanClazz = ((String[]) ParameterUtil.resolveParam(request, thisAction.getInputObjectType(), actionParams))[0]; inputObject = BeanMonkey.populateCollection(beanClazz, thisAction.getIndexParam(), actionParams, false, thisAction.getValidationErrorMode(), instanceErrorMessages); collection = true; className = beanClazz.substring(beanClazz.lastIndexOf(".") + 1); } else { try { BeanMonkey.populate(inputObject, actionParams, instanceErrorMessages); } catch (ValidationException e) { Iterator errIter = e.getErrors().iterator(); while (errIter.hasNext()) { Errors err = (Errors) errIter.next(); instanceErrorMessages.addAll(err.getAllErrors()); } } className = inputObject.getClass().getName(); } // If there are no error messages for the object don't produce an error object //if (instanceErrorMessages.size() == 0) continue; // and get the validator for the input object IValidator v = null; className = className.substring(className.lastIndexOf(".") + 1); String validatorName = className + "Validator"; if (beanFactory.containsBean(validatorName)) { v = (IValidator) beanFactory.getBean(validatorName); } else { log.warn("No validator " + validatorName + " for " + className); } // if there's no validator, then just continue... if (v == null) continue; // call the validator's prepare method, // pipe the populated bean through the validator's getSafeBean method // and, finally dump the populated object into the error objects map actionParams.put("doit.validation.error.mode", new Boolean(true)); v.prepare(inputObject, actionParams); if (collection && inputObject != null && inputObject instanceof Collection) { Iterator iter = ((Collection) inputObject).iterator(); while (iter.hasNext()) { instanceErrorObjects.add(v.getSafeBean(iter.next(), actionParams)); } } else { instanceErrorObjects.add(v.getSafeBean(inputObject, actionParams)); } } continue; } globalErrorMessages.addAll(instanceErrorMessages); globalErrorObjects.addAll(instanceErrorObjects); } // put the populated error objs in the request scope. responseMap.put(ForwardStrategy.VALIDATION_ERROR_OBJECTS, globalErrorObjects); responseMap.put(ForwardStrategy.VALIDATION_ERROR_MESSAGES, globalErrorMessages); } if (log.isDebugEnabled()) { log.debug("EXIT pullErrorObjectsIntoRequest"); } }
From source file:com.ibm.jaggr.core.impl.transport.AbstractHttpTransportTest.java
@Test public void testGetFeaturesFromRequest() throws Exception { Map<String, Object> requestAttributes = new HashMap<String, Object>(); Map<String, String[]> requestParameters = new HashMap<String, String[]>(); AbstractHttpTransport transport = new TestHttpTransport(); Cookie[] cookies = new Cookie[1]; HttpServletRequest request = TestUtils.createMockRequest(null, requestAttributes, requestParameters, cookies, null);/*from ww w . ja v a 2 s . c o m*/ EasyMock.replay(request); assertNull(transport.getHasConditionsFromRequest(request)); String hasConditions = "foo;!bar"; requestParameters.put("has", new String[] { hasConditions }); Features features = transport.getFeaturesFromRequest(request); assertEquals(2, features.featureNames().size()); Assert.assertTrue(features.featureNames().contains("foo") && features.featureNames().contains("bar")); Assert.assertTrue(features.isFeature("foo")); Assert.assertFalse(features.isFeature("bar")); // Now try specifying the has conditions in the cookie requestParameters.clear(); requestParameters.put("hashash", new String[] { "xxxx" }); // value not checked by server cookies[0] = new Cookie("has", hasConditions); features = transport.getFeaturesFromRequest(request); assertEquals(2, features.featureNames().size()); Assert.assertTrue(features.featureNames().contains("foo") && features.featureNames().contains("bar")); Assert.assertTrue(features.isFeature("foo")); Assert.assertFalse(features.isFeature("bar")); // Make sure we handle null cookie values without throwing requestParameters.put("hashash", new String[] { "xxxx" }); // value not checked by server cookies[0] = new Cookie("has", null); features = transport.getFeaturesFromRequest(request); assertEquals(0, features.featureNames().size()); // Try missing cookie cookies[0] = new Cookie("foo", "bar"); features = transport.getFeaturesFromRequest(request); assertEquals(0, features.featureNames().size()); }
From source file:com.flexive.ejb.beans.LanguageBean.java
/** * Initial load function.//from w ww . ja v a 2 s .c o m * * @param used load used or unused languages? * @param add2cache put loaded languages into cache? * @return list containing requested languages */ private synchronized List<FxLanguage> loadAll(boolean used, boolean add2cache) { String sql = "SELECT l.LANG_CODE, l.ISO_CODE, t.LANG, t.DESCRIPTION FROM " + TBL_LANG + " l, " + TBL_LANG + ML + " t " + "WHERE t.LANG_CODE=l.LANG_CODE AND l.INUSE=" + StorageManager.getBooleanExpression(used) + " ORDER BY l.DISPPOS ASC, l.LANG_CODE ASC"; Connection con = null; Statement stmt = null; List<FxLanguage> alLang = new ArrayList<FxLanguage>(140); try { con = Database.getDbConnection(); stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(sql); Map<Long, String> hmMl = new HashMap<Long, String>(5); int lang_code = -1; String iso_code = null; FxCacheMBean cache = CacheAdmin.getInstance(); while (rs != null && rs.next()) { if (lang_code != rs.getInt(1)) { if (lang_code != -1 && lang_code != FxLanguage.SYSTEM_ID) { //add FxLanguage lang = new FxLanguage(lang_code, iso_code, new FxString(FxLanguage.DEFAULT_ID, hmMl), true); if (add2cache) { cache.put(CacheAdmin.LANGUAGES_ID, lang.getId(), lang); cache.put(CacheAdmin.LANGUAGES_ISO, lang.getIso2digit(), lang); } alLang.add(lang); } lang_code = rs.getInt(1); iso_code = rs.getString(2); hmMl.clear(); } hmMl.put(rs.getLong(3), rs.getString(4)); } if (lang_code != -1 && lang_code != FxLanguage.SYSTEM_ID) { //add FxLanguage lang = new FxLanguage(lang_code, iso_code, new FxString(FxLanguage.DEFAULT_ID, hmMl), true); if (add2cache && used) { cache.put(CacheAdmin.LANGUAGES_ID, lang.getId(), lang); cache.put(CacheAdmin.LANGUAGES_ISO, lang.getIso2digit(), lang); } alLang.add(lang); } if (add2cache && used) { cache.put(CacheAdmin.LANGUAGES_ALL, CACHE_KEY_ALL_LANG_IDS, alLang); } } catch (SQLException e) { LOG.error(e, e); } catch (FxCacheException e) { LOG.error(e, e); } finally { Database.closeObjects(LanguageBean.class, con, stmt); } return alLang; }
From source file:com.hyeb.service.StaticServiceImpl.java
@Transactional(readOnly = true) public int buildSitemap() { int buildCount = 0; Template sitemapIndexTemplate = templateService.get("sitemapIndex"); Template sitemapTemplate = templateService.get("sitemap"); Map<String, Object> model = new HashMap<String, Object>(); List<String> staticPaths = new ArrayList<String>(); for (int step = 0, index = 0, first = 0, count = SITEMAP_MAX_SIZE;;) { try {/* ww w .j a v a2s . c om*/ model.put("index", index); String templatePath = sitemapTemplate.getTemplatePath(); String staticPath = FreemarkerUtils.process(sitemapTemplate.getStaticPath(), model); if (step == 0) { List<Article> articles = articleDao.findList(first, count, null, null); model.put("articles", articles); if (articles.size() < count) { step++; first = 0; count -= articles.size(); } else { buildCount += build(templatePath, staticPath, model); articleDao.clear(); articleDao.flush(); staticPaths.add(staticPath); model.clear(); index++; first += articles.size(); count = SITEMAP_MAX_SIZE; } } else if (step == 1) { List<Product> products = productDao.findList(first, count, null, null); model.put("products", products); if (products.size() < count) { step++; first = 0; count -= products.size(); } else { buildCount += build(templatePath, staticPath, model); productDao.clear(); productDao.flush(); staticPaths.add(staticPath); model.clear(); index++; first += products.size(); count = SITEMAP_MAX_SIZE; } } else if (step == 2) { } else if (step == 3) { } break; } catch (Exception e) { e.printStackTrace(); } } return buildCount; }
From source file:com.esd.ps.AdministratorController.java
/** * ?/*from www .j a v a2 s . co m*/ * * @param userId * @param userStatus * @return */ @RequestMapping(value = "/userStatus", method = RequestMethod.POST) @ResponseBody public Map<String, Object> userStatus(int userId, int userStatus) { //logger.debug("userId:{},userStatus:{}", userId, userStatus); Map<String, Object> map = new HashMap<>(); user user = new user(); user.setUserId(userId); if (userStatus == 1) { user.setUserStatus(true); } else if (userStatus == 0) { user.setUserStatus(false); } StackTraceElement[] items = Thread.currentThread().getStackTrace(); user.setUpdateMethod(items[1].toString()); int replay = userService.updateByPrimaryKeySelective(user); if (replay == 1) { map.clear(); map.put(Constants.REPLAY, replay); map.put(Constants.MESSAGE, MSG_UPDATE_SUCCESS); return map; } map.clear(); map.put(Constants.REPLAY, 0); map.put(Constants.MESSAGE, MSG_UPDATE_ERROR); return map; }