Update CXF.

Code refactoring.
Changes to config files.
This commit is contained in:
Vova Perebykivskyi 2016-05-10 13:20:53 +03:00 committed by Dgray16
parent f0d69af651
commit 5c7b5d92ef
11 changed files with 388 additions and 411 deletions

View file

@ -42,6 +42,10 @@ Changes
* Update Commons Collections * Update Commons Collections
* Update Commons Logging * Update Commons Logging
* Update CXF-transports-http
* Update CXF-frontend-jaxrs
* Add CXF-rs-client
* Update MPXJ * Update MPXJ
* Update Bonecp * Update Bonecp
* Update Guava * Update Guava

View file

@ -476,6 +476,10 @@
<groupId>org.apache.cxf</groupId> <groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId> <artifactId>cxf-rt-frontend-jaxrs</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId> <groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId> <artifactId>jackson-jaxrs-json-provider</artifactId>

View file

@ -53,11 +53,6 @@ public class JiraRESTClient {
*/ */
public static final String PATH_AUTH_SESSION = "rest/auth/latest/session"; public static final String PATH_AUTH_SESSION = "rest/auth/latest/session";
/**
* Path for issue operations in JIRA REST API
*/
public static final String PATH_ISSUE = "/rest/api/latest/issue/";
/** /**
* Fields to include in the response of rest/api/latest/search. * Fields to include in the response of rest/api/latest/search.
*/ */
@ -82,6 +77,7 @@ public class JiraRESTClient {
*/ */
public static String getAllLables(String url) { public static String getAllLables(String url) {
WebClient client = WebClient.create(url).accept(mediaTypes); WebClient client = WebClient.create(url).accept(mediaTypes);
return client.get(String.class); return client.get(String.class);
} }
@ -100,21 +96,23 @@ public class JiraRESTClient {
* the query * the query
* @return list of jira issues * @return list of jira issues
*/ */
public static List<IssueDTO> getIssues(String url, String username, public static List<IssueDTO> getIssues(String url, String username, String password, String path, String query) {
String password, String path, String query) {
WebClient client = createClient(url); WebClient client = createClient(url);
checkAutherization(client, username, password); checkAutherization(client, username, password);
client.back(true);// Go to baseURI // Go to baseURI
client.back(true);
client.path(path); client.path(path);
if (!query.isEmpty()) {
if ( !query.isEmpty() ) {
client.query("jql", query); client.query("jql", query);
} }
client.query("maxResults", MAX_RESULTS); client.query("maxResults", MAX_RESULTS);
client.query("fields", client.query("fields", StringUtils.deleteWhitespace(FIELDS_TO_INCLUDE_IN_RESPONSE));
StringUtils.deleteWhitespace(FIELDS_TO_INCLUDE_IN_RESPONSE));
SearchResultDTO searchResult = client.get(SearchResultDTO.class); SearchResultDTO searchResult = client.get(SearchResultDTO.class);
@ -133,8 +131,7 @@ public class JiraRESTClient {
JacksonJaxbJsonProvider jacksonJaxbJsonProvider = new JacksonJaxbJsonProvider(); JacksonJaxbJsonProvider jacksonJaxbJsonProvider = new JacksonJaxbJsonProvider();
jacksonJaxbJsonProvider.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); jacksonJaxbJsonProvider.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return WebClient.create(url, return WebClient.create(url, Collections.singletonList(jacksonJaxbJsonProvider)).accept(mediaTypes);
Collections.singletonList(jacksonJaxbJsonProvider)).accept(mediaTypes);
} }
@ -148,8 +145,7 @@ public class JiraRESTClient {
* @param password * @param password
* login password * login password
*/ */
private static void checkAutherization(WebClient client, String login, private static void checkAutherization(WebClient client, String login, String password) {
String password) {
NaiveTrustProvider.setAlwaysTrust(true); NaiveTrustProvider.setAlwaysTrust(true);
client.path(PATH_AUTH_SESSION); client.path(PATH_AUTH_SESSION);
@ -157,7 +153,7 @@ public class JiraRESTClient {
Util.addAuthorizationHeader(client, login, password); Util.addAuthorizationHeader(client, login, password);
Response response = client.get(); Response response = client.get();
if (response.getStatus() != Status.OK.getStatusCode()) { if ( response.getStatus() != Status.OK.getStatusCode() ) {
throw new RuntimeException("Authorization failed"); throw new RuntimeException("Authorization failed");
} }
} }

View file

@ -95,12 +95,12 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public List<SubcontractedTaskData> getSubcontractedTasks() { public List<SubcontractedTaskData> getSubcontractedTasks() {
List<SubcontractedTaskData> result = subcontractedTaskDataDAO List<SubcontractedTaskData> result = subcontractedTaskDataDAO.getAllForMasterScenario();
.getAllForMasterScenario();
for (SubcontractedTaskData subcontractedTaskData : result) { for (SubcontractedTaskData subcontractedTaskData : result) {
forceLoadExternalCompany(subcontractedTaskData); forceLoadExternalCompany(subcontractedTaskData);
forceLastDeliveryDate(subcontractedTaskData); forceLastDeliveryDate(subcontractedTaskData);
} }
return sortByState(result); return sortByState(result);
} }
@ -108,8 +108,7 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
subcontractedTaskData.getLastRequiredDeliverDate(); subcontractedTaskData.getLastRequiredDeliverDate();
} }
private void forceLoadExternalCompany( private void forceLoadExternalCompany(SubcontractedTaskData subcontractedTaskData) {
SubcontractedTaskData subcontractedTaskData) {
subcontractedTaskData.getExternalCompany().getName(); subcontractedTaskData.getExternalCompany().getName();
} }
@ -118,29 +117,34 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
@Override @Override
public int compare(SubcontractedTaskData arg0, SubcontractedTaskData arg1) { public int compare(SubcontractedTaskData arg0, SubcontractedTaskData arg1) {
if((arg0 == null) || (arg0.getState() == null)){ if( (arg0 == null) || (arg0.getState() == null) ){
return -1; return -1;
} }
if((arg1 == null) || (arg1.getState() == null)){
if( (arg1 == null) || (arg1.getState() == null) ){
return 1; return 1;
} }
if(arg0.getState().equals(arg1.getState())){
if( arg0.getState().equals(arg1.getState()) ){
return 0; return 0;
} }
if (arg0.getState().equals(
SubcontractState.PENDING_INITIAL_SEND)) { if ( arg0.getState().equals(SubcontractState.PENDING_INITIAL_SEND) ) {
return 1; return 1;
} }
if (arg1.getState().equals(
SubcontractState.PENDING_INITIAL_SEND)) { if ( arg1.getState().equals(SubcontractState.PENDING_INITIAL_SEND) ) {
return -1; return -1;
} }
if( arg0.getState().equals(SubcontractState.PENDING_UPDATE_DELIVERING_DATE)) {
if( arg0.getState().equals(SubcontractState.PENDING_UPDATE_DELIVERING_DATE) ) {
return 1; return 1;
} }
return -1; return -1;
} }
}); });
return tasks; return tasks;
} }
@ -148,42 +152,40 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
@Transactional(readOnly = true) @Transactional(readOnly = true)
public Order getOrder(SubcontractedTaskData subcontractedTaskData) { public Order getOrder(SubcontractedTaskData subcontractedTaskData) {
Task task = subcontractedTaskData.getTask(); Task task = subcontractedTaskData.getTask();
OrderElement orderElement = orderDAO.loadOrderAvoidingProxyFor(task OrderElement orderElement = orderDAO.loadOrderAvoidingProxyFor(task.getOrderElement());
.getOrderElement());
return orderElement.getOrder(); return orderElement.getOrder();
} }
@Override @Override
@Transactional @Transactional
public void sendToSubcontractor(SubcontractedTaskData subcontractedTaskData) public void sendToSubcontractor(SubcontractedTaskData subcontractedTaskData)
throws ValidationException, ConnectionProblemsException, throws ValidationException, ConnectionProblemsException, UnrecoverableErrorServiceException {
UnrecoverableErrorServiceException {
subcontractedTaskDataDAO.save(subcontractedTaskData); subcontractedTaskDataDAO.save(subcontractedTaskData);
SubcontractState currentState = subcontractedTaskData.getState(); SubcontractState currentState = subcontractedTaskData.getState();
if (currentState.equals(SubcontractState.PENDING_INITIAL_SEND)) { if ( currentState.equals(SubcontractState.PENDING_INITIAL_SEND) ) {
subcontractedTaskData.setState(SubcontractState.FAILED_SENT); subcontractedTaskData.setState(SubcontractState.FAILED_SENT);
} else if (currentState } else if ( currentState.equals(SubcontractState.PENDING_UPDATE_DELIVERING_DATE) ) {
.equals(SubcontractState.PENDING_UPDATE_DELIVERING_DATE)) {
subcontractedTaskData.setState(SubcontractState.FAILED_UPDATE); subcontractedTaskData.setState(SubcontractState.FAILED_UPDATE);
} }
if (!subcontractedTaskData.isSendable()) { if ( !subcontractedTaskData.isSendable() ) {
throw new RuntimeException("Subcontracted task already sent"); throw new RuntimeException("Subcontracted task already sent");
} }
if (!subcontractedTaskData.getExternalCompany() if ( !subcontractedTaskData.getExternalCompany().getInteractsWithApplications() ) {
.getInteractsWithApplications()) { throw new RuntimeException("External company has not interaction fields filled");
throw new RuntimeException(
"External company has not interaction fields filled");
} }
makeSubcontractRequestRequest(subcontractedTaskData,currentState); makeSubcontractRequestRequest(subcontractedTaskData,currentState);
Date today = new Date(); Date today = new Date();
if ((currentState.equals(SubcontractState.PENDING_INITIAL_SEND)) if ( (currentState.equals(SubcontractState.PENDING_INITIAL_SEND)) ||
|| (currentState.equals(SubcontractState.FAILED_SENT))) { (currentState.equals(SubcontractState.FAILED_SENT)) ) {
subcontractedTaskData.setSubcontractCommunicationDate(today); subcontractedTaskData.setSubcontractCommunicationDate(today);
} }
@ -194,16 +196,19 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
} }
private void makeSubcontractRequestRequest( private void makeSubcontractRequestRequest(
SubcontractedTaskData subcontractedTaskData, SubcontractedTaskData subcontractedTaskData, SubcontractState currentState)
SubcontractState currentState) throws ConnectionProblemsException, throws ConnectionProblemsException, UnrecoverableErrorServiceException {
UnrecoverableErrorServiceException {
if (subcontractedTaskData.getState() != null) { if ( subcontractedTaskData.getState() != null ) {
if ((currentState.equals(SubcontractState.PENDING_INITIAL_SEND) || (currentState
.equals(SubcontractState.FAILED_SENT)))) { if ( (currentState.equals(SubcontractState.PENDING_INITIAL_SEND) ||
(currentState.equals(SubcontractState.FAILED_SENT))) ) {
makeSubcontractRequestRequest_InitialSent(subcontractedTaskData); makeSubcontractRequestRequest_InitialSent(subcontractedTaskData);
} else if ((currentState
.equals(SubcontractState.PENDING_UPDATE_DELIVERING_DATE) || currentState } else if ( (currentState.equals(SubcontractState.PENDING_UPDATE_DELIVERING_DATE) ||
.equals(SubcontractState.FAILED_UPDATE))) { currentState.equals(SubcontractState.FAILED_UPDATE)) ) {
makeSubcontractRequestRequest_UpdateDeliverDate(subcontractedTaskData); makeSubcontractRequestRequest_UpdateDeliverDate(subcontractedTaskData);
} }
} }
@ -211,10 +216,11 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
private void makeSubcontractRequestRequest_UpdateDeliverDate(SubcontractedTaskData subcontractedTaskData) private void makeSubcontractRequestRequest_UpdateDeliverDate(SubcontractedTaskData subcontractedTaskData)
throws ConnectionProblemsException, UnrecoverableErrorServiceException { throws ConnectionProblemsException, UnrecoverableErrorServiceException {
UpdateDeliveringDateDTO updateDeliveringDateDTO = SubcontractedTaskDataConverter
.toUpdateDeliveringDateDTO(getCompanyCode(), subcontractedTaskData); UpdateDeliveringDateDTO updateDeliveringDateDTO =
ExternalCompany externalCompany = subcontractedTaskData SubcontractedTaskDataConverter.toUpdateDeliveringDateDTO(getCompanyCode(), subcontractedTaskData);
.getExternalCompany();
ExternalCompany externalCompany = subcontractedTaskData.getExternalCompany();
NaiveTrustProvider.setAlwaysTrust(true); NaiveTrustProvider.setAlwaysTrust(true);
@ -222,31 +228,30 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
WebClient client = WebClient.create(externalCompany.getAppURI()); WebClient client = WebClient.create(externalCompany.getAppURI());
client.path("ws/rest/subcontracting/subcontract/update"); client.path("ws/rest/subcontracting/subcontract/update");
Util.addAuthorizationHeader(client, Util.addAuthorizationHeader(
externalCompany.getOurCompanyLogin(), client, externalCompany.getOurCompanyLogin(), externalCompany.getOurCompanyPassword());
externalCompany.getOurCompanyPassword());
InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = client InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO =
.post(updateDeliveringDateDTO, client.post(updateDeliveringDateDTO, InstanceConstraintViolationsListDTO.class);
InstanceConstraintViolationsListDTO.class);
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = instanceConstraintViolationsListDTO.instanceConstraintViolationsList; List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList =
if ((instanceConstraintViolationsList != null) instanceConstraintViolationsListDTO.instanceConstraintViolationsList;
&& (!instanceConstraintViolationsList.isEmpty())) {
if ( (instanceConstraintViolationsList != null) && (!instanceConstraintViolationsList.isEmpty()) ) {
String message = ""; String message = "";
for (ConstraintViolationDTO constraintViolationDTO : instanceConstraintViolationsList for (ConstraintViolationDTO current : instanceConstraintViolationsList.get(0).constraintViolations) {
.get(0).constraintViolations) { message += current.toString() + "\n";
message += constraintViolationDTO.toString() + "\n";
} }
throw new UnrecoverableErrorServiceException(message); throw new UnrecoverableErrorServiceException(message);
} }
} catch (WebApplicationException e) { } catch (WebApplicationException e) {
LOG.error("Problems connecting with subcontractor web service", e); LOG.error("Problems connecting with subcontractor web service", e);
String message = _("Problems connecting with subcontractor web service"); String message = _("Problems connecting with subcontractor web service");
if (e.getMessage() != null) { if ( e.getMessage() != null ) {
message += ". " + _("Error: {0}", e.getMessage()); message += ". " + _("Error: {0}", e.getMessage());
} }
@ -254,13 +259,12 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
} }
} }
private void makeSubcontractRequestRequest_InitialSent( private void makeSubcontractRequestRequest_InitialSent(SubcontractedTaskData subcontractedTaskData)
SubcontractedTaskData subcontractedTaskData)
throws ConnectionProblemsException, UnrecoverableErrorServiceException { throws ConnectionProblemsException, UnrecoverableErrorServiceException {
SubcontractedTaskDataDTO subcontractedTaskDataDTO = getSubcontractedTaskData(subcontractedTaskData); SubcontractedTaskDataDTO subcontractedTaskDataDTO = getSubcontractedTaskData(subcontractedTaskData);
ExternalCompany externalCompany = subcontractedTaskData ExternalCompany externalCompany = subcontractedTaskData.getExternalCompany();
.getExternalCompany();
NaiveTrustProvider.setAlwaysTrust(true); NaiveTrustProvider.setAlwaysTrust(true);
@ -269,30 +273,30 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
client.path("ws/rest/subcontracting/subcontract/create"); client.path("ws/rest/subcontracting/subcontract/create");
Util.addAuthorizationHeader(client, externalCompany Util.addAuthorizationHeader(
.getOurCompanyLogin(), externalCompany client, externalCompany.getOurCompanyLogin(), externalCompany.getOurCompanyPassword());
.getOurCompanyPassword());
InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = client InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO =
.post(subcontractedTaskDataDTO, client.post(subcontractedTaskDataDTO, InstanceConstraintViolationsListDTO.class);
InstanceConstraintViolationsListDTO.class);
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = instanceConstraintViolationsListDTO.instanceConstraintViolationsList; List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList =
if ((instanceConstraintViolationsList != null) instanceConstraintViolationsListDTO.instanceConstraintViolationsList;
&& (!instanceConstraintViolationsList.isEmpty())) {
if ( (instanceConstraintViolationsList != null) && (!instanceConstraintViolationsList.isEmpty()) ) {
String message = ""; String message = "";
for (ConstraintViolationDTO constraintViolationDTO : instanceConstraintViolationsList.get(0).constraintViolations) { for (ConstraintViolationDTO current : instanceConstraintViolationsList.get(0).constraintViolations) {
message += constraintViolationDTO.toString() + "\n"; message += current.toString() + "\n";
} }
throw new UnrecoverableErrorServiceException(message); throw new UnrecoverableErrorServiceException(message);
} }
} catch (WebApplicationException e) { } catch (WebApplicationException e) {
LOG.error("Problems connecting with subcontractor web service", e); LOG.error("Problems connecting with subcontractor web service", e);
String message = _("Problems connecting with subcontractor web service"); String message = _("Problems connecting with subcontractor web service");
if (e.getMessage() != null) { if ( e.getMessage() != null ) {
message += ". " + _("Error: {0}", e.getMessage()); message += ". " + _("Error: {0}", e.getMessage());
} }
@ -300,65 +304,58 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
} }
} }
private SubcontractedTaskDataDTO getSubcontractedTaskData( private SubcontractedTaskDataDTO getSubcontractedTaskData(SubcontractedTaskData subcontractedTaskData) {
SubcontractedTaskData subcontractedTaskData) { return SubcontractedTaskDataConverter.toDTO(
return SubcontractedTaskDataConverter.toDTO(getCompanyCode(), getCompanyCode(), subcontractedTaskData, getOrderElement(subcontractedTaskData));
subcontractedTaskData, getOrderElement(subcontractedTaskData));
} }
private String getCompanyCode() { private String getCompanyCode() {
return configurationDAO.getConfiguration().getCompanyCode(); return configurationDAO.getConfiguration().getCompanyCode();
} }
private OrderElementDTO getOrderElement( private OrderElementDTO getOrderElement(SubcontractedTaskData subcontractedTaskData) {
SubcontractedTaskData subcontractedTaskData) {
OrderElement orderElement; OrderElement orderElement;
try { try {
orderElement = orderElementDAO.find(subcontractedTaskData.getTask() orderElement = orderElementDAO.find(subcontractedTaskData.getTask().getOrderElement().getId());
.getOrderElement().getId());
} catch (InstanceNotFoundException e) { } catch (InstanceNotFoundException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
if (subcontractedTaskData.isNodeWithoutChildrenExported()) { if ( subcontractedTaskData.isNodeWithoutChildrenExported() ) {
orderElement = orderElement.calculateOrderLineForSubcontract(); orderElement = orderElement.calculateOrderLineForSubcontract();
} }
OrderElementDTO orderElementDTO = OrderElementConverter.toDTO( OrderElementDTO orderElementDTO =
orderElement, OrderElementConverter.toDTO(orderElement, getConfiguration(subcontractedTaskData));
getConfiguration(subcontractedTaskData));
overrideDateInformationForRootNode(orderElementDTO, overrideDateInformationForRootNode(orderElementDTO, subcontractedTaskData.getTask());
subcontractedTaskData.getTask());
return orderElementDTO; return orderElementDTO;
} }
private void overrideDateInformationForRootNode( private void overrideDateInformationForRootNode(OrderElementDTO orderElementDTO, Task task) {
OrderElementDTO orderElementDTO, Task task) { orderElementDTO.initDate = DateConverter.toXMLGregorianCalendar(task.getStartDate());
orderElementDTO.initDate = DateConverter.toXMLGregorianCalendar(task orderElementDTO.deadline = DateConverter.toXMLGregorianCalendar(task.getEndDate());
.getStartDate());
orderElementDTO.deadline = DateConverter.toXMLGregorianCalendar(task
.getEndDate());
} }
private ConfigurationOrderElementConverter getConfiguration( private ConfigurationOrderElementConverter getConfiguration(SubcontractedTaskData subcontractedTaskData) {
SubcontractedTaskData subcontractedTaskData) {
// Never export criterions and advances to subcontract // Never export criterions and advances to subcontract
boolean isCriterionsExported = false; return ConfigurationOrderElementConverter.create(
boolean isAdvancesExported = false; subcontractedTaskData.isLabelsExported(),
subcontractedTaskData.isMaterialAssignmentsExported(),
return ConfigurationOrderElementConverter.create(subcontractedTaskData false,
.isLabelsExported(), subcontractedTaskData
.isMaterialAssignmentsExported(), isAdvancesExported,
subcontractedTaskData.isHoursGroupsExported(), subcontractedTaskData.isHoursGroupsExported(),
isCriterionsExported); false);
} }
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public String exportXML(SubcontractedTaskData subcontractedTaskData) { public String exportXML(SubcontractedTaskData subcontractedTaskData) {
SubcontractState currentState = subcontractedTaskData.getState(); SubcontractState currentState = subcontractedTaskData.getState();
if ((currentState.equals(SubcontractState.PENDING_INITIAL_SEND) || (currentState
.equals(SubcontractState.FAILED_SENT)))) { if ( (currentState.equals(SubcontractState.PENDING_INITIAL_SEND) ||
(currentState.equals(SubcontractState.FAILED_SENT))) ) {
return exportXML_CreateSubcontractor(subcontractedTaskData); return exportXML_CreateSubcontractor(subcontractedTaskData);
} else { } else {
return exportXML_UpdateSubcontractor(subcontractedTaskData); return exportXML_UpdateSubcontractor(subcontractedTaskData);
@ -370,8 +367,7 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
StringWriter xml = new StringWriter(); StringWriter xml = new StringWriter();
try { try {
JAXBContext jaxbContext = JAXBContext JAXBContext jaxbContext = JAXBContext.newInstance(SubcontractedTaskDataDTO.class);
.newInstance(SubcontractedTaskDataDTO.class);
Marshaller marshaller = jaxbContext.createMarshaller(); Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.marshal(subcontractedTaskDataDTO, xml); marshaller.marshal(subcontractedTaskDataDTO, xml);
} catch (Exception e) { } catch (Exception e) {
@ -383,13 +379,13 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel {
public String exportXML_UpdateSubcontractor(SubcontractedTaskData subcontractedTaskData){ public String exportXML_UpdateSubcontractor(SubcontractedTaskData subcontractedTaskData){
subcontractedTaskDataDAO.reattachUnmodifiedEntity(subcontractedTaskData); subcontractedTaskDataDAO.reattachUnmodifiedEntity(subcontractedTaskData);
UpdateDeliveringDateDTO updateDeliveringDateDTO = SubcontractedTaskDataConverter
.toUpdateDeliveringDateDTO(getCompanyCode(), subcontractedTaskData); UpdateDeliveringDateDTO updateDeliveringDateDTO =
SubcontractedTaskDataConverter.toUpdateDeliveringDateDTO(getCompanyCode(), subcontractedTaskData);
StringWriter xml = new StringWriter(); StringWriter xml = new StringWriter();
try { try {
JAXBContext jaxbContext = JAXBContext JAXBContext jaxbContext = JAXBContext.newInstance(UpdateDeliveringDateDTO.class);
.newInstance(UpdateDeliveringDateDTO.class);
Marshaller marshaller = jaxbContext.createMarshaller(); Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.marshal(updateDeliveringDateDTO, xml); marshaller.marshal(updateDeliveringDateDTO, xml);
} catch (Exception e) { } catch (Exception e) {

View file

@ -30,26 +30,25 @@ package org.libreplan.ws.common.impl;
public class ConfigurationOrderElementConverter { public class ConfigurationOrderElementConverter {
public static ConfigurationOrderElementConverter create(boolean labels, public static ConfigurationOrderElementConverter create(boolean labels,
boolean materialAssignments, boolean advanceMeasurements, boolean materialAssignments,
boolean hoursGroups, boolean criterionRequirements) { boolean advanceMeasurements,
return new ConfigurationOrderElementConverter(labels, boolean hoursGroups,
materialAssignments, advanceMeasurements, hoursGroups, boolean criterionRequirements) {
criterionRequirements);
return new ConfigurationOrderElementConverter(
labels, materialAssignments, advanceMeasurements, hoursGroups, criterionRequirements);
} }
public static ConfigurationOrderElementConverter all() { public static ConfigurationOrderElementConverter all() {
return new ConfigurationOrderElementConverter(true, true, true, true, return new ConfigurationOrderElementConverter(true, true, true, true, true);
true);
} }
public static ConfigurationOrderElementConverter none() { public static ConfigurationOrderElementConverter none() {
return new ConfigurationOrderElementConverter(false, false, false, return new ConfigurationOrderElementConverter(false, false, false, false, false);
false, false);
} }
public static ConfigurationOrderElementConverter noAdvanceMeasurements() { public static ConfigurationOrderElementConverter noAdvanceMeasurements() {
return new ConfigurationOrderElementConverter(true, true, false, true, return new ConfigurationOrderElementConverter(true, true, false, true, true);
true);
} }
private boolean labels; private boolean labels;
@ -59,8 +58,10 @@ public class ConfigurationOrderElementConverter {
private boolean criterionRequirements; private boolean criterionRequirements;
private ConfigurationOrderElementConverter(boolean labels, private ConfigurationOrderElementConverter(boolean labels,
boolean materialAssignments, boolean advanceMeasurements, boolean materialAssignments,
boolean hoursGroups, boolean criterionRequirements) { boolean advanceMeasurements,
boolean hoursGroups,
boolean criterionRequirements) {
this.labels = labels; this.labels = labels;
this.materialAssignments = materialAssignments; this.materialAssignments = materialAssignments;
this.advanceMeasurements = advanceMeasurements; this.advanceMeasurements = advanceMeasurements;

View file

@ -63,7 +63,6 @@
<!-- CXF --> <!-- CXF -->
<import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxrs:server id="rest" address="/"> <jaxrs:server id="rest" address="/">

View file

@ -193,14 +193,16 @@
p:passwordEncoderService-ref="dbPasswordEncoderService"> p:passwordEncoderService-ref="dbPasswordEncoderService">
</beans:bean> </beans:bean>
<beans:bean id="authenticationProvider" class="org.libreplan.web.users.services.AuthenticationProviderLoggingDecorator"> <beans:bean id="authenticationProvider"
<beans:property name="decoratedProvider" ref="realAuthenticationProvider"></beans:property> class="org.libreplan.web.users.services.AuthenticationProviderLoggingDecorator">
<beans:property name="decoratedProvider" ref="realAuthenticationProvider"/>
</beans:bean> </beans:bean>
<!-- This bean is used to implement UserDetailsService with LDAP authentication <!-- This bean is used to implement UserDetailsService with LDAP authentication
Provider. --> Provider. -->
<beans:bean id="ldapUserDetailsService" <beans:bean id="ldapUserDetailsService" class="org.libreplan.web.users.services.LDAPUserDetailsService" />
class="org.libreplan.web.users.services.LDAPUserDetailsService" />
<authentication-manager> <authentication-manager>
<authentication-provider ref="authenticationProvider"/> <authentication-provider ref="authenticationProvider"/>

View file

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" <web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>libreplan-webapp</display-name> <display-name>libreplan-webapp</display-name>
<!-- <!--
@ -17,7 +16,6 @@
<param-value> <param-value>
classpath*:/libreplan-business-spring-config.xml classpath*:/libreplan-business-spring-config.xml
classpath:/libreplan-webapp-spring-config.xml classpath:/libreplan-webapp-spring-config.xml
classpath*:/libreplan-override-spring-config.xml
classpath:/libreplan-webapp-spring-security-config.xml classpath:/libreplan-webapp-spring-security-config.xml
</param-value> </param-value>
</context-param> </context-param>
@ -70,7 +68,6 @@
</listener> </listener>
<!-- Spring listeners --> <!-- Spring listeners -->
<listener> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> </listener>
@ -78,7 +75,6 @@
<listener-class> <listener-class>
org.springframework.web.context.request.RequestContextListener</listener-class> org.springframework.web.context.request.RequestContextListener</listener-class>
</listener> </listener>
<!-- end Spring listeners --> <!-- end Spring listeners -->
<!-- Loads all IDataBootstrap and executes them --> <!-- Loads all IDataBootstrap and executes them -->

View file

@ -22,13 +22,12 @@ package org.libreplan.importers;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import javax.ws.rs.WebApplicationException; import javax.ws.rs.ProcessingException;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.junit.Before; import org.junit.Before;
@ -46,10 +45,9 @@ public class JiraRESTClientTest {
private Properties properties = null; private Properties properties = null;
@Before @Before
public void loadProperties() throws FileNotFoundException, IOException { public void loadProperties() throws IOException {
String filename = System.getProperty("user.dir") String filename = System.getProperty("user.dir") + "/../scripts/jira-connector/jira-conn.properties";
+ "/../scripts/jira-connector/jira-conn.properties";
properties = new Properties(); properties = new Properties();
properties.load(new FileInputStream(filename)); properties.load(new FileInputStream(filename));
@ -63,13 +61,13 @@ public class JiraRESTClientTest {
@Test @Test
@Ignore("Only working if you have a JIRA server configured") @Ignore("Only working if you have a JIRA server configured")
public void testGetAllLablesFromValidLabelUrl() { public void testGetAllLablesFromValidLabelUrl() {
String labels = JiraRESTClient.getAllLables(properties String labels = JiraRESTClient.getAllLables(properties.getProperty("label_url"));
.getProperty("label_url"));
List<String> result = Arrays.asList(StringUtils.split(labels, ",")); List<String> result = Arrays.asList(StringUtils.split(labels, ","));
assertTrue(result.size() > 0); assertTrue(result.size() > 0);
} }
@Test(expected = WebApplicationException.class) @Test(expected = ProcessingException.class)
public void testGetAllLablesFromInValidLabelUrl() { public void testGetAllLablesFromInValidLabelUrl() {
JiraRESTClient.getAllLables(""); JiraRESTClient.getAllLables("");
} }
@ -82,12 +80,14 @@ public class JiraRESTClientTest {
properties.getProperty("username"), properties.getProperty("username"),
properties.getProperty("password"), JiraRESTClient.PATH_SEARCH, properties.getProperty("password"), JiraRESTClient.PATH_SEARCH,
getJiraLabel(properties.getProperty("label"))); getJiraLabel(properties.getProperty("label")));
assertTrue(issues.size() > 0); assertTrue(issues.size() > 0);
} }
@Test(expected = RuntimeException.class) @Test(expected = RuntimeException.class)
public void testGetIssuesForValidLabelButUnAuthorizedUser() { public void testGetIssuesForValidLabelButUnAuthorizedUser() {
JiraRESTClient.getIssues(properties.getProperty("url"), "", "", JiraRESTClient.getIssues(
properties.getProperty("url"), "", "",
JiraRESTClient.PATH_SEARCH, JiraRESTClient.PATH_SEARCH,
getJiraLabel(properties.getProperty("label"))); getJiraLabel(properties.getProperty("label")));
} }
@ -98,8 +98,8 @@ public class JiraRESTClientTest {
List<IssueDTO> issues = JiraRESTClient.getIssues( List<IssueDTO> issues = JiraRESTClient.getIssues(
properties.getProperty("url"), properties.getProperty("url"),
properties.getProperty("username"), properties.getProperty("username"),
properties.getProperty("password"), JiraRESTClient.PATH_SEARCH, properties.getProperty("password"), JiraRESTClient.PATH_SEARCH, "");
"");
assertTrue(issues.size() > 0); assertTrue(issues.size() > 0);
} }
} }

View file

@ -33,7 +33,6 @@ import static org.libreplan.web.test.WebappGlobalNames.WEBAPP_SPRING_SECURITY_CO
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
@ -98,8 +97,12 @@ import org.springframework.transaction.annotation.Transactional;
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com> * @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE, @ContextConfiguration(locations = {
WEBAPP_SPRING_CONFIG_FILE, WEBAPP_SPRING_CONFIG_TEST_FILE, BUSINESS_SPRING_CONFIG_FILE,
WEBAPP_SPRING_CONFIG_FILE,
WEBAPP_SPRING_CONFIG_TEST_FILE,
WEBAPP_SPRING_SECURITY_CONFIG_FILE, WEBAPP_SPRING_SECURITY_CONFIG_FILE,
WEBAPP_SPRING_SECURITY_CONFIG_TEST_FILE }) WEBAPP_SPRING_SECURITY_CONFIG_TEST_FILE })
public class WorkReportServiceTest { public class WorkReportServiceTest {
@ -195,17 +198,16 @@ public class WorkReportServiceTest {
} }
private static <T extends IntegrationEntity> T findOrCreate( private static <T extends IntegrationEntity> T findOrCreate(
IIntegrationEntityDAO<? super T> dao, Class<T> klass, IIntegrationEntityDAO<? super T> dao, Class<T> klass, String code, Object... constructorArguments) {
String code, Object... constructorArguments) {
if (dao.existsByCode(code)) { if ( dao.existsByCode(code) ) {
return klass.cast(dao.findExistingEntityByCode(code)); return klass.cast(dao.findExistingEntityByCode(code));
} else { } else {
try { try {
Method create = klass.getMethod("create", Method create = klass.getMethod("create", asClasses(constructorArguments));
asClasses(constructorArguments)); T result = klass.cast(create.invoke(null, constructorArguments));
T result = klass
.cast(create.invoke(null, constructorArguments));
result.setCode(code); result.setCode(code);
return result; return result;
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@ -218,33 +220,30 @@ public class WorkReportServiceTest {
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
result[i] = constructorArguments[i].getClass(); result[i] = constructorArguments[i].getClass();
} }
return result; return result;
} }
private void givenWorkerStored() { private void givenWorkerStored() {
Worker worker = findOrCreate(dao, Worker.class, resourceCode, Worker worker = findOrCreate(dao, Worker.class, resourceCode, "Firstname", "Surname", resourceCode);
"Firstname", "Surname", resourceCode); if ( worker.isNewObject() ) {
if (worker.isNewObject()) {
dao.save(worker); dao.save(worker);
} }
} }
private void givenOrderLineStored() { private void givenOrderLineStored() {
OrderLine orderLine = findOrCreate(orderElementDAO, OrderLine.class, OrderLine orderLine = findOrCreate(orderElementDAO, OrderLine.class, orderElementCode);
orderElementCode); if ( orderLine.isNewObject() ) {
if (orderLine.isNewObject()) {
orderLine.setName("order-line-name" + UUID.randomUUID()); orderLine.setName("order-line-name" + UUID.randomUUID());
orderElementDAO.save(orderLine); orderElementDAO.save(orderLine);
} }
} }
private void createAPairOfLabelTypes() { private void createAPairOfLabelTypes() {
LabelType labelType_A = findOrCreate(labelTypeDAO, LabelType.class, LabelType labelType_A = findOrCreate(labelTypeDAO, LabelType.class, labelTypeA, labelTypeA, labelTypeA);
labelTypeA, labelTypeA, labelTypeA); LabelType labelType_B = findOrCreate(labelTypeDAO, LabelType.class, labelTypeB, labelTypeB, labelTypeB);
LabelType labelType_B = findOrCreate(labelTypeDAO, LabelType.class,
labelTypeB, labelTypeB, labelTypeB);
if (labelType_A.isNewObject()) { if ( labelType_A.isNewObject() ) {
Label label_A1 = Label.create(labelA1, labelA1); Label label_A1 = Label.create(labelA1, labelA1);
Label label_A2 = Label.create(labelA2, labelA2); Label label_A2 = Label.create(labelA2, labelA2);
Label label_B1 = Label.create(labelB1, labelB1); Label label_B1 = Label.create(labelB1, labelB1);
@ -259,13 +258,11 @@ public class WorkReportServiceTest {
} }
private void givenTypeOfWorkHoursStored() { private void givenTypeOfWorkHoursStored() {
TypeOfWorkHours typeOfWorkHours = findOrCreate(typeOfWorkHoursDAO, TypeOfWorkHours typeOfWorkHours = findOrCreate(typeOfWorkHoursDAO, TypeOfWorkHours.class, typeOfWorkHoursCode);
TypeOfWorkHours.class, typeOfWorkHoursCode);
if (typeOfWorkHours.isNewObject()) { if ( typeOfWorkHours.isNewObject() ) {
typeOfWorkHours.setCode(typeOfWorkHoursCode); typeOfWorkHours.setCode(typeOfWorkHoursCode);
typeOfWorkHours.setName("type-of-work-hours-name-" typeOfWorkHours.setName("type-of-work-hours-name-" + UUID.randomUUID());
+ UUID.randomUUID());
typeOfWorkHours.setDefaultPrice(BigDecimal.TEN); typeOfWorkHours.setDefaultPrice(BigDecimal.TEN);
typeOfWorkHoursDAO.save(typeOfWorkHours); typeOfWorkHoursDAO.save(typeOfWorkHours);
@ -273,60 +270,48 @@ public class WorkReportServiceTest {
} }
private void givenWorkReportTypeStored() { private void givenWorkReportTypeStored() {
WorkReportType t = givenWorkReportTypeStored(false, false, false, null, WorkReportType t = givenWorkReportTypeStored(false, false, false, null, workReportTypeCode);
workReportTypeCode);
workReportTypeDAO.save(t); workReportTypeDAO.save(t);
} }
private void givenWorkReportTypeStored2() { private void givenWorkReportTypeStored2() {
WorkReportType t = givenWorkReportTypeStored(true, false, false, null, WorkReportType t = givenWorkReportTypeStored(true, false, false, null, workReportTypeCode2);
workReportTypeCode2);
workReportTypeDAO.save(t); workReportTypeDAO.save(t);
} }
private void givenWorkReportTypeStored3() { private void givenWorkReportTypeStored3() {
WorkReportType t = givenWorkReportTypeStored(false, false, false, WorkReportType t = givenWorkReportTypeStored(false, false, false,
HoursManagementEnum.HOURS_CALCULATED_BY_CLOCK, HoursManagementEnum.HOURS_CALCULATED_BY_CLOCK, workReportTypeCode3);
workReportTypeCode3);
workReportTypeDAO.save(t); workReportTypeDAO.save(t);
} }
private void givenWorkReportTypeStored4() { private void givenWorkReportTypeStored4() {
WorkReportType type = givenWorkReportTypeStored(false, false, false, WorkReportType type = givenWorkReportTypeStored(false, false, false, null, workReportTypeCode4);
null, workReportTypeCode4);
if (type.isNewObject()) { if ( type.isNewObject() ) {
type.addDescriptionFieldToEndHead(DescriptionField.create(field1, type.addDescriptionFieldToEndHead(DescriptionField.create(field1, 10));
10)); type.addDescriptionFieldToEndLine(DescriptionField.create(field2, 10));
type.addDescriptionFieldToEndLine(DescriptionField.create(field2,
10));
workReportTypeDAO.save(type); workReportTypeDAO.save(type);
} }
} }
private void givenWorkReportTypeStored5() { private void givenWorkReportTypeStored5() {
WorkReportType type = givenWorkReportTypeStored(false, false, false, WorkReportType type = givenWorkReportTypeStored(false, false, false, null, workReportTypeCode5);
null, workReportTypeCode5); if ( !type.isNewObject() ) {
if (!type.isNewObject()) {
return; return;
} }
WorkReportLabelTypeAssigment labelAssigment1 = WorkReportLabelTypeAssigment WorkReportLabelTypeAssigment labelAssigment1 = WorkReportLabelTypeAssigment.create(true);
.create(true); WorkReportLabelTypeAssigment labelAssigment2 = WorkReportLabelTypeAssigment.create(false);
WorkReportLabelTypeAssigment labelAssigment2 = WorkReportLabelTypeAssigment
.create(false);
labelAssigment1.setLabelType(labelTypeDAO labelAssigment1.setLabelType(labelTypeDAO.findExistingEntityByCode(labelTypeA));
.findExistingEntityByCode(labelTypeA)); labelAssigment1.setDefaultLabel(labelDAO.findExistingEntityByCode(labelA1));
labelAssigment1.setDefaultLabel(labelDAO
.findExistingEntityByCode(labelA1));
labelAssigment1.setPositionNumber(0); labelAssigment1.setPositionNumber(0);
labelAssigment2.setLabelType(labelTypeDAO labelAssigment2.setLabelType(labelTypeDAO.findExistingEntityByCode(labelTypeB));
.findExistingEntityByCode(labelTypeB)); labelAssigment2.setDefaultLabel(labelDAO.findExistingEntityByCode(labelB1));
labelAssigment2.setDefaultLabel(labelDAO
.findExistingEntityByCode(labelB1));
labelAssigment2.setPositionNumber(0); labelAssigment2.setPositionNumber(0);
type.addLabelAssigmentToEndHead(labelAssigment1); type.addLabelAssigmentToEndHead(labelAssigment1);
@ -336,12 +321,13 @@ public class WorkReportServiceTest {
} }
private WorkReportType givenWorkReportTypeStored(boolean dateShared, private WorkReportType givenWorkReportTypeStored(boolean dateShared,
boolean orderElementShared, boolean resourceShared, boolean orderElementShared,
HoursManagementEnum hoursManagement, String workReportTypeCode) { boolean resourceShared,
HoursManagementEnum hoursManagement,
String workReportTypeCode) {
WorkReportType workReportType = findOrCreate(workReportTypeDAO, WorkReportType workReportType = findOrCreate(workReportTypeDAO, WorkReportType.class, workReportTypeCode);
WorkReportType.class, workReportTypeCode); if ( !workReportType.isNewObject() ) {
if (!workReportType.isNewObject()) {
return workReportType; return workReportType;
} }
@ -352,7 +338,7 @@ public class WorkReportServiceTest {
workReportType.setOrderElementIsSharedInLines(orderElementShared); workReportType.setOrderElementIsSharedInLines(orderElementShared);
workReportType.setResourceIsSharedInLines(resourceShared); workReportType.setResourceIsSharedInLines(resourceShared);
if (hoursManagement != null) { if ( hoursManagement != null ) {
workReportType.setHoursManagement(hoursManagement); workReportType.setHoursManagement(hoursManagement);
} }
@ -365,8 +351,7 @@ public class WorkReportServiceTest {
workReportLineDTO.code = "work-report-line-code-" + UUID.randomUUID(); workReportLineDTO.code = "work-report-line-code-" + UUID.randomUUID();
workReportLineDTO.resource = resourceCode; workReportLineDTO.resource = resourceCode;
workReportLineDTO.orderElement = orderElementCode; workReportLineDTO.orderElement = orderElementCode;
workReportLineDTO.date = DateConverter workReportLineDTO.date = DateConverter.toXMLGregorianCalendar(new Date());
.toXMLGregorianCalendar(new Date());
workReportLineDTO.typeOfWorkHours = typeOfWorkHoursCode; workReportLineDTO.typeOfWorkHours = typeOfWorkHoursCode;
workReportLineDTO.numHours = "8:15"; workReportLineDTO.numHours = "8:15";
@ -378,6 +363,7 @@ public class WorkReportServiceTest {
workReportDTO.code = "work-report-code-" + UUID.randomUUID(); workReportDTO.code = "work-report-code-" + UUID.randomUUID();
workReportDTO.workReportType = type; workReportDTO.workReportType = type;
workReportDTO.workReportLines.add(createWorkReportLineDTO()); workReportDTO.workReportLines.add(createWorkReportLineDTO());
return workReportDTO; return workReportDTO;
} }
@ -387,25 +373,23 @@ public class WorkReportServiceTest {
// create work report with a work report line // create work report with a work report line
WorkReportDTO workReportDTO = createWorkReportDTO(workReportTypeCode5); WorkReportDTO workReportDTO = createWorkReportDTO(workReportTypeCode5);
// create invalid description value to add into head and lines. // create invalid description value to add into head and lines
LabelReferenceDTO labelDTO1 = new LabelReferenceDTO("codeLabelNoexiste"); LabelReferenceDTO labelDTO1 = new LabelReferenceDTO("codeLabelNoexiste");
LabelReferenceDTO labelDTO2 = new LabelReferenceDTO(labelA1); LabelReferenceDTO labelDTO2 = new LabelReferenceDTO(labelA1);
// it assigne a label type LabelTypeA, but it should be a label type // it assigns a label type LabelTypeA, but it should be a label type LabelTypeB
// LabelTypeB
workReportDTO.labels.add(labelDTO1); workReportDTO.labels.add(labelDTO1);
for (WorkReportLineDTO lineDTO : workReportDTO.workReportLines) { for (WorkReportLineDTO lineDTO : workReportDTO.workReportLines) {
lineDTO.labels.add(labelDTO2); lineDTO.labels.add(labelDTO2);
} }
WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays WorkReportListDTO workReportListDTO = new WorkReportListDTO(Collections.singletonList(workReportDTO));
.asList(workReportDTO));
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = workReportService List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList =
.addWorkReports(workReportListDTO).instanceConstraintViolationsList; workReportService.addWorkReports(workReportListDTO).instanceConstraintViolationsList;
// Test // Test
assertTrue(instanceConstraintViolationsList.toString(), assertTrue(instanceConstraintViolationsList.toString(), instanceConstraintViolationsList.size() == 1);
instanceConstraintViolationsList.size() == 1);
} }
@Test @Test
@ -418,21 +402,19 @@ public class WorkReportServiceTest {
LabelReferenceDTO labelDTO1 = new LabelReferenceDTO(labelA1); LabelReferenceDTO labelDTO1 = new LabelReferenceDTO(labelA1);
LabelReferenceDTO labelDTO2 = new LabelReferenceDTO(labelB1); LabelReferenceDTO labelDTO2 = new LabelReferenceDTO(labelB1);
// it assigne a label type LabelTypeA, but it should be a label type // it assigns a label type LabelTypeA, but it should be a label type LabelTypeB
// LabelTypeB
workReportDTO.labels.add(labelDTO1); workReportDTO.labels.add(labelDTO1);
for (WorkReportLineDTO lineDTO : workReportDTO.workReportLines) { for (WorkReportLineDTO lineDTO : workReportDTO.workReportLines) {
lineDTO.labels.add(labelDTO2); lineDTO.labels.add(labelDTO2);
} }
WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays WorkReportListDTO workReportListDTO = new WorkReportListDTO(Collections.singletonList(workReportDTO));
.asList(workReportDTO));
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = workReportService List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList =
.addWorkReports(workReportListDTO).instanceConstraintViolationsList; workReportService.addWorkReports(workReportListDTO).instanceConstraintViolationsList;
// Test // Test
assertTrue(instanceConstraintViolationsList.toString(), assertTrue(instanceConstraintViolationsList.toString(), instanceConstraintViolationsList.size() == 0);
instanceConstraintViolationsList.size() == 0);
} }
@Test @Test
@ -442,27 +424,25 @@ public class WorkReportServiceTest {
WorkReportDTO workReportDTO = createWorkReportDTO(workReportTypeCode4); WorkReportDTO workReportDTO = createWorkReportDTO(workReportTypeCode4);
// create invalid description value to add into head and lines. // create invalid description value to add into head and lines.
DescriptionValueDTO valueDTO1 = new DescriptionValueDTO(field1 + "X", DescriptionValueDTO valueDTO1 = new DescriptionValueDTO(field1 + "X", "incorrecto");
"incorrecto"); DescriptionValueDTO valueDTO2 = new DescriptionValueDTO(field2 + "X", "incorrecto");
DescriptionValueDTO valueDTO2 = new DescriptionValueDTO(field2 + "X",
"incorrecto");
workReportDTO.descriptionValues.add(valueDTO1); workReportDTO.descriptionValues.add(valueDTO1);
for (WorkReportLineDTO lineDTO : workReportDTO.workReportLines) { for (WorkReportLineDTO lineDTO : workReportDTO.workReportLines) {
lineDTO.descriptionValues.add(valueDTO2); lineDTO.descriptionValues.add(valueDTO2);
} }
WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays WorkReportListDTO workReportListDTO = new WorkReportListDTO(Collections.singletonList(workReportDTO));
.asList(workReportDTO));
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = workReportService List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList =
.addWorkReports(workReportListDTO).instanceConstraintViolationsList; workReportService.addWorkReports(workReportListDTO).instanceConstraintViolationsList;
// Test // Test
assertTrue(instanceConstraintViolationsList.toString(), assertTrue(instanceConstraintViolationsList.toString(), instanceConstraintViolationsList.size() == 1);
instanceConstraintViolationsList.size() == 1);
assertTrue(instanceConstraintViolationsList.get(0).constraintViolations assertTrue(
.toString(), instanceConstraintViolationsList.get(0).constraintViolations.toString(),
instanceConstraintViolationsList.get(0).constraintViolations instanceConstraintViolationsList.get(0).constraintViolations.size() == 2);
.size() == 2);
} }
@Test @Test
@ -472,29 +452,26 @@ public class WorkReportServiceTest {
WorkReportDTO workReportDTO = createWorkReportDTO(workReportTypeCode4); WorkReportDTO workReportDTO = createWorkReportDTO(workReportTypeCode4);
// create invalid description value to add into head and lines. // create invalid description value to add into head and lines.
DescriptionValueDTO valueDTO1 = new DescriptionValueDTO(field1, DescriptionValueDTO valueDTO1 = new DescriptionValueDTO(field1, "correcto");
"correcto"); DescriptionValueDTO valueDTO2 = new DescriptionValueDTO(field2, "correcto");
DescriptionValueDTO valueDTO2 = new DescriptionValueDTO(field2,
"correcto");
workReportDTO.descriptionValues.add(valueDTO1); workReportDTO.descriptionValues.add(valueDTO1);
for (WorkReportLineDTO lineDTO : workReportDTO.workReportLines) { for (WorkReportLineDTO lineDTO : workReportDTO.workReportLines) {
lineDTO.descriptionValues.add(valueDTO2); lineDTO.descriptionValues.add(valueDTO2);
} }
WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays WorkReportListDTO workReportListDTO = new WorkReportListDTO(Collections.singletonList(workReportDTO));
.asList(workReportDTO));
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = workReportService List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList =
.addWorkReports(workReportListDTO).instanceConstraintViolationsList; workReportService.addWorkReports(workReportListDTO).instanceConstraintViolationsList;
// Test // Test
assertTrue(instanceConstraintViolationsList.toString(), assertTrue(instanceConstraintViolationsList.toString(), instanceConstraintViolationsList.size() == 0);
instanceConstraintViolationsList.size() == 0);
} }
@Test @Test
public void importValidWorkReport() { public void importValidWorkReport() {
int previous = transactionService int previous = transactionService.runOnTransaction(new IOnTransaction<Integer>() {
.runOnTransaction(new IOnTransaction<Integer>() {
@Override @Override
public Integer execute() { public Integer execute() {
return workReportDAO.getAll().size(); return workReportDAO.getAll().size();
@ -505,43 +482,41 @@ public class WorkReportServiceTest {
@Override @Override
public Void execute() { public Void execute() {
WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays WorkReportListDTO workReportListDTO =
.asList(createWorkReportDTO(workReportTypeCode))); new WorkReportListDTO(Collections.singletonList(createWorkReportDTO(workReportTypeCode)));
InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO =
workReportService.addWorkReports(workReportListDTO);
assertThat(instanceConstraintViolationsListDTO.instanceConstraintViolationsList.size(), equalTo(0));
InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = workReportService
.addWorkReports(workReportListDTO);
assertThat(
instanceConstraintViolationsListDTO.instanceConstraintViolationsList
.size(), equalTo(0));
return null; return null;
} }
}); });
List<WorkReport> workReports = transactionService List<WorkReport> workReports = transactionService.runOnTransaction(new IOnTransaction<List<WorkReport>>() {
.runOnTransaction(new IOnTransaction<List<WorkReport>>() {
@Override @Override
public List<WorkReport> execute() { public List<WorkReport> execute() {
List<WorkReport> list = workReportDAO.getAll(); List<WorkReport> list = workReportDAO.getAll();
for (WorkReport workReport : list) { for (WorkReport workReport : list) {
Set<WorkReportLine> workReportLines = workReport Set<WorkReportLine> workReportLines = workReport.getWorkReportLines();
.getWorkReportLines();
for (WorkReportLine line : workReportLines) { for (WorkReportLine line : workReportLines) {
line.getEffort().getHours(); line.getEffort().getHours();
} }
} }
return list; return list;
} }
}); });
assertThat(workReports.size(), equalTo(previous + 1)); assertThat(workReports.size(), equalTo(previous + 1));
Set<WorkReportLine> workReportLines = workReports.get(previous) Set<WorkReportLine> workReportLines = workReports.get(previous).getWorkReportLines();
.getWorkReportLines();
assertThat(workReportLines.size(), equalTo(1)); assertThat(workReportLines.size(), equalTo(1));
assertThat(workReportLines.iterator().next().getEffort(), assertThat(
equalTo(EffortDuration.sum(EffortDuration.hours(8), workReportLines.iterator().next().getEffort(),
EffortDuration.minutes(15)))); equalTo(EffortDuration.sum(EffortDuration.hours(8), EffortDuration.minutes(15))));
} }
@ -550,15 +525,16 @@ public class WorkReportServiceTest {
public void importInvalidWorkReportWithoutDateAtWorkReportLevel() { public void importInvalidWorkReportWithoutDateAtWorkReportLevel() {
int previous = workReportDAO.getAll().size(); int previous = workReportDAO.getAll().size();
WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays WorkReportListDTO workReportListDTO =
.asList(createWorkReportDTO(workReportTypeCode2))); new WorkReportListDTO(Collections.singletonList(createWorkReportDTO(workReportTypeCode2)));
InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO =
workReportService.addWorkReports(workReportListDTO);
assertThat(instanceConstraintViolationsListDTO.instanceConstraintViolationsList.size(), equalTo(1));
InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = workReportService
.addWorkReports(workReportListDTO);
assertThat(
instanceConstraintViolationsListDTO.instanceConstraintViolationsList
.size(), equalTo(1));
List<WorkReport> workReports = workReportDAO.getAll(); List<WorkReport> workReports = workReportDAO.getAll();
assertThat(workReports.size(), equalTo(previous)); assertThat(workReports.size(), equalTo(previous));
} }
@ -571,14 +547,12 @@ public class WorkReportServiceTest {
Date date = new LocalDate().toDateTimeAtStartOfDay().toDate(); Date date = new LocalDate().toDateTimeAtStartOfDay().toDate();
workReportDTO.date = DateConverter.toXMLGregorianCalendar(date); workReportDTO.date = DateConverter.toXMLGregorianCalendar(date);
WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays WorkReportListDTO workReportListDTO = new WorkReportListDTO(Collections.singletonList(workReportDTO));
.asList(workReportDTO));
InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = workReportService InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO =
.addWorkReports(workReportListDTO); workReportService.addWorkReports(workReportListDTO);
assertThat(
instanceConstraintViolationsListDTO.instanceConstraintViolationsList assertThat(instanceConstraintViolationsListDTO.instanceConstraintViolationsList.size(), equalTo(0));
.size(), equalTo(0));
/** /**
* Default code that was before was not working with MySQL * Default code that was before was not working with MySQL
@ -591,8 +565,7 @@ public class WorkReportServiceTest {
StatelessSession statelessSession = sessionFactory.openStatelessSession(); StatelessSession statelessSession = sessionFactory.openStatelessSession();
List<WorkReport> workReports = statelessSession.createCriteria(WorkReport.class) List workReports = statelessSession.createCriteria(WorkReport.class).addOrder(Order.asc("code")).list();
.addOrder(Order.asc("code")).list();
assertThat(workReports.size(), equalTo(previous + 1)); assertThat(workReports.size(), equalTo(previous + 1));
@ -601,12 +574,11 @@ public class WorkReportServiceTest {
assertThat(imported.getDate(), equalTo(date)); assertThat(imported.getDate(), equalTo(date));
List<WorkReportLine> importedLines = new ArrayList<WorkReportLine>( List<WorkReportLine> importedLines = new ArrayList<>(imported.getWorkReportLines());
imported.getWorkReportLines());
Collections.sort(importedLines); Collections.sort(importedLines);
List<WorkReportLineDTO> exportedLines = new ArrayList<WorkReportLineDTO>( List<WorkReportLineDTO> exportedLines = new ArrayList<>(workReportDTO.workReportLines);
workReportDTO.workReportLines);
Collections.sort(exportedLines, new Comparator<WorkReportLineDTO>() { Collections.sort(exportedLines, new Comparator<WorkReportLineDTO>() {
@Override @Override
public int compare(WorkReportLineDTO o1, WorkReportLineDTO o2) { public int compare(WorkReportLineDTO o1, WorkReportLineDTO o2) {
@ -622,8 +594,7 @@ public class WorkReportServiceTest {
} }
private long asTime(XMLGregorianCalendar date2) { private long asTime(XMLGregorianCalendar date2) {
return date2 return date2.toGregorianCalendar().getTime().getTime();
.toGregorianCalendar().getTime().getTime();
} }
@Test @Test
@ -631,22 +602,22 @@ public class WorkReportServiceTest {
public void importInvalidWorkReportCalculatedHours() { public void importInvalidWorkReportCalculatedHours() {
int previous = workReportDAO.getAll().size(); int previous = workReportDAO.getAll().size();
WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays WorkReportListDTO workReportListDTO =
.asList(createWorkReportDTO(workReportTypeCode3))); new WorkReportListDTO(Collections.singletonList(createWorkReportDTO(workReportTypeCode3)));
InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO =
workReportService.addWorkReports(workReportListDTO);
assertThat(instanceConstraintViolationsListDTO.instanceConstraintViolationsList.size(), equalTo(1));
InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = workReportService
.addWorkReports(workReportListDTO);
assertThat(
instanceConstraintViolationsListDTO.instanceConstraintViolationsList
.size(), equalTo(1));
List<WorkReport> workReports = workReportDAO.getAll(); List<WorkReport> workReports = workReportDAO.getAll();
assertThat(workReports.size(), equalTo(previous)); assertThat(workReports.size(), equalTo(previous));
} }
@Test @Test
public void importValidWorkReportCalculatedHours() { public void importValidWorkReportCalculatedHours() {
int previous = transactionService int previous = transactionService.runOnTransaction(new IOnTransaction<Integer>() {
.runOnTransaction(new IOnTransaction<Integer>() {
@Override @Override
public Integer execute() { public Integer execute() {
return workReportDAO.getAll().size(); return workReportDAO.getAll().size();
@ -654,54 +625,48 @@ public class WorkReportServiceTest {
}); });
WorkReportDTO workReportDTO = createWorkReportDTO(workReportTypeCode3); WorkReportDTO workReportDTO = createWorkReportDTO(workReportTypeCode3);
WorkReportLineDTO workReportLineDTO = workReportDTO.workReportLines WorkReportLineDTO workReportLineDTO = workReportDTO.workReportLines.iterator().next();
.iterator().next();
int hours = 12; int hours = 12;
LocalTime start = new LocalTime(8, 0); LocalTime start = new LocalTime(8, 0);
LocalTime end = start.plusHours(hours); LocalTime end = start.plusHours(hours);
workReportLineDTO.clockStart = DateConverter workReportLineDTO.clockStart = DateConverter.toXMLGregorianCalendar(start);
.toXMLGregorianCalendar(start); workReportLineDTO.clockFinish = DateConverter.toXMLGregorianCalendar(end);
workReportLineDTO.clockFinish = DateConverter
.toXMLGregorianCalendar(end);
WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays WorkReportListDTO workReportListDTO = new WorkReportListDTO(Collections.singletonList(workReportDTO));
.asList(workReportDTO));
InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = workReportService InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO =
.addWorkReports(workReportListDTO); workReportService.addWorkReports(workReportListDTO);
assertThat(
instanceConstraintViolationsListDTO.instanceConstraintViolationsList assertThat(instanceConstraintViolationsListDTO.instanceConstraintViolationsList.size(), equalTo(0));
.size(), equalTo(0));
List<WorkReport> workReports = transactionService List<WorkReport> workReports = transactionService.runOnTransaction(new IOnTransaction<List<WorkReport>>() {
.runOnTransaction(new IOnTransaction<List<WorkReport>>() {
@Override @Override
public List<WorkReport> execute() { public List<WorkReport> execute() {
List<WorkReport> list = workReportDAO.getAll(); List<WorkReport> list = workReportDAO.getAll();
for (WorkReport workReport : list) { for (WorkReport workReport : list) {
Set<WorkReportLine> workReportLines = workReport Set<WorkReportLine> workReportLines = workReport.getWorkReportLines();
.getWorkReportLines();
for (WorkReportLine line : workReportLines) { for (WorkReportLine line : workReportLines) {
line.getEffort().getHours(); line.getEffort().getHours();
} }
} }
return list; return list;
} }
}); });
assertThat(workReports.size(), equalTo(previous + 1)); assertThat(workReports.size(), equalTo(previous + 1));
Set<WorkReportLine> workReportLines = workReports.get(previous) Set<WorkReportLine> workReportLines = workReports.get(previous).getWorkReportLines();
.getWorkReportLines();
assertThat(workReportLines.size(), equalTo(1)); assertThat(workReportLines.size(), equalTo(1));
assertThat(workReportLines.iterator().next().getEffort().getHours(), assertThat(workReportLines.iterator().next().getEffort().getHours(), equalTo(hours));
equalTo(hours));
} }
@Test @Test
public void importAndUpdateValidWorkReport() { public void importAndUpdateValidWorkReport() {
int previous = transactionService int previous = transactionService.runOnTransaction(new IOnTransaction<Integer>() {
.runOnTransaction(new IOnTransaction<Integer>() {
@Override @Override
public Integer execute() { public Integer execute() {
return workReportDAO.getAll().size(); return workReportDAO.getAll().size();
@ -709,48 +674,43 @@ public class WorkReportServiceTest {
}); });
WorkReportDTO workReportDTO = createWorkReportDTO(workReportTypeCode); WorkReportDTO workReportDTO = createWorkReportDTO(workReportTypeCode);
WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays WorkReportListDTO workReportListDTO = new WorkReportListDTO(Collections.singletonList(workReportDTO));
.asList(workReportDTO));
InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = workReportService InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO =
.addWorkReports(workReportListDTO); workReportService.addWorkReports(workReportListDTO);
assertThat(
instanceConstraintViolationsListDTO.instanceConstraintViolationsList assertThat(instanceConstraintViolationsListDTO.instanceConstraintViolationsList.size(), equalTo(0));
.size(), equalTo(0));
List<WorkReport> workReports = transactionService List<WorkReport> workReports = transactionService.runOnTransaction(new IOnTransaction<List<WorkReport>>() {
.runOnTransaction(new IOnTransaction<List<WorkReport>>() {
@Override @Override
public List<WorkReport> execute() { public List<WorkReport> execute() {
List<WorkReport> list = workReportDAO.getAll(); List<WorkReport> list = workReportDAO.getAll();
for (WorkReport workReport : list) { for (WorkReport workReport : list) {
Set<WorkReportLine> workReportLines = workReport Set<WorkReportLine> workReportLines = workReport.getWorkReportLines();
.getWorkReportLines();
for (WorkReportLine line : workReportLines) { for (WorkReportLine line : workReportLines) {
line.getEffort().getHours(); line.getEffort().getHours();
} }
} }
return list; return list;
} }
}); });
assertThat(workReports.size(), equalTo(previous + 1)); assertThat(workReports.size(), equalTo(previous + 1));
Set<WorkReportLine> workReportLines = workReports.get(previous) Set<WorkReportLine> workReportLines = workReports.get(previous).getWorkReportLines();
.getWorkReportLines();
assertThat(workReportLines.size(), equalTo(1)); assertThat(workReportLines.size(), equalTo(1));
assertThat(workReportLines.iterator().next().getEffort(), assertThat(
equalTo(EffortDuration.sum(EffortDuration.hours(8), workReportLines.iterator().next().getEffort(),
EffortDuration.minutes(15)))); equalTo(EffortDuration.sum(EffortDuration.hours(8), EffortDuration.minutes(15))));
workReportDTO.workReportLines.add(createWorkReportLineDTO()); workReportDTO.workReportLines.add(createWorkReportLineDTO());
WorkReportListDTO workReportListDTO2 = new WorkReportListDTO(Arrays WorkReportListDTO workReportListDTO2 = new WorkReportListDTO(Collections.singletonList(workReportDTO));
.asList(workReportDTO)); instanceConstraintViolationsListDTO = workReportService.addWorkReports(workReportListDTO2);
instanceConstraintViolationsListDTO = workReportService
.addWorkReports(workReportListDTO2);
assertThat( assertThat(instanceConstraintViolationsListDTO.instanceConstraintViolationsList.size(), equalTo(0));
instanceConstraintViolationsListDTO.instanceConstraintViolationsList
.size(), equalTo(0));
} }
} }

23
pom.xml
View file

@ -530,7 +530,7 @@
<dependency> <dependency>
<groupId>org.apache.cxf</groupId> <groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId> <artifactId>cxf-rt-transports-http</artifactId>
<version>2.2.3</version> <version>3.1.6</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
@ -553,7 +553,26 @@
<dependency> <dependency>
<groupId>org.apache.cxf</groupId> <groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId> <artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>2.2.3</version> <version>3.1.6</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>3.1.6</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>