}
avail = avail / resources.size();
Object nodeData = null;
if (key instanceof String) {
nodeData = new AutoGroupCompositeFlyweight(avail, parentResource, (String) key, resources.size());
} else if (key instanceof ResourceTypeFlyweight) {
ResourceTypeFlyweight typeKey = (ResourceTypeFlyweight) key;
if (typeKey.isSingleton()) {
nodeData = resources.get(0);
} else {
boolean isDupResourceTypeName = dupResourceTypeNames.contains(typeKey.getName());
nodeData = new AutoGroupCompositeFlyweight(avail, parentResource, typeKey, resources.size(),
isDupResourceTypeName);
}
}
ResourceTreeNode node = new ResourceTreeNode(nodeData, parentNode);
load(node);
if (!recursivelyLocked(node)) {
parentNode.getChildren().add(node);
}
}
} else {
// #####################################################################################
AutoGroupCompositeFlyweight compositeParent = (AutoGroupCompositeFlyweight) parentNode.getData();
Map<Object, List<ResourceFlyweight>> children = new HashMap<Object, List<ResourceFlyweight>>();
log.debug("composite parent" + compositeParent);
if (compositeParent != null) {
MembersCategoryHint membersCategory = MembersCategoryHint.NONE;
MembersAvailabilityHint membersAvailabilityHint = MembersAvailabilityHint.UP;
for (ResourceFlyweight res : compositeParent.getParentResource().getChildResources()) {
boolean process = false;
if (compositeParent.getSubcategory() != null) {
// parent is a sub category
if (res.getResourceType().getSubCategory() != null
//BZ1069545 This functionality is no longer needed since portal-war is no longer needed.
//&& compositeParent.getSubcategory().equals(
// res.getResourceType().getSubCategory().getParentSubCategory())
&& compositeParent.getParentResource().equals(res.getParentResource())) {
// A subSubCategory in a subcategory
addToList(children, res.getResourceType().getSubCategory(), res);
process = true;
} else if (compositeParent.getSubcategory().equals(res.getResourceType().getSubCategory())
&& compositeParent.getParentResource().equals(res.getParentResource())) {
// Direct entries in a subcategory... now group them by autogroup (type)
addToList(children, res.getResourceType(), res);
process = true;
}
} else if (compositeParent.getResourceType() != null) {
if (compositeParent.getResourceType().equals(res.getResourceType())
&& compositeParent.getParentResource().getId() == res.getParentResource().getId()) {
addToList(children, res.getResourceType(), res);
process = true;
}
}
if (process) {
//amend the overall category of all the members of the auto group.
switch (membersCategory) {
case NONE: //this is the first child, so let's use its category as a starting point
membersCategory = MembersCategoryHint.fromResourceCategory(res.getResourceType()
.getCategory());
break;
case MIXED: //this is the "final" state. The children type is not going to change from this.
break;
default: //check if this child has the same category as its previous siblings.
if (MembersCategoryHint.fromResourceCategory(res.getResourceType().getCategory()) != membersCategory) {
membersCategory = MembersCategoryHint.MIXED;
}
}
//amend the availability hint of the autogroup. If all resources are up, the hint is UP, if some of the resources
//are down, the hint is DOWN, if some of the resources' avail state is unknown, the hint is UNKNOWN.
//The down state has the highest priority.
switch (membersAvailabilityHint) {
case UP:
membersAvailabilityHint = MembersAvailabilityHint.fromAvailabilityType(res
.getCurrentAvailability().getAvailabilityType());
break;
case UNKNOWN:
if (res.getCurrentAvailability().getAvailabilityType() == AvailabilityType.DOWN) {
membersAvailabilityHint = MembersAvailabilityHint.DOWN;
}
break;
case DOWN:
; //a "terminal" state... if some resource is down, the overall state is going to be down as that is the most important information.
}
}
}
compositeParent.setMembersCategoryHint(membersCategory);
compositeParent.setMembersAvailabilityHint(membersAvailabilityHint);
}
AutoGroupCompositeFlyweight compositeParentNode = (AutoGroupCompositeFlyweight) parentNode.getData();
for (Map.Entry<Object, List<ResourceFlyweight>> entry : children.entrySet()) {
Object key = entry.getKey();
List<ResourceFlyweight> resources = entry.getValue();
if (compositeParentNode.getSubcategory() != null) {
double avail = 0;
for (ResourceFlyweight res : resources) {
avail += res.getCurrentAvailability().getAvailabilityType() == AvailabilityType.UP ? 1 : 0;
}
avail = avail / resources.size();
Object nodeData = null;
if (key instanceof String) {
nodeData = new AutoGroupCompositeFlyweight(avail, compositeParent.getParentResource(),
(String) key, resources.size());
} else if (key instanceof ResourceTypeFlyweight) {
ResourceTypeFlyweight typeKey = (ResourceTypeFlyweight) key;
if (typeKey.isSingleton()) {
nodeData = resources.get(0);
} else {
nodeData = new AutoGroupCompositeFlyweight(avail, compositeParent.getParentResource(),
typeKey, resources.size(), false);
}
}
ResourceTreeNode node = new ResourceTreeNode(nodeData, parentNode);
load(node);