Fixed stream handling and some sonar issues
This commit is contained in:
@@ -20,10 +20,11 @@ import feign.RequestLine;
|
|||||||
/**
|
/**
|
||||||
* Client binding for the Distribution resource of the management API.
|
* Client binding for the Distribution resource of the management API.
|
||||||
*/
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
public interface DistributionSetResource {
|
public interface DistributionSetResource {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a list of distrbution sets.
|
* Creates a list of distribution sets.
|
||||||
*
|
*
|
||||||
* @param sets
|
* @param sets
|
||||||
* the request body java bean containing the necessary attributes
|
* the request body java bean containing the necessary attributes
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class MongoConfiguration extends AbstractMongoConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes mongo client when destroyd.
|
* Closes mongo client when destroyed.
|
||||||
*/
|
*/
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
public void close() {
|
public void close() {
|
||||||
@@ -74,22 +74,13 @@ public class MongoConfiguration extends AbstractMongoConfiguration {
|
|||||||
public Mongo mongo() throws UnknownHostException {
|
public Mongo mongo() throws UnknownHostException {
|
||||||
final MongoClientURI uri = new MongoClientURI(properties.getUri(), createBuilderOutOfOptions(options));
|
final MongoClientURI uri = new MongoClientURI(properties.getUri(), createBuilderOutOfOptions(options));
|
||||||
|
|
||||||
try {
|
if (properties.getPort() != null) {
|
||||||
if (properties.getPort() != null) {
|
LOG.debug("Create mongo by properties (host: {}, port: {})", uri.getHosts().get(0), properties.getPort());
|
||||||
LOG.debug("Create mongo by properties (host: {}, port: {})", uri.getHosts().get(0),
|
this.mongoConnection = new MongoClient(
|
||||||
properties.getPort());
|
Arrays.asList(new ServerAddress(uri.getHosts().get(0), properties.getPort())), uri.getOptions());
|
||||||
this.mongoConnection = new MongoClient(
|
} else {
|
||||||
Arrays.asList(new ServerAddress(uri.getHosts().get(0), properties.getPort())),
|
LOG.debug("Create mongo by URI : {}", uri);
|
||||||
uri.getOptions());
|
this.mongoConnection = new MongoClient(uri);
|
||||||
} else {
|
|
||||||
LOG.debug("Create mongo by URI : {}", uri);
|
|
||||||
this.mongoConnection = new MongoClient(uri);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (this.mongoConnection != null) {
|
|
||||||
this.mongoConnection.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.mongoConnection;
|
return this.mongoConnection;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import com.vaadin.spring.boot.internal.VaadinServletConfigurationProperties;
|
|||||||
@Import(VaadinServletConfiguration.class)
|
@Import(VaadinServletConfiguration.class)
|
||||||
public class AsyncVaadinServletConfiguration extends VaadinServletConfiguration {
|
public class AsyncVaadinServletConfiguration extends VaadinServletConfiguration {
|
||||||
|
|
||||||
|
@Override
|
||||||
@Bean
|
@Bean
|
||||||
protected ServletRegistrationBean vaadinServletRegistration() {
|
protected ServletRegistrationBean vaadinServletRegistration() {
|
||||||
return createServletRegistrationBean();
|
return createServletRegistrationBean();
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
@@ -63,14 +64,12 @@ import com.vaadin.ui.Upload.SucceededListener;
|
|||||||
/**
|
/**
|
||||||
* Bulk target upload handler.
|
* Bulk target upload handler.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class BulkUploadHandler extends CustomComponent
|
public class BulkUploadHandler extends CustomComponent
|
||||||
implements SucceededListener, FailedListener, Receiver, StartedListener {
|
implements SucceededListener, FailedListener, Receiver, StartedListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* *
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -1273494705754674501L;
|
private static final long serialVersionUID = -1273494705754674501L;
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(BulkUploadHandler.class);
|
private static final Logger LOG = LoggerFactory.getLogger(BulkUploadHandler.class);
|
||||||
@@ -208,15 +207,18 @@ public class BulkUploadHandler extends CustomComponent
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
BufferedReader reader = null;
|
|
||||||
long innerCounter = 0;
|
long innerCounter = 0;
|
||||||
String line;
|
String line;
|
||||||
if (tempFile != null) {
|
if (tempFile == null) {
|
||||||
try {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (InputStream tempStream = new FileInputStream(tempFile)) {
|
||||||
|
try (BufferedReader reader = new BufferedReader(
|
||||||
|
new InputStreamReader(tempStream, Charset.defaultCharset()))) {
|
||||||
LOG.info("Bulk file upload started");
|
LOG.info("Bulk file upload started");
|
||||||
final double totalFileSize = getTotalNumberOfLines();
|
final double totalFileSize = getTotalNumberOfLines();
|
||||||
reader = new BufferedReader(
|
|
||||||
new InputStreamReader(new FileInputStream(tempFile), Charset.defaultCharset()));
|
|
||||||
/**
|
/**
|
||||||
* Once control is in upload succeeded method automatically
|
* Once control is in upload succeeded method automatically
|
||||||
* upload button is re-enabled. To disable the button firing
|
* upload button is re-enabled. To disable the button firing
|
||||||
@@ -232,21 +234,16 @@ public class BulkUploadHandler extends CustomComponent
|
|||||||
|
|
||||||
// Clearing after assignments are done
|
// Clearing after assignments are done
|
||||||
managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated().clear();
|
managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated().clear();
|
||||||
} catch (final FileNotFoundException e) {
|
|
||||||
LOG.error("File not found with name {}", tempFile.getName(), e);
|
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
LOG.error("Error reading file {}", tempFile.getName(), e);
|
LOG.error("Error reading file {}", tempFile.getName(), e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
resetCounts();
|
||||||
if (null != reader) {
|
deleteFile();
|
||||||
reader.close();
|
|
||||||
resetCounts();
|
|
||||||
deleteFile();
|
|
||||||
}
|
|
||||||
} catch (final IOException e) {
|
|
||||||
LOG.error("Error while reading file ", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} catch (final FileNotFoundException e) {
|
||||||
|
LOG.error("Temporary file not found with name {}", tempFile.getName(), e);
|
||||||
|
} catch (final IOException e) {
|
||||||
|
LOG.error("Error while opening temorary file ", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -307,24 +304,19 @@ public class BulkUploadHandler extends CustomComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
private double getTotalNumberOfLines() {
|
private double getTotalNumberOfLines() {
|
||||||
InputStreamReader inputStreamReader;
|
|
||||||
BufferedReader readerForSize = null;
|
|
||||||
double totalFileSize = 0;
|
double totalFileSize = 0;
|
||||||
try {
|
try (InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(tempFile),
|
||||||
inputStreamReader = new InputStreamReader(new FileInputStream(tempFile), Charset.defaultCharset());
|
Charset.defaultCharset())) {
|
||||||
readerForSize = new BufferedReader(inputStreamReader);
|
try (BufferedReader readerForSize = new BufferedReader(inputStreamReader)) {
|
||||||
totalFileSize = readerForSize.lines().count();
|
totalFileSize = readerForSize.lines().count();
|
||||||
|
}
|
||||||
} catch (final FileNotFoundException e) {
|
} catch (final FileNotFoundException e) {
|
||||||
LOG.error("Error reading file {}", tempFile.getName(), e);
|
LOG.error("Error reading file {}", tempFile.getName(), e);
|
||||||
} finally {
|
} catch (final IOException e) {
|
||||||
if (readerForSize != null) {
|
LOG.error("Error while closing reader of file {}", tempFile.getName(), e);
|
||||||
try {
|
|
||||||
readerForSize.close();
|
|
||||||
} catch (final IOException e) {
|
|
||||||
LOG.error("Error while closing reader of file {}", tempFile.getName(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return totalFileSize;
|
return totalFileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user