Пример #1
0
  protected void setResource(HttpServletRequest request, boolean config) throws Exception {
    try {
      Subject subject = WebUtility.getSubject(request);
      Integer resourceTypeId =
          WebUtility.getOptionalIntRequestParameter(
              request, ParamConstants.RESOURCE_TYPE_ID_PARAM, -1);
      int groupId = WebUtility.getOptionalIntRequestParameter(request, AttrConstants.GROUP_ID, -1);
      int parent = WebUtility.getOptionalIntRequestParameter(request, "parent", -1);
      String[] r = request.getParameterValues("r");
      String[] resourceIds = request.getParameterValues("resourceIds");

      // TODO rewrite the selection using WebUtility.getMetricsDisplayMode()
      if ((resourceTypeId > 0) && (parent > 0)) // autogroup
      {
        ResourceTypeManagerLocal resourceTypeManager = LookupUtil.getResourceTypeManager();
        ResourceType resourceType =
            resourceTypeManager.getResourceTypeById(subject, resourceTypeId);
        request.setAttribute(AttrConstants.RESOURCE_TYPE_ATTR, resourceType);
        request.setAttribute(AttrConstants.TITLE_PARAM_ATTR, resourceType.getName());
        request.setAttribute("parent", parent);
        request.setAttribute(ParamConstants.RESOURCE_TYPE_ID_PARAM, resourceTypeId);
        if (log.isDebugEnabled()) {
          log.debug("Autogroup p=" + parent + ", ct=" + resourceTypeId);
        }
      } else if (groupId > 0) // compat (or mixed) group
      {
        ResourceGroupManagerLocal resourceGroupManager = LookupUtil.getResourceGroupManager();
        ResourceGroup group = resourceGroupManager.getResourceGroupById(subject, groupId, null);
        request.setAttribute(AttrConstants.GROUP_ID, groupId);
        request.setAttribute(AttrConstants.TITLE_PARAM_ATTR, group.getName());
        // TODO more ?
      } else if ((resourceTypeId > 0) && (parent == -1)) // MeasurementDefinition
      {
        ResourceTypeManagerLocal resourceTypeManager = LookupUtil.getResourceTypeManager();
        ResourceType resourceType =
            resourceTypeManager.getResourceTypeById(subject, resourceTypeId);
        request.setAttribute(AttrConstants.RESOURCE_TYPE_ATTR, resourceType);
        request.setAttribute(ParamConstants.RESOURCE_TYPE_ID_PARAM, resourceTypeId);
      } else if ((r != null) && (r.length > 0)) // multiple scathered resources
      {
        log.trace("Multiple resources not handled yet"); // TODO what do we do here?
      } else if ((resourceIds != null) && (resourceIds.length > 0)) {
        log.trace("Multiple resources not yet handled"); // TODO what to we do here?
      } else // single resource
      {
        Integer resourceId =
            WebUtility.getRequiredIntRequestParameter(request, ParamConstants.RESOURCE_ID_PARAM);
        ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
        Resource resource = resourceManager.getResourceById(subject, resourceId);
        ResourceUIBean resourceUIBean = new ResourceUIBean(resource, subject);
        request.setAttribute(AttrConstants.RESOURCE_ATTR, resource);
        request.setAttribute(AttrConstants.RESOURCE_ID_ATTR, resourceId);
        request.setAttribute(AttrConstants.TITLE_PARAM_ATTR, resource.getName());
        request.setAttribute(
            AttrConstants.PERFORMANCE_SUPPORTED_ATTR, resourceUIBean.getFacets().isCallTime());
      }
    } catch (ResourceNotFoundException e) {
      RequestUtils.setError(request, MessageConstants.ERR_RESOURCE_NOT_FOUND);
    }
  }
Пример #2
0
  /** Get a list of the individual 'child resources' of that autogroup. */
  private List<AutoGroupComposite> getAutoGroupChildren(
      Subject subject, int parentId, int resourceTypeId) {
    List<AutoGroupComposite> children = new ArrayList<AutoGroupComposite>();
    ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
    ResourceTypeManagerLocal resourceTypeMananger = LookupUtil.getResourceTypeManager();
    Resource parentResource = resourceManager.getResourceById(subject, parentId);
    ResourceType resourceType = null;
    try {
      resourceType = resourceTypeMananger.getResourceTypeById(subject, resourceTypeId);
    } catch (ResourceTypeNotFoundException e) {
      return children; // empty list if we don't know the child type
    }

    if ((resourceType != null) && (parentResource != null)) {

      // first get the resources in the autogroup
      List<ResourceWithAvailability> resourcesForAutoGroup =
          resourceManager.findResourcesByParentAndType(subject, parentResource, resourceType);

      int i = 0;
      int[] resourceIds = new int[resourcesForAutoGroup.size()];
      for (ResourceWithAvailability resourceInAutoGroup : resourcesForAutoGroup) {
        int id = resourceInAutoGroup.getResource().getId();
        resourceIds[i++] = id;
      }

      // And then the composite to return
      List<AutoGroupComposite> composites =
          resourceManager.findResourcesAutoGroups(subject, resourceIds);

      return composites;
    }

    return children; // empty
  }