javaapirtc

How to find out if work item change set file item is newly added or modified?


I have some change set objects and I need to find out if the file in the change set is newly added or modified. below is the code I am using to fetch the change set:

    IChangeSetHandle changeSets = convertToChangeSetHandles(extracted);

                        changeSet = (IChangeSet) repoApac.itemManager().fetchCompleteItem(changeSets,
                                    IItemManager.DEFAULT, monitor);

public static List<IFileItem> changeSetFileName(IChangeSet changeSet) throws TeamRepositoryException{
        IVersionableManager vm = SCMPlatform.getWorkspaceManager(repoApac).versionableManager(); 
        List changes = changeSet.changes(); 
        List<IFileItem> changeSetFileNames = new ArrayList<>();
        for(int i=0;i<changes.size();i++) { 
            Change change = (Change) changes.get(i); 
            IVersionableHandle after = change.afterState();
            if( after != null && after instanceof IFileItemHandle) { 
                IFileItem fileItem = (IFileItem) vm.fetchCompleteState(after, null); 
                changeSetFileNames.add(fileItem);
            } 
        } 
        return changeSetFileNames;
    }

        if(changeSet.isNewItem()){
                return "ADDED"; 
            }else{
                return "MODIFIED";
            }

Solution

  • This is the working code:

    for (IChange change : (List<IChange>) changeSet.changes()) {
                    if (change.kind() == IChange.MODIFY) {
                        return "MODIFIED";
                    }
                    if (change.kind() == IChange.ADD) {
                        return "ADDED";
                    }
                }