Book a Demo

Author Topic: Applying Auto Names to Elements  (Read 3976 times)

Krayol

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Applying Auto Names to Elements
« on: January 28, 2010, 04:25:52 am »
I've finally persuaded my company to buy a few corporate copies of EA for the department and I've spent a few days now translating an unstructured requirements document for a new product into a very nice EA-based model.

However...I realised only too late that I had no unique names because I hadn't turned the Auto Name Counters on.  :-[

My question of course is...how do I get the numbers/names applied retrospectively to the thousands of elements that I have already created?  

(Hopefully there is a way...? :()

Thanks in advance....Karl.

Chris Tatem

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
Re: Applying Auto Names to Elements
« Reply #1 on: February 02, 2010, 02:49:48 am »
You can try export to CSV, add the numbers through Excel or whatever, then import back to your model - preserving the GUIDs per this.

http://www.sparxsystems.com/uml_tool_guide/uml_model_management/csvimport.html

Then turn auto-name on and set the number to +1 from your highest one to date.


Krayol

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Re: Applying Auto Names to Elements
« Reply #2 on: February 02, 2010, 11:12:13 pm »
Thanks for that Chris.  I didn't do as you suggest but it did get me thinking! :)

Since it was on SQL Server I thought that rather than export/import I might do it 'in situ' through the back end.  So - I wrote this which worked fine (although it's perhaps overcomplicated).  It might help someone else, but if so, replace the prefix patterns and numbers to suit your scenario and try it with the 'Rollback' first! :)

Caveat Emptor of course! - I don't understand EA enough to know if it could break something but it appears ok.


--Let's take care here!
BEGIN TRANSACTION

--Create Table to contain number sequence lookup
CREATE TABLE SequenceLookup(
      PK int NOT NULL IDENTITY PRIMARY KEY,
      Prefix varchar(10),
      MatchValue varchar(1000))

--Set Unused Range: 50 -> 9999 in this case
DBCC CHECKIDENT('SequenceLookup', RESEED, 50)

--Insert range of values letting PK be created for ones missing prefix
-- Make sure pattern only selects the blank ones!

INSERT INTO SequenceLookup(MatchValue)
SELECT Name
  FROM t_object
  WHERE Object_Type = 'Requirement'
  AND NOT Name LIKE 'REQ%:%'

--Generate a Formatted Prefix
UPDATE SequenceLookup
SET Prefix = 'REQ' + Right('0000' + CAST(PK AS varchar(10)), 4) + ': '

--Join and update the original table
UPDATE t_object
SET Name = SL.Prefix + t_object.Name
FROM
      t_object
      INNER JOIN SequenceLookup SL on SL.MatchValue = t_object.Name

---View Results to see last assigned prefix
--to set Auto Name Counter to...

SELECT Name
  FROM t_object
  WHERE Object_Type = 'Requirement'
  ORDER BY Name

--Clean Up
DROP TABLE SequenceLookup

--Run with ROLLBACK here first! :)
COMMIT
« Last Edit: February 02, 2010, 11:14:18 pm by Krayol »

Chris Tatem

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
Re: Applying Auto Names to Elements
« Reply #3 on: February 03, 2010, 12:17:52 am »
Good work - I may borrow this as I would love to assign auto-names based on my stereotypes of Requirements, like Assumptions or other categorizations

Since the auto-number is only using an already supported field that's not a key (as in DB FK), I think you are good to go!  In fact, one downside is you can change these in the Properties...

cwt