Skip to content

Commit

Permalink
ATLDEV-304 Refactor user information (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brunner-Leo authored May 7, 2021
1 parent 2f4b2c6 commit 7f5a837
Show file tree
Hide file tree
Showing 8 changed files with 397 additions and 207 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.catrobat.jira</groupId>
<artifactId>timesheet</artifactId>
<version>2.4.1</version>
<version>2.4.2</version>

<organization>
<name>International Catrobat Association</name>
Expand Down
49 changes: 40 additions & 9 deletions src/main/java/org/catrobat/jira/timesheet/rest/UserRest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.sql.Time;
import java.time.LocalDate;
import java.util.*;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -126,18 +127,20 @@ public Response getUsers(@Context HttpServletRequest request) {
@Path("/getUserInformation")
@Produces(MediaType.APPLICATION_JSON)
public Response getUserInformation(@Context HttpServletRequest request) {

logger.debug("1 /getUserInformation reached");
Date date = new Date();

Response response = permissionService.checkRootPermission();
if (response != null) {
return response;
}
List<JsonUserInformation> jsonUserInformationList = timesheetsToJson(timesheetService.all());

return Response.ok(jsonUserInformationList).build();
}

private List<JsonUserInformation> timesheetsToJson(List<Timesheet> timesheetList)
{
List<JsonUserInformation> jsonUserInformationList = new ArrayList<>();

for (Timesheet timesheet : timesheetService.all()) {
for (Timesheet timesheet : timesheetList) {

ApplicationUser u = ComponentAccessor.getUserManager().getUserByKey(timesheet.getUserKey());
if (u == null) {
Expand Down Expand Up @@ -191,15 +194,43 @@ public Response getUserInformation(@Context HttpServletRequest request) {

jsonUserInformationList.add(jsonUserInformation);
}
return jsonUserInformationList;
}

Date date1 = new Date();
long diffInMillies = date1.getTime() - date.getTime();
TimeUnit timeUnit = TimeUnit.SECONDS;
logger.debug("2 /getUserInformation diffInMillies/diffInSeconds: " + diffInMillies + "/" + timeUnit.convert(diffInMillies, TimeUnit.MILLISECONDS));
@GET
@Path("/getUserInformation/{State}")
@Produces(MediaType.APPLICATION_JSON)
public Response getUserInformationWithState(@Context HttpServletRequest request, @PathParam("State") String state) {
Response response = permissionService.checkRootPermission();
if (response != null) {
return response;
}
List<JsonUserInformation> jsonUserInformationList = timesheetsToJson(timesheetService.allWithState(state));

return Response.ok(jsonUserInformationList).build();
}

@GET
@Path("/getUserInformationStats")
@Produces(MediaType.APPLICATION_JSON)
public Response getUserInformationStats(@Context HttpServletRequest request) {
Response response = permissionService.checkRootPermission();
if (response != null) {
return response;
}

List<String> states = Arrays.asList("ACTIVE", "INACTIVE", "AUTO_INACTIVE", "INACTIVE_OFFLINE", "DISABLED", "DONE");

List<Integer> userInformationStats = new ArrayList<>();

for (String state : states) {
userInformationStats.add(timesheetService.getStateAmount(state));
}

return Response.ok(userInformationStats).build();
}


@GET
@Path("/getUsersForCoordinator/{currentTimesheetID}")
@Produces(MediaType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ Timesheet add(String userKey, String displayName,
@NotNull
List<Timesheet> all();

@NotNull
List<Timesheet> allWithState(String state);

@NotNull
int getStateAmount(String state);

@Nullable
Timesheet updateTimesheetEnableState(int timesheetID, Boolean isEnabled) throws ServiceException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ public List<Timesheet> all() {
return newArrayList(ao.find(Timesheet.class));
}

@NotNull
@Override
public List<Timesheet> allWithState(String state) {
return newArrayList(ao.find(Timesheet.class, "STATE = ?", state));
}

@NotNull
@Override
public int getStateAmount(String state) {
return ao.find(Timesheet.class, "STATE = ?", state).length;
}

@Nullable
@Override
public Timesheet updateTimesheetEnableState(int timesheetID, Boolean isEnabled) throws ServiceException {
Expand Down
Loading

0 comments on commit 7f5a837

Please sign in to comment.