diff --git a/README.md b/README.md
index bc00c5c8d..778391f32 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,12 @@
-Build: [](https://circleci.com/gh/eclipse/hawkbit)
-
# Eclipse.IoT hawkBit - Update Server
[hawkBit](https://projects.eclipse.org/projects/iot.hawkbit) is an domain independent back end solution for rolling out software updates to constrained edge devices as well as more powerful controllers and gateways connected to IP based networking infrastructure.
+Build: [](https://circleci.com/gh/eclipse/hawkbit)
+[](https://sonar.eu-gb.mybluemix.net)
+
# Documentation
see [hawkBit Wiki](https://github.com/eclipse/hawkbit/wiki)
diff --git a/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/MyUI.java b/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/MyUI.java
index 5ef632d10..964994317 100644
--- a/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/MyUI.java
+++ b/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/MyUI.java
@@ -8,6 +8,8 @@ package org.eclipse.hawkbit.app;
* http://www.eclipse.org/legal/epl-v10.html
*/
+import java.util.concurrent.ScheduledExecutorService;
+
import org.eclipse.hawkbit.ui.HawkbitUI;
import org.eclipse.hawkbit.ui.UIEventProvider;
import org.eclipse.hawkbit.ui.push.DelayedEventBusPushStrategy;
@@ -38,8 +40,8 @@ public class MyUI extends HawkbitUI {
private static final long serialVersionUID = 1L;
@Autowired
- public MyUI(final EventBus systemEventBus, final org.vaadin.spring.events.EventBus.SessionEventBus eventBus,
- final UIEventProvider provider) {
- super(new DelayedEventBusPushStrategy(eventBus, systemEventBus, provider));
+ public MyUI(final ScheduledExecutorService executorService, final EventBus systemEventBus,
+ final org.vaadin.spring.events.EventBus.SessionEventBus eventBus, final UIEventProvider provider) {
+ super(new DelayedEventBusPushStrategy(executorService, eventBus, systemEventBus, provider));
}
}
diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpConfiguration.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpConfiguration.java
index 5e9b3e049..6a8826c82 100644
--- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpConfiguration.java
+++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpConfiguration.java
@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.simulator.amqp;
import static org.eclipse.hawkbit.simulator.amqp.AmqpProperties.CONFIGURATION_PREFIX;
import java.time.Duration;
-import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
@@ -36,6 +35,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.retry.backoff.ExponentialBackOffPolicy;
import org.springframework.retry.support.RetryTemplate;
+import com.google.common.collect.Maps;
+
/**
* The spring AMQP configuration to use a AMQP for communication with SP update
* server.
@@ -200,13 +201,13 @@ public class AmqpConfiguration {
}
private Map getDeadLetterExchangeArgs() {
- final Map args = new HashMap<>();
+ final Map args = Maps.newHashMapWithExpectedSize(1);
args.put("x-dead-letter-exchange", amqpProperties.getDeadLetterExchange());
return args;
}
private static Map getTTLMaxArgs() {
- final Map args = new HashMap<>();
+ final Map args = Maps.newHashMapWithExpectedSize(2);
args.put("x-message-ttl", Duration.ofDays(1).toMillis());
args.put("x-max-length", 100_000);
return args;
diff --git a/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/MyUI.java b/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/MyUI.java
index e5bc7535d..0316b68e5 100644
--- a/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/MyUI.java
+++ b/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/MyUI.java
@@ -8,6 +8,8 @@
*/
package org.eclipse.hawkbit.app;
+import java.util.concurrent.ScheduledExecutorService;
+
import org.eclipse.hawkbit.ui.HawkbitUI;
import org.eclipse.hawkbit.ui.UIEventProvider;
import org.eclipse.hawkbit.ui.push.DelayedEventBusPushStrategy;
@@ -37,8 +39,8 @@ public class MyUI extends HawkbitUI {
private static final long serialVersionUID = 1L;
@Autowired
- public MyUI(final EventBus systemEventBus, final org.vaadin.spring.events.EventBus.SessionEventBus eventBus,
- final UIEventProvider provider) {
- super(new DelayedEventBusPushStrategy(eventBus, systemEventBus, provider));
+ public MyUI(final ScheduledExecutorService scheduledExecutorService, final EventBus systemEventBus,
+ final org.vaadin.spring.events.EventBus.SessionEventBus eventBus, final UIEventProvider provider) {
+ super(new DelayedEventBusPushStrategy(scheduledExecutorService, eventBus, systemEventBus, provider));
}
}
diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/url/PropertyHostnameResolverAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/url/PropertyHostnameResolverAutoConfiguration.java
index 0bd4a8240..83885ae08 100644
--- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/url/PropertyHostnameResolverAutoConfiguration.java
+++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/url/PropertyHostnameResolverAutoConfiguration.java
@@ -41,14 +41,11 @@ public class PropertyHostnameResolverAutoConfiguration {
@Bean
@ConditionalOnMissingBean(value = HostnameResolver.class)
public HostnameResolver hostnameResolver() {
- return new HostnameResolver() {
- @Override
- public URL resolveHostname() {
- try {
- return new URL(serverProperties.getUrl());
- } catch (final MalformedURLException e) {
- throw Throwables.propagate(e);
- }
+ return () -> {
+ try {
+ return new URL(serverProperties.getUrl());
+ } catch (final MalformedURLException e) {
+ throw Throwables.propagate(e);
}
};
}
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/DataConversionHelper.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java
index 55be6f58a..3a50ede61 100644
--- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java
+++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java
@@ -12,7 +12,6 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -73,16 +72,16 @@ public final class DataConversionHelper {
* of the target
* @param module
* the software module
+ * @param artifactUrlHandler
+ * for creating download URLs
* @return a list of artifacts or a empty list. Cannot be .
*/
public static List createArtifacts(final String targetid,
final org.eclipse.hawkbit.repository.model.SoftwareModule module,
final ArtifactUrlHandler artifactUrlHandler) {
- final List files = new ArrayList<>();
- module.getLocalArtifacts()
- .forEach(artifact -> files.add(createArtifact(targetid, artifactUrlHandler, artifact)));
- return files;
+ return module.getLocalArtifacts().stream()
+ .map(artifact -> createArtifact(targetid, artifactUrlHandler, artifact)).collect(Collectors.toList());
}
private static DdiArtifact createArtifact(final String targetid, final ArtifactUrlHandler artifactUrlHandler,
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/AmqpConfiguration.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java
index 09edd41d3..b8cbb8162 100644
--- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java
+++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java
@@ -9,7 +9,6 @@
package org.eclipse.hawkbit.amqp;
import java.time.Duration;
-import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
@@ -47,6 +46,8 @@ import org.springframework.retry.backoff.ExponentialBackOffPolicy;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.ErrorHandler;
+import com.google.common.collect.Maps;
+
/**
* Spring configuration for AMQP 0.9 based DMF communication for indirect device
* integration.
@@ -306,7 +307,7 @@ public class AmqpConfiguration {
}
private static Map getTTLMaxArgsAuthenticationQueue() {
- final Map args = new HashMap<>();
+ final Map args = Maps.newHashMapWithExpectedSize(2);
args.put("x-message-ttl", Duration.ofSeconds(30).toMillis());
args.put("x-max-length", 1_000);
return args;
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 7ed5e90c1..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
@@ -9,24 +9,26 @@
package org.eclipse.hawkbit.amqp;
import java.time.Duration;
-import java.util.HashMap;
import java.util.Map;
import org.springframework.amqp.core.Queue;
import org.springframework.boot.context.properties.ConfigurationProperties;
+import com.google.common.collect.Maps;
+
/**
* Bean which holds the necessary properties for configuring the AMQP deadletter
* queue.
*/
@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.
@@ -36,7 +38,7 @@ public class AmqpDeadletterProperties {
* @return map which holds the properties
*/
public Map getDeadLetterExchangeArgs(final String exchange) {
- final Map args = new HashMap<>();
+ final Map args = Maps.newHashMapWithExpectedSize(1);
args.put("x-dead-letter-exchange", exchange);
return args;
}
@@ -53,7 +55,7 @@ public class AmqpDeadletterProperties {
}
private Map getTTLArgs() {
- final Map args = new HashMap<>();
+ final Map args = Maps.newHashMapWithExpectedSize(1);
args.put("x-message-ttl", getTtl());
return args;
}
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/MgmtDistributionSetMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java
index 4a0f8d90e..acd088c85 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java
@@ -12,7 +12,10 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import java.util.List;
+import java.util.stream.Collectors;
import org.eclipse.hawkbit.mgmt.json.model.MgmtMetadata;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet;
@@ -34,10 +37,6 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule;
/**
* A mapper which maps repository model to RESTful model representation and
* back.
- *
- *
- *
- *
*/
public final class MgmtDistributionSetMapper {
private MgmtDistributionSetMapper() {
@@ -75,15 +74,13 @@ public final class MgmtDistributionSetMapper {
* to use for conversion
* @return converted list of {@link DistributionSet}s
*/
- static List dsFromRequest(final Iterable sets,
+ static List dsFromRequest(final Collection sets,
final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement,
final EntityFactory entityFactory) {
- final List mappedList = new ArrayList<>();
- for (final MgmtDistributionSetRequestBodyPost dsRest : sets) {
- mappedList.add(fromRequest(dsRest, softwareManagement, distributionSetManagement, entityFactory));
- }
- return mappedList;
+ return sets.stream()
+ .map(dsRest -> fromRequest(dsRest, softwareManagement, distributionSetManagement, entityFactory))
+ .collect(Collectors.toList());
}
@@ -139,15 +136,12 @@ public final class MgmtDistributionSetMapper {
*/
static List fromRequestDsMetadata(final DistributionSet ds,
final List metadata, final EntityFactory entityFactory) {
- final List mappedList = new ArrayList<>(metadata.size());
- for (final MgmtMetadata metadataRest : metadata) {
- if (metadataRest.getKey() == null) {
- throw new IllegalArgumentException("the key of the metadata must be present");
- }
- mappedList.add(
- entityFactory.generateDistributionSetMetadata(ds, metadataRest.getKey(), metadataRest.getValue()));
+ if (metadata == null) {
+ return Collections.emptyList();
}
- return mappedList;
+
+ return metadata.stream().map(metadataRest -> entityFactory.generateDistributionSetMetadata(ds,
+ metadataRest.getKey(), metadataRest.getValue())).collect(Collectors.toList());
}
/**
@@ -196,15 +190,12 @@ public final class MgmtDistributionSetMapper {
return result;
}
- static List toResponseDistributionSets(final Iterable sets) {
- final List response = new ArrayList<>();
- if (sets != null) {
-
- for (final DistributionSet set : sets) {
- response.add(toResponse(set));
- }
+ static List toResponseDistributionSets(final Collection sets) {
+ if (sets == null) {
+ return Collections.emptyList();
}
- return response;
+
+ return sets.stream().map(MgmtDistributionSetMapper::toResponse).collect(Collectors.toList());
}
static MgmtMetadata toResponseDsMetadata(final DistributionSetMetadata metadata) {
@@ -224,14 +215,10 @@ public final class MgmtDistributionSetMapper {
}
static List toResponseFromDsList(final List sets) {
- final List mappedList = new ArrayList<>();
- if (sets != null) {
- for (final DistributionSet set : sets) {
- final MgmtDistributionSet response = toResponse(set);
-
- mappedList.add(response);
- }
+ if (sets == null) {
+ return Collections.emptyList();
}
- return mappedList;
+
+ return sets.stream().map(MgmtDistributionSetMapper::toResponse).collect(Collectors.toList());
}
}
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java
index 721995d88..b49654460 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java
@@ -8,6 +8,7 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
+import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -123,7 +124,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
.runAsSystem(() -> this.systemManagement.getTenantMetadata().getDefaultDsType().getKey());
sets.stream().filter(ds -> ds.getType() == null).forEach(ds -> ds.setType(defaultDsKey));
- final Iterable createdDSets = this.distributionSetManagement
+ final Collection createdDSets = this.distributionSetManagement
.createDistributionSets(MgmtDistributionSetMapper.dsFromRequest(sets, this.softwareManagement,
this.distributionSetManagement, entityFactory));
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java
index 675fe9df0..33b81ab73 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java
@@ -11,8 +11,10 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
-import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import java.util.List;
+import java.util.stream.Collectors;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetType;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPost;
@@ -39,13 +41,13 @@ final class MgmtDistributionSetTypeMapper {
static List smFromRequest(final EntityFactory entityFactory,
final SoftwareManagement softwareManagement,
- final Iterable smTypesRest) {
- final List mappedList = new ArrayList<>();
-
- for (final MgmtDistributionSetTypeRequestBodyPost smRest : smTypesRest) {
- mappedList.add(fromRequest(entityFactory, softwareManagement, smRest));
+ final Collection smTypesRest) {
+ if (smTypesRest == null) {
+ return Collections.emptyList();
}
- return mappedList;
+
+ return smTypesRest.stream().map(smRest -> fromRequest(entityFactory, softwareManagement, smRest))
+ .collect(Collectors.toList());
}
static DistributionSetType fromRequest(final EntityFactory entityFactory,
@@ -91,19 +93,19 @@ final class MgmtDistributionSetTypeMapper {
}
static List toTypesResponse(final List types) {
- final List response = new ArrayList<>();
- for (final DistributionSetType dsType : types) {
- response.add(toResponse(dsType));
+ if (types == null) {
+ return Collections.emptyList();
}
- return response;
+
+ return types.stream().map(MgmtDistributionSetTypeMapper::toResponse).collect(Collectors.toList());
}
static List toListResponse(final List types) {
- final List response = new ArrayList<>();
- for (final DistributionSetType dsType : types) {
- response.add(toResponse(dsType));
+ if (types == null) {
+ return Collections.emptyList();
}
- return response;
+
+ return types.stream().map(MgmtDistributionSetTypeMapper::toResponse).collect(Collectors.toList());
}
static MgmtDistributionSetType toResponse(final DistributionSetType type) {
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java
index d69e4d8d4..fe62ff369 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java
@@ -8,6 +8,12 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
+import static org.eclipse.hawkbit.mgmt.rest.resource.MgmtDistributionSetTypeMapper.toResponse;
+import static org.eclipse.hawkbit.mgmt.rest.resource.MgmtDistributionSetTypeMapper.toTypesResponse;
+import static org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleTypeMapper.toResponse;
+import static org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleTypeMapper.toTypesResponse;
+import static org.springframework.http.HttpStatus.CREATED;
+
import java.util.List;
import org.eclipse.hawkbit.mgmt.json.model.MgmtId;
@@ -32,7 +38,6 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
-import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
@@ -42,8 +47,6 @@ import org.springframework.web.bind.annotation.RestController;
/**
* REST Resource handling for {@link SoftwareModule} and related
* {@link Artifact} CRUD operations.
- *
- *
*/
@RestController
public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeRestApi {
@@ -67,7 +70,6 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeDistributionSetTypeSortParam(sortParam);
-
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Slice findModuleTypessAll;
@@ -82,31 +84,32 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
final List rest = MgmtDistributionSetTypeMapper
.toListResponse(findModuleTypessAll.getContent());
- return new ResponseEntity<>(new PagedList<>(rest, countModulesAll), HttpStatus.OK);
+ return ResponseEntity.ok(new PagedList<>(rest, countModulesAll));
}
@Override
public ResponseEntity getDistributionSetType(
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId) {
- final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
- return new ResponseEntity<>(MgmtDistributionSetTypeMapper.toResponse(foundType), HttpStatus.OK);
+ final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
+ return ResponseEntity.ok(toResponse(foundType));
}
@Override
public ResponseEntity deleteDistributionSetType(
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId) {
- final DistributionSetType module = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
+ final DistributionSetType module = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
distributionSetManagement.deleteDistributionSetType(module);
- return new ResponseEntity<>(HttpStatus.OK);
+ return ResponseEntity.ok().build();
}
@Override
public ResponseEntity updateDistributionSetType(
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId,
@RequestBody final MgmtDistributionSetTypeRequestBodyPut restDistributionSetType) {
+
final DistributionSetType type = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
// only description can be modified
@@ -117,8 +120,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
final DistributionSetType updatedDistributionSetType = distributionSetManagement
.updateDistributionSetType(type);
- return new ResponseEntity<>(MgmtDistributionSetTypeMapper.toResponse(updatedDistributionSetType),
- HttpStatus.OK);
+ return ResponseEntity.ok(toResponse(updatedDistributionSetType));
}
@Override
@@ -128,16 +130,17 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
final List createdSoftwareModules = distributionSetManagement.createDistributionSetTypes(
MgmtDistributionSetTypeMapper.smFromRequest(entityFactory, softwareManagement, distributionSetTypes));
- return new ResponseEntity<>(MgmtDistributionSetTypeMapper.toTypesResponse(createdSoftwareModules),
- HttpStatus.CREATED);
+ return ResponseEntity.status(CREATED).body(toTypesResponse(createdSoftwareModules));
}
private DistributionSetType findDistributionSetTypeWithExceptionIfNotFound(final Long distributionSetTypeId) {
+
final DistributionSetType module = distributionSetManagement.findDistributionSetTypeById(distributionSetTypeId);
if (module == null) {
throw new EntityNotFoundException(
"DistributionSetType with Id {" + distributionSetTypeId + "} does not exist");
}
+
return module;
}
@@ -146,8 +149,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId) {
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
- return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toListResponse(foundType.getMandatoryModuleTypes()),
- HttpStatus.OK);
+ return ResponseEntity.ok(toTypesResponse(foundType.getMandatoryModuleTypes()));
}
@Override
@@ -156,7 +158,6 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
@PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) {
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
-
final SoftwareModuleType foundSmType = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
if (!foundType.containsMandatoryModuleType(foundSmType)) {
@@ -164,7 +165,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
"Software module with given ID is not part of this distribution set type!");
}
- return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toResponse(foundSmType), HttpStatus.OK);
+ return ResponseEntity.ok(toResponse(foundSmType));
}
@Override
@@ -173,7 +174,6 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
@PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) {
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
-
final SoftwareModuleType foundSmType = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
if (!foundType.containsOptionalModuleType(foundSmType)) {
@@ -181,7 +181,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
"Software module with given ID is not part of this distribution set type!");
}
- return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toResponse(foundSmType), HttpStatus.OK);
+ return ResponseEntity.ok(toResponse(foundSmType));
}
@Override
@@ -189,9 +189,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId) {
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
-
- return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toListResponse(foundType.getOptionalModuleTypes()),
- HttpStatus.OK);
+ return ResponseEntity.ok(toTypesResponse(foundType.getOptionalModuleTypes()));
}
@Override
@@ -200,7 +198,6 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
@PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) {
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
-
final SoftwareModuleType foundSmType = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
if (!foundType.containsMandatoryModuleType(foundSmType)) {
@@ -209,18 +206,17 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
}
foundType.removeModuleType(softwareModuleTypeId);
-
distributionSetManagement.updateDistributionSetType(foundType);
- return new ResponseEntity<>(HttpStatus.OK);
+ return ResponseEntity.ok().build();
}
@Override
public ResponseEntity removeOptionalModule(
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId,
@PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) {
- final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
+ final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
final SoftwareModuleType foundSmType = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
if (!foundType.containsOptionalModuleType(foundSmType)) {
@@ -229,10 +225,9 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
}
foundType.removeModuleType(softwareModuleTypeId);
-
distributionSetManagement.updateDistributionSetType(foundType);
- return new ResponseEntity<>(HttpStatus.OK);
+ return ResponseEntity.ok().build();
}
@Override
@@ -240,14 +235,11 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId, @RequestBody final MgmtId smtId) {
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
-
final SoftwareModuleType smType = findSoftwareModuleTypeWithExceptionIfNotFound(smtId.getId());
-
foundType.addMandatoryModuleType(smType);
-
distributionSetManagement.updateDistributionSetType(foundType);
- return new ResponseEntity<>(HttpStatus.OK);
+ return ResponseEntity.ok().build();
}
@Override
@@ -255,23 +247,22 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId, @RequestBody final MgmtId smtId) {
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
-
final SoftwareModuleType smType = findSoftwareModuleTypeWithExceptionIfNotFound(smtId.getId());
-
foundType.addOptionalModuleType(smType);
distributionSetManagement.updateDistributionSetType(foundType);
- return new ResponseEntity<>(HttpStatus.OK);
-
+ return ResponseEntity.ok().build();
}
private SoftwareModuleType findSoftwareModuleTypeWithExceptionIfNotFound(final Long softwareModuleTypeId) {
+
final SoftwareModuleType module = softwareManagement.findSoftwareModuleTypeById(softwareModuleTypeId);
if (module == null) {
throw new EntityNotFoundException(
"SoftwareModuleType with Id {" + softwareModuleTypeId + "} does not exist");
}
+
return module;
}
}
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java
index 7467a45b0..2a092851d 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java
@@ -11,8 +11,9 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import java.util.stream.Collectors;
import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutCondition.Condition;
import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutErrorAction.ErrorAction;
@@ -48,9 +49,11 @@ final class MgmtRolloutMapper {
}
static List toResponseRollout(final List rollouts) {
- final List result = new ArrayList<>(rollouts.size());
- rollouts.forEach(r -> result.add(toResponseRollout(r)));
- return result;
+ if (rollouts == null) {
+ return Collections.emptyList();
+ }
+
+ return rollouts.stream().map(MgmtRolloutMapper::toResponseRollout).collect(Collectors.toList());
}
static MgmtRolloutResponseBody toResponseRollout(final Rollout rollout) {
@@ -103,9 +106,11 @@ final class MgmtRolloutMapper {
}
static List toResponseRolloutGroup(final List rollouts) {
- final List result = new ArrayList<>(rollouts.size());
- rollouts.forEach(r -> result.add(toResponseRolloutGroup(r)));
- return result;
+ if (rollouts == null) {
+ return Collections.emptyList();
+ }
+
+ return rollouts.stream().map(MgmtRolloutMapper::toResponseRolloutGroup).collect(Collectors.toList());
}
static MgmtRolloutGroupResponseBody toResponseRolloutGroup(final RolloutGroup rolloutGroup) {
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java
index 3960fb3c2..2166a7e43 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java
@@ -11,8 +11,10 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
-import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import java.util.List;
+import java.util.stream.Collectors;
import org.eclipse.hawkbit.mgmt.json.model.MgmtMetadata;
import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact;
@@ -65,60 +67,46 @@ public final class MgmtSoftwareModuleMapper {
}
static List fromRequestSwMetadata(final EntityFactory entityFactory,
- final SoftwareModule sw, final List metadata) {
- final List mappedList = new ArrayList<>(metadata.size());
- for (final MgmtMetadata metadataRest : metadata) {
- if (metadataRest.getKey() == null) {
- throw new IllegalArgumentException("the key of the metadata must be present");
- }
- mappedList.add(
- entityFactory.generateSoftwareModuleMetadata(sw, metadataRest.getKey(), metadataRest.getValue()));
+ final SoftwareModule sw, final Collection metadata) {
+ if (metadata == null) {
+ return Collections.emptyList();
}
- return mappedList;
+
+ return metadata.stream().map(metadataRest -> entityFactory.generateSoftwareModuleMetadata(sw,
+ metadataRest.getKey(), metadataRest.getValue())).collect(Collectors.toList());
}
static List smFromRequest(final EntityFactory entityFactory,
- final Iterable smsRest, final SoftwareManagement softwareManagement) {
- final List mappedList = new ArrayList<>();
- for (final MgmtSoftwareModuleRequestBodyPost smRest : smsRest) {
- mappedList.add(fromRequest(entityFactory, smRest, softwareManagement));
+ final Collection smsRest, final SoftwareManagement softwareManagement) {
+ if (smsRest == null) {
+ return Collections.emptyList();
}
- return mappedList;
+
+ return smsRest.stream().map(smRest -> fromRequest(entityFactory, smRest, softwareManagement))
+ .collect(Collectors.toList());
}
/**
* Create response for sw modules.
*
- * @param baseSoftareModules
+ * @param softwareModules
* the modules
* @return the response
*/
- public static List toResponse(final List baseSoftareModules) {
- final List mappedList = new ArrayList<>();
- if (baseSoftareModules != null) {
- for (final SoftwareModule target : baseSoftareModules) {
- final MgmtSoftwareModule response = toResponse(target);
-
- mappedList.add(response);
- }
+ public static List toResponse(final Collection softwareModules) {
+ if (softwareModules == null) {
+ return Collections.emptyList();
}
- return mappedList;
+
+ return softwareModules.stream().map(MgmtSoftwareModuleMapper::toResponse).collect(Collectors.toList());
}
- static List toResponseSoftwareModules(final Iterable softwareModules) {
- final List response = new ArrayList<>();
- for (final SoftwareModule softwareModule : softwareModules) {
- response.add(toResponse(softwareModule));
+ static List toResponseSwMetadata(final Collection metadata) {
+ if (metadata == null) {
+ return Collections.emptyList();
}
- return response;
- }
- static List toResponseSwMetadata(final List metadata) {
- final List mappedList = new ArrayList<>(metadata.size());
- for (final SoftwareModuleMetadata distributionSetMetadata : metadata) {
- mappedList.add(toResponseSwMetadata(distributionSetMetadata));
- }
- return mappedList;
+ return metadata.stream().map(MgmtSoftwareModuleMapper::toResponseSwMetadata).collect(Collectors.toList());
}
static MgmtMetadata toResponseSwMetadata(final SoftwareModuleMetadata metadata) {
@@ -194,15 +182,11 @@ public final class MgmtSoftwareModuleMapper {
return artifactRest;
}
- static List artifactsToResponse(final List artifacts) {
- final List mappedList = new ArrayList<>();
-
- if (artifacts != null) {
- for (final Artifact artifact : artifacts) {
- final MgmtArtifact response = toResponse(artifact);
- mappedList.add(response);
- }
+ static List artifactsToResponse(final Collection artifacts) {
+ if (artifacts == null) {
+ return Collections.emptyList();
}
- return mappedList;
+
+ return artifacts.stream().map(MgmtSoftwareModuleMapper::toResponse).collect(Collectors.toList());
}
}
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 b475c473f..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
@@ -8,7 +8,15 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
+import static org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleMapper.artifactsToResponse;
+import static org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleMapper.toResponse;
+import static org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleMapper.toResponseSwMetadata;
+import static org.springframework.http.HttpStatus.BAD_REQUEST;
+import static org.springframework.http.HttpStatus.CREATED;
+import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
+
import java.io.IOException;
+import java.util.Collection;
import java.util.List;
import org.eclipse.hawkbit.mgmt.json.model.MgmtMetadata;
@@ -46,10 +54,10 @@ import org.springframework.web.multipart.MultipartFile;
/**
* REST Resource handling for {@link SoftwareModule} and related
* {@link Artifact} CRUD operations.
- *
*/
@RestController
public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
+
private static final Logger LOG = LoggerFactory.getLogger(MgmtSoftwareModuleResource.class);
@Autowired
@@ -69,7 +77,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
@RequestParam(value = "sha1sum", required = false) final String sha1Sum) {
if (file.isEmpty()) {
- return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
+ return new ResponseEntity<>(BAD_REQUEST);
}
String fileName = optionalFileName;
@@ -81,10 +89,10 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
final Artifact result = artifactManagement.createLocalArtifact(file.getInputStream(), softwareModuleId,
fileName, md5Sum == null ? null : md5Sum.toLowerCase(),
sha1Sum == null ? null : sha1Sum.toLowerCase(), false, file.getContentType());
- return new ResponseEntity<>(MgmtSoftwareModuleMapper.toResponse(result), HttpStatus.CREATED);
+ return ResponseEntity.status(CREATED).body(toResponse(result));
} catch (final IOException e) {
LOG.error("Failed to store artifact", e);
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ return new ResponseEntity<>(INTERNAL_SERVER_ERROR);
}
}
@@ -92,31 +100,34 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
@ResponseBody
public ResponseEntity> getArtifacts(
@PathVariable("softwareModuleId") final Long softwareModuleId) {
- final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
- return new ResponseEntity<>(MgmtSoftwareModuleMapper.artifactsToResponse(module.getArtifacts()), HttpStatus.OK);
+ final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
+ return ResponseEntity.ok(artifactsToResponse(module.getArtifacts()));
}
@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 new ResponseEntity<>(MgmtSoftwareModuleMapper.toResponse(module.getLocalArtifact(artifactId).get()),
- HttpStatus.OK);
+ return ResponseEntity.ok(toResponse(module.getLocalArtifact(artifactId).get()));
}
@Override
@ResponseBody
public ResponseEntity deleteArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId,
@PathVariable("artifactId") final Long artifactId) {
- findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
+ findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
artifactManagement.deleteLocalArtifact(artifactId);
- return new ResponseEntity<>(HttpStatus.OK);
-
+ return ResponseEntity.ok().build();
}
@Override
@@ -143,33 +154,34 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
}
final List rest = MgmtSoftwareModuleMapper.toResponse(findModulesAll.getContent());
- return new ResponseEntity<>(new PagedList<>(rest, countModulesAll), HttpStatus.OK);
+ return ResponseEntity.ok(new PagedList<>(rest, countModulesAll));
}
@Override
public ResponseEntity getSoftwareModule(
@PathVariable("softwareModuleId") final Long softwareModuleId) {
- final SoftwareModule findBaseSoftareModule = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
- return new ResponseEntity<>(MgmtSoftwareModuleMapper.toResponse(findBaseSoftareModule), HttpStatus.OK);
+ final SoftwareModule findBaseSoftareModule = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
+ return ResponseEntity.ok(toResponse(findBaseSoftareModule));
}
@Override
public ResponseEntity> createSoftwareModules(
@RequestBody final List softwareModules) {
+
LOG.debug("creating {} softwareModules", softwareModules.size());
- final Iterable createdSoftwareModules = softwareManagement.createSoftwareModule(
+ final Collection createdSoftwareModules = softwareManagement.createSoftwareModule(
MgmtSoftwareModuleMapper.smFromRequest(entityFactory, softwareModules, softwareManagement));
LOG.debug("{} softwareModules created, return status {}", softwareModules.size(), HttpStatus.CREATED);
- return new ResponseEntity<>(MgmtSoftwareModuleMapper.toResponseSoftwareModules(createdSoftwareModules),
- HttpStatus.CREATED);
+ return ResponseEntity.status(CREATED).body(toResponse(createdSoftwareModules));
}
@Override
public ResponseEntity updateSoftwareModule(
@PathVariable("softwareModuleId") final Long softwareModuleId,
@RequestBody final MgmtSoftwareModuleRequestBodyPut restSoftwareModule) {
+
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
// only description and vendor can be modified
@@ -181,16 +193,16 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
}
final SoftwareModule updateSoftwareModule = softwareManagement.updateSoftwareModule(module);
- return new ResponseEntity<>(MgmtSoftwareModuleMapper.toResponse(updateSoftwareModule), HttpStatus.OK);
+ return ResponseEntity.ok(toResponse(updateSoftwareModule));
}
@Override
public ResponseEntity deleteSoftwareModule(@PathVariable("softwareModuleId") final Long softwareModuleId) {
- final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
+ final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
softwareManagement.deleteSoftwareModule(module);
- return new ResponseEntity<>(HttpStatus.OK);
+ return ResponseEntity.ok().build();
}
@Override
@@ -218,34 +230,38 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
metaDataPage = softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(softwareModuleId, pageable);
}
- return new ResponseEntity<>(
- new PagedList<>(MgmtSoftwareModuleMapper.toResponseSwMetadata(metaDataPage.getContent()),
- metaDataPage.getTotalElements()),
- HttpStatus.OK);
+ return ResponseEntity
+ .ok(new PagedList<>(toResponseSwMetadata(metaDataPage.getContent()), metaDataPage.getTotalElements()));
}
@Override
public ResponseEntity getMetadataValue(@PathVariable("softwareModuleId") final Long softwareModuleId,
@PathVariable("metadataKey") final String metadataKey) {
+
final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
final SoftwareModuleMetadata findOne = softwareManagement.findSoftwareModuleMetadata(sw, metadataKey);
- return ResponseEntity. ok(MgmtSoftwareModuleMapper.toResponseSwMetadata(findOne));
+
+ return ResponseEntity.ok(toResponseSwMetadata(findOne));
}
@Override
public ResponseEntity updateMetadata(@PathVariable("softwareModuleId") final Long softwareModuleId,
@PathVariable("metadataKey") final String metadataKey, @RequestBody final MgmtMetadata metadata) {
+
final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
final SoftwareModuleMetadata updated = softwareManagement.updateSoftwareModuleMetadata(
entityFactory.generateSoftwareModuleMetadata(sw, metadataKey, metadata.getValue()));
- return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponseSwMetadata(updated));
+
+ return ResponseEntity.ok(toResponseSwMetadata(updated));
}
@Override
public ResponseEntity deleteMetadata(@PathVariable("softwareModuleId") final Long softwareModuleId,
@PathVariable("metadataKey") final String metadataKey) {
+
final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
softwareManagement.deleteSoftwareModuleMetadata(sw, metadataKey);
+
return ResponseEntity.ok().build();
}
@@ -253,24 +269,25 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
public ResponseEntity> createMetadata(
@PathVariable("softwareModuleId") final Long softwareModuleId,
@RequestBody final List metadataRest) {
- final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
+ final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
final List created = softwareManagement.createSoftwareModuleMetadata(
MgmtSoftwareModuleMapper.fromRequestSwMetadata(entityFactory, sw, metadataRest));
- return new ResponseEntity<>(MgmtSoftwareModuleMapper.toResponseSwMetadata(created), HttpStatus.CREATED);
-
+ return ResponseEntity.status(CREATED).body(toResponseSwMetadata(created));
}
private SoftwareModule findSoftwareModuleWithExceptionIfNotFound(final Long softwareModuleId,
final Long artifactId) {
+
final SoftwareModule module = softwareManagement.findSoftwareModuleById(softwareModuleId);
if (module == null) {
throw new EntityNotFoundException("SoftwareModule with Id {" + softwareModuleId + "} does not exist");
- } else if (artifactId != null && !module.getLocalArtifact(artifactId).isPresent()) {
+ }
+ if (artifactId != null && !module.getLocalArtifact(artifactId).isPresent()) {
throw new EntityNotFoundException("Artifact with Id {" + artifactId + "} does not exist");
}
+
return module;
}
-
}
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java
index 565af7eb8..e14ed27fa 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java
@@ -11,9 +11,10 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
-import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
+import java.util.stream.Collectors;
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleType;
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeRequestBodyPost;
@@ -25,9 +26,6 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
* A mapper which maps repository model to RESTful model representation and
* back.
*
- *
- *
- *
*/
final class MgmtSoftwareModuleTypeMapper {
@@ -37,13 +35,12 @@ final class MgmtSoftwareModuleTypeMapper {
}
static List smFromRequest(final EntityFactory entityFactory,
- final Iterable smTypesRest) {
- final List mappedList = new ArrayList<>();
-
- for (final MgmtSoftwareModuleTypeRequestBodyPost smRest : smTypesRest) {
- mappedList.add(fromRequest(entityFactory, smRest));
+ final Collection smTypesRest) {
+ if (smTypesRest == null) {
+ return Collections.emptyList();
}
- return mappedList;
+
+ return smTypesRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).collect(Collectors.toList());
}
static SoftwareModuleType fromRequest(final EntityFactory entityFactory,
@@ -57,20 +54,12 @@ final class MgmtSoftwareModuleTypeMapper {
return result;
}
- static List toTypesResponse(final List types) {
- final List response = new ArrayList<>();
- for (final SoftwareModuleType softwareModule : types) {
- response.add(toResponse(softwareModule));
+ static List toTypesResponse(final Collection types) {
+ if (types == null) {
+ return Collections.emptyList();
}
- return response;
- }
- static List toListResponse(final Collection types) {
- final List response = new ArrayList<>();
- for (final SoftwareModuleType softwareModule : types) {
- response.add(toResponse(softwareModule));
- }
- return response;
+ return types.stream().map(MgmtSoftwareModuleTypeMapper::toResponse).collect(Collectors.toList());
}
static MgmtSoftwareModuleType toResponse(final SoftwareModuleType type) {
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java
index 353cf16e5..762dd7c1c 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java
@@ -72,7 +72,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
}
final List rest = MgmtSoftwareModuleTypeMapper
- .toListResponse(findModuleTypessAll.getContent());
+ .toTypesResponse(findModuleTypessAll.getContent());
return new ResponseEntity<>(new PagedList<>(rest, countModulesAll), HttpStatus.OK);
}
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java
index a889edc35..014d0e9e3 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java
@@ -13,9 +13,11 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import java.net.URI;
import java.time.ZoneId;
-import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Date;
import java.util.List;
+import java.util.stream.Collectors;
import org.eclipse.hawkbit.mgmt.json.model.MgmtPollStatus;
import org.eclipse.hawkbit.mgmt.json.model.action.MgmtAction;
@@ -92,17 +94,17 @@ public final class MgmtTargetMapper {
* the targets
* @return the response
*/
- public static List toResponseWithLinksAndPollStatus(final Iterable targets) {
- final List mappedList = new ArrayList<>();
- if (targets != null) {
- for (final Target target : targets) {
- final MgmtTarget response = toResponse(target);
- addPollStatus(target, response);
- addTargetLinks(response);
- mappedList.add(response);
- }
+ public static List toResponseWithLinksAndPollStatus(final Collection targets) {
+ if (targets == null) {
+ return Collections.emptyList();
}
- return mappedList;
+
+ return targets.stream().map(target -> {
+ final MgmtTarget response = toResponse(target);
+ addPollStatus(target, response);
+ addTargetLinks(response);
+ return response;
+ }).collect(Collectors.toList());
}
/**
@@ -112,15 +114,12 @@ public final class MgmtTargetMapper {
* list of targets
* @return the response
*/
- public static List toResponse(final Iterable targets) {
- final List mappedList = new ArrayList<>();
- if (targets != null) {
- for (final Target target : targets) {
- final MgmtTarget response = toResponse(target);
- mappedList.add(response);
- }
+ public static List toResponse(final Collection targets) {
+ if (targets == null) {
+ return Collections.emptyList();
}
- return mappedList;
+
+ return targets.stream().map(MgmtTargetMapper::toResponse).collect(Collectors.toList());
}
/**
@@ -173,12 +172,13 @@ public final class MgmtTargetMapper {
}
static List fromRequest(final EntityFactory entityFactory,
- final Iterable targetsRest) {
- final List mappedList = new ArrayList<>();
- for (final MgmtTargetRequestBody targetRest : targetsRest) {
- mappedList.add(fromRequest(entityFactory, targetRest));
+ final Collection targetsRest) {
+ if (targetsRest == null) {
+ return Collections.emptyList();
}
- return mappedList;
+
+ return targetsRest.stream().map(targetRest -> fromRequest(entityFactory, targetRest))
+ .collect(Collectors.toList());
}
static Target fromRequest(final EntityFactory entityFactory, final MgmtTargetRequestBody targetRest) {
@@ -190,17 +190,12 @@ public final class MgmtTargetMapper {
return target;
}
- static List toActionStatusRestResponse(final List actionStatus) {
- final List mappedList = new ArrayList<>();
-
- if (actionStatus != null) {
- for (final ActionStatus status : actionStatus) {
- final MgmtActionStatus response = toResponse(status);
- mappedList.add(response);
- }
+ static List toActionStatusRestResponse(final Collection actionStatus) {
+ if (actionStatus == null) {
+ return Collections.emptyList();
}
- return mappedList;
+ return actionStatus.stream().map(MgmtTargetMapper::toResponse).collect(Collectors.toList());
}
static MgmtAction toResponse(final String targetId, final Action action, final boolean isActive) {
@@ -222,14 +217,13 @@ public final class MgmtTargetMapper {
return result;
}
- static List toResponse(final String targetId, final List actions) {
- final List mappedList = new ArrayList<>();
-
- for (final Action action : actions) {
- final MgmtAction response = toResponse(targetId, action, action.isActive());
- mappedList.add(response);
+ static List toResponse(final String targetId, final Collection actions) {
+ if (actions == null) {
+ return Collections.emptyList();
}
- return mappedList;
+
+ return actions.stream().map(action -> toResponse(targetId, action, action.isActive()))
+ .collect(Collectors.toList());
}
private static String getNameOfActionStatusType(final Action.Status type) {
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java
index 5ddb74314..d0d72be40 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
+import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -108,7 +109,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@Override
public ResponseEntity> createTargets(@RequestBody final List targets) {
LOG.debug("creating {} targets", targets.size());
- final Iterable createdTargets = this.targetManagement
+ final Collection createdTargets = this.targetManagement
.createTargets(MgmtTargetMapper.fromRequest(entityFactory, targets));
LOG.debug("{} targets created, return status {}", targets.size(), HttpStatus.CREATED);
return new ResponseEntity<>(MgmtTargetMapper.toResponse(createdTargets), HttpStatus.CREATED);
diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java
index 9d5b0d002..0dd90b35f 100644
--- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java
+++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java
@@ -494,9 +494,6 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
final SoftwareModuleType testSmType = softwareManagement.createSoftwareModuleType(
entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
- final List types = new ArrayList<>();
- types.add(testType);
-
// DST does not exist
mvc.perform(get("/rest/v1/distributionsettypes/12345678")).andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
@@ -554,9 +551,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
- final DistributionSetType missingName = entityFactory.generateDistributionSetType("test123", null, "Desc123");
- mvc.perform(post("/rest/v1/distributionsettypes")
- .content(JsonBuilder.distributionSetTypes(Lists.newArrayList(missingName)))
+ // Missing mandatory field name
+ mvc.perform(post("/rest/v1/distributionsettypes").content("[{\"description\":\"Desc123\",\"key\":\"test123\"}]")
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java
index f5c79fb6c..4f3e12b16 100644
--- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java
+++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java
@@ -438,8 +438,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
- final List modules = new ArrayList<>();
- modules.add(sm);
+ final List modules = Lists.newArrayList(sm);
// SM does not exist
mvc.perform(get("/rest/v1/softwaremodules/12345678")).andDo(MockMvcResultPrinter.print())
@@ -457,11 +456,10 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
- final SoftwareModule missingName = entityFactory.generateSoftwareModule(osType, null, "version 1", null, null);
- mvc.perform(
- post("/rest/v1/softwaremodules").content(JsonBuilder.softwareModules(Lists.newArrayList(missingName)))
- .contentType(MediaType.APPLICATION_JSON))
- .andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
+ mvc.perform(post("/rest/v1/softwaremodules")
+ .content("[{\"description\":\"Desc123\",\"key\":\"test123\", \"type\":\"os\"}]")
+ .contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
+ .andExpect(status().isBadRequest());
final SoftwareModule toLongName = entityFactory.generateSoftwareModule(osType,
RandomStringUtils.randomAscii(80), "version 1", null, null);
diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java
index 8c60815e3..8150eba54 100644
--- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java
+++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java
@@ -318,8 +318,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
- final List types = new ArrayList<>();
- types.add(testType);
+ final List types = Lists.newArrayList(testType);
// SM does not exist
mvc.perform(get("/rest/v1/softwaremoduletypes/12345678")).andDo(MockMvcResultPrinter.print())
@@ -337,9 +336,9 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
- final SoftwareModuleType missingName = entityFactory.generateSoftwareModuleType("test123", null, "Desc123", 5);
mvc.perform(post("/rest/v1/softwaremoduletypes")
- .content(JsonBuilder.softwareModuleTypes(Lists.newArrayList(missingName)))
+ .content(
+ "[{\"description\":\"Desc123\",\"id\":9223372036854775807,\"key\":\"test123\",\"maxAssignments\":5}]")
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
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-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java
index 87919729e..925351807 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java
@@ -11,6 +11,8 @@ package org.eclipse.hawkbit.repository;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
+import javax.validation.constraints.NotNull;
+
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.ActionStatus;
@@ -64,7 +66,7 @@ public interface EntityFactory {
*
* @return {@link ActionStatus} object
*/
- ActionStatus generateActionStatus(Action action, Status status, Long occurredAt);
+ ActionStatus generateActionStatus(@NotNull Action action, @NotNull Status status, Long occurredAt);
/**
* Generates an {@link ActionStatus} object without persisting it.
@@ -81,7 +83,7 @@ public interface EntityFactory {
*
* @return {@link ActionStatus} object
*/
- ActionStatus generateActionStatus(Action action, final Status status, Long occurredAt,
+ ActionStatus generateActionStatus(@NotNull Action action, @NotNull Status status, Long occurredAt,
final Collection messages);
/**
@@ -99,7 +101,8 @@ public interface EntityFactory {
*
* @return {@link ActionStatus} object
*/
- ActionStatus generateActionStatus(Action action, Status status, Long occurredAt, final String message);
+ ActionStatus generateActionStatus(@NotNull Action action, @NotNull Status status, Long occurredAt,
+ final String message);
/**
* Generates an empty {@link DistributionSet} without persisting it.
@@ -124,8 +127,8 @@ public interface EntityFactory {
*
* @return {@link DistributionSet} object
*/
- DistributionSet generateDistributionSet(String name, String version, String description, DistributionSetType type,
- Collection moduleList);
+ DistributionSet generateDistributionSet(@NotNull String name, @NotNull String version, String description,
+ @NotNull DistributionSetType type, Collection moduleList);
/**
* Generates an empty {@link DistributionSetMetadata} element without
@@ -148,7 +151,8 @@ public interface EntityFactory {
*
* @return {@link DistributionSetMetadata} object
*/
- DistributionSetMetadata generateDistributionSetMetadata(DistributionSet distributionSet, String key, String value);
+ DistributionSetMetadata generateDistributionSetMetadata(@NotNull DistributionSet distributionSet,
+ @NotNull String key, String value);
/**
* Generates an empty {@link DistributionSetTag} without persisting it.
@@ -164,7 +168,7 @@ public interface EntityFactory {
* of the tag
* @return {@link DistributionSetTag} object
*/
- DistributionSetTag generateDistributionSetTag(String name);
+ DistributionSetTag generateDistributionSetTag(@NotNull String name);
/**
* Generates a {@link DistributionSetTag} without persisting it.
@@ -177,7 +181,7 @@ public interface EntityFactory {
* of the tag
* @return {@link DistributionSetTag} object
*/
- DistributionSetTag generateDistributionSetTag(String name, String description, String colour);
+ DistributionSetTag generateDistributionSetTag(@NotNull String name, String description, String colour);
/**
* Generates an empty {@link DistributionSetType} without persisting it.
@@ -198,7 +202,7 @@ public interface EntityFactory {
*
* @return {@link DistributionSetType} object
*/
- DistributionSetType generateDistributionSetType(String key, String name, String description);
+ DistributionSetType generateDistributionSetType(@NotNull String key, @NotNull String name, String description);
/**
* Generates an empty {@link Rollout} without persisting it.
@@ -237,8 +241,8 @@ public interface EntityFactory {
*
* @return {@link SoftwareModule} object
*/
- SoftwareModule generateSoftwareModule(SoftwareModuleType type, String name, String version, String description,
- String vendor);
+ SoftwareModule generateSoftwareModule(@NotNull SoftwareModuleType type, @NotNull String name,
+ @NotNull String version, String description, String vendor);
/**
* Generates an empty {@link SoftwareModuleMetadata} pair without persisting
@@ -260,7 +264,8 @@ public interface EntityFactory {
*
* @return {@link SoftwareModuleMetadata} object
*/
- SoftwareModuleMetadata generateSoftwareModuleMetadata(SoftwareModule softwareModule, String key, String value);
+ SoftwareModuleMetadata generateSoftwareModuleMetadata(@NotNull SoftwareModule softwareModule, @NotNull String key,
+ String value);
/**
* Generates an empty {@link SoftwareModuleType} without persisting it.
@@ -283,7 +288,8 @@ public interface EntityFactory {
*
* @return {@link SoftwareModuleType} object
*/
- SoftwareModuleType generateSoftwareModuleType(String key, String name, String description, int maxAssignments);
+ SoftwareModuleType generateSoftwareModuleType(@NotNull String key, @NotNull String name, String description,
+ int maxAssignments);
/**
* Generates an empty {@link Target} without persisting it.
@@ -307,7 +313,7 @@ public interface EntityFactory {
*
* @return {@link Target} object
*/
- Target generateTarget(@NotEmpty String controllerID, @NotEmpty String securityToken);
+ Target generateTarget(@NotEmpty String controllerID, String securityToken);
/**
* Generates an empty {@link TargetFilterQuery} without persisting it.
@@ -330,7 +336,7 @@ public interface EntityFactory {
* of the tag
* @return {@link TargetTag} object
*/
- TargetTag generateTargetTag(String name);
+ TargetTag generateTargetTag(@NotNull String name);
/**
* Generates a {@link TargetTag} without persisting it.
@@ -343,7 +349,7 @@ public interface EntityFactory {
* of the tag
* @return {@link TargetTag} object
*/
- TargetTag generateTargetTag(String name, String description, String colour);
+ TargetTag generateTargetTag(@NotNull String name, String description, String colour);
/**
* Generates an empty {@link LocalArtifact} without persisting it.
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java
index e83108fe8..2b5daed2e 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java
@@ -47,10 +47,10 @@ public interface ActionStatus extends TenantAwareBaseEntity {
* @return current {@link Status#DOWNLOAD} progress if known by the update
* server.
*/
- int getDownloadProgressPercent();
+ short getDownloadProgressPercent();
/**
- * @return list of message entries that can be added to the
+ * @return immutable list of message entries that in the
* {@link ActionStatus}.
*/
List getMessages();
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java
index cc726839d..e0a142b43 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java
@@ -37,6 +37,6 @@ public interface Artifact extends TenantAwareBaseEntity {
/**
* @return size of the artifact in bytes.
*/
- Long getSize();
+ long getSize();
}
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java
index 2a9948bc5..c6717d021 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java
@@ -44,6 +44,6 @@ public interface BaseEntity extends Serializable, Identifiable {
/**
* @return version of the {@link BaseEntity}.
*/
- long getOptLockRevision();
+ int getOptLockRevision();
}
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java
index 5747b38f3..b0bff56cb 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java
@@ -26,10 +26,25 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement;
public interface DistributionSet extends NamedVersionedEntity {
/**
- * @return {@link Set} of assigned {@link DistributionSetTag}s.
+ * @return immutable {@link Set} of assigned {@link DistributionSetTag}s.
*/
Set getTags();
+ /**
+ * @param tag
+ * to add
+ * @return true if tag could be added sucessfully (i.e. was not
+ * already in the list).
+ */
+ boolean addTag(final DistributionSetTag tag);
+
+ /**
+ * @param tag
+ * to remove
+ * @return true if tag was in the list and removed
+ */
+ boolean removeTag(final DistributionSetTag tag);
+
/**
* @return true if the set is deleted and only kept for history
* purposes.
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java
index 05089d138..9507e29b2 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java
@@ -17,8 +17,8 @@ import java.util.List;
public interface DistributionSetTag extends Tag {
/**
- * @return {@link List} of {@link DistributionSet}s this {@link Tag} is
- * assigned to.
+ * @return immutable {@link List} of {@link DistributionSet}s this
+ * {@link Tag} is assigned to.
*/
List getAssignedToDistributionSet();
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java
index cf5da40b2..57420bbad 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java
@@ -27,15 +27,15 @@ public interface DistributionSetType extends NamedEntity {
boolean isDeleted();
/**
- * @return set of {@link SoftwareModuleType}s that need to be in a
+ * @return immutable set of {@link SoftwareModuleType}s that need to be in a
* {@link DistributionSet} of this type to be
* {@link DistributionSet#isComplete()}.
*/
Set getMandatoryModuleTypes();
/**
- * @return set of optional {@link SoftwareModuleType}s that can be in a
- * {@link DistributionSet} of this type.
+ * @return immutable set of optional {@link SoftwareModuleType}s that can be
+ * in a {@link DistributionSet} of this type.
*/
Set getOptionalModuleTypes();
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java
index 37185a8e2..72d7e7c53 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java
@@ -38,7 +38,7 @@ public interface Rollout extends NamedEntity {
void setDistributionSet(DistributionSet distributionSet);
/**
- * @return list of deployment groups of the rollout.
+ * @return immutable list of deployment groups of the rollout.
*/
List getRolloutGroups();
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java
index 3180fdb6a..286085eba 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java
@@ -155,7 +155,7 @@ public interface RolloutGroup extends NamedEntity {
/**
* @return the total amount of targets containing in this group
*/
- long getTotalTargets();
+ int getTotalTargets();
/**
* @return the totalTargetCountStatus
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java
index 3c3a24fd0..e3bf1468f 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java
@@ -11,6 +11,10 @@ package org.eclipse.hawkbit.repository.model;
import java.util.List;
import java.util.Optional;
+/**
+ * Software package as sub element of a {@link DistributionSet}.
+ *
+ */
public interface SoftwareModule extends NamedVersionedEntity {
/**
@@ -40,12 +44,12 @@ public interface SoftwareModule extends NamedVersionedEntity {
Optional getLocalArtifactByFilename(String fileName);
/**
- * @return the artifacts
+ * @return immutable list of all artifacts
*/
List getArtifacts();
/**
- * @return local artifacts only
+ * @return immutable list of local artifacts only
*/
List getLocalArtifacts();
@@ -104,7 +108,8 @@ public interface SoftwareModule extends NamedVersionedEntity {
List getMetadata();
/**
- * @return the assignedTo
+ * @return immutable list of {@link DistributionSet}s the module is assigned
+ * to
*/
List getAssignedTo();
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Target.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Target.java
index c09b28a2f..c07a8c224 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Target.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Target.java
@@ -32,12 +32,12 @@ public interface Target extends NamedEntity {
String getControllerId();
/**
- * @return assigned {@link TargetTag}s.
+ * @return immutable set of assigned {@link TargetTag}s.
*/
Set getTags();
/**
- * @return {@link Action} history of the {@link Target}.
+ * @return immutable {@link Action} history of the {@link Target}.
*/
List getActions();
@@ -64,4 +64,19 @@ public interface Target extends NamedEntity {
*/
void setSecurityToken(String token);
+ /**
+ * @param tag
+ * to add
+ * @return true if tag could be added sucessfully (i.e. was not
+ * already in the list).
+ */
+ public boolean addTag(TargetTag tag);
+
+ /**
+ * @param tag
+ * to remove
+ * @return true if tag was in the list and removed
+ */
+ public boolean removeTag(TargetTag tag);
+
}
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java
index 2eb2f05c7..76a975f75 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java
@@ -36,7 +36,8 @@ public interface TargetInfo extends Serializable {
/**
* @return time in {@link TimeUnit#MILLISECONDS} GMT when the {@link Target}
- * polled the server the last time.
+ * polled the server the last time or null if target
+ * has never queried yet.
*/
Long getLastTargetQuery();
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java
index f222e9e90..afe0ff59a 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java
@@ -17,7 +17,7 @@ import java.util.List;
public interface TargetTag extends Tag {
/**
- * @return {@link List} of targets assigned to this {@link Tag}.
+ * @return immutable {@link List} of targets assigned to this {@link Tag}.
*/
List getAssignedToTargets();
diff --git a/hawkbit-repository/hawkbit-repository-jpa/pom.xml b/hawkbit-repository/hawkbit-repository-jpa/pom.xml
index 3a66a0a9d..9f7a0bbb7 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/pom.xml
+++ b/hawkbit-repository/hawkbit-repository-jpa/pom.xml
@@ -89,6 +89,10 @@
cz.jirutka.rsql
rsql-parser
+
+ org.apache.commons
+ commons-collections4
+
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java
index e1297e94e..f09cae8f2 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java
@@ -8,7 +8,6 @@
*/
package org.eclipse.hawkbit;
-import java.util.HashMap;
import java.util.Map;
import org.eclipse.hawkbit.repository.ArtifactManagement;
@@ -73,6 +72,7 @@ import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
+import com.google.common.collect.Maps;
import com.google.common.eventbus.EventBus;
/**
@@ -197,7 +197,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
@Override
protected Map getVendorProperties() {
- final Map properties = new HashMap<>();
+ final Map properties = Maps.newHashMapWithExpectedSize(5);
// Turn off dynamic weaving to disable LTW lookup in static weaving mode
properties.put("eclipselink.weaving", "false");
// needed for reports
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java
index 8989a5a41..b39d760c3 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java
@@ -30,6 +30,7 @@ import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
+import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.EntityGraph.EntityGraphType;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
@@ -103,7 +104,7 @@ public interface ActionRepository extends BaseEntityRepository,
* @return the found {@link Action}
*/
@EntityGraph(value = "Action.ds", type = EntityGraphType.LOAD)
- Optional findFirstByTargetAndActiveOrderByIdAsc(final JpaTarget target, boolean active);
+ Optional findFirstByTargetAndActive(final Sort sort, final JpaTarget target, boolean active);
/**
* Retrieves latest {@link UpdateAction} for given target and
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java
index 41ad6f179..03ace2e1f 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java
@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.jpa;
import java.net.URI;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -54,6 +54,8 @@ import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.transaction.annotation.Isolation;
@@ -163,12 +165,15 @@ public class JpaControllerManagement implements ControllerManagement {
@Override
public Optional findOldestActiveActionByTarget(final Target target) {
- return actionRepository.findFirstByTargetAndActiveOrderByIdAsc((JpaTarget) target, true);
+ // used in favorite to findFirstByTargetAndActiveOrderByIdAsc due to
+ // DATAJPA-841 issue.
+ return actionRepository.findFirstByTargetAndActive(new Sort(Direction.ASC, "id"), (JpaTarget) target, true);
}
@Override
public List findSoftwareModulesByDistributionSet(final DistributionSet distributionSet) {
- return new ArrayList<>(softwareModuleRepository.findByAssignedTo((JpaDistributionSet) distributionSet));
+ return Collections
+ .unmodifiableList(softwareModuleRepository.findByAssignedTo((JpaDistributionSet) distributionSet));
}
@Override
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java
index 54d6dadc0..1a7655096 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java
@@ -597,7 +597,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
multiselect.where(cb.equal(actionRoot.get(JpaAction_.target), target));
multiselect.orderBy(cb.desc(actionRoot.get(JpaAction_.id)));
multiselect.groupBy(actionRoot.get(JpaAction_.id));
- return new ArrayList<>(entityManager.createQuery(multiselect).getResultList());
+ return Collections.unmodifiableList(entityManager.createQuery(multiselect).getResultList());
}
@Override
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java
index d1f9a68ef..7d719acbe 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java
@@ -15,7 +15,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
-import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@@ -68,6 +67,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
import com.google.common.eventbus.EventBus;
/**
@@ -130,26 +130,24 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
final DistributionSetTag myTag = tagManagement.findDistributionSetTag(tagName);
DistributionSetTagAssignmentResult result;
- final List toBeChangedDSs = new ArrayList<>();
- for (final JpaDistributionSet set : sets) {
- if (set.getTags().add(myTag)) {
- toBeChangedDSs.add(set);
- }
- }
+
+ final List toBeChangedDSs = sets.stream().filter(set -> set.addTag(myTag))
+ .collect(Collectors.toList());
// un-assignment case
if (toBeChangedDSs.isEmpty()) {
for (final JpaDistributionSet set : sets) {
- if (set.getTags().remove(myTag)) {
+ if (set.removeTag(myTag)) {
toBeChangedDSs.add(set);
}
}
result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), 0,
toBeChangedDSs.size(), Collections.emptyList(),
- new ArrayList<>(distributionSetRepository.save(toBeChangedDSs)), myTag);
+ Collections.unmodifiableList(distributionSetRepository.save(toBeChangedDSs)), myTag);
} else {
result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), toBeChangedDSs.size(),
- 0, new ArrayList<>(distributionSetRepository.save(toBeChangedDSs)), Collections.emptyList(), myTag);
+ 0, Collections.unmodifiableList(distributionSetRepository.save(toBeChangedDSs)),
+ Collections.emptyList(), myTag);
}
final DistributionSetTagAssignmentResult resultAssignment = result;
@@ -178,8 +176,6 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public void deleteDistributionSet(final Long... distributionSetIDs) {
- final List toHardDelete = new ArrayList<>();
-
final List assigned = distributionSetRepository
.findAssignedToTargetDistributionSetsById(distributionSetIDs);
assigned.addAll(distributionSetRepository.findAssignedToRolloutDistributionSetsById(distributionSetIDs));
@@ -190,13 +186,10 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
// mark the rest as hard delete
- for (final Long setId : distributionSetIDs) {
- if (!assigned.contains(setId)) {
- toHardDelete.add(setId);
- }
- }
+ final List toHardDelete = Arrays.stream(distributionSetIDs).filter(setId -> !assigned.contains(setId))
+ .collect(Collectors.toList());
- // hard delete the rest if exixts
+ // hard delete the rest if exists
if (!toHardDelete.isEmpty()) {
// don't give the delete statement an empty list, JPA/Oracle cannot
// handle the empty list
@@ -243,7 +236,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@SuppressWarnings({ "unchecked", "rawtypes" })
final Collection toSave = (Collection) distributionSets;
- return new ArrayList<>(distributionSetRepository.save(toSave));
+ return Collections.unmodifiableList(distributionSetRepository.save(toSave));
}
@Override
@@ -296,7 +289,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
private static Page convertDsTPage(final Page findAll) {
- return new PageImpl<>(new ArrayList<>(findAll.getContent()));
+ return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()));
}
@Override
@@ -314,7 +307,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
private static Page convertDsPage(final Page findAll,
final Pageable pageable) {
- return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements());
+ return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
/**
@@ -337,7 +330,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override
public Page findDistributionSetsByDeletedAndOrCompleted(final Pageable pageReq,
final Boolean deleted, final Boolean complete) {
- final List> specList = new ArrayList<>();
+ final List> specList = new ArrayList<>(2);
if (deleted != null) {
final Specification spec = DistributionSetSpecification.isDeleted(deleted);
@@ -359,11 +352,12 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
final Specification spec = RSQLUtility.parse(rsqlParam, DistributionSetFields.class,
virtualPropertyLookup);
- final List> specList = new ArrayList<>();
+ final List> specList = new ArrayList<>(2);
if (deleted != null) {
specList.add(DistributionSetSpecification.isDeleted(deleted));
}
specList.add(spec);
+
return convertDsPage(findByCriteriaAPI(pageReq, specList), pageReq);
}
@@ -388,7 +382,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
final Page findDistributionSetsByFilters = findDistributionSetsByFilters(pageable,
dsFilterWithNoTargetLinked);
- final List resultSet = new LinkedList<>(findDistributionSetsByFilters.getContent());
+ final List resultSet = new ArrayList<>(findDistributionSetsByFilters.getContent());
int orderIndex = 0;
if (installedDS != null) {
final boolean remove = resultSet.remove(installedDS);
@@ -419,18 +413,15 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override
public List findDistributionSetsAll(final Collection dist) {
- return new ArrayList<>(distributionSetRepository.findAll(DistributionSetSpecification.byIds(dist)));
+ return Collections
+ .unmodifiableList(distributionSetRepository.findAll(DistributionSetSpecification.byIds(dist)));
}
@Override
public Long countDistributionSetsAll() {
-
- final List> specList = new LinkedList<>();
-
final Specification spec = DistributionSetSpecification.isDeleted(Boolean.FALSE);
- specList.add(spec);
- return distributionSetRepository.count(SpecificationsBuilder.combineWithAnd(specList));
+ return distributionSetRepository.count(SpecificationsBuilder.combineWithAnd(Lists.newArrayList(spec)));
}
@Override
@@ -560,7 +551,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override
public List findDistributionSetMetadataByDistributionSetId(final Long distributionSetId) {
- return new ArrayList<>(distributionSetMetadataRepository
+ return Collections.unmodifiableList(distributionSetMetadataRepository
.findAll((Specification) (root, query, cb) -> cb.equal(
root.get(JpaDistributionSetMetadata_.distributionSet).get(JpaDistributionSet_.id),
distributionSetId)));
@@ -584,7 +575,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
private static Page convertMdPage(final Page findAll,
final Pageable pageable) {
- return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements());
+ return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
@Override
@@ -609,7 +600,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
private static List> buildDistributionSetSpecifications(
final DistributionSetFilter distributionSetFilter) {
- final List> specList = new ArrayList<>();
+ final List> specList = new ArrayList<>(7);
Specification spec;
@@ -710,9 +701,9 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
public List assignTag(final Collection dsIds, final DistributionSetTag tag) {
final List allDs = findDistributionSetListWithDetails(dsIds);
- allDs.forEach(ds -> ds.getTags().add(tag));
+ allDs.forEach(ds -> ds.addTag(tag));
- final List save = new ArrayList<>(distributionSetRepository.save(allDs));
+ final List save = Collections.unmodifiableList(distributionSetRepository.save(allDs));
afterCommit.afterCommit(() -> {
@@ -732,7 +723,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@SuppressWarnings({ "unchecked", "rawtypes" })
final Collection distributionSets = (Collection) tag.getAssignedToDistributionSet();
- return new ArrayList<>(unAssignTag(distributionSets, tag));
+ return Collections.unmodifiableList(unAssignTag(distributionSets, tag));
}
@Override
@@ -746,7 +737,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
private List unAssignTag(final Collection distributionSets,
final DistributionSetTag tag) {
- distributionSets.forEach(ds -> ds.getTags().remove(tag));
+ distributionSets.forEach(ds -> ds.removeTag(tag));
return distributionSetRepository.save(distributionSets);
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java
index 51b59f08f..1bc8063ec 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java
@@ -43,11 +43,13 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.eclipse.hawkbit.repository.model.TargetTag;
+import org.springframework.validation.annotation.Validated;
/**
* JPA Implementation of {@link EntityFactory}.
*
*/
+@Validated
public class JpaEntityFactory implements EntityFactory {
@Override
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java
index c977283dd..0453bf26b 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java
@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -85,11 +85,11 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
}
private static Page convertPage(final Page findAll, final Pageable pageable) {
- return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements());
+ return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
private static Page convertTPage(final Page findAll, final Pageable pageable) {
- return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements());
+ return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
@Override
@@ -119,7 +119,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
for (final RolloutGroup rolloutGroup : rolloutGroups) {
final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus(
- allStatesForRollout.get(rolloutGroup.getId()), rolloutGroup.getTotalTargets());
+ allStatesForRollout.get(rolloutGroup.getId()), Long.valueOf(rolloutGroup.getTotalTargets()));
rolloutGroup.setTotalTargetCountStatus(totalTargetCountStatus);
}
@@ -133,7 +133,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
.getStatusCountByRolloutGroupId(rolloutGroupId);
final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus(rolloutStatusCountItems,
- rolloutGroup.getTotalTargets());
+ Long.valueOf(rolloutGroup.getTotalTargets()));
rolloutGroup.setTotalTargetCountStatus(totalTargetCountStatus);
return rolloutGroup;
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java
index f1138a6d7..ca5c8389d 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java
@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -144,11 +144,11 @@ public class JpaRolloutManagement implements RolloutManagement {
}
private static Page convertPage(final Page findAll, final Pageable pageable) {
- return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements());
+ return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
private static Slice convertPage(final Slice findAll, final Pageable pageable) {
- return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, 0);
+ return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, 0);
}
@Override
@@ -656,7 +656,7 @@ public class JpaRolloutManagement implements RolloutManagement {
@Override
public float getFinishedPercentForRunningGroup(final Long rolloutId, final RolloutGroup rolloutGroup) {
- final Long totalGroup = rolloutGroup.getTotalTargets();
+ final int totalGroup = rolloutGroup.getTotalTargets();
final Long finished = actionRepository.countByRolloutIdAndRolloutGroupIdAndStatus(rolloutId,
rolloutGroup.getId(), Action.Status.FINISHED);
if (totalGroup == 0) {
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java
index 9e612bc38..fad743baf 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java
@@ -11,12 +11,15 @@ package org.eclipse.hawkbit.repository.jpa;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
@@ -66,6 +69,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
/**
@@ -170,7 +174,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
@SuppressWarnings({ "unchecked", "rawtypes" })
final Collection jpaCast = (Collection) swModules;
- return new ArrayList<>(softwareModuleRepository.save(jpaCast));
+ return Collections.unmodifiableList(softwareModuleRepository.save(jpaCast));
}
@Override
@@ -189,22 +193,22 @@ public class JpaSoftwareManagement implements SoftwareManagement {
private static Slice convertSmPage(final Slice findAll,
final Pageable pageable) {
- return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, 0);
+ return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, 0);
}
private static Page convertSmPage(final Page findAll, final Pageable pageable) {
- return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements());
+ return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
private static Page convertSmMdPage(final Page findAll,
final Pageable pageable) {
- return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements());
+ return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
@Override
public Long countSoftwareModulesByType(final SoftwareModuleType type) {
- final List> specList = new ArrayList<>();
+ final List> specList = new ArrayList<>(2);
Specification spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type);
specList.add(spec);
@@ -281,7 +285,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
@Override
public Slice findSoftwareModulesAll(final Pageable pageable) {
- final List> specList = new ArrayList<>();
+ final List> specList = new ArrayList<>(2);
Specification spec = SoftwareModuleSpecification.isDeletedFalse();
specList.add(spec);
@@ -300,13 +304,9 @@ public class JpaSoftwareManagement implements SoftwareManagement {
@Override
public Long countSoftwareModulesAll() {
-
- final List> specList = new ArrayList<>();
-
final Specification spec = SoftwareModuleSpecification.isDeletedFalse();
- specList.add(spec);
- return countSwModuleByCriteriaAPI(specList);
+ return countSwModuleByCriteriaAPI(Lists.newArrayList(spec));
}
@Override
@@ -333,20 +333,20 @@ public class JpaSoftwareManagement implements SoftwareManagement {
private static Page convertSmTPage(final Page findAll,
final Pageable pageable) {
- return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements());
+ return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
@Override
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
public List findSoftwareModulesById(final Collection ids) {
- return new ArrayList<>(softwareModuleRepository.findByIdIn(ids));
+ return Collections.unmodifiableList(softwareModuleRepository.findByIdIn(ids));
}
@Override
public Slice findSoftwareModuleByFilters(final Pageable pageable, final String searchText,
final SoftwareModuleType type) {
- final List> specList = new ArrayList<>();
+ final List> specList = new ArrayList<>(4);
Specification spec = SoftwareModuleSpecification.isDeletedFalse();
specList.add(spec);
@@ -444,7 +444,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
private static List> buildSpecificationList(final String searchText,
final JpaSoftwareModuleType type) {
- final List> specList = new ArrayList<>();
+ final List> specList = new ArrayList<>(3);
if (!Strings.isNullOrEmpty(searchText)) {
specList.add(SoftwareModuleSpecification.likeNameOrVersion(searchText));
}
@@ -458,18 +458,15 @@ public class JpaSoftwareManagement implements SoftwareManagement {
private Predicate[] specificationsToPredicate(final List> specifications,
final Root root, final CriteriaQuery> query, final CriteriaBuilder cb,
final Predicate... additionalPredicates) {
- final List