Obtains the collection of server groups defined for a profile

@param model
@param profileId
@return
@throws Exception
199204
@RequestMapping(value = "api/servergroup", method = RequestMethod.GET)
    public
    @ResponseBody
    HashMap<String, Object> getServerGroups(Model model,
                                            @RequestParam(value = "profileId", required = false) Integer profileId,
                                            @RequestParam(value = "search", required = false) String search,
                                            @RequestParam(value = "profileIdentifier", required = false) String profileIdentifier) throws Exception {
        if (profileId == null && profileIdentifier == null) {
            throw new Exception("profileId required");
        }
        if (profileId == null) {
            profileId = ProfileService.getInstance().getIdFromName(profileIdentifier);
        }

        List<ServerGroup> serverGroups = ServerRedirectService.getInstance().tableServerGroups(profileId);

        if (search != null) {
            Iterator<ServerGroup> iterator = serverGroups.iterator();
            while (iterator.hasNext()) {
                ServerGroup serverGroup = iterator.next();
                if (!serverGroup.getName().toLowerCase().contains(search.toLowerCase())) {
                    iterator.remove();
                }
            }
        }
        HashMap<String, Object> returnJson = Utils.getJQGridJSON(serverGroups, "servergroups");
        return returnJson;
    }
842994
@RequestMapping(value = "/api/history/{profileIdentifier}", method = RequestMethod.GET)
    public
    @ResponseBody
    HashMap<String, Object> getHistory(Model mode, @PathVariable String profileIdentifier,
                                       @RequestParam(value = "clientUUID", defaultValue = Constants.PROFILE_CLIENT_DEFAULT_ID) String clientUUID,
                                       @RequestParam(value = "offset", defaultValue = "0") int offset,
                                       @RequestParam(value = "limit", defaultValue = "-1") int limit,
                                       @RequestParam(value = "source_uri[]", required = false) String[] sourceURIFilters,
                                       @RequestParam(value = "page", defaultValue = "1") int page,
                                       @RequestParam(value = "rows", defaultValue = "-1") int rows,
                                       @RequestParam(value = "hasMessage", defaultValue = "false") boolean hasMessage) throws Exception {
        Integer profileId = ControllerUtils.convertProfileIdentifier(profileIdentifier);
        HashMap<String, String[]> filters = new HashMap<String, String[]>();
        if (sourceURIFilters != null) {
            filters.put(Constants.HISTORY_FILTER_SOURCE_URI, sourceURIFilters);
        }

        // rows exists because jqgrid uses it.. but limit is more common
        // set limit to rows if it was set
        if (rows != -1) {
            limit = rows;
        }

        // offset id # of page(-1) * rows if not passed in
        if (offset == 0) {
            offset = (page - 1) * rows;
        }

        History[] histories = HistoryService.getInstance().getHistory(profileId, clientUUID, offset, limit, false, filters, hasMessage);
        int totalRows = HistoryService.getInstance().getHistoryCount(profileId, clientUUID, filters);
        HashMap<String, Object> returnJSON = Utils.getJQGridJSON(histories, "history", offset, totalRows, limit);

        return returnJSON;
    }
1352415
private Collection<Membership> findMembershipsByUserAndGroup(Session session, String userName, String groupId) throws Exception
   {
      Node groupNode;
      Node refUserNode;

      try
      {
         groupNode = utils.getGroupNode(session, groupId);
         refUserNode = groupNode.getNode(JCROrganizationServiceImpl.JOS_MEMBERSHIP).getNode(userName);
      }
      catch (PathNotFoundException e)
      {
         return new ArrayList<Membership>();
      }

      return findMembershipsByUserAndGroup(session, refUserNode, groupNode);
   }
349391
public Profile getProfile() throws IOException, KiteException, JSONException {
        String url = routes.get("user.profile");
        JSONObject response = new KiteRequestHandler(proxy).getRequest(url, apiKey, accessToken);
        return gson.fromJson(String.valueOf(response.get("data")), Profile.class);
    }
392155
public List<com.groupon.odo.proxylib.models.Method> getMethodsNotInGroup(int groupId) throws Exception {
        List<com.groupon.odo.proxylib.models.Method> allMethods = getAllMethods();
        List<com.groupon.odo.proxylib.models.Method> methodsNotInGroup = new ArrayList<com.groupon.odo.proxylib.models.Method>();
        List<com.groupon.odo.proxylib.models.Method> methodsInGroup = editService.getMethodsFromGroupId(groupId, null);

        for (int i = 0; i < allMethods.size(); i++) {
            boolean add = true;
            String methodName = allMethods.get(i).getMethodName();
            String className = allMethods.get(i).getClassName();

            for (int j = 0; j < methodsInGroup.size(); j++) {
                if ((methodName.equals(methodsInGroup.get(j).getMethodName())) &&
                    (className.equals(methodsInGroup.get(j).getClassName()))) {
                    add = false;
                }
            }
            if (add) {
                methodsNotInGroup.add(allMethods.get(i));
            }
        }
        return methodsNotInGroup;
    }
523864
@Override
    public Iterator findMemberGroups(IEntityGroup eg) throws GroupsException {
        Map groups = new HashMap();
        IEntityGroup group = null;
        for (Iterator itr = findLocalMemberGroups(eg); itr.hasNext(); ) {
            group = (IEntityGroup) itr.next();
            groups.put(group.getKey(), group);
        }

        String[] memberGroupKeys = getGroupStore().findMemberGroupKeys(eg);
        for (int i = 0; i < memberGroupKeys.length; i++) {
            if (!groups.containsKey(memberGroupKeys[i])) {
                group = GroupService.findGroup(memberGroupKeys[i]);
                if (group != null) {
                    groups.put(group.getKey(), group);
                }
            }
        }
        return groups.values().iterator();
    }
588723
@RequestMapping(value = "group", method = RequestMethod.GET)
    public String newGroupGet(Model model) {
        model.addAttribute("groups",
                pathOverrideService.findAllGroups());
        return "groups";
    }
508407
public static Profile findProfile(Model mavenModel, String profileId) {
        List<Profile> profiles = mavenModel.getProfiles();
        if (profiles != null) {
            for (Profile profile : profiles) {
                if (Objects.equal(profile.getId(), profileId)) {
                    return profile;
                }
            }
        }
        return null;
    }
720849
public List<OrgActiveRuleDto> selectByProfileUuid(DbSession dbSession, String uuid) {
    return mapper(dbSession).selectByProfileUuid(uuid);
  }
40884
@RequestMapping(value = "", method = RequestMethod.GET)
    public String pathOrderHome(Model model, @PathVariable int profileId,
                                @RequestParam(value = "clientUUID", defaultValue = "-1") String clientUUID) throws Exception {

        model.addAttribute("profile_id", profileId);
        model.addAttribute("profile_name", ProfileService.getInstance().getNamefromId(profileId));
        model.addAttribute("pathnames", PathOverrideService.getInstance().getPaths(profileId, clientUUID, null));

        return "pathOrder";
    }
1066925
public List<CmsContainerPageElementPanel> getModelGroups() {

        final List<CmsContainerPageElementPanel> result = Lists.newArrayList();

        processPageContent(new I_PageContentVisitor() {

            public boolean beginContainer(String name, CmsContainer container) {

                return true;
            }

            public void endContainer() {

                // do nothing
            }

            public void handleElement(CmsContainerPageElementPanel element) {

                if (element.isModelGroup()) {
                    result.add(element);
                }
            }
        });
        return result;
    }
386952
@RequestMapping(value = "/api/history/{profileIdentifier}/{id}", method = RequestMethod.GET)
    public
    @ResponseBody
    HashMap<String, Object> getHistoryForId(Model mode, @PathVariable String profileIdentifier, @PathVariable Integer id,
                                            @RequestParam(value = "format", required = false) String formatted) {
        HashMap<String, Object> returnData = new HashMap<String, Object>();
        History history = HistoryService.getInstance().getHistoryForID(id);
        if (formatted != null) {
            try {
                if (formatted.equals("formattedAll")) {
                    history.setFormattedResponseData(history.getResponseData());
                    history.setFormattedOriginalResponseData(history.getOriginalResponseData());
                } else if (formatted.equals("formattedModified")) {
                    history.setFormattedResponseData(history.getResponseData());
                } else if (formatted.equals("formattedOriginal")) {
                    history.setFormattedOriginalResponseData(history.getOriginalResponseData());
                }
                returnData.put("history", history);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            returnData = new HashMap<String, Object>();
            returnData.put("history", HistoryService.getInstance().getHistoryForID(id));
        }

        return returnData;
    }
1342821
@RequestMapping(value = "/api/path/{pathId}", method = RequestMethod.DELETE)
    @ResponseBody
    public HashMap<String, Object> deletePath(Model model, @PathVariable int pathId,
                                              @RequestParam(value = "clientUUID", defaultValue = Constants.PROFILE_CLIENT_DEFAULT_ID) String clientUUID) throws Exception {
        EndpointOverride currentPath = PathOverrideService.getInstance().getPath(pathId);
        int profileId = currentPath.getProfileId();

        // remove the path
        logger.info("Removing path {}", pathId);
        PathOverrideService.getInstance().removePath(pathId);

        // return the remaining data
        List<EndpointOverride> paths = PathOverrideService.getInstance().getPaths(profileId, clientUUID, null);

        return Utils.getJQGridJSON(paths, "paths");
    }
100498
private Collection<Group> findGroups(Session session, Group parent, boolean recursive) throws Exception
   {
      List<Group> groups = new ArrayList<Group>();
      String parentId = parent == null ? "" : parent.getId();

      NodeIterator childNodes = utils.getGroupNode(session, parentId).getNodes();

      while (childNodes.hasNext())
      {
         Node groupNode = childNodes.nextNode();
         if (!groupNode.getName().startsWith(JCROrganizationServiceImpl.JOS_MEMBERSHIP))
         {
            Group group = readGroup(groupNode);
            groups.add(group);

            if (recursive)
            {
               groups.addAll(findGroups(session, group, recursive));
            }
         }
      }

      return groups;
   }
283450
private List<Group> getGroups() throws Exception {
        List<Group> groups = new ArrayList<Group>();
        List<Group> sourceGroups = PathOverrideService.getInstance().findAllGroups();

        // loop through the groups
        for (Group sourceGroup : sourceGroups) {
            Group group = new Group();

            // add all methods
            ArrayList<Method> methods = new ArrayList<Method>();
            for (Method sourceMethod : EditService.getInstance().getMethodsFromGroupId(sourceGroup.getId(), null)) {
                Method method = new Method();
                method.setClassName(sourceMethod.getClassName());
                method.setMethodName(sourceMethod.getMethodName());
                methods.add(method);
            }

            group.setMethods(methods);
            group.setName(sourceGroup.getName());
            groups.add(group);
        }

        return groups;
    }
774871
@RequestMapping(value = "/api/profile", method = RequestMethod.DELETE)
    public
    @ResponseBody
    HashMap<String, Object> deleteProfile(Model model, int id) throws Exception {
        profileService.remove(id);
        return Utils.getJQGridJSON(profileService.findAllProfiles(), "profiles");
    }
567836
public Profile[] getProfilesForServerName(String serverName) throws Exception {
        int profileId = -1;
        ArrayList<Profile> returnProfiles = new ArrayList<Profile>();

        PreparedStatement queryStatement = null;
        ResultSet results = null;
        try (Connection sqlConnection = sqlService.getConnection()) {
            queryStatement = sqlConnection.prepareStatement(
                "SELECT " + Constants.GENERIC_PROFILE_ID + " FROM " + Constants.DB_TABLE_SERVERS +
                    " WHERE " + Constants.SERVER_REDIRECT_SRC_URL + " = ? GROUP BY " +
                    Constants.GENERIC_PROFILE_ID
            );
            queryStatement.setString(1, serverName);
            results = queryStatement.executeQuery();

            while (results.next()) {
                profileId = results.getInt(Constants.GENERIC_PROFILE_ID);

                Profile profile = ProfileService.getInstance().findProfile(profileId);

                returnProfiles.add(profile);
            }
        } catch (SQLException e) {
            throw e;
        } finally {
            try {
                if (results != null) {
                    results.close();
                }
            } catch (Exception e) {
            }
            try {
                if (queryStatement != null) {
                    queryStatement.close();
                }
            } catch (Exception e) {
            }
        }

        if (returnProfiles.size() == 0) {
            return null;
        }
        return returnProfiles.toArray(new Profile[0]);
    }