Index: packages/security/authorisation.cfc
===================================================================
RCS file: /cvs/farcry/farcry_core/packages/security/authorisation.cfc,v
retrieving revision 1.37
diff -u -r1.37 authorisation.cfc
--- packages/security/authorisation.cfc	2 Jun 2004 01:26:47 -0000	1.37
+++ packages/security/authorisation.cfc	10 Jun 2004 19:01:02 -0000
@@ -306,33 +306,53 @@
 			stPolicyGroup = getPolicyGroup(policyGroupName=arguments.policyGroupName);
 			stPolicyStore = getPolicyStore();
 			stResult = structNew();
-			if (NOT structIsEmpty(stPolicyGroup))
-			{
+		</cfscript>
+		<cfif NOT structIsEmpty(stPolicyGroup)>
+			<cfscript>
 				stResult.bSuccess = false;
-				stResult.message = "Policy Group already exists";
-			}
-			else
-			{
-				switch (application.dbType)
-				{
-					case "ora":
-					{
-						sql = "
-							INSERT INTO #application.dbowner##stPolicyStore.PolicyGroupTable# (policyGroupID, policyGroupName,policyGroupNotes )
+				stResult.message = "Policy Group already exists";			
+			</cfscript>		
+		<cfelse>	
+			<cfswitch expression="#application.dbType#">	
+				<cfcase value="ora">
+					<!--- clean up the dmpolicygroup_seq --->
+					<cftransaction>
+						<cftry>
+						<cfquery name="q" datasource="#stPolicyStore.datasource#">
+							INSERT INTO 
+								#application.dbowner##stPolicyStore.PolicyGroupTable# 
+								(	policyGroupID, 
+									policyGroupName,
+									policyGroupNotes 
+								)
 							VALUES
-							(DMPOLICYGROUP_SEQ.nextval,'#arguments.PolicyGroupName#','#arguments.PolicyGroupNotes#')";
-						break;	
-					}
-					case "postgresql":
-					{
-						sql = "
-							INSERT INTO #application.dbowner##stPolicyStore.PolicyGroupTable# ( policyGroupName,policyGroupNotes )
-							VALUES
-							('#arguments.PolicyGroupName#','#arguments.PolicyGroupNotes#')";
-						break;	
-					}
-					case "mysql":
-					{
+								(
+									<cfif isDefined("arguments.policyGroupID")>#arguments.policyGroupId#<cfelse>DMPOLICYGROUP_SEQ.nextval</cfif>,
+									'#arguments.PolicyGroupName#',
+									'#arguments.PolicyGroupNotes#'
+								)								
+						</cfquery>
+						<cfif isDefined("arguments.policyGroupID")>
+							<cfquery name="getMaxID" datasource="#stPolicyStore.datasource#">
+								SELECT MAX (policyGroupID) AS MaxID
+								FROM #application.dbowner##stPolicyStore.PolicyGroupTable#
+							</cfquery>
+							<cfquery name="dropSequence" datasource="#stPolicyStore.datasource#">
+								DROP SEQUENCE DMPOLICYGROUP_SEQ
+							</cfquery>
+							<cfquery name="createSequence" datasource="#stPolicyStore.datasource#">
+								CREATE SEQUENCE DMPOLICYGROUP_SEQ MINVALUE #Val(getMaxID.MaxID + 1)#
+							</cfquery>	
+						</cfif>
+							<cfcatch>
+								<cftransaction action="ROLLBACK">
+								<cfset bSuccess = false>
+							</cfcatch>
+						</cftry>
+					</cftransaction>			
+				</cfcase>
+				<cfcase value="mysql">
+					<cfscript>
 						sql = "
 						INSERT INTO #application.dbowner##stPolicyStore.PolicyGroupTable# ( policyGroupName,policyGroupNotes ";
 						if (isDefined("arguments.policyGroupId"))
@@ -343,11 +363,12 @@
 						if (isDefined("arguments.policyGroupId"))
 							sql = sql & ",#arguments.policyGroupId#";
 						sql = sql & ")";	
-						break;	
-					}
-					
-					default:
-					{
+						query(sql=sql,dsn=stPolicyStore.datasource);
+						bSuccess = true;
+					</cfscript>				
+				</cfcase>
+				<cfdefaultcase>
+					<cfscript>
 						sql = "
 						INSERT INTO #application.dbowner##stPolicyStore.PolicyGroupTable# ( policyGroupName,policyGroupNotes ";
 						if (isDefined("arguments.policyGroupId"))
@@ -358,21 +379,26 @@
 						if (isDefined("arguments.policyGroupId"))
 							sql = sql & ",#arguments.policyGroupId#";
 						sql = sql & ")";	
-					}
+						query(sql=sql,dsn=stPolicyStore.datasource);
+						bSuccess = true;
+					</cfscript>
+				</cfdefaultcase>
+			</cfswitch>	
+			<cfscript>
+				if (bSuccess) {
+					stResult.bSuccess = true;
+					stResult.message = "Policy group successfully added";
+					oAuthentication = createObject("component","#application.securitypackagepath#.authentication");
+					oAudit = createObject("component","#application.packagepath#.farcry.audit");
+					stuser = oAuthentication.getUserAuthenticationData();
+						if(stUser.bLoggedIn)
+							oaudit.logActivity(auditType="dmSec.createPolicyGroup", username=Stuser.userlogin, location=cgi.remote_host, note="policy group #arguments.policygroupname# created");	
+				} else {
+					stResult.bSuccess = false;
+					stResult.message = "Policy Group not added";				
 				}
-
-				query(sql=sql,dsn=stPolicyStore.datasource);
-				stResult.bSuccess = true;
-				stResult.message = "Policy group successfully added";
-				oAuthentication = createObject("component","#application.securitypackagepath#.authentication");
-				oAudit = createObject("component","#application.packagepath#.farcry.audit");
-				stuser = oAuthentication.getUserAuthenticationData();
-					if(stUser.bLoggedIn)
-						oaudit.logActivity(auditType="dmSec.createPolicyGroup", username=Stuser.userlogin, location=cgi.remote_host, note="policy group #arguments.policygroupname# created");	
-
-			}
-				
-		</cfscript>
+			</cfscript>
+		</cfif>
 		<cfreturn stResult>
 	</cffunction>
 	
