Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Guillaume on September 21, 2015, 04:39:16 pm
-
Hi,
I'm working on an add'in that carries recursive updates on a package or element and its subelements.
Having the Security and/or Version Control configured on the opened project, I need to prevent the recursive job if an element is locked.
I test the Locked property on a selected element so that can be prevented for a selected element, if it is locked.
However is there an easy and efficient way to test if a package/element or one of its subelements is locked, in which case we don't process anything.
I could run a foreach element / package in package until an element is locked, but this doesn't sound like an efficient way to go...
I guess a SQL query might be better? Surely this must be a recurring issue to sort for add'ins.
Thanks
-
Hi Guillaume,
Yes, you could use an SQL query to figure it out.
Since the EA model is a tree I would use a recursive approach
- Suppose you start at PackageA
- Use a query to find all locks for elements in the package. Something like
select o.ea_guid from t_object o
join t_seclocks s on o.ea_guid = s.EntityID
where o.Package_ID = 123
union
select d.ea_guid from t_diagram d
join t_seclocks s on d.ea_guid = s.EntityID
where d.Package_ID = 123- Do the same for all sub-packages.
That will get you all the locks, but it doesn't mean they are read-only.
We use Require User Lock to edit, and i use this code to figure out if an element is read-only:
/// <summary>
/// returns true if this element is readonly
/// </summary>
/// <returns>true if this element is readonly</returns>
public override bool isReadOnly()
{
if (this.isLocked())
{
string SQLQuery = @"select s.UserID from t_seclocks s
where s.entityID = '" + this.getGUID() + "'";
XmlDocument result = ((EAModel)this.model).SQLQuery(SQLQuery);
XmlNode userIDNode = result.SelectSingleNode("//UserID");
if (userIDNode.InnerText.Equals(((EAModel)this.model).getWrappedModel().GetCurrentLoginUser(true), StringComparison.InvariantCultureIgnoreCase))
return false;
}
//else
return true;
}IsLocked() looks like this:
/// <summary>
/// returns true if currently locked
/// </summary>
/// <returns>true if currently locked</returns>
public override bool isLocked()
{
return (this.getLockedUser() != string.Empty);
}and getLockedUser() finally does this:
/// <summary>
/// returns the name of the user currently locking this element
/// </summary>
/// <returns>the name of the user currently locking this element</returns>
public override string getLockedUser()
{
string lockedUser = string.Empty;
//if (this.wrappedElement.Locked)
//{
string SQLQuery = @"select u.FirstName, u.Surname from t_seclocks s
inner join t_secuser u on s.userID = u.userID
where s.entityID = '" + this.getGUID() + "'";
XmlDocument result = ((EAModel)this.model).SQLQuery(SQLQuery);
XmlNode firstNameNode = result.SelectSingleNode("//FirstName");
XmlNode lastNameNode = result.SelectSingleNode("//Surname");
if (firstNameNode != null && lastNameNode != null)
{
lockedUser = firstNameNode.InnerText + " " + lastNameNode.InnerText;
}
//}
return lockedUser;
}
-
Thanks Geert! :)
I'll try it out.
-
Hi Geert,
I figured out that I need to address both version control and EA security. I started with the VC considering a package cannot be processed if I get one of the following: csCheckedIn, csReadOnlyVersion, csCheckedOutToAnotherUser, csCheckedOutOfflineByOther
I started testing a Package VC status with the method VersionControlGetStatus(). To make things easier, I'd like to test it against values from the enumeration EnumCheckOutStatus (see Package help page).
I cannot find this enum from EA API. So I attempted to create a similar enum but comparison with the method returned values don't work.
Has anyone successfully used the Check Out Statut enum values?
public enum EA_EnumCheckOutStatus
{
csUncontrolled = 0,
csCheckedIn = 1,
csCheckedOutToThisUser = 2,
csReadOnlyVersion = 3,
csCheckedOutToAnotherUser = 4,
csOfflineCheckedIn = 5,
csCheckedOutOfflineByUser = 6,
csCheckedOutOfflineByOther = 7,
csDeleted = 8
};