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); } }
/** 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 }
public void testRegisterPlugins() throws Exception { subjectMgr = LookupUtil.getSubjectManager(); resourceTypeMgr = LookupUtil.getResourceTypeManager(); registerParentPluginV1(); // create an initial type (called the parent) registerChildPluginV1(); // using plugin extension mechanism, create a child type that extends // that parent type registerParentPluginV2(); // update the parent type checkChildPlugin(); // check that the changes to the parent type propogated to the child }
@BeforeMethod public void setupBeforeMethod() throws Exception { // Plugin service setup prepareScheduler(); pluginService = new TestContentServerPluginService(this); TransactionManager tx = getTransactionManager(); try { tx.begin(); EntityManager entityManager = getEntityManager(); ContentManagerLocal contentManager = LookupUtil.getContentManager(); ContentSourceManagerLocal contentSourceManager = LookupUtil.getContentSourceManager(); RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal(); ResourceTypeManagerLocal resourceTypeManager = LookupUtil.getResourceTypeManager(); SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager(); Subject overlord = subjectManager.getOverlord(); // protect if it aleady exists due to a failed run contentSourceType = contentSourceManager.getContentSourceType("testType"); if (null == contentSourceType) { // Create a sample content source type that will be used in this test contentSourceType = new ContentSourceType("testType"); entityManager.persist(contentSourceType); entityManager.flush(); } // protect if it aleady exists due to a failed run ContentSource cs1 = contentSourceManager.getContentSourceByNameAndType( overlord, "contentSource1", "testType"); if (null == cs1) { // A repo sync will query all providers for that repo, so add multiple providers cs1 = new ContentSource("contentSource1", contentSourceType); cs1.setDownloadMode(DownloadMode.DATABASE); cs1 = contentSourceManager.simpleCreateContentSource(overlord, cs1); } ContentSource cs2 = contentSourceManager.getContentSourceByNameAndType( overlord, "contentSource2", "testType"); if (null == cs2) { cs2 = new ContentSource("contentSource2", contentSourceType); cs2.setDownloadMode(DownloadMode.DATABASE); cs2 = contentSourceManager.simpleCreateContentSource(overlord, cs2); } pluginService.associateContentProvider(cs1, contentProvider1); pluginService.associateContentProvider(cs2, contentProvider2); repoContentSources.add(cs1); repoContentSources.add(cs2); // Create the package type packages will be created against resourceType = resourceTypeManager.getResourceTypeByNameAndPlugin( TestContentProvider.RESOURCE_TYPE_NAME, TestContentProvider.RESOURCE_TYPE_PLUGIN_NAME); if (null == resourceType) { resourceType = new ResourceType( TestContentProvider.RESOURCE_TYPE_NAME, TestContentProvider.RESOURCE_TYPE_PLUGIN_NAME, ResourceCategory.PLATFORM, null); entityManager.persist(resourceType); entityManager.flush(); } List<PackageType> packageTypes = contentManager.findPackageTypes( overlord, TestContentProvider.RESOURCE_TYPE_NAME, TestContentProvider.RESOURCE_TYPE_PLUGIN_NAME); if (!packageTypes.isEmpty()) { packageType = packageTypes.get(0); } else { packageType = new PackageType(TestContentProvider.PACKAGE_TYPE_NAME, resourceType); entityManager.persist(packageType); } // Create the repo to be synced List<Repo> repos = repoManager.getRepoByName(TestContentProvider.REPO_WITH_PACKAGES); if (!repos.isEmpty()) { repoToSync = repos.get(0); } else { Repo repo = new Repo(TestContentProvider.REPO_WITH_PACKAGES); repo.addContentSource(cs1); // repo.addContentSource(cs2); Disabled until we implement a second test content // source to return new stuff repoToSync = repoManager.createRepo(overlord, repo); } tx.commit(); } catch (Throwable t) { tx.rollback(); // rethrow because if we swallow the exception then tests proceed to execute when they // probably should not throw new RuntimeException(t); } }