It's all about the answers!

Ask a question

com.ibm.team.scm.common.ComponentNotInWorkspaceException


Kodac Hasubo (364) | asked Mar 05 '22, 8:19 a.m.

com.ibm.team.scm.common.ComponentNotInWorkspaceException


I am posting a fileto SCM by  JAVA API

Until now, there was no problem, but this error occurred when the component name was incorrect.

An error has been issued that the component has been locked. However, we have unlocked all the components. However, the error persists. Does anyone know about this error?

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
IFileContentManager contentManager = FileSystemCore
.getContentManager(teamRepository);

IFileContent storedzipContent = contentManager.storeContent(
IFileContent.ENCODING_UTF_8,
FileLineDelimiter.LINE_DELIMITER_PLATFORM,
new VersionedContentManagerByteArrayInputStreamPovider(
contents.toByteArray()), null, monitor);

if (!storedzipContent.sameContent(aFile.getContent()))
{
IFileItem fileWorkingCopy = (IFileItem) aFile.getWorkingCopy();
fileWorkingCopy.setContent(storedzipContent);

Collection col = (Collection)Collections.singletonList( workspaceConne.configurationOpFactory().save(fileWorkingCopy));

workspaceConne.commit(changeSetHandle, col, monitor);

IConfiguration configuration = workspaceConne.configuration(component);

exctractToComponentBaseline(teamRepository, workspaceConne, myStream, component, strZipFilePath,
  workItemId, monitor, changeSetHandle, configuration,
  MYName ,systemName, planTargetName, modelCodeName,confidentialName,destinationName, shitukaName);


Comments
Kodac Hasubo commented Mar 05 '22, 9:09 a.m. | edited Mar 06 '22, 8:39 p.m.
postscript
 Some component locks cannot be retrieved.

It is written in the log


Accepted answer


permanent link
David Lafreniere (4.8k7) | answered Mar 05 '22, 12:18 p.m.
FORUM MODERATOR / JAZZ DEVELOPER
edited Mar 05 '22, 12:20 p.m.

 A ComponentNotInWorkspaceException usually is a case where the component you are trying to perform operations against (ex: check-in to, or deliver to) does not exist in the repository workspace (or stream) that you are trying to work against.

Ex: 

-The component did exist in the repository workspace, but was later removed.
-The component perhaps had it's visibility updated such that the user can no longer see it, and perhaps the code being used is is considering this a 'component not in workspace' case.
-Your code is retrieving/using the wrong component Ex: If you are trying to get a component by name (not at all recommended when writing plain-Java code) if could happen that someone else in the repository created a component with the same name... and in this case finding a component based on the name is not reliable. You should always build up an IComponentHandle using the components itemId (UUD) which will NEVER change, that way you can ensure you are always working against the same component going forward.
-The other possibility is you are also geting the wrong repository workspace (one that also doesn't have the component) (again, it's normally recommended to use the workspace itemId (UUID) to ensure you are working against the same repo workspace).

-Your snippets do now show how you are getting the repository workspace, or the component, so it's hard to give suggestions around this.
-You should also give a snippet of the stack trace error, as it might help narrow down where the issue is happening (devs might be able to provide insight around this)

Kodac Hasubo selected this answer as the correct answer

Comments
Kodac Hasubo commented Mar 05 '22, 7:37 p.m. | edited Mar 06 '22, 8:39 p.m.

 Thank you for the advice. Thank you very much.


I accidentally specified a component that doesn't exist. That's when this error occurred.

The specified component was then modified. However, 
this error still occurs. I don't know how to escape.

※I was able to check in the file manually.

※Below is the source code for obtaining the components.

------------------------------------------------

IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(teamRepository);


HashMap<String, IComponentHandle> allComponents = getComponentMap(wm, monitor);

IComponentHandle component = allComponents.get(componentName);

private static HashMap<String, IComponentHandle> getComponentMap(IWorkspaceManager wm, IProgressMonitor monitor)throws TeamRepositoryException {
HashMap<String, IComponentHandle> allComponents = new HashMap<String, IComponentHandle>();
// These are the components I need
// Try to find all components

@SuppressWarnings("deprecation")
Set<String> components = wm.findAllComponentNames(monitor);

for (String compName : components) {

IComponentSearchCriteria criteria = IComponentSearchCriteria.FACTORY
.newInstance();
criteria.setExactName(compName);
List<IComponentHandle> found = wm.findComponents(criteria,
Integer.MAX_VALUE, monitor);

if (found.size() > 1) {
System.out.println("Ambiguousonent Names");
}

for (IComponentHandle iComponentHandle : found) {
allComponents.put(compName, iComponentHandle);
}
}
return allComponents;
}


Kodac Hasubo commented Mar 05 '22, 7:45 p.m. | edited Mar 06 '22, 8:39 p.m.
Function to get workspace

 private static IWorkspaceConnection findConnection(String streamName, IProgressMonitor monitor, IWorkspaceManager wm, int kind) throws TeamRepositoryException {



IWorkspaceSearchCriteria criteria = IWorkspaceSearchCriteria.FACTORY.newInstance().setKind(kind);

if (streamName != null) {
criteria.setExactName(streamName);
}

List<IWorkspaceHandle>workspaces= wm.findWorkspaces(criteria, Integer.MAX_VALUE, monitor);

IWorkspaceHandle firstFound = null;
IWorkspaceConnection connection = null;

if (!workspaces.isEmpty()) {
firstFound = workspaces.get(0);
connection = wm.getWorkspaceConnection(firstFound, monitor);
}
return connection;
}


David Lafreniere commented Mar 06 '22, 9:01 p.m. | edited Mar 06 '22, 9:06 p.m.
FORUM MODERATOR / JAZZ DEVELOPER

Few comments.

1) I figured if you were trying to check-in (and deliver) to a file using the Plain-Java API, you might already have an idea of what component/workspace you want to check it into.
It looks like your code is fetching every single component in the repository (this seems like a lot of unnecessary work, and would likely result in a performance hit if this were ran often enough (ex: Not sure if you run the same code for all file check-ins) 

2) You are using deprecated API. IWorkspaceConnection.findAllComponentNames() is deprecated, and will simply give you the names of 4 thousand (but not more) components in the repo.

3) Then for each of those (potentially 4 thousand component) you are creating individual component search queries using the name. Again, if more than one component has the same name, you will run into the case where you likely won't know which want you want.

4) ...I'm past the character limit... so I will post the rest in a new comment....


David Lafreniere commented Mar 06 '22, 9:04 p.m. | edited Mar 06 '22, 9:05 p.m.
FORUM MODERATOR / JAZZ DEVELOPER

4) "IF" you really need all component handles for all components in the repo, you could avoid the first fetch of getting all component names, and also making 'x' number of component search criteria requests. Try just doing a single component search criteria... try either not specifying any filters (such as name), or try setting "" for I

ComponentSearchCriteria.setPartialName(""). Note: Again I strongly advise against fetching all components in the repo.. you'd want to change your program so you can pass in the itemIds of the components you care about (since these will never change).

5) Likewise for fetching the WorkspaceConnection. This also would not work if there are more than one repository workspaces or streams with the same name.

Here is some sample code of how you can get a componentHandle and workspaceConnection if you just use the itemIds..

... out of character limit again, this will follow in the next comment...


David Lafreniere commented Mar 06 '22, 9:05 p.m.
FORUM MODERATOR / JAZZ DEVELOPER

String workspaceItemIdString = "_g4a2I37zEeqR6peqpx3x5w";

UUID workspaceItemId = UUID.valueOf(workspaceItemIdString);
IWorkspaceHandle workspaceHandle = (IWorkspaceHandle) IWorkspace.ITEM_TYPE.createItemHandle(workspaceItemId, null);
IWorkspaceConnection workspaceConnection = workspaceManager.getWorkspaceConnection(workspaceHandle, monitor);
        
String componentItemIdString = "_h4a2IK7zEeqR6peqpx0Wrg";
UUID componentItemId = UUID.valueOf(componentItemIdString);
IComponentHandle componentHandle = (IComponentHandle) IComponent.ITEM_TYPE.createItemHandle(componentItemId, null);

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.