Jira-integration: modified to test the classes instead code copied and jira label is moved to jira-conn-properties
This commit is contained in:
parent
685f0ac77d
commit
946c66163b
3 changed files with 70 additions and 387 deletions
|
|
@ -39,35 +39,21 @@ import java.util.UUID;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
import org.joda.time.LocalDate;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.libreplan.business.IDataBootstrap;
|
import org.libreplan.business.IDataBootstrap;
|
||||||
import org.libreplan.business.advance.bootstrap.PredefinedAdvancedTypes;
|
|
||||||
import org.libreplan.business.advance.entities.AdvanceMeasurement;
|
|
||||||
import org.libreplan.business.advance.entities.AdvanceType;
|
|
||||||
import org.libreplan.business.advance.entities.DirectAdvanceAssignment;
|
|
||||||
import org.libreplan.business.advance.exceptions.DuplicateAdvanceAssignmentForOrderElementException;
|
|
||||||
import org.libreplan.business.advance.exceptions.DuplicateValueTrueReportGlobalAdvanceException;
|
|
||||||
import org.libreplan.business.common.IAdHocTransactionService;
|
import org.libreplan.business.common.IAdHocTransactionService;
|
||||||
import org.libreplan.business.common.IOnTransaction;
|
import org.libreplan.business.common.IOnTransaction;
|
||||||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||||
import org.libreplan.business.common.entities.JiraConfiguration;
|
|
||||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||||
import org.libreplan.business.orders.daos.IOrderDAO;
|
import org.libreplan.business.orders.daos.IOrderDAO;
|
||||||
import org.libreplan.business.orders.entities.HoursGroup;
|
|
||||||
import org.libreplan.business.orders.entities.Order;
|
import org.libreplan.business.orders.entities.Order;
|
||||||
import org.libreplan.business.orders.entities.OrderElement;
|
|
||||||
import org.libreplan.business.orders.entities.OrderLine;
|
|
||||||
import org.libreplan.business.scenarios.IScenarioManager;
|
import org.libreplan.business.scenarios.IScenarioManager;
|
||||||
import org.libreplan.business.scenarios.entities.OrderVersion;
|
import org.libreplan.business.scenarios.entities.OrderVersion;
|
||||||
import org.libreplan.business.scenarios.entities.Scenario;
|
import org.libreplan.business.scenarios.entities.Scenario;
|
||||||
import org.libreplan.importers.jira.IssueDTO;
|
import org.libreplan.importers.jira.IssueDTO;
|
||||||
import org.libreplan.importers.jira.TimeTrackingDTO;
|
|
||||||
import org.libreplan.importers.jira.WorkLogDTO;
|
|
||||||
import org.libreplan.importers.jira.WorkLogItemDTO;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
@ -104,13 +90,14 @@ public class JiraOrderElementSynchronizerTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IScenarioManager scenarioManager;
|
private IScenarioManager scenarioManager;
|
||||||
|
|
||||||
private static final String LABEL = "labels=epd_12a_ZorgActiviteiten";
|
|
||||||
|
|
||||||
private List<IssueDTO> issues;
|
private List<IssueDTO> issues;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IOrderDAO orderDAO;
|
private IOrderDAO orderDAO;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IJiraOrderElementSynchronizer jiraOrderElementSynchronizer;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void loadRequiredaData() {
|
public void loadRequiredaData() {
|
||||||
|
|
@ -137,7 +124,8 @@ public class JiraOrderElementSynchronizerTest {
|
||||||
issues = JiraRESTClient.getIssues(properties.getProperty("url"),
|
issues = JiraRESTClient.getIssues(properties.getProperty("url"),
|
||||||
properties.getProperty("username"),
|
properties.getProperty("username"),
|
||||||
properties.getProperty("password"),
|
properties.getProperty("password"),
|
||||||
JiraRESTClient.PATH_SEARCH, LABEL);
|
JiraRESTClient.PATH_SEARCH,
|
||||||
|
getJiraLabel(properties.getProperty("label")));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
@ -158,6 +146,10 @@ public class JiraOrderElementSynchronizerTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getJiraLabel(String label) {
|
||||||
|
return "labels=" + label;
|
||||||
|
}
|
||||||
|
|
||||||
private Order givenOrder() {
|
private Order givenOrder() {
|
||||||
return transactionService
|
return transactionService
|
||||||
.runOnAnotherTransaction(new IOnTransaction<Order>() {
|
.runOnAnotherTransaction(new IOnTransaction<Order>() {
|
||||||
|
|
@ -168,8 +160,6 @@ public class JiraOrderElementSynchronizerTest {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Order givenValidOrderAlreadyStored() {
|
private Order givenValidOrderAlreadyStored() {
|
||||||
Order order = Order.create();
|
Order order = Order.create();
|
||||||
order.setCode(UUID.randomUUID().toString());
|
order.setCode(UUID.randomUUID().toString());
|
||||||
|
|
@ -199,32 +189,12 @@ public class JiraOrderElementSynchronizerTest {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Order givenValidOrderWithValidOrderLinesAlreadyStored() {
|
private Order givenValidOrderWithValidOrderLinesAlreadyStored() {
|
||||||
Order order = Order.create();
|
Order order = givenOrder();
|
||||||
order.setCode(UUID.randomUUID().toString());
|
jiraOrderElementSynchronizer.syncOrderElementsWithJiraIssues(issues, order);
|
||||||
order.setName("Order name " + UUID.randomUUID());
|
order.dontPoseAsTransientObjectAnymore();
|
||||||
order.setInitDate(new Date());
|
orderDAO.saveWithoutValidating(order);
|
||||||
order.setCalendar(configurationDAO.getConfiguration()
|
|
||||||
.getDefaultCalendar());
|
|
||||||
OrderVersion version = setupVersionUsing(scenarioManager, order);
|
|
||||||
order.useSchedulingDataFor(version);
|
|
||||||
for (IssueDTO issue : issues) {
|
|
||||||
String code = JiraConfiguration.CODE_PREFIX + order.getCode() + "-"
|
|
||||||
+ issue.getKey();
|
|
||||||
String name = issue.getFields().getSummary();
|
|
||||||
|
|
||||||
syncOrderLine(order, code, name);
|
|
||||||
|
|
||||||
int estimatedHours = getEstimatedHours(
|
|
||||||
issue.getFields().getTimetracking()).intValue();
|
|
||||||
|
|
||||||
syncHoursGroup((OrderLine) order.getOrderElement(code), code,
|
|
||||||
estimatedHours);
|
|
||||||
|
|
||||||
syncPorgressMeasurement(order.getOrderElement(code), issue);
|
|
||||||
|
|
||||||
}
|
|
||||||
orderDAO.save(order);
|
|
||||||
orderDAO.flush();
|
orderDAO.flush();
|
||||||
try {
|
try {
|
||||||
return orderDAO.find(order.getId());
|
return orderDAO.find(order.getId());
|
||||||
|
|
@ -241,155 +211,11 @@ public class JiraOrderElementSynchronizerTest {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void syncOrderLine(Order order, String code, String name) {
|
|
||||||
OrderLine orderLine = (OrderLine) order.getOrderElement(code);
|
|
||||||
if (orderLine == null) {
|
|
||||||
orderLine = OrderLine.createOrderLineWithUnfixedPercentage(1000);
|
|
||||||
order.add(orderLine);
|
|
||||||
orderLine.setCode(code);
|
|
||||||
}
|
|
||||||
orderLine.setName(name);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void syncHoursGroup(OrderLine orderLine, String code,
|
|
||||||
Integer workingHours) {
|
|
||||||
HoursGroup hoursGroup = orderLine.getHoursGroup(code);
|
|
||||||
if (hoursGroup == null) {
|
|
||||||
hoursGroup = HoursGroup.create(orderLine);
|
|
||||||
hoursGroup.setCode(code);
|
|
||||||
orderLine.addHoursGroup(hoursGroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
hoursGroup.setWorkingHours(workingHours);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void syncPorgressMeasurement(OrderElement orderElement, IssueDTO issue) {
|
|
||||||
|
|
||||||
WorkLogDTO workLog = issue.getFields().getWorklog();
|
|
||||||
|
|
||||||
if (workLog == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (orderElement == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<WorkLogItemDTO> workLogItems = workLog.getWorklogs();
|
|
||||||
if (workLogItems.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer estimatedHours = getEstimatedHours(issue.getFields()
|
|
||||||
.getTimetracking());
|
|
||||||
|
|
||||||
if (estimatedHours == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer loggedHours = getLoggedHours(issue.getFields()
|
|
||||||
.getTimetracking());
|
|
||||||
|
|
||||||
BigDecimal percentage = new BigDecimal((loggedHours * 100)
|
|
||||||
/ (loggedHours + estimatedHours));
|
|
||||||
|
|
||||||
LocalDate latestWorkLogDate = new LocalDate();
|
|
||||||
|
|
||||||
updateOrCreateProgressAssignmentAndMeasurement(orderElement,
|
|
||||||
percentage, latestWorkLogDate);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateOrCreateProgressAssignmentAndMeasurement(
|
|
||||||
OrderElement orderElement, BigDecimal percentage,
|
|
||||||
LocalDate latestWorkLogDate) {
|
|
||||||
|
|
||||||
AdvanceType advanceType = PredefinedAdvancedTypes.PERCENTAGE.getType();
|
|
||||||
|
|
||||||
DirectAdvanceAssignment directAdvanceAssignment = orderElement
|
|
||||||
.getDirectAdvanceAssignmentByType(advanceType);
|
|
||||||
if (directAdvanceAssignment == null) {
|
|
||||||
directAdvanceAssignment = DirectAdvanceAssignment.create(false,
|
|
||||||
new BigDecimal(100));
|
|
||||||
directAdvanceAssignment.setAdvanceType(advanceType);
|
|
||||||
}
|
|
||||||
directAdvanceAssignment.setOrderElement(orderElement);
|
|
||||||
|
|
||||||
AdvanceMeasurement advanceMeasurement = directAdvanceAssignment
|
|
||||||
.getAdvanceMeasurementAtExactDate(latestWorkLogDate);
|
|
||||||
if (advanceMeasurement == null) {
|
|
||||||
advanceMeasurement = AdvanceMeasurement.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
advanceMeasurement.setValue(percentage);
|
|
||||||
advanceMeasurement.setDate(latestWorkLogDate);
|
|
||||||
|
|
||||||
directAdvanceAssignment.addAdvanceMeasurements(advanceMeasurement);
|
|
||||||
|
|
||||||
advanceMeasurement.setAdvanceAssignment(directAdvanceAssignment);
|
|
||||||
|
|
||||||
if (directAdvanceAssignment.isNewObject()) {
|
|
||||||
try {
|
|
||||||
directAdvanceAssignment.getOrderElement().addAdvanceAssignment(
|
|
||||||
directAdvanceAssignment);
|
|
||||||
} catch (DuplicateValueTrueReportGlobalAdvanceException e) {
|
|
||||||
} catch (DuplicateAdvanceAssignmentForOrderElementException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private Integer getEstimatedHours(TimeTrackingDTO timeTracking) {
|
|
||||||
if (timeTracking == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer timeestimate = timeTracking.getRemainingEstimateSeconds();
|
|
||||||
if (timeestimate != null && timeestimate > 0) {
|
|
||||||
return timeestimate / 3600;
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer timeoriginalestimate = timeTracking
|
|
||||||
.getOriginalEstimateSeconds();
|
|
||||||
if (timeoriginalestimate != null) {
|
|
||||||
return timeoriginalestimate / 3600;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Integer getLoggedHours(TimeTrackingDTO timeTracking) {
|
|
||||||
if (timeTracking == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer timespentInSec = timeTracking.getTimeSpentSeconds();
|
|
||||||
if (timespentInSec != null && timespentInSec > 0) {
|
|
||||||
return timespentInSec / 3600;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Only working if you have a JIRA server configured")
|
@Ignore("Only working if you have a JIRA server configured")
|
||||||
public void testSyncOrderElementsOfAnExistingOrderWithNoOrderLines() {
|
public void testSyncOrderElementsOfAnExistingOrderWithNoOrderLines() {
|
||||||
Order order = givenOrder();
|
Order order = givenOrder();
|
||||||
for (IssueDTO issue : issues) {
|
jiraOrderElementSynchronizer.syncOrderElementsWithJiraIssues(issues, order);
|
||||||
String code = JiraConfiguration.CODE_PREFIX + order.getCode() + "-"
|
|
||||||
+ issue.getKey();
|
|
||||||
String name = issue.getFields().getSummary();
|
|
||||||
|
|
||||||
syncOrderLine(order, code, name);
|
|
||||||
|
|
||||||
syncHoursGroup((OrderLine) order.getOrderElement(code), code,
|
|
||||||
getEstimatedHours(issue.getFields().getTimetracking()));
|
|
||||||
|
|
||||||
syncPorgressMeasurement(order.getOrderElement(code), issue);
|
|
||||||
|
|
||||||
}
|
|
||||||
assertEquals(order.getOrderElements().size(), issues.size());
|
assertEquals(order.getOrderElements().size(), issues.size());
|
||||||
assertTrue(order.getOrderElements().get(0).getHoursGroups().size() > 0);
|
assertTrue(order.getOrderElements().get(0).getHoursGroups().size() > 0);
|
||||||
assertTrue(!order.getAdvancePercentage().equals(BigDecimal.ZERO));
|
assertTrue(!order.getAdvancePercentage().equals(BigDecimal.ZERO));
|
||||||
|
|
@ -401,25 +227,9 @@ public class JiraOrderElementSynchronizerTest {
|
||||||
public void testReSyncOrderElementsOfAnExistingOrderWithOrderLines() {
|
public void testReSyncOrderElementsOfAnExistingOrderWithOrderLines() {
|
||||||
Order order = givenOrderWithValidOrderLines();
|
Order order = givenOrderWithValidOrderLines();
|
||||||
Integer workingHours = order.getWorkHours();
|
Integer workingHours = order.getWorkHours();
|
||||||
for (IssueDTO issue : issues) {
|
jiraOrderElementSynchronizer.syncOrderElementsWithJiraIssues(issues, order);
|
||||||
String code = JiraConfiguration.CODE_PREFIX + order.getCode() + "-"
|
|
||||||
+ issue.getKey();
|
|
||||||
String name = issue.getFields().getSummary();
|
|
||||||
|
|
||||||
syncOrderLine(order, code, name);
|
|
||||||
|
|
||||||
Integer estimatedHours = getEstimatedHours(issue.getFields()
|
|
||||||
.getTimetracking()) * 10;
|
|
||||||
|
|
||||||
syncHoursGroup((OrderLine) order.getOrderElement(code), code,
|
|
||||||
estimatedHours);
|
|
||||||
|
|
||||||
syncPorgressMeasurement(order.getOrderElement(code), issue);
|
|
||||||
|
|
||||||
}
|
|
||||||
assertEquals(order.getOrderElements().size(), issues.size());
|
assertEquals(order.getOrderElements().size(), issues.size());
|
||||||
assertEquals(workingHours.intValue(),
|
assertEquals(workingHours.intValue(), order.getWorkHours().intValue());
|
||||||
(order.getWorkHours().intValue() / 10));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,8 @@ import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
@ -47,27 +45,14 @@ import org.libreplan.business.IDataBootstrap;
|
||||||
import org.libreplan.business.common.IAdHocTransactionService;
|
import org.libreplan.business.common.IAdHocTransactionService;
|
||||||
import org.libreplan.business.common.IOnTransaction;
|
import org.libreplan.business.common.IOnTransaction;
|
||||||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||||
import org.libreplan.business.common.entities.JiraConfiguration;
|
|
||||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||||
import org.libreplan.business.costcategories.entities.TypeOfWorkHours;
|
|
||||||
import org.libreplan.business.orders.daos.IOrderDAO;
|
import org.libreplan.business.orders.daos.IOrderDAO;
|
||||||
import org.libreplan.business.orders.entities.Order;
|
import org.libreplan.business.orders.entities.Order;
|
||||||
import org.libreplan.business.orders.entities.OrderElement;
|
|
||||||
import org.libreplan.business.orders.entities.OrderLine;
|
|
||||||
import org.libreplan.business.resources.entities.Worker;
|
|
||||||
import org.libreplan.business.scenarios.IScenarioManager;
|
import org.libreplan.business.scenarios.IScenarioManager;
|
||||||
import org.libreplan.business.scenarios.entities.OrderVersion;
|
import org.libreplan.business.scenarios.entities.OrderVersion;
|
||||||
import org.libreplan.business.scenarios.entities.Scenario;
|
import org.libreplan.business.scenarios.entities.Scenario;
|
||||||
import org.libreplan.business.workingday.EffortDuration;
|
import org.libreplan.business.workreports.entities.IWorkReportTypeBootstrap;
|
||||||
import org.libreplan.business.workreports.daos.IWorkReportDAO;
|
|
||||||
import org.libreplan.business.workreports.entities.WorkReport;
|
|
||||||
import org.libreplan.business.workreports.entities.WorkReportLine;
|
|
||||||
import org.libreplan.business.workreports.entities.WorkReportType;
|
|
||||||
import org.libreplan.business.workreports.valueobjects.DescriptionField;
|
|
||||||
import org.libreplan.business.workreports.valueobjects.DescriptionValue;
|
|
||||||
import org.libreplan.importers.jira.IssueDTO;
|
import org.libreplan.importers.jira.IssueDTO;
|
||||||
import org.libreplan.importers.jira.WorkLogDTO;
|
|
||||||
import org.libreplan.importers.jira.WorkLogItemDTO;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
@ -95,6 +80,9 @@ public class JiraTimesheetSynchronizerTest {
|
||||||
@Resource
|
@Resource
|
||||||
private IDataBootstrap configurationBootstrap;
|
private IDataBootstrap configurationBootstrap;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IWorkReportTypeBootstrap workReportTypeBootstrap;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IAdHocTransactionService transactionService;
|
private IAdHocTransactionService transactionService;
|
||||||
|
|
||||||
|
|
@ -104,20 +92,16 @@ public class JiraTimesheetSynchronizerTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IScenarioManager scenarioManager;
|
private IScenarioManager scenarioManager;
|
||||||
|
|
||||||
private static final String LABEL = "labels=epd_12a_ZorgActiviteiten";
|
|
||||||
|
|
||||||
private List<IssueDTO> issues;
|
private List<IssueDTO> issues;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IOrderDAO orderDAO;
|
private IOrderDAO orderDAO;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IWorkReportDAO workReportDAO;
|
private IJiraOrderElementSynchronizer jiraOrderElementSynchronizer;
|
||||||
|
|
||||||
private TypeOfWorkHours typeOfWorkHours;
|
|
||||||
|
|
||||||
private WorkReportType workReportType;
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IJiraTimesheetSynchronizer jiraTimesheetSynchronizer;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void loadRequiredaData() {
|
public void loadRequiredaData() {
|
||||||
|
|
@ -129,6 +113,7 @@ public class JiraTimesheetSynchronizerTest {
|
||||||
defaultAdvanceTypesBootstrapListener.loadRequiredData();
|
defaultAdvanceTypesBootstrapListener.loadRequiredData();
|
||||||
configurationBootstrap.loadRequiredData();
|
configurationBootstrap.loadRequiredData();
|
||||||
scenariosBootstrap.loadRequiredData();
|
scenariosBootstrap.loadRequiredData();
|
||||||
|
workReportTypeBootstrap.loadRequiredData();
|
||||||
issues = getJiraIssues();
|
issues = getJiraIssues();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -144,7 +129,8 @@ public class JiraTimesheetSynchronizerTest {
|
||||||
issues = JiraRESTClient.getIssues(properties.getProperty("url"),
|
issues = JiraRESTClient.getIssues(properties.getProperty("url"),
|
||||||
properties.getProperty("username"),
|
properties.getProperty("username"),
|
||||||
properties.getProperty("password"),
|
properties.getProperty("password"),
|
||||||
JiraRESTClient.PATH_SEARCH, LABEL);
|
JiraRESTClient.PATH_SEARCH,
|
||||||
|
getJiraLabel(properties.getProperty("label")));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
@ -165,7 +151,40 @@ public class JiraTimesheetSynchronizerTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getJiraLabel(String label) {
|
||||||
|
return "labels=" + label;
|
||||||
|
}
|
||||||
|
|
||||||
private Order givenOrder() {
|
private Order givenOrder() {
|
||||||
|
return transactionService
|
||||||
|
.runOnAnotherTransaction(new IOnTransaction<Order>() {
|
||||||
|
@Override
|
||||||
|
public Order execute() {
|
||||||
|
return givenValidOrderAlreadyStored();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private Order givenValidOrderAlreadyStored() {
|
||||||
|
Order order = Order.create();
|
||||||
|
order.setCode(UUID.randomUUID().toString());
|
||||||
|
order.setName("Order name " + UUID.randomUUID());
|
||||||
|
order.setInitDate(new Date());
|
||||||
|
order.setCalendar(configurationDAO.getConfiguration()
|
||||||
|
.getDefaultCalendar());
|
||||||
|
OrderVersion version = setupVersionUsing(scenarioManager, order);
|
||||||
|
order.useSchedulingDataFor(version);
|
||||||
|
|
||||||
|
orderDAO.save(order);
|
||||||
|
orderDAO.flush();
|
||||||
|
try {
|
||||||
|
return orderDAO.find(order.getId());
|
||||||
|
} catch (InstanceNotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Order givenOrderWithValidOrderLines() {
|
||||||
return transactionService
|
return transactionService
|
||||||
.runOnAnotherTransaction(new IOnTransaction<Order>() {
|
.runOnAnotherTransaction(new IOnTransaction<Order>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -176,30 +195,12 @@ public class JiraTimesheetSynchronizerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Order givenValidOrderWithValidOrderLinesAlreadyStored() {
|
private Order givenValidOrderWithValidOrderLinesAlreadyStored() {
|
||||||
Order order = Order.create();
|
Order order = givenOrder();
|
||||||
order.setCode(UUID.randomUUID().toString());
|
jiraOrderElementSynchronizer.syncOrderElementsWithJiraIssues(issues,
|
||||||
order.setName("Order name " + UUID.randomUUID());
|
order);
|
||||||
order.setInitDate(new Date());
|
order.dontPoseAsTransientObjectAnymore();
|
||||||
order.setCalendar(configurationDAO.getConfiguration()
|
orderDAO.saveWithoutValidating(order);
|
||||||
.getDefaultCalendar());
|
|
||||||
OrderVersion version = setupVersionUsing(scenarioManager, order);
|
|
||||||
order.useSchedulingDataFor(version);
|
|
||||||
for (IssueDTO issue : issues) {
|
|
||||||
String code = JiraConfiguration.CODE_PREFIX + order.getCode() + "-"
|
|
||||||
+ issue.getKey();
|
|
||||||
String name = issue.getFields().getSummary();
|
|
||||||
|
|
||||||
OrderLine orderLine = OrderLine
|
|
||||||
.createOrderLineWithUnfixedPercentage(1000);
|
|
||||||
orderLine.useSchedulingDataFor(version);
|
|
||||||
order.add(orderLine);
|
|
||||||
orderLine.setCode(code);
|
|
||||||
orderLine.setName(name);
|
|
||||||
|
|
||||||
}
|
|
||||||
orderDAO.save(order);
|
|
||||||
orderDAO.flush();
|
orderDAO.flush();
|
||||||
try {
|
try {
|
||||||
return orderDAO.find(order.getId());
|
return orderDAO.find(order.getId());
|
||||||
|
|
@ -216,144 +217,15 @@ public class JiraTimesheetSynchronizerTest {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WorkReport getOrCreateWorkReport(String code) {
|
|
||||||
WorkReport workReport = findWorkReport(code);
|
|
||||||
if (workReport == null) {
|
|
||||||
workReport = WorkReport.create(workReportType);
|
|
||||||
workReport.setCode(code);
|
|
||||||
}
|
|
||||||
return workReport;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void updateOrCreateWorkReportLineAndAddToWorkReport(
|
|
||||||
WorkReport workReport, OrderElement orderElement,
|
|
||||||
List<WorkLogItemDTO> workLogItems) {
|
|
||||||
|
|
||||||
for (WorkLogItemDTO workLogItem : workLogItems) {
|
|
||||||
WorkReportLine workReportLine;
|
|
||||||
try {
|
|
||||||
workReportLine = workReport
|
|
||||||
.getWorkReportLineByCode(orderElement.getCode() + "-"
|
|
||||||
+ workLogItem.getId());
|
|
||||||
} catch (InstanceNotFoundException e) {
|
|
||||||
workReportLine = WorkReportLine.create(workReport);
|
|
||||||
}
|
|
||||||
|
|
||||||
org.libreplan.business.resources.entities.Resource resource = createAndGetWorker(workLogItem
|
|
||||||
.getAuthor().getName());
|
|
||||||
if (resource != null) {
|
|
||||||
|
|
||||||
updateWorkReportLine(workReportLine, orderElement, workLogItem,
|
|
||||||
resource);
|
|
||||||
if (workReportLine.isNewObject()) {
|
|
||||||
workReport.addWorkReportLine(workReportLine);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateWorkReportLine(WorkReportLine workReportLine,
|
|
||||||
OrderElement orderElement, WorkLogItemDTO workLogItem,
|
|
||||||
org.libreplan.business.resources.entities.Resource resource) {
|
|
||||||
|
|
||||||
String code = orderElement.getCode() + "-" + workLogItem.getId();
|
|
||||||
int timeSpent = workLogItem.getTimeSpentSeconds().intValue();
|
|
||||||
|
|
||||||
workReportLine.setCode(code);
|
|
||||||
workReportLine.setDate(workLogItem.getStarted());
|
|
||||||
workReportLine.setResource(resource);
|
|
||||||
workReportLine.setOrderElement(orderElement);
|
|
||||||
workReportLine.setEffort(EffortDuration
|
|
||||||
.hours(EffortDuration.Granularity.HOURS
|
|
||||||
.convertFromSeconds(timeSpent)));
|
|
||||||
workReportLine.setTypeOfWorkHours(typeOfWorkHours);
|
|
||||||
|
|
||||||
updateOrCreateDescriptionValuesAndAddToWorkReportLine(workReportLine,
|
|
||||||
workLogItem.getComment());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateOrCreateDescriptionValuesAndAddToWorkReportLine(
|
|
||||||
WorkReportLine workReportLine, String comment) {
|
|
||||||
Set<DescriptionValue> descriptionValues = new HashSet<DescriptionValue>();
|
|
||||||
for (DescriptionField descriptionField : workReportType.getLineFields()) {
|
|
||||||
DescriptionValue descriptionValue;
|
|
||||||
try {
|
|
||||||
descriptionValue = workReportLine
|
|
||||||
.getDescriptionValueByFieldName(descriptionField
|
|
||||||
.getFieldName());
|
|
||||||
descriptionValue.setValue(comment.substring(0,
|
|
||||||
Math.min(comment.length(), 254)));
|
|
||||||
} catch (InstanceNotFoundException e) {
|
|
||||||
descriptionValue = DescriptionValue.create(
|
|
||||||
descriptionField.getFieldName(), comment);
|
|
||||||
}
|
|
||||||
descriptionValues.add(descriptionValue);
|
|
||||||
}
|
|
||||||
workReportLine.setDescriptionValues(descriptionValues);
|
|
||||||
}
|
|
||||||
|
|
||||||
private WorkReport findWorkReport(String code) {
|
|
||||||
try {
|
|
||||||
return workReportDAO.findByCodeAnotherTransaction(code);
|
|
||||||
} catch (InstanceNotFoundException e) {
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private WorkReportType createWorkReportType(String name) {
|
|
||||||
WorkReportType workReportType = WorkReportType.create();
|
|
||||||
workReportType.setName("Jira-connector");
|
|
||||||
workReportType.setCodeAutogenerated(true);
|
|
||||||
return workReportType;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TypeOfWorkHours createTypeOfWorkHours(String name) {
|
|
||||||
typeOfWorkHours = TypeOfWorkHours.create();
|
|
||||||
typeOfWorkHours.setName("Default");
|
|
||||||
typeOfWorkHours.setCodeAutogenerated(true);
|
|
||||||
return typeOfWorkHours;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Worker createAndGetWorker(String nif) {
|
|
||||||
Worker worker = Worker.create(nif, nif, nif);
|
|
||||||
return worker;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Only working if you have a JIRA server configured")
|
@Ignore("Only working if you have a JIRA server configured")
|
||||||
public void testSyncJiraTimesheet() {
|
public void testSyncJiraTimesheet() {
|
||||||
|
|
||||||
workReportType = createWorkReportType("Jira-connector");
|
Order order = givenOrderWithValidOrderLines();
|
||||||
typeOfWorkHours = createTypeOfWorkHours("Default");
|
jiraTimesheetSynchronizer
|
||||||
|
.syncJiraTimesheetWithJiraIssues(issues, order);
|
||||||
Order order = givenOrder();
|
assertTrue(order.getWorkReportLines(false).size() > 0);
|
||||||
|
|
||||||
String code = order.getCode();
|
|
||||||
|
|
||||||
WorkReport workReport = getOrCreateWorkReport(code);
|
|
||||||
|
|
||||||
for (IssueDTO issue : issues) {
|
|
||||||
WorkLogDTO worklog = issue.getFields().getWorklog();
|
|
||||||
if (worklog != null) {
|
|
||||||
List<WorkLogItemDTO> workLogItems = worklog.getWorklogs();
|
|
||||||
if (workLogItems != null && !workLogItems.isEmpty()) {
|
|
||||||
|
|
||||||
String code1 = JiraConfiguration.CODE_PREFIX
|
|
||||||
+ order.getCode() + "-" + issue.getKey();
|
|
||||||
|
|
||||||
OrderElement orderElement = order.getOrderElement(code1);
|
|
||||||
|
|
||||||
if (orderElement != null) {
|
|
||||||
updateOrCreateWorkReportLineAndAddToWorkReport(
|
|
||||||
workReport, orderElement, workLogItems);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assertTrue(workReport.getWorkReportLines().size() > 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,4 @@ url=http://domain:port/
|
||||||
label_url=http://domain:port/jiralabel/jiralabels.php
|
label_url=http://domain:port/jiralabel/jiralabels.php
|
||||||
username=username
|
username=username
|
||||||
password=password
|
password=password
|
||||||
|
label=jira-label
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue