From: <dcr...@hy...> - 2010-02-19 01:00:28
|
Author: dcrutchf Date: 2010-02-18 15:55:45 -0800 (Thu, 18 Feb 2010) New Revision: 14306 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=14306 Modified: trunk/src/org/hyperic/hq/authz/shared/ResourceOperationsHelper.java trunk/src/org/hyperic/hq/events/server/session/SessionBase.java Log: Made methods on ResourceOperationHelper static Modified: trunk/src/org/hyperic/hq/authz/shared/ResourceOperationsHelper.java =================================================================== --- trunk/src/org/hyperic/hq/authz/shared/ResourceOperationsHelper.java 2010-02-18 17:42:01 UTC (rev 14305) +++ trunk/src/org/hyperic/hq/authz/shared/ResourceOperationsHelper.java 2010-02-18 23:55:45 UTC (rev 14306) @@ -36,7 +36,7 @@ private static List operationsList; - public ResourceOperationsHelper() { + static { // ArrayList containing all the operations for each resource type... // ORDER IS IMPORTANT! operationsList = new ArrayList(48); @@ -88,74 +88,74 @@ operationsList.add(AuthzConstants.escOpModifyEscalation); operationsList.add(AuthzConstants.escOpRemoveEscalation); operationsList.add(null); - operationsList.add(null); + operationsList.add(null); } - - public String getOperationName(int resourceTypeCode, int operationCode) { + + public static String getOperationName(int resourceTypeCode, int operationCode) { return (String) operationsList.get(resourceTypeCode + operationCode); } - public String getCreateOperation(Resource resource) + public static String getCreateOperation(Resource resource) throws IllegalArgumentException { return getOperation(resource, CREATE); } - public String getReadOperation(Resource resource) + public static String getReadOperation(Resource resource) throws IllegalArgumentException { return getOperation(resource, READ); } - public String getUpdateOperation(Resource resource) + public static String getUpdateOperation(Resource resource) throws IllegalArgumentException { return getOperation(resource, UPDATE); } - public String getDeleteOperation(Resource resource) + public static String getDeleteOperation(Resource resource) throws IllegalArgumentException { return getOperation(resource, DELETE); } - public String getManageAlertOperation(Resource resource) + public static String getManageAlertOperation(Resource resource) throws IllegalArgumentException { return getOperation(resource, MANAGE_ALERTS); } - public String getManageControlOperation(Resource resource) + public static String getManageControlOperation(Resource resource) throws IllegalArgumentException { return getOperation(resource, MANAGE_CONTROLS); } - public String getCreateOperation(int resourceTypeId) + public static String getCreateOperation(int resourceTypeId) throws IllegalArgumentException { return getOperation(resourceTypeId, CREATE); } - public String getReadOperation(int resourceTypeId) + public static String getReadOperation(int resourceTypeId) throws IllegalArgumentException { return getOperation(resourceTypeId, READ); } - public String getUpdateOperation(int resourceTypeId) + public static String getUpdateOperation(int resourceTypeId) throws IllegalArgumentException { return getOperation(resourceTypeId, UPDATE); } - public String getDeleteOperation(int resourceTypeId) + public static String getDeleteOperation(int resourceTypeId) throws IllegalArgumentException { return getOperation(resourceTypeId, DELETE); } - public String getManageAlertOperation(int resourceTypeId) + public static String getManageAlertOperation(int resourceTypeId) throws IllegalArgumentException { return getOperation(resourceTypeId, MANAGE_ALERTS); } - public String getManageControlOperation(int resourceTypeId) + public static String getManageControlOperation(int resourceTypeId) throws IllegalArgumentException { return getOperation(resourceTypeId, MANAGE_CONTROLS); } - public String getResourceType(Resource resource) + public static String getResourceType(Resource resource) throws IllegalArgumentException, UnsupportedOperationException { if (resource == null || resource.getResourceType() == null) { throw new IllegalArgumentException("resource must be not be null and must have a valid resource type."); @@ -166,7 +166,7 @@ return getResourceType(resourceTypeId); } - public String getResourceType(int resourceTypeId) + public static String getResourceType(int resourceTypeId) throws IllegalArgumentException, UnsupportedOperationException { switch (resourceTypeId) { case AppdefEntityConstants.APPDEF_TYPE_PLATFORM: @@ -182,14 +182,14 @@ } } - private String getOperation(Resource resource, int operationCode) + private static String getOperation(Resource resource, int operationCode) throws IllegalArgumentException { int resourceTypeId = resource.getResourceType().getId().intValue(); return getOperation(resourceTypeId, operationCode); } - private String getOperation(int resourceTypeId, int operationCode) + private static String getOperation(int resourceTypeId, int operationCode) throws IllegalArgumentException { int resourceTypeCode; @@ -217,7 +217,7 @@ return getOperationName(resourceTypeCode, operationCode); } - public CodePair getResourceTypeOperationCodePair(String operationName) { + public static CodePair getResourceTypeOperationCodePair(String operationName) { int index = operationsList.indexOf(operationName); int resourceTypeCode = ((index < MULTIPLIER) ? 0 : index/MULTIPLIER) * MULTIPLIER; int operationCode = index - resourceTypeCode; @@ -225,7 +225,7 @@ return new CodePair(resourceTypeCode, operationCode); } - public class CodePair { + public static class CodePair { int resourceTypeCode; int operationCode; Modified: trunk/src/org/hyperic/hq/events/server/session/SessionBase.java =================================================================== --- trunk/src/org/hyperic/hq/events/server/session/SessionBase.java 2010-02-18 17:42:01 UTC (rev 14305) +++ trunk/src/org/hyperic/hq/events/server/session/SessionBase.java 2010-02-18 23:55:45 UTC (rev 14306) @@ -164,8 +164,6 @@ return ResourceManagerEJBImpl.getOne().findResource(id); } - private static ResourceOperationsHelper resourceOperationsHelper = new ResourceOperationsHelper(); - public static void canViewResourceTypeAlertDefinitionTemplate(AuthzSubject user) throws PermissionException { // ...right now, you have to be a member of the super user's role to do anything with @@ -210,14 +208,14 @@ throws PermissionException { // ...we need to check the resource associated with the alert definition to determine // if the user can view the alert definition. Must have read permission on resource... - checkAlertDefinitionPermission(user, entityId, resourceOperationsHelper.getReadOperation(entityId.getType())); + checkAlertDefinitionPermission(user, entityId, ResourceOperationsHelper.getReadOperation(entityId.getType())); } public static void canModifyAlertDefinition(AuthzSubject user, AppdefEntityID entityId) throws PermissionException { // ...we need to check the resource associated with the alert definition to determine // if the user can modify the alert definition. Must have modify permission on resource... - checkAlertDefinitionPermission(user, entityId, resourceOperationsHelper.getUpdateOperation(entityId.getType())); + checkAlertDefinitionPermission(user, entityId, ResourceOperationsHelper.getUpdateOperation(entityId.getType())); } public static void canCreateAlertDefinition(AuthzSubject user, AppdefEntityID entityId) @@ -226,7 +224,7 @@ // if the user can modify the alert definition. Must have modify permission on resource... // TODO ...If we introduce finer grained permission for Alert definition, we can make the change here // and the rest should just work... - checkAlertDefinitionPermission(user, entityId, resourceOperationsHelper.getUpdateOperation(entityId.getType())); + checkAlertDefinitionPermission(user, entityId, ResourceOperationsHelper.getUpdateOperation(entityId.getType())); } public static void canDeleteAlertDefinition(AuthzSubject user, AppdefEntityID entityId) @@ -235,7 +233,7 @@ // if the user can modify the alert definition. Must have modify permission on resource... // TODO ...If we introduce finer grained permission for Alert definition, we can make the change here // and the rest should just work... - checkAlertDefinitionPermission(user, entityId, resourceOperationsHelper.getUpdateOperation(entityId.getType())); + checkAlertDefinitionPermission(user, entityId, ResourceOperationsHelper.getUpdateOperation(entityId.getType())); } private static void checkAlertDefinitionPermission(AuthzSubject user, AppdefEntityID id, String operationName) @@ -303,9 +301,9 @@ // ...then check if we have fix/acknowledge permissions on alert... checkPermission(user.getId(), - resourceOperationsHelper.getResourceType(resourceTypeId), + ResourceOperationsHelper.getResourceType(resourceTypeId), entityId.getId(), - resourceOperationsHelper.getManageAlertOperation(resourceTypeId)); + ResourceOperationsHelper.getManageAlertOperation(resourceTypeId)); } } |