It's all about the answers!

Ask a question

Why can't I find any changeset links?


Andy Jewell (24224867) | asked Oct 21 '15, 7:42 p.m.
edited Oct 22 '15, 8:38 p.m.
Can anyone help me determine why I can't find the changesets on a workitem?  I'm nearly positive the first method was working now suddenly it's stopped.  The first method was an approach that I think I got from Ralph's workitem handling code.  The second method is from other parts of the forum which is "new" (to me) and untested but seems to be the way that should work, though it's hard to use ILinkManager since it's not documented.

In short, neither method is picking up changesets that I know are linked to the incoming work item.

If you've worked with changeset links, does this look right?

UPDATE:
I removed the old sample code here and put a completely generic, out of the basic example.  Sorry, I don't know why this forum code puts in extra newlines but there are too many to clean up.
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ibm.team.links.common.IReference;
import com.ibm.team.links.common.registry.IEndPointDescriptor;
import com.ibm.team.repository.client.IItemManager;
import com.ibm.team.repository.client.ITeamRepository
import com.ibm.team.repository.client.TeamPlatform;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.scm.common.IChangeSet;
import com.ibm.team.workitem.client.IWorkItemClient;
import com.ibm.team.workitem.client.IWorkItemWorkingCopyManager;
import com.ibm.team.workitem.client.WorkItemWorkingCopy;
import com.ibm.team.workitem.common.IWorkItemCommon;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.workitem.common.model.IWorkItemHandle;
import com.ibm.team.workitem.common.model.IWorkItemReferences;
import com.ibm.team.workitem.common.model.WorkItemLinkTypes;

public class TestLinksStandalone {
    private static Logger log = LoggerFactory.getLogger(TestLinksStandalone.class.getName());
    private String RTCUSER = System.getProperty("org.gradle.project.rtcuser", "DEFAULT_USER");
    private String RTCPASS = System.getProperty("org.gradle.project.rtcpass", "DEFAULT_PASSWD");
    private String RTCURL = System.getProperty("org.gradle.project.rtcurl", "DEFAULT_URL");
    // use some WI here that has various links, including a CHANGESET
    private String WI_WITH_CHGSET_LINK = "297";
    
    ITeamRepository repo = null;
    private static IProgressMonitor monitor;
    @Before
    public void setUp() throws Exception {
        repo = login(RTCUSER,RTCPASS,RTCURL);
    }

    @After
    public void tearDown() {
        TeamPlatform.shutdown();
    }
    
    @Test
    public void testChangesetLinks() {
        IWorkItem wi_that_has_refs = getWorkitemById(WI_WITH_CHGSET_LINK);
        log.trace("Have the work item");
        WorkItemWorkingCopy wc = getWorkingCopy(wi_that_has_refs);
        assertNotNull(wc);
        try {
            List<IChangeSet> chgsets = findChangesetsOnWorkItem(wc);
            assertTrue("Should have found some changesets",chgsets.size() > 0);
        } catch (TeamRepositoryException e) {
            fail(e.getMessage());
        }
    }
    
    private IWorkItem getWorkitemById(String workitem) {
        log.trace("Getting workitem for ID {}",workitem);
        IWorkItemCommon common= (IWorkItemCommon) repo.getClientLibrary(IWorkItemCommon.class);
        IWorkItem work_item = null;
        try {
            int wi = Integer.parseInt(workitem);
            work_item = common.findWorkItemById(wi, IWorkItem.FULL_PROFILE, monitor);
            assertNotNull(work_item);
        } catch (NumberFormatException e) {
            fail(String.format("%s didn't seem to be a number we could use",workitem));
        } catch (TeamRepositoryException e) {
            fail("Had problem fetching workitem: "+e.getMessage());
        }
        return work_item;
    }
    
    public WorkItemWorkingCopy getWorkingCopy(IWorkItem wi) {
        WorkItemWorkingCopy wc = null;
        IWorkItemClient client = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
        IWorkItemWorkingCopyManager cm = client.getWorkItemWorkingCopyManager();

        cm = client.getWorkItemWorkingCopyManager();
        try {
            cm.connect(wi, IWorkItem.FULL_PROFILE, monitor);
        } catch (TeamRepositoryException e) {
            fail(e.getMessage());
        }
        wc = cm.getWorkingCopy(wi);
        return wc;
    }
    
    private List<IChangeSet> findChangesetsOnWorkItem(WorkItemWorkingCopy wc) throws TeamRepositoryException {
        log.trace("Getting changesets from work item {}",wc.getWorkItem().getId());
        IWorkItemCommon common= (IWorkItemCommon) repo.getClientLibrary(IWorkItemCommon.class);
        IWorkItemReferences references;
        references = common.resolveWorkItemReferences((IWorkItemHandle)wc.getWorkItem().getItemHandle(), monitor);
        
        List<IReference> chgsetrefs = new ArrayList<IReference>();
        List<IEndPointDescriptor> types = references.getTypes();
        log.trace("{} different reference types found",types.size());
        for (IEndPointDescriptor iEndPointDescriptor : types ) {
            log.trace("Endpoint        {} - ID: {}",iEndPointDescriptor.getDisplayName(),iEndPointDescriptor.getLinkType().getLinkTypeId());
            if(iEndPointDescriptor.getLinkType().equals(WorkItemLinkTypes.CHANGE_SET)){
                chgsetrefs.addAll(references.getReferences(iEndPointDescriptor));
            } else {
                log.warn("'{}' did not equal '{}'",iEndPointDescriptor.getDisplayName(),WorkItemLinkTypes.CHANGE_SET.toString());
            }
        }
        return resolveChangesetReferences(chgsetrefs);
    }
    
    private List<IChangeSet>resolveChangesetReferences(List<IReference> cshandles) throws TeamRepositoryException{
        log.trace("Entered with {} changeset refs",cshandles.size());
        IItemManager itemManager = repo.itemManager();
        List<IChangeSet> chgsets = (List<IChangeSet>)itemManager.fetchCompleteItems(cshandles, IItemManager.DEFAULT, monitor);
        return chgsets;
    }
    
    private static ITeamRepository login(final String rtcuser,final String rtcpasswd,String repoURL)
            throws TeamRepositoryException {
        TeamPlatform.startup();
        monitor = new SysoutProgressMonitor();
        ITeamRepository repository = TeamPlatform.getTeamRepositoryService().getTeamRepository(repoURL);
        repository.registerLoginHandler(new ITeamRepository.ILoginHandler() {
            public ILoginInfo challenge(ITeamRepository repository) {
                return new ILoginInfo() {
                    public String getUserId() {
                        return rtcuser;
                    }

                    public String getPassword() {
                        return rtcpasswd;
                    }
                };
            }
        });
        repository.login(monitor);
        monitor.subTask("Connected.");
        return repository;
    }
}

I appreciate any suggestions!

I should also add that I can find OTHER links -- just not changeset links.

UPDATE:

This is still baffling me.  Where I'm running the query to pull back the workitem, I added this troubleshooting code:
 
ItemProfile<IWorkItem> profile  = ItemProfile.createFullProfile(IWorkItem.ITEM_TYPE,true);

log.debug("Checking if this profile includes changeset links ({})",WorkItemLinkTypes.CHANGE_SET.toString());
if(profile.containsReference(WorkItemLinkTypes.CHANGE_SET)){
    log.debug("Apparently it DOES");
} else {
    log.debug("It does NOT.  What it has is:");
    log.debug("Reference links are:");
    for(String reftype : profile.getReferencesArray()){
        log.debug("Ref type: {}",reftype);
    }
}

And the reference type that most people seem to use (WorkItemLinkTypes.CHANGE_SET or " com.ibm.team.filesystem.workitems.change_set" ) is not in the list:

..log ->   Ref type: com.ibm.team.workitem.linktype.qm.relatedTestSuite
..log ->   Ref type: com.ibm.team.filesystem.oslc_cm.change_request.change_set
..log ->   Ref type: com.ibm.team.workitem.linktype.attachment
..log ->   Ref type: com.ibm.team.workitem.linktype.duplicateworkitem
..log ->   Ref type: com.ibm.team.workitem.linktype.parentworkitem
..log ->   Ref type: com.ibm.team.workitem.linktype.timeSheetEntry
..log ->   Ref type: com.ibm.team.workitem.linktype.rm.relatedRequirement
..log ->   Ref type: com.ibm.team.workitem.linktype.rm.tracksRequirement
..log ->   Ref type: com.ibm.team.workitem.linktype.am.elaboratedBy
..log ->   Ref type: com.ibm.team.workitem.linktype.qm.relatedExecutionRecord
..log ->   Ref type: com.ibm.team.workitem.linktype.schedulePredecessor
..log ->   Ref type: com.ibm.team.workitem.linktype.tracksworkitem
..log ->   Ref type: com.ibm.team.workitem.linktype.implementsRequirement
..log ->   Ref type: com.ibm.team.workitem.linktype.relatedartifact
..log ->   Ref type: com.ibm.team.workitem.linktype.testedByTestCase
..log ->   Ref type: com.ibm.team.workitem.linktype.copiedworkitem
..log ->   Ref type: com.ibm.team.workitem.linktype.blocksworkitem
..log ->   Ref type: com.ibm.team.workitem.linktype.textualReference
..log ->   Ref type: com.ibm.team.workitem.linktype.relatedChangeManagement
..log ->   Ref type: com.ibm.team.workitem.linktype.scm.tracksChanges
..log ->   Ref type: com.ibm.team.build.linktype.reportedWorkItems
..log ->   Ref type: com.ibm.team.workitem.linktype.qm.relatedTestPlan
..log ->   Ref type: com.ibm.team.workitem.linktype.relatedworkitem
..log ->   Ref type: com.ibm.team.workitem.linktype.blocksTestExecutionRecord
..log ->   Ref type: com.ibm.team.workitem.linktype.qm.relatedTestCase
..log ->   Ref type: com.ibm.team.workitem.linktype.cm.affectsPlanItem
..log ->   Ref type: com.ibm.team.workitem.linktype.affectsExecutionResult
..log ->   Ref type: com.ibm.team.workitem.linktype.cm.affectedByDefect
..log ->   Ref type: com.ibm.team.workitem.linktype.qm.relatedTestScript
..log ->   Ref type: com.ibm.team.workitem.linktype.resolvesworkitem
..log ->   Ref type: com.ibm.team.build.linktype.includedWorkItems
..log ->   Ref type: com.ibm.team.workitem.linktype.trackedworkitem

Does anyone know why " com.ibm.team.filesystem.workitems.change_set " wouldn't be in the list of references?  That should come with FULL_PROFILE, I assume?  Or does it not have anything to do with that??  This is killing me slowly and NOT by its love!



Andy

One answer



permanent link
Andy Jewell (24224867) | answered Oct 27 '15, 11:11 a.m.
edited Oct 27 '15, 11:19 a.m.
After spending the better part of three days chasing this, I "sort of" found the resolution.

Firstly, my Eclipse was setup to use JDK logging and was using a logging properties file that buried some errors.  In the process of creating a completely clean environment, I built and ran the test from the command line and using logback discovered a bunch of these kinds of errors being logged:

Oct 27, 2015 7:56:30 AM com.ibm.team.repository.common.util.ExtensionRegistryReader logError
SEVERE: The com.ibm.team.build.common bundle's plugin.xml file contains a <component> element with the id attribute value com.ibm.team.build that is not unique.
Oct 27, 2015 7:56:30 AM com.ibm.team.repository.common.util.ExtensionRegistryReader logError
SEVERE: The com.ibm.team.calm.foundation.common bundle's plugin.xml file contains a <component> element with the id attribute value com.ibm.team.calmfoundation that is not unique.
Oct 27, 2015 7:56:30 AM com.ibm.team.repository.common.util.ExtensionRegistryReader logError
SEVERE: The com.ibm.team.datawarehouse.common bundle's plugin.xml file contains a <component> element with the id attribute value com.ibm.team.datawarehouse that is not unique.
Oct 27, 2015 7:56:30 AM com.ibm.team.repository.common.util.ExtensionRegistryReader logError
SEVERE: The com.ibm.team.enterprise.buildablesubset.common bundle's plugin.xml file contains a <component> element with the id attribute value com.ibm.team.enterprise.buildablesubset that is not unique.

Included among all these failures were these:

SEVERE: linkTypes extension-point: A link type registry entry with id com.ibm.team.workitem.linktype.blocksworkitem already exists: LinkTypeEntry for com.ibm.team.workitem.linktype.blocksworkitem:, source: com.ibm.team.links.common.internal.registry.EndPointDescriptor@2771d7fc, target: com.ibm.team.links.common.internal.registry.EndPointDescriptor@76db3508. Keeping the existing link type and ignoring the following link type:LinkTypeEntry for com.ibm.team.workitem.linktype.blocksworkitem:, source: com.ibm.team.links.common.internal.registry.EndPointDescriptor@2581f0f0, target: com.ibm.team.links.common.internal.registry.EndPointDescriptor@1ff59035
Oct 27, 2015 8:03:37 AM com.ibm.team.links.common.internal.registry.LinkTypeRegistry$Impl register
SEVERE: linkTypes extension-point: A link type registry entry with id com.ibm.team.workitem.linktype.parentworkitem already exists: LinkTypeEntry for com.ibm.team.workitem.linktype.parentworkitem:, source: com.ibm.team.links.common.internal.registry.EndPointDescriptor@4f61cf8c, target: com.ibm.team.links.common.internal.registry.EndPointDescriptor@4614d08e. Keeping the existing link type and ignoring the following link type:LinkTypeEntry for com.ibm.team.workitem.linktype.parentworkitem:, source: com.ibm.team.links.common.internal.registry.EndPointDescriptor@49c4d357, target: com.ibm.team.links.common.internal.registry.EndPointDescriptor@782deae8
Oct 27, 2015 8:03:37 AM com.ibm.team.links.common.internal.registry.LinkTypeRegistry$Impl register
SEVERE: linkTypes extension-point: A link type registry entry with id com.ibm.team.workitem.linktype.textualReference already exists: LinkTypeEntry for com.ibm.team.workitem.linktype.textualReference:, source: com.ibm.team.links.common.internal.registry.EndPointDescriptor@43518e26, target: com.ibm.team.links.common.internal.registry.EndPointDescriptor@5c4e8081. Keeping the existing link type and ignoring the following link type:LinkTypeEntry for com.ibm.team.workitem.linktype.textualReference:, source: com.ibm.team.links.common.internal.registry.EndPointDescriptor@6dbf7483, target: com.ibm.team.links.common.internal.registry.EndPointDescriptor@1ee262dc
Oct 27, 2015 8:03:37 AM com.ibm.team.links.common.internal.registry.LinkTypeRegistry$Impl register
SEVERE: linkTypes extension-point: A link type registry entry with id com.ibm.team.workitem.linktype.schedulePredecessor already exists: LinkTypeEntry for com.ibm.team.workitem.linktype.schedulePredecessor:, source: com.ibm.team.links.common.internal.registry.EndPointDescriptor@7826b259, target: com.ibm.team.links.common.internal.registry.EndPointDescriptor@6ce8317d. Keeping the existing link type and ignoring the following link type:LinkTypeEntry for com.ibm.team.workitem.linktype.schedulePredecessor:, source: com.ibm.team.links.common.internal.registry.EndPointDescriptor@7362edfd, target: com.ibm.team.links.common.internal.registry.EndPointDescriptor@412c75a2
Oct 27, 2015 8:03:37 AM com.ibm.team.links.common.internal.registry.LinkTypeRegistry$Impl register
SEVERE: linkTypes extension-point: A link type registry entry with id com.ibm.team.workitem.linktype.resolvesworkitem already exists: LinkTypeEntry for com.ibm.team.workitem.linktype.resolvesworkitem:, source: com.ibm.team.links.common.internal.registry.EndPointDescriptor@780bfbd5, target: com.ibm.team.links.common.internal.registry.EndPointDescriptor@3a35d0fa. Keeping the existing link type and ignoring the following link type:LinkTypeEntry for com.ibm.team.workitem.linktype.resolvesworkitem:, source: com.ibm.team.links.common.internal.registry.EndPointDescriptor@19a29b25, target: com.ibm.team.links.common.internal.registry.EndPointDescriptor@1b02344b
Oct 27, 2015 8:03:37 AM com.ibm.team.links.common.internal.registry.LinkTypeRegistry$Impl register
SEVERE: linkTypes extension-point: A link type registry entry with id com.ibm.team.workitem.linktype.tracksworkitem already exists: LinkTypeEntry for com.ibm.team.workitem.linktype.tracksworkitem:, source: com.ibm.team.links.common.internal.registry.EndPointDescriptor@3ff264e0, target: com.ibm.team.links.common.internal.registry.EndPointDescriptor@2f02dc20. Keeping the existing link type and ignoring the following link type:LinkTypeEntry for com.ibm.team.workitem.linktype.tracksworkitem:, source: com.ibm.team.links.common.internal.registry.EndPointDescriptor@297928e1, target: com.ibm.team.links.common.internal.registry.EndPointDescriptor@42b51d9e
Oct 27, 2015 8:03:37 AM com.ibm.team.links.common.internal.registry.LinkTypeRegistry$Impl register
SEVERE: linkTypes extension-point: A link type registry entry with id com.ibm.team.workitem.linktype.trackedworkitem already exists: LinkTypeEntry for com.ibm.team.workitem.linktype.trackedworkitem:,



Googling for this resulted in me adding -Djava.ext.lib=jre/lib/ext;plainjava/lib to the command line and the problem was "apparently" resolved.  I say apparently because I still get a bunch of these plugin errors, though not the linktype errors.  The functionality I'm testing is working now and if I remove the java.ext.lib I get the problem back so it clearly solves my particular issue.

So, I'm not sure what's going on exactly, but for the moment my problem is resolved.  My other questions would be:

1.  Why wouldn't these warrant a Runtime Error?  Sure would have saved me time.
2.  Why was it working before?  I've never used that parameter before.
3.  Why didn't the extensions library parameter resolve all the plugin errors and not just some of them?

Ugh, it's bittersweet - finally getting to the bottom of it but still not sure exactly what the solution was.  Any additional insights?

Andy

Your answer


Register or to post your answer.