Permission Error is reported when trying to upload a work item attachment using Plain Java API
Environment:
RTC 6.0.2 Plain Java API
I have a work item created in a test CCM.
The work item is related to a team area where I have super user rights.
When I try to upload an attachment in that work item using the RTC Eclipse client, the work item is successfully saved and the attachment can be downloaded later.
On the other hand, I have created a Java command line application which main purpose is to save attachments automatically.
The code of the test application is taken from https://rsjazz.wordpress.com/2012/08/01/uploading-attachments-to-work-items/
Result: When I run the application I receive the following error:
The 'Save Attachment' operation cannot be completed. Permission is required to complete the operation.
I use the same user name and password as well as the same work item and files.
Q: How can I save the attachments using the API without the need to grant privileges in the project area, but only in the team area as I managed to do it manually using the Eclipse client?
Thanks!
Accepted answer
Hello.
We've finally managed to run the example successfully.
Here is how an attachment is created in the example:
private static void attachFile1(
WorkItemWorkingCopy workingCopy,
String name, String contentType,
String encoding,
IProgressMonitor monitor)
throws TeamRepositoryException,
IOException {
File attachmentFile = new File(name);
FileInputStream fis = new FileInputStream(attachmentFile);
IWorkItem workItem = workingCopy.getWorkItem();
IWorkItemClient workItemClient =
(IWorkItemClient) ((ITeamRepository)workItem.getOrigin()).getClientLibrary(IWorkItemClient.class);
try {
IAttachment newAttachment =
workItemClient.createAttachment( workItem.getProjectArea(),
attachmentFile.getName(),
"",
contentType,
encoding,
fis,
monitor);
newAttachment = (IAttachment) newAttachment.getWorkingCopy();
newAttachment = workItemClient.saveAttachment(newAttachment, monitor);
IItemReference ref = WorkItemLinkTypes.createAttachmentReference(newAttachment);
workingCopy.getReferences().add(WorkItemEndPoints.ATTACHMENT, ref);
} finally {
if (fis != null) {
fis.close();
}
}
}
}
Instead, we created the attachment like this, and it worked without the need to grant privileges on PA level:
private static void attachFile( WorkItemWorkingCopy workingCopy, String fileName)
throws TeamRepositoryException, IOException {
File attachmentFile = new File(fileName);
IReference ref = IReferenceFactory
.INSTANCE
.createReferenceFromURI(
attachmentFile.toURI(),
attachmentFile.getName());
workingCopy.getReferences().add(WorkItemEndPoints.ATTACHMENT, ref);
}
2 other answers
Krasimir,
Comments
Hello, Alexander.
The code can be found here: https://rsjazz.wordpress.com/?s=attachments&submit=Search
1. There are no super users in RTC. Repository roles control what you can see and to some extend what you can do. You can have the repository role JazzAdmin, which gives you a lot more to see. It also gives you the ability to make yourself administrator and member of a project area.
Comments
Hello, Ralf.
I basically don't know. You should not be able to do things you have no permission to. If you are administrator in a project area, you gain the ability to define roles and give roles permissions and save the process XML - overriding the permission to do so, if you don't have it, If you have a JazzAdmin repository role you see work items even if they are hidden and you can make yourself admin of a project area etc.