From 48cdded3e0b84461265ede9f1ee62c126e4fbc67 Mon Sep 17 00:00:00 2001 From: Miciele Ghiorghis Date: Thu, 7 Feb 2013 15:04:13 +0100 Subject: [PATCH] Tim-connector: Classes renamed according Libreplan naming convention DTO classes are renamed to class-name with suffix DTO according to Libreplan naming convention Modified all classes which are affected by the renamed classes Comments and author information added where applicable Test cases modified --- .../orders/daos/IOrderSyncInfoDAO.java | 3 +- .../importers/ExportTimesheetsToTim.java | 86 +++--- .../importers/IExportTimesheetsToTim.java | 15 +- .../importers/IImportRosterFromTim.java | 13 +- .../importers/ISchedulerManager.java | 25 +- .../importers/ImportRosterFromTim.java | 184 +++++++------ .../libreplan/importers/RosterException.java | 39 +-- .../libreplan/importers/SchedulerInfo.java | 3 +- .../libreplan/importers/SchedulerManager.java | 5 + .../libreplan/importers/TimSoapClient.java | 53 ++-- .../importers/tim/{Data.java => DataDTO.java} | 9 +- .../{Department.java => DepartmentDTO.java} | 7 +- .../tim/{Duration.java => DurationDTO.java} | 7 +- .../tim/{Filter.java => FilterDTO.java} | 31 ++- .../tim/{Period.java => PeriodDTO.java} | 7 +- .../tim/{Person.java => PersonDTO.java} | 7 +- .../tim/{Product.java => ProductDTO.java} | 9 +- ...tionDate.java => RegistrationDateDTO.java} | 7 +- ...erCategory.java => RosterCategoryDTO.java} | 7 +- .../tim/{Roster.java => RosterDTO.java} | 37 +-- ...sterRequest.java => RosterRequestDTO.java} | 13 +- ...erResponse.java => RosterResponseDTO.java} | 13 +- .../importers/tim/TimDateTimeAdapter.java | 6 + .../importers/tim/TimDoubleAdapter.java | 6 + .../importers/tim/TimLocalDateAdapter.java | 6 + .../libreplan/importers/tim/TimOptions.java | 7 +- .../importers/tim/TimTimeAdapter.java | 6 + ...stration.java => TimeRegistrationDTO.java} | 31 ++- ...t.java => TimeRegistrationRequestDTO.java} | 13 +- ....java => TimeRegistrationResponseDTO.java} | 7 +- .../libreplan/importers/tim/package-info.java | 5 + .../web/common/JobSchedulerController.java | 4 + .../importers/ExportTimesheetsToTimTest.java | 191 ++++++++----- .../importers/ImportRosterFromTimTest.java | 258 +++--------------- .../java/importers/TimSoapClientTest.java | 182 +++++++++++- 35 files changed, 742 insertions(+), 560 deletions(-) rename libreplan-webapp/src/main/java/org/libreplan/importers/tim/{Data.java => DataDTO.java} (87%) rename libreplan-webapp/src/main/java/org/libreplan/importers/tim/{Department.java => DepartmentDTO.java} (90%) rename libreplan-webapp/src/main/java/org/libreplan/importers/tim/{Duration.java => DurationDTO.java} (91%) rename libreplan-webapp/src/main/java/org/libreplan/importers/tim/{Filter.java => FilterDTO.java} (68%) rename libreplan-webapp/src/main/java/org/libreplan/importers/tim/{Period.java => PeriodDTO.java} (91%) rename libreplan-webapp/src/main/java/org/libreplan/importers/tim/{Person.java => PersonDTO.java} (94%) rename libreplan-webapp/src/main/java/org/libreplan/importers/tim/{Product.java => ProductDTO.java} (92%) rename libreplan-webapp/src/main/java/org/libreplan/importers/tim/{RegistrationDate.java => RegistrationDateDTO.java} (90%) rename libreplan-webapp/src/main/java/org/libreplan/importers/tim/{RosterCategory.java => RosterCategoryDTO.java} (93%) rename libreplan-webapp/src/main/java/org/libreplan/importers/tim/{Roster.java => RosterDTO.java} (85%) rename libreplan-webapp/src/main/java/org/libreplan/importers/tim/{RosterRequest.java => RosterRequestDTO.java} (80%) rename libreplan-webapp/src/main/java/org/libreplan/importers/tim/{RosterResponse.java => RosterResponseDTO.java} (82%) rename libreplan-webapp/src/main/java/org/libreplan/importers/tim/{TimeRegistration.java => TimeRegistrationDTO.java} (67%) rename libreplan-webapp/src/main/java/org/libreplan/importers/tim/{TimeRegistrationRequest.java => TimeRegistrationRequestDTO.java} (78%) rename libreplan-webapp/src/main/java/org/libreplan/importers/tim/{TimeRegistrationResponse.java => TimeRegistrationResponseDTO.java} (88%) diff --git a/libreplan-business/src/main/java/org/libreplan/business/orders/daos/IOrderSyncInfoDAO.java b/libreplan-business/src/main/java/org/libreplan/business/orders/daos/IOrderSyncInfoDAO.java index 1973be538..4773f179d 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/orders/daos/IOrderSyncInfoDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/orders/daos/IOrderSyncInfoDAO.java @@ -33,7 +33,8 @@ import org.libreplan.business.orders.entities.OrderSyncInfo; public interface IOrderSyncInfoDAO extends IGenericDAO { /** - * Search last sychronized info for the specified {@link Order} + * Search last synchronized info for the specified + * {@link Order} * * @param order * the order to search for diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/ExportTimesheetsToTim.java b/libreplan-webapp/src/main/java/org/libreplan/importers/ExportTimesheetsToTim.java index 0909538e0..1f7ec224b 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/ExportTimesheetsToTim.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/ExportTimesheetsToTim.java @@ -40,20 +40,25 @@ import org.libreplan.business.resources.daos.IWorkerDAO; import org.libreplan.business.resources.entities.Worker; import org.libreplan.business.workreports.daos.IWorkReportLineDAO; import org.libreplan.business.workreports.entities.WorkReportLine; -import org.libreplan.importers.tim.Duration; -import org.libreplan.importers.tim.Person; -import org.libreplan.importers.tim.Product; -import org.libreplan.importers.tim.RegistrationDate; +import org.libreplan.importers.tim.DurationDTO; +import org.libreplan.importers.tim.PersonDTO; +import org.libreplan.importers.tim.ProductDTO; +import org.libreplan.importers.tim.RegistrationDateDTO; import org.libreplan.importers.tim.TimOptions; -import org.libreplan.importers.tim.TimeRegistration; -import org.libreplan.importers.tim.TimeRegistrationRequest; -import org.libreplan.importers.tim.TimeRegistrationResponse; +import org.libreplan.importers.tim.TimeRegistrationDTO; +import org.libreplan.importers.tim.TimeRegistrationRequestDTO; +import org.libreplan.importers.tim.TimeRegistrationResponseDTO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +/** + * Implementation of export timesheets to tim + * + * @author Miciele Ghiorghis + */ @Component @Scope(BeanDefinition.SCOPE_PROTOTYPE) public class ExportTimesheetsToTim implements IExportTimesheetsToTim { @@ -134,8 +139,7 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim { Map appProperties) { workers = workerDAO.findAll(); - LOG.info("workers.findAll(): " + workers.size()); - if (workers == null && workers.isEmpty()) { + if (workers == null || workers.isEmpty()) { LOG.warn("No workers found!"); return false; } @@ -156,30 +160,30 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim { return false; } - List timeRegistrations = new ArrayList(); + List timeRegistrationDTOs = new ArrayList(); for (WorkReportLine workReportLine : workReportLines) { - TimeRegistration timeRegistration = createExportTimeRegistration( + TimeRegistrationDTO timeRegistrationDTO = createExportTimeRegistration( productCode, workReportLine); - if (timeRegistration != null) { - timeRegistrations.add(timeRegistration); + if (timeRegistrationDTO != null) { + timeRegistrationDTOs.add(timeRegistrationDTO); } } - if (timeRegistrations.isEmpty()) { - LOG.warn("Unable to crate timeregistration request"); + if (timeRegistrationDTOs.isEmpty()) { + LOG.warn("Unable to crate timeregistration for request"); return false; } - TimeRegistrationRequest timeRegistrationRequest = new TimeRegistrationRequest(); - timeRegistrationRequest.setTimeRegistrations(timeRegistrations); + TimeRegistrationRequestDTO timeRegistrationRequestDTO = new TimeRegistrationRequestDTO(); + timeRegistrationRequestDTO.setTimeRegistrations(timeRegistrationDTOs); - TimeRegistrationResponse timeRegistrationResponse = TimSoapClient + TimeRegistrationResponseDTO timeRegistrationResponseDTO = TimSoapClient .sendRequestReceiveResponse(url, userName, password, - timeRegistrationRequest, TimeRegistrationResponse.class); + timeRegistrationRequestDTO, TimeRegistrationResponseDTO.class); - if (isRefsListEmpty(timeRegistrationResponse.getRefs())) { - LOG.warn("Registration response empty refs"); + if (isRefsListEmpty(timeRegistrationResponseDTO.getRefs())) { + LOG.warn("Registration response with empty refs"); return false; } saveSyncInfoOnAnotherTransaction(productCode, order); @@ -231,9 +235,9 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim { * the product code * @param workReportLine * the workreportLine - * @return timeRegistration + * @return timeRegistration DTO */ - private TimeRegistration createExportTimeRegistration(String productCode, + private TimeRegistrationDTO createExportTimeRegistration(String productCode, WorkReportLine workReportLine) { Worker worker = getWorker(workReportLine.getResource().getCode()); if (worker == null) { @@ -241,30 +245,30 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim { return null; } - Person person = new Person(); - person.setName(worker.getName()); + PersonDTO personDTO = new PersonDTO(); + personDTO.setName(worker.getName()); // person.setNetworkName(worker.getNif()); - person.setOptions(TimOptions.UPDATE_OR_INSERT); + personDTO.setOptions(TimOptions.UPDATE_OR_INSERT); - Product product = new Product(); - product.setOptions(TimOptions.UPDATE_OR_INSERT); - product.setCode(productCode); + ProductDTO productDTO = new ProductDTO(); + productDTO.setOptions(TimOptions.UPDATE_OR_INSERT); + productDTO.setCode(productCode); - RegistrationDate date = new RegistrationDate(); - date.setOptions(TimOptions.UPDATE_OR_INSERT); - date.setDate(workReportLine.getLocalDate()); + RegistrationDateDTO registrationDTO = new RegistrationDateDTO(); + registrationDTO.setOptions(TimOptions.UPDATE_OR_INSERT); + registrationDTO.setDate(workReportLine.getLocalDate()); - Duration duration = new Duration(); - duration.setOptions(TimOptions.DECIMAL); - duration.setDuration(workReportLine.getEffort() + DurationDTO durationDTO = new DurationDTO(); + durationDTO.setOptions(TimOptions.DECIMAL); + durationDTO.setDuration(workReportLine.getEffort() .toHoursAsDecimalWithScale(2).doubleValue()); - TimeRegistration timeRegistration = new TimeRegistration(); - timeRegistration.setPerson(person); - timeRegistration.setProduct(product); - timeRegistration.setRegistrationDate(date); - timeRegistration.setDuration(duration); - return timeRegistration; + TimeRegistrationDTO timeRegistrationDTO = new TimeRegistrationDTO(); + timeRegistrationDTO.setPerson(personDTO); + timeRegistrationDTO.setProduct(productDTO); + timeRegistrationDTO.setRegistrationDate(registrationDTO); + timeRegistrationDTO.setDuration(durationDTO); + return timeRegistrationDTO; } /** diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/IExportTimesheetsToTim.java b/libreplan-webapp/src/main/java/org/libreplan/importers/IExportTimesheetsToTim.java index 4dfdb0a9e..d3b0164d6 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/IExportTimesheetsToTim.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/IExportTimesheetsToTim.java @@ -19,6 +19,7 @@ package org.libreplan.importers; +import org.libreplan.business.common.entities.AppProperties; import org.libreplan.business.orders.entities.Order; import org.libreplan.business.orders.entities.OrderSyncInfo; @@ -26,13 +27,17 @@ import org.libreplan.business.orders.entities.OrderSyncInfo; * Export time sheets of an existing order to Tim SOAP server using * {@link TimSoapClient}. * + * It exports the time sheets between periods current-date minus + * NrDaysTimesheetToTim specified in configuration entity + * {@link AppProperties} and the current-date + * * @author Miciele Ghiorghis */ public interface IExportTimesheetsToTim { /** * Exports time sheets of the specified productCode and - * {@link Order} + * {@link Order} to Tim SOAP server * * @param productCode * the Tim's productCode @@ -42,11 +47,9 @@ public interface IExportTimesheetsToTim { boolean exportTimesheets(String productCode, Order order); /** - * Loops through all the time sheets of all {@link Order}s which has tim's - * productcodes and export them to Tim SOAP server - *

- * This method is of importance for the scheduler service - *

+ * Loops through all existing {@link Order}s and searches for last + * synchronized order. if found, start exporting the time sheets of that + * order to Tim SOAP server. if not found write info to the log file. */ void exportTimesheets(); diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/IImportRosterFromTim.java b/libreplan-webapp/src/main/java/org/libreplan/importers/IImportRosterFromTim.java index 05349b835..a5abbfab9 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/IImportRosterFromTim.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/IImportRosterFromTim.java @@ -20,20 +20,25 @@ package org.libreplan.importers; import org.libreplan.business.calendars.entities.CalendarException; +import org.libreplan.business.common.entities.AppProperties; /** * Import Rosters from Tim SOAP server using {@link TimSoapClient} and updates * worker's Exception calendar accordingly * + * It imports the Rosters between periods current-date and current-date plus + * NrDaysRosterFromTim specified in configuration entity + * {@link AppProperties} + * * @author Miciele Ghiorghis */ public interface IImportRosterFromTim { /** - * Import rosters from Tim and update workers' {@link CalendarException} - *

- * If worker's calendar exception already exists it will be removed and - * added new one, in other cases a new calendar exception will be created + * Import rosters from Tim and update workers {@link CalendarException} + * + * If worker calendar exception already exists it will be removed and added + * new one, in other cases a new calendar exception will be created */ void importRosters(); } diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/ISchedulerManager.java b/libreplan-webapp/src/main/java/org/libreplan/importers/ISchedulerManager.java index b02a75d44..c5913488e 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/ISchedulerManager.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/ISchedulerManager.java @@ -28,35 +28,36 @@ import org.springframework.scheduling.quartz.JobDetailBean; /** * A manager(client) that dynamically creates jobs and cron-triggers using * spring quartz library. - *

+ * * The start and destroy of the scheduler itself is managed by the Spring * framework. The scheduler starts automatically when the application starts and * destroyed when the application stops. The sole purpose of this manager is to * create jobs {@link JobDetailBean} and cron-triggers {@link CronTriggerBean} * when the scheduler is started. It links the triggers with the jobs and add * them to the scheduler. - *

- * It also supports the rescheduling of jobs. - *

+ * * The SchedulerManager reads the jobs to be scheduled and the cron-triggers to - * fire the jobs form {@link JobSchedulerConfiguration}. Hence the - * {@link JobSchedulerConfiguration} must exist with predefined jobs and valid - * cron-triggers + * fire the jobs form the {@link JobSchedulerConfiguration} entity. Hence the + * {@link JobSchedulerConfiguration} entity must exist with predefined jobs and + * valid cron-triggers + * + * This manager also supports the rescheduling of jobs. * * @author Miciele Ghiorghis */ public interface ISchedulerManager { /** - * Reads job configuration from the database and schedules the jobs + * Reads job configuration from the {@link JobSchedulerConfiguration} and + * schedules the jobs as defined in the configuration */ void scheduleJobs(); /** * Reschedule the job. - *

+ * * Reads the job to be rescheduled from the specified parameter - * {@link JobSchedulerConfiguration} and reschedule the job + * {@link JobSchedulerConfiguration} and reschedule the job accordingly * * @param jobSchedulerConfiguration * the job scheduler configuration @@ -64,9 +65,9 @@ public interface ISchedulerManager { void rescheduleJob(JobSchedulerConfiguration jobSchedulerConfiguration); /** - * returns the scheduler info list. This is necessary for UI + * returns the scheduler info list. Can be useful to display in UI * - * @return + * @return list of scheduler info */ List getSchedulerInfos(); diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/ImportRosterFromTim.java b/libreplan-webapp/src/main/java/org/libreplan/importers/ImportRosterFromTim.java index e1f6c10ba..1e151041f 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/ImportRosterFromTim.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/ImportRosterFromTim.java @@ -45,15 +45,15 @@ import org.libreplan.business.resources.daos.IWorkerDAO; import org.libreplan.business.resources.entities.Worker; import org.libreplan.business.workingday.EffortDuration; import org.libreplan.importers.RosterException.RosterExceptionItem; -import org.libreplan.importers.tim.Data; -import org.libreplan.importers.tim.Department; -import org.libreplan.importers.tim.Filter; -import org.libreplan.importers.tim.Period; -import org.libreplan.importers.tim.Person; -import org.libreplan.importers.tim.Roster; -import org.libreplan.importers.tim.RosterCategory; -import org.libreplan.importers.tim.RosterRequest; -import org.libreplan.importers.tim.RosterResponse; +import org.libreplan.importers.tim.DataDTO; +import org.libreplan.importers.tim.DepartmentDTO; +import org.libreplan.importers.tim.FilterDTO; +import org.libreplan.importers.tim.PeriodDTO; +import org.libreplan.importers.tim.PersonDTO; +import org.libreplan.importers.tim.RosterCategoryDTO; +import org.libreplan.importers.tim.RosterDTO; +import org.libreplan.importers.tim.RosterRequestDTO; +import org.libreplan.importers.tim.RosterResponseDTO; import org.libreplan.web.calendars.IBaseCalendarModel; import org.libreplan.web.resources.worker.IWorkerModel; import org.springframework.beans.factory.annotation.Autowired; @@ -63,6 +63,11 @@ import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +/** + * Implementation of import roosters from tim + * + * @author Miciele Ghiorghis + */ @Component @Scope(BeanDefinition.SCOPE_SINGLETON) public class ImportRosterFromTim implements IImportRosterFromTim { @@ -106,12 +111,12 @@ public class ImportRosterFromTim implements IImportRosterFromTim { int nrDaysRosterFromTim = Integer.parseInt(prop .get("NrDaysRosterFromTim")); - RosterRequest rosterRequest = createRosterRequest(nrDaysRosterFromTim); - RosterResponse rosterResponse = TimSoapClient + RosterRequestDTO rosterRequestDTO = createRosterRequest(nrDaysRosterFromTim); + RosterResponseDTO rosterResponseDTO = TimSoapClient .sendRequestReceiveResponse(url, userName, password, - rosterRequest, RosterResponse.class); + rosterRequestDTO, RosterResponseDTO.class); - updateWorkersCalendarException(rosterResponse); + updateWorkersCalendarException(rosterResponseDTO); } @@ -122,7 +127,7 @@ public class ImportRosterFromTim implements IImportRosterFromTim { * the response from Tim SOAP server */ private void updateWorkersCalendarException( - final RosterResponse rosterResponse) { + final RosterResponseDTO rosterResponse) { adHocTransactionService .runOnAnotherTransaction(new IOnTransaction() { @@ -133,7 +138,7 @@ public class ImportRosterFromTim implements IImportRosterFromTim { if (!rosterExceptions.isEmpty()) { updateCalendarException(rosterExceptions); } else { - LOG.info("No roster-exceptions found in the response object"); + LOG.info("No roster-exceptions found in the response"); } return null; } @@ -141,25 +146,25 @@ public class ImportRosterFromTim implements IImportRosterFromTim { } /** - * Loops through rosterResponse and creates - * {@link RosterException}s if any and link them to the worker + * Loops through rosterResponseDTO and creates + * {@link RosterException}s and link them to the worker * - * @param rosterResponse + * @param rosterResponseDTO * the response * @return a list of RosterExceptions */ private List getRosterExceptions( - RosterResponse rosterResponse) { - Map> map = getRosterExceptionPerWorker(rosterResponse); + RosterResponseDTO rosterResponseDTO) { + Map> map = getRosterExceptionPerWorker(rosterResponseDTO); List rosterExceptions = new ArrayList(); - for (Map.Entry> entry : map.entrySet()) { + for (Map.Entry> entry : map.entrySet()) { Worker worker = getWorker(entry.getKey()); if (worker != null) { - List list = entry.getValue(); - Collections.sort(list, new Comparator() { + List list = entry.getValue(); + Collections.sort(list, new Comparator() { @Override - public int compare(Roster o1, Roster o2) { + public int compare(RosterDTO o1, RosterDTO o2) { return o1.getDate().compareTo(o2.getDate()); } }); @@ -172,25 +177,26 @@ public class ImportRosterFromTim implements IImportRosterFromTim { } /** - * Filters the roster exceptions and creates map of personsNetwork name with - * associated roster (exceptions) + * Filters the roster on exceptions(absence) and creates a map with + * personsNetwork-name as key + * and list of roster-exception as value * - * @param rosterResponse + * @param rosterResponseDTO * the response * @return person-roster exception map */ - private Map> getRosterExceptionPerWorker( - RosterResponse rosterResponse) { - Map> rosterMap = new HashMap>(); - List rosters = rosterResponse.getRosters(); - for (Roster roster : rosters) { - if (roster.getPrecence().equals("Afwezig")) { - String personsNetWorkName = roster.getPersons().get(0) + private Map> getRosterExceptionPerWorker( + RosterResponseDTO rosterResponseDTO) { + Map> rosterMap = new HashMap>(); + List rosterDTOs = rosterResponseDTO.getRosters(); + for (RosterDTO rosterDTO : rosterDTOs) { + if (rosterDTO.getPrecence().equals("Afwezig")) { + String personsNetWorkName = rosterDTO.getPersons().get(0) .getNetworkName(); if (!rosterMap.containsKey(personsNetWorkName)) { - rosterMap.put(personsNetWorkName, new ArrayList()); + rosterMap.put(personsNetWorkName, new ArrayList()); } - rosterMap.get(personsNetWorkName).add(roster); + rosterMap.get(personsNetWorkName).add(rosterDTO); } } return rosterMap; @@ -198,7 +204,7 @@ public class ImportRosterFromTim implements IImportRosterFromTim { /** - * updates workers calendar exception + * updates the workers calendar exception * * @param rosterExceptions * list of roster exceptions @@ -218,8 +224,8 @@ public class ImportRosterFromTim implements IImportRosterFromTim { /** - * updates calendar exception of the specified {@link Worker} - * for the specified date + * updates the calendar exception of the specified + * {@link Worker} for the specified date * * @param worker * the worker @@ -265,7 +271,7 @@ public class ImportRosterFromTim implements IImportRosterFromTim { */ private CalendarExceptionType getCalendarExceptionType(String name) { if (name == null || name.isEmpty()) { - LOG.error("name should not be empty"); + LOG.error("Exception name should not be empty"); return null; } try { @@ -290,7 +296,7 @@ public class ImportRosterFromTim implements IImportRosterFromTim { } /** - * returns {@link Worker} based on the specified nif + * returns {@link Worker} for the specified nif * * @param nif * the worker's nif @@ -306,81 +312,81 @@ public class ImportRosterFromTim implements IImportRosterFromTim { } /** - * creates and returns {@link RosterRequest} + * creates and returns {@link RosterRequestDTO} * * @param nrDaysRosterFromTim * nr of days required to set the end date */ - private RosterRequest createRosterRequest(int nrDaysRosterFromTim) { - Roster roster = createRoster(nrDaysRosterFromTim); + private RosterRequestDTO createRosterRequest(int nrDaysRosterFromTim) { + RosterDTO rosterDTO = createRoster(nrDaysRosterFromTim); - Period periode = new Period(); - periode.setStart(new org.joda.time.DateTime()); - periode.setEnd(new org.joda.time.DateTime() + PeriodDTO periodeDTO = new PeriodDTO(); + periodeDTO.setStart(new org.joda.time.DateTime()); + periodeDTO.setEnd(new org.joda.time.DateTime() .plusDays(nrDaysRosterFromTim)); - List periods = new ArrayList(); - periods.add(periode); + List periodDTOs = new ArrayList(); + periodDTOs.add(periodeDTO); - Department department = new Department(); - department.setRef("4"); // TODO: make this configurable + DepartmentDTO departmentDTO = new DepartmentDTO(); + departmentDTO.setRef("4"); // TODO: make this configurable - Filter filter = new Filter(); - filter.setPeriods(periods); - filter.setDepartment(department); + FilterDTO filterDTO = new FilterDTO(); + filterDTO.setPeriods(periodDTOs); + filterDTO.setDepartment(departmentDTO); - roster.setFilter(filter); + rosterDTO.setFilter(filterDTO); - roster.setPersons(createPerson()); + rosterDTO.setPersons(createPerson()); - roster.setRosterCategories(createRosterCategory()); + rosterDTO.setRosterCategories(createRosterCategory()); - roster.setDepartment(department); + rosterDTO.setDepartment(departmentDTO); - roster.setPrecence(new String()); - roster.setPeriods(periods); + rosterDTO.setPrecence(new String()); + rosterDTO.setPeriods(periodDTOs); - RosterRequest exportRosterRequest = new RosterRequest(); - Data data = new Data(); - data.setData(roster); + RosterRequestDTO exportRosterRequestDTO = new RosterRequestDTO(); + DataDTO dataDTO = new DataDTO(); + dataDTO.setData(rosterDTO); - exportRosterRequest.setData(data); - return exportRosterRequest; + exportRosterRequestDTO.setData(dataDTO); + return exportRosterRequestDTO; } /** - * creates and returns list of {@link Persoon} + * creates and returns list of {@link PersonDTO} */ - private List createPerson() { - List persons = new ArrayList(); - persons.add(new Person()); - return persons; + private List createPerson() { + List personDTOs = new ArrayList(); + personDTOs.add(new PersonDTO()); + return personDTOs; } /** - * creates and returns list of {@link RosterCategory} + * creates and returns list of {@link RosterCategoryDTO} */ - private List createRosterCategory() { - List rosterCategories = new ArrayList(); - RosterCategory rosterCategory = new RosterCategory(); - rosterCategory.setName(new String()); - rosterCategories.add(rosterCategory); - return rosterCategories; + private List createRosterCategory() { + List rosterCategorieDTOs = new ArrayList(); + RosterCategoryDTO rosterCategoryDTO = new RosterCategoryDTO(); + rosterCategoryDTO.setName(new String()); + rosterCategorieDTOs.add(rosterCategoryDTO); + return rosterCategorieDTOs; } /** - * creates and returns {@Roster} + * creates and returns {@link RosterDTO} */ - private Roster createRoster(int nrDaysRosterFromTim) { - Roster roster = new Roster(); - roster.setStartDate(new LocalDate()); - roster.setEndDate(new LocalDate().plusDays(nrDaysRosterFromTim)); - roster.setResourcePlanning(false); - roster.setDayPlanning(false); - roster.setCalendar(false); - roster.setNonPlaned(true); - roster.setFullDay(false); - roster.setConcept(false); - return roster; + private RosterDTO createRoster(int nrDaysRosterFromTim) { + RosterDTO rosterDTO = new RosterDTO(); + rosterDTO.setStartDate(new LocalDate()); + rosterDTO.setEndDate(new LocalDate().plusDays(nrDaysRosterFromTim)); + rosterDTO.setResourcePlanning(false); + rosterDTO.setDayPlanning(false); + rosterDTO.setCalendar(false); + rosterDTO.setNonPlaned(true); + rosterDTO.setFullDay(false); + rosterDTO.setConcept(false); + return rosterDTO; } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/RosterException.java b/libreplan-webapp/src/main/java/org/libreplan/importers/RosterException.java index 4fee77f05..29ac804d0 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/RosterException.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/RosterException.java @@ -27,10 +27,10 @@ import java.util.TreeMap; import org.joda.time.LocalDate; import org.libreplan.business.resources.entities.Worker; import org.libreplan.business.workingday.EffortDuration; -import org.libreplan.importers.tim.Roster; +import org.libreplan.importers.tim.RosterDTO; /** - * Helper class to convert the Roster response to the RosterExceptions + * Class to convert the Roster response DTO to the RosterException * * @author Miciele Ghiorghis */ @@ -46,20 +46,21 @@ public class RosterException { * Reads the rosters and add the exceptions to * rosterExceptionItems * - * @param rosters + * @param rosterDTOs + * list of rosterDTO */ - public void addRosterExceptions(List rosters) { - Map> mapDateRoster = new TreeMap>(); + public void addRosterExceptions(List rosterDTOs) { + Map> mapDateRosterDTO = new TreeMap>(); - for (Roster roster : rosters) { - if (!mapDateRoster.containsKey(roster.getDate())) { - mapDateRoster.put(roster.getDate(), new ArrayList()); + for (RosterDTO rosterDTO : rosterDTOs) { + if (!mapDateRosterDTO.containsKey(rosterDTO.getDate())) { + mapDateRosterDTO.put(rosterDTO.getDate(), new ArrayList()); } - mapDateRoster.get(roster.getDate()).add(roster); + mapDateRosterDTO.get(rosterDTO.getDate()).add(rosterDTO); } - for (Map.Entry> entry : mapDateRoster + for (Map.Entry> entry : mapDateRosterDTO .entrySet()) { RosterExceptionItem item = new RosterExceptionItem(entry.getKey()); updateExceptionTypeAndEffort(item, entry.getValue()); @@ -72,20 +73,21 @@ public class RosterException { * * @param rosterExceptionItem * the rosterException item - * @param rosters - * list of rosters + * @param rosterDTOs + * list of rosterDTO */ private void updateExceptionTypeAndEffort( - RosterExceptionItem rosterExceptionItem, List rosters) { + RosterExceptionItem rosterExceptionItem, List rosterDTOs) { EffortDuration max = EffortDuration.zero(); EffortDuration sum = EffortDuration.zero(); - String rosterCatName = rosters.get(0).getRosterCategories().get(0) + String rosterCatName = rosterDTOs.get(0).getRosterCategories().get(0) .getName(); - for (Roster roster : rosters) { + for (RosterDTO rosterDTO : rosterDTOs) { EffortDuration duration = EffortDuration - .parseFromFormattedString(roster.getDuration()); + .parseFromFormattedString(rosterDTO.getDuration()); if (duration.compareTo(max) > 0) { - rosterCatName = roster.getRosterCategories().get(0).getName(); + rosterCatName = rosterDTO.getRosterCategories().get(0) + .getName(); } max = EffortDuration.max(max, duration); sum = EffortDuration.sum(sum, duration); @@ -109,6 +111,9 @@ public class RosterException { return rosterExceptionItems; } + /** + * class representing RosterExceptionItem + */ public class RosterExceptionItem { private LocalDate date; private String exceptionType; diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/SchedulerInfo.java b/libreplan-webapp/src/main/java/org/libreplan/importers/SchedulerInfo.java index 277d45fac..5cd0e15f1 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/SchedulerInfo.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/SchedulerInfo.java @@ -22,7 +22,8 @@ package org.libreplan.importers; import org.libreplan.business.common.entities.JobSchedulerConfiguration; /** - * The schedulerInfo non persistent entity + * Holds information about the scheduler, The information comes partly form + * {@link JobSchedulerConfiguration} and partly form {@link SchedulerManager} * * @author Miciele Ghiorghis */ diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/SchedulerManager.java b/libreplan-webapp/src/main/java/org/libreplan/importers/SchedulerManager.java index 14a007cb3..302290f2d 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/SchedulerManager.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/SchedulerManager.java @@ -41,6 +41,11 @@ import org.springframework.scheduling.quartz.JobDetailBean; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +/** + * Implementation of scheduler manager + * + * @author Miciele Ghiorghis + */ @Service @Scope(BeanDefinition.SCOPE_SINGLETON) public class SchedulerManager implements ISchedulerManager { diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/TimSoapClient.java b/libreplan-webapp/src/main/java/org/libreplan/importers/TimSoapClient.java index f51835b74..edd96c064 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/TimSoapClient.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/TimSoapClient.java @@ -38,15 +38,14 @@ import javax.xml.soap.SOAPPart; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.cxf.common.util.Base64Utility; -import org.libreplan.importers.tim.RosterResponse; +import org.libreplan.importers.tim.RosterResponseDTO; /** * Client to interact with Tim SOAP server. - *

- * It creates SOAP message, makes connection to the SOAP server and sends the - * request. - *

- * The received response is converted to java objects + * + * This client creates SOAP message, makes connection to the SOAP server and + * sends the request. It is also the task of this client to convert the + * response(xml document) to java objects * * @author Miciele Ghiorghis */ @@ -58,13 +57,16 @@ public class TimSoapClient { * Creates request message to be send to the SOAP server * * @param clazz + * object to be marshaled * @param userName * the user name * @param password * the password * @return the created soap message * @throws SOAPException + * if unable to create message or envelope * @throws JAXBException + * if unable to marshal the clazz */ private static SOAPMessage createRequest(T clazz, String userName, String password) throws SOAPException, JAXBException { @@ -85,8 +87,9 @@ public class TimSoapClient { /** * Creates SOAP message to be send to the SOAP server * - * @return the SOAP message + * @return the created SOAP message * @throws SOAPException + * if unable to create soap message */ private static SOAPMessage createMessage() throws SOAPException { MessageFactory messageFactory = MessageFactory.newInstance(); @@ -113,7 +116,8 @@ public class TimSoapClient { } /** - * Creates SOAP envelope + * Creates SOAP envelope and adds namespace declaration and sets encoding + * style * * @param soapPart * the message part @@ -164,13 +168,15 @@ public class TimSoapClient { } /** - * Marshals the specified parameter clazz + * Marshals the specified parameter clazz to the specified + * soapBody * * @param clazz * the object to be marshaled * @param soapBody - * the SOAP body + * the SOAP body, result of marshal * @throws JAXBException + * if marshaling failed */ private static void marshal(T clazz, SOAPBody soapBody) throws JAXBException { @@ -180,14 +186,16 @@ public class TimSoapClient { } /** - * Unmarshals the specified paramter soapBody + * Unmarshals the specified paramter soapBody to the specified + * clazz * * @param clazz - * object for unmarashal + * object to hold unmarashal result * @param soapBody * the soap body to be unmarshalled * @return the unmarashalled object * @throws JAXBException + * if unmarshal failed */ @SuppressWarnings("unchecked") private static T unmarshal(Class clazz, SOAPBody soapBody) @@ -211,6 +219,7 @@ public class TimSoapClient { * the SOAP message to be send * @return the response, SOAP message * @throws SOAPException + * if unable to send request */ private static SOAPMessage sendRequest(String url, SOAPMessage message) throws SOAPException { @@ -233,6 +242,7 @@ public class TimSoapClient { * * @return the SOAPconnection object * @throws SOAPException + * if unable to create connection */ private static SOAPConnection createConnection() throws SOAPException { SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory @@ -247,6 +257,7 @@ public class TimSoapClient { * @param connection * the SOAP connection * @throws SOAPException + * if unable to close connection */ private static void closeConnection(SOAPConnection connection) throws SOAPException { @@ -267,7 +278,7 @@ public class TimSoapClient { * the request object * @param response * the response class - * @return returns the expected object + * @return the expected object or null */ public static T sendRequestReceiveResponse(String url, String userName, String password, U request, Class response) { @@ -285,7 +296,7 @@ public class TimSoapClient { } /** - * Checks authorization based on the specified username and + * Checks authorization for the specified username and * password * * @param url @@ -311,21 +322,23 @@ public class TimSoapClient { /** * simulates roster response, to be used for example by unit test - *

- * unmarshals roster xml from file and returns {@link RosterResponse} + * + * unmarshals the roster xml from the specified file and + * returns {@link RosterResponseDTO} * * @param file * file with xml contents + * @return exportRosterDTO if unmarshal succeeded otherwise null */ - public static RosterResponse unmarshalRosterFromFile(File file) { + public static RosterResponseDTO unmarshalRosterFromFile(File file) { try { JAXBContext jaxbContext = JAXBContext - .newInstance(RosterResponse.class); + .newInstance(RosterResponseDTO.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - RosterResponse exportResponse = (RosterResponse) unmarshaller + RosterResponseDTO exportResponseDTO = (RosterResponseDTO) unmarshaller .unmarshal(file); - return exportResponse; + return exportResponseDTO; } catch (JAXBException e) { LOG.error("Error processing response: ", e); } diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/Data.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/DataDTO.java similarity index 87% rename from libreplan-webapp/src/main/java/org/libreplan/importers/tim/Data.java rename to libreplan-webapp/src/main/java/org/libreplan/importers/tim/DataDTO.java index b94b4c728..7cfb9e2fa 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/Data.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/DataDTO.java @@ -25,10 +25,15 @@ import javax.xml.bind.annotation.XmlAnyElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlSeeAlso; +/** + * DTO representing a tim-connector Data + * + * @author Miciele Ghiorghis + */ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement -@XmlSeeAlso({ Roster.class }) -public class Data { +@XmlSeeAlso({ RosterDTO.class }) +public class DataDTO { @XmlAnyElement private T data; diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/Department.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/DepartmentDTO.java similarity index 90% rename from libreplan-webapp/src/main/java/org/libreplan/importers/tim/Department.java rename to libreplan-webapp/src/main/java/org/libreplan/importers/tim/DepartmentDTO.java index 88ca422e9..57368e9de 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/Department.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/DepartmentDTO.java @@ -26,9 +26,14 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +/** + * DTO representing a tim-connector Department + * + * @author Miciele Ghiorghis + */ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "Afdeling") -public class Department { +public class DepartmentDTO { @XmlJavaTypeAdapter(CollapsedStringAdapter.class) @XmlElement diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/Duration.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/DurationDTO.java similarity index 91% rename from libreplan-webapp/src/main/java/org/libreplan/importers/tim/Duration.java rename to libreplan-webapp/src/main/java/org/libreplan/importers/tim/DurationDTO.java index 6ebd5125b..9ed34bc86 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/Duration.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/DurationDTO.java @@ -26,9 +26,14 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlValue; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +/** + * DTO representing a tim-connector Duration + * + * @author Miciele Ghiorghis + */ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement -public class Duration { +public class DurationDTO { @XmlAttribute(name = "options", required = true) private String options; diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/Filter.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/FilterDTO.java similarity index 68% rename from libreplan-webapp/src/main/java/org/libreplan/importers/tim/Filter.java rename to libreplan-webapp/src/main/java/org/libreplan/importers/tim/FilterDTO.java index fc83d82fa..3027c475a 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/Filter.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/FilterDTO.java @@ -26,51 +26,56 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +/** + * DTO representing a tim-connector filter + * + * @author Miciele Ghiorghis + */ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement -public class Filter { +public class FilterDTO { @XmlElement(name = "persoon") - private Person person; + private PersonDTO person; @XmlElement(name = "periode") - private List periods; + private List periods; @XmlElement(name = "Afdeling") - private Department department; + private DepartmentDTO department; @XmlElement(name = "roostercategorie") - private RosterCategory rosterCategory; + private RosterCategoryDTO rosterCategory; - public Person getPerson() { + public PersonDTO getPerson() { return person; } - public void setPerson(Person person) { + public void setPerson(PersonDTO person) { this.person = person; } - public List getPeriods() { + public List getPeriods() { return periods; } - public void setPeriods(List periods) { + public void setPeriods(List periods) { this.periods = periods; } - public Department getDepartment() { + public DepartmentDTO getDepartment() { return department; } - public void setDepartment(Department department) { + public void setDepartment(DepartmentDTO department) { this.department = department; } - public RosterCategory getRosterCategory() { + public RosterCategoryDTO getRosterCategory() { return rosterCategory; } - public void setRosterCategory(RosterCategory rosterCategory) { + public void setRosterCategory(RosterCategoryDTO rosterCategory) { this.rosterCategory = rosterCategory; } diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/Period.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/PeriodDTO.java similarity index 91% rename from libreplan-webapp/src/main/java/org/libreplan/importers/tim/Period.java rename to libreplan-webapp/src/main/java/org/libreplan/importers/tim/PeriodDTO.java index 1819a6bd5..7e1b81a64 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/Period.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/PeriodDTO.java @@ -26,9 +26,14 @@ import javax.xml.bind.annotation.XmlRootElement; import org.joda.time.DateTime; +/** + * DTO representing a tim-connector Period + * + * @author Miciele Ghiorghis + */ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement -public class Period { +public class PeriodDTO { @XmlElement(name = "startdate", required = true, nillable = true) private DateTime start; diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/Person.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/PersonDTO.java similarity index 94% rename from libreplan-webapp/src/main/java/org/libreplan/importers/tim/Person.java rename to libreplan-webapp/src/main/java/org/libreplan/importers/tim/PersonDTO.java index 3339764fd..61c112c02 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/Person.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/PersonDTO.java @@ -28,10 +28,15 @@ import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +/** + * DTO representing a tim-connector Person + * + * @author Miciele Ghiorghis + */ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "Persoon") @XmlType(propOrder = { "networkName", "name", "emailAddress" }) -public class Person { +public class PersonDTO { @XmlAttribute(name = "options") private String options; diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/Product.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/ProductDTO.java similarity index 92% rename from libreplan-webapp/src/main/java/org/libreplan/importers/tim/Product.java rename to libreplan-webapp/src/main/java/org/libreplan/importers/tim/ProductDTO.java index 677be7552..e657d249d 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/Product.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/ProductDTO.java @@ -27,9 +27,14 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +/** + * DTO representing a tim-connector Product + * + * @author Miciele Ghiorghis + */ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement -public class Product { +public class ProductDTO { @XmlAttribute(required = true) private String options; @@ -38,8 +43,6 @@ public class Product { @XmlElement private String code; - // @XmlJavaTypeAdapter(CollapsedStringAdapter.class) - // @XmlElement(name = "naam", nillable = true) private String name; public String getOptions() { diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RegistrationDate.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RegistrationDateDTO.java similarity index 90% rename from libreplan-webapp/src/main/java/org/libreplan/importers/tim/RegistrationDate.java rename to libreplan-webapp/src/main/java/org/libreplan/importers/tim/RegistrationDateDTO.java index c216878db..3cd66a8fe 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RegistrationDate.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RegistrationDateDTO.java @@ -27,9 +27,14 @@ import javax.xml.bind.annotation.XmlValue; import org.joda.time.LocalDate; +/** + * DTO representing a tim-connector RegistrationDate + * + * @author Miciele Ghiorghis + */ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "datum") -public class RegistrationDate { +public class RegistrationDateDTO { @XmlAttribute(name = "options", required = true) private String options; diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterCategory.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterCategoryDTO.java similarity index 93% rename from libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterCategory.java rename to libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterCategoryDTO.java index 1038c5ed9..56045fff4 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterCategory.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterCategoryDTO.java @@ -27,10 +27,15 @@ import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +/** + * DTO representing a tim-connector RosterCategory + * + * @author Miciele Ghiorghis + */ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "roostercategorie") @XmlType(propOrder = { "name", "presence", "status" }) -public class RosterCategory { +public class RosterCategoryDTO { @XmlJavaTypeAdapter(CollapsedStringAdapter.class) @XmlElement(name = "naam", required = true, nillable = true) diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/Roster.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterDTO.java similarity index 85% rename from libreplan-webapp/src/main/java/org/libreplan/importers/tim/Roster.java rename to libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterDTO.java index 5f452e3da..1bd831e0b 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/Roster.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterDTO.java @@ -32,9 +32,14 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import org.joda.time.LocalDate; import org.joda.time.LocalTime; +/** + * DTO representing a tim-connector Roster + * + * @author Miciele Ghiorghis + */ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "bezettingblok") -public class Roster { +public class RosterDTO { @XmlAttribute(name = "startdate", required = true) private LocalDate startDate; @@ -61,16 +66,16 @@ public class Roster { private Boolean concept; @XmlElement - private Filter filter; + private FilterDTO filter; @XmlElement(name = "Persoon") - private List persons; + private List persons; @XmlElement(name = "Roostercategorie") - private List rosterCategories; + private List rosterCategories; @XmlElement(name = "Afdeling") - private Department department; + private DepartmentDTO department; @XmlElement(name = "Datum", required = true, nillable = true) private LocalDate date; @@ -87,7 +92,7 @@ public class Roster { private String precence; @XmlElement(name = "periode") - private List periods; + private List periods; @XmlJavaTypeAdapter(CollapsedStringAdapter.class) @XmlElement(name = "status") @@ -157,35 +162,35 @@ public class Roster { this.concept = concept; } - public Filter getFilter() { + public FilterDTO getFilter() { return filter; } - public void setFilter(Filter filter) { + public void setFilter(FilterDTO filter) { this.filter = filter; } - public List getPersons() { + public List getPersons() { return persons; } - public void setPersons(List persons) { + public void setPersons(List persons) { this.persons = persons; } - public List getRosterCategories() { + public List getRosterCategories() { return rosterCategories; } - public void setRosterCategories(List rosterCategories) { + public void setRosterCategories(List rosterCategories) { this.rosterCategories = rosterCategories; } - public Department getDepartment() { + public DepartmentDTO getDepartment() { return department; } - public void setDepartment(Department department) { + public void setDepartment(DepartmentDTO department) { this.department = department; } @@ -221,11 +226,11 @@ public class Roster { this.precence = precence; } - public List getPeriods() { + public List getPeriods() { return periods; } - public void setPeriods(List periods) { + public void setPeriods(List periods) { this.periods = periods; } diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterRequest.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterRequestDTO.java similarity index 80% rename from libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterRequest.java rename to libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterRequestDTO.java index 5aacb8cf2..5e035ffc3 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterRequest.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterRequestDTO.java @@ -24,18 +24,23 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +/** + * DTO representing a tim-connector RosterRequest + * + * @author Miciele Ghiorghis + */ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "export", namespace = "impexp.timn.aenova.nl") -public class RosterRequest { +public class RosterRequestDTO { @XmlElement - private Data data; + private DataDTO data; - public Data getData() { + public DataDTO getData() { return data; } - public void setData(Data data) { + public void setData(DataDTO data) { this.data = data; } diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterResponse.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterResponseDTO.java similarity index 82% rename from libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterResponse.java rename to libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterResponseDTO.java index 8dabe6db9..7696f2cda 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterResponse.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/RosterResponseDTO.java @@ -27,19 +27,24 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; +/** + * DTO representing a tim-connector RosterResponse + * + * @author Miciele Ghiorghis + */ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "exportResponse", namespace = "impexp.timn.aenova.nl") -public class RosterResponse { +public class RosterResponseDTO { @XmlElementWrapper(name = "return") @XmlElement(name = "bezettingblok") - private List rosters; + private List rosters; - public List getRosters() { + public List getRosters() { return rosters; } - public void setRosters(List rosters) { + public void setRosters(List rosters) { this.rosters = rosters; } diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimDateTimeAdapter.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimDateTimeAdapter.java index d36afd714..643d4aba7 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimDateTimeAdapter.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimDateTimeAdapter.java @@ -25,6 +25,12 @@ import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; +/** + * Adapter responsible for converting from DateTime to + * string(tim-string-datetime) and vice versa + * + * @author Miciele Ghiorghis + */ public class TimDateTimeAdapter extends XmlAdapter { @Override diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimDoubleAdapter.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimDoubleAdapter.java index f9c3f8f50..431f3c6d0 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimDoubleAdapter.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimDoubleAdapter.java @@ -24,6 +24,12 @@ import java.util.Locale; import javax.xml.bind.DatatypeConverter; import javax.xml.bind.annotation.adapters.XmlAdapter; +/** + * Adapter responsible for converting from Double to + * string(tim-string-double) and vice versa + * + * @author Miciele Ghiorghis + */ public class TimDoubleAdapter extends XmlAdapter { @Override diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimLocalDateAdapter.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimLocalDateAdapter.java index 5fe698f88..7edf3e3b9 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimLocalDateAdapter.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimLocalDateAdapter.java @@ -25,6 +25,12 @@ import org.joda.time.LocalDate; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; +/** + * Adapter responsible for converting from LocalDate to + * string(tim-string-date) and vice versa + * + * @author Miciele Ghiorghis + */ public class TimLocalDateAdapter extends XmlAdapter { @Override diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimOptions.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimOptions.java index 0e038bb8e..8a0930a7b 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimOptions.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimOptions.java @@ -19,7 +19,12 @@ package org.libreplan.importers.tim; -public class TimOptions { +/** + * Class containing all constants for Tim-options. + * + * @author Miciele Ghiorghis + */ +public final class TimOptions { private TimOptions() { diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimTimeAdapter.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimTimeAdapter.java index 417513315..35f137ade 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimTimeAdapter.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimTimeAdapter.java @@ -23,6 +23,12 @@ import javax.xml.bind.annotation.adapters.XmlAdapter; import org.joda.time.LocalTime; +/** + * Adapter responsible for converting from LocalTime to + * string(tim-string-time) and vice versa + * + * @author Miciele Ghiorghis + */ public class TimTimeAdapter extends XmlAdapter { @Override diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistration.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistrationDTO.java similarity index 67% rename from libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistration.java rename to libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistrationDTO.java index 0f0374864..c4edc891e 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistration.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistrationDTO.java @@ -24,50 +24,55 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +/** + * DTO representing a tim-connector TimeRegistration + * + * @author Miciele Ghiorghis + */ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "tijdregistratie") -public class TimeRegistration { +public class TimeRegistrationDTO { @XmlElement(name = "persoon") - private Person person; + private PersonDTO person; - private Product product; + private ProductDTO product; @XmlElement(name = "datum") - private RegistrationDate registrationDate; + private RegistrationDateDTO registrationDate; @XmlElement(name = "duur") - private Duration duration; + private DurationDTO duration; - public Person getPerson() { + public PersonDTO getPerson() { return person; } - public void setPerson(Person person) { + public void setPerson(PersonDTO person) { this.person = person; } - public Product getProduct() { + public ProductDTO getProduct() { return product; } - public void setProduct(Product product) { + public void setProduct(ProductDTO product) { this.product = product; } - public RegistrationDate getRegistrationDate() { + public RegistrationDateDTO getRegistrationDate() { return registrationDate; } - public void setRegistrationDate(RegistrationDate registrationDate) { + public void setRegistrationDate(RegistrationDateDTO registrationDate) { this.registrationDate = registrationDate; } - public Duration getDuration() { + public DurationDTO getDuration() { return duration; } - public void setDuration(Duration duration) { + public void setDuration(DurationDTO duration) { this.duration = duration; } diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistrationRequest.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistrationRequestDTO.java similarity index 78% rename from libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistrationRequest.java rename to libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistrationRequestDTO.java index 6f9afebfb..e49b53fdd 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistrationRequest.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistrationRequestDTO.java @@ -27,19 +27,24 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; +/** + * DTO representing a tim-connector TimeRegistrationRequest + * + * @author Miciele Ghiorghis + */ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "import", namespace = "impexp.timn.aenova.nl") -public class TimeRegistrationRequest { +public class TimeRegistrationRequestDTO { @XmlElementWrapper(name = "data") @XmlElement(name = "tijdregistratie") - private List timeRegistrations; + private List timeRegistrations; - public List getTimeRegistrations() { + public List getTimeRegistrations() { return timeRegistrations; } - public void setTimeRegistrations(List timeRegistrations) { + public void setTimeRegistrations(List timeRegistrations) { this.timeRegistrations = timeRegistrations; } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistrationResponse.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistrationResponseDTO.java similarity index 88% rename from libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistrationResponse.java rename to libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistrationResponseDTO.java index 214cae8e0..23edc172a 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistrationResponse.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/TimeRegistrationResponseDTO.java @@ -27,9 +27,14 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; +/** + * DTO representing a tim-connector TimeRegistrationResponse + * + * @author Miciele Ghiorghis + */ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "importResponse", namespace = "impexp.timn.aenova.nl") -public class TimeRegistrationResponse { +public class TimeRegistrationResponseDTO { @XmlElementWrapper(name = "return") @XmlElement(name = "ref") diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/package-info.java b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/package-info.java index 677a210e5..3e67d0999 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/tim/package-info.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/tim/package-info.java @@ -17,6 +17,11 @@ * along with this program. If not, see . */ +/** + * An xmlAdapaters that will be applied within this package + * + * @author Miciele Ghiorghis + */ @javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters({ @javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(type = DateTime.class, value = org.libreplan.importers.tim.TimDateTimeAdapter.class), @javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(type = LocalDate.class, value = org.libreplan.importers.tim.TimLocalDateAdapter.class), diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/JobSchedulerController.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/JobSchedulerController.java index 724d9ad4c..89ce2467f 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/JobSchedulerController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/JobSchedulerController.java @@ -225,6 +225,7 @@ public class JobSchedulerController extends GenericForwardComposer { private String getNextToken(String token) { return token.isEmpty() ? "" : token.trim(); } + private void appendManualStart(final Row row, final SchedulerInfo schedulerInfo) { final Button rescheduleButton = new Button("Manual"); @@ -266,6 +267,9 @@ public class JobSchedulerController extends GenericForwardComposer { cronExpressionInputPopup.close(); } + /** + * Class representing cron expression + */ public class CronExpression { private String seconds; private String minutes; diff --git a/libreplan-webapp/src/test/java/importers/ExportTimesheetsToTimTest.java b/libreplan-webapp/src/test/java/importers/ExportTimesheetsToTimTest.java index 75051d1bc..8772a73ce 100644 --- a/libreplan-webapp/src/test/java/importers/ExportTimesheetsToTimTest.java +++ b/libreplan-webapp/src/test/java/importers/ExportTimesheetsToTimTest.java @@ -21,37 +21,59 @@ package importers; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.libreplan.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE; +import static org.libreplan.web.WebappGlobalNames.WEBAPP_SPRING_CONFIG_FILE; +import static org.libreplan.web.WebappGlobalNames.WEBAPP_SPRING_SECURITY_CONFIG_FILE; +import static org.libreplan.web.test.WebappGlobalNames.WEBAPP_SPRING_CONFIG_TEST_FILE; +import static org.libreplan.web.test.WebappGlobalNames.WEBAPP_SPRING_SECURITY_CONFIG_TEST_FILE; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; +import java.util.Date; import java.util.Properties; +import java.util.UUID; + +import javax.annotation.Resource; -import org.joda.time.LocalDate; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.libreplan.business.IDataBootstrap; +import org.libreplan.business.common.IAdHocTransactionService; +import org.libreplan.business.common.IOnTransaction; +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.entities.Order; +import org.libreplan.business.scenarios.IScenarioManager; +import org.libreplan.business.scenarios.entities.OrderVersion; +import org.libreplan.business.scenarios.entities.Scenario; import org.libreplan.importers.ExportTimesheetsToTim; -import org.libreplan.importers.TimSoapClient; -import org.libreplan.importers.tim.Duration; -import org.libreplan.importers.tim.Person; -import org.libreplan.importers.tim.Product; -import org.libreplan.importers.tim.RegistrationDate; -import org.libreplan.importers.tim.TimOptions; -import org.libreplan.importers.tim.TimeRegistration; -import org.libreplan.importers.tim.TimeRegistrationRequest; -import org.libreplan.importers.tim.TimeRegistrationResponse; +import org.libreplan.importers.IExportTimesheetsToTim; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.transaction.annotation.Transactional; /** * Test for {@link ExportTimesheetsToTim} * * @author Miciele Ghiorghis */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE, + WEBAPP_SPRING_CONFIG_FILE, WEBAPP_SPRING_CONFIG_TEST_FILE, + WEBAPP_SPRING_SECURITY_CONFIG_FILE, + WEBAPP_SPRING_SECURITY_CONFIG_TEST_FILE }) +@Transactional public class ExportTimesheetsToTimTest { private Properties properties = null; + @Autowired + IExportTimesheetsToTim exportTimesheetsToTim; + @Before public void loadProperties() throws FileNotFoundException, IOException { String filename = System.getProperty("user.dir") @@ -60,78 +82,99 @@ public class ExportTimesheetsToTimTest { properties.load(new FileInputStream(filename)); } - private TimeRegistration createTimeRegistration(String name, - String productCode, LocalDate localDate, Double hours) { - Person person = new Person(); - person.setName(name); - person.setOptions(TimOptions.UPDATE_OR_INSERT); + @Resource + private IDataBootstrap defaultAdvanceTypesBootstrapListener; - Product product = new Product(); - product.setOptions(TimOptions.UPDATE_OR_INSERT); - product.setCode(productCode); + @Resource + private IDataBootstrap scenariosBootstrap; - RegistrationDate date = new RegistrationDate(); - date.setOptions(TimOptions.UPDATE_OR_INSERT); - date.setDate(localDate); + @Resource + private IDataBootstrap configurationBootstrap; - Duration duration = new Duration(); - duration.setOptions(TimOptions.DECIMAL); - duration.setDuration(hours); + @Autowired + private IAdHocTransactionService transactionService; - TimeRegistration timeRegistration = new TimeRegistration(); - timeRegistration.setPerson(person); - timeRegistration.setProduct(product); - timeRegistration.setRegistrationDate(date); - timeRegistration.setDuration(duration); - return timeRegistration; + @Autowired + private IConfigurationDAO configurationDAO; + + @Autowired + private IOrderDAO orderDAO; + + @Autowired + private IScenarioManager scenarioManager; + + @Before + public void loadRequiredaData() { + + IOnTransaction load = new IOnTransaction() { + + @Override + public Void execute() { + defaultAdvanceTypesBootstrapListener.loadRequiredData(); + configurationBootstrap.loadRequiredData(); + scenariosBootstrap.loadRequiredData(); + return null; + } + }; + + transactionService.runOnAnotherTransaction(load); + } + + private Order givenOrder() { + return transactionService + .runOnAnotherTransaction(new IOnTransaction() { + @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 OrderVersion setupVersionUsing(IScenarioManager scenarioManager, + Order order) { + Scenario current = scenarioManager.getCurrent(); + OrderVersion result = OrderVersion.createInitialVersion(current); + order.setVersionForScenario(current, result); + return result; } @Test - public void testExporttTimeRegistrationWith1Item() { - List timeRegistrations = new ArrayList(); - TimeRegistration timeRegistration = createTimeRegistration( - "Baten, Jeroen", "5160", new LocalDate().minusDays(1), - 9.00); - timeRegistrations.add(timeRegistration); - TimeRegistrationRequest timeRegistrationRequest = new TimeRegistrationRequest(); - timeRegistrationRequest.setTimeRegistrations(timeRegistrations); - - TimeRegistrationResponse timeRegistrationResponse = TimSoapClient - .sendRequestReceiveResponse(properties.getProperty("url"), - properties.getProperty("username"), - properties.getProperty("password"), - timeRegistrationRequest, - TimeRegistrationResponse.class); - if (timeRegistrationResponse == null) { - fail("Time Registration Response is null"); + public void testExportTimesheetsToTimWithValidCodeAndOrder() { + Order order = givenOrder(); + boolean result = exportTimesheetsToTim.exportTimesheets("5160", order); + if (!result) { + fail("Export timesheets to tim failed"); } - assertTrue(!timeRegistrationResponse.getRefs().isEmpty()); + assertTrue(result); } - @Test - public void testExportTimeRegistrationWith2Items() { - List timeRegistrations = new ArrayList(); - TimeRegistration timeRegistration1 = createTimeRegistration( - "Baten, Jeroen", "5160", new LocalDate(), - 8.00); - timeRegistrations.add(timeRegistration1); - - TimeRegistration timeRegistration2 = createTimeRegistration( - "Baten, Jeroen", "5160", new LocalDate(), 9.00); - timeRegistrations.add(timeRegistration2); - - TimeRegistrationRequest timeRegistrationRequest = new TimeRegistrationRequest(); - timeRegistrationRequest.setTimeRegistrations(timeRegistrations); - - TimeRegistrationResponse timeRegistrationResponse = TimSoapClient - .sendRequestReceiveResponse(properties.getProperty("url"), - properties.getProperty("username"), - properties.getProperty("password"), - timeRegistrationRequest, TimeRegistrationResponse.class); - if (timeRegistrationResponse == null) { - fail("Time Registration Response is null"); - } - assertTrue(!timeRegistrationResponse.getRefs().isEmpty()); + @Test(expected = RuntimeException.class) + public void testExportTimesheetsToTimWithInvalidCode() { + Order order = givenOrder(); + exportTimesheetsToTim.exportTimesheets("", order); } + @Test(expected = RuntimeException.class) + public void testExportTimesheetsToTimWithOrderNull() { + exportTimesheetsToTim.exportTimesheets("5160", null); + } } diff --git a/libreplan-webapp/src/test/java/importers/ImportRosterFromTimTest.java b/libreplan-webapp/src/test/java/importers/ImportRosterFromTimTest.java index 07850f21b..2ac5d5187 100644 --- a/libreplan-webapp/src/test/java/importers/ImportRosterFromTimTest.java +++ b/libreplan-webapp/src/test/java/importers/ImportRosterFromTimTest.java @@ -19,56 +19,26 @@ package importers; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import static org.libreplan.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE; import static org.libreplan.web.WebappGlobalNames.WEBAPP_SPRING_CONFIG_FILE; import static org.libreplan.web.WebappGlobalNames.WEBAPP_SPRING_SECURITY_CONFIG_FILE; import static org.libreplan.web.test.WebappGlobalNames.WEBAPP_SPRING_CONFIG_TEST_FILE; import static org.libreplan.web.test.WebappGlobalNames.WEBAPP_SPRING_SECURITY_CONFIG_TEST_FILE; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.TreeMap; +import javax.annotation.Resource; -import org.joda.time.LocalDate; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.libreplan.business.calendars.entities.CalendarException; -import org.libreplan.business.calendars.entities.CalendarExceptionType; -import org.libreplan.business.calendars.entities.CalendarExceptionTypeColor; -import org.libreplan.business.calendars.entities.Capacity; -import org.libreplan.business.calendars.entities.ResourceCalendar; +import org.libreplan.business.IDataBootstrap; import org.libreplan.business.common.IAdHocTransactionService; import org.libreplan.business.common.IOnTransaction; -import org.libreplan.business.resources.daos.IWorkerDAO; -import org.libreplan.business.resources.entities.Worker; -import org.libreplan.business.workingday.EffortDuration; +import org.libreplan.importers.IImportRosterFromTim; import org.libreplan.importers.ImportRosterFromTim; -import org.libreplan.importers.TimSoapClient; -import org.libreplan.importers.tim.Data; -import org.libreplan.importers.tim.Department; -import org.libreplan.importers.tim.Filter; -import org.libreplan.importers.tim.Period; -import org.libreplan.importers.tim.Person; -import org.libreplan.importers.tim.Roster; -import org.libreplan.importers.tim.RosterCategory; -import org.libreplan.importers.tim.RosterRequest; -import org.libreplan.importers.tim.RosterResponse; -import org.libreplan.web.resources.worker.IWorkerModel; +import org.libreplan.web.calendars.IBaseCalendarModel; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -83,213 +53,47 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; WEBAPP_SPRING_SECURITY_CONFIG_FILE, WEBAPP_SPRING_SECURITY_CONFIG_TEST_FILE }) public class ImportRosterFromTimTest { - private Properties properties = null; - private RosterResponse rosterResponse = null; - @Autowired - IWorkerDAO workerDAO; + @Resource + private IDataBootstrap defaultAdvanceTypesBootstrapListener; - @Autowired - IWorkerModel workerModel; + @Resource + private IDataBootstrap scenariosBootstrap; + + @Resource + private IDataBootstrap configurationBootstrap; @Autowired private IAdHocTransactionService transactionService; - @Before - public void loadProperties() throws FileNotFoundException, IOException { - String filename = System.getProperty("user.dir") - + "/../scripts/tim-connector/tim-conn.properties"; - properties = new Properties(); - properties.load(new FileInputStream(filename)); - } + @Autowired + private IImportRosterFromTim importRosterFromTim; + + @Autowired + @Qualifier("subclass") + private IBaseCalendarModel baseCalendarModel; @Before - public void createRosterResponseFromFile() { - String filename = System.getProperty("user.dir") - + "/../scripts/tim_test/rosterResponse.xml"; - File file = new File(filename); - rosterResponse = TimSoapClient.unmarshalRosterFromFile(file); + public void loadRequiredaData() { - } + IOnTransaction load = new IOnTransaction() { - private List getAllWorkers() { - return transactionService - .runOnAnotherTransaction(new IOnTransaction>() { - @Override - public List execute() { - return workerDAO.findAll(); - } - }); - } - - private RosterRequest createtRosterRequest() { - Roster roster = new Roster(); - roster.setStartDate(new LocalDate()); - roster.setEndDate(new LocalDate().plusDays(7)); - roster.setResourcePlanning(false); - roster.setDayPlanning(false); - roster.setCalendar(false); - roster.setNonPlaned(true); - roster.setFullDay(false); - roster.setConcept(false); - - Period periode = new Period(); - periode.setStart(new org.joda.time.DateTime()); - periode.setEnd(new org.joda.time.DateTime().plusDays(7)); - List periods = new ArrayList(); - periods.add(periode); - - Department department = new Department(); - department.setRef("4"); - - RosterCategory rosterCategory = new RosterCategory(); - rosterCategory.setName(new String()); - List rosterCategories = new ArrayList(); - rosterCategories.add(rosterCategory); - - Filter filter = new Filter(); - filter.setPeriods(periods); - filter.setDepartment(department); - - roster.setFilter(filter); - - List persons = new ArrayList(); - persons.add(new Person()); - roster.setPersons(persons); - - roster.setRosterCategories(rosterCategories); - - roster.setDepartment(department); - - roster.setPrecence(new String()); - - roster.setPeriods(periods); - - RosterRequest exportRosterRequest = new RosterRequest(); - Data data = new Data(); - data.setData(roster); - - exportRosterRequest.setData(data); - return exportRosterRequest; - - } - - private Map> getRosterExceptionPerWorker() { - Map> rosterExceptionMap = new HashMap>(); - List rosters = rosterResponse.getRosters(); - for (Roster roster : rosters) { - if (roster.getPrecence().equals("Afwezig")) { - String personsNetWorkName = roster.getPersons().get(0) - .getNetworkName(); - if (!rosterExceptionMap.containsKey(personsNetWorkName)) { - rosterExceptionMap.put(personsNetWorkName, - new ArrayList()); - } - rosterExceptionMap.get(personsNetWorkName).add(roster); + @Override + public Void execute() { + defaultAdvanceTypesBootstrapListener.loadRequiredData(); + configurationBootstrap.loadRequiredData(); + scenariosBootstrap.loadRequiredData(); + return null; } - } - return rosterExceptionMap; - } + }; - private List getTheFirstRosterException() { - Map> rosterExceptionMap = getRosterExceptionPerWorker(); - return (List) rosterExceptionMap.entrySet().iterator().next() - .getValue(); - } - - private String getExceptionType(List rosters) { - for (Roster roster : rosters) { - return roster.getRosterCategories().get(0).getName(); - } - return null; - } - - private Entry getTheFirstEffortDuration( - List rosters) { - EffortDuration sum = EffortDuration.zero(); - Map map = new TreeMap(); - for (Roster roster : rosters) { - EffortDuration duration = EffortDuration - .parseFromFormattedString(roster.getDuration()); - sum = EffortDuration.sum(sum, duration); - map.put(roster.getDate(), sum); - } - return map.entrySet().iterator().next(); - } - - private Worker getWorker(final String nif) { - for (Worker worker : getAllWorkers()) { - if (worker.getNif().equals(nif)) { - return worker; - } - } - - Worker worker = Worker.create(); - worker.setFirstName("First name"); - worker.setSurname("Surname"); - worker.setNif(nif); - return worker; + transactionService.runOnAnotherTransaction(load); } @Test - public void testImportRostersFromServer() { - RosterResponse rosterResponse = TimSoapClient - .sendRequestReceiveResponse(properties.getProperty("url"), - properties.getProperty("username"), - properties.getProperty("password"), - createtRosterRequest(), RosterResponse.class); - if (rosterResponse == null) { - fail("Roster Response is null"); - } - assertTrue(rosterResponse != null); - } - - @Test - public void testImportRosterAndCheckRosterExceptionsPerWorker() { - Map> result = getRosterExceptionPerWorker(); - assertTrue(!result.isEmpty()); - } - - @Test - public void testRosterExceptionType() { - List rosters = getTheFirstRosterException(); - String exceptionType = getExceptionType(rosters); - assertEquals(exceptionType, "1Jus uren (van budget)"); - } - - @Test - public void testRosterExceptionsTotalEffortDuration() { - List rosters = getTheFirstRosterException(); - Entry effortDurationMap = getTheFirstEffortDuration(rosters); - EffortDuration duration = effortDurationMap.getValue(); - assertThat(duration.getHours(), equalTo(8)); - } - - @Test - public void testCreateCalendarException() { - List rosters = getTheFirstRosterException(); - String nif = rosters.get(0).getPersons().get(0).getNetworkName(); - - Entry dateDurationEntry = getTheFirstEffortDuration(rosters); - LocalDate date = dateDurationEntry.getKey(); - EffortDuration duration = dateDurationEntry.getValue(); - - Capacity capacity = Capacity.create(duration); - Worker worker = getWorker(nif); - - ResourceCalendar resourceCalendar = ResourceCalendar.create(); - resourceCalendar.setName("test"); - resourceCalendar.setCodeAutogenerated(); - resourceCalendar.setCapacity(capacity.getStandardEffort().getHours()); - worker.setCalendar(resourceCalendar); - - CalendarExceptionType type = CalendarExceptionType.create("TEST", - CalendarExceptionTypeColor.DEFAULT, true); - CalendarException calendarException = CalendarException.create(date, - capacity, type); - resourceCalendar.addExceptionDay(calendarException); - assertEquals(capacity.getStandardEffort().getHours(), resourceCalendar - .getCapacity().intValue()); + public void testImportRosters() { + importRosterFromTim.importRosters(); + assertTrue(baseCalendarModel.getCalendarExceptionType() != null); } } diff --git a/libreplan-webapp/src/test/java/importers/TimSoapClientTest.java b/libreplan-webapp/src/test/java/importers/TimSoapClientTest.java index fe2907985..f0c24479c 100644 --- a/libreplan-webapp/src/test/java/importers/TimSoapClientTest.java +++ b/libreplan-webapp/src/test/java/importers/TimSoapClientTest.java @@ -20,15 +20,36 @@ package importers; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.Properties; +import org.joda.time.LocalDate; import org.junit.Before; import org.junit.Test; import org.libreplan.importers.TimSoapClient; +import org.libreplan.importers.tim.DataDTO; +import org.libreplan.importers.tim.DepartmentDTO; +import org.libreplan.importers.tim.DurationDTO; +import org.libreplan.importers.tim.FilterDTO; +import org.libreplan.importers.tim.PeriodDTO; +import org.libreplan.importers.tim.PersonDTO; +import org.libreplan.importers.tim.ProductDTO; +import org.libreplan.importers.tim.RegistrationDateDTO; +import org.libreplan.importers.tim.RosterCategoryDTO; +import org.libreplan.importers.tim.RosterDTO; +import org.libreplan.importers.tim.RosterRequestDTO; +import org.libreplan.importers.tim.RosterResponseDTO; +import org.libreplan.importers.tim.TimOptions; +import org.libreplan.importers.tim.TimeRegistrationDTO; +import org.libreplan.importers.tim.TimeRegistrationRequestDTO; +import org.libreplan.importers.tim.TimeRegistrationResponseDTO; /** * Test for {@link TimSoapClient} @@ -47,8 +68,86 @@ public class TimSoapClientTest { properties.load(new FileInputStream(filename)); } + private TimeRegistrationDTO createTimeRegistration(String name, + String productCode, LocalDate localDate, Double hours) { + PersonDTO personDTO = new PersonDTO(); + personDTO.setName(name); + personDTO.setOptions(TimOptions.UPDATE_OR_INSERT); + + ProductDTO productDTO = new ProductDTO(); + productDTO.setOptions(TimOptions.UPDATE_OR_INSERT); + productDTO.setCode(productCode); + + RegistrationDateDTO dateDTO = new RegistrationDateDTO(); + dateDTO.setOptions(TimOptions.UPDATE_OR_INSERT); + dateDTO.setDate(localDate); + + DurationDTO durationDTO = new DurationDTO(); + durationDTO.setOptions(TimOptions.DECIMAL); + durationDTO.setDuration(hours); + + TimeRegistrationDTO timeRegistrationDTO = new TimeRegistrationDTO(); + timeRegistrationDTO.setPerson(personDTO); + timeRegistrationDTO.setProduct(productDTO); + timeRegistrationDTO.setRegistrationDate(dateDTO); + timeRegistrationDTO.setDuration(durationDTO); + return timeRegistrationDTO; + } + + private RosterRequestDTO createtRosterRequest() { + RosterDTO rosterDTO = new RosterDTO(); + rosterDTO.setStartDate(new LocalDate()); + rosterDTO.setEndDate(new LocalDate().plusDays(7)); + rosterDTO.setResourcePlanning(false); + rosterDTO.setDayPlanning(false); + rosterDTO.setCalendar(false); + rosterDTO.setNonPlaned(true); + rosterDTO.setFullDay(false); + rosterDTO.setConcept(false); + + PeriodDTO periodeDTO = new PeriodDTO(); + periodeDTO.setStart(new org.joda.time.DateTime()); + periodeDTO.setEnd(new org.joda.time.DateTime().plusDays(7)); + List periods = new ArrayList(); + periods.add(periodeDTO); + + DepartmentDTO departmentDTO = new DepartmentDTO(); + departmentDTO.setRef("4"); + + RosterCategoryDTO rosterCategoryDTO = new RosterCategoryDTO(); + rosterCategoryDTO.setName(new String()); + List rosterCategories = new ArrayList(); + rosterCategories.add(rosterCategoryDTO); + + FilterDTO filterDTO = new FilterDTO(); + filterDTO.setPeriods(periods); + filterDTO.setDepartment(departmentDTO); + + rosterDTO.setFilter(filterDTO); + + List personDTOs = new ArrayList(); + personDTOs.add(new PersonDTO()); + rosterDTO.setPersons(personDTOs); + + rosterDTO.setRosterCategories(rosterCategories); + + rosterDTO.setDepartment(departmentDTO); + + rosterDTO.setPrecence(new String()); + + rosterDTO.setPeriods(periods); + + RosterRequestDTO exportRosterRequestDTO = new RosterRequestDTO(); + DataDTO data = new DataDTO(); + data.setData(rosterDTO); + + exportRosterRequestDTO.setData(data); + return exportRosterRequestDTO; + + } + @Test - public void testAuthorization() { + public void testValidAuthorization() { boolean result = TimSoapClient.checkAuthorization( properties.getProperty("url"), properties.getProperty("username"), @@ -56,4 +155,85 @@ public class TimSoapClientTest { assertTrue(result); } + @Test + public void testInvalidAuthorization() { + boolean result = TimSoapClient.checkAuthorization( + properties.getProperty("url"), + properties.getProperty("username"), properties.getProperty("")); + assertTrue(!result); + } + + @Test + public void testImportRostersFromFile() { + String filename = System.getProperty("user.dir") + + "/../scripts/tim_test/rosterResponse.xml"; + File file = new File(filename); + RosterResponseDTO rosterResponseDTO = TimSoapClient + .unmarshalRosterFromFile(file); + if (rosterResponseDTO == null) { + fail("Roster Response is null"); + } + assertTrue(rosterResponseDTO.getRosters().size() > 0); + } + + @Test + public void testImportRostersFromServer() { + RosterResponseDTO rosterResponseDTO = TimSoapClient + .sendRequestReceiveResponse(properties.getProperty("url"), + properties.getProperty("username"), + properties.getProperty("password"), + createtRosterRequest(), RosterResponseDTO.class); + if (rosterResponseDTO == null) { + fail("Roster Response is null"); + } + assertTrue(rosterResponseDTO.getRosters().size() > 0); + } + + @Test + public void testExportTimeRegistrationWith1Item() { + List timeRegistrations = new ArrayList(); + TimeRegistrationDTO timeRegistration = createTimeRegistration( + "Baten, Jeroen", "5160", new LocalDate().minusDays(1), 9.00); + timeRegistrations.add(timeRegistration); + TimeRegistrationRequestDTO timeRegistrationRequestDTO = new TimeRegistrationRequestDTO(); + timeRegistrationRequestDTO.setTimeRegistrations(timeRegistrations); + + TimeRegistrationResponseDTO timeRegistrationResponse = TimSoapClient + .sendRequestReceiveResponse(properties.getProperty("url"), + properties.getProperty("username"), + properties.getProperty("password"), + timeRegistrationRequestDTO, + TimeRegistrationResponseDTO.class); + if (timeRegistrationResponse == null) { + fail("Time Registration Response is null"); + } + assertTrue(!timeRegistrationResponse.getRefs().isEmpty()); + } + + @Test + public void testExportTimeRegistrationWith2Items() { + List timeRegistrationDTOs = new ArrayList(); + TimeRegistrationDTO timeRegistrationDTO1 = createTimeRegistration( + "Baten, Jeroen", "5160", new LocalDate(), 8.00); + timeRegistrationDTOs.add(timeRegistrationDTO1); + + TimeRegistrationDTO timeRegistrationDTO2 = createTimeRegistration( + "Baten, Jeroen", "5160", new LocalDate(), 9.00); + timeRegistrationDTOs.add(timeRegistrationDTO2); + + TimeRegistrationRequestDTO timeRegistrationRequest = new TimeRegistrationRequestDTO(); + timeRegistrationRequest.setTimeRegistrations(timeRegistrationDTOs); + + TimeRegistrationResponseDTO timeRegistrationResponse = TimSoapClient + .sendRequestReceiveResponse(properties.getProperty("url"), + properties.getProperty("username"), + properties.getProperty("password"), + timeRegistrationRequest, + TimeRegistrationResponseDTO.class); + if (timeRegistrationResponse == null) { + fail("Time Registration Response is null"); + } + assertTrue(!timeRegistrationResponse.getRefs().isEmpty()); + } + }