It's all about the answers!

Ask a question

Controlling addition of files in the second level directory of RTC Components


Sudaraazhi Arivalagan (441328) | asked Oct 13 '14, 8:57 a.m.

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



permanent link
Martin Dam Pedersen (1352814) | answered Oct 13 '14, 9:47 a.m.
 Hi, 

The beforestate is null if the change kind is ADD. 

You should try to use the afterstate instead.

Comments
Sudaraazhi Arivalagan commented Oct 13 '14, 9:57 a.m. | edited Oct 15 '14, 10:06 a.m.

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?


Martin Dam Pedersen commented Oct 15 '14, 7:47 a.m. | edited Oct 15 '14, 10:06 a.m.

 Hi,


The kind, beforestate and afterstate are all from the IChange. 

I would say you should look at the change kind, and if its different from delete, check the afterstate to see if it is in the right folder.

Then you also have to consider the delete situation, if you want to avoid the deletion of files in the root folder. Look at the beforestate to see if the file being deleted is in the root folder. If it is in the root folder, let your advisor reject the change.

There are some special cases when merging, where both the afterstate and beforestate are null. The the change kind is NONE. So as you can see it's not enough to just look at the before/afterstate, you also have to take the change kind into consideration.
The javaodc says:
Kind constant indicating the change has equivalent "before" and "after" states. Both states are either both  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.


Tim Mok commented Oct 15 '14, 10:17 a.m.
JAZZ DEVELOPER

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.


Also, you get the before state and fetch the full item but never intend to use the fetched item. You don't need to fetch it because the call to configurationLocateAncestors only requires the versionable handle. In fact, you don't really need to give it a versionable handle that has state. You only want to check that the IChange#kind() is an add. When you calculate the path, you already create the configProvider that will give context for the item's parent folder.


Sudaraazhi Arivalagan commented Oct 16 '14, 3:07 a.m.

Ok Thanks Tim !!!


Sudaraazhi Arivalagan commented Oct 16 '14, 3:08 a.m.

Thank you all for the favour !!

Your answer


Register or to post your answer.