Controlling addition of files in the second level directory of RTC Components
Hi,
Can you please anyone help the below requirement?
Should be restricting access on adding file/folder under the directory of RTC components from Source Control ???
I require, User should be allowed to add some files or a folder on only the second level directory of components under particular streams.
Here my code describes,
- The condition applies for all the streams which prefixed "RTC",
- If the changeSet has a list of changes, filters add operation using change.kind() method
- Display the alert message, when the "before" state of the item is null using IVersionableHandle interface method change.beforeState();
if
(streamName.startsWith("RTC") && !isAuthorizedApprover){
while
(changeSetIterator.hasNext()) {
IChangeSet changeSet = (IChangeSet) changeSetIterator.next();
if (changeSet == null)
continue;
}
for (IChange change : (List<IChange>) changeSet.changes()) {
ServiceConfigurationProvider configProvider = ServiceConfigurationProvider.FACTORY.create(
data.getDestWorkspace(), changeSet.getComponent());
if (change.kind() == IChange.ADD) {
IVersionableHandle versionableHandle = change.beforeState();
IVersionable item = (IVersionable) scmService.fetchState(versionableHandle, null, null);
IAncestorReport reports[] = scmService.configurationLocateAncestors(configProvider,new IVersionableHandle[] {versionableHandle}, null, null);
if(versionableHandle == null){
IAdvisorInfo info = collector.createProblemInfo(
"Adding file "+ toFullPath(item, reports[0].getNameItemPairs())+" in this level of directory is strictly prohibited",
"Please contact Integration team to add the files/folder in this second level directory structure on the RTC components",
"error");
collector.addInfo(info);
}
}
I am getting the Exception "IVersionableHandle must have stateId"
Please help on resolving this......
Thanks
Sudar
One answer
Comments
Hi Martin,
Thanks for your response !
As per the description given for the IVersionableHandle interface,
beforeState():
Returns the "before" state of the versionable item, or
null
if the change is the addition of a versionable item to the configuration.
Always returns
null
for an addition. For a modification, returns non-
null
.
- Returns:
-
the "before" state of the versionable item, or
null
if the change is an addition
afterState():
Returns the "after" state of the versionable item, or
null
if the change is the deletion of a versionable item from the configuration.
Always returns
null
for a deletion. For a modification or addition, always returns non-
null
.
- Returns:
-
the "after" state of the versionable item, or
null
if the change is a deletion
So i want to catch the state when versionHandle is null on beforeState(), so that it restrict addition of files.
Am i correct?
Hi,
null
, or both non-
null
with equivalent item and state identifiers. This may occur when a user resolves a conflict with "mine". The before state is the same as the after. The change is relevant because it represents what happened during the merge but nothing really happened.
You'll want the after state as Martin said. The before state in an addition will always be null. You're fetching the full item for the before state but never checking if it is null. You're getting that error because the argument is either null or is a versionable handle with no state id.
Ok Thanks Tim !!!
Thank you all for the favour !!