Skip to content

Commit

Permalink
Merge pull request #60 from m-herold/develop
Browse files Browse the repository at this point in the history
Release 2.4.3
  • Loading branch information
m-herold authored Jun 4, 2021
2 parents f183342 + bd5e8bc commit ab3df38
Show file tree
Hide file tree
Showing 29 changed files with 330 additions and 97 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.2</version>
<version>2.4.3</version>

<organization>
<name>International Catrobat Association</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ enum State {
@Ignore
int calculateTotalHours();

@Ignore
TimesheetEntry[] getEntriesDesc();

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,10 @@ public final int calculateTotalHours() {

return (sumTotalMinutes / 60);
}

public final TimesheetEntry[] getEntriesDesc() {
TimesheetEntry[] entries = timesheet.getEntries();
Arrays.sort(entries, Comparator.comparing(TimesheetEntry::getBeginDate).reversed());
return entries;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Response getMonitoring(@Context HttpServletRequest request) {

Monitoring monitoring = monitoringService.getMonitoring();
JsonMonitoring jsonMonitoring = new JsonMonitoring(monitoring);
jsonMonitoring.setPeriodTime(monitoringService.getLastIntervalFormattedAsString());
jsonMonitoring.setPeriodTime(monitoringService.formatIntervalToString(monitoringService.getCurrentInterval()));

return Response.ok(jsonMonitoring).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public Response getTimesheetEntriesOfAllTeamMembers(@Context HttpServletRequest
Timesheet sheet = sheetService.getTimesheetByUser(userKey);

//all entries of each user
TimesheetEntry[] entries = entryService.getEntriesBySheet(sheet);
TimesheetEntry[] entries = sheet.getEntriesDesc();

// Add entries anonymously
for (TimesheetEntry entry : entries) {
Expand Down Expand Up @@ -234,7 +234,7 @@ public Response getAllTimesheetEntriesForTeam(@Context HttpServletRequest reques
if (!permissionService.userCanViewTimesheet(user, timesheetByUser)) {
return Response.status(Response.Status.UNAUTHORIZED).entity("You are not allowed to see the timesheet.").build();
}
timesheetEntries = timesheetByUser.getEntries();
timesheetEntries = timesheetByUser.getEntriesDesc();
} catch (ServiceException e) {
return Response.serverError().entity("At least one Team Member has no valid Timesheet Entries.").build();
}
Expand Down Expand Up @@ -391,7 +391,7 @@ public Response getTimesheetEntries(@Context HttpServletRequest request,
return Response.status(Response.Status.UNAUTHORIZED).entity("You are not allowed to see the timesheet.").build();
}

TimesheetEntry[] entries = entryService.getEntriesBySheet(sheet);
TimesheetEntry[] entries = sheet.getEntriesDesc();

List<JsonTimesheetEntry> jsonEntries = new ArrayList<>(entries.length);

Expand Down Expand Up @@ -836,7 +836,7 @@ public Response deleteTimesheetEntry(@Context HttpServletRequest request,

//update latest timesheet entry date if latest entry date is < new latest entry in the table
if (sheet.getEntries().length > 0) {
if (entry.getBeginDate().compareTo(entryService.getEntriesBySheet(sheet)[0].getBeginDate()) > 0) {
if (entry.getBeginDate().compareTo(sheet.getEntriesDesc()[0].getBeginDate()) > 0) {
sheetService.editTimesheets(ComponentAccessor.
getUserKeyService().getKeyForUsername(user.getUsername()),
sheet.getTargetHours(), deducted_hours,
Expand Down Expand Up @@ -921,7 +921,7 @@ public Response getInactiveUsers(@Context HttpServletRequest request) {
ArrayList<Timesheet> timesheets = new ArrayList<>();

for (Timesheet timesheet : timesheetList) {
if (entryService.getEntriesBySheet(timesheet).length == 0) { // nothing to do
if (timesheet.getEntries().length == 0) { // nothing to do
continue;
}
if (timesheet.getState() != Timesheet.State.ACTIVE) {
Expand Down
17 changes: 8 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,7 +43,6 @@
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 @@ -139,6 +138,8 @@ public Response getUserInformation(@Context HttpServletRequest request) {
private List<JsonUserInformation> timesheetsToJson(List<Timesheet> timesheetList)
{
List<JsonUserInformation> jsonUserInformationList = new ArrayList<>();
Map.Entry<LocalDate, LocalDate> cur_interval = monitoringService.getCurrentInterval();
Map.Entry<LocalDate, LocalDate> last_interval = monitoringService.getLastInterval();

for (Timesheet timesheet : timesheetList) {

Expand All @@ -149,11 +150,9 @@ private List<JsonUserInformation> timesheetsToJson(List<Timesheet> timesheetList

JsonUserInformation jsonUserInformation = new JsonUserInformation(timesheet);

Map.Entry<LocalDate, LocalDate> interval = monitoringService.getLastInterval();

jsonUserInformation.setHoursPerHalfYear(timesheetEntryService.getHoursOfLastXMonths(timesheet, 6));
jsonUserInformation.setHoursPerMonth(timesheetEntryService.getHoursOfLastXMonths(timesheet, 1));
jsonUserInformation.setHoursPerMonitoringPeriod(timesheetEntryService.getHours(timesheet, interval.getKey(), interval.getValue()));
jsonUserInformation.setHoursPerMonitoringPeriod(timesheetEntryService.getHours(timesheet, cur_interval.getKey(), cur_interval.getValue()));
jsonUserInformation.setHoursPerLastMonitoringPeriod(timesheetEntryService.getHours(timesheet, last_interval.getKey(), last_interval.getValue()));

TimesheetEntry latestInactiveEntry = timesheetEntryService.getLatestInactiveEntry(timesheet);
if (latestInactiveEntry != null && (timesheet.getState() == Timesheet.State.INACTIVE
Expand Down Expand Up @@ -295,6 +294,8 @@ public Response getUsersForCoordinator(@Context HttpServletRequest request, @Pat


List<JsonUserInformation> jsonUserInformationListForCoordinator = new ArrayList<>();
Map.Entry<LocalDate, LocalDate> cur_interval = monitoringService.getCurrentInterval();
Map.Entry<LocalDate, LocalDate> last_interval = monitoringService.getLastInterval();

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

Expand Down Expand Up @@ -342,11 +343,9 @@ public Response getUsersForCoordinator(@Context HttpServletRequest request, @Pat

jsonUserInformation.setTeams(teamString.toString());

Map.Entry<LocalDate, LocalDate> interval = monitoringService.getLastInterval();

jsonUserInformation.setHoursPerHalfYear(timesheetEntryService.getHoursOfLastXMonths(timesheet, 6));
jsonUserInformation.setHoursPerMonth(timesheetEntryService.getHoursOfLastXMonths(timesheet, 1));
jsonUserInformation.setHoursPerMonitoringPeriod(timesheetEntryService.getHours(timesheet, interval.getKey(), interval.getValue()));
jsonUserInformation.setHoursPerMonitoringPeriod(timesheetEntryService.getHours(timesheet, cur_interval.getKey(), cur_interval.getValue()));
jsonUserInformation.setHoursPerLastMonitoringPeriod(timesheetEntryService.getHours(timesheet, last_interval.getKey(), last_interval.getValue()));

TimesheetEntry latestInactiveEntry = timesheetEntryService.getLatestInactiveEntry(timesheet);
if (latestInactiveEntry != null && (timesheet.getState() == Timesheet.State.INACTIVE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public class JsonUserInformation {
@XmlElement
private Timesheet.State state;
@XmlElement
private int hoursPerMonth;
@XmlElement
private int hoursPerHalfYear;
@XmlElement
private int hoursPerMonitoringPeriod;
@XmlElement
private int hoursPerLastMonitoringPeriod;
@XmlElement
private int remainingHours;
@XmlElement
private int targetTotalHours;
Expand Down Expand Up @@ -86,14 +86,6 @@ public void setState(Timesheet.State state) {
this.state = state;
}

public int getHoursPerMonth() {
return hoursPerMonth;
}

public void setHoursPerMonth(int hoursPerMonth) {
this.hoursPerMonth = hoursPerMonth;
}

public int getHoursPerMonitoringPeriod(){
return hoursPerMonitoringPeriod;
}
Expand All @@ -102,6 +94,14 @@ public void setHoursPerMonitoringPeriod(int hoursPerMonitoringPeriod) {
this.hoursPerMonitoringPeriod = hoursPerMonitoringPeriod;
}

public int getHoursPerLastMonitoringPeriod(){
return hoursPerLastMonitoringPeriod;
}

public void setHoursPerLastMonitoringPeriod(int hoursPerLastMonitoringPeriod) {
this.hoursPerLastMonitoringPeriod = hoursPerLastMonitoringPeriod;
}

public int getHoursPerHalfYear() {
return hoursPerHalfYear;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void execute(Map<String, Object> map) {
String userKey = timesheet.getUserKey();
ApplicationUser user = ComponentAccessor.getUserManager().getUserByKey(userKey);

if (entryService.getEntriesBySheet(timesheet).length == 0) { // nothing to do
if (timesheet.getEntries().length == 0) { // nothing to do
continue;
}
if (timesheet.getState() == Timesheet.State.INACTIVE_OFFLINE) { // user is offline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void execute(Map<String, Object> map) {
ApplicationUser user = ComponentAccessor.getUserManager().getUserByKey(userKey);
String statusFlagMessage = "nothing changed";

TimesheetEntry[] entries = entryService.getEntriesBySheet(timesheet);
TimesheetEntry[] entries = timesheet.getEntries();
if (entries.length == 0) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ public interface MonitoringService {

void setMonitoring(int period, int requiredHours, int exceptions);

Map.Entry<LocalDate, LocalDate> getCurrentInterval();

Map.Entry<LocalDate, LocalDate> getLastInterval();

String getLastIntervalFormattedAsString();
String formatIntervalToString(Map.Entry<LocalDate, LocalDate> interval);

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ TimesheetEntry edit(int entryID, Timesheet sheet, Date begin, Date end, Category

TimesheetEntry getEntryByID(int entryID);

TimesheetEntry[] getEntriesBySheet(Timesheet sheet);

void delete(TimesheetEntry entry) throws ServiceException;

int getHoursOfLastXMonths(Timesheet sheet, int months);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void setMonitoring(int period, int requiredHours, int exceptions) {
}

@Override
public Map.Entry<LocalDate, LocalDate> getLastInterval() {
public Map.Entry<LocalDate, LocalDate> getCurrentInterval() {
LocalDate begin = LocalDate.now().withDayOfMonth(1);
LocalDate end = LocalDate.now();
if (getMonitoring().getPeriod() > 1) {
Expand All @@ -68,10 +68,18 @@ public Map.Entry<LocalDate, LocalDate> getLastInterval() {
return new AbstractMap.SimpleEntry<>(begin, end);
}

@Override
public String getLastIntervalFormattedAsString() {
public Map.Entry<LocalDate, LocalDate> getLastInterval() {
Map.Entry<LocalDate, LocalDate> current_interval = getCurrentInterval();
LocalDate begin = current_interval.getKey().minusMonths(getMonitoring().getPeriod());
LocalDate end = current_interval.getKey().minusDays(1);
if (getMonitoring().getPeriod() < 1) {
begin = end.withDayOfMonth(1);
}
return new AbstractMap.SimpleEntry<>(begin, end);
}

public String formatIntervalToString(Map.Entry<LocalDate, LocalDate> interval) {
DateTimeFormatter formatter;
Map.Entry<LocalDate, LocalDate> interval = getLastInterval();
if (interval.getKey().getYear() != interval.getValue().getYear()) {
formatter = DateTimeFormatter.ofPattern("dd.MM.yy");
} else if(interval.getKey().getMonth() != interval.getValue().getMonth()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.atlassian.activeobjects.external.ActiveObjects;
import com.atlassian.jira.service.ServiceException;
import net.java.ao.Query;
import org.catrobat.jira.timesheet.activeobjects.Category;
import org.catrobat.jira.timesheet.activeobjects.Team;
import org.catrobat.jira.timesheet.activeobjects.Timesheet;
Expand All @@ -28,7 +27,6 @@
import org.springframework.stereotype.Component;

import javax.annotation.Nullable;
import java.sql.Time;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
Expand Down Expand Up @@ -61,17 +59,17 @@ public TimesheetEntry add(Timesheet sheet, Date begin, Date end, Category catego
}

private TimesheetEntry setTimesheetEntryData(Timesheet sheet, Date begin, Date end, Category category, String description,
int pause, Team team, boolean isGoogleDocImport, Date inactiveEndDate, String jiraTicketID, String userName,
int pauseMin, Team team, boolean isGoogleDocImport, Date inactiveEndDate, String jiraTicketID, String userName,
boolean teamroom, TimesheetEntry entry) throws ServiceException {

checkParams(begin, end, category, description, team, jiraTicketID, userName);
checkParams(begin, end, category, description, team, jiraTicketID, userName, pauseMin);

entry.setTimeSheet(sheet);
entry.setBeginDate(begin);
entry.setEndDate(end);
entry.setCategory(category);
entry.setDescription(description);
entry.setPauseMinutes(pause);
entry.setPauseMinutes(pauseMin);
entry.setTeam(team);
entry.setIsGoogleDocImport(isGoogleDocImport);
entry.setTeamroom(teamroom);
Expand All @@ -85,7 +83,7 @@ private TimesheetEntry setTimesheetEntryData(Timesheet sheet, Date begin, Date e

private void checkParams(Date begin, Date end, Category category, String description,
Team team, String jiraTicketID,
String userName) throws ServiceException {
String userName, int pauseMin) throws ServiceException {
if (team == null) {
throw new ServiceException("TimesheetEntry is not allowed with null Team.");
}
Expand All @@ -104,6 +102,10 @@ private void checkParams(Date begin, Date end, Category category, String descrip
if (begin.compareTo(end) > 0) {
throw new ServiceException("Begin Date must be before End Date.");
}
long workMin = (end.getTime() - begin.getTime()) / (1000 * 60);
if(pauseMin > workMin) {
throw new ServiceException("The break duration should not be larger than the working time.");
}
}

private void updateTimesheet(Timesheet sheet, TimesheetEntry entry) throws ServiceException {
Expand Down Expand Up @@ -168,17 +170,6 @@ public TimesheetEntry edit(int entryId, Timesheet sheet, Date begin, Date end, C
inactiveEndDate, jiraTicketID, userName, teamroom, entry);
}

@Override
public TimesheetEntry[] getEntriesBySheet(Timesheet sheet) {
if (sheet == null) return new TimesheetEntry[0];
return ao.find(
TimesheetEntry.class,
Query.select()
.where("TIME_SHEET_ID = ?", sheet.getID())
.order("BEGIN_DATE DESC")
);
}

@Override
public void delete(TimesheetEntry entry) throws ServiceException {
Timesheet timesheet = entry.getTimeSheet();
Expand All @@ -197,7 +188,7 @@ public void delete(TimesheetEntry entry) throws ServiceException {
public int getHoursOfLastXMonths(Timesheet sheet, int months) {
ZonedDateTime xMonthsAgo = ZonedDateTime.now().minusMonths(months);
int minutes = 0;
for (TimesheetEntry entry : getEntriesBySheet(sheet)) {
for (TimesheetEntry entry : sheet.getEntries()) {
Instant instant = entry.getBeginDate().toInstant();
ZonedDateTime beginDate = instant.atZone(ZoneId.systemDefault());
if (beginDate.isAfter(xMonthsAgo)) {
Expand All @@ -210,7 +201,7 @@ public int getHoursOfLastXMonths(Timesheet sheet, int months) {
@Override
public int getHours(Timesheet sheet, LocalDate begin, LocalDate end){
int minutes = 0;
for (TimesheetEntry entry : getEntriesBySheet(sheet)) {
for (TimesheetEntry entry : sheet.getEntries()) {
Instant instant = entry.getBeginDate().toInstant();
LocalDate beginDate = instant.atZone(ZoneId.systemDefault()).toLocalDate();

Expand All @@ -223,7 +214,7 @@ public int getHours(Timesheet sheet, LocalDate begin, LocalDate end){

@Override
public TimesheetEntry getLatestEntry(Timesheet timesheet) {
TimesheetEntry[] entries = this.getEntriesBySheet(timesheet);
TimesheetEntry[] entries = timesheet.getEntriesDesc();
if (entries.length == 0) {
return null;
}
Expand All @@ -232,7 +223,7 @@ public TimesheetEntry getLatestEntry(Timesheet timesheet) {

@Override
public TimesheetEntry getLatestInactiveEntry(Timesheet timesheet) {
TimesheetEntry[] entries = this.getEntriesBySheet(timesheet);
TimesheetEntry[] entries = timesheet.getEntries();
for (TimesheetEntry entry : entries) {
String categoryName = entry.getCategory().getName();
if ((categoryName.equals(SpecialCategories.INACTIVE) || categoryName.equals(SpecialCategories.INACTIVE_OFFLINE))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro

List<Timesheet> timesheetList = sheetService.all();
for (Timesheet timesheet : timesheetList) {
TimesheetEntry[] entries = entryService.getEntriesBySheet(timesheet);
TimesheetEntry[] entries = timesheet.getEntriesDesc();

List<JsonTimesheetEntry> jsonEntries = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
response.sendError(HttpServletResponse.SC_CONFLICT, "You are not allowed to see the timesheet.");
}

TimesheetEntry[] entries = entryService.getEntriesBySheet(timesheet);
TimesheetEntry[] entries = timesheet.getEntriesDesc();

List<JsonTimesheetEntry> jsonEntries = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
paramMap.put("isAdmin", permissionService.isJiraAdministrator(user));
}

paramMap.put("monitoringPeriod", monitoringService.getLastIntervalFormattedAsString());
paramMap.put("monitoringPeriod", monitoringService.formatIntervalToString(monitoringService.getCurrentInterval()));
paramMap.put("lastMonitoringPeriod", monitoringService.formatIntervalToString(monitoringService.getLastInterval()));
paramMap.put("isCoordinator", permissionService.isUserTeamCoordinator(user));
paramMap.put("isReadOnlyUser", permissionService.isReadOnlyUser(user));
paramMap.put("timesheetID", timesheet.getID());
Expand Down
Loading

0 comments on commit ab3df38

Please sign in to comment.