UPDATE! The community will be go into read-only on April 19, 8am Pacific in preparation for migration on April 21. Read more.
UPDATE! The community will be go into read-only on April 19, 8am Pacific in preparation for migration on April 21.Read more.
Absent Member.
Absent Member.
1383 views

find shared views of one change request

Jump to solution

how to find views of one change request be shared?

below method don't work. I don't know why.

List<View> getCRSharedViews(ChangeRequest cr) {
if (cr == null) return null;
ViewMemberCollection vmc = cr.getHistory();
List<View> list = new ArrayList<View>();
for (int i = 0; i < vmc.size(); i++) {
ChangeRequest t = (ChangeRequest)vmc.get(i);
Property viewProperty = t.getType().getProperties()
.find(TypedResource.Type.ViewProperty.NAME);
View v = (View) t.getValue(viewProperty);
if (list.indexOf(v) == -1) {
list.add(v);
}
}
return list;
}

0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

Terence,

Are you trying to access the share tree of a Change Request?

You need to use the api getAllShares(); Each returned Share can be walked up (to its parent) or walked down (to its child shares), and the views that the CR is shared into are accessible thusly.

/**

* Returns the shares for this view member.

*

* @return All shares of this view member

*/

public Share[] ViewMember::getAllShares() {

there are several examples in the junit test source, specifically CR 2565, CR4742 & CR5414.

You can get to the full junit source code in a .zip off the ftp site.  ftp://stsdkcust:LpeEFPwNMJ@emeaftp.microfocus.com/st-sdk-14.0-readme.htm

below, i have copied the code cut out from CR4742...

public void testCR4742() throws java.io.IOException {

// Create a conflict situation.

View source = getViewForTest(com.starteam.test.SDKTestCase

.getUniqueName("Source"));

Item sourceCr = makeItem(source.getRootFolder(),

com.starteam.ChangeRequest.Type.NAME);

((ChangeRequest) sourceCr).setSynopsis("Source synopsis.");

sourceCr.update();

View target = source.createChildViewShareAllItems(

com.starteam.test.SDKTestCase.getUniqueName("target"),

"a test", source.getRootFolder(), source.getPath(),

source.getConfiguration(), true);

target.update();

Folder f = findFolderByName(target.getRootFolder(), sourceCr

.getParentFolder().getName());

Item targetCr = (Item) f.getItems(

f.getServer().getTypes().CHANGE_REQUEST).get(0);

targetCr.setFixedConfiguration(com.starteam.ViewConfiguration

.createFrom(targetCr.getModifiedTime()));

targetCr.setBranchOnChange(true);

((ChangeRequest) targetCr).setSynopsis("Target synopsis.");

targetCr.update();

targetCr.moveTo(target.getRootFolder());

// Try it with the new namespace.

Share[] refs = sourceCr.getAllShares();

for (int n = 0; n < refs.length; n++) {

Share ref = refsNo;

if (ref.getDotNotation().equals(sourceCr.getDotNotation())) {

// Parent should be null.

junit.framework.Assert.assertNull(

"New namespace, parent of SourceCr should be null.",

ref.getParentShare());

// Children should contain target.

Share[] kids = ref.getChildShares();

junit.framework.Assert.assertTrue(

"New namespace, should have 1 child of SourceCr.",

(kids.length == 1));

junit.framework.Assert

.assertEquals(

"New namespace, only child of SourceCr should be TargetCr.",

kids[0].getDotNotation(),

targetCr.getDotNotation());

} else if (ref.getDotNotation().equals(targetCr.getDotNotation())) {

junit.framework.Assert.assertNotNull(

"New namespace, parent of targetCr should not be null",

ref.getParentShare());

// Parent should be SourceCr.

junit.framework.Assert

.assertEquals(

"New namespace, parent of targetCr should be sourceCr.",

ref.getParentShare().getDotNotation(),

sourceCr.getDotNotation());

// Children should be empty.

junit.framework.Assert.assertEquals(

"New namespace, children of targetCr should be empty.",

ref.getChildShares().length, 0);

} else {

junit.framework.Assert

.assertTrue(

"New namespace, refs should be either sourceCr or targetCr.",

false);

}

}

}

View solution in original post

0 Likes
1 Reply
Micro Focus Expert
Micro Focus Expert

Terence,

Are you trying to access the share tree of a Change Request?

You need to use the api getAllShares(); Each returned Share can be walked up (to its parent) or walked down (to its child shares), and the views that the CR is shared into are accessible thusly.

/**

* Returns the shares for this view member.

*

* @return All shares of this view member

*/

public Share[] ViewMember::getAllShares() {

there are several examples in the junit test source, specifically CR 2565, CR4742 & CR5414.

You can get to the full junit source code in a .zip off the ftp site.  ftp://stsdkcust:LpeEFPwNMJ@emeaftp.microfocus.com/st-sdk-14.0-readme.htm

below, i have copied the code cut out from CR4742...

public void testCR4742() throws java.io.IOException {

// Create a conflict situation.

View source = getViewForTest(com.starteam.test.SDKTestCase

.getUniqueName("Source"));

Item sourceCr = makeItem(source.getRootFolder(),

com.starteam.ChangeRequest.Type.NAME);

((ChangeRequest) sourceCr).setSynopsis("Source synopsis.");

sourceCr.update();

View target = source.createChildViewShareAllItems(

com.starteam.test.SDKTestCase.getUniqueName("target"),

"a test", source.getRootFolder(), source.getPath(),

source.getConfiguration(), true);

target.update();

Folder f = findFolderByName(target.getRootFolder(), sourceCr

.getParentFolder().getName());

Item targetCr = (Item) f.getItems(

f.getServer().getTypes().CHANGE_REQUEST).get(0);

targetCr.setFixedConfiguration(com.starteam.ViewConfiguration

.createFrom(targetCr.getModifiedTime()));

targetCr.setBranchOnChange(true);

((ChangeRequest) targetCr).setSynopsis("Target synopsis.");

targetCr.update();

targetCr.moveTo(target.getRootFolder());

// Try it with the new namespace.

Share[] refs = sourceCr.getAllShares();

for (int n = 0; n < refs.length; n++) {

Share ref = refsNo;

if (ref.getDotNotation().equals(sourceCr.getDotNotation())) {

// Parent should be null.

junit.framework.Assert.assertNull(

"New namespace, parent of SourceCr should be null.",

ref.getParentShare());

// Children should contain target.

Share[] kids = ref.getChildShares();

junit.framework.Assert.assertTrue(

"New namespace, should have 1 child of SourceCr.",

(kids.length == 1));

junit.framework.Assert

.assertEquals(

"New namespace, only child of SourceCr should be TargetCr.",

kids[0].getDotNotation(),

targetCr.getDotNotation());

} else if (ref.getDotNotation().equals(targetCr.getDotNotation())) {

junit.framework.Assert.assertNotNull(

"New namespace, parent of targetCr should not be null",

ref.getParentShare());

// Parent should be SourceCr.

junit.framework.Assert

.assertEquals(

"New namespace, parent of targetCr should be sourceCr.",

ref.getParentShare().getDotNotation(),

sourceCr.getDotNotation());

// Children should be empty.

junit.framework.Assert.assertEquals(

"New namespace, children of targetCr should be empty.",

ref.getChildShares().length, 0);

} else {

junit.framework.Assert

.assertTrue(

"New namespace, refs should be either sourceCr or targetCr.",

false);

}

}

}

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.