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
This commit is contained in:
Miciele Ghiorghis 2013-02-07 15:04:13 +01:00 committed by Manuel Rego Casasnovas
parent a5ddbd45d4
commit 48cdded3e0
35 changed files with 742 additions and 560 deletions

View file

@ -33,7 +33,8 @@ import org.libreplan.business.orders.entities.OrderSyncInfo;
public interface IOrderSyncInfoDAO extends IGenericDAO<OrderSyncInfo, Long> {
/**
* Search last sychronized info for the specified <code>{@link Order}</code>
* Search last synchronized info for the specified
* <code>{@link Order}</code>
*
* @param order
* the order to search for

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
@ -134,8 +139,7 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
Map<String, String> 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<TimeRegistration> timeRegistrations = new ArrayList<TimeRegistration>();
List<TimeRegistrationDTO> timeRegistrationDTOs = new ArrayList<TimeRegistrationDTO>();
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;
}
/**

View file

@ -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
* <code>NrDaysTimesheetToTim</code> specified in configuration entity
* {@link AppProperties} and the current-date
*
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
*/
public interface IExportTimesheetsToTim {
/**
* Exports time sheets of the specified <code>productCode</code> and
* <code>{@link Order}</code>
* <code>{@link Order}</code> 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
* <p>
* This method is of importance for the scheduler service
* </p>
* 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();

View file

@ -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
* <code>NrDaysRosterFromTim</code> specified in configuration entity
* {@link AppProperties}
*
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
*/
public interface IImportRosterFromTim {
/**
* Import rosters from Tim and update workers' {@link CalendarException}
* <p>
* 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();
}

View file

@ -28,35 +28,36 @@ import org.springframework.scheduling.quartz.JobDetailBean;
/**
* A manager(client) that dynamically creates jobs and cron-triggers using
* spring quartz library.
* <p>
*
* 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.
* <p>
* It also supports the rescheduling of jobs.
* <p>
*
* 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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
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.
* <p>
*
* 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<SchedulerInfo> getSchedulerInfos();

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@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<Void>() {
@ -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 <code>rosterResponse</code> and creates
* {@link RosterException}s if any and link them to the worker
* Loops through <code>rosterResponseDTO</code> and creates
* {@link RosterException}s and link them to the <code>worker</code>
*
* @param rosterResponse
* @param rosterResponseDTO
* the response
* @return a list of RosterExceptions
*/
private List<RosterException> getRosterExceptions(
RosterResponse rosterResponse) {
Map<String, List<Roster>> map = getRosterExceptionPerWorker(rosterResponse);
RosterResponseDTO rosterResponseDTO) {
Map<String, List<RosterDTO>> map = getRosterExceptionPerWorker(rosterResponseDTO);
List<RosterException> rosterExceptions = new ArrayList<RosterException>();
for (Map.Entry<String, List<Roster>> entry : map.entrySet()) {
for (Map.Entry<String, List<RosterDTO>> entry : map.entrySet()) {
Worker worker = getWorker(entry.getKey());
if (worker != null) {
List<Roster> list = entry.getValue();
Collections.sort(list, new Comparator<Roster>() {
List<RosterDTO> list = entry.getValue();
Collections.sort(list, new Comparator<RosterDTO>() {
@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
* <code>personsNetwork-name</name> as key
* and list of <code>roster-exception</code> as value
*
* @param rosterResponse
* @param rosterResponseDTO
* the response
* @return person-roster exception map
*/
private Map<String, List<Roster>> getRosterExceptionPerWorker(
RosterResponse rosterResponse) {
Map<String, List<Roster>> rosterMap = new HashMap<String, List<Roster>>();
List<Roster> rosters = rosterResponse.getRosters();
for (Roster roster : rosters) {
if (roster.getPrecence().equals("Afwezig")) {
String personsNetWorkName = roster.getPersons().get(0)
private Map<String, List<RosterDTO>> getRosterExceptionPerWorker(
RosterResponseDTO rosterResponseDTO) {
Map<String, List<RosterDTO>> rosterMap = new HashMap<String, List<RosterDTO>>();
List<RosterDTO> 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<Roster>());
rosterMap.put(personsNetWorkName, new ArrayList<RosterDTO>());
}
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 <code>{@link Worker}</code>
* for the specified <code>date</code>
* updates the calendar exception of the specified
* <code>{@link Worker}</code> for the specified <code>date</code>
*
* @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 <code>nif</code>
* returns {@link Worker} for the specified <code>nif</code>
*
* @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<Period> periods = new ArrayList<Period>();
periods.add(periode);
List<PeriodDTO> periodDTOs = new ArrayList<PeriodDTO>();
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<Roster> data = new Data<Roster>();
data.setData(roster);
RosterRequestDTO exportRosterRequestDTO = new RosterRequestDTO();
DataDTO<RosterDTO> dataDTO = new DataDTO<RosterDTO>();
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<Person> createPerson() {
List<Person> persons = new ArrayList<Person>();
persons.add(new Person());
return persons;
private List<PersonDTO> createPerson() {
List<PersonDTO> personDTOs = new ArrayList<PersonDTO>();
personDTOs.add(new PersonDTO());
return personDTOs;
}
/**
* creates and returns list of {@link RosterCategory}
* creates and returns list of {@link RosterCategoryDTO}
*/
private List<RosterCategory> createRosterCategory() {
List<RosterCategory> rosterCategories = new ArrayList<RosterCategory>();
RosterCategory rosterCategory = new RosterCategory();
rosterCategory.setName(new String());
rosterCategories.add(rosterCategory);
return rosterCategories;
private List<RosterCategoryDTO> createRosterCategory() {
List<RosterCategoryDTO> rosterCategorieDTOs = new ArrayList<RosterCategoryDTO>();
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;
}
}

View file

@ -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 <code>RosterException<code>
*
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
*/
@ -46,20 +46,21 @@ public class RosterException {
* Reads the rosters and add the exceptions to
* <code>rosterExceptionItems</code>
*
* @param rosters
* @param rosterDTOs
* list of rosterDTO
*/
public void addRosterExceptions(List<Roster> rosters) {
Map<LocalDate, List<Roster>> mapDateRoster = new TreeMap<LocalDate, List<Roster>>();
public void addRosterExceptions(List<RosterDTO> rosterDTOs) {
Map<LocalDate, List<RosterDTO>> mapDateRosterDTO = new TreeMap<LocalDate, List<RosterDTO>>();
for (Roster roster : rosters) {
if (!mapDateRoster.containsKey(roster.getDate())) {
mapDateRoster.put(roster.getDate(), new ArrayList<Roster>());
for (RosterDTO rosterDTO : rosterDTOs) {
if (!mapDateRosterDTO.containsKey(rosterDTO.getDate())) {
mapDateRosterDTO.put(rosterDTO.getDate(), new ArrayList<RosterDTO>());
}
mapDateRoster.get(roster.getDate()).add(roster);
mapDateRosterDTO.get(rosterDTO.getDate()).add(rosterDTO);
}
for (Map.Entry<LocalDate, List<Roster>> entry : mapDateRoster
for (Map.Entry<LocalDate, List<RosterDTO>> 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<Roster> rosters) {
RosterExceptionItem rosterExceptionItem, List<RosterDTO> 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;

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@Service
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class SchedulerManager implements ISchedulerManager {

View file

@ -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.
* <p>
* It creates SOAP message, makes connection to the SOAP server and sends the
* request.
* <p>
* 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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@ -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 <T> 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 <code>clazz</code>
* Marshals the specified parameter <code>clazz</code> to the specified
* <code>soapBody</code>
*
* @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 <T> void marshal(T clazz, SOAPBody soapBody)
throws JAXBException {
@ -180,14 +186,16 @@ public class TimSoapClient {
}
/**
* Unmarshals the specified paramter <code>soapBody</code>
* Unmarshals the specified paramter <code>soapBody</code> to the specified
* <code>clazz</code>
*
* @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> T unmarshal(Class<T> 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, U> T sendRequestReceiveResponse(String url,
String userName, String password, U request, Class<T> response) {
@ -285,7 +296,7 @@ public class TimSoapClient {
}
/**
* Checks authorization based on the specified <code>username</code> and
* Checks authorization for the specified <code>username</code> and
* <code>password</code>
*
* @param url
@ -311,21 +322,23 @@ public class TimSoapClient {
/**
* simulates roster response, to be used for example by unit test
* <p>
* unmarshals roster xml from file and returns {@link RosterResponse}
*
* unmarshals the roster xml from the specified <code>file</code> 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);
}

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
@XmlSeeAlso({ Roster.class })
public class Data<T> {
@XmlSeeAlso({ RosterDTO.class })
public class DataDTO<T> {
@XmlAnyElement
private T data;

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Afdeling")
public class Department {
public class DepartmentDTO {
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlElement

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Duration {
public class DurationDTO {
@XmlAttribute(name = "options", required = true)
private String options;

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Filter {
public class FilterDTO {
@XmlElement(name = "persoon")
private Person person;
private PersonDTO person;
@XmlElement(name = "periode")
private List<Period> periods;
private List<PeriodDTO> 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<Period> getPeriods() {
public List<PeriodDTO> getPeriods() {
return periods;
}
public void setPeriods(List<Period> periods) {
public void setPeriods(List<PeriodDTO> 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;
}

View file

@ -26,9 +26,14 @@ import javax.xml.bind.annotation.XmlRootElement;
import org.joda.time.DateTime;
/**
* DTO representing a tim-connector Period
*
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Period {
public class PeriodDTO {
@XmlElement(name = "startdate", required = true, nillable = true)
private DateTime start;

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Persoon")
@XmlType(propOrder = { "networkName", "name", "emailAddress" })
public class Person {
public class PersonDTO {
@XmlAttribute(name = "options")
private String options;

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@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() {

View file

@ -27,9 +27,14 @@ import javax.xml.bind.annotation.XmlValue;
import org.joda.time.LocalDate;
/**
* DTO representing a tim-connector RegistrationDate
*
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "datum")
public class RegistrationDate {
public class RegistrationDateDTO {
@XmlAttribute(name = "options", required = true)
private String options;

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@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)

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@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<Person> persons;
private List<PersonDTO> persons;
@XmlElement(name = "Roostercategorie")
private List<RosterCategory> rosterCategories;
private List<RosterCategoryDTO> 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<Period> periods;
private List<PeriodDTO> 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<Person> getPersons() {
public List<PersonDTO> getPersons() {
return persons;
}
public void setPersons(List<Person> persons) {
public void setPersons(List<PersonDTO> persons) {
this.persons = persons;
}
public List<RosterCategory> getRosterCategories() {
public List<RosterCategoryDTO> getRosterCategories() {
return rosterCategories;
}
public void setRosterCategories(List<RosterCategory> rosterCategories) {
public void setRosterCategories(List<RosterCategoryDTO> 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<Period> getPeriods() {
public List<PeriodDTO> getPeriods() {
return periods;
}
public void setPeriods(List<Period> periods) {
public void setPeriods(List<PeriodDTO> periods) {
this.periods = periods;
}

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "export", namespace = "impexp.timn.aenova.nl")
public class RosterRequest {
public class RosterRequestDTO {
@XmlElement
private Data<Roster> data;
private DataDTO<RosterDTO> data;
public Data<Roster> getData() {
public DataDTO<RosterDTO> getData() {
return data;
}
public void setData(Data<Roster> data) {
public void setData(DataDTO<RosterDTO> data) {
this.data = data;
}

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@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<Roster> rosters;
private List<RosterDTO> rosters;
public List<Roster> getRosters() {
public List<RosterDTO> getRosters() {
return rosters;
}
public void setRosters(List<Roster> rosters) {
public void setRosters(List<RosterDTO> rosters) {
this.rosters = rosters;
}

View file

@ -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 <code>DateTime</code> to
* string(tim-string-datetime) and vice versa
*
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
*/
public class TimDateTimeAdapter extends XmlAdapter<String, DateTime> {
@Override

View file

@ -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 <code>Double</code> to
* string(tim-string-double) and vice versa
*
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
*/
public class TimDoubleAdapter extends XmlAdapter<String, Double> {
@Override

View file

@ -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 <code>LocalDate</code> to
* string(tim-string-date) and vice versa
*
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
*/
public class TimLocalDateAdapter extends XmlAdapter<String, LocalDate> {
@Override

View file

@ -19,7 +19,12 @@
package org.libreplan.importers.tim;
public class TimOptions {
/**
* Class containing all constants for Tim-options.
*
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
*/
public final class TimOptions {
private TimOptions() {

View file

@ -23,6 +23,12 @@ import javax.xml.bind.annotation.adapters.XmlAdapter;
import org.joda.time.LocalTime;
/**
* Adapter responsible for converting from <code>LocalTime</code> to
* string(tim-string-time) and vice versa
*
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
*/
public class TimTimeAdapter extends XmlAdapter<String, LocalTime> {
@Override

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@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;
}

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@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<TimeRegistration> timeRegistrations;
private List<TimeRegistrationDTO> timeRegistrations;
public List<TimeRegistration> getTimeRegistrations() {
public List<TimeRegistrationDTO> getTimeRegistrations() {
return timeRegistrations;
}
public void setTimeRegistrations(List<TimeRegistration> timeRegistrations) {
public void setTimeRegistrations(List<TimeRegistrationDTO> timeRegistrations) {
this.timeRegistrations = timeRegistrations;
}
}

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "importResponse", namespace = "impexp.timn.aenova.nl")
public class TimeRegistrationResponse {
public class TimeRegistrationResponseDTO {
@XmlElementWrapper(name = "return")
@XmlElement(name = "ref")

View file

@ -17,6 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* An xmlAdapaters that will be applied within this package
*
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
*/
@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),

View file

@ -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;

View file

@ -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 <m.ghiorghis@antoniusziekenhuis.nl>
*/
@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<Void> load = new IOnTransaction<Void>() {
@Override
public Void execute() {
defaultAdvanceTypesBootstrapListener.loadRequiredData();
configurationBootstrap.loadRequiredData();
scenariosBootstrap.loadRequiredData();
return null;
}
};
transactionService.runOnAnotherTransaction(load);
}
private Order givenOrder() {
return transactionService
.runOnAnotherTransaction(new IOnTransaction<Order>() {
@Override
public Order execute() {
return givenValidOrderAlreadyStored();
}
});
}
private Order givenValidOrderAlreadyStored() {
Order order = Order.create();
order.setCode(UUID.randomUUID().toString());
order.setName("Order name " + UUID.randomUUID());
order.setInitDate(new Date());
order.setCalendar(configurationDAO.getConfiguration()
.getDefaultCalendar());
OrderVersion version = setupVersionUsing(scenarioManager, order);
order.useSchedulingDataFor(version);
orderDAO.save(order);
orderDAO.flush();
try {
return orderDAO.find(order.getId());
} catch (InstanceNotFoundException e) {
return null;
}
}
private 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<TimeRegistration> timeRegistrations = new ArrayList<TimeRegistration>();
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<TimeRegistration> timeRegistrations = new ArrayList<TimeRegistration>();
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);
}
}

View file

@ -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<Void> load = new IOnTransaction<Void>() {
private List<Worker> getAllWorkers() {
return transactionService
.runOnAnotherTransaction(new IOnTransaction<List<Worker>>() {
@Override
public List<Worker> 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<Period> periods = new ArrayList<Period>();
periods.add(periode);
Department department = new Department();
department.setRef("4");
RosterCategory rosterCategory = new RosterCategory();
rosterCategory.setName(new String());
List<RosterCategory> rosterCategories = new ArrayList<RosterCategory>();
rosterCategories.add(rosterCategory);
Filter filter = new Filter();
filter.setPeriods(periods);
filter.setDepartment(department);
roster.setFilter(filter);
List<Person> persons = new ArrayList<Person>();
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<Roster> data = new Data<Roster>();
data.setData(roster);
exportRosterRequest.setData(data);
return exportRosterRequest;
}
private Map<String, List<Roster>> getRosterExceptionPerWorker() {
Map<String, List<Roster>> rosterExceptionMap = new HashMap<String, List<Roster>>();
List<Roster> 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<Roster>());
}
rosterExceptionMap.get(personsNetWorkName).add(roster);
@Override
public Void execute() {
defaultAdvanceTypesBootstrapListener.loadRequiredData();
configurationBootstrap.loadRequiredData();
scenariosBootstrap.loadRequiredData();
return null;
}
}
return rosterExceptionMap;
}
};
private List<Roster> getTheFirstRosterException() {
Map<String, List<Roster>> rosterExceptionMap = getRosterExceptionPerWorker();
return (List<Roster>) rosterExceptionMap.entrySet().iterator().next()
.getValue();
}
private String getExceptionType(List<Roster> rosters) {
for (Roster roster : rosters) {
return roster.getRosterCategories().get(0).getName();
}
return null;
}
private Entry<LocalDate, EffortDuration> getTheFirstEffortDuration(
List<Roster> rosters) {
EffortDuration sum = EffortDuration.zero();
Map<LocalDate, EffortDuration> map = new TreeMap<LocalDate, EffortDuration>();
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<String, List<Roster>> result = getRosterExceptionPerWorker();
assertTrue(!result.isEmpty());
}
@Test
public void testRosterExceptionType() {
List<Roster> rosters = getTheFirstRosterException();
String exceptionType = getExceptionType(rosters);
assertEquals(exceptionType, "1Jus uren (van budget)");
}
@Test
public void testRosterExceptionsTotalEffortDuration() {
List<Roster> rosters = getTheFirstRosterException();
Entry<LocalDate, EffortDuration> effortDurationMap = getTheFirstEffortDuration(rosters);
EffortDuration duration = effortDurationMap.getValue();
assertThat(duration.getHours(), equalTo(8));
}
@Test
public void testCreateCalendarException() {
List<Roster> rosters = getTheFirstRosterException();
String nif = rosters.get(0).getPersons().get(0).getNetworkName();
Entry<LocalDate, EffortDuration> 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);
}
}

View file

@ -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<PeriodDTO> periods = new ArrayList<PeriodDTO>();
periods.add(periodeDTO);
DepartmentDTO departmentDTO = new DepartmentDTO();
departmentDTO.setRef("4");
RosterCategoryDTO rosterCategoryDTO = new RosterCategoryDTO();
rosterCategoryDTO.setName(new String());
List<RosterCategoryDTO> rosterCategories = new ArrayList<RosterCategoryDTO>();
rosterCategories.add(rosterCategoryDTO);
FilterDTO filterDTO = new FilterDTO();
filterDTO.setPeriods(periods);
filterDTO.setDepartment(departmentDTO);
rosterDTO.setFilter(filterDTO);
List<PersonDTO> personDTOs = new ArrayList<PersonDTO>();
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<RosterDTO> data = new DataDTO<RosterDTO>();
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<TimeRegistrationDTO> timeRegistrations = new ArrayList<TimeRegistrationDTO>();
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<TimeRegistrationDTO> timeRegistrationDTOs = new ArrayList<TimeRegistrationDTO>();
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());
}
}