diff --git a/NEWS.rst b/NEWS.rst index af3a1d705..84837ad4e 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -42,6 +42,10 @@ Changes * Update Commons Collections * Update Commons Logging +* Update CXF-transports-http +* Update CXF-frontend-jaxrs +* Add CXF-rs-client + * Update MPXJ * Update Bonecp * Update Guava diff --git a/libreplan-webapp/pom.xml b/libreplan-webapp/pom.xml index ae7e941d3..5a6790a73 100644 --- a/libreplan-webapp/pom.xml +++ b/libreplan-webapp/pom.xml @@ -476,6 +476,10 @@ org.apache.cxf cxf-rt-frontend-jaxrs + + org.apache.cxf + cxf-rt-rs-client + com.fasterxml.jackson.jaxrs jackson-jaxrs-json-provider diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/JiraRESTClient.java b/libreplan-webapp/src/main/java/org/libreplan/importers/JiraRESTClient.java index 4be21cd77..7800cf2e5 100755 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/JiraRESTClient.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/JiraRESTClient.java @@ -53,11 +53,6 @@ public class JiraRESTClient { */ 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. */ @@ -82,6 +77,7 @@ public class JiraRESTClient { */ public static String getAllLables(String url) { WebClient client = WebClient.create(url).accept(mediaTypes); + return client.get(String.class); } @@ -100,21 +96,23 @@ public class JiraRESTClient { * the query * @return list of jira issues */ - public static List getIssues(String url, String username, - String password, String path, String query) { + public static List getIssues(String url, String username, String password, String path, String query) { WebClient client = createClient(url); checkAutherization(client, username, password); - client.back(true);// Go to baseURI + // Go to baseURI + client.back(true); + client.path(path); - if (!query.isEmpty()) { + + if ( !query.isEmpty() ) { client.query("jql", query); } + client.query("maxResults", MAX_RESULTS); - client.query("fields", - StringUtils.deleteWhitespace(FIELDS_TO_INCLUDE_IN_RESPONSE)); + client.query("fields", StringUtils.deleteWhitespace(FIELDS_TO_INCLUDE_IN_RESPONSE)); SearchResultDTO searchResult = client.get(SearchResultDTO.class); @@ -133,8 +131,7 @@ public class JiraRESTClient { JacksonJaxbJsonProvider jacksonJaxbJsonProvider = new JacksonJaxbJsonProvider(); jacksonJaxbJsonProvider.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - return WebClient.create(url, - Collections.singletonList(jacksonJaxbJsonProvider)).accept(mediaTypes); + return WebClient.create(url, Collections.singletonList(jacksonJaxbJsonProvider)).accept(mediaTypes); } @@ -148,8 +145,7 @@ public class JiraRESTClient { * @param password * login password */ - private static void checkAutherization(WebClient client, String login, - String password) { + private static void checkAutherization(WebClient client, String login, String password) { NaiveTrustProvider.setAlwaysTrust(true); client.path(PATH_AUTH_SESSION); @@ -157,7 +153,7 @@ public class JiraRESTClient { Util.addAuthorizationHeader(client, login, password); Response response = client.get(); - if (response.getStatus() != Status.OK.getStatusCode()) { + if ( response.getStatus() != Status.OK.getStatusCode() ) { throw new RuntimeException("Authorization failed"); } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/subcontract/SubcontractedTasksModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/subcontract/SubcontractedTasksModel.java index bd19eac50..7ae3f123a 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/subcontract/SubcontractedTasksModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/subcontract/SubcontractedTasksModel.java @@ -95,12 +95,12 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel { @Override @Transactional(readOnly = true) public List getSubcontractedTasks() { - List result = subcontractedTaskDataDAO - .getAllForMasterScenario(); + List result = subcontractedTaskDataDAO.getAllForMasterScenario(); for (SubcontractedTaskData subcontractedTaskData : result) { forceLoadExternalCompany(subcontractedTaskData); forceLastDeliveryDate(subcontractedTaskData); } + return sortByState(result); } @@ -108,8 +108,7 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel { subcontractedTaskData.getLastRequiredDeliverDate(); } - private void forceLoadExternalCompany( - SubcontractedTaskData subcontractedTaskData) { + private void forceLoadExternalCompany(SubcontractedTaskData subcontractedTaskData) { subcontractedTaskData.getExternalCompany().getName(); } @@ -118,29 +117,34 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel { @Override public int compare(SubcontractedTaskData arg0, SubcontractedTaskData arg1) { - if((arg0 == null) || (arg0.getState() == null)){ + if( (arg0 == null) || (arg0.getState() == null) ){ return -1; } - if((arg1 == null) || (arg1.getState() == null)){ + + if( (arg1 == null) || (arg1.getState() == null) ){ return 1; } - if(arg0.getState().equals(arg1.getState())){ - return 0; + + if( arg0.getState().equals(arg1.getState()) ){ + return 0; } - if (arg0.getState().equals( - SubcontractState.PENDING_INITIAL_SEND)) { + + if ( arg0.getState().equals(SubcontractState.PENDING_INITIAL_SEND) ) { return 1; } - if (arg1.getState().equals( - SubcontractState.PENDING_INITIAL_SEND)) { - return -1; + + if ( arg1.getState().equals(SubcontractState.PENDING_INITIAL_SEND) ) { + return -1; } - if( arg0.getState().equals(SubcontractState.PENDING_UPDATE_DELIVERING_DATE)) { - return 1; + + if( arg0.getState().equals(SubcontractState.PENDING_UPDATE_DELIVERING_DATE) ) { + return 1; } + return -1; } }); + return tasks; } @@ -148,42 +152,40 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel { @Transactional(readOnly = true) public Order getOrder(SubcontractedTaskData subcontractedTaskData) { Task task = subcontractedTaskData.getTask(); - OrderElement orderElement = orderDAO.loadOrderAvoidingProxyFor(task - .getOrderElement()); + OrderElement orderElement = orderDAO.loadOrderAvoidingProxyFor(task.getOrderElement()); + return orderElement.getOrder(); } @Override @Transactional public void sendToSubcontractor(SubcontractedTaskData subcontractedTaskData) - throws ValidationException, ConnectionProblemsException, - UnrecoverableErrorServiceException { + throws ValidationException, ConnectionProblemsException, UnrecoverableErrorServiceException { + subcontractedTaskDataDAO.save(subcontractedTaskData); SubcontractState currentState = subcontractedTaskData.getState(); - if (currentState.equals(SubcontractState.PENDING_INITIAL_SEND)) { + if ( currentState.equals(SubcontractState.PENDING_INITIAL_SEND) ) { subcontractedTaskData.setState(SubcontractState.FAILED_SENT); - } else if (currentState - .equals(SubcontractState.PENDING_UPDATE_DELIVERING_DATE)) { + } else if ( currentState.equals(SubcontractState.PENDING_UPDATE_DELIVERING_DATE) ) { subcontractedTaskData.setState(SubcontractState.FAILED_UPDATE); } - if (!subcontractedTaskData.isSendable()) { + if ( !subcontractedTaskData.isSendable() ) { throw new RuntimeException("Subcontracted task already sent"); } - if (!subcontractedTaskData.getExternalCompany() - .getInteractsWithApplications()) { - throw new RuntimeException( - "External company has not interaction fields filled"); + if ( !subcontractedTaskData.getExternalCompany().getInteractsWithApplications() ) { + throw new RuntimeException("External company has not interaction fields filled"); } makeSubcontractRequestRequest(subcontractedTaskData,currentState); Date today = new Date(); - if ((currentState.equals(SubcontractState.PENDING_INITIAL_SEND)) - || (currentState.equals(SubcontractState.FAILED_SENT))) { + if ( (currentState.equals(SubcontractState.PENDING_INITIAL_SEND)) || + (currentState.equals(SubcontractState.FAILED_SENT)) ) { + subcontractedTaskData.setSubcontractCommunicationDate(today); } @@ -194,27 +196,31 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel { } private void makeSubcontractRequestRequest( - SubcontractedTaskData subcontractedTaskData, - SubcontractState currentState) throws ConnectionProblemsException, - UnrecoverableErrorServiceException { - if (subcontractedTaskData.getState() != null) { - if ((currentState.equals(SubcontractState.PENDING_INITIAL_SEND) || (currentState - .equals(SubcontractState.FAILED_SENT)))) { + SubcontractedTaskData subcontractedTaskData, SubcontractState currentState) + throws ConnectionProblemsException, UnrecoverableErrorServiceException { + + if ( subcontractedTaskData.getState() != null ) { + + if ( (currentState.equals(SubcontractState.PENDING_INITIAL_SEND) || + (currentState.equals(SubcontractState.FAILED_SENT))) ) { + makeSubcontractRequestRequest_InitialSent(subcontractedTaskData); - } else if ((currentState - .equals(SubcontractState.PENDING_UPDATE_DELIVERING_DATE) || currentState - .equals(SubcontractState.FAILED_UPDATE))) { + + } else if ( (currentState.equals(SubcontractState.PENDING_UPDATE_DELIVERING_DATE) || + currentState.equals(SubcontractState.FAILED_UPDATE)) ) { + makeSubcontractRequestRequest_UpdateDeliverDate(subcontractedTaskData); } } } private void makeSubcontractRequestRequest_UpdateDeliverDate(SubcontractedTaskData subcontractedTaskData) - throws ConnectionProblemsException, UnrecoverableErrorServiceException { - UpdateDeliveringDateDTO updateDeliveringDateDTO = SubcontractedTaskDataConverter - .toUpdateDeliveringDateDTO(getCompanyCode(), subcontractedTaskData); - ExternalCompany externalCompany = subcontractedTaskData - .getExternalCompany(); + throws ConnectionProblemsException, UnrecoverableErrorServiceException { + + UpdateDeliveringDateDTO updateDeliveringDateDTO = + SubcontractedTaskDataConverter.toUpdateDeliveringDateDTO(getCompanyCode(), subcontractedTaskData); + + ExternalCompany externalCompany = subcontractedTaskData.getExternalCompany(); NaiveTrustProvider.setAlwaysTrust(true); @@ -222,31 +228,30 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel { WebClient client = WebClient.create(externalCompany.getAppURI()); client.path("ws/rest/subcontracting/subcontract/update"); - Util.addAuthorizationHeader(client, - externalCompany.getOurCompanyLogin(), - externalCompany.getOurCompanyPassword()); + Util.addAuthorizationHeader( + client, externalCompany.getOurCompanyLogin(), externalCompany.getOurCompanyPassword()); - InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = client - .post(updateDeliveringDateDTO, - InstanceConstraintViolationsListDTO.class); + InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = + client.post(updateDeliveringDateDTO, InstanceConstraintViolationsListDTO.class); - List instanceConstraintViolationsList = instanceConstraintViolationsListDTO.instanceConstraintViolationsList; - if ((instanceConstraintViolationsList != null) - && (!instanceConstraintViolationsList.isEmpty())) { + List instanceConstraintViolationsList = + instanceConstraintViolationsListDTO.instanceConstraintViolationsList; + + if ( (instanceConstraintViolationsList != null) && (!instanceConstraintViolationsList.isEmpty()) ) { String message = ""; - for (ConstraintViolationDTO constraintViolationDTO : instanceConstraintViolationsList - .get(0).constraintViolations) { - message += constraintViolationDTO.toString() + "\n"; + for (ConstraintViolationDTO current : instanceConstraintViolationsList.get(0).constraintViolations) { + message += current.toString() + "\n"; } throw new UnrecoverableErrorServiceException(message); } + } catch (WebApplicationException e) { LOG.error("Problems connecting with subcontractor web service", e); String message = _("Problems connecting with subcontractor web service"); - if (e.getMessage() != null) { + if ( e.getMessage() != null ) { message += ". " + _("Error: {0}", e.getMessage()); } @@ -254,13 +259,12 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel { } } - private void makeSubcontractRequestRequest_InitialSent( - SubcontractedTaskData subcontractedTaskData) + private void makeSubcontractRequestRequest_InitialSent(SubcontractedTaskData subcontractedTaskData) throws ConnectionProblemsException, UnrecoverableErrorServiceException { + SubcontractedTaskDataDTO subcontractedTaskDataDTO = getSubcontractedTaskData(subcontractedTaskData); - ExternalCompany externalCompany = subcontractedTaskData - .getExternalCompany(); + ExternalCompany externalCompany = subcontractedTaskData.getExternalCompany(); NaiveTrustProvider.setAlwaysTrust(true); @@ -269,30 +273,30 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel { client.path("ws/rest/subcontracting/subcontract/create"); - Util.addAuthorizationHeader(client, externalCompany - .getOurCompanyLogin(), externalCompany - .getOurCompanyPassword()); + Util.addAuthorizationHeader( + client, externalCompany.getOurCompanyLogin(), externalCompany.getOurCompanyPassword()); - InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = client - .post(subcontractedTaskDataDTO, - InstanceConstraintViolationsListDTO.class); + InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = + client.post(subcontractedTaskDataDTO, InstanceConstraintViolationsListDTO.class); - List instanceConstraintViolationsList = instanceConstraintViolationsListDTO.instanceConstraintViolationsList; - if ((instanceConstraintViolationsList != null) - && (!instanceConstraintViolationsList.isEmpty())) { + List instanceConstraintViolationsList = + instanceConstraintViolationsListDTO.instanceConstraintViolationsList; + + if ( (instanceConstraintViolationsList != null) && (!instanceConstraintViolationsList.isEmpty()) ) { String message = ""; - for (ConstraintViolationDTO constraintViolationDTO : instanceConstraintViolationsList.get(0).constraintViolations) { - message += constraintViolationDTO.toString() + "\n"; + for (ConstraintViolationDTO current : instanceConstraintViolationsList.get(0).constraintViolations) { + message += current.toString() + "\n"; } throw new UnrecoverableErrorServiceException(message); } + } catch (WebApplicationException e) { LOG.error("Problems connecting with subcontractor web service", e); String message = _("Problems connecting with subcontractor web service"); - if (e.getMessage() != null) { + if ( e.getMessage() != null ) { message += ". " + _("Error: {0}", e.getMessage()); } @@ -300,65 +304,58 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel { } } - private SubcontractedTaskDataDTO getSubcontractedTaskData( - SubcontractedTaskData subcontractedTaskData) { - return SubcontractedTaskDataConverter.toDTO(getCompanyCode(), - subcontractedTaskData, getOrderElement(subcontractedTaskData)); + private SubcontractedTaskDataDTO getSubcontractedTaskData(SubcontractedTaskData subcontractedTaskData) { + return SubcontractedTaskDataConverter.toDTO( + getCompanyCode(), subcontractedTaskData, getOrderElement(subcontractedTaskData)); } private String getCompanyCode() { return configurationDAO.getConfiguration().getCompanyCode(); } - private OrderElementDTO getOrderElement( - SubcontractedTaskData subcontractedTaskData) { + private OrderElementDTO getOrderElement(SubcontractedTaskData subcontractedTaskData) { OrderElement orderElement; try { - orderElement = orderElementDAO.find(subcontractedTaskData.getTask() - .getOrderElement().getId()); + orderElement = orderElementDAO.find(subcontractedTaskData.getTask().getOrderElement().getId()); } catch (InstanceNotFoundException e) { throw new RuntimeException(e); } - if (subcontractedTaskData.isNodeWithoutChildrenExported()) { + if ( subcontractedTaskData.isNodeWithoutChildrenExported() ) { orderElement = orderElement.calculateOrderLineForSubcontract(); } - OrderElementDTO orderElementDTO = OrderElementConverter.toDTO( - orderElement, - getConfiguration(subcontractedTaskData)); - overrideDateInformationForRootNode(orderElementDTO, - subcontractedTaskData.getTask()); + OrderElementDTO orderElementDTO = + OrderElementConverter.toDTO(orderElement, getConfiguration(subcontractedTaskData)); + + overrideDateInformationForRootNode(orderElementDTO, subcontractedTaskData.getTask()); + return orderElementDTO; } - private void overrideDateInformationForRootNode( - OrderElementDTO orderElementDTO, Task task) { - orderElementDTO.initDate = DateConverter.toXMLGregorianCalendar(task - .getStartDate()); - orderElementDTO.deadline = DateConverter.toXMLGregorianCalendar(task - .getEndDate()); + private void overrideDateInformationForRootNode(OrderElementDTO orderElementDTO, Task task) { + orderElementDTO.initDate = DateConverter.toXMLGregorianCalendar(task.getStartDate()); + orderElementDTO.deadline = DateConverter.toXMLGregorianCalendar(task.getEndDate()); } - private ConfigurationOrderElementConverter getConfiguration( - SubcontractedTaskData subcontractedTaskData) { + private ConfigurationOrderElementConverter getConfiguration(SubcontractedTaskData subcontractedTaskData) { // Never export criterions and advances to subcontract - boolean isCriterionsExported = false; - boolean isAdvancesExported = false; - - return ConfigurationOrderElementConverter.create(subcontractedTaskData - .isLabelsExported(), subcontractedTaskData - .isMaterialAssignmentsExported(), isAdvancesExported, + return ConfigurationOrderElementConverter.create( + subcontractedTaskData.isLabelsExported(), + subcontractedTaskData.isMaterialAssignmentsExported(), + false, subcontractedTaskData.isHoursGroupsExported(), - isCriterionsExported); + false); } @Override @Transactional(readOnly = true) public String exportXML(SubcontractedTaskData subcontractedTaskData) { 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); } else { return exportXML_UpdateSubcontractor(subcontractedTaskData); @@ -370,8 +367,7 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel { StringWriter xml = new StringWriter(); try { - JAXBContext jaxbContext = JAXBContext - .newInstance(SubcontractedTaskDataDTO.class); + JAXBContext jaxbContext = JAXBContext.newInstance(SubcontractedTaskDataDTO.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(subcontractedTaskDataDTO, xml); } catch (Exception e) { @@ -383,13 +379,13 @@ public class SubcontractedTasksModel implements ISubcontractedTasksModel { public String exportXML_UpdateSubcontractor(SubcontractedTaskData subcontractedTaskData){ subcontractedTaskDataDAO.reattachUnmodifiedEntity(subcontractedTaskData); - UpdateDeliveringDateDTO updateDeliveringDateDTO = SubcontractedTaskDataConverter - .toUpdateDeliveringDateDTO(getCompanyCode(), subcontractedTaskData); + + UpdateDeliveringDateDTO updateDeliveringDateDTO = + SubcontractedTaskDataConverter.toUpdateDeliveringDateDTO(getCompanyCode(), subcontractedTaskData); StringWriter xml = new StringWriter(); try { - JAXBContext jaxbContext = JAXBContext - .newInstance(UpdateDeliveringDateDTO.class); + JAXBContext jaxbContext = JAXBContext.newInstance(UpdateDeliveringDateDTO.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(updateDeliveringDateDTO, xml); } catch (Exception e) { diff --git a/libreplan-webapp/src/main/java/org/libreplan/ws/common/impl/ConfigurationOrderElementConverter.java b/libreplan-webapp/src/main/java/org/libreplan/ws/common/impl/ConfigurationOrderElementConverter.java index 0df8f6612..e2166798f 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/ws/common/impl/ConfigurationOrderElementConverter.java +++ b/libreplan-webapp/src/main/java/org/libreplan/ws/common/impl/ConfigurationOrderElementConverter.java @@ -30,26 +30,25 @@ package org.libreplan.ws.common.impl; public class ConfigurationOrderElementConverter { public static ConfigurationOrderElementConverter create(boolean labels, - boolean materialAssignments, boolean advanceMeasurements, - boolean hoursGroups, boolean criterionRequirements) { - return new ConfigurationOrderElementConverter(labels, - materialAssignments, advanceMeasurements, hoursGroups, - criterionRequirements); + boolean materialAssignments, + boolean advanceMeasurements, + boolean hoursGroups, + boolean criterionRequirements) { + + return new ConfigurationOrderElementConverter( + labels, materialAssignments, advanceMeasurements, hoursGroups, criterionRequirements); } public static ConfigurationOrderElementConverter all() { - return new ConfigurationOrderElementConverter(true, true, true, true, - true); + return new ConfigurationOrderElementConverter(true, true, true, true, true); } public static ConfigurationOrderElementConverter none() { - return new ConfigurationOrderElementConverter(false, false, false, - false, false); + return new ConfigurationOrderElementConverter(false, false, false, false, false); } public static ConfigurationOrderElementConverter noAdvanceMeasurements() { - return new ConfigurationOrderElementConverter(true, true, false, true, - true); + return new ConfigurationOrderElementConverter(true, true, false, true, true); } private boolean labels; @@ -59,8 +58,10 @@ public class ConfigurationOrderElementConverter { private boolean criterionRequirements; private ConfigurationOrderElementConverter(boolean labels, - boolean materialAssignments, boolean advanceMeasurements, - boolean hoursGroups, boolean criterionRequirements) { + boolean materialAssignments, + boolean advanceMeasurements, + boolean hoursGroups, + boolean criterionRequirements) { this.labels = labels; this.materialAssignments = materialAssignments; this.advanceMeasurements = advanceMeasurements; diff --git a/libreplan-webapp/src/main/resources/libreplan-webapp-spring-config.xml b/libreplan-webapp/src/main/resources/libreplan-webapp-spring-config.xml index ae1fb81b0..71eb67791 100644 --- a/libreplan-webapp/src/main/resources/libreplan-webapp-spring-config.xml +++ b/libreplan-webapp/src/main/resources/libreplan-webapp-spring-config.xml @@ -63,7 +63,6 @@ - diff --git a/libreplan-webapp/src/main/resources/libreplan-webapp-spring-security-config.xml b/libreplan-webapp/src/main/resources/libreplan-webapp-spring-security-config.xml index 8cea71490..5dea568fe 100644 --- a/libreplan-webapp/src/main/resources/libreplan-webapp-spring-security-config.xml +++ b/libreplan-webapp/src/main/resources/libreplan-webapp-spring-security-config.xml @@ -193,14 +193,16 @@ p:passwordEncoderService-ref="dbPasswordEncoderService"> - - + + + + - + diff --git a/libreplan-webapp/src/main/webapp/WEB-INF/web.xml b/libreplan-webapp/src/main/webapp/WEB-INF/web.xml index b6b177fb3..5d99d6350 100644 --- a/libreplan-webapp/src/main/webapp/WEB-INF/web.xml +++ b/libreplan-webapp/src/main/webapp/WEB-INF/web.xml @@ -1,8 +1,7 @@ + xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> libreplan-webapp - org.springframework.web.context.ContextLoaderListener @@ -78,7 +75,6 @@ org.springframework.web.context.request.RequestContextListener - diff --git a/libreplan-webapp/src/test/java/org/libreplan/importers/JiraRESTClientTest.java b/libreplan-webapp/src/test/java/org/libreplan/importers/JiraRESTClientTest.java index 3f1740f12..3368a35ec 100644 --- a/libreplan-webapp/src/test/java/org/libreplan/importers/JiraRESTClientTest.java +++ b/libreplan-webapp/src/test/java/org/libreplan/importers/JiraRESTClientTest.java @@ -22,13 +22,12 @@ package org.libreplan.importers; import static org.junit.Assert.assertTrue; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.Properties; -import javax.ws.rs.WebApplicationException; +import javax.ws.rs.ProcessingException; import org.apache.commons.lang3.StringUtils; import org.junit.Before; @@ -46,10 +45,9 @@ public class JiraRESTClientTest { private Properties properties = null; @Before - public void loadProperties() throws FileNotFoundException, IOException { + public void loadProperties() throws IOException { - String filename = System.getProperty("user.dir") - + "/../scripts/jira-connector/jira-conn.properties"; + String filename = System.getProperty("user.dir") + "/../scripts/jira-connector/jira-conn.properties"; properties = new Properties(); properties.load(new FileInputStream(filename)); @@ -63,13 +61,13 @@ public class JiraRESTClientTest { @Test @Ignore("Only working if you have a JIRA server configured") public void testGetAllLablesFromValidLabelUrl() { - String labels = JiraRESTClient.getAllLables(properties - .getProperty("label_url")); + String labels = JiraRESTClient.getAllLables(properties.getProperty("label_url")); List result = Arrays.asList(StringUtils.split(labels, ",")); + assertTrue(result.size() > 0); } - @Test(expected = WebApplicationException.class) + @Test(expected = ProcessingException.class) public void testGetAllLablesFromInValidLabelUrl() { JiraRESTClient.getAllLables(""); } @@ -82,12 +80,14 @@ public class JiraRESTClientTest { properties.getProperty("username"), properties.getProperty("password"), JiraRESTClient.PATH_SEARCH, getJiraLabel(properties.getProperty("label"))); + assertTrue(issues.size() > 0); } @Test(expected = RuntimeException.class) public void testGetIssuesForValidLabelButUnAuthorizedUser() { - JiraRESTClient.getIssues(properties.getProperty("url"), "", "", + JiraRESTClient.getIssues( + properties.getProperty("url"), "", "", JiraRESTClient.PATH_SEARCH, getJiraLabel(properties.getProperty("label"))); } @@ -98,8 +98,8 @@ public class JiraRESTClientTest { List issues = JiraRESTClient.getIssues( properties.getProperty("url"), properties.getProperty("username"), - properties.getProperty("password"), JiraRESTClient.PATH_SEARCH, - ""); + properties.getProperty("password"), JiraRESTClient.PATH_SEARCH, ""); + assertTrue(issues.size() > 0); } } diff --git a/libreplan-webapp/src/test/java/org/libreplan/web/test/ws/workreports/WorkReportServiceTest.java b/libreplan-webapp/src/test/java/org/libreplan/web/test/ws/workreports/WorkReportServiceTest.java index d54ef6e30..56e9a844d 100644 --- a/libreplan-webapp/src/test/java/org/libreplan/web/test/ws/workreports/WorkReportServiceTest.java +++ b/libreplan-webapp/src/test/java/org/libreplan/web/test/ws/workreports/WorkReportServiceTest.java @@ -33,7 +33,6 @@ import static org.libreplan.web.test.WebappGlobalNames.WEBAPP_SPRING_SECURITY_CO import java.lang.reflect.Method; import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -98,8 +97,12 @@ import org.springframework.transaction.annotation.Transactional; * @author Vova Perebykivskiy */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE, - WEBAPP_SPRING_CONFIG_FILE, WEBAPP_SPRING_CONFIG_TEST_FILE, +@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 }) public class WorkReportServiceTest { @@ -195,17 +198,16 @@ public class WorkReportServiceTest { } private static T findOrCreate( - IIntegrationEntityDAO dao, Class klass, - String code, Object... constructorArguments) { - if (dao.existsByCode(code)) { + IIntegrationEntityDAO dao, Class klass, String code, Object... constructorArguments) { + + if ( dao.existsByCode(code) ) { return klass.cast(dao.findExistingEntityByCode(code)); } else { try { - Method create = klass.getMethod("create", - asClasses(constructorArguments)); - T result = klass - .cast(create.invoke(null, constructorArguments)); + Method create = klass.getMethod("create", asClasses(constructorArguments)); + T result = klass.cast(create.invoke(null, constructorArguments)); result.setCode(code); + return result; } catch (Exception e) { throw new RuntimeException(e); @@ -218,33 +220,30 @@ public class WorkReportServiceTest { for (int i = 0; i < result.length; i++) { result[i] = constructorArguments[i].getClass(); } + return result; } private void givenWorkerStored() { - Worker worker = findOrCreate(dao, Worker.class, resourceCode, - "Firstname", "Surname", resourceCode); - if (worker.isNewObject()) { + Worker worker = findOrCreate(dao, Worker.class, resourceCode, "Firstname", "Surname", resourceCode); + if ( worker.isNewObject() ) { dao.save(worker); } } private void givenOrderLineStored() { - OrderLine orderLine = findOrCreate(orderElementDAO, OrderLine.class, - orderElementCode); - if (orderLine.isNewObject()) { + OrderLine orderLine = findOrCreate(orderElementDAO, OrderLine.class, orderElementCode); + if ( orderLine.isNewObject() ) { orderLine.setName("order-line-name" + UUID.randomUUID()); orderElementDAO.save(orderLine); } } private void createAPairOfLabelTypes() { - LabelType labelType_A = findOrCreate(labelTypeDAO, LabelType.class, - labelTypeA, labelTypeA, labelTypeA); - LabelType labelType_B = findOrCreate(labelTypeDAO, LabelType.class, - labelTypeB, labelTypeB, labelTypeB); + LabelType labelType_A = findOrCreate(labelTypeDAO, LabelType.class, labelTypeA, labelTypeA, labelTypeA); + 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_A2 = Label.create(labelA2, labelA2); Label label_B1 = Label.create(labelB1, labelB1); @@ -259,13 +258,11 @@ public class WorkReportServiceTest { } private void givenTypeOfWorkHoursStored() { - TypeOfWorkHours typeOfWorkHours = findOrCreate(typeOfWorkHoursDAO, - TypeOfWorkHours.class, typeOfWorkHoursCode); + TypeOfWorkHours typeOfWorkHours = findOrCreate(typeOfWorkHoursDAO, TypeOfWorkHours.class, typeOfWorkHoursCode); - if (typeOfWorkHours.isNewObject()) { + if ( typeOfWorkHours.isNewObject() ) { typeOfWorkHours.setCode(typeOfWorkHoursCode); - typeOfWorkHours.setName("type-of-work-hours-name-" - + UUID.randomUUID()); + typeOfWorkHours.setName("type-of-work-hours-name-" + UUID.randomUUID()); typeOfWorkHours.setDefaultPrice(BigDecimal.TEN); typeOfWorkHoursDAO.save(typeOfWorkHours); @@ -273,60 +270,48 @@ public class WorkReportServiceTest { } private void givenWorkReportTypeStored() { - WorkReportType t = givenWorkReportTypeStored(false, false, false, null, - workReportTypeCode); + WorkReportType t = givenWorkReportTypeStored(false, false, false, null, workReportTypeCode); workReportTypeDAO.save(t); } private void givenWorkReportTypeStored2() { - WorkReportType t = givenWorkReportTypeStored(true, false, false, null, - workReportTypeCode2); + WorkReportType t = givenWorkReportTypeStored(true, false, false, null, workReportTypeCode2); workReportTypeDAO.save(t); } private void givenWorkReportTypeStored3() { WorkReportType t = givenWorkReportTypeStored(false, false, false, - HoursManagementEnum.HOURS_CALCULATED_BY_CLOCK, - workReportTypeCode3); + HoursManagementEnum.HOURS_CALCULATED_BY_CLOCK, workReportTypeCode3); + workReportTypeDAO.save(t); } private void givenWorkReportTypeStored4() { - WorkReportType type = givenWorkReportTypeStored(false, false, false, - null, workReportTypeCode4); + WorkReportType type = givenWorkReportTypeStored(false, false, false, null, workReportTypeCode4); - if (type.isNewObject()) { - type.addDescriptionFieldToEndHead(DescriptionField.create(field1, - 10)); - type.addDescriptionFieldToEndLine(DescriptionField.create(field2, - 10)); + if ( type.isNewObject() ) { + type.addDescriptionFieldToEndHead(DescriptionField.create(field1, 10)); + type.addDescriptionFieldToEndLine(DescriptionField.create(field2, 10)); workReportTypeDAO.save(type); } } private void givenWorkReportTypeStored5() { - WorkReportType type = givenWorkReportTypeStored(false, false, false, - null, workReportTypeCode5); - if (!type.isNewObject()) { + WorkReportType type = givenWorkReportTypeStored(false, false, false, null, workReportTypeCode5); + if ( !type.isNewObject() ) { return; } - WorkReportLabelTypeAssigment labelAssigment1 = WorkReportLabelTypeAssigment - .create(true); - WorkReportLabelTypeAssigment labelAssigment2 = WorkReportLabelTypeAssigment - .create(false); + WorkReportLabelTypeAssigment labelAssigment1 = WorkReportLabelTypeAssigment.create(true); + WorkReportLabelTypeAssigment labelAssigment2 = WorkReportLabelTypeAssigment.create(false); - labelAssigment1.setLabelType(labelTypeDAO - .findExistingEntityByCode(labelTypeA)); - labelAssigment1.setDefaultLabel(labelDAO - .findExistingEntityByCode(labelA1)); + labelAssigment1.setLabelType(labelTypeDAO.findExistingEntityByCode(labelTypeA)); + labelAssigment1.setDefaultLabel(labelDAO.findExistingEntityByCode(labelA1)); labelAssigment1.setPositionNumber(0); - labelAssigment2.setLabelType(labelTypeDAO - .findExistingEntityByCode(labelTypeB)); - labelAssigment2.setDefaultLabel(labelDAO - .findExistingEntityByCode(labelB1)); + labelAssigment2.setLabelType(labelTypeDAO.findExistingEntityByCode(labelTypeB)); + labelAssigment2.setDefaultLabel(labelDAO.findExistingEntityByCode(labelB1)); labelAssigment2.setPositionNumber(0); type.addLabelAssigmentToEndHead(labelAssigment1); @@ -336,12 +321,13 @@ public class WorkReportServiceTest { } private WorkReportType givenWorkReportTypeStored(boolean dateShared, - boolean orderElementShared, boolean resourceShared, - HoursManagementEnum hoursManagement, String workReportTypeCode) { + boolean orderElementShared, + boolean resourceShared, + HoursManagementEnum hoursManagement, + String workReportTypeCode) { - WorkReportType workReportType = findOrCreate(workReportTypeDAO, - WorkReportType.class, workReportTypeCode); - if (!workReportType.isNewObject()) { + WorkReportType workReportType = findOrCreate(workReportTypeDAO, WorkReportType.class, workReportTypeCode); + if ( !workReportType.isNewObject() ) { return workReportType; } @@ -352,7 +338,7 @@ public class WorkReportServiceTest { workReportType.setOrderElementIsSharedInLines(orderElementShared); workReportType.setResourceIsSharedInLines(resourceShared); - if (hoursManagement != null) { + if ( hoursManagement != null ) { workReportType.setHoursManagement(hoursManagement); } @@ -365,8 +351,7 @@ public class WorkReportServiceTest { workReportLineDTO.code = "work-report-line-code-" + UUID.randomUUID(); workReportLineDTO.resource = resourceCode; workReportLineDTO.orderElement = orderElementCode; - workReportLineDTO.date = DateConverter - .toXMLGregorianCalendar(new Date()); + workReportLineDTO.date = DateConverter.toXMLGregorianCalendar(new Date()); workReportLineDTO.typeOfWorkHours = typeOfWorkHoursCode; workReportLineDTO.numHours = "8:15"; @@ -378,6 +363,7 @@ public class WorkReportServiceTest { workReportDTO.code = "work-report-code-" + UUID.randomUUID(); workReportDTO.workReportType = type; workReportDTO.workReportLines.add(createWorkReportLineDTO()); + return workReportDTO; } @@ -387,25 +373,23 @@ public class WorkReportServiceTest { // create work report with a work report line 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 labelDTO2 = new LabelReferenceDTO(labelA1); - // it assigne a label type LabelTypeA, but it should be a label type - // LabelTypeB + // it assigns a label type LabelTypeA, but it should be a label type LabelTypeB workReportDTO.labels.add(labelDTO1); for (WorkReportLineDTO lineDTO : workReportDTO.workReportLines) { lineDTO.labels.add(labelDTO2); } - WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays - .asList(workReportDTO)); - List instanceConstraintViolationsList = workReportService - .addWorkReports(workReportListDTO).instanceConstraintViolationsList; + WorkReportListDTO workReportListDTO = new WorkReportListDTO(Collections.singletonList(workReportDTO)); + + List instanceConstraintViolationsList = + workReportService.addWorkReports(workReportListDTO).instanceConstraintViolationsList; // Test - assertTrue(instanceConstraintViolationsList.toString(), - instanceConstraintViolationsList.size() == 1); + assertTrue(instanceConstraintViolationsList.toString(), instanceConstraintViolationsList.size() == 1); } @Test @@ -418,21 +402,19 @@ public class WorkReportServiceTest { LabelReferenceDTO labelDTO1 = new LabelReferenceDTO(labelA1); LabelReferenceDTO labelDTO2 = new LabelReferenceDTO(labelB1); - // it assigne a label type LabelTypeA, but it should be a label type - // LabelTypeB + // it assigns a label type LabelTypeA, but it should be a label type LabelTypeB workReportDTO.labels.add(labelDTO1); for (WorkReportLineDTO lineDTO : workReportDTO.workReportLines) { lineDTO.labels.add(labelDTO2); } - WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays - .asList(workReportDTO)); - List instanceConstraintViolationsList = workReportService - .addWorkReports(workReportListDTO).instanceConstraintViolationsList; + WorkReportListDTO workReportListDTO = new WorkReportListDTO(Collections.singletonList(workReportDTO)); + + List instanceConstraintViolationsList = + workReportService.addWorkReports(workReportListDTO).instanceConstraintViolationsList; // Test - assertTrue(instanceConstraintViolationsList.toString(), - instanceConstraintViolationsList.size() == 0); + assertTrue(instanceConstraintViolationsList.toString(), instanceConstraintViolationsList.size() == 0); } @Test @@ -442,27 +424,25 @@ public class WorkReportServiceTest { WorkReportDTO workReportDTO = createWorkReportDTO(workReportTypeCode4); // create invalid description value to add into head and lines. - DescriptionValueDTO valueDTO1 = new DescriptionValueDTO(field1 + "X", - "incorrecto"); - DescriptionValueDTO valueDTO2 = new DescriptionValueDTO(field2 + "X", - "incorrecto"); + DescriptionValueDTO valueDTO1 = new DescriptionValueDTO(field1 + "X", "incorrecto"); + DescriptionValueDTO valueDTO2 = new DescriptionValueDTO(field2 + "X", "incorrecto"); + workReportDTO.descriptionValues.add(valueDTO1); for (WorkReportLineDTO lineDTO : workReportDTO.workReportLines) { lineDTO.descriptionValues.add(valueDTO2); } - WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays - .asList(workReportDTO)); - List instanceConstraintViolationsList = workReportService - .addWorkReports(workReportListDTO).instanceConstraintViolationsList; + WorkReportListDTO workReportListDTO = new WorkReportListDTO(Collections.singletonList(workReportDTO)); + + List instanceConstraintViolationsList = + workReportService.addWorkReports(workReportListDTO).instanceConstraintViolationsList; // Test - assertTrue(instanceConstraintViolationsList.toString(), - instanceConstraintViolationsList.size() == 1); - assertTrue(instanceConstraintViolationsList.get(0).constraintViolations - .toString(), - instanceConstraintViolationsList.get(0).constraintViolations - .size() == 2); + assertTrue(instanceConstraintViolationsList.toString(), instanceConstraintViolationsList.size() == 1); + + assertTrue( + instanceConstraintViolationsList.get(0).constraintViolations.toString(), + instanceConstraintViolationsList.get(0).constraintViolations.size() == 2); } @Test @@ -472,76 +452,71 @@ public class WorkReportServiceTest { WorkReportDTO workReportDTO = createWorkReportDTO(workReportTypeCode4); // create invalid description value to add into head and lines. - DescriptionValueDTO valueDTO1 = new DescriptionValueDTO(field1, - "correcto"); - DescriptionValueDTO valueDTO2 = new DescriptionValueDTO(field2, - "correcto"); + DescriptionValueDTO valueDTO1 = new DescriptionValueDTO(field1, "correcto"); + DescriptionValueDTO valueDTO2 = new DescriptionValueDTO(field2, "correcto"); workReportDTO.descriptionValues.add(valueDTO1); + for (WorkReportLineDTO lineDTO : workReportDTO.workReportLines) { lineDTO.descriptionValues.add(valueDTO2); } - WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays - .asList(workReportDTO)); - List instanceConstraintViolationsList = workReportService - .addWorkReports(workReportListDTO).instanceConstraintViolationsList; + WorkReportListDTO workReportListDTO = new WorkReportListDTO(Collections.singletonList(workReportDTO)); + + List instanceConstraintViolationsList = + workReportService.addWorkReports(workReportListDTO).instanceConstraintViolationsList; // Test - assertTrue(instanceConstraintViolationsList.toString(), - instanceConstraintViolationsList.size() == 0); + assertTrue(instanceConstraintViolationsList.toString(), instanceConstraintViolationsList.size() == 0); } @Test public void importValidWorkReport() { - int previous = transactionService - .runOnTransaction(new IOnTransaction() { - @Override - public Integer execute() { - return workReportDAO.getAll().size(); - } - }); + int previous = transactionService.runOnTransaction(new IOnTransaction() { + @Override + public Integer execute() { + return workReportDAO.getAll().size(); + } + }); transactionService.runOnTransaction(new IOnTransaction() { @Override public Void execute() { - WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays - .asList(createWorkReportDTO(workReportTypeCode))); + WorkReportListDTO workReportListDTO = + 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; } }); - List workReports = transactionService - .runOnTransaction(new IOnTransaction>() { - @Override - public List execute() { - List list = workReportDAO.getAll(); - for (WorkReport workReport : list) { - Set workReportLines = workReport - .getWorkReportLines(); - for (WorkReportLine line : workReportLines) { - line.getEffort().getHours(); - } - } - return list; + List workReports = transactionService.runOnTransaction(new IOnTransaction>() { + @Override + public List execute() { + List list = workReportDAO.getAll(); + for (WorkReport workReport : list) { + Set workReportLines = workReport.getWorkReportLines(); + for (WorkReportLine line : workReportLines) { + line.getEffort().getHours(); } - }); + } + + return list; + } + }); assertThat(workReports.size(), equalTo(previous + 1)); - Set workReportLines = workReports.get(previous) - .getWorkReportLines(); + Set workReportLines = workReports.get(previous).getWorkReportLines(); assertThat(workReportLines.size(), equalTo(1)); - assertThat(workReportLines.iterator().next().getEffort(), - equalTo(EffortDuration.sum(EffortDuration.hours(8), - EffortDuration.minutes(15)))); + assertThat( + workReportLines.iterator().next().getEffort(), + equalTo(EffortDuration.sum(EffortDuration.hours(8), EffortDuration.minutes(15)))); } @@ -550,15 +525,16 @@ public class WorkReportServiceTest { public void importInvalidWorkReportWithoutDateAtWorkReportLevel() { int previous = workReportDAO.getAll().size(); - WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays - .asList(createWorkReportDTO(workReportTypeCode2))); + WorkReportListDTO workReportListDTO = + 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 workReports = workReportDAO.getAll(); + assertThat(workReports.size(), equalTo(previous)); } @@ -571,28 +547,25 @@ public class WorkReportServiceTest { Date date = new LocalDate().toDateTimeAtStartOfDay().toDate(); workReportDTO.date = DateConverter.toXMLGregorianCalendar(date); - WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays - .asList(workReportDTO)); + WorkReportListDTO workReportListDTO = new WorkReportListDTO(Collections.singletonList(workReportDTO)); - InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = workReportService - .addWorkReports(workReportListDTO); - assertThat( - instanceConstraintViolationsListDTO.instanceConstraintViolationsList - .size(), equalTo(0)); + InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = + workReportService.addWorkReports(workReportListDTO); + + assertThat(instanceConstraintViolationsListDTO.instanceConstraintViolationsList.size(), equalTo(0)); /** - * Default code that was before was not working with MySQL - * and works perfect with PostgreSQL - * For example: List workReports = workReportDAO.getAll(); - * was returning 0 but COUNT in DB was 1 - * Also set workReportLines in WorkReports.hbm.xml has been changed to fetch='join' - * Possible reason: Hibernate 4.3.11.Final bug / caching - */ + * Default code that was before was not working with MySQL + * and works perfect with PostgreSQL + * For example: List workReports = workReportDAO.getAll(); + * was returning 0 but COUNT in DB was 1 + * Also set workReportLines in WorkReports.hbm.xml has been changed to fetch='join' + * Possible reason: Hibernate 4.3.11.Final bug / caching + */ StatelessSession statelessSession = sessionFactory.openStatelessSession(); - List workReports = statelessSession.createCriteria(WorkReport.class) - .addOrder(Order.asc("code")).list(); + List workReports = statelessSession.createCriteria(WorkReport.class).addOrder(Order.asc("code")).list(); assertThat(workReports.size(), equalTo(previous + 1)); @@ -601,12 +574,11 @@ public class WorkReportServiceTest { assertThat(imported.getDate(), equalTo(date)); - List importedLines = new ArrayList( - imported.getWorkReportLines()); + List importedLines = new ArrayList<>(imported.getWorkReportLines()); Collections.sort(importedLines); - List exportedLines = new ArrayList( - workReportDTO.workReportLines); + List exportedLines = new ArrayList<>(workReportDTO.workReportLines); + Collections.sort(exportedLines, new Comparator() { @Override public int compare(WorkReportLineDTO o1, WorkReportLineDTO o2) { @@ -622,8 +594,7 @@ public class WorkReportServiceTest { } private long asTime(XMLGregorianCalendar date2) { - return date2 - .toGregorianCalendar().getTime().getTime(); + return date2.toGregorianCalendar().getTime().getTime(); } @Test @@ -631,126 +602,115 @@ public class WorkReportServiceTest { public void importInvalidWorkReportCalculatedHours() { int previous = workReportDAO.getAll().size(); - WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays - .asList(createWorkReportDTO(workReportTypeCode3))); + WorkReportListDTO workReportListDTO = + 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 workReports = workReportDAO.getAll(); + assertThat(workReports.size(), equalTo(previous)); } @Test public void importValidWorkReportCalculatedHours() { - int previous = transactionService - .runOnTransaction(new IOnTransaction() { - @Override - public Integer execute() { - return workReportDAO.getAll().size(); - } - }); + int previous = transactionService.runOnTransaction(new IOnTransaction() { + @Override + public Integer execute() { + return workReportDAO.getAll().size(); + } + }); WorkReportDTO workReportDTO = createWorkReportDTO(workReportTypeCode3); - WorkReportLineDTO workReportLineDTO = workReportDTO.workReportLines - .iterator().next(); + WorkReportLineDTO workReportLineDTO = workReportDTO.workReportLines.iterator().next(); int hours = 12; LocalTime start = new LocalTime(8, 0); LocalTime end = start.plusHours(hours); - workReportLineDTO.clockStart = DateConverter - .toXMLGregorianCalendar(start); - workReportLineDTO.clockFinish = DateConverter - .toXMLGregorianCalendar(end); + workReportLineDTO.clockStart = DateConverter.toXMLGregorianCalendar(start); + workReportLineDTO.clockFinish = DateConverter.toXMLGregorianCalendar(end); - WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays - .asList(workReportDTO)); + WorkReportListDTO workReportListDTO = new WorkReportListDTO(Collections.singletonList(workReportDTO)); - InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = workReportService - .addWorkReports(workReportListDTO); - assertThat( - instanceConstraintViolationsListDTO.instanceConstraintViolationsList - .size(), equalTo(0)); - List workReports = transactionService - .runOnTransaction(new IOnTransaction>() { - @Override - public List execute() { - List list = workReportDAO.getAll(); - for (WorkReport workReport : list) { - Set workReportLines = workReport - .getWorkReportLines(); - for (WorkReportLine line : workReportLines) { - line.getEffort().getHours(); - } - } - return list; + InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = + workReportService.addWorkReports(workReportListDTO); + + assertThat(instanceConstraintViolationsListDTO.instanceConstraintViolationsList.size(), equalTo(0)); + + List workReports = transactionService.runOnTransaction(new IOnTransaction>() { + @Override + public List execute() { + List list = workReportDAO.getAll(); + for (WorkReport workReport : list) { + Set workReportLines = workReport.getWorkReportLines(); + for (WorkReportLine line : workReportLines) { + line.getEffort().getHours(); } - }); + } + + return list; + } + }); + assertThat(workReports.size(), equalTo(previous + 1)); - Set workReportLines = workReports.get(previous) - .getWorkReportLines(); + Set workReportLines = workReports.get(previous).getWorkReportLines(); + assertThat(workReportLines.size(), equalTo(1)); - assertThat(workReportLines.iterator().next().getEffort().getHours(), - equalTo(hours)); + assertThat(workReportLines.iterator().next().getEffort().getHours(), equalTo(hours)); } @Test public void importAndUpdateValidWorkReport() { - int previous = transactionService - .runOnTransaction(new IOnTransaction() { - @Override - public Integer execute() { - return workReportDAO.getAll().size(); - } - }); + int previous = transactionService.runOnTransaction(new IOnTransaction() { + @Override + public Integer execute() { + return workReportDAO.getAll().size(); + } + }); WorkReportDTO workReportDTO = createWorkReportDTO(workReportTypeCode); - WorkReportListDTO workReportListDTO = new WorkReportListDTO(Arrays - .asList(workReportDTO)); + WorkReportListDTO workReportListDTO = new WorkReportListDTO(Collections.singletonList(workReportDTO)); - InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = workReportService - .addWorkReports(workReportListDTO); - assertThat( - instanceConstraintViolationsListDTO.instanceConstraintViolationsList - .size(), equalTo(0)); - List workReports = transactionService - .runOnTransaction(new IOnTransaction>() { - @Override - public List execute() { - List list = workReportDAO.getAll(); - for (WorkReport workReport : list) { - Set workReportLines = workReport - .getWorkReportLines(); - for (WorkReportLine line : workReportLines) { - line.getEffort().getHours(); - } - } - return list; + InstanceConstraintViolationsListDTO instanceConstraintViolationsListDTO = + workReportService.addWorkReports(workReportListDTO); + + assertThat(instanceConstraintViolationsListDTO.instanceConstraintViolationsList.size(), equalTo(0)); + + List workReports = transactionService.runOnTransaction(new IOnTransaction>() { + @Override + public List execute() { + List list = workReportDAO.getAll(); + for (WorkReport workReport : list) { + Set workReportLines = workReport.getWorkReportLines(); + for (WorkReportLine line : workReportLines) { + line.getEffort().getHours(); } - }); + } + + return list; + } + }); + assertThat(workReports.size(), equalTo(previous + 1)); - Set workReportLines = workReports.get(previous) - .getWorkReportLines(); + Set workReportLines = workReports.get(previous).getWorkReportLines(); + assertThat(workReportLines.size(), equalTo(1)); - assertThat(workReportLines.iterator().next().getEffort(), - equalTo(EffortDuration.sum(EffortDuration.hours(8), - EffortDuration.minutes(15)))); + assertThat( + workReportLines.iterator().next().getEffort(), + equalTo(EffortDuration.sum(EffortDuration.hours(8), EffortDuration.minutes(15)))); workReportDTO.workReportLines.add(createWorkReportLineDTO()); - WorkReportListDTO workReportListDTO2 = new WorkReportListDTO(Arrays - .asList(workReportDTO)); - instanceConstraintViolationsListDTO = workReportService - .addWorkReports(workReportListDTO2); + WorkReportListDTO workReportListDTO2 = new WorkReportListDTO(Collections.singletonList(workReportDTO)); + instanceConstraintViolationsListDTO = workReportService.addWorkReports(workReportListDTO2); - assertThat( - instanceConstraintViolationsListDTO.instanceConstraintViolationsList - .size(), equalTo(0)); + assertThat(instanceConstraintViolationsListDTO.instanceConstraintViolationsList.size(), equalTo(0)); } } diff --git a/pom.xml b/pom.xml index 9ac5431ec..5f5986b93 100644 --- a/pom.xml +++ b/pom.xml @@ -530,7 +530,7 @@ org.apache.cxf cxf-rt-transports-http - 2.2.3 + 3.1.6 org.springframework @@ -553,7 +553,26 @@ org.apache.cxf cxf-rt-frontend-jaxrs - 2.2.3 + 3.1.6 + + + org.springframework + spring-core + + + org.springframework + spring-beans + + + org.springframework + spring-context + + + + + org.apache.cxf + cxf-rt-rs-client + 3.1.6 org.springframework