It's all about the answers!

Ask a question

Is there a way to add or modify a timesheet entry to an RTC workitem via REST API?


Serghei Zagorinyak (482913) | asked Apr 26 '13, 10:34 a.m.
edited Apr 29 '13, 11:38 a.m.
I've been looking through the RTC REST API, but couldn't find a way to programmatically create a timesheet entry via REST. Can this be done at all? If so, how can I do it? 


  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/">
<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>

  3. PUT/POST https://***:9443/ccm/resource/itemOid/com.ibm.team.workitem.TimeSheetEntry/_86jcF652EeKBe6dbNNyQ5w
<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


permanent link
Michael Fiedler (9113) | answered May 02 '13, 10:11 a.m.
JAZZ DEVELOPER
timeSheet and timeSheetEntry creation (POST) and update (PUT) are not available via the REST API.   Those resources are only available via GET.   So, the 405 (method not allowed) is a correct response from the server.

You can use the Java API to create and update time sheets.   See https://jazz.net/wiki/bin/view/Main/OSLCAccessForTimesheetEntry for details on what the REST API supports today and a snippet of code on how to use the Java API
Serghei Zagorinyak selected this answer as the correct answer

Comments
Serghei Zagorinyak commented May 07 '13, 8:36 a.m.

  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?


Serghei Zagorinyak commented May 07 '13, 8:37 a.m. | edited May 07 '13, 9:06 a.m.

  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?


Martin Aeschlimann commented May 08 '13, 5:39 a.m.
JAZZ DEVELOPER
  1. 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.
  2. 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.

Serghei Zagorinyak commented May 13 '13, 4:25 a.m. | edited May 13 '13, 4:36 a.m.

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.gif
Looks like this is an issue of RTC configuration. How can this be solved?

One other answer



permanent link
Serghei Zagorinyak (482913) | answered May 13 '13, 4:34 a.m.
edited May 13 '13, 4:39 a.m.
Thank you for the replies!
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.ScriptAttributeValueProvider
I 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.jar
  to 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.(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)
This also loks like a misconfigured RTC to me. How can I fix this?

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.