Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 4.60 KB | None | 0 0
  1. USE [SG_UTNet4_Sprint_11_Tune]
  2. GO
  3.  
  4. /****** Object:  StoredProcedure [utbio].[DeleteEnrollmentData]    Script Date: 3/24/2017 11:34:26 AM ******/
  5. DROP PROCEDURE [utbio].[DeleteEnrollmentData]
  6. GO
  7.  
  8. /****** Object:  StoredProcedure [utbio].[DeleteEnrollmentData]    Script Date: 3/24/2017 11:34:26 AM ******/
  9. SET ANSI_NULLS ON
  10. GO
  11.  
  12. SET QUOTED_IDENTIFIER ON
  13. GO
  14.  
  15. -- =============================================
  16. -- Author:      Boris Kostadinov
  17. -- Create date: 26.11.2013
  18. -- Last update author: Ognjan Ognjanoski
  19. -- Last update date: 28.07.2015
  20. -- Description: Used to delete the biometrics data from a client file.
  21. -- Version:     1.3
  22. -- =============================================
  23. CREATE PROCEDURE [utbio].[DeleteEnrollmentData]
  24.     @ImplementationID nvarchar(50),
  25.     @UserProfileID bigint,
  26.     @UseDeleteAuthorization bit,
  27.     @UserIPAddress nvarchar(46),
  28.     @ClientFileID bigint,
  29.     @BiometricsDataTypeID nchar(1) = 'P', -- add in 1.3
  30.     @DeleteReason nvarchar(200),
  31.     @Result bigint OUTPUT,
  32.     @ResultMessage nvarchar(max) OUTPUT
  33. AS
  34. BEGIN
  35.     SET NOCOUNT ON;
  36.  
  37.     DECLARE
  38.         @BiometricsDataID bigint,
  39.         @UserCanModify bit,
  40.         @ActivityDetails nvarchar(max)
  41.  
  42.     IF @ClientFileID != 0 AND EXISTS( SELECT * FROM utbio.tClientFiles WHERE ClientFileID = @ClientFileID AND IsDeleted = 'False' )
  43.     BEGIN
  44.         -- Check the access rights:
  45.         --EXEC utUserManagement.VerifyAccessRight
  46.         --  @UserProfileID = @UserProfileID,
  47.         --  @ImplementationID = @ImplementationID,
  48.         --  @UserIPAddress = @UserIPAddress,
  49.         --  @AccessRightCode = 'BDE',
  50.         --  @ProtectedObjectRef = NULL,
  51.         --  @Result = @UserCanModify OUTPUT;
  52.            
  53.         --IF @UserCanModify = 'True'
  54.         --BEGIN
  55.             BEGIN TRAN DeleteEnrollmentData
  56.  
  57.             BEGIN TRY
  58.                 SELECT @BiometricsDataID = BiometricsDataID FROM utbio.tBiometricsData WHERE ClientFileID = @ClientFileID AND IsDeleted = 'False' AND BiometricsTypeID = @BiometricsDataTypeID
  59.  
  60.                 IF @BiometricsDataID IS NOT NULL
  61.                 BEGIN
  62.                     IF @UseDeleteAuthorization = 1 -- Check for is there a Delete Authorization for the implementation
  63.                     BEGIN
  64.                    
  65.                     Insert into utbio.tDeleteAuthorizations
  66.                     values( @BiometricsDataID, GETDATE(), @UserProfileID, @DeleteReason, 0, null, null )
  67.                    
  68.                     -- Add log entry:
  69.                     SET @ActivityDetails = '<Details><Description>' + CASE
  70.                         WHEN @DeleteReason IS NULL OR @DeleteReason = '' THEN 'Biometrics fingerprint data send for delete authorization by user.'
  71.                         ELSE 'Biometrics fingerprint data send for delete authorization by user with reason: ' + @DeleteReason END + '</Description></Details>';
  72.  
  73.                     EXEC utbio.InsertBiometricsLogEntry
  74.                         @ActivityCodeID = 'BDDL',
  75.                         @ActivityOn = NULL,
  76.                         @ActivityBy = @UserProfileID,
  77.                         @UserIPAddress = @UserIPAddress,
  78.                         @ClientFileID = @ClientFileID,
  79.                         @BiometricsDataID = @BiometricsDataID,
  80.                         @ActivityDetails = @ActivityDetails,
  81.                         @IsSystemAction = 'False'
  82.                    
  83.                     END
  84.                    
  85.                     ELSE -- @UseDeleteAuthorization = 0
  86.                     BEGIN
  87.                    
  88.                     -- Mark this entry as delted:
  89.                     UPDATE utbio.tBiometricsData
  90.                     SET
  91.                         IsDeleted = 'True',
  92.                         DeletedOn = GETDATE(),
  93.                         DeletedBy = @UserProfileID
  94.                     WHERE BiometricsDataID = @BiometricsDataID
  95.  
  96.                     -- Add log entry:
  97.                     SET @ActivityDetails = '<Details><Description>' + CASE
  98.                         WHEN @DeleteReason IS NULL OR @DeleteReason = '' THEN 'Biometrics fingerprint data deleted by user.'
  99.                         ELSE 'Biometrics fingerprint data deleted by user with reason: ' + @DeleteReason END + '</Description></Details>';
  100.  
  101.                     EXEC utbio.InsertBiometricsLogEntry
  102.                         @ActivityCodeID = 'BDDL',
  103.                         @ActivityOn = NULL,
  104.                         @ActivityBy = @UserProfileID,
  105.                         @UserIPAddress = @UserIPAddress,
  106.                         @ClientFileID = @ClientFileID,
  107.                         @BiometricsDataID = @BiometricsDataID,
  108.                         @ActivityDetails = @ActivityDetails,
  109.                         @IsSystemAction = 'False'
  110.                     END
  111.                 END
  112.  
  113.                 SET @Result = 0
  114.                 SET @ResultMessage = 'Successfully deleted biometrics data.'
  115.            
  116.                 COMMIT TRAN DeleteEnrollmentData
  117.             END TRY
  118.             BEGIN CATCH
  119.                 ROLLBACK TRAN DeleteEnrollmentData
  120.  
  121.                 SET @Result = 1
  122.                 SET @ResultMessage = 'SQL error while trying to delete enrollment data!'
  123.        
  124.                 DECLARE
  125.                     @Error int,
  126.                     @Message nvarchar(max)
  127.  
  128.                 SELECT @Error = ERROR_NUMBER(), @Message = ERROR_MESSAGE()
  129.  
  130.                 RAISERROR( 'UTBio_DeleteEnrollmentData: %d - %s', 16, 1, @Error, @Message );
  131.             END CATCH
  132.         --END
  133.         --ELSE
  134.         --BEGIN
  135.         --  SET @Result = 3
  136.         --  SET @ResultMessage = 'User is not allowed to modify client file biometrics data!'
  137.         --END
  138.     END
  139.     ELSE
  140.     BEGIN
  141.         SET @Result = 2
  142.         SET @ResultMessage = 'Client file with the provided ID does not exist!'
  143.     END
  144. END
  145.  
  146. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement