Fix sonar issue

This commit is contained in:
Kai Zimmermann
2016-02-02 10:19:37 +01:00
parent 4df411b97f
commit bc46bac2ac

View File

@@ -207,39 +207,12 @@ public class BulkUploadHandler extends CustomComponent
@Override @Override
public void run() { public void run() {
long innerCounter = 0;
String line;
if (tempFile == null) { if (tempFile == null) {
return; return;
} }
try (InputStream tempStream = new FileInputStream(tempFile)) { try (InputStream tempStream = new FileInputStream(tempFile)) {
try (BufferedReader reader = new BufferedReader( readFileStream(tempStream);
new InputStreamReader(tempStream, Charset.defaultCharset()))) {
LOG.info("Bulk file upload started");
final double totalFileSize = getTotalNumberOfLines();
/**
* Once control is in upload succeeded method automatically
* upload button is re-enabled. To disable the button firing
* below event.
*/
eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.BULK_UPLOAD_PROCESS_STARTED));
while ((line = reader.readLine()) != null) {
innerCounter++;
readEachLine(line, innerCounter, totalFileSize);
}
doAssignments();
eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.BULK_UPLOAD_COMPLETED));
// Clearing after assignments are done
managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated().clear();
} catch (final IOException e) {
LOG.error("Error reading file {}", tempFile.getName(), e);
} finally {
resetCounts();
deleteFile();
}
} catch (final FileNotFoundException e) { } catch (final FileNotFoundException e) {
LOG.error("Temporary file not found with name {}", tempFile.getName(), e); LOG.error("Temporary file not found with name {}", tempFile.getName(), e);
} catch (final IOException e) { } catch (final IOException e) {
@@ -248,6 +221,37 @@ public class BulkUploadHandler extends CustomComponent
} }
private void readFileStream(final InputStream tempStream) {
String line;
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(tempStream, Charset.defaultCharset()))) {
LOG.info("Bulk file upload started");
long innerCounter = 0;
final double totalFileSize = getTotalNumberOfLines();
/**
* Once control is in upload succeeded method automatically
* upload button is re-enabled. To disable the button firing
* below event.
*/
eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.BULK_UPLOAD_PROCESS_STARTED));
while ((line = reader.readLine()) != null) {
innerCounter++;
readEachLine(line, innerCounter, totalFileSize);
}
doAssignments();
eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.BULK_UPLOAD_COMPLETED));
// Clearing after assignments are done
managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated().clear();
} catch (final IOException e) {
LOG.error("Error reading file {}", tempFile.getName(), e);
} finally {
resetCounts();
deleteFile();
}
}
private void doAssignments() { private void doAssignments() {
final StringBuilder errorMessage = new StringBuilder(); final StringBuilder errorMessage = new StringBuilder();
String dsAssignmentFailedMsg = null; String dsAssignmentFailedMsg = null;