modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/group/inventory/AddGroupResourcesFormPrepareAction.java | 5 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java | 172 +++++----- 2 files changed, 101 insertions(+), 76 deletions(-)
New commits: commit 4714eb87aeeb6dce6a6ebcb7573bc80dafa3928d Merge: e25997a... 7f4d769... Author: Heiko W. Rupp hwr@redhat.com Date: Wed Feb 24 18:19:46 2010 +0100
Merge branch 'master' into alertPlugin
commit 7f4d76951a1e2686aa4d104477765d9b4d350dad Author: Lukas Krejci lkrejci@redhat.com Date: Wed Feb 24 18:13:05 2010 +0100
BZ 566749 - fixing the NPE when adding platforms (that don't have a parent) to a resource group.
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/group/inventory/AddGroupResourcesFormPrepareAction.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/group/inventory/AddGroupResourcesFormPrepareAction.java index 698cb5a..808f331 100644 --- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/group/inventory/AddGroupResourcesFormPrepareAction.java +++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/group/inventory/AddGroupResourcesFormPrepareAction.java @@ -201,7 +201,10 @@ public class AddGroupResourcesFormPrepareAction extends Action { Resource resource = dr.getOriginal();
Resource parent = resource.getParentResource(); - parent.setName(buildLineage(dr.getParents())); + //platforms don't have parents, need to check for null here + if (parent != null) { + parent.setName(buildLineage(dr.getParents())); + }
convertedResults.add(resource); }
commit e25997a61a0e49e38768d20461afffb9d19a554e Merge: 33e3625... 1e8ab54... Author: Heiko W. Rupp hwr@redhat.com Date: Wed Feb 24 16:53:45 2010 +0100
Merge branch 'master' into alertPlugin
commit 1e8ab544201de380a8911b2fa88701c4b9b1a206 Author: Lukas Krejci lkrejci@redhat.com Date: Wed Feb 24 15:33:18 2010 +0100
BZ 567925 - Restructured the ResourceManagerBean.disambiguate() method to handle (hopefully) all the corner cases resulting from the fact that not all of the provided results have to be mappable to a resource.
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java index b0db81c..6755733 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java @@ -2162,45 +2162,23 @@ public class ResourceManagerBean implements ResourceManagerLocal, ResourceManage return (findChildResources(subject, parentResource, pageControl)); }
- public <T> ResourceNamesDisambiguationResult<T> disambiguate(List<T> results, boolean alwaysIncludeParent, IntExtractor<? super T> extractor) { - if (results.isEmpty()) { - return new ResourceNamesDisambiguationResult<T>(new ArrayList<DisambiguationReport<T>>(), false, false, false); - } + public <T> ResourceNamesDisambiguationResult<T> disambiguate(List<T> results, boolean alwaysIncludeParent, + IntExtractor<? super T> extractor) {
- String query = Resource.NATIVE_QUERY_FIND_DISAMBIGUATION_LEVEL; - - query = JDBCUtil.transformQueryForMultipleInParameters(query, "@@RESOURCE_IDS@@", results.size()); - Query disambiguateQuery = entityManager.createNativeQuery(query); - int i = 1; - for (T r : results) { - disambiguateQuery.setParameter(i++, extractor.extract(r)); - } - - Object[] rs = (Object[]) disambiguateQuery.getSingleResult(); - - int disambiguationLevel = Resource.MAX_SUPPORTED_RESOURCE_HIERARCHY_DEPTH; //the max we support - - int targetCnt = ((BigInteger) rs[0]).intValue(); - int typeCnt = ((BigInteger) rs[1]).intValue(); - int typeAndPluginCnt = ((BigInteger) rs[2]).intValue(); - for (i = 1; i <= Resource.MAX_SUPPORTED_RESOURCE_HIERARCHY_DEPTH; ++i) { - int levelCnt = ((BigInteger) rs[2 + i]).intValue(); - if (levelCnt == targetCnt) { - disambiguationLevel = i - 1; - break; - } - } - - if (alwaysIncludeParent && disambiguationLevel == 0) { - disambiguationLevel = 1; + if (results.isEmpty()) { + return new ResourceNamesDisambiguationResult<T>(new ArrayList<DisambiguationReport<T>>(), false, false, + false); }
- boolean typeResolutionNeeded = typeAndPluginCnt > 1; - boolean pluginResolutionNeeded = typeAndPluginCnt > typeCnt; - boolean parentResolutionNeeded = disambiguationLevel > 0; + //this will contain the disambiguated results + List<DisambiguationReport<T>> resolution = new ArrayList<DisambiguationReport<T>>(results.size()); + boolean typeResolutionNeeded = false; + boolean pluginResolutionNeeded = false; + boolean parentResolutionNeeded = false;
- //we can't assume any ordering in the results, hence this map - Map<Integer, MutableDisambiguationReport<T>> reportByResourceId = new LinkedHashMap<Integer, MutableDisambiguationReport<T>>(); + //we can't assume the ordering of the provided results and the disambiguation query results + //will be the same, hence this map. + Map<Integer, MutableDisambiguationReport<T>> reportByResourceId = new HashMap<Integer, MutableDisambiguationReport<T>>(); for (T r : results) { MutableDisambiguationReport<T> value = new MutableDisambiguationReport<T>(); value.original = r; @@ -2210,57 +2188,101 @@ public class ResourceManagerBean implements ResourceManagerLocal, ResourceManage } }
- //k, now let's construct the JPQL query to get the parents and type infos... - StringBuilder selectBuilder = new StringBuilder("SELECT r0.id, r0.resourceType.name, r0.resourceType.plugin"); - StringBuilder fromBuilder = new StringBuilder("FROM Resource r0"); + //check that we still have something to disambiguate + if (reportByResourceId.isEmpty()) { + //no, we don't. construct the resolution only using the results.
- for (i = 1; i <= disambiguationLevel; ++i) { - int pi = i - 1; - selectBuilder.append(", r").append(i).append(".id"); - selectBuilder.append(", r").append(i).append(".name"); - fromBuilder.append(" left join r").append(pi).append(".parentResource r").append(i); - } + for (T result : results) { + DisambiguationReport<T> report = new DisambiguationReport<T>(result, Collections + .<ResourceParentFlyweight> emptyList(), null, null); + resolution.add(report); + } + } else { + //first find out how many ancestors we are going to require to disambiguate the resuls + String query = Resource.NATIVE_QUERY_FIND_DISAMBIGUATION_LEVEL; + + query = JDBCUtil.transformQueryForMultipleInParameters(query, "@@RESOURCE_IDS@@", results.size()); + Query disambiguateQuery = entityManager.createNativeQuery(query); + int i = 1; + for (T r : results) { + disambiguateQuery.setParameter(i++, extractor.extract(r)); + }
- fromBuilder.append(" WHERE r0.id IN (:resourceIds)"); + Object[] rs = (Object[]) disambiguateQuery.getSingleResult();
- Query parentsQuery = entityManager.createQuery(selectBuilder.append(" ").append(fromBuilder).toString()); + int disambiguationLevel = Resource.MAX_SUPPORTED_RESOURCE_HIERARCHY_DEPTH; //the max we support
- parentsQuery.setParameter("resourceIds", reportByResourceId.keySet()); + int targetCnt = ((BigInteger) rs[0]).intValue(); + int typeCnt = ((BigInteger) rs[1]).intValue(); + int typeAndPluginCnt = ((BigInteger) rs[2]).intValue(); + for (i = 1; i <= Resource.MAX_SUPPORTED_RESOURCE_HIERARCHY_DEPTH; ++i) { + int levelCnt = ((BigInteger) rs[2 + i]).intValue(); + if (levelCnt == targetCnt) { + disambiguationLevel = i - 1; + break; + } + } + + if (alwaysIncludeParent && disambiguationLevel == 0) { + disambiguationLevel = 1; + }
- @SuppressWarnings("unchecked") - List<Object[]> parentsResults = (List<Object[]>) parentsQuery.getResultList(); - for (Object[] parentsResult : parentsResults) { - List<ResourceParentFlyweight> parents = new ArrayList<ResourceParentFlyweight>(disambiguationLevel); - Integer resourceId = (Integer) parentsResult[0]; - String typeName = (String) parentsResult[1]; - String pluginName = (String) parentsResult[2]; + typeResolutionNeeded = typeAndPluginCnt > 1; + pluginResolutionNeeded = typeAndPluginCnt > typeCnt; + parentResolutionNeeded = disambiguationLevel > 0; + + //k, now let's construct the JPQL query to get the parents and type infos... + StringBuilder selectBuilder = new StringBuilder( + "SELECT r0.id, r0.resourceType.name, r0.resourceType.plugin"); + StringBuilder fromBuilder = new StringBuilder("FROM Resource r0");
for (i = 1; i <= disambiguationLevel; ++i) { - Integer parentId = (Integer) parentsResult[2 * i + 1]; - if (parentId == null) - break; - String parentName = (String) parentsResult[2 * i + 2]; - parents.add(new ResourceParentFlyweight(parentId, parentName)); + int pi = i - 1; + selectBuilder.append(", r").append(i).append(".id"); + selectBuilder.append(", r").append(i).append(".name"); + fromBuilder.append(" left join r").append(pi).append(".parentResource r").append(i); } - MutableDisambiguationReport<T> report = reportByResourceId.get(resourceId); - report.typeName = typeName; - report.pluginName = pluginName; - report.parents = parents; - }
- //now we have all the information to create the result. - //first create the immutable reports. - List<DisambiguationReport<T>> resolution = new ArrayList<DisambiguationReport<T>>(results.size()); + fromBuilder.append(" WHERE r0.id IN (:resourceIds)");
- for(T result : results) { - int resourceId = extractor.extract(result); - if (resourceId > 0) { + Query parentsQuery = entityManager.createQuery(selectBuilder.append(" ").append(fromBuilder).toString()); + + parentsQuery.setParameter("resourceIds", reportByResourceId.keySet()); + + @SuppressWarnings("unchecked") + List<Object[]> parentsResults = (List<Object[]>) parentsQuery.getResultList(); + for (Object[] parentsResult : parentsResults) { + List<ResourceParentFlyweight> parents = new ArrayList<ResourceParentFlyweight>(disambiguationLevel); + Integer resourceId = (Integer) parentsResult[0]; + String typeName = (String) parentsResult[1]; + String pluginName = (String) parentsResult[2]; + + for (i = 1; i <= disambiguationLevel; ++i) { + Integer parentId = (Integer) parentsResult[2 * i + 1]; + if (parentId == null) + break; + String parentName = (String) parentsResult[2 * i + 2]; + parents.add(new ResourceParentFlyweight(parentId, parentName)); + } MutableDisambiguationReport<T> report = reportByResourceId.get(resourceId); - resolution.add(report.getReport()); - } else { - //this result doesn't correspond to any resource, need to handle it specially - DisambiguationReport<T> report = new DisambiguationReport<T>(result, Collections.<ResourceParentFlyweight>emptyList(), null, null); - resolution.add(report); + report.typeName = typeName; + report.pluginName = pluginName; + report.parents = parents; + } + + //now we have all the information to create the result. + for (T result : results) { + int resourceId = extractor.extract(result); + if (resourceId > 0) { + //this results was disambiguated by the query above... + MutableDisambiguationReport<T> report = reportByResourceId.get(resourceId); + resolution.add(report.getReport()); + } else { + //this result doesn't correspond to any resource, need to handle it specially + DisambiguationReport<T> report = new DisambiguationReport<T>(result, Collections + .<ResourceParentFlyweight> emptyList(), null, null); + resolution.add(report); + } } }
rhq-commits@lists.fedorahosted.org