Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<parent>
<groupId>org.everit.jira.worklog.query.plugin</groupId>
<artifactId>main</artifactId>
<version>1.0.0</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>org.everit.jira.worklog.query.plugin.core</artifactId>
Expand Down Expand Up @@ -58,11 +58,32 @@
</build>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>com.atlassian.crowd</groupId>
<artifactId>embedded-crowd-api</artifactId>
<version>2.2.8</version>
</dependency>
<dependency>
<groupId>com.atlassian.ofbiz</groupId>
<artifactId>entityengine</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>atlassian-jira</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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<JSONObject> worklogs = new ArrayList<JSONObject>();
Expand All @@ -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<EntityExpr> usersConditions = createUsersConditions(userString, groupString);
EntityCondition userCondition = new EntityConditionList(usersConditions, EntityOperator.OR);
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/resources/atlassian-plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
plugins-version="2">

<plugin-info>
<version>1.0.0</version>
<version>1.1.0</version>
<description>Jira Worklog Query Plugin</description>
<application-version min="4.4" />
<vendor name="EverIT Kft." url="https://www.everit.biz" />
</plugin-info>

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

Expand Down
2 changes: 1 addition & 1 deletion itest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<parent>
<groupId>org.everit.jira.worklog.query.plugin</groupId>
<artifactId>main</artifactId>
<version>1.0.0</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>org.everit.jira.worklog.query.plugin.itest</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

<groupId>org.everit.jira.worklog.query.plugin</groupId>
<artifactId>main</artifactId>
<version>1.0.0</version>
<version>1.1.0-SNAPSHOT</version>

<packaging>pom</packaging>

Expand Down