INTSAMPLES-143: Fix Package Tangles
JIRA: https://jira.spring.io/browse/INTSAMPLES-143 Add Sonar support to build.gradle. Fix critical violations.
This commit is contained in:
committed by
Artem Bilan
parent
70b4d12870
commit
61603c2437
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
*/
|
||||
public class LoanQuote implements Comparable<LoanQuote>{
|
||||
|
||||
@@ -78,8 +79,9 @@ public class LoanQuote implements Comparable<LoanQuote>{
|
||||
this.rate = rate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(LoanQuote other) {
|
||||
if (this.rate > other.rate) {
|
||||
if (this.rate > other.rate) { //NOSONAR
|
||||
return 1;
|
||||
}
|
||||
else if (this.rate < other.rate) {
|
||||
@@ -88,8 +90,9 @@ public class LoanQuote implements Comparable<LoanQuote>{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.lender + ":\t" + this.rate;
|
||||
return this.lender + ":\t" + this.rate;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,7 +38,7 @@ public class Accumulator {
|
||||
if (shark == null) {
|
||||
shark = new LoanShark();
|
||||
shark.setName(quote.getSharkName());
|
||||
shark.setCounter(new Long(0));
|
||||
shark.setCounter(Long.valueOf(0));
|
||||
shark.setAverageRate(0.0d);
|
||||
shark.persist();
|
||||
}
|
||||
@@ -46,5 +46,5 @@ public class Accumulator {
|
||||
shark.setCounter(shark.getCounter().longValue() + 1);
|
||||
shark.setAverageRate((current + quote.getSharkRate()) / shark.getCounter());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.Scanner;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.samples.enricher.domain.User;
|
||||
import org.springframework.integration.samples.enricher.service.UserService;
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
@@ -10,31 +10,34 @@
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.samples.enricher;
|
||||
package org.springframework.integration.samples.enricher.domain;
|
||||
|
||||
public class User {
|
||||
private String username;
|
||||
private String password;
|
||||
private String email;
|
||||
|
||||
public User(String username, String password, String email) {
|
||||
super();
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.email = email;
|
||||
}
|
||||
private String username;
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
private String password;
|
||||
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
private String email;
|
||||
|
||||
public String getEmail() {
|
||||
return this.email;
|
||||
}
|
||||
public User(String username, String password, String email) {
|
||||
super();
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return this.email;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
@@ -51,12 +54,8 @@ public class User {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("User [username=")
|
||||
.append(this.username)
|
||||
.append(", password=")
|
||||
.append(this.password)
|
||||
.append(", email=")
|
||||
.append(this.email).append("]");
|
||||
builder.append("User [username=").append(this.username).append(", password=").append(this.password)
|
||||
.append(", email=").append(this.email).append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.integration.samples.enricher.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.integration.samples.enricher.User;
|
||||
import org.springframework.integration.samples.enricher.domain.User;
|
||||
|
||||
/**
|
||||
* Provides user services.
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
package org.springframework.integration.samples.enricher.service.impl;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.integration.samples.enricher.User;
|
||||
|
||||
import org.springframework.integration.samples.enricher.domain.User;
|
||||
|
||||
/**
|
||||
* Simple Service class for retrieving user information.
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.samples.enricher.User;
|
||||
import org.springframework.integration.samples.enricher.domain.User;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,8 @@ import java.util.Scanner;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.samples.jdbc.domain.Gender;
|
||||
import org.springframework.integration.samples.jdbc.domain.Person;
|
||||
import org.springframework.integration.samples.jdbc.service.PersonService;
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.samples.jdbc;
|
||||
package org.springframework.integration.samples.jdbc.domain;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.samples.jdbc;
|
||||
package org.springframework.integration.samples.jdbc.domain;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.samples.jdbc;
|
||||
package org.springframework.integration.samples.jdbc.domain;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@@ -10,7 +10,7 @@
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.samples.jdbc;
|
||||
package org.springframework.integration.samples.jdbc.domain;
|
||||
|
||||
public class User {
|
||||
private String username;
|
||||
@@ -10,7 +10,7 @@
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.samples.jdbc;
|
||||
package org.springframework.integration.samples.jdbc.domain;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@@ -18,7 +18,7 @@ package org.springframework.integration.samples.jdbc.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.integration.samples.jdbc.Person;
|
||||
import org.springframework.integration.samples.jdbc.domain.Person;
|
||||
|
||||
/**
|
||||
* The Service used to create Person instance in database
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<bean id="personResultMapper" class="org.springframework.integration.samples.jdbc.PersonMapper"/>
|
||||
<bean id="personResultMapper" class="org.springframework.integration.samples.jdbc.domain.PersonMapper"/>
|
||||
<int-jdbc:outbound-gateway data-source="datasource"
|
||||
request-channel="createPersonRequestChannel"
|
||||
reply-channel="createPersonReplyChannel"
|
||||
|
||||
@@ -22,6 +22,8 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.samples.jdbc.domain.Gender;
|
||||
import org.springframework.integration.samples.jdbc.domain.Person;
|
||||
import org.springframework.integration.samples.jdbc.service.PersonService;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.springframework.context.support.GenericXmlApplicationContext;
|
||||
import org.springframework.integration.samples.jpa.domain.Person;
|
||||
import org.springframework.integration.samples.jpa.service.PersonService;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -28,6 +29,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Gunnar Hillert
|
||||
* @author Amol Nayak
|
||||
* @author Gary Russell
|
||||
* @version 1.0
|
||||
*
|
||||
*/
|
||||
@@ -104,13 +106,16 @@ public final class Main {
|
||||
while (true) {
|
||||
final String input = scanner.nextLine();
|
||||
|
||||
if("1".equals(input.trim())) {
|
||||
if ("1".equals(input.trim())) {
|
||||
findPeople(personService);
|
||||
} else if("2".equals(input.trim())) {
|
||||
createPersonDetails(scanner,personService);
|
||||
} else if("q".equals(input.trim())) {
|
||||
}
|
||||
else if ("2".equals(input.trim())) {
|
||||
createPersonDetails(scanner, personService);
|
||||
}
|
||||
else if ("q".equals(input.trim())) {
|
||||
break;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
System.out.println("Invalid choice\n\n");
|
||||
}
|
||||
|
||||
@@ -122,6 +127,7 @@ public final class Main {
|
||||
}
|
||||
|
||||
System.out.println("Exiting application...bye.");
|
||||
context.close();
|
||||
System.exit(0);
|
||||
|
||||
}
|
||||
@@ -169,7 +175,7 @@ public final class Main {
|
||||
if(people != null && !people.isEmpty()) {
|
||||
for(Person person : people) {
|
||||
System.out.print(String.format("%d, %s, ", person.getId(), person.getName()));
|
||||
System.out.println(DATE_FORMAT.format(person.getCreatedDateTime()));
|
||||
System.out.println(DATE_FORMAT.format(person.getCreatedDateTime()));//NOSONAR
|
||||
}
|
||||
} else {
|
||||
System.out.println(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.samples.jpa;
|
||||
package org.springframework.integration.samples.jpa.domain;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.integration.samples.jpa.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.integration.samples.jpa.Person;
|
||||
import org.springframework.integration.samples.jpa.domain.Person;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.samples.jpa.domain.Person;
|
||||
import org.springframework.integration.samples.jpa.service.PersonService;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,14 +25,15 @@ import org.springframework.integration.annotation.ServiceActivator;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
*/
|
||||
@MessageEndpoint
|
||||
public class QuoteService {
|
||||
|
||||
@ServiceActivator(inputChannel="tickers", outputChannel="quotes")
|
||||
public Quote lookupQuote(String ticker) {
|
||||
BigDecimal price = new BigDecimal(new Random().nextDouble() * 100);
|
||||
return new Quote(ticker, price.setScale(2, RoundingMode.HALF_EVEN));
|
||||
BigDecimal price = new BigDecimal(new Random().nextDouble() * 100);//NOSONAR
|
||||
return new Quote(ticker, price.setScale(2, RoundingMode.HALF_EVEN));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,14 +31,20 @@ public class Main {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"META-INF/spring/integration/04-externalgateway/*.xml");
|
||||
"META-INF/spring/integration/04-externalgateway/*.xml");
|
||||
System.out.println("Please enter zip");
|
||||
|
||||
|
||||
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
|
||||
String zip = console.readLine().trim();
|
||||
WeatherAndTraffic weatherAndTraffic = context.getBean("wat", WeatherAndTraffic.class);
|
||||
List<String> result = weatherAndTraffic.getByZip(zip);
|
||||
System.out.println(result.get(0) + "\r\n" + result.get(1) + "\r\n");
|
||||
String line = console.readLine();
|
||||
if (line != null) {
|
||||
String zip = line.trim();
|
||||
WeatherAndTraffic weatherAndTraffic = context.getBean("wat", WeatherAndTraffic.class);
|
||||
List<String> result = weatherAndTraffic.getByZip(zip);
|
||||
System.out.println(result.get(0) + "\r\n" + result.get(1) + "\r\n");
|
||||
}
|
||||
else {
|
||||
System.out.println("Console closed");
|
||||
}
|
||||
context.close();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
47
build.gradle
47
build.gradle
@@ -24,6 +24,14 @@ buildscript {
|
||||
|
||||
allprojects {
|
||||
group = 'org.springframework.integration.samples'
|
||||
|
||||
repositories {
|
||||
// mavenLocal()
|
||||
maven { url 'http://repo.spring.io/libs-snapshot' }
|
||||
maven { url 'http://repo.spring.io/libs-milestone' }
|
||||
// maven { url 'http://repo.spring.io/libs-staging-local' }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
subprojects { subproject ->
|
||||
@@ -138,16 +146,14 @@ subprojects { subproject ->
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
// mavenLocal()
|
||||
maven { url 'http://repo.spring.io/libs-snapshot' }
|
||||
maven { url 'http://repo.spring.io/libs-milestone' }
|
||||
// maven { url 'http://repo.spring.io/libs-staging-local' }
|
||||
}
|
||||
|
||||
if (!(subproject.name in ['advanced', 'applications', 'basic', 'intermediate', 'cafe'])) {
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'jacoco'
|
||||
|
||||
jacoco {
|
||||
toolVersion = "0.7.2.201409121644"
|
||||
}
|
||||
|
||||
sourceCompatibility = 1.6
|
||||
|
||||
@@ -224,9 +230,21 @@ subprojects { subproject ->
|
||||
ext.xLintArg = '-Xlint:all,-options'
|
||||
[compileJava, compileTestJava]*.options*.compilerArgs = [xLintArg]
|
||||
|
||||
jacocoTestReport {
|
||||
reports {
|
||||
xml.enabled false
|
||||
csv.enabled false
|
||||
html.destination "${buildDir}/reports/jacoco/html"
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
// suppress all console output during testing unless running `gradle -i`
|
||||
logging.captureStandardOutput(LogLevel.INFO)
|
||||
jacoco {
|
||||
append = false
|
||||
destinationFile = file("$buildDir/jacoco.exec")
|
||||
}
|
||||
}
|
||||
|
||||
task checkTestConfigs << {
|
||||
@@ -249,6 +267,7 @@ subprojects { subproject ->
|
||||
}
|
||||
|
||||
test.dependsOn checkTestConfigs
|
||||
build.dependsOn jacocoTestReport
|
||||
}
|
||||
|
||||
task cleanTarget(type: Delete) {
|
||||
@@ -1139,6 +1158,20 @@ project('stomp-chat') {
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'sonar-runner'
|
||||
|
||||
sonarRunner {
|
||||
sonarProperties {
|
||||
property "sonar.jacoco.reportPath", "${buildDir.name}/jacoco.exec"
|
||||
property "sonar.links.homepage", linkHomepage
|
||||
property "sonar.links.ci", linkCi
|
||||
property "sonar.links.issue", linkIssue
|
||||
property "sonar.links.scm", linkScmUrl
|
||||
property "sonar.links.scm_dev", linkScmDevConnection
|
||||
property "sonar.java.coveragePlugin", "jacoco"
|
||||
}
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
description = 'Generates gradlew[.bat] scripts'
|
||||
gradleVersion = '2.3'
|
||||
|
||||
@@ -19,11 +19,11 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.support.ChannelInterceptorAdapter;
|
||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
/**
|
||||
@@ -37,9 +37,9 @@ import org.springframework.util.StopWatch;
|
||||
@ManagedResource
|
||||
public class PayloadAwareTimingInterceptor extends ChannelInterceptorAdapter {
|
||||
|
||||
private ThreadLocal<StopWatchHolder> stopWatchHolder = new ThreadLocal<PayloadAwareTimingInterceptor.StopWatchHolder>();
|
||||
private final ThreadLocal<StopWatchHolder> stopWatchHolder = new ThreadLocal<PayloadAwareTimingInterceptor.StopWatchHolder>();
|
||||
|
||||
private Map<Class<?>, Stats> statsMap = new ConcurrentHashMap<Class<?>, PayloadAwareTimingInterceptor.Stats>();
|
||||
private final Map<Class<?>, Stats> statsMap = new ConcurrentHashMap<Class<?>, PayloadAwareTimingInterceptor.Stats>();
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -68,12 +68,12 @@ public class PayloadAwareTimingInterceptor extends ChannelInterceptorAdapter {
|
||||
StopWatchHolder holder = this.stopWatchHolder.get();
|
||||
if (holder != null) {
|
||||
holder.getStopWatch().stop();
|
||||
Stats stats = this.statsMap.get(holder.getType());
|
||||
if (stats == null) {
|
||||
stats = this.statsMap.get(Object.class);
|
||||
}
|
||||
stats.add(holder.getStopWatch().getLastTaskTimeMillis());
|
||||
}
|
||||
Stats stats = this.statsMap.get(holder.getType());
|
||||
if (stats == null) {
|
||||
stats = this.statsMap.get(Object.class);
|
||||
}
|
||||
stats.add(holder.getStopWatch().getLastTaskTimeMillis());
|
||||
}
|
||||
|
||||
@ManagedOperation
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,17 +19,19 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.springframework.integration.samples.rest.domain.Employee;
|
||||
import org.springframework.integration.samples.rest.domain.EmployeeList;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.integration.samples.rest.domain.Employee;
|
||||
import org.springframework.integration.samples.rest.domain.EmployeeList;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* EmployeeSearchService.java: This is the default employee search service
|
||||
* @author Vigil Bose
|
||||
* @author Gary Russell
|
||||
*/
|
||||
@Service("employeeSearchService")
|
||||
public class EmployeeSearchService {
|
||||
@@ -46,41 +48,46 @@ public class EmployeeSearchService {
|
||||
*/
|
||||
@Secured("ROLE_REST_HTTP_USER")
|
||||
public Message<EmployeeList> getEmployee(Message<?> inMessage){
|
||||
|
||||
|
||||
EmployeeList employeeList = new EmployeeList();
|
||||
Map<String, Object> responseHeaderMap = new HashMap<String, Object>();
|
||||
|
||||
|
||||
try{
|
||||
MessageHeaders headers = inMessage.getHeaders();
|
||||
String id = (String)headers.get("employeeId");
|
||||
boolean isFound;
|
||||
if (id.equals("1")){
|
||||
if (id.equals("1")) {
|
||||
employeeList.getEmployee().add(new Employee(1, "John", "Doe"));
|
||||
isFound = true;
|
||||
}else if (id.equals("2")){
|
||||
}
|
||||
else if (id.equals("2")) {
|
||||
employeeList.getEmployee().add(new Employee(2, "Jane", "Doe"));
|
||||
isFound = true;
|
||||
}else if (id.equals("0")){
|
||||
employeeList.getEmployee().add(new Employee(1, "John", "Doe"));
|
||||
employeeList.getEmployee().add(new Employee(2, "Jane", "Doe"));
|
||||
isFound = true;
|
||||
}else{
|
||||
isFound = false;
|
||||
}
|
||||
if (isFound){
|
||||
setReturnStatusAndMessage("0", "Success", employeeList, responseHeaderMap);
|
||||
}else{
|
||||
setReturnStatusAndMessage("2", "Employee Not Found", employeeList, responseHeaderMap);
|
||||
}
|
||||
|
||||
}catch (Throwable e){
|
||||
else if (id.equals("0")) {
|
||||
employeeList.getEmployee().add(new Employee(1, "John", "Doe"));
|
||||
employeeList.getEmployee().add(new Employee(2, "Jane", "Doe"));
|
||||
isFound = true;
|
||||
}
|
||||
else {
|
||||
isFound = false;
|
||||
}
|
||||
if (isFound) {
|
||||
setReturnStatusAndMessage("0", "Success", employeeList, responseHeaderMap);
|
||||
}
|
||||
else {
|
||||
setReturnStatusAndMessage("2", "Employee Not Found", employeeList, responseHeaderMap);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
setReturnStatusAndMessage("1", "System Error", employeeList, responseHeaderMap);
|
||||
logger.error("System error occured :"+e);
|
||||
logger.error("System error occured :" + e);
|
||||
}
|
||||
Message<EmployeeList> message = new GenericMessage<EmployeeList>(employeeList, responseHeaderMap);
|
||||
return message;
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The API <code>setReturnStatusAndMessage()</code> sets the return status and return message
|
||||
* in the return message payload and its header.
|
||||
@@ -89,16 +96,17 @@ public class EmployeeSearchService {
|
||||
* @param employeeList
|
||||
* @param responseHeaderMap
|
||||
*/
|
||||
private void setReturnStatusAndMessage(String status,
|
||||
String message,
|
||||
EmployeeList employeeList,
|
||||
private void setReturnStatusAndMessage(String status,
|
||||
String message,
|
||||
EmployeeList employeeList,
|
||||
Map<String, Object> responseHeaderMap){
|
||||
|
||||
|
||||
employeeList.setReturnStatus(status);
|
||||
employeeList.setReturnStatusMsg(message);
|
||||
responseHeaderMap.put("Return-Status", status);
|
||||
responseHeaderMap.put("Return-Status-Msg", message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ package org.springframework.integration.samples.splitteraggregator;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.springframework.integration.samples.splitteraggregator.support.CriteriaA;
|
||||
|
||||
/**
|
||||
* One type of search.
|
||||
*
|
||||
|
||||
@@ -17,6 +17,8 @@ package org.springframework.integration.samples.splitteraggregator;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.springframework.integration.samples.splitteraggregator.support.CriteriaB;
|
||||
|
||||
/**
|
||||
* Another type of search.
|
||||
*
|
||||
|
||||
@@ -17,6 +17,9 @@ package org.springframework.integration.samples.splitteraggregator;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.integration.samples.splitteraggregator.support.AbstractCriteria;
|
||||
import org.springframework.integration.samples.splitteraggregator.support.CompositeCriteria;
|
||||
|
||||
/**
|
||||
* Given CompositeCriteria, return a collection of the individual criterion.
|
||||
*
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.integration.samples.splitteraggregator;
|
||||
|
||||
import org.springframework.integration.samples.splitteraggregator.support.CompositeCriteria;
|
||||
|
||||
/**
|
||||
* A service interface responsible for performing a search and returning a
|
||||
* result synchronously.
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.samples.splitteraggregator;
|
||||
package org.springframework.integration.samples.splitteraggregator.support;
|
||||
|
||||
/**
|
||||
* A class that represents all criteria.
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.samples.splitteraggregator;
|
||||
package org.springframework.integration.samples.splitteraggregator.support;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.samples.splitteraggregator;
|
||||
package org.springframework.integration.samples.splitteraggregator.support;
|
||||
|
||||
/**
|
||||
* One type of criteria.
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.samples.splitteraggregator;
|
||||
package org.springframework.integration.samples.splitteraggregator.support;
|
||||
|
||||
/**
|
||||
* Another type of criteria.
|
||||
@@ -15,11 +15,6 @@
|
||||
*/
|
||||
package org.springframework.integration.samples.splitteraggregator.support;
|
||||
|
||||
import org.springframework.integration.samples.splitteraggregator.CompositeCriteria;
|
||||
import org.springframework.integration.samples.splitteraggregator.CriteriaA;
|
||||
import org.springframework.integration.samples.splitteraggregator.CriteriaB;
|
||||
|
||||
|
||||
/**
|
||||
* @author Gunnar Hillert
|
||||
* @since 1.0
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
|
||||
<int:payload-type-router input-channel="search-requests">
|
||||
<int:mapping
|
||||
type="org.springframework.integration.samples.splitteraggregator.CriteriaA"
|
||||
type="org.springframework.integration.samples.splitteraggregator.support.CriteriaA"
|
||||
channel="search-request-a" />
|
||||
<int:mapping
|
||||
type="org.springframework.integration.samples.splitteraggregator.CriteriaB"
|
||||
type="org.springframework.integration.samples.splitteraggregator.support.CriteriaB"
|
||||
channel="search-request-b" />
|
||||
</int:payload-type-router>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,6 +26,7 @@ import org.springframework.jdbc.support.JdbcUtils;
|
||||
/**
|
||||
*
|
||||
* @author Gunnar Hillert
|
||||
* @author Gary Russell
|
||||
* @since 2.1
|
||||
*
|
||||
*/
|
||||
@@ -49,7 +50,8 @@ public final class DerbyStoredProcedures {
|
||||
resultset.next();
|
||||
coffeeDescription[0] = resultset.getString("COFFEE_DESCRIPTION");
|
||||
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
JdbcUtils.closeStatement(statement);
|
||||
JdbcUtils.closeConnection(connection);
|
||||
}
|
||||
@@ -62,10 +64,16 @@ public final class DerbyStoredProcedures {
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
|
||||
connection = DriverManager.getConnection("jdbc:default:connection");
|
||||
String sql = "SELECT * FROM COFFEE_BEVERAGES";
|
||||
statement = connection.prepareStatement(sql);
|
||||
coffeeBeverages[0] = statement.executeQuery();
|
||||
try {
|
||||
connection = DriverManager.getConnection("jdbc:default:connection");
|
||||
String sql = "SELECT * FROM COFFEE_BEVERAGES";
|
||||
statement = connection.prepareStatement(sql);//NOSONAR see below
|
||||
coffeeBeverages[0] = statement.executeQuery();
|
||||
}
|
||||
finally {
|
||||
// JdbcUtils.closeStatement(statement); // cannot close due to result set being returned
|
||||
JdbcUtils.closeConnection(connection);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user