RequestUtils.setError(request, "resource.group.inventory.error.GroupTypeIsRequired");
return returnFailure(request, mapping);
}
ResourceTypeManagerLocal resourceTypeManager = LookupUtil.getResourceTypeManager();
ResourceGroupManagerLocal resourceGroupManager = LookupUtil.getResourceGroupManager();
ResourceGroup newGroup = new ResourceGroup(newGroupName);
try {
if (category == GroupCategory.COMPATIBLE) {
ResourceType groupResourceType = resourceTypeManager.getResourceTypeById(subject, resourceTypeId);
newGroup.setResourceType(groupResourceType);
}
} catch (ResourceTypeNotFoundException ex) {
log.debug("group created failed: ", ex);
RequestUtils.setError(request, "resource.group.inventory.error.ResourceTypeIdNotFound");
return returnFailure(request, mapping);
}
String location = newForm.getLocation();
String description = newForm.getDescription();
boolean recursive = newForm.isRecursive();
try {
newGroup.setDescription(description);
//newGroup.setLocation(location);
newGroup.setRecursive(recursive);
log.trace("creating group [" + newForm.getName() + "]" + " with attributes " + newForm);
// ctime, mtime, and modifiedBy should all be persistence hooks
resourceGroupManager.createResourceGroup(subject, newGroup);
} catch (Throwable t) {
log.debug("group creation failed: ", t);
RequestUtils.setError(request, "resource.group.inventory.error.GroupCreateError", t.getMessage());
return returnFailure(request, mapping);
}
// Check for resources
int groupId = newGroup.getId();
Integer[] newResourceIds = newForm.getResourceIds();
if ((newResourceIds != null) && (newResourceIds.length > 0)) {
// Clean up after ourselves first
HttpSession session = request.getSession();
session.removeAttribute(Constants.RESOURCE_IDS_ATTR);
session.removeAttribute(Constants.RESOURCE_TYPE_ATTR);
// Now add the new entities to group
resourceGroupManager.addResourcesToGroup(subject, groupId, ArrayUtils.unwrapArray(newResourceIds));
}
RequestUtils.setConfirmation(request, "resource.group.inventory.confirm.CreateGroup", newGroupName);
HashMap<String, Object> forwardParams = new HashMap<String, Object>(2);