Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1368 lines
32 KiB

  1. -- Script: uddi.v2.publisher.sql
  2. -- Author: [email protected]
  3. -- Description: Stored procedures associated with a publisher
  4. -- Note: This file is best viewed and edited with a tab width of 2.
  5. -- =============================================
  6. -- Section: Authentication routines
  7. -- =============================================
  8. -- =============================================
  9. -- Name: net_publisher_isRegistered
  10. -- =============================================
  11. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_publisher_isRegistered' AND type = 'P')
  12. DROP PROCEDURE net_publisher_isRegistered
  13. GO
  14. CREATE PROCEDURE net_publisher_isRegistered
  15. @PUID nvarchar(450)
  16. WITH ENCRYPTION
  17. AS
  18. BEGIN
  19. DECLARE
  20. @flag int
  21. IF dbo.publisherExists(@PUID) = 0
  22. RETURN 10150
  23. RETURN 0
  24. END
  25. GO
  26. -- =============================================
  27. -- Name: net_publisher_isVerified
  28. -- =============================================
  29. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_publisher_isVerified' AND type = 'P')
  30. DROP PROCEDURE net_publisher_isVerified
  31. GO
  32. CREATE PROCEDURE net_publisher_isVerified
  33. @PUID nvarchar(450)
  34. WITH ENCRYPTION
  35. AS
  36. BEGIN
  37. DECLARE
  38. @flag int
  39. IF dbo.publisherExists(@PUID) = 0
  40. RETURN 10150
  41. SELECT
  42. @flag = [flag]
  43. FROM
  44. UDO_publishers
  45. WHERE
  46. PUID = @PUID
  47. IF ((@flag & 0x01) <> 0x01)
  48. RETURN 50013
  49. RETURN 0
  50. END
  51. GO
  52. -- =============================================
  53. -- Name: net_publisher_login
  54. -- =============================================
  55. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_publisher_login' AND type = 'P')
  56. DROP PROCEDURE net_publisher_login
  57. GO
  58. CREATE PROCEDURE net_publisher_login
  59. @PUID nvarchar(450),
  60. @email nvarchar(100) OUTPUT,
  61. @name nvarchar(100) OUTPUT,
  62. @phone varchar(20) OUTPUT,
  63. @companyName nvarchar(100) OUTPUT,
  64. @altPhone varchar(20) OUTPUT,
  65. @addressLine1 nvarchar(4000) OUTPUT,
  66. @addressLine2 nvarchar(4000) OUTPUT,
  67. @city nvarchar(100) OUTPUT,
  68. @stateProvince nvarchar(100) OUTPUT,
  69. @postalCode nvarchar(100) OUTPUT,
  70. @country nvarchar(100) OUTPUT,
  71. @isoLangCode varchar(17) OUTPUT,
  72. @businessLimit int OUTPUT,
  73. @businessCount int OUTPUT,
  74. @tModelLimit int OUTPUT,
  75. @tModelCount int OUTPUT,
  76. @serviceLimit int OUTPUT,
  77. @bindingLimit int OUTPUT,
  78. @assertionLimit int OUTPUT,
  79. @assertionCount int OUTPUT
  80. WITH ENCRYPTION
  81. AS
  82. BEGIN
  83. DECLARE
  84. @oldEmail nvarchar(100),
  85. @publisherStatus nvarchar(256),
  86. @error int,
  87. @context nvarchar(4000),
  88. @flag int,
  89. @publisherID bigint
  90. -- Verify the publisher exists
  91. SET @publisherID = dbo.publisherID(@PUID)
  92. IF (@publisherID IS NULL)
  93. BEGIN
  94. SET @error = 60150 -- E_unknownUser
  95. SET @context = 'Unknown publisher, email ''' + @email + ''''
  96. GOTO errorLabel
  97. END
  98. -- Get the publisher data
  99. SELECT
  100. @publisherStatus = dbo.publisherStatus([publisherStatusID]),
  101. @oldEmail = [email],
  102. @flag = [flag]
  103. FROM
  104. [UDO_publishers]
  105. WHERE
  106. ([publisherID] = @publisherID)
  107. -- Determine which email validation mode we are in.
  108. -- 0 = track Passport
  109. -- 1 = custom email validation
  110. IF ((@flag & 0x02) = 0x02)
  111. BEGIN
  112. -- We're using custom validation (i.e. not tracking the Passport
  113. -- email address), so we'll ignore the @email input parameter and
  114. -- make sure they have validated through our custom validation.
  115. IF ((@flag & 0x01) = 0x00)
  116. BEGIN
  117. -- User has not validated their email address.
  118. SET @error = 60150 -- E_unknownUser
  119. SET @context = 'Email address has not yet been validated.'
  120. GOTO errorLabel
  121. END
  122. SET @email = @oldEmail
  123. END
  124. ELSE
  125. BEGIN
  126. -- We are tracking Passport, so make sure a valid email address
  127. -- was displayed.
  128. IF (@email IS NULL)
  129. BEGIN
  130. SET @error = 60150 -- E_unknownUser
  131. SET @context = 'Your Passport profile information is not shared. Please change your email options on the registration page or change your Passport profile to share your email address with this site.'
  132. GOTO errorLabel
  133. END
  134. SET @flag = (@flag | 0x01)
  135. END
  136. IF (@publisherStatus = 'disabled')
  137. BEGIN
  138. SET @error = 50013 -- E_userDisabled
  139. SET @context = 'Account disabled for publisher.'
  140. GOTO errorLabel
  141. END
  142. -- Only update the publisher record if the email has changed
  143. IF (ISNULL(@email,'') <> ISNULL(@oldEmail,''))
  144. BEGIN
  145. UPDATE
  146. [UDO_publishers]
  147. SET
  148. [email] = @email,
  149. [flag] = @flag
  150. WHERE
  151. [publisherID] = @publisherID
  152. END
  153. -- Return the publisher details
  154. SELECT
  155. @name = PU.[name],
  156. @email = PU.[email],
  157. @phone = PU.[phone],
  158. @companyName = PU.[companyName],
  159. @altPhone = PU.[altPhone],
  160. @addressLine1 = PU.[addressLine1],
  161. @addressLine2 = PU.[addressLine2],
  162. @city = PU.[city],
  163. @stateProvince = PU.[stateProvince],
  164. @postalCode = PU.[postalCode],
  165. @country = PU.[country],
  166. @isoLangCode = PU.[isoLangCode],
  167. @businessLimit = PU.[businessLimit],
  168. @businessCount = (SELECT COUNT(*) FROM [UDC_businessEntities] BE WITH (READUNCOMMITTED) WHERE BE.[publisherID] = @publisherID),
  169. @tModelLimit = PU.[tModelLimit],
  170. @tModelCount = (SELECT COUNT(*) FROM [UDC_tModels] TM WITH (READUNCOMMITTED) WHERE TM.[publisherID] = @publisherID),
  171. @serviceLimit = PU.[serviceLimit],
  172. @bindingLimit = PU.[bindingLimit],
  173. @assertionLimit = PU.[assertionLimit],
  174. @assertionCount = (SELECT COUNT(*) FROM [UDC_assertions_BE] ASS WITH (READUNCOMMITTED) JOIN [UDC_businessEntities] BE WITH (READUNCOMMITTED) ON ASS.[fromKey] = BE.[businessKey] WHERE BE.[publisherID] = @publisherID)
  175. FROM
  176. [UDO_publishers] PU
  177. WHERE
  178. ([publisherID] = @publisherID)
  179. RETURN 0
  180. errorLabel:
  181. RAISERROR (@error, 16, 1, @context)
  182. RETURN 1
  183. END -- net_publisher_login
  184. GO
  185. -- =============================================
  186. -- Section: Get routines
  187. -- =============================================
  188. -- =============================================
  189. -- Name: net_publisher_businessInfos_get
  190. -- =============================================
  191. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_publisher_businessInfos_get' and type = 'P')
  192. DROP PROCEDURE net_publisher_businessInfos_get
  193. GO
  194. CREATE PROCEDURE net_publisher_businessInfos_get
  195. @PUID nvarchar(450)
  196. WITH ENCRYPTION
  197. AS
  198. BEGIN
  199. DECLARE
  200. @error int,
  201. @context nvarchar(4000),
  202. @publisherID bigint
  203. -- Validate PUID
  204. SET @publisherID = dbo.publisherID(@PUID)
  205. IF @publisherID IS NULL
  206. BEGIN
  207. SET @error = 60150 -- E_unknownUser
  208. SET @context = 'PUID = ' + @PUID
  209. GOTO errorLabel
  210. END
  211. SELECT
  212. [businessKey]
  213. FROM
  214. [UDC_businessEntities]
  215. WHERE
  216. ([publisherID] = @publisherID)
  217. RETURN 0
  218. errorLabel:
  219. RAISERROR (@error, 16, 1, @context)
  220. RETURN 1
  221. END -- net_publisher_businessInfos_get
  222. GO
  223. -- =============================================
  224. -- Name: net_publisher_tModelInfos_get
  225. -- =============================================
  226. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_publisher_tModelInfos_get' and type = 'P')
  227. DROP PROCEDURE net_publisher_tModelInfos_get
  228. GO
  229. CREATE PROCEDURE net_publisher_tModelInfos_get
  230. @PUID nvarchar(450)
  231. WITH ENCRYPTION
  232. AS
  233. BEGIN
  234. DECLARE
  235. @error int,
  236. @context nvarchar(4000),
  237. @publisherID bigint
  238. -- Validate PUID
  239. SET @publisherID = dbo.publisherID(@PUID)
  240. IF @publisherID IS NULL
  241. BEGIN
  242. SET @error = 60150 -- E_unknownUser
  243. SET @context = 'PUID = ' + @PUID
  244. GOTO errorLabel
  245. END
  246. SELECT
  247. [tModelKey],
  248. [name],
  249. [flag]
  250. FROM
  251. [UDC_tModels]
  252. WHERE
  253. ([publisherID] = @publisherID)
  254. RETURN 0
  255. errorLabel:
  256. RAISERROR (@error, 16, 1, @context)
  257. RETURN 1
  258. END -- net_publisher_tModelInfos_get
  259. GO
  260. -- =============================================
  261. -- Name: net_pubOperator_get
  262. -- =============================================
  263. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_pubOperator_get' AND type = 'P')
  264. DROP PROCEDURE net_pubOperator_get
  265. GO
  266. CREATE PROCEDURE net_pubOperator_get
  267. @publisherID bigint,
  268. @operatorID bigint OUTPUT,
  269. @replActive bit = 0 OUTPUT
  270. WITH ENCRYPTION
  271. AS
  272. BEGIN
  273. DECLARE
  274. @error int,
  275. @context nvarchar(4000)
  276. SET @replActive = 0
  277. -- Validate operator / publisher association (replication only)
  278. IF @publisherID IN (SELECT [publisherID] FROM [UDO_operators])
  279. BEGIN
  280. SET @replActive = 1
  281. IF @operatorID IS NULL
  282. BEGIN
  283. SELECT
  284. @operatorID = [operatorID]
  285. FROM
  286. [UDO_operators]
  287. WHERE
  288. ([publisherID] = @publisherID)
  289. END
  290. IF NOT EXISTS(SELECT * FROM [UDO_operators] WHERE [operatorID] = @operatorID AND [publisherID] = @publisherID)
  291. BEGIN
  292. SET @error = 60130 -- E_operatorMismatch
  293. SET @context = 'Operator ''' + dbo.operatorName(@operatorID) + 'and PUID ''' + dbo.PUID(@publisherID) + ''' are not associated.'
  294. GOTO errorLabel
  295. END
  296. END
  297. ELSE
  298. BEGIN
  299. IF @operatorID IS NULL
  300. SET @operatorID = dbo.currentOperatorID()
  301. END
  302. RETURN 0
  303. errorLabel:
  304. RAISERROR (@error, 16, 1, @context)
  305. RETURN 1
  306. END -- net_pubOperator_get
  307. GO
  308. -- =============================================
  309. -- Section: Find routines
  310. -- =============================================
  311. -- =============================================
  312. -- Name: net_find_publisher_name
  313. -- =============================================
  314. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_find_publisher_name' and type = 'P')
  315. DROP PROCEDURE net_find_publisher_name
  316. GO
  317. CREATE PROCEDURE net_find_publisher_name
  318. @contextID uniqueidentifier,
  319. @name nvarchar(450),
  320. @rows int OUTPUT
  321. WITH ENCRYPTION
  322. AS
  323. BEGIN
  324. DECLARE
  325. @error int,
  326. @context nvarchar(4000),
  327. @contextRows int,
  328. @wildCardSarg nvarchar(451)
  329. DECLARE @tempIDs TABLE(
  330. [publisherID] bigint,
  331. [name] nvarchar(450))
  332. SET @contextRows = (SELECT COUNT(*) FROM [UDS_pubResults] WHERE [contextID] = @contextID)
  333. --
  334. -- Do a wildcard search (default)
  335. --
  336. SET @wildCardSarg = @name
  337. IF dbo.containsWildcard(@name) = 0
  338. SET @wildCardSarg = @wildCardSarg + N'%'
  339. IF @contextRows = 0
  340. BEGIN
  341. INSERT INTO @tempIDs(
  342. [publisherID],
  343. [name])
  344. SELECT
  345. [publisherID],
  346. [name]
  347. FROM
  348. [UDO_publishers]
  349. WHERE
  350. ([name] LIKE @wildCardSarg)
  351. END
  352. ELSE
  353. BEGIN
  354. INSERT INTO @tempIDs(
  355. [publisherID],
  356. [name])
  357. SELECT
  358. [publisherID],
  359. [name]
  360. FROM
  361. [UDO_publishers]
  362. WHERE
  363. ([publisherID] IN (SELECT [publisherID] FROM [UDS_pubResults] WHERE ([contextID] = @contextID))) AND
  364. ([name] LIKE @wildCardSarg)
  365. END
  366. INSERT [UDS_pubResults] (
  367. [contextID],
  368. [publisherID])
  369. SELECT DISTINCT
  370. @contextID,
  371. [publisherID]
  372. FROM
  373. @tempIDs
  374. SET @rows = @@ROWCOUNT
  375. RETURN 0
  376. errorLabel:
  377. RAISERROR (@error, 16, 1, @context)
  378. RETURN 1
  379. END -- net_find_publisher_name
  380. GO
  381. -- =============================================
  382. -- Name: net_find_publisher_email
  383. -- =============================================
  384. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_find_publisher_email' and type = 'P')
  385. DROP PROCEDURE net_find_publisher_email
  386. GO
  387. CREATE PROCEDURE net_find_publisher_email
  388. @contextID uniqueidentifier,
  389. @email nvarchar(450),
  390. @rows int OUTPUT
  391. WITH ENCRYPTION
  392. AS
  393. BEGIN
  394. DECLARE
  395. @error int,
  396. @context nvarchar(4000),
  397. @contextRows int,
  398. @wildCardSarg nvarchar(451)
  399. DECLARE @tempIDs TABLE(
  400. [publisherID] bigint,
  401. [email] nvarchar(450))
  402. SET @contextRows = (SELECT COUNT(*) FROM [UDS_pubResults] WHERE [contextID] = @contextID)
  403. --
  404. -- Do a wildcard search (default)
  405. --
  406. SET @wildCardSarg = @email
  407. IF dbo.containsWildcard(@email) = 0
  408. SET @wildCardSarg = @wildCardSarg + N'%'
  409. IF @contextRows = 0
  410. BEGIN
  411. INSERT INTO @tempIDs(
  412. [publisherID],
  413. [email])
  414. SELECT
  415. [publisherID],
  416. [email]
  417. FROM
  418. [UDO_publishers]
  419. WHERE
  420. ([email] LIKE @wildCardSarg)
  421. END
  422. ELSE
  423. BEGIN
  424. INSERT INTO @tempIDs(
  425. [publisherID],
  426. [email])
  427. SELECT
  428. [publisherID],
  429. [email]
  430. FROM
  431. [UDO_publishers]
  432. WHERE
  433. ([publisherID] IN (SELECT [publisherID] FROM [UDS_pubResults] WHERE ([contextID] = @contextID))) AND
  434. ([email] LIKE @wildCardSarg)
  435. END
  436. INSERT [UDS_pubResults] (
  437. [contextID],
  438. [publisherID])
  439. SELECT DISTINCT
  440. @contextID,
  441. [publisherID]
  442. FROM
  443. @tempIDs
  444. SET @rows = @@ROWCOUNT
  445. RETURN 0
  446. errorLabel:
  447. RAISERROR (@error, 16, 1, @context)
  448. RETURN 1
  449. END -- net_find_publisher_email
  450. GO
  451. -- =============================================
  452. -- Name: net_find_publisher_companyName
  453. -- =============================================
  454. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_find_publisher_companyName' and type = 'P')
  455. DROP PROCEDURE net_find_publisher_companyName
  456. GO
  457. CREATE PROCEDURE net_find_publisher_companyName
  458. @contextID uniqueidentifier,
  459. @companyName nvarchar(100),
  460. @rows int OUTPUT
  461. WITH ENCRYPTION
  462. AS
  463. BEGIN
  464. DECLARE
  465. @error int,
  466. @context nvarchar(4000),
  467. @contextRows int,
  468. @wildCardSarg nvarchar(451)
  469. DECLARE @tempIDs TABLE(
  470. [publisherID] bigint,
  471. [companyName] nvarchar(100))
  472. SET @contextRows = (SELECT COUNT(*) FROM [UDS_pubResults] WHERE [contextID] = @contextID)
  473. --
  474. -- Do a wildcard search (default)
  475. --
  476. SET @wildCardSarg = @companyName
  477. IF dbo.containsWildcard(@companyName) = 0
  478. SET @wildCardSarg = @wildCardSarg + N'%'
  479. IF @contextRows = 0
  480. BEGIN
  481. INSERT INTO @tempIDs(
  482. [publisherID],
  483. [companyName])
  484. SELECT
  485. [publisherID],
  486. [companyName]
  487. FROM
  488. [UDO_publishers]
  489. WHERE
  490. ([companyName] LIKE @wildCardSarg)
  491. END
  492. ELSE
  493. BEGIN
  494. INSERT INTO @tempIDs(
  495. [publisherID],
  496. [companyName])
  497. SELECT
  498. [publisherID],
  499. [companyName]
  500. FROM
  501. [UDO_publishers]
  502. WHERE
  503. ([publisherID] IN (SELECT [publisherID] FROM [UDS_pubResults] WHERE ([contextID] = @contextID))) AND
  504. ([companyName] LIKE @wildCardSarg)
  505. END
  506. INSERT [UDS_pubResults] (
  507. [contextID],
  508. [publisherID])
  509. SELECT DISTINCT
  510. @contextID,
  511. [publisherID]
  512. FROM
  513. @tempIDs
  514. SET @rows = @@ROWCOUNT
  515. RETURN 0
  516. errorLabel:
  517. RAISERROR (@error, 16, 1, @context)
  518. RETURN 1
  519. END -- net_find_publisher_companyName
  520. GO
  521. -- =============================================
  522. -- Name: net_find_publisher_cleanup
  523. -- =============================================
  524. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_find_publisher_cleanup' AND type = 'P')
  525. DROP PROCEDURE net_find_publisher_cleanup
  526. GO
  527. CREATE PROCEDURE net_find_publisher_cleanup
  528. @contextID uniqueidentifier
  529. WITH ENCRYPTION
  530. AS
  531. BEGIN
  532. -- Cleans up leftover rows in scratch table
  533. DELETE
  534. [UDS_pubResults]
  535. WHERE
  536. ([contextID] = @contextID)
  537. RETURN 0
  538. END -- net_find_publisher_cleanup
  539. GO
  540. -- =============================================
  541. -- Name: net_find_publisher_commit
  542. -- =============================================
  543. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_find_publisher_commit' AND type = 'P')
  544. DROP PROCEDURE net_find_publisher_commit
  545. GO
  546. CREATE PROCEDURE net_find_publisher_commit
  547. @contextID uniqueidentifier,
  548. @sortByNameAsc bit = 1,
  549. @sortByEmailAsc bit = 0,
  550. @sortByCompanyNameAsc bit = 0
  551. WITH ENCRYPTION
  552. AS
  553. BEGIN
  554. DECLARE
  555. @error int,
  556. @context nvarchar(4000),
  557. @contextRows int
  558. SET @contextRows = (SELECT COUNT(*) FROM [UDS_pubResults] WHERE [contextID] = @contextID)
  559. IF @contextRows = 0
  560. RETURN 0
  561. DECLARE @tempIDs TABLE (
  562. [seqNo] bigint IDENTITY PRIMARY KEY ,
  563. [publisherID] bigint,
  564. [PUID] nvarchar(450) NULL,
  565. [name] nvarchar(450) NULL,
  566. [email] nvarchar(450) NULL,
  567. [companyName] nvarchar(100) NULL)
  568. -- Set default sorting option
  569. IF (@sortByNameAsc = 0) AND (@sortByEmailAsc = 0) AND (@sortByCompanyNameAsc = 0)
  570. SET @sortByNameAsc = 1
  571. -- sortByNameAsc
  572. IF (@sortByNameAsc = 1)
  573. BEGIN
  574. INSERT @tempIDs(
  575. [publisherID],
  576. [PUID],
  577. [name],
  578. [email],
  579. [companyName])
  580. SELECT DISTINCT
  581. PR.[publisherID],
  582. PU.[PUID],
  583. PU.[name],
  584. PU.[email],
  585. PU.[companyName]
  586. FROM
  587. [UDS_pubResults] PR
  588. JOIN [UDO_publishers] PU ON PR.[publisherID] = PU.[publisherID]
  589. WHERE
  590. (PR.[contextID] = @contextID)
  591. ORDER BY
  592. 3 ASC
  593. GOTO endLabel
  594. END
  595. -- sortByEmailAsc
  596. IF (@sortByEmailAsc = 1)
  597. BEGIN
  598. INSERT @tempIDs(
  599. [publisherID],
  600. [PUID],
  601. [name],
  602. [email],
  603. [companyName])
  604. SELECT DISTINCT
  605. PR.[publisherID],
  606. PU.[PUID],
  607. PU.[name],
  608. PU.[email],
  609. PU.[companyName]
  610. FROM
  611. [UDS_pubResults] PR
  612. JOIN [UDO_publishers] PU ON PR.[publisherID] = PU.[publisherID]
  613. WHERE
  614. (PR.[contextID] = @contextID)
  615. ORDER BY
  616. 4 ASC
  617. GOTO endLabel
  618. END
  619. -- sortByCompanyNameAsc
  620. IF (@sortByCompanyNameAsc = 1)
  621. BEGIN
  622. INSERT @tempIDs(
  623. [publisherID],
  624. [PUID],
  625. [name],
  626. [email],
  627. [companyName])
  628. SELECT DISTINCT
  629. PR.[publisherID],
  630. PU.[PUID],
  631. PU.[name],
  632. PU.[email],
  633. PU.[companyName]
  634. FROM
  635. [UDS_pubResults] PR
  636. JOIN [UDO_publishers] PU ON PR.[publisherID] = PU.[publisherID]
  637. WHERE
  638. (PR.[contextID] = @contextID)
  639. ORDER BY
  640. 5 ASC
  641. GOTO endLabel
  642. END
  643. endLabel:
  644. -- Return results
  645. SELECT
  646. [PUID],
  647. [email],
  648. [name],
  649. [companyName]
  650. FROM
  651. @tempIDs
  652. -- Run cleanup
  653. EXEC net_find_publisher_cleanup @contextID
  654. RETURN 0
  655. errorLabel:
  656. RAISERROR (@error, 16, 1, @context)
  657. RETURN 1
  658. END -- net_find_publisher_commit
  659. GO
  660. -- =============================================
  661. -- Section: Publisher assertions
  662. -- =============================================
  663. -- =============================================
  664. -- Name: net_publisher_assertion_save
  665. -- =============================================
  666. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_publisher_assertion_save' and type = 'P')
  667. DROP PROCEDURE net_publisher_assertion_save
  668. GO
  669. CREATE PROCEDURE net_publisher_assertion_save
  670. @PUID nvarchar(450),
  671. @fromKey uniqueidentifier,
  672. @toKey uniqueidentifier,
  673. @tModelKey uniqueidentifier,
  674. @keyName nvarchar(225),
  675. @keyValue nvarchar(225),
  676. @flag int OUTPUT
  677. WITH ENCRYPTION
  678. AS
  679. BEGIN
  680. DECLARE
  681. @error int,
  682. @context nvarchar(4000),
  683. @publisherID bigint,
  684. @completionStatus int,
  685. @rows int,
  686. @keyOwnership int
  687. SET @publisherID = dbo.publisherID(@PUID)
  688. IF @publisherID IS NULL
  689. BEGIN
  690. SET @error = 60140
  691. SET @context = 'Unknown publisher.'
  692. GOTO errorLabel
  693. END
  694. -- Check for required parameters
  695. IF (@fromKey IS NULL)
  696. BEGIN
  697. SET @error=60050 -- E_unsupported
  698. SET @context='fromKey is required'
  699. GOTO errorLabel
  700. END
  701. IF (@toKey IS NULL)
  702. BEGIN
  703. SET @error=60050 -- E_unsupported
  704. SET @context='toKey is required'
  705. GOTO errorLabel
  706. END
  707. IF (@keyName IS NULL)
  708. BEGIN
  709. SET @error=60050 -- E_unsupported
  710. SET @context='keyName is required'
  711. GOTO errorLabel
  712. END
  713. IF (@keyValue IS NULL)
  714. BEGIN
  715. SET @error=60050 -- E_unsupported
  716. SET @context='keyValue is required'
  717. GOTO errorLabel
  718. END
  719. IF (@tModelKey IS NULL)
  720. BEGIN
  721. SET @error=60050 -- E_unsupported
  722. SET @context='tModelKey is required'
  723. GOTO errorLabel
  724. END
  725. -- Check to see if tModelKey is a valid tModelKey
  726. IF NOT EXISTS(SELECT * FROM [UDC_tModels] WHERE [tModelKey] = @tModelKey)
  727. BEGIN
  728. SET @error = 60210 -- E_invalidKey
  729. SET @context = ' Invalid tModelKey=' + dbo.UUIDSTR(@tModelKey)
  730. GOTO errorLabel
  731. END
  732. -- Check to see if fromKey is a valid business key
  733. IF NOT EXISTS(SELECT * FROM [UDC_businessEntities] WHERE [businessKey] = @fromKey)
  734. BEGIN
  735. SET @error = 60210 -- E_invalidKey
  736. SET @context = ' Invalid fromKey=' + dbo.UUIDSTR(@fromKey)
  737. GOTO errorLabel
  738. END
  739. -- Check to see if toKey is a valid business key
  740. IF NOT EXISTS(SELECT * FROM [UDC_businessEntities] WHERE [businessKey] = @toKey)
  741. BEGIN
  742. SET @error = 60210 -- E_invalidKey
  743. SET @context = ' Invalid toKey=' + dbo.UUIDSTR(@toKey)
  744. GOTO errorLabel
  745. END
  746. -- We want to determine what keys this publisher owns. @keyOwnership = 0 if the publisher does not own any
  747. -- any keys, 0x2 if it owns the fromKey, 0x1 if it owns the toKey and 0x3 if it owns both keys.
  748. -- Check to see if the publisher owns the fromKey
  749. SET @keyOwnership = 0
  750. IF EXISTS(SELECT * FROM [UDC_businessEntities] WHERE [businessKey] = @fromKey AND [publisherID] = @publisherID)
  751. SET @keyOwnership = @keyOwnership | 0x2
  752. -- Check to see if the publisher owns the toKey
  753. IF EXISTS(SELECT * FROM [UDC_businessEntities] WHERE [businessKey] = @toKey AND [publisherID] = @publisherID)
  754. SET @keyOwnership = @keyOwnership | 0x1
  755. -- If the owner does not own either key, then it is an error
  756. IF @keyOwnership = 0
  757. BEGIN
  758. SET @error = 60140 -- E_userMismatch
  759. SET @context = 'Publisher must own at least one of the businesses involved in a publisher assertion (fromKey=''' + dbo.UUIDSTR(@fromKey) + ''', toKey=''' + dbo.UUIDSTR(@toKey) + ''', tModelKey=''' + dbo.UUIDSTR(@tModelKey) + ''', keyName=''' + @keyName + ''', keyValue=''' + @keyValue + ''')'
  760. GOTO errorLabel
  761. END
  762. -- @flag is the status of the assertion as passed in by the caller.
  763. IF @flag IS NULL
  764. BEGIN
  765. -- If @flag is NULL, then we should determine the status based on key ownership.
  766. -- If the caller owns the formKey, the status of this assertion is set to status:toKey_incomplete (2). If the caller owns the toKey, the status of the assertion is set to
  767. -- status:fromKey_incomplete (1). If the caller owns both keys, then the status is set to status:complete (3).
  768. SET @completionStatus = @keyOwnership
  769. END
  770. ELSE
  771. BEGIN
  772. -- The caller has specified a status value for this assertion. This will usually happen we this assertion is being saved during
  773. -- a replication cycle. We have to make sure that the key ownership is compatible with the flag passed. Unless the publisher
  774. -- owns both keys, @flag and @keyOwnership have to be of the same value.
  775. IF @flag <> @keyOwnership AND @keyOwnership <> 0x3
  776. BEGIN
  777. SET @error = 60140 -- E_userMismatch
  778. -- Note that varchar(15) is just a safe choice of size; @flag should only ever be a single digit integer.
  779. SET @context = 'This publisher is not allowed to save this assertion in this state: ' + CAST(@flag AS varchar(15)) + '.'
  780. GOTO errorLabel
  781. END
  782. SET @completionStatus = @flag
  783. END
  784. -- At this point, @completionStatus now holds the status of this assertion that we are saving.
  785. -- Check to see if the assertion already exists.
  786. SELECT
  787. @rows = COUNT(*)
  788. FROM
  789. [UDC_assertions_BE]
  790. WHERE
  791. ([fromKey] = @fromKey) AND
  792. ([tModelKey] = @tModelKey) AND
  793. ([keyName] = @keyName) AND
  794. ([keyValue] = @keyValue) AND
  795. ([toKey] = @toKey)
  796. IF @rows = 0
  797. BEGIN
  798. -- Add the new assertion
  799. INSERT [UDC_assertions_BE](
  800. [fromKey],
  801. [toKey],
  802. [tModelKey],
  803. [keyName],
  804. [keyValue],
  805. [flag])
  806. VALUES(
  807. @fromKey,
  808. @toKey,
  809. @tModelKey,
  810. @keyName,
  811. @keyValue,
  812. @completionStatus)
  813. END
  814. ELSE
  815. BEGIN
  816. -- Update the existing assertion
  817. UPDATE
  818. [UDC_assertions_BE]
  819. SET
  820. [flag] = [flag] | @completionStatus
  821. WHERE
  822. ([fromKey] = @fromKey) AND
  823. ([tModelKey] = @tModelKey) AND
  824. ([keyValue] = @keyValue) AND
  825. ([keyName] = @keyName) AND
  826. ([toKey] = @toKey)
  827. END
  828. SET @flag = @completionStatus
  829. RETURN 0
  830. errorLabel:
  831. RAISERROR (@error, 16, 1, @context)
  832. RETURN 1
  833. END -- net_publisher_assertion_save
  834. GO
  835. -- =============================================
  836. -- Name: net_publisher_assertion_delete
  837. -- =============================================
  838. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_publisher_assertion_delete' and type = 'P')
  839. DROP PROCEDURE net_publisher_assertion_delete
  840. GO
  841. CREATE PROCEDURE net_publisher_assertion_delete
  842. @PUID nvarchar(450),
  843. @fromKey uniqueidentifier,
  844. @toKey uniqueidentifier,
  845. @tModelKey uniqueidentifier,
  846. @keyName nvarchar(225),
  847. @keyValue nvarchar(225),
  848. @flag int OUTPUT
  849. WITH ENCRYPTION
  850. AS
  851. BEGIN
  852. DECLARE
  853. @error int,
  854. @context nvarchar(4000),
  855. @publisherID bigint,
  856. @completionStatus int,
  857. @rows int,
  858. @keyOwnership int
  859. SET @publisherID = dbo.publisherID(@PUID)
  860. IF @publisherID IS NULL
  861. BEGIN
  862. SET @error = 60150 -- E_unknownUser
  863. SET @context = 'Unknown publisher.'
  864. GOTO errorLabel
  865. END
  866. -- Make sure the assertion exists
  867. SELECT
  868. @rows = COUNT(*)
  869. FROM
  870. [UDC_assertions_BE]
  871. WHERE
  872. ([fromKey] = @fromKey) AND
  873. ([tModelKey] = @tModelKey) AND
  874. ([keyValue] = @keyValue) AND
  875. ([toKey] = @toKey)
  876. IF @rows = 0
  877. BEGIN
  878. SET @error = 80000 -- E_assertionNotFound
  879. SET @context = 'Publisher assertion not found (fromKey=''' + dbo.UUIDSTR(@fromKey) + ''', toKey=''' + dbo.UUIDSTR(@toKey) + ''', tModelKey=''' + dbo.UUIDSTR(@tModelKey) + ''', keyName=''' + @keyName + ''', keyValue=''' + @keyValue + ''')'
  880. GOTO errorLabel
  881. END
  882. -- We want to determine what keys this publisher owns. @keyOwnership = 0 if the publisher does not own any
  883. -- any keys, 0x2 if it owns the fromKey, 0x1 if it owns the toKey and 0x3 if it owns both keys.
  884. -- Check to see if the publisher owns the fromKey
  885. SET @keyOwnership = 0
  886. IF EXISTS(SELECT * FROM [UDC_businessEntities] WHERE [businessKey] = @fromKey AND [publisherID] = @publisherID)
  887. SET @keyOwnership = @keyOwnership | 0x2
  888. -- Check to see if the publisher owns the toKey
  889. IF EXISTS(SELECT * FROM [UDC_businessEntities] WHERE [businessKey] = @toKey AND [publisherID] = @publisherID)
  890. SET @keyOwnership = @keyOwnership | 0x1
  891. -- If the owner does not own either key, then it is an error
  892. IF @keyOwnership = 0
  893. BEGIN
  894. SET @error = 60140 -- E_userMismatch
  895. SET @context = 'Publisher must own at least one of the businesses involved in a publisher assertion (fromKey=''' + dbo.UUIDSTR(@fromKey) + ''', toKey=''' + dbo.UUIDSTR(@toKey) + ''', tModelKey=''' + dbo.UUIDSTR(@tModelKey) + ''', keyName=''' + @keyName + ''', keyValue=''' + @keyValue + ''')'
  896. GOTO errorLabel
  897. END
  898. -- @flag represents the side that the caller wants to delete
  899. IF @flag IS NULL
  900. BEGIN
  901. SET @completionStatus = @keyOwnership
  902. END
  903. ELSE
  904. BEGIN
  905. -- The caller has specified what side that they want to delete. This will usually happen when this assertion is being deleted
  906. -- during a replication cycle. We have to make sure that the key ownership is compatible with the side the user wants to delete.
  907. -- Unless the publisher owns both keys, @flag and @keyOwnership have to be of the same value.
  908. IF @flag <> @keyOwnership AND @keyOwnership <> 0x3
  909. BEGIN
  910. SET @error = 60140 -- E_userMismatch
  911. -- Note that varchar(15) is just a safe choice of size; @flag should only ever be a single digit integer.
  912. SET @context = 'This publisher is not allowed to set this assertion to this state: ' + CAST(@flag AS varchar(15)) + '.'
  913. GOTO errorLabel
  914. END
  915. SET @completionStatus = @flag
  916. END
  917. -- Get the assertion completion status flag
  918. SELECT
  919. @flag = [flag]
  920. FROM
  921. [UDC_assertions_BE]
  922. WHERE
  923. ([fromKey] = @fromKey) AND
  924. ([tModelKey] = @tModelKey) AND
  925. ([keyValue] = @keyValue) AND
  926. ([toKey] = @toKey)
  927. -- Check to see if we have to remove the assertion completely or just update it
  928. IF (@flag = @completionStatus) OR (@completionStatus = 0x3 AND @keyOwnership = 0x3)
  929. BEGIN
  930. -- Remove the assertion from the database completely
  931. DELETE
  932. [UDC_assertions_BE]
  933. WHERE
  934. ([fromKey] = @fromKey) AND
  935. ([tModelKey] = @tModelKey) AND
  936. ([keyValue] = @keyValue) AND
  937. ([toKey] = @toKey)
  938. END
  939. ELSE
  940. BEGIN
  941. -- If the assertion is not complete, the wrong publisher must be trying to delete this assertion, so throw an error
  942. IF @flag <> 0x3 AND @keyOwnership <> 0x3
  943. BEGIN
  944. SET @error = 60140 -- E_userMismatch
  945. SET @context = 'This publisher is not allowed to delete this assertion.'
  946. GOTO errorLabel
  947. END
  948. -- Remove the publisher's portion of the assertion
  949. UPDATE
  950. [UDC_assertions_BE]
  951. SET
  952. [flag] = @flag & (~@completionStatus)
  953. WHERE
  954. ([fromKey] = @fromKey) AND
  955. ([tModelKey] = @tModelKey) AND
  956. ([keyValue] = @keyValue) AND
  957. ([toKey] = @toKey)
  958. END
  959. SET @flag = @completionStatus
  960. RETURN 0
  961. errorLabel:
  962. RAISERROR (@error, 16, 1, @context)
  963. RETURN 1
  964. END -- net_publisher_assertion_delete
  965. GO
  966. -- =============================================
  967. -- Name: net_publisher_assertions_get
  968. -- =============================================
  969. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_publisher_assertions_get' and type = 'P')
  970. DROP PROCEDURE net_publisher_assertions_get
  971. GO
  972. CREATE PROCEDURE net_publisher_assertions_get
  973. @PUID nvarchar(450),
  974. @authorizedName nvarchar(4000) OUTPUT
  975. WITH ENCRYPTION
  976. AS
  977. BEGIN
  978. DECLARE
  979. @error int,
  980. @context nvarchar(4000),
  981. @publisherID bigint
  982. DECLARE @report TABLE(
  983. [seqNo] bigint,
  984. [fromKey] uniqueidentifier,
  985. [toKey] uniqueidentifier,
  986. [keyName] nvarchar(225),
  987. [keyValue] nvarchar(225),
  988. [tModelKey] uniqueidentifier)
  989. SET @publisherID = dbo.publisherID(@PUID)
  990. IF @publisherID IS NULL
  991. BEGIN
  992. SET @error = 60140
  993. SET @context = 'Unknown publisher.'
  994. GOTO errorLabel
  995. END
  996. SET @authorizedName = dbo.publisherName(@publisherID)
  997. INSERT @report(
  998. [seqNo],
  999. [fromKey],
  1000. [toKey],
  1001. [keyName],
  1002. [keyValue],
  1003. [tModelKey])
  1004. SELECT
  1005. PA.[seqNo],
  1006. PA.[fromKey],
  1007. PA.[toKey],
  1008. PA.[keyName],
  1009. PA.[keyValue],
  1010. PA.[tModelKey]
  1011. FROM
  1012. [UDC_assertions_BE] PA
  1013. JOIN [UDC_businessEntities] BE ON PA.[fromKey] = BE.[businessKey]
  1014. WHERE
  1015. (BE.[publisherID] = @publisherID) AND
  1016. (PA.[flag] & 0x2 = 0x2)
  1017. UNION ALL
  1018. SELECT
  1019. PA.[seqNo],
  1020. PA.[fromKey],
  1021. PA.[toKey],
  1022. PA.[keyName],
  1023. PA.[keyValue],
  1024. PA.[tModelKey]
  1025. FROM
  1026. [UDC_assertions_BE] PA
  1027. JOIN [UDC_businessEntities] BE ON PA.[toKey] = BE.[businessKey]
  1028. WHERE
  1029. (BE.[publisherID] = @publisherID) AND
  1030. (PA.[flag] & 0x1 = 0x1)
  1031. SELECT DISTINCT
  1032. [fromKey],
  1033. [toKey],
  1034. [keyName],
  1035. [keyValue],
  1036. [tModelKey],
  1037. [seqNo]
  1038. FROM
  1039. @report
  1040. ORDER BY
  1041. [seqNo] ASC
  1042. RETURN 0
  1043. errorLabel:
  1044. RAISERROR (@error, 16, 1, @context)
  1045. RETURN 1
  1046. END -- net_publisher_assertions_get
  1047. GO
  1048. -- =============================================
  1049. -- Name: net_publisher_assertionStatus_get
  1050. -- =============================================
  1051. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_publisher_assertionStatus_get' and type = 'P')
  1052. DROP PROCEDURE net_publisher_assertionStatus_get
  1053. GO
  1054. CREATE PROCEDURE net_publisher_assertionStatus_get
  1055. @PUID nvarchar(450),
  1056. @completionStatus int = NULL
  1057. WITH ENCRYPTION
  1058. AS
  1059. BEGIN
  1060. DECLARE
  1061. @error int,
  1062. @context nvarchar(4000),
  1063. @publisherID int
  1064. DECLARE @report TABLE(
  1065. [fromKey] uniqueidentifier,
  1066. [toKey] uniqueidentifier,
  1067. [keyName] nvarchar(225),
  1068. [keyValue] nvarchar(225),
  1069. [tModelKey] uniqueidentifier,
  1070. [flag] int,
  1071. [seqNo] bigint)
  1072. SET @publisherID = dbo.publisherID(@PUID)
  1073. IF @publisherID IS NULL
  1074. BEGIN
  1075. SET @error = 60140
  1076. SET @context = 'Unknown publisher.'
  1077. GOTO errorLabel
  1078. END
  1079. IF @completionStatus IS NULL
  1080. BEGIN
  1081. -- Get all assertions for this publisher regardless of completionStatus
  1082. INSERT @report(
  1083. [fromKey],
  1084. [toKey],
  1085. [keyName],
  1086. [keyValue],
  1087. [tModelKey],
  1088. [flag],
  1089. [seqNo])
  1090. SELECT
  1091. PA.[fromKey],
  1092. PA.[toKey],
  1093. PA.[keyName],
  1094. PA.[keyValue],
  1095. PA.[tModelKey],
  1096. PA.[flag],
  1097. PA.[seqNo]
  1098. FROM
  1099. [UDC_assertions_BE] PA
  1100. JOIN [UDC_businessEntities] BE ON PA.[fromKey] = BE.[businessKey]
  1101. WHERE
  1102. (BE.[publisherID] = @publisherID)
  1103. UNION ALL
  1104. SELECT
  1105. PA.[fromKey],
  1106. PA.[toKey],
  1107. PA.[keyName],
  1108. PA.[keyValue],
  1109. PA.[tModelKey],
  1110. PA.[flag],
  1111. PA.[seqNo]
  1112. FROM
  1113. [UDC_assertions_BE] PA
  1114. JOIN [UDC_businessEntities] BE ON PA.[toKey] = BE.[businessKey]
  1115. WHERE
  1116. (BE.[publisherID] = @publisherID)
  1117. END
  1118. ELSE
  1119. BEGIN
  1120. -- Get all assertions for this publisher for a specific completionStatus
  1121. INSERT @report(
  1122. [fromKey],
  1123. [toKey],
  1124. [keyName],
  1125. [keyValue],
  1126. [tModelKey],
  1127. [flag],
  1128. [seqNo])
  1129. SELECT
  1130. PA.[fromKey],
  1131. PA.[toKey],
  1132. PA.[keyName],
  1133. PA.[keyValue],
  1134. PA.[tModelKey],
  1135. PA.[flag],
  1136. PA.[seqNo]
  1137. FROM
  1138. [UDC_assertions_BE] PA
  1139. JOIN [UDC_businessEntities] BE ON PA.[fromKey] = BE.[businessKey]
  1140. WHERE
  1141. (BE.[publisherID] = @publisherID) AND
  1142. (PA.[flag] = @completionStatus)
  1143. UNION ALL
  1144. SELECT
  1145. PA.[fromKey],
  1146. PA.[toKey],
  1147. PA.[keyName],
  1148. PA.[keyValue],
  1149. PA.[tModelKey],
  1150. PA.[flag],
  1151. PA.[seqNo]
  1152. FROM
  1153. [UDC_assertions_BE] PA
  1154. JOIN [UDC_businessEntities] BE ON PA.[toKey] = BE.[businessKey]
  1155. WHERE
  1156. (BE.[publisherID] = @publisherID) AND
  1157. (PA.[flag] = @completionStatus)
  1158. END
  1159. SELECT DISTINCT
  1160. [fromKey],
  1161. [toKey],
  1162. [keyName],
  1163. [keyValue],
  1164. [tModelKey],
  1165. [flag],
  1166. dbo.ownerFlag(@publisherID,[fromKey],[toKey]) AS [ownerFlag],
  1167. [seqNo]
  1168. FROM
  1169. @report
  1170. ORDER BY
  1171. 8 ASC
  1172. RETURN 0
  1173. errorLabel:
  1174. RAISERROR (@error, 16, 1, @context)
  1175. RETURN 1
  1176. END -- net_publisher_assertionStatus_get
  1177. GO