Details of API to fetch status of a object in stream
Accepted answer
You can pass the list of versionables to IWorkspaceManager#findLocks(ILockSearchCriteria criteria, IProgressMonitor monitor) and it will return ILockSearchResult that indicates the versionables that are locked.
To unlock when the user is not the same as the user who has locked the file, you need to pass a custom ILockDilemmaHandler to IUnlockOperation where you override the method currentUserDoesntOwnLock and return IDilemmaHandler.CONTINUE. The lock will be released only if the user has the right permissions.
One other answer
Hi Shashikant,
ILockSearchResult returns whether the object is locked or not. But it doesn't return user who locked the object in stream. instead it shows repository login user id.
IFileItemHandle fileH = (IFileItemHandle) item;
file = (IFileItem) componentConfig.fetchCompleteItem(fileH, null);
criteria.getVersionables().add(file);
criteria.getComponents().add(component);
criteria.getStreams().add(workspace);
// wkspManager = SCMPlatform.getWorkspaceManager(teamRepository);
ILockSearchResult result = wkspManager.findLocks(criteria, IWorkspaceManager.MAX_QUERY_SIZE, null);
Collection<IStreamLockReport> reports = result.getReports();
// IProgressMonitor monitor = new LoggerProgressMonitor();
// ILockAttribute lockAttribute = newLockAttribute(false,"");
for (IStreamLockReport report : reports) {
Collection<IComponentLockReport> componentLocks = report.getComponentLocks();
for (IComponentLockReport componentLock : componentLocks) {
Collection<IVersionableLock> locks1 = componentLock.getLocks();
if (!locks1.isEmpty()) {
for (IVersionableLock iVersionableLock : locks1) {
iVersionableLock.getContributor();
iVersionableLock.getVersionable();
// IContributor contributor = (IContributor) repo.itemManager().fetchCompleteItem(iVersionableLock.getContributor(), ItemManager.DEFAULT, null);
// lockAttribute = new LockAttribute(true, contributor.getName());
}
} else {
// IComponent component = (IComponent) repo.itemManager().fetchCompleteItem(componentLock.getComponent(), ItemManager.DEFAULT, monitor);
// if (logger.isDebugEnabled()) logger.debug("no lock for component " + component.getName());
}
}
}