From 97b3313642aeaa79f5871d0124ff5c473b129b84 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Tue, 27 Sep 2016 09:43:46 +0200 Subject: [PATCH] Fixed Sonar issues Signed-off-by: kaizimmerm --- .../rest/api/DdiRootControllerRestApi.java | 20 ++++++++++++++++++- .../resource/DdiArtifactStoreController.java | 2 +- .../ddi/rest/resource/DdiRootController.java | 8 ++++++++ .../amqp/AmqpDeadletterProperties.java | 3 ++- .../eclipse/hawkbit/amqp/AmqpProperties.java | 20 ++++++++++++++----- .../resource/MgmtSoftwareModuleResource.java | 5 +++++ .../src/test/resources/logback-spring.xml | 2 +- .../upload/UploadConfirmationWindow.java | 6 +++++- .../ui/artifacts/upload/UploadLayout.java | 7 ++++++- .../dstable/DistributionSetDetails.java | 8 +++++--- .../CreateOrUpdateFilterHeader.java | 8 ++++++-- .../management/dstable/DistributionTable.java | 6 +++++- 12 files changed, 78 insertions(+), 17 deletions(-) diff --git a/hawkbit-ddi-api/src/main/java/org/eclipse/hawkbit/ddi/rest/api/DdiRootControllerRestApi.java b/hawkbit-ddi-api/src/main/java/org/eclipse/hawkbit/ddi/rest/api/DdiRootControllerRestApi.java index f67e0591b..c33a07d60 100644 --- a/hawkbit-ddi-api/src/main/java/org/eclipse/hawkbit/ddi/rest/api/DdiRootControllerRestApi.java +++ b/hawkbit-ddi-api/src/main/java/org/eclipse/hawkbit/ddi/rest/api/DdiRootControllerRestApi.java @@ -37,7 +37,9 @@ public interface DdiRootControllerRestApi { /** * Returns all artifacts of a given software module and target. - * + * + * @param tenant + * of the request * @param targetid * of the target that matches to controller id * @param softwareModuleId @@ -53,6 +55,8 @@ public interface DdiRootControllerRestApi { /** * Root resource for an individual {@link Target}. * + * @param tenant + * of the request * @param targetid * of the target that matches to controller id * @param request @@ -68,6 +72,8 @@ public interface DdiRootControllerRestApi { * Handles GET {@link DdiArtifact} download request. This could be full or * partial (as specified by RFC7233 (Range Requests)) download request. * + * @param tenant + * of the request * @param targetid * of the related target * @param softwareModuleId @@ -92,6 +98,8 @@ public interface DdiRootControllerRestApi { /** * Handles GET {@link DdiArtifact} MD5 checksum file download request. * + * @param tenant + * of the request * @param targetid * of the related target * @param softwareModuleId @@ -116,6 +124,8 @@ public interface DdiRootControllerRestApi { /** * Resource for software module. * + * @param tenant + * of the request * @param targetid * of the target that matches to controller id * @param actionId @@ -139,6 +149,8 @@ public interface DdiRootControllerRestApi { /** * This is the feedback channel for the {@link DdiDeploymentBase} action. * + * @param tenant + * of the request * @param feedback * to provide * @param targetid @@ -159,6 +171,8 @@ public interface DdiRootControllerRestApi { /** * This is the feedback channel for the config data action. * + * @param tenant + * of the request * @param configData * as body * @param targetid @@ -176,6 +190,8 @@ public interface DdiRootControllerRestApi { /** * RequestMethod.GET method for the {@link DdiCancel} action. * + * @param tenant + * of the request * @param targetid * ID of the calling target * @param actionId @@ -195,6 +211,8 @@ public interface DdiRootControllerRestApi { * RequestMethod.POST method receiving the {@link DdiActionFeedback} from * the target. * + * @param tenant + * of the request * @param feedback * the {@link DdiActionFeedback} from the target. * @param targetid diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java index 3feb3068f..d3f57a7f7 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java @@ -35,7 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.WebApplicationContext; diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java index 33d7daf69..5e5c0d7c5 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java @@ -151,7 +151,12 @@ public class DdiRootController implements DdiRootControllerRestApi { LOG.warn("Softare module with id {} could not be found.", softwareModuleId); result = new ResponseEntity<>(HttpStatus.NOT_FOUND); } else { + + // Exception squid:S3655 - Optional access is checked in checkModule + // subroutine + @SuppressWarnings("squid:S3655") final LocalArtifact artifact = module.getLocalArtifactByFilename(fileName).get(); + final DbArtifact file = artifactManagement.loadLocalArtifactBinary(artifact); final String ifMatch = requestResponseContextHolder.getHttpServletRequest().getHeader("If-Match"); @@ -196,6 +201,9 @@ public class DdiRootController implements DdiRootControllerRestApi { } @Override + // Exception squid:S3655 - Optional access is checked in checkModule + // subroutine + @SuppressWarnings("squid:S3655") public ResponseEntity downloadArtifactMd5(@PathVariable("tenant") final String tenant, @PathVariable("targetid") final String targetid, @PathVariable("softwareModuleId") final Long softwareModuleId, diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpDeadletterProperties.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpDeadletterProperties.java index 723caf44c..5a7e3e083 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpDeadletterProperties.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpDeadletterProperties.java @@ -22,12 +22,13 @@ import com.google.common.collect.Maps; */ @ConfigurationProperties("hawkbit.dmf.rabbitmq.deadLetter") public class AmqpDeadletterProperties { + private static final int THREE_WEEKS = 21; /** * Message time to live (ttl) for the deadletter queue. Default ttl is 3 * weeks. */ - private long ttl = Duration.ofDays(21).toMillis(); + private long ttl = Duration.ofDays(THREE_WEEKS).toMillis(); /** * Return the deadletter arguments. diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpProperties.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpProperties.java index b90f8ca46..dd80262a5 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpProperties.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpProperties.java @@ -20,6 +20,16 @@ import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties("hawkbit.dmf.rabbitmq") public class AmqpProperties { + private static final int ONE_MINUTE = 60; + + private static final int DEFAULT_QUEUE_DECLARATION_RETRIES = 50; + + private static final int DEFAULT_INITIAL_CONSUMERS = 3; + + private static final int DEFAULT_PREFETCH_COUNT = 10; + + private static final int DEFAULT_MAX_CONSUMERS = 10; + /** * Enable DMF API based on AMQP 0.9 */ @@ -54,24 +64,24 @@ public class AmqpProperties { /** * Requested heartbeat interval from broker in {@link TimeUnit#SECONDS}. */ - private int requestedHeartBeat = (int) TimeUnit.SECONDS.toSeconds(60); + private int requestedHeartBeat = (int) TimeUnit.SECONDS.toSeconds(ONE_MINUTE); /** * Sets an upper limit to the number of consumers. */ - private int maxConcurrentConsumers = 10; + private int maxConcurrentConsumers = DEFAULT_MAX_CONSUMERS; /** * Tells the broker how many messages to send to each consumer in a single * request. Often this can be set quite high to improve throughput. */ - private int prefetchCount = 10; + private int prefetchCount = DEFAULT_PREFETCH_COUNT; /** * Initial number of consumers. Is scaled up if necessary up to * {@link #maxConcurrentConsumers}. */ - private int initialConcurrentConsumers = 3; + private int initialConcurrentConsumers = DEFAULT_INITIAL_CONSUMERS; /** * The number of retry attempts when passive queue declaration fails. @@ -79,7 +89,7 @@ public class AmqpProperties { * consuming from multiple queues, when not all queues were available during * initialization. */ - private int declarationRetries = 50; + private int declarationRetries = DEFAULT_QUEUE_DECLARATION_RETRIES; public int getDeclarationRetries() { return declarationRetries; diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java index ae099dcf6..1706a8030 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java @@ -107,10 +107,15 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { @Override @ResponseBody + // Exception squid:S3655 - Optional access is checked in + // findSoftwareModuleWithExceptionIfNotFound + // subroutine + @SuppressWarnings("squid:S3655") public ResponseEntity getArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("artifactId") final Long artifactId) { final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId); + return ResponseEntity.ok(toResponse(module.getLocalArtifact(artifactId).get())); } diff --git a/hawkbit-mgmt-resource/src/test/resources/logback-spring.xml b/hawkbit-mgmt-resource/src/test/resources/logback-spring.xml index 6dd6c94e0..39f7e6bbf 100644 --- a/hawkbit-mgmt-resource/src/test/resources/logback-spring.xml +++ b/hawkbit-mgmt-resource/src/test/resources/logback-spring.xml @@ -23,7 +23,7 @@ - + diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationWindow.java index 098ebb2c4..c71a58367 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationWindow.java @@ -32,11 +32,11 @@ import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleTiny; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; +import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -572,6 +572,9 @@ public class UploadConfirmationWindow implements Button.ClickListener { } + // Exception squid:S3655 - Optional access is checked in + // checkIfArtifactDetailsDispalyed subroutine + @SuppressWarnings("squid:S3655") private void processArtifactUpload() { final List itemIds = (List) uploadDetailsTable.getItemIds(); if (preUploadValidation(itemIds)) { @@ -593,6 +596,7 @@ public class UploadConfirmationWindow implements Button.ClickListener { } refreshArtifactDetailsLayout = checkIfArtifactDetailsDispalyed(bSoftwareModule.getId()); } + if (refreshArtifactDetailsLayout) { uploadLayout.refreshArtifactDetailsLayout(artifactUploadState.getSelectedBaseSoftwareModule().get()); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index e887cf020..92f6a1f36 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -34,10 +34,10 @@ import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmall; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.UINotification; import org.eclipse.hawkbit.util.SPInfo; import org.slf4j.Logger; @@ -254,6 +254,11 @@ 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 + + if (!artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) { + return; + } + final SoftwareModule selectedSw = artifactUploadState.getSelectedBaseSoftwareModule().get(); // reset the flag hasDirectory = Boolean.FALSE; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java index 0b1fb5af2..b6f90e7ac 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java @@ -173,9 +173,11 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet } private Button assignSoftModuleButton(final String softwareModuleName) { - if (getPermissionChecker().hasUpdateDistributionPermission() && distributionSetManagement - .findDistributionSetById(manageDistUIState.getLastSelectedDistribution().get().getId()) - .getAssignedTargets().isEmpty()) { + if (getPermissionChecker().hasUpdateDistributionPermission() + && manageDistUIState.getLastSelectedDistribution().isPresent() + && distributionSetManagement + .findDistributionSetById(manageDistUIState.getLastSelectedDistribution().get().getId()) + .getAssignedTargets().isEmpty()) { final Button reassignSoftModule = SPUIComponentProvider.getButton(softwareModuleName, "", "", "", true, FontAwesome.TIMES, SPUIButtonStyleSmallNoBorder.class); reassignSoftModule.setEnabled(false); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java index 14e46cdf1..46b43dc5b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java @@ -26,9 +26,9 @@ import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.filtermanagement.event.CustomFilterUIEvent; import org.eclipse.hawkbit.ui.filtermanagement.state.FilterManagementUIState; import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.UINotification; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -136,7 +136,7 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button private LayoutClickListener nameLayoutClickListner; - private boolean validationFailed = false; + private boolean validationFailed; /** * Initialize the Campaign Status History Header. @@ -509,6 +509,10 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button } private void updateCustomFilter() { + if (!filterManagementUIState.getTfQuery().isPresent()) { + return; + } + final TargetFilterQuery targetFilterQuery = filterManagementUIState.getTfQuery().get(); targetFilterQuery.setName(nameTextField.getValue()); targetFilterQuery.setQuery(queryTextField.getValue()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index 749ed772c..728e1036b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -42,11 +42,11 @@ import org.eclipse.hawkbit.ui.management.event.PinUnpinEvent; import org.eclipse.hawkbit.ui.management.event.SaveActionWindowEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.TableColumn; +import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.UINotification; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; @@ -525,6 +525,10 @@ public class DistributionTable extends AbstractNamedVersionTable