tim-connector: Avoid to load all workers to import/export timesheets from/to Tim

Maybe it's not needed to get all workers, so the call to findAll has been changed by findByCode.

Moreover, it was using code in ExportTimesheetsToTim and NIF in
ImportRosterFromTim which was not coherent, so it has been changed to use code
in both places.

FEA: ItEr77S16JiraAndTimConnectorContributionIntegration
This commit is contained in:
Manuel Rego Casasnovas 2013-02-11 14:03:54 +01:00
parent 863c087f0f
commit 8824c9a24a
2 changed files with 14 additions and 53 deletions

View file

@ -32,6 +32,7 @@ import org.libreplan.business.common.IAdHocTransactionService;
import org.libreplan.business.common.IOnTransaction;
import org.libreplan.business.common.daos.IAppPropertiesDAO;
import org.libreplan.business.common.daos.IConfigurationDAO;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.orders.daos.IOrderDAO;
import org.libreplan.business.orders.daos.IOrderSyncInfoDAO;
import org.libreplan.business.orders.entities.Order;
@ -81,8 +82,6 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
@Autowired
private IAdHocTransactionService adHocTransactionService;
private List<Worker> workers;
@Autowired
private IAppPropertiesDAO appPropertiesDAO;
@ -138,12 +137,6 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
private boolean exportTimesheets(String productCode, Order order,
Map<String, String> appProperties) {
workers = workerDAO.findAll();
if (workers == null || workers.isEmpty()) {
LOG.warn("No workers found!");
return false;
}
String url = appProperties.get("Server");
String userName = appProperties.get("Username");
String password = appProperties.get("Password");
@ -240,9 +233,12 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
*/
private TimeRegistrationDTO createExportTimeRegistration(String productCode,
WorkReportLine workReportLine) {
Worker worker = getWorker(workReportLine.getResource().getCode());
if (worker == null) {
LOG.warn("Worker not found!");
Worker worker;
String workerCode = workReportLine.getResource().getCode();
try {
worker = workerDAO.findByCode(workerCode);
} catch (InstanceNotFoundException e) {
LOG.warn("Worker \"" + workerCode + "\" not found!");
return null;
}
@ -271,21 +267,6 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
return timeRegistrationDTO;
}
/**
* get worker based on the specified <code>code</code>
*
* @param code
* @return worker
*/
private Worker getWorker(String code) {
for (Worker worker : workers) {
if (worker.getCode().equals(code)) {
return worker;
}
}
return null;
}
@Override
@Transactional(readOnly = true)
public OrderSyncInfo getOrderLastSyncInfo(Order order) {

View file

@ -99,8 +99,6 @@ public class ImportRosterFromTim implements IImportRosterFromTim {
@Qualifier("subclass")
private IBaseCalendarModel baseCalendarModel;
private List<Worker> workers;
@Override
@Transactional
public void importRosters() {
@ -133,7 +131,6 @@ public class ImportRosterFromTim implements IImportRosterFromTim {
@Override
public Void execute() {
addAllWorkers();
List<RosterException> rosterExceptions = getRosterExceptions(rosterResponse);
if (!rosterExceptions.isEmpty()) {
updateCalendarException(rosterExceptions);
@ -159,7 +156,13 @@ public class ImportRosterFromTim implements IImportRosterFromTim {
List<RosterException> rosterExceptions = new ArrayList<RosterException>();
for (Map.Entry<String, List<RosterDTO>> entry : map.entrySet()) {
Worker worker = getWorker(entry.getKey());
Worker worker = null;
String workerCode = entry.getKey();
try {
worker = workerDAO.findByCode(workerCode);
} catch (InstanceNotFoundException e) {
LOG.warn("Worker \"" + workerCode + "\" not found!");
}
if (worker != null) {
List<RosterDTO> list = entry.getValue();
Collections.sort(list, new Comparator<RosterDTO>() {
@ -288,29 +291,6 @@ public class ImportRosterFromTim implements IImportRosterFromTim {
}
/**
* adds all existing workers to workers list
*/
private void addAllWorkers() {
workers = workerDAO.findAll();
}
/**
* returns {@link Worker} for the specified <code>nif</code>
*
* @param nif
* the worker's nif
* @return Worker if found, otherwise null
*/
private Worker getWorker(String nif) {
for (Worker worker : workers) {
if (worker.getNif().equals(nif)) {
return worker;
}
}
return null;
}
/**
* creates and returns {@link RosterRequestDTO}
*