Skip to content

Commit

Permalink
Merge pull request #43 from m-herold/ATLDEV-301
Browse files Browse the repository at this point in the history
ATLDEV-301 Support for Jira 8.13.*
  • Loading branch information
m-herold authored Jan 20, 2021
2 parents c216f98 + 9d626d6 commit 654fa1c
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 35 deletions.
36 changes: 23 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.catrobat.jira</groupId>
<artifactId>timesheet</artifactId>
<version>2.3</version>
<version>2.4</version>

<organization>
<name>Catrobat</name>
<name>International Catrobat Association</name>
<url>https://github.com/Catrobat</url>
</organization>

<name>Timesheet</name>
<description>A timesheet plugin for everyone</description>
<description>A timesheet plugin for teams</description>
<packaging>atlassian-plugin</packaging>

<dependencies>
Expand Down Expand Up @@ -92,8 +92,8 @@
<!-- We're going to write a simple servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>

Expand Down Expand Up @@ -154,6 +154,16 @@
<artifactId>jira-tests</artifactId>
<version>${jira.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.junit.jupiter</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
Expand Down Expand Up @@ -209,7 +219,7 @@
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-jira-plugin</artifactId>
<artifactId>jira-maven-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
Expand All @@ -226,7 +236,6 @@
</pluginArtifacts>
-->
<enableQuickReload>true</enableQuickReload>
<enableFastdev>false</enableFastdev>
<allowGoogleTracking>false</allowGoogleTracking>
<compressJs>${compressJs}</compressJs>

Expand All @@ -243,12 +252,13 @@
<Import-Package>
org.springframework.osgi.*;resolution:="optional",
org.eclipse.gemini.blueprint.*;resolution:="optional",
com.atlassian.jira.event,
com.atlassian.plugin.web.baseconditions,
javax.ws.rs*;version="[1,2)",
javax.servlet*;version="2.5",
javax.xml.bind*;version="[2.1,3)",
*;version="0";resolution:=optional,
org.springframework*;version="2.5",
junit*;version="[4.10,5)",
*;resolution:=optional
</Import-Package>

Expand Down Expand Up @@ -308,15 +318,15 @@
</build>

<properties>
<jira.version>7.11.2</jira.version>
<amps.version>6.2.6</amps.version>
<ao.version>1.2.0</ao.version>
<jira.version>8.13.3</jira.version>
<amps.version>8.0.2</amps.version>
<ao.version>3.0.0</ao.version>
<plugin.testrunner.version>1.2.3</plugin.testrunner.version>
<atlassian.spring.scanner.version>2.1.3</atlassian.spring.scanner.version>
<!-- This key is used to keep the consistency between the key in atlassian-plugin.xml and the key to generate bundle. -->
<atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
<!-- TestKit version 6.x for JIRA 6.x -->
<testkit.version>7.0.97</testkit.version>
<!-- TestKit version 8.x for JIRA 8.x -->
<testkit.version>8.1.26</testkit.version>
<mockito.version>1.10.19</mockito.version>
<powermock.version>1.6.4</powermock.version>
<compressJs>true</compressJs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.catrobat.jira.timesheet.services.impl;

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
import org.springframework.stereotype.Component;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
Expand All @@ -33,6 +35,7 @@ public class XlsxExportServiceImpl implements XlsxExportService {

public static final String TIMESHEET_WORKBOOK_NAME = "Timesheets";
public static final String TIMESHEET_ENTRIES_WORKBOOK_NAME = "Timesheets entries";
public static final String INVALID_USER_NAME = "User does not exist anymore";

public XlsxExportServiceImpl() {
}
Expand All @@ -48,7 +51,7 @@ public Workbook exportTimesheets(List<Timesheet> timesheetList) {
private XSSFSheet generateTimesheetWorksheet(XSSFWorkbook workbook, List<Timesheet> timesheetList) {
XSSFSheet worksheet = workbook.createSheet(TIMESHEET_WORKBOOK_NAME);

String[] header = {"Username","Hours Done","Subtracted Hours","Total Hours","Remaining Hours","Penalty Text","Lecture"};
String[] header = {"UserKey","Name","Hours Done","Subtracted Hours","Total Hours","Remaining Hours","Penalty Text","Lecture"};
int rownum = 0;
int column = 0;
Row headerRow = worksheet.createRow(rownum);
Expand All @@ -60,26 +63,33 @@ private XSSFSheet generateTimesheetWorksheet(XSSFWorkbook workbook, List<Timeshe

if (timesheetList.size() > 0) {
for (Timesheet timesheet : timesheetList) {
String userKey = timesheet.getUserKey();
ApplicationUser user = ComponentAccessor.getUserManager().getUserByKey(userKey);
String name = user == null ? INVALID_USER_NAME : user.getDisplayName();

Row dataRow = worksheet.createRow(rownum);
Cell cellUserName = dataRow.createCell(0);
cellUserName.setCellValue(timesheet.getUserKey());
cellUserName.setCellValue(userKey);

Cell cellName = dataRow.createCell(1);
cellName.setCellValue(name);

Cell cellHoursDone = dataRow.createCell(1);
Cell cellHoursDone = dataRow.createCell(2);
cellHoursDone.setCellValue(timesheet.getHoursCompleted());

Cell cellSubtractedHours = dataRow.createCell(2);
Cell cellSubtractedHours = dataRow.createCell(3);
cellSubtractedHours.setCellValue(timesheet.getHoursDeducted());

Cell cellTotalHours = dataRow.createCell(3);
Cell cellTotalHours = dataRow.createCell(4);
cellTotalHours.setCellValue(timesheet.getTargetHours());

Cell cellRemaininglHours = dataRow.createCell(4);
Cell cellRemaininglHours = dataRow.createCell(5);
cellRemaininglHours.setCellValue(timesheet.getTargetHours() - timesheet.getHoursCompleted());

Cell cellPenaltyText = dataRow.createCell(5);
Cell cellPenaltyText = dataRow.createCell(6);
cellPenaltyText.setCellValue(timesheet.getReason());

Cell cellLecture = dataRow.createCell(6);
Cell cellLecture = dataRow.createCell(7);
cellLecture.setCellValue(timesheet.getLectures());

rownum++;
Expand All @@ -92,7 +102,7 @@ private XSSFSheet generateTimesheetWorksheet(XSSFWorkbook workbook, List<Timeshe
private XSSFSheet generateTimesheetEntryWorksheet(XSSFWorkbook workbook, List<Timesheet> timesheetList) {
XSSFSheet worksheet = workbook.createSheet(TIMESHEET_ENTRIES_WORKBOOK_NAME);

String[] header = {"Inactive Date","Date","Begin","End","Duration Minutes","Pause Minutes","Category","Description","Team","UserKey"};
String[] header = {"Inactive Date","Date","Begin","End","Duration Minutes","Pause Minutes","Category","Description","Team","UserKey","Name"};
int rownum = 0;
int column = 0;
Row headerRow = worksheet.createRow(rownum);
Expand All @@ -105,6 +115,10 @@ private XSSFSheet generateTimesheetEntryWorksheet(XSSFWorkbook workbook, List<Ti
if (timesheetList.size() > 0) {
for (Timesheet timesheet : timesheetList) {
for (TimesheetEntry timesheetEntry : timesheet.getEntries()) {
String userKey = timesheetEntry.getTimeSheet().getUserKey();
ApplicationUser user = ComponentAccessor.getUserManager().getUserByKey(userKey);
String name = user == null ? INVALID_USER_NAME : user.getDisplayName();

Row dataRow = worksheet.createRow(rownum);
Cell cellInactiveDate = dataRow.createCell(0);
cellInactiveDate.setCellValue(timesheetEntry.getInactiveEndDate().toString());
Expand Down Expand Up @@ -134,7 +148,10 @@ private XSSFSheet generateTimesheetEntryWorksheet(XSSFWorkbook workbook, List<Ti
cellTeam.setCellValue(timesheetEntry.getTeam().getTeamName());

Cell cellUserKey = dataRow.createCell(9);
cellUserKey.setCellValue(timesheetEntry.getTimeSheet().getUserKey());
cellUserKey.setCellValue(userKey);

Cell cellName = dataRow.createCell(10);
cellName.setCellValue(name);

rownum++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.Date;
import java.util.List;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.catrobat.jira.timesheet.services.XlsxExportService;

public class ExportAllTimesheetsAsXlsxServlet extends HighPrivilegeServlet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.common.collect.Maps;
import org.catrobat.jira.timesheet.activeobjects.Timesheet;
import org.catrobat.jira.timesheet.rest.TimesheetRest;
import org.catrobat.jira.timesheet.services.MonitoringService;
import org.catrobat.jira.timesheet.services.PermissionService;
import org.catrobat.jira.timesheet.services.TimesheetService;
import org.slf4j.Logger;
Expand All @@ -43,15 +44,18 @@ public class TimesheetServlet extends HttpServlet {
private final LoginUriProvider loginUriProvider;
private final TemplateRenderer templateRenderer;
private final TimesheetService sheetService;
private final MonitoringService monitoringService;
private final PermissionService permissionService;
private static final Logger logger = LoggerFactory.getLogger(TimesheetServlet.class);
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(TimesheetServlet.class);

public TimesheetServlet(final LoginUriProvider loginUriProvider, final TemplateRenderer templateRenderer,
final TimesheetService sheetService, final PermissionService permissionService) {
final TimesheetService sheetService, final MonitoringService monitoringService,
final PermissionService permissionService) {
this.loginUriProvider = loginUriProvider;
this.templateRenderer = templateRenderer;
this.sheetService = sheetService;
this.monitoringService = monitoringService;
this.permissionService = permissionService;
}

Expand Down Expand Up @@ -136,6 +140,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
paramMap.put("isAdmin", permissionService.isJiraAdministrator(user));
}

paramMap.put("monitoringPeriod", monitoringService.getLastIntervalFormattedAsString());
paramMap.put("isCoordinator", permissionService.isUserTeamCoordinator(user));
paramMap.put("isReadOnlyUser", permissionService.isReadOnlyUser(user));
paramMap.put("timesheetID", timesheet.getID());
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/administration.vm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<body>
<a name="top"></a>
<div id="aui-message-bar"></div>
<div class="loadingDiv"><span class="aui-icon aui-icon-wait">Loading...</span></div>
<div class="loadingDiv"><aui-spinner></aui-spinner></div>
<div class="aui-tabs horizontal-tabs">
<ul class="tabs-menu">
<li class="menu-item">
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/css/timesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
width: 130px;
}

#timesheet-table .th.teamroom,
#timesheet-table .td.room {
width: 160px;
}

.select2-container {
min-width: 80px;
width: 150px;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/import.vm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

<footer class="aui-dialog2-footer">
<div class="aui-dialog2-footer-actions">
<div class="loadingDiv" style="display: inline-block;visibility: hidden"><span>Saving</span><span class="aui-icon aui-icon-wait">Loading...</span></div>
<div class="loadingDiv" style="display: inline-block;visibility: hidden"><span>Saving</span><aui-spinner></aui-spinner></div>
<button class="aui-button aui-button-primary start-import">Import</button>
</div>
</footer>
Expand Down
6 changes: 2 additions & 4 deletions src/main/resources/js/timesheet/coordinator.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ function initCoordinatorUserList(userInformation) {
} else {
inactiveEndDate = (new Date(userInformation[i].inactiveEndDate)).toLocaleDateString("en-US");
}
thisUsersName = userInformation[i].userName;

var view_timesheet_button = "<button class='aui-button aui-button-primary view-timesheet-button' " +
"data-timesheet-id='" + userInformation[i].timesheetID + "'>Timesheet</button>";

var row = "<tr>" +
"<td headers='ti-users'>" + thisUsersName +
"<td headers='ti-users'>" + userInformation[i].userName +
"</td><td headers='ti-view-timesheet'>"+ view_timesheet_button +
"</td><td headers='ti-teams'>" + userInformation[i].teams +
"</td><td headers='ti-state'>" + userInformation[i].state +
Expand All @@ -39,7 +37,7 @@ function initCoordinatorUserList(userInformation) {
"</td><td headers='ti-target-total-hours'>" + userInformation[i].targetTotalHours +
"</td><td headers='ti-total-hours'>" + userInformation[i].totalHours +
"</td><td headers='ti-hours-per-half-year'>" + userInformation[i].hoursPerHalfYear +
"</td><td headers='ti-hours-per-month'>" + userInformation[i].hoursPerMonth +
"</td><td headers='ti-hours-per-monitoring-period'>" + userInformation[i].hoursPerMonitoringPeriod +
"</td><td headers='ti-latest-entry-date'>" + latestEntryDate +
"</td><td headers='ti-latest-entry-description'>" + userInformation[i].latestEntryDescription +
"</td></tr>";
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/js/timesheet/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ function prepareForm(entry, timesheetData, isModified) {
width: 'resolve'
});

form.teamroomField.auiSelect2({
width: '90px',
minimumResultsForSearch: -1
});

var baseUrl = AJS.params.baseURL; // we have to reassign it otherwise it would be undefined
var tickets = [];
var queryString = "/rest/api/2/issue/picker";
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/timesheet.vm
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<div id="timesheet-table" class="aui aui-table-interactive aui-table-sortable table">
<div class="tr">
<span class="td">
<span class="aui-icon aui-icon-wait">Loading...</span>
<aui-spinner></aui-spinner>
</span>
</div>
</div>
Expand Down Expand Up @@ -141,7 +141,7 @@
<th id="ti-target-total-hours">Target Total Hours</th>
<th id="ti-total-hours">Finished Hours</th>
<th id="ti-hours-per-half-year">Hours last Half Year</th>
<th id="ti-hours-per-month">Hours last Month</th>
<th id="ti-hours-per-monitoring-period">Hours ($monitoringPeriod)</th>
<th id="ti-latest-entry-date">Date of the Latest Entry</th>
<th id="ti-latest-entry-description">Description of the Latest Entry</th>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/user_information.vm
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

<h1><b>Timesheet - User Information</b></h1>
<div id="aui-message-bar"></div>
<div class="loadingDiv"><span class="aui-icon aui-icon-wait">Loading...</span></div>
<div class="loadingDiv"><aui-spinner></aui-spinner></div>

#*Tabs view*#

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package ut.org.catrobat.jira.timesheet.services.impl;

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.mock.component.MockComponentWorker;
import com.atlassian.jira.user.util.UserManager;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.catrobat.jira.timesheet.activeobjects.Category;
Expand All @@ -10,6 +13,7 @@
import org.catrobat.jira.timesheet.services.impl.XlsxExportServiceImpl;
import org.junit.Before;
import org.junit.Test;
import org.powermock.api.mockito.PowerMockito;

import java.util.Arrays;
import java.util.Collections;
Expand All @@ -24,6 +28,14 @@ public class XlsExportServiceTest {

@Before
public void setUp() {
UserManager userManager = mock(UserManager.class);

MockComponentWorker mockComponentWorker = new MockComponentWorker();
mockComponentWorker.addMock(UserManager.class, userManager);
mockComponentWorker.init();

ComponentAccessor.initialiseWorker(mockComponentWorker);

xlsxExportService = new XlsxExportServiceImpl();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.atlassian.sal.api.auth.LoginUriProvider;
import com.atlassian.templaterenderer.TemplateRenderer;
import org.catrobat.jira.timesheet.activeobjects.Timesheet;
import org.catrobat.jira.timesheet.services.MonitoringService;
import org.catrobat.jira.timesheet.services.PermissionService;
import org.catrobat.jira.timesheet.services.TimesheetService;
import org.catrobat.jira.timesheet.servlet.TimesheetServlet;
Expand All @@ -29,14 +30,16 @@ public void setUp() throws Exception {
LoginUriProvider loginUriProvider = mock(LoginUriProvider.class);
TemplateRenderer templateRenderer = mock(TemplateRenderer.class);
TimesheetService sheetService = mock(TimesheetService.class);
MonitoringService monitoringService = mock(MonitoringService.class);
PermissionService permissionService = mock(PermissionService.class);

Timesheet timeSheet = mock(Timesheet.class);

request = mock(HttpServletRequest.class);
response = mock(HttpServletResponse.class);

timesheetServlet = new TimesheetServlet(loginUriProvider, templateRenderer, sheetService, permissionService);
timesheetServlet = new TimesheetServlet(loginUriProvider, templateRenderer, sheetService,
monitoringService, permissionService);

ApplicationUser admin = mock(ApplicationUser.class);
String admin_key = "admin_key";
Expand Down

0 comments on commit 654fa1c

Please sign in to comment.