private APIInfoDTO doGetAPIInfo(String context, String apiVersion) {
    APIInfoDTO apiInfoDTO = new APIInfoDTO();
    try {
      ArrayList<URITemplate> uriTemplates = getAllURITemplates(context, apiVersion);

      apiInfoDTO.setApiName(context);
      apiInfoDTO.setContext(context);
      apiInfoDTO.setVersion(apiVersion);
      apiInfoDTO.setResources(new HashSet<ResourceInfoDTO>());

      ResourceInfoDTO resourceInfoDTO = null;
      VerbInfoDTO verbInfoDTO = null;
      int i = 0;
      for (URITemplate uriTemplate : uriTemplates) {
        if (resourceInfoDTO != null
            && resourceInfoDTO.getUrlPattern().equalsIgnoreCase(uriTemplate.getUriTemplate())) {
          HashSet<VerbInfoDTO> verbs = (HashSet<VerbInfoDTO>) resourceInfoDTO.getHttpVerbs();
          verbInfoDTO = new VerbInfoDTO();
          verbInfoDTO.setHttpVerb(uriTemplate.getHTTPVerb());
          verbInfoDTO.setAuthType(uriTemplate.getAuthType());
          verbs.add(verbInfoDTO);
          resourceInfoDTO.setHttpVerbs(verbs);
          apiInfoDTO.getResources().add(resourceInfoDTO);
        } else {
          resourceInfoDTO = new ResourceInfoDTO();
          resourceInfoDTO.setUrlPattern(uriTemplate.getUriTemplate());
          verbInfoDTO = new VerbInfoDTO();
          verbInfoDTO.setHttpVerb(uriTemplate.getHTTPVerb());
          verbInfoDTO.setAuthType(uriTemplate.getAuthType());
          HashSet<VerbInfoDTO> httpVerbs2 = new HashSet();
          httpVerbs2.add(verbInfoDTO);
          resourceInfoDTO.setHttpVerbs(httpVerbs2);
          apiInfoDTO.getResources().add(resourceInfoDTO);
        }
      }
    } catch (APIManagementException e) {
      log.error("Loading URI templates for " + context + ":" + apiVersion + " failed", e);
    } catch (APISecurityException e) {
      log.error("Loading URI templates for " + context + ":" + apiVersion + " failed", e);
    }
    return apiInfoDTO;
  }
  private APIInfoDTO doGetAPIInfo(String context, String apiVersion) throws APISecurityException {
    APIInfoDTO apiInfoDTO = new APIInfoDTO();

    ArrayList<URITemplate> uriTemplates = getAllURITemplates(context, apiVersion);

    apiInfoDTO.setApiName(context);
    apiInfoDTO.setContext(context);
    apiInfoDTO.setVersion(apiVersion);
    apiInfoDTO.setResources(new LinkedHashSet<ResourceInfoDTO>());

    ResourceInfoDTO resourceInfoDTO = null;
    VerbInfoDTO verbInfoDTO = null;

    // The following map is used to retrieve already created ResourceInfoDTO rather than iterating -
    // the resource Set in apiInfoDTO.
    LinkedHashMap<String, ResourceInfoDTO> resourcesMap =
        new LinkedHashMap<String, ResourceInfoDTO>();
    for (URITemplate uriTemplate : uriTemplates) {
      resourceInfoDTO = resourcesMap.get(uriTemplate.getUriTemplate());
      if (null == resourceInfoDTO) {
        resourceInfoDTO = new ResourceInfoDTO();
        resourceInfoDTO.setUrlPattern(uriTemplate.getUriTemplate());
        resourceInfoDTO.setHttpVerbs(new LinkedHashSet());
        apiInfoDTO.getResources().add(resourceInfoDTO);
        resourcesMap.put(uriTemplate.getUriTemplate(), resourceInfoDTO);
      }
      verbInfoDTO = new VerbInfoDTO();
      verbInfoDTO.setHttpVerb(uriTemplate.getHTTPVerb());
      verbInfoDTO.setAuthType(uriTemplate.getAuthType());
      verbInfoDTO.setThrottling(uriTemplate.getThrottlingTier());
      verbInfoDTO.setThrottlingConditions(uriTemplate.getThrottlingConditions());
      verbInfoDTO.setConditionGroups(uriTemplate.getConditionGroups());
      verbInfoDTO.setApplicableLevel(uriTemplate.getApplicableLevel());
      resourceInfoDTO.getHttpVerbs().add(verbInfoDTO);
    }

    return apiInfoDTO;
  }