private void addLoginParams(Request request, LoginInfo loginInfo) { MultiMap<String> params = new MultiMap<>(); if (loginInfo != null && loginInfo.rememberAccount) { params.put(PARAM_USER_ID, loginInfo.userId); } request.setParameters(params); }
@Test public void testIssue508And513() throws Exception { HazelcastClient client = getHazelcastClient(); IMap<String, HashSet<byte[]>> callEventsMap = client.getMap("CALL_EVENTS"); IMap<String, Long> metaDataMap = client.getMap("CALL_META_DATA"); IMap<String, byte[]> callStartMap = client.getMap("CALL_START_EVENTS"); MultiMap<String, String> calls = client.getMultiMap("CALLS"); calls.lock("1"); calls.unlock("1"); byte[] bytes = new byte[10]; HashSet<byte[]> hashSet = new HashSet<byte[]>(); hashSet.add(bytes); String callId = "1"; callEventsMap.put(callId, hashSet); callStartMap.put(callId, bytes); metaDataMap.put(callId, 10L); Transaction txn = client.getTransaction(); txn.begin(); try { // remove the data callEventsMap.remove(callId); // remove meta data metaDataMap.remove(callId); // remove call start callStartMap.remove(callId); calls.put(callId, callId); txn.commit(); } catch (Exception e) { fail(); } assertNull(callEventsMap.get(callId)); assertNull(metaDataMap.get(callId)); assertNull(callStartMap.get(callId)); assertEquals(0, callEventsMap.size()); assertEquals(0, metaDataMap.size()); assertEquals(0, callStartMap.size()); }
private List<TemplatesGroup> fillTemplatesMap(WizardContext context) { List<ModuleBuilder> builders = ModuleBuilder.getAllBuilders(); if (context.isCreatingNewProject()) { builders.add(new EmptyModuleBuilder()); } Map<String, TemplatesGroup> groupMap = new HashMap<String, TemplatesGroup>(); for (ModuleBuilder builder : builders) { BuilderBasedTemplate template = new BuilderBasedTemplate(builder); if (builder.isTemplate()) { TemplatesGroup group = groupMap.get(builder.getGroupName()); if (group == null) { group = new TemplatesGroup(builder); } myTemplatesMap.putValue(group, template); } else { TemplatesGroup group = new TemplatesGroup(builder); groupMap.put(group.getName(), group); myTemplatesMap.put(group, new ArrayList<ProjectTemplate>()); } } MultiMap<TemplatesGroup, ProjectTemplate> map = CreateFromTemplateMode.getTemplatesMap(context); myTemplatesMap.putAllValues(map); for (ProjectCategory category : ProjectCategory.EXTENSION_POINT_NAME.getExtensions()) { TemplatesGroup group = new TemplatesGroup(category); myTemplatesMap.remove(group); myTemplatesMap.put(group, new ArrayList<ProjectTemplate>()); } if (context.isCreatingNewProject()) { MultiMap<String, ProjectTemplate> localTemplates = loadLocalTemplates(); for (TemplatesGroup group : myTemplatesMap.keySet()) { myTemplatesMap.putValues(group, localTemplates.get(group.getId())); } } // remove Static Web group in IDEA Community if no specific templates found (IDEA-120593) if (PlatformUtils.isIdeaCommunity()) { for (TemplatesGroup group : myTemplatesMap.keySet()) { if (WebModuleTypeBase.WEB_MODULE.equals(group.getId()) && myTemplatesMap.get(group).isEmpty()) { myTemplatesMap.remove(group); break; } } } List<TemplatesGroup> groups = new ArrayList<TemplatesGroup>(myTemplatesMap.keySet()); // sorting by module type popularity final MultiMap<ModuleType, TemplatesGroup> moduleTypes = new MultiMap<ModuleType, TemplatesGroup>(); for (TemplatesGroup group : groups) { ModuleType type = getModuleType(group); moduleTypes.putValue(type, group); } Collections.sort( groups, new Comparator<TemplatesGroup>() { @Override public int compare(TemplatesGroup o1, TemplatesGroup o2) { int i = o2.getWeight() - o1.getWeight(); if (i != 0) return i; int i1 = moduleTypes.get(getModuleType(o2)).size() - moduleTypes.get(getModuleType(o1)).size(); if (i1 != 0) return i1; return o1.compareTo(o2); } }); Set<String> groupNames = ContainerUtil.map2Set( groups, new Function<TemplatesGroup, String>() { @Override public String fun(TemplatesGroup group) { return group.getParentGroup(); } }); // move subgroups MultiMap<String, TemplatesGroup> subGroups = new MultiMap<String, TemplatesGroup>(); for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) { TemplatesGroup group = iterator.next(); String parentGroup = group.getParentGroup(); if (parentGroup != null && groupNames.contains(parentGroup) && !group.getName().equals(parentGroup) && groupMap.containsKey(parentGroup)) { subGroups.putValue(parentGroup, group); iterator.remove(); } } for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) { TemplatesGroup group = iterator.next(); for (TemplatesGroup subGroup : subGroups.get(group.getName())) { iterator.add(subGroup); } } return groups; }
/** * Normally sets the path and a few attributes that the JSPs are likely to need. Also verifies the * login information. If necessary, just redirects to the login page. * * @param target * @param request * @param httpServletResponse * @param secured * @return true if the request is already handled so the .jsp shouldn't get called * @throws Exception */ private boolean prepareForJspGet( String target, Request request, HttpServletResponse httpServletResponse, boolean secured) throws Exception { LoginInfo.SessionInfo sessionInfo = UserHelpers.getSessionInfo(request); LOG.info( String.format( "hndl - %s ; %s; %s ; %s", target, request.getPathInfo(), request.getMethod(), secured ? "secured" : "not secured")); String path = request.getUri().getDecodedPath(); boolean redirectToLogin = path.equals(PATH_LOGOUT); LoginInfo loginInfo = null; if (sessionInfo.isNull()) { redirectToLogin = true; LOG.info("Null session info. Logging in again."); } else { loginInfo = loginInfoDb.get( sessionInfo.browserId, sessionInfo.sessionId); // ttt2 use a cache, to avoid going to DB if (loginInfo == null || loginInfo.expiresOn < System.currentTimeMillis()) { LOG.info("Session has expired. Logging in again. Info: " + loginInfo); redirectToLogin = true; } } if (!path.equals(PATH_LOGIN) && !path.equals(PATH_SIGNUP) && !path.equals(PATH_ERROR)) { if (redirectToLogin) { // ttt2 perhaps store URI, to return to it after login logOut(sessionInfo.browserId); addLoginParams(request, loginInfo); httpServletResponse.sendRedirect(PATH_LOGIN); return true; } User user = userDb.get(loginInfo.userId); if (user == null) { WebUtils.redirectToError("Unknown user", request, httpServletResponse); return true; } if (!user.active) { WebUtils.redirectToError("Account is not active", request, httpServletResponse); return true; } request.setAttribute(VAR_FEED_DB, feedDb); request.setAttribute(VAR_USER_DB, userDb); request.setAttribute(VAR_ARTICLE_DB, articleDb); request.setAttribute(VAR_READ_ARTICLES_COLL_DB, readArticlesCollDb); request.setAttribute(VAR_USER, user); request.setAttribute(VAR_LOGIN_INFO, loginInfo); MultiMap<String> params = new MultiMap<>(); params.put(PARAM_PATH, path); request.setParameters(params); } if (path.equals(PATH_LOGIN)) { addLoginParams(request, loginInfo); } return false; }