Skip to content

Commit 964a541

Browse files
Merge pull request #3 from everit-org/v1.1.0-SNAPSHOT
prepare release v1.1.0
2 parents 8f4d942 + 7d5f6d3 commit 964a541

File tree

6 files changed

+146
-20
lines changed

6 files changed

+146
-20
lines changed

core/pom.xml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<parent>
3030
<groupId>org.everit.jira.worklog.query.plugin</groupId>
3131
<artifactId>main</artifactId>
32-
<version>1.0.0</version>
32+
<version>1.1.0-SNAPSHOT</version>
3333
</parent>
3434

3535
<artifactId>org.everit.jira.worklog.query.plugin.core</artifactId>
@@ -58,11 +58,32 @@
5858
</build>
5959

6060
<dependencies>
61+
<dependency>
62+
<groupId>org.slf4j</groupId>
63+
<artifactId>slf4j-api</artifactId>
64+
<version>1.5.8</version>
65+
</dependency>
66+
<dependency>
67+
<groupId>com.atlassian.crowd</groupId>
68+
<artifactId>embedded-crowd-api</artifactId>
69+
<version>2.2.8</version>
70+
</dependency>
71+
<dependency>
72+
<groupId>com.atlassian.ofbiz</groupId>
73+
<artifactId>entityengine</artifactId>
74+
<version>1.0.3</version>
75+
</dependency>
6176
<dependency>
6277
<groupId>com.atlassian.jira</groupId>
6378
<artifactId>atlassian-jira</artifactId>
6479
<version>${jira.version}</version>
6580
<scope>provided</scope>
81+
<exclusions>
82+
<exclusion>
83+
<groupId>*</groupId>
84+
<artifactId>*</artifactId>
85+
</exclusion>
86+
</exclusions>
6687
</dependency>
6788
<dependency>
6889
<groupId>javax.ws.rs</groupId>

core/src/main/java/org/everit/jira/worklog/query/plugin/core/WorklogQueryResource.java

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
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")
6363
public 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);

core/src/main/resources/atlassian-plugin.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
plugins-version="2">
2525

2626
<plugin-info>
27-
<version>1.0.0</version>
27+
<version>1.1.0</version>
2828
<description>Jira Worklog Query Plugin</description>
2929
<application-version min="4.4" />
3030
<vendor name="EverIT Kft." url="https://www.everit.biz" />
3131
</plugin-info>
3232

33-
<rest key="JWQP" path="/jira-worklog-query" version="1.0.0">
33+
<rest key="JWQP" path="/jira-worklog-query" version="1.1.0">
3434
<description>Provides the REST resource for the Worklog Query plugin.</description>
3535
</rest>
3636

itest/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<parent>
3030
<groupId>org.everit.jira.worklog.query.plugin</groupId>
3131
<artifactId>main</artifactId>
32-
<version>1.0.0</version>
32+
<version>1.1.0-SNAPSHOT</version>
3333
</parent>
3434

3535
<artifactId>org.everit.jira.worklog.query.plugin.itest</artifactId>

itest/src/main/java/org/everit/jira/worklog/query/test/WorklogQueryTest.java

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ public final class WorklogQueryTest {
4242
* The status code of the unsuccessful authorization.
4343
*/
4444
public static final int INVALID_AUTHOR_STATUS = 401;
45+
/**
46+
* The user name for authentication.
47+
*/
48+
public static final String USERNAME = "admin";
49+
/**
50+
* The password for authentication.
51+
*/
52+
public static final String PASSWORD = "admin";
4553

4654
/**
4755
* The WorklogQueryTest class main method.
@@ -52,6 +60,7 @@ public final class WorklogQueryTest {
5260
public static void main(final String[] args) {
5361
try {
5462
WorklogQueryTest.simpleClientTest();
63+
WorklogQueryTest.simpleClientUpdateTest();
5564
} catch (Exception e) {
5665
LOGGER.error("Fail to test jira-worklog-query", e);
5766
}
@@ -64,14 +73,42 @@ public static void main(final String[] args) {
6473
* If any Exception happen.
6574
*/
6675
public static void simpleClientTest() throws Exception {
67-
String username = "admin";
68-
String password = "admin";
6976
String url =
70-
"http://127.0.0.1:8080/"
71-
+ "rest/jira-worklog-query/1.0.0/"
72-
+ "findWorklogs?startDate=2012-12-12&user=admin&project=TESTTWO";
77+
"http://localhost:8080/"
78+
+ "rest/jira-worklog-query/1.1.0/"
79+
+ "find/"
80+
+ "worklogs?startDate=2012-12-12&user=admin";
81+
LOGGER.info("Start the simple test");
82+
byte[] authByteArray = Base64.encode(USERNAME + ":" + PASSWORD);
83+
String auth = new String(authByteArray, "UTF8");
84+
Client client = Client.create();
85+
WebResource webResource = client.resource(url);
86+
ClientResponse response = webResource.header("Authorization", "Basic " + auth).type("application/json")
87+
.accept("application/json").get(ClientResponse.class);
88+
int statusCode = response.getStatus();
89+
90+
if (statusCode == INVALID_AUTHOR_STATUS) {
91+
throw new Exception("Invalid Username or Password");
92+
}
93+
final String stringResponse = response.getEntity(String.class);
94+
LOGGER.info("sr: " + stringResponse);
95+
96+
}
97+
98+
/**
99+
* The jira-worklog-query HTTP BASIC AUTHORIZATION test.
100+
*
101+
* @throws Exception
102+
* If any Exception happen.
103+
*/
104+
public static void simpleClientUpdateTest() throws Exception {
105+
String url =
106+
"http://localhost:8080/"
107+
+ "rest/jira-worklog-query/1.1.0/"
108+
+ "find/"
109+
+ "updatedWorklogs?startDate=2013-04-15&user=admin";
73110
LOGGER.info("Start the simple test");
74-
byte[] authByteArray = Base64.encode(username + ":" + password);
111+
byte[] authByteArray = Base64.encode(USERNAME + ":" + PASSWORD);
75112
String auth = new String(authByteArray, "UTF8");
76113
Client client = Client.create();
77114
WebResource webResource = client.resource(url);

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
<groupId>org.everit.jira.worklog.query.plugin</groupId>
3636
<artifactId>main</artifactId>
37-
<version>1.0.0</version>
37+
<version>1.1.0-SNAPSHOT</version>
3838

3939
<packaging>pom</packaging>
4040

0 commit comments

Comments
 (0)