Fix sonar issue

Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
SirWayne
2016-08-05 15:55:49 +02:00
parent c71cf4852a
commit 5f20066cff
9 changed files with 121 additions and 67 deletions

View File

@@ -248,7 +248,7 @@ public class UploadLayout extends VerticalLayout {
final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles();
// selected software module at the time of file drop is
// considered for upload
SoftwareModule selectedSw = artifactUploadState.getSelectedBaseSoftwareModule().get();
final SoftwareModule selectedSw = artifactUploadState.getSelectedBaseSoftwareModule().get();
// reset the flag
hasDirectory = Boolean.FALSE;
for (final Html5File file : files) {
@@ -265,7 +265,7 @@ public class UploadLayout extends VerticalLayout {
}
}
private void processFile(final Html5File file, SoftwareModule selectedSw) {
private void processFile(final Html5File file, final SoftwareModule selectedSw) {
if (!isDirectory(file)) {
if (!checkForDuplicate(file.getFileName(), selectedSw)) {
artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet();
@@ -276,7 +276,7 @@ public class UploadLayout extends VerticalLayout {
}
}
private StreamVariable createStreamVariable(final Html5File file, SoftwareModule selectedSw) {
private StreamVariable createStreamVariable(final Html5File file, final SoftwareModule selectedSw) {
return new UploadHandler(file.getFileName(), file.getFileSize(), UploadLayout.this,
spInfo.getMaxArtifactFileSize(), null, file.getType(), selectedSw);
}
@@ -366,11 +366,13 @@ public class UploadLayout extends VerticalLayout {
* in case of upload errors
*/
OutputStream saveUploadedFileDetails(final String name, final long size, final String mimeType,
SoftwareModule selectedSw) {
final SoftwareModule selectedSw) {
File tempFile = null;
try {
tempFile = File.createTempFile("spUiArtifactUpload", null);
// we return the outputstream so we cannot close it here
@SuppressWarnings("squid:S2095")
final OutputStream out = new FileOutputStream(tempFile);
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(selectedSw.getName(),
@@ -445,8 +447,8 @@ public class UploadLayout extends VerticalLayout {
*/
public Boolean checkIfFileIsDuplicate(final String name, final SoftwareModule selectedSoftwareModule) {
Boolean isDuplicate = false;
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(
selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion());
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil
.getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion());
for (final CustomFile customFile : artifactUploadState.getFileSelected()) {
final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(
@@ -510,9 +512,9 @@ public class UploadLayout extends VerticalLayout {
artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet();
}
void updateFileSize(final String name, final long size, SoftwareModule selectedSoftwareModule) {
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(
selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion());
void updateFileSize(final String name, final long size, final SoftwareModule selectedSoftwareModule) {
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil
.getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion());
for (final CustomFile customFile : artifactUploadState.getFileSelected()) {
final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(
@@ -594,12 +596,12 @@ public class UploadLayout extends VerticalLayout {
private void setConfirmationPopupHeightWidth(final float newWidth, final float newHeight) {
if (currentUploadConfirmationwindow != null) {
currentUploadConfirmationwindow.getUploadArtifactDetails().setWidth(
HawkbitCommonUtil.getArtifactUploadPopupWidth(newWidth,
SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), Unit.PIXELS);
currentUploadConfirmationwindow.getUploadDetailsTable().setHeight(
HawkbitCommonUtil.getArtifactUploadPopupHeight(newHeight,
SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), Unit.PIXELS);
currentUploadConfirmationwindow.getUploadArtifactDetails().setWidth(HawkbitCommonUtil
.getArtifactUploadPopupWidth(newWidth, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH),
Unit.PIXELS);
currentUploadConfirmationwindow.getUploadDetailsTable().setHeight(HawkbitCommonUtil
.getArtifactUploadPopupHeight(newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT),
Unit.PIXELS);
}
}
@@ -616,12 +618,10 @@ public class UploadLayout extends VerticalLayout {
&& currentUploadConfirmationwindow.getCurrentUploadResultWindow() != null) {
final UploadResultWindow uploadResultWindow = currentUploadConfirmationwindow
.getCurrentUploadResultWindow();
uploadResultWindow.getUploadResultsWindow().setWidth(
HawkbitCommonUtil.getArtifactUploadPopupWidth(newWidth,
SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), Unit.PIXELS);
uploadResultWindow.getUploadResultTable().setHeight(
HawkbitCommonUtil.getArtifactUploadPopupHeight(newHeight,
SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), Unit.PIXELS);
uploadResultWindow.getUploadResultsWindow().setWidth(HawkbitCommonUtil.getArtifactUploadPopupWidth(newWidth,
SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), Unit.PIXELS);
uploadResultWindow.getUploadResultTable().setHeight(HawkbitCommonUtil.getArtifactUploadPopupHeight(
newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), Unit.PIXELS);
}
}
@@ -632,8 +632,8 @@ public class UploadLayout extends VerticalLayout {
} else {
currentUploadConfirmationwindow = new UploadConfirmationwindow(this, artifactUploadState);
UI.getCurrent().addWindow(currentUploadConfirmationwindow.getUploadConfrimationWindow());
setConfirmationPopupHeightWidth(Page.getCurrent().getBrowserWindowWidth(), Page.getCurrent()
.getBrowserWindowHeight());
setConfirmationPopupHeightWidth(Page.getCurrent().getBrowserWindowWidth(),
Page.getCurrent().getBrowserWindowHeight());
}
}
}
@@ -682,7 +682,7 @@ public class UploadLayout extends VerticalLayout {
displayDuplicateValidationMessage();
}
private void onUploadStreamingFailure(UploadStatusEvent event) {
private void onUploadStreamingFailure(final UploadStatusEvent event) {
/**
* If upload interrupted because of duplicate file,do not remove the
* file already in upload list
@@ -691,13 +691,13 @@ public class UploadLayout extends VerticalLayout {
|| !getDuplicateFileNamesList().contains(event.getUploadStatus().getFileName())) {
final SoftwareModule sw = event.getUploadStatus().getSoftwareModule();
if (sw != null) {
getFileSelected().remove(
new CustomFile(event.getUploadStatus().getFileName(), sw.getName(), sw.getVersion()));
getFileSelected()
.remove(new CustomFile(event.getUploadStatus().getFileName(), sw.getName(), sw.getVersion()));
}
// failed reason to be updated only if there is error other than
// duplicate file error
uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus()
.getFailureReason(), event.getUploadStatus().getSoftwareModule());
uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(),
event.getUploadStatus().getFailureReason(), event.getUploadStatus().getSoftwareModule());
increaseNumberOfFileUploadsFailed();
}
decreaseNumberOfFileUploadsExpected();
@@ -711,9 +711,9 @@ public class UploadLayout extends VerticalLayout {
displayDuplicateValidationMessage();
}
private void onUploadSuccess(UploadStatusEvent event) {
updateFileSize(event.getUploadStatus().getFileName(), event.getUploadStatus().getContentLength(), event
.getUploadStatus().getSoftwareModule());
private void onUploadSuccess(final UploadStatusEvent event) {
updateFileSize(event.getUploadStatus().getFileName(), event.getUploadStatus().getContentLength(),
event.getUploadStatus().getSoftwareModule());
// recorded that we now one more uploaded
increaseNumberOfFilesActuallyUpload();
}
@@ -730,8 +730,8 @@ public class UploadLayout extends VerticalLayout {
}
private boolean isUploadComplete() {
int uploadedCount = artifactUploadState.getNumberOfFilesActuallyUpload().intValue();
int expectedUploadsCount = artifactUploadState.getNumberOfFileUploadsExpected().intValue();
final int uploadedCount = artifactUploadState.getNumberOfFilesActuallyUpload().intValue();
final int expectedUploadsCount = artifactUploadState.getNumberOfFileUploadsExpected().intValue();
return uploadedCount == expectedUploadsCount;
}
@@ -744,13 +744,13 @@ public class UploadLayout extends VerticalLayout {
|| !getDuplicateFileNamesList().contains(event.getUploadStatus().getFileName())) {
final SoftwareModule sw = event.getUploadStatus().getSoftwareModule();
if (sw != null) {
getFileSelected().remove(
new CustomFile(event.getUploadStatus().getFileName(), sw.getName(), sw.getVersion()));
getFileSelected()
.remove(new CustomFile(event.getUploadStatus().getFileName(), sw.getName(), sw.getVersion()));
}
// failed reason to be updated only if there is error other than
// duplicate file error
uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus()
.getFailureReason(), event.getUploadStatus().getSoftwareModule());
uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(),
event.getUploadStatus().getFailureReason(), event.getUploadStatus().getSoftwareModule());
increaseNumberOfFileUploadsFailed();
decreaseNumberOfFileUploadsExpected();
}
@@ -773,8 +773,8 @@ public class UploadLayout extends VerticalLayout {
* @param selectedBaseSoftwareModule
*/
public void refreshArtifactDetailsLayout(final SoftwareModule selectedBaseSoftwareModule) {
eventBus.publish(this, new SoftwareModuleEvent(SoftwareModuleEventType.ARTIFACTS_CHANGED,
selectedBaseSoftwareModule));
eventBus.publish(this,
new SoftwareModuleEvent(SoftwareModuleEventType.ARTIFACTS_CHANGED, selectedBaseSoftwareModule));
}
/**
@@ -804,10 +804,10 @@ public class UploadLayout extends VerticalLayout {
}
void updateStatusButtonCount() {
int uploadsPending = artifactUploadState.getNumberOfFileUploadsExpected().get()
final int uploadsPending = artifactUploadState.getNumberOfFileUploadsExpected().get()
- artifactUploadState.getNumberOfFilesActuallyUpload().get();
int uploadsFailed = artifactUploadState.getNumberOfFileUploadsFailed().get();
StringBuilder builder = new StringBuilder("");
final int uploadsFailed = artifactUploadState.getNumberOfFileUploadsFailed().get();
final StringBuilder builder = new StringBuilder("");
if (uploadsFailed != 0) {
if (uploadsPending != 0) {
builder.append("<div class='error-count error-count-color'>" + uploadsFailed + "</div>");

View File

@@ -14,7 +14,7 @@ import com.vaadin.shared.ui.colorpicker.Color;
* Provides color constants for the ColorPickerLayout
*
*/
public class ColorPickerConstants {
public final class ColorPickerConstants {
public static final String DEFAULT_COLOR = "rgb(44,151,32)";
public static final Color START_COLOR = new Color(0, 146, 58);

View File

@@ -20,7 +20,7 @@ import com.vaadin.ui.Slider.ValueOutOfBoundsException;
* Contains helper methods for the ColorPickerLayout to handle the ColorPicker
*
*/
public class ColorPickerHelper {
public final class ColorPickerHelper {
private static final Logger LOG = LoggerFactory.getLogger(ColorPickerHelper.class);
@@ -30,7 +30,9 @@ public class ColorPickerHelper {
/**
* Get color picked value as string.
*
*
* @param preview
* the color picker preview
* @return String of color picked value.
*/
public static String getColorPickedString(final SpColorPickerPreview preview) {
@@ -59,7 +61,7 @@ public class ColorPickerHelper {
final int green = Integer.parseInt(colors[1]);
final int blue = Integer.parseInt(colors[2]);
if (colors.length > 3) {
final int alpha = (int) (Double.parseDouble(colors[3]) * 255d);
final int alpha = (int) (Double.parseDouble(colors[3]) * 255D);
return new Color(red, green, blue, alpha);
}
return new Color(red, green, blue);

View File

@@ -24,7 +24,7 @@ import com.vaadin.ui.GridLayout;
* duration in the DurationField or he can configure using the global duration
* by changing the CheckBox.
*/
public class DurationConfigField extends GridLayout implements ConfigurationItem {
public final class DurationConfigField extends GridLayout implements ConfigurationItem {
private static final long serialVersionUID = 1L;
@@ -130,45 +130,96 @@ public class DurationConfigField extends GridLayout implements ConfigurationItem
configurationChangeListeners.add(listener);
}
/**
* Create a DurationConfigFieldBuilder.
*
* @return the builder
*/
public static DurationConfigFieldBuilder builder() {
return new DurationConfigFieldBuilder();
}
public static class DurationConfigFieldBuilder {
/**
* Builder for the calendar widget.
*
*/
public static final class DurationConfigFieldBuilder {
private final DurationConfigField field;
private Duration globalDuration = null;
private Duration tenantDuration = null;
private Duration globalDuration;
private Duration tenantDuration;
private DurationConfigFieldBuilder() {
field = new DurationConfigField();
};
}
/**
* set the checkbox tooltip.
*
* @param label
* the tooltip
* @return the builder
*/
public DurationConfigFieldBuilder checkBoxTooltip(final String label) {
field.setCheckBoxTooltip(label);
return this;
}
/**
* set the global duration.
*
* @param globalDuration
* the global duration
* @return the builder
*/
public DurationConfigFieldBuilder globalDuration(final Duration globalDuration) {
this.globalDuration = globalDuration;
return this;
}
/**
* set the caption.
*
* @param caption
* the caption
* @return the builder
*/
public DurationConfigFieldBuilder caption(final String caption) {
field.setCaption(caption);
return this;
}
/**
* set the range.
*
* @param minDuration
* min duration
* @param maxDuration
* max duration
* @return the builder
*/
public DurationConfigFieldBuilder range(final Duration minDuration, final Duration maxDuration) {
field.setAllowedRange(minDuration, maxDuration);
return this;
}
/**
* set the tenant duration.
*
* @param tenantDuration
* the duration
* @return the builder
*/
public DurationConfigFieldBuilder tenantDuration(final Duration tenantDuration) {
this.tenantDuration = tenantDuration;
return this;
}
/**
* Create the {@link DurationConfigField}.
*
* @return the {@link DurationConfigField}
*/
public DurationConfigField build() {
if (globalDuration == null) {
throw new IllegalStateException(
@@ -178,5 +229,5 @@ public class DurationConfigField extends GridLayout implements ConfigurationItem
field.init(globalDuration, tenantDuration);
return field;
}
};
}
}