5959/**
6060 * The WorklogQueryResource class. The class contains the findWorklogs method. The class grant the JIRA worklog query.
6161 */
62- @ Path ("/findWorklogs " )
62+ @ Path ("/find " )
6363public class WorklogQueryResource {
6464
6565 /**
@@ -250,7 +250,7 @@ private JSONObject createWorklogJSONObject(final GenericValue worklog) throws JS
250250 }
251251
252252 /**
253- * The findWorklogs restful api method.
253+ * The updatedWorklogs restful api method.
254254 *
255255 * @param startDate
256256 * The query startDate parameter.
@@ -268,6 +268,63 @@ private JSONObject createWorklogJSONObject(final GenericValue worklog) throws JS
268268 */
269269 @ GET
270270 @ Produces ("*/*" )
271+ @ Path ("/updatedWorklogs" )
272+ public Response findUpdatedWorklogs (
273+ @ QueryParam ("startDate" ) final String startDate ,
274+ @ QueryParam ("endDate" ) final String endDate ,
275+ @ QueryParam ("user" ) final String user ,
276+ @ QueryParam ("group" ) final String group ,
277+ @ QueryParam ("project" ) final String project ) {
278+
279+ Response checkRequiredFindWorklogsParamResponse = checkRequiredFindWorklogsParameter (startDate , user , group );
280+ if (checkRequiredFindWorklogsParamResponse != null ) {
281+ return checkRequiredFindWorklogsParamResponse ;
282+ }
283+ Calendar startDateCalendar ;
284+ try {
285+ startDateCalendar = convertStartDate (startDate );
286+ } catch (ParseException e ) {
287+ LOGGER .debug ("Failed to convert start date" , e );
288+ return Response .status (Response .Status .BAD_REQUEST )
289+ .entity ("Cannot parse the 'startDate' parameter: " + startDate ).build ();
290+ }
291+ Calendar endDateCalendar ;
292+ try {
293+ endDateCalendar = convertEndDate (endDate );
294+ } catch (ParseException e ) {
295+ LOGGER .debug ("Failed to convert end date" , e );
296+ return Response .status (Response .Status .BAD_REQUEST )
297+ .entity ("Cannot parse the 'endDate' parameter: " + endDate ).build ();
298+ }
299+ try {
300+ return Response .ok (worklogQuery (startDateCalendar , endDateCalendar , user , group , project , true )).build ();
301+ } catch (Exception e ) {
302+ LOGGER .error ("Failed to query the worklogs" , e );
303+ return Response .status (Response .Status .INTERNAL_SERVER_ERROR )
304+ .entity (e .getMessage ()).build ();
305+ }
306+ }
307+
308+ /**
309+ * The worklogs restful api method.
310+ *
311+ * @param startDate
312+ * The query startDate parameter.
313+ * @param endDate
314+ * The query endDate parameter, optional. Default value is the current time.
315+ * @param user
316+ * The query user parameter, optional. This or the group parameter is required.
317+ * @param group
318+ * The query group parameter, optional. This or the user parameter is required.
319+ * @param project
320+ * The query project parameter, optional. Default is all project.
321+ * @return {@link Response} what contains the result of the query. If the method parameters was wrong then a message
322+ * what contains the description of the bad request. In case of any exception return {@link Response} with
323+ * INTERNAL_SERVER_ERROR status what contains the original exception message.
324+ */
325+ @ GET
326+ @ Produces ("*/*" )
327+ @ Path ("/worklogs" )
271328 public Response findWorklogs (
272329 @ QueryParam ("startDate" ) final String startDate ,
273330 @ QueryParam ("endDate" ) final String endDate ,
@@ -296,7 +353,7 @@ public Response findWorklogs(
296353 .entity ("Cannot parse the 'endDate' parameter: " + endDate ).build ();
297354 }
298355 try {
299- return Response .ok (worklogQuery (startDateCalendar , endDateCalendar , user , group , project )).build ();
356+ return Response .ok (worklogQuery (startDateCalendar , endDateCalendar , user , group , project , false )).build ();
300357 } catch (Exception e ) {
301358 LOGGER .error ("Failed to query the worklogs" , e );
302359 return Response .status (Response .Status .INTERNAL_SERVER_ERROR )
@@ -331,6 +388,9 @@ private boolean isStringEmpty(final String theString) {
331388 * The group String parameter.
332389 * @param projectString
333390 * The project String parameter.
391+ * @param updated
392+ * True if the method give back the worklogs which were created or updated in the given period, else
393+ * false. The false give back the worklogs of the period.
334394 * @return JSONString what contains a list of queried worklogs.
335395 * @throws ParseException
336396 * If can't parse the dates.
@@ -340,7 +400,7 @@ private boolean isStringEmpty(final String theString) {
340400 * If the createWorklogJSONObject method throw a JSONException.
341401 */
342402 private String worklogQuery (final Calendar startDate , final Calendar endDate , final String userString ,
343- final String groupString , final String projectString )
403+ final String groupString , final String projectString , final boolean updated )
344404 throws ParseException , GenericEntityException , JSONException {
345405
346406 List <JSONObject > worklogs = new ArrayList <JSONObject >();
@@ -350,11 +410,19 @@ private String worklogQuery(final Calendar startDate, final Calendar endDate, fi
350410 User user = authenticationContext .getLoggedInUser ();
351411
352412 // Date expr
353- EntityExpr startExpr = new EntityExpr ("startdate" , EntityOperator .GREATER_THAN_EQUAL_TO ,
354- new Timestamp (startDate .getTimeInMillis ()));
355- EntityExpr endExpr = new EntityExpr ("startdate" , EntityOperator .LESS_THAN ,
356- new Timestamp (endDate .getTimeInMillis ()));
357-
413+ EntityExpr startExpr ;
414+ EntityExpr endExpr ;
415+ if (updated ) {
416+ startExpr = new EntityExpr ("updated" , EntityOperator .GREATER_THAN_EQUAL_TO ,
417+ new Timestamp (startDate .getTimeInMillis ()));
418+ endExpr = new EntityExpr ("updated" , EntityOperator .LESS_THAN ,
419+ new Timestamp (endDate .getTimeInMillis ()));
420+ } else {
421+ startExpr = new EntityExpr ("startdate" , EntityOperator .GREATER_THAN_EQUAL_TO ,
422+ new Timestamp (startDate .getTimeInMillis ()));
423+ endExpr = new EntityExpr ("startdate" , EntityOperator .LESS_THAN ,
424+ new Timestamp (endDate .getTimeInMillis ()));
425+ }
358426 // set the users condition
359427 List <EntityExpr > usersConditions = createUsersConditions (userString , groupString );
360428 EntityCondition userCondition = new EntityConditionList (usersConditions , EntityOperator .OR );
0 commit comments