Is there a way to add or modify a timesheet entry to an RTC workitem via REST API?
I tried to use the GET/PUT mechanism to modify an already existing collection of TimeSheetEntry, but I keep getting a 405 error no matter what I do.
<?xml version="1.0" encoding="UTF-8"?><oslc_cm:error xmlns:oslc_cm="http://open-services.net/xmlns/cm/1.0/"> <oslc_cm:status>405</oslc_cm:status> <oslc_cm:message/> </oslc_cm:error>
This what I've done so far:
1. GET https://***:9443/ccm/oslc/workitems/156/rtc_cm:timeSheet
response:
<?xml version="1.0" encoding="UTF-8"?><rtc_cm:TimeSheet xmlns:rtc_cm="http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/" rdf:about="https://stend-402.aplana.com:9443/ccm/oslc/workitems/156/rtc_cm:timeSheet" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:oslc_cm="http://open-services.net/xmlns/cm/1.0/">
<rtc_cm:entry oslc_cm:collref="https://***:9443/ccm/oslc/workitems/156/rtc_cm:timeSheet/rtc_cm:entry"/>
</rtc_cm:TimeSheet>
2. GET https://***:9443/ccm/oslc/workitems/156/rtc_cm:timeSheet/rtc_cm:entry
response:
<?xml version="1.0" encoding="UTF-8"?><oslc_cm:Collection xmlns:oslc_cm="http://open-services.net/xmlns/cm/1.0/" oslc_cm:totalCount="2" xmlns:dc="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rtc_cm="http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/">3. PUT/POST https://***:9443/ccm/resource/itemOid/com.ibm.team.workitem.TimeSheetEntry/_86jcF652EeKBe6dbNNyQ5w
<rtc_cm:TimeSheetEntry rdf:resource="https://***:9443/ccm/resource/itemOid/com.ibm.team.workitem.TimeSheetEntry/_69Fp1a52EeKBe6dbNNyQ5w">
<rtc_cm:workItem rdf:resource="https://***:9443/ccm/resource/itemName/com.ibm.team.workitem.WorkItem/156"/>
<dc:creator rdf:resource="https://***:9443/jts/users/jazz"/>
<rtc_cm:startDate>2013-04-23T17:40:38.545Z</rtc_cm:startDate>
<rtc_cm:timeCode>Planning</rtc_cm:timeCode>
<rtc_cm:timeCodeId>timecode.literal.l6</rtc_cm:timeCodeId>
<rtc_cm:timeSpent>0</rtc_cm:timeSpent>
</rtc_cm:TimeSheetEntry>
<rtc_cm:TimeSheetEntry rdf:resource="https://***:9443/ccm/resource/itemOid/com.ibm.team.workitem.TimeSheetEntry/_86jcF652EeKBe6dbNNyQ5w">
<rtc_cm:workItem rdf:resource="https://***:9443/ccm/resource/itemName/com.ibm.team.workitem.WorkItem/156"/>
<dc:creator rdf:resource="https://***:9443/jts/users/jazz"/>
<rtc_cm:startDate>2013-04-22T17:40:56.994Z</rtc_cm:startDate>
<rtc_cm:timeCode>Planning</rtc_cm:timeCode>
<rtc_cm:timeCodeId>timecode.literal.l6</rtc_cm:timeCodeId>
<rtc_cm:timeSpent>7200000</rtc_cm:timeSpent>
</rtc_cm:TimeSheetEntry>
</oslc_cm:Collection>
<rtc_cm:TimeSheetEntry xmlns:oslc_cm="http://open-services.net/xmlns/cm/1.0/" oslc_cm:totalCount="2" xmlns:dc="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rtc_cm="http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/">
<rtc_cm:workItem rdf:resource="https://***:9443/ccm/resource/itemName/com.ibm.team.workitem.WorkItem/156"/>
<dc:creator rdf:resource="https://***:9443/jts/users/jazz"/>
<rtc_cm:startDate>2013-04-22T17:40:56.994Z</rtc_cm:startDate>
<rtc_cm:timeCode>Planning</rtc_cm:timeCode>
<rtc_cm:timeCodeId>timecode.literal.l6</rtc_cm:timeCodeId>
<rtc_cm:timeSpent>3600000</rtc_cm:timeSpent>
</rtc_cm:TimeSheetEntry>
and here I get the 405 error.
I also tried to POST and PUT a new collecton of timesheet entries like this:
POST/PUT https://***:9443/ccm/oslc/workitems/156/rtc_cm:timeSheet/rtc_cm:entry
<?xml version="1.0" encoding="UTF-8"?><oslc_cm:Collection xmlns:oslc_cm="http://open-services.net/xmlns/cm/1.0/" oslc_cm:totalCount="0"/>
<
I expected this to replace the existing TimeSheetEntry collection with an empty one but I still get 405.
Accepted answer
Comments
1. I used the code from this link: https://jazz.net/wiki/bin/view/Main/OSLCAccessForTimesheetEntry and was able to create a timesheet for a workitem, however, the code throws an exception on workingCopyManager.dispose(); line.
It says:
org.eclipse.core.runtime.AssertionFailedException: assertion failed: at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110) at org.eclipse.core.runtime.Assert.isTrue(Assert.java:96) at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyManager.dispose(WorkItemWorkingCopyManager.java:178) at com.***.timesheet.TimesheetService.addTimeSheetEntry(TimesheetService.java:54) ...
All I did was getting a workitem and passing it into the addTimeSheetEntry method. This doesn't seem to affect timesheet creation but clutters logfiles. Can this be fixed?
2. One more thing is that when a timesheet entry is added with the same starting time, same timecode and same owner more than once, then only the last timesheet info is displayed in the CCM WebUI. The last value is also used for calculation of week total field, while the sum of all timesheets is used for the task total field. I.e. if we add timesheets with duration of 2, 4 and 8 hours, week total will be 8 and task total will be 14 hours, while only 8 hrs record is displayed in Web UI.
The timesheet value also cannot be modified from the Web UI in this case. After a workitem is saved, timesheet entry value is reset to the last one. This looks like an unexpected state for RTC CCM.
How do I get the list of all timesheet entries attached to a workitem and modify them if necessary via Java API?
- The exception your seeing says that are disposing a work item working copy that is also in use somewhere else. I guess the file is open in the editor.
Use workingCopyManager.connectNew instead to force a new working copy that you can can dispose when done, or first find out if a working copy already exists with workingCopyManager.connectLocal and do not dispose if it already does. - It's the APIs users responsibility that no two time sheet entries for the same owner/date and code are created. So before adding one, check that there isn't one already. To remove an existing entry just remove it from the work item references.
Modifying existing time sheet entries is not permitted on the client API. Use remove and add instead.
Thank you for your replies! I'm getting a number of errors logged on workitem creation. The call
IWorkItemType workItemType = workItemClient.findWorkItemType(projectAreaHandle, "task", null);causes these erros to show up:
13.05.2013 12:22:11 com.ibm.team.foundation.common.util.FoundationLog unexpectedError SEVERE: URL not found: processattachment:/workitemtype/Issue_bitmap.bmp 13.05.2013 12:22:11 com.ibm.team.foundation.common.util.FoundationLog unexpectedError SEVERE: URL not found: processattachment:/workitemtype/enhancement.gif 13.05.2013 12:22:11 com.ibm.team.foundation.common.util.FoundationLog unexpectedError SEVERE: URL not found: processattachment:/workitemtype/general.gif 13.05.2013 12:22:11 com.ibm.team.foundation.common.util.FoundationLog unexpectedError SEVERE: URL not found: processattachment:/workitemtype/gear.png 13.05.2013 12:22:11 com.ibm.team.foundation.common.util.FoundationLog unexpectedError SEVERE: URL not found: processattachment:/workitemtype/unknown.gifLooks like this is an issue of RTC configuration. How can this be solved?
One other answer
I'm also getting errors from
IWorkItemHandle handle = workItemClient.getWorkItemWorkingCopyManager().connectNew(workItemType, null);:
13.05.2013 12:25:31 com.ibm.team.foundation.common.util.FoundationLog unexpectedError SEVERE: Default value provider not found: com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider 13.05.2013 12:25:33 com.ibm.team.foundation.common.util.FoundationLog unexpectedError SEVERE: Value provider not found: com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProviderI tried to add the following jars:
com.ibm.team.rtc.common.scriptengine_3.1.200.v20120924_1445.jar com.ibm.team.workitem.api.common_3.1.200.v20121022_1010.jar com.ibm.team.workitem.shared.common_3.1.200.v20121022_1010.jar org.mozilla.javascript_1.7.2.v201005080400.jarto the build path, as they contain the ScriptAttributeValueProvider definition and referenced classes, but in this case I'm getting an Exception:
Exception in thread "main" java.lang.ExceptionInInitializerError at org.eclipse.core.runtime.FileLocator.find(FileLocator.java:84) at com.ibm.team.rtc.common.scriptengine.environment.FileScriptFeature.findFile(FileScriptFeature.java:107) at com.ibm.team.rtc.common.scriptengine.environment.FileScriptFeature.create(FileScriptFeature.java:50) at com.ibm.team.rtc.common.scriptengine.environment.FileScriptFeature.create(FileScriptFeature.java:46) at com.ibm.team.rtc.common.scriptengine.environment.dojo.DojoFeature.This also loks like a misconfigured RTC to me. How can I fix this?(DojoFeature.java:62) at com.ibm.team.rtc.common.scriptengine.environment.dojo.DefaultDojoEnvironment.createDojoFeature(DefaultDojoEnvironment.java:60) at com.ibm.team.rtc.common.scriptengine.environment.dojo.DefaultDojoEnvironment.createFeatures(DefaultDojoEnvironment.java:44) at com.ibm.team.rtc.common.scriptengine.environment.dojo.DefaultDojoEnvironment.createFeatures(DefaultDojoEnvironment.java:33) at com.ibm.team.workitem.shared.common.internal.ScriptEnvironmentManager.updateCache(ScriptEnvironmentManager.java:53) at com.ibm.team.workitem.common.internal.util.CacheHelper.internalCheckCache(CacheHelper.java:114) at com.ibm.team.workitem.common.internal.util.CacheHelper.checkCache(CacheHelper.java:89) at com.ibm.team.workitem.common.internal.util.CacheHelper.checkCache(CacheHelper.java:81) at com.ibm.team.workitem.shared.common.internal.ScriptEnvironmentManager.getScriptEnvironment(ScriptEnvironmentManager.java:58) at com.ibm.team.workitem.shared.common.internal.ScriptEnvironmentManager.getScriptEnvironment(ScriptEnvironmentManager.java:39) at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider$ProviderCall.getProvider(ScriptAttributeValueProvider.java:197) at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider$ProviderCall. (ScriptAttributeValueProvider.java:183) at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider.getDefaultValue(ScriptAttributeValueProvider.java:81) at com.ibm.team.workitem.common.internal.attributeValueProviders.AttributeValueProviderRegistry$SafeDefaultValueProvider.getDefaultValue(AttributeValueProviderRegistry.java:113) at com.ibm.team.workitem.common.internal.model.impl.AttributeImpl.getDefaultValue(AttributeImpl.java:887) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.ibm.team.repository.common.internal.util.ItemStore$ItemInvocationHandler.invoke(ItemStore.java:597) at $Proxy26.getDefaultValue(Unknown Source) at com.ibm.team.workitem.common.internal.WorkItemCommon.createWorkItem(WorkItemCommon.java:236) at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyRegistry.createNewUnconnected(WorkItemWorkingCopyRegistry.java:601) at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyRegistry.connectNew(WorkItemWorkingCopyRegistry.java:595) at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyManager.connectNew(WorkItemWorkingCopyManager.java:94) at com.***.service.WorkitemService.createWorkitem(WorkitemService.java:67)