diff --git a/core/pom.xml b/core/pom.xml
index 6618097..637f4c5 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -29,7 +29,7 @@
org.everit.jira.worklog.query.plugin
main
- 1.0.0
+ 1.1.0-SNAPSHOT
org.everit.jira.worklog.query.plugin.core
@@ -58,11 +58,32 @@
+
+ org.slf4j
+ slf4j-api
+ 1.5.8
+
+
+ com.atlassian.crowd
+ embedded-crowd-api
+ 2.2.8
+
+
+ com.atlassian.ofbiz
+ entityengine
+ 1.0.3
+
com.atlassian.jira
atlassian-jira
${jira.version}
provided
+
+
+ *
+ *
+
+
javax.ws.rs
diff --git a/core/src/main/java/org/everit/jira/worklog/query/plugin/core/WorklogQueryResource.java b/core/src/main/java/org/everit/jira/worklog/query/plugin/core/WorklogQueryResource.java
index 8cf49d2..478cb04 100644
--- a/core/src/main/java/org/everit/jira/worklog/query/plugin/core/WorklogQueryResource.java
+++ b/core/src/main/java/org/everit/jira/worklog/query/plugin/core/WorklogQueryResource.java
@@ -59,7 +59,7 @@
/**
* The WorklogQueryResource class. The class contains the findWorklogs method. The class grant the JIRA worklog query.
*/
-@Path("/findWorklogs")
+@Path("/find")
public class WorklogQueryResource {
/**
@@ -250,7 +250,7 @@ private JSONObject createWorklogJSONObject(final GenericValue worklog) throws JS
}
/**
- * The findWorklogs restful api method.
+ * The updatedWorklogs restful api method.
*
* @param startDate
* The query startDate parameter.
@@ -268,6 +268,63 @@ private JSONObject createWorklogJSONObject(final GenericValue worklog) throws JS
*/
@GET
@Produces("*/*")
+ @Path("/updatedWorklogs")
+ public Response findUpdatedWorklogs(
+ @QueryParam("startDate") final String startDate,
+ @QueryParam("endDate") final String endDate,
+ @QueryParam("user") final String user,
+ @QueryParam("group") final String group,
+ @QueryParam("project") final String project) {
+
+ Response checkRequiredFindWorklogsParamResponse = checkRequiredFindWorklogsParameter(startDate, user, group);
+ if (checkRequiredFindWorklogsParamResponse != null) {
+ return checkRequiredFindWorklogsParamResponse;
+ }
+ Calendar startDateCalendar;
+ try {
+ startDateCalendar = convertStartDate(startDate);
+ } catch (ParseException e) {
+ LOGGER.debug("Failed to convert start date", e);
+ return Response.status(Response.Status.BAD_REQUEST)
+ .entity("Cannot parse the 'startDate' parameter: " + startDate).build();
+ }
+ Calendar endDateCalendar;
+ try {
+ endDateCalendar = convertEndDate(endDate);
+ } catch (ParseException e) {
+ LOGGER.debug("Failed to convert end date", e);
+ return Response.status(Response.Status.BAD_REQUEST)
+ .entity("Cannot parse the 'endDate' parameter: " + endDate).build();
+ }
+ try {
+ return Response.ok(worklogQuery(startDateCalendar, endDateCalendar, user, group, project, true)).build();
+ } catch (Exception e) {
+ LOGGER.error("Failed to query the worklogs", e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
+ .entity(e.getMessage()).build();
+ }
+ }
+
+ /**
+ * The worklogs restful api method.
+ *
+ * @param startDate
+ * The query startDate parameter.
+ * @param endDate
+ * The query endDate parameter, optional. Default value is the current time.
+ * @param user
+ * The query user parameter, optional. This or the group parameter is required.
+ * @param group
+ * The query group parameter, optional. This or the user parameter is required.
+ * @param project
+ * The query project parameter, optional. Default is all project.
+ * @return {@link Response} what contains the result of the query. If the method parameters was wrong then a message
+ * what contains the description of the bad request. In case of any exception return {@link Response} with
+ * INTERNAL_SERVER_ERROR status what contains the original exception message.
+ */
+ @GET
+ @Produces("*/*")
+ @Path("/worklogs")
public Response findWorklogs(
@QueryParam("startDate") final String startDate,
@QueryParam("endDate") final String endDate,
@@ -296,7 +353,7 @@ public Response findWorklogs(
.entity("Cannot parse the 'endDate' parameter: " + endDate).build();
}
try {
- return Response.ok(worklogQuery(startDateCalendar, endDateCalendar, user, group, project)).build();
+ return Response.ok(worklogQuery(startDateCalendar, endDateCalendar, user, group, project, false)).build();
} catch (Exception e) {
LOGGER.error("Failed to query the worklogs", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
@@ -331,6 +388,9 @@ private boolean isStringEmpty(final String theString) {
* The group String parameter.
* @param projectString
* The project String parameter.
+ * @param updated
+ * True if the method give back the worklogs which were created or updated in the given period, else
+ * false. The false give back the worklogs of the period.
* @return JSONString what contains a list of queried worklogs.
* @throws ParseException
* If can't parse the dates.
@@ -340,7 +400,7 @@ private boolean isStringEmpty(final String theString) {
* If the createWorklogJSONObject method throw a JSONException.
*/
private String worklogQuery(final Calendar startDate, final Calendar endDate, final String userString,
- final String groupString, final String projectString)
+ final String groupString, final String projectString, final boolean updated)
throws ParseException, GenericEntityException, JSONException {
List worklogs = new ArrayList();
@@ -350,11 +410,19 @@ private String worklogQuery(final Calendar startDate, final Calendar endDate, fi
User user = authenticationContext.getLoggedInUser();
// Date expr
- EntityExpr startExpr = new EntityExpr("startdate", EntityOperator.GREATER_THAN_EQUAL_TO,
- new Timestamp(startDate.getTimeInMillis()));
- EntityExpr endExpr = new EntityExpr("startdate", EntityOperator.LESS_THAN,
- new Timestamp(endDate.getTimeInMillis()));
-
+ EntityExpr startExpr;
+ EntityExpr endExpr;
+ if (updated) {
+ startExpr = new EntityExpr("updated", EntityOperator.GREATER_THAN_EQUAL_TO,
+ new Timestamp(startDate.getTimeInMillis()));
+ endExpr = new EntityExpr("updated", EntityOperator.LESS_THAN,
+ new Timestamp(endDate.getTimeInMillis()));
+ } else {
+ startExpr = new EntityExpr("startdate", EntityOperator.GREATER_THAN_EQUAL_TO,
+ new Timestamp(startDate.getTimeInMillis()));
+ endExpr = new EntityExpr("startdate", EntityOperator.LESS_THAN,
+ new Timestamp(endDate.getTimeInMillis()));
+ }
// set the users condition
List usersConditions = createUsersConditions(userString, groupString);
EntityCondition userCondition = new EntityConditionList(usersConditions, EntityOperator.OR);
diff --git a/core/src/main/resources/atlassian-plugin.xml b/core/src/main/resources/atlassian-plugin.xml
index 50296a8..82af3f7 100644
--- a/core/src/main/resources/atlassian-plugin.xml
+++ b/core/src/main/resources/atlassian-plugin.xml
@@ -24,13 +24,13 @@
plugins-version="2">
- 1.0.0
+ 1.1.0
Jira Worklog Query Plugin
-
+
Provides the REST resource for the Worklog Query plugin.
diff --git a/itest/pom.xml b/itest/pom.xml
index 5887655..f9efb84 100644
--- a/itest/pom.xml
+++ b/itest/pom.xml
@@ -29,7 +29,7 @@
org.everit.jira.worklog.query.plugin
main
- 1.0.0
+ 1.1.0-SNAPSHOT
org.everit.jira.worklog.query.plugin.itest
diff --git a/itest/src/main/java/org/everit/jira/worklog/query/test/WorklogQueryTest.java b/itest/src/main/java/org/everit/jira/worklog/query/test/WorklogQueryTest.java
index f2a116b..af39b8a 100644
--- a/itest/src/main/java/org/everit/jira/worklog/query/test/WorklogQueryTest.java
+++ b/itest/src/main/java/org/everit/jira/worklog/query/test/WorklogQueryTest.java
@@ -42,6 +42,14 @@ public final class WorklogQueryTest {
* The status code of the unsuccessful authorization.
*/
public static final int INVALID_AUTHOR_STATUS = 401;
+ /**
+ * The user name for authentication.
+ */
+ public static final String USERNAME = "admin";
+ /**
+ * The password for authentication.
+ */
+ public static final String PASSWORD = "admin";
/**
* The WorklogQueryTest class main method.
@@ -52,6 +60,7 @@ public final class WorklogQueryTest {
public static void main(final String[] args) {
try {
WorklogQueryTest.simpleClientTest();
+ WorklogQueryTest.simpleClientUpdateTest();
} catch (Exception e) {
LOGGER.error("Fail to test jira-worklog-query", e);
}
@@ -64,14 +73,42 @@ public static void main(final String[] args) {
* If any Exception happen.
*/
public static void simpleClientTest() throws Exception {
- String username = "admin";
- String password = "admin";
String url =
- "http://127.0.0.1:8080/"
- + "rest/jira-worklog-query/1.0.0/"
- + "findWorklogs?startDate=2012-12-12&user=admin&project=TESTTWO";
+ "http://localhost:8080/"
+ + "rest/jira-worklog-query/1.1.0/"
+ + "find/"
+ + "worklogs?startDate=2012-12-12&user=admin";
+ LOGGER.info("Start the simple test");
+ byte[] authByteArray = Base64.encode(USERNAME + ":" + PASSWORD);
+ String auth = new String(authByteArray, "UTF8");
+ Client client = Client.create();
+ WebResource webResource = client.resource(url);
+ ClientResponse response = webResource.header("Authorization", "Basic " + auth).type("application/json")
+ .accept("application/json").get(ClientResponse.class);
+ int statusCode = response.getStatus();
+
+ if (statusCode == INVALID_AUTHOR_STATUS) {
+ throw new Exception("Invalid Username or Password");
+ }
+ final String stringResponse = response.getEntity(String.class);
+ LOGGER.info("sr: " + stringResponse);
+
+ }
+
+ /**
+ * The jira-worklog-query HTTP BASIC AUTHORIZATION test.
+ *
+ * @throws Exception
+ * If any Exception happen.
+ */
+ public static void simpleClientUpdateTest() throws Exception {
+ String url =
+ "http://localhost:8080/"
+ + "rest/jira-worklog-query/1.1.0/"
+ + "find/"
+ + "updatedWorklogs?startDate=2013-04-15&user=admin";
LOGGER.info("Start the simple test");
- byte[] authByteArray = Base64.encode(username + ":" + password);
+ byte[] authByteArray = Base64.encode(USERNAME + ":" + PASSWORD);
String auth = new String(authByteArray, "UTF8");
Client client = Client.create();
WebResource webResource = client.resource(url);
diff --git a/pom.xml b/pom.xml
index 5d9d742..81476b5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,7 +34,7 @@
org.everit.jira.worklog.query.plugin
main
- 1.0.0
+ 1.1.0-SNAPSHOT
pom