diff --git a/MIGRATION.md b/MIGRATION.md index eacce864d..8db1ee57c 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -7,3 +7,7 @@ - hawkbit.server.email.support has changed to hawkbit.server.ui.links.support - hawkbit.server.email.request.account has changed to hawkbit.server.ui.links.requestAccount - hawkbit.server.im.login.url has changed to hawkbit.server.ui.links.userManagement + +### REST API model changes for clients +- ENTITYPagedList classes have been removed; generic PagedList used instead (e.g. PagedList instead of TargetPagedList). +- ENTITYsrest classes have been removed; List used instead (e.g. List instead of TargetsRest) diff --git a/README.md b/README.md index fb649633b..461e12e81 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,11 @@ see [hawkBit Wiki](https://github.com/eclipse/hawkbit/wiki) * Having issues with hawkBit? Open a [GitHub issue](https://github.com/eclipse/hawkbit/issues). * You can also check out our [Project Homepage](https://projects.eclipse.org/projects/iot.hawkbit) for further contact options. +# hawkBit sandbox + +We offer a sandbox installation that is free for everyone to try out hawkBit. However, keep in mind that the sandbox database will be reset from time to time. It is also not possible to upload any artifacts into the sandbox. But you can use it to try out the Management UI, Management API and DDI API. + +https://hawkbit.eu-gb.mybluemix.net/UI/ # Compile, Run and Getting Started diff --git a/deployHawkBitSandbox.sh b/deployHawkBitSandbox.sh new file mode 100644 index 000000000..d774f4205 --- /dev/null +++ b/deployHawkBitSandbox.sh @@ -0,0 +1,20 @@ +# +# Copyright (c) 2015 Bosch Software Innovations GmbH and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# + +# This script allows the deployment of the complete hawkBit sandbox including +# data example to a cloud foundry enviroment. Expects existing CF CLI +# installation and login to be existing already. + +cd examples/hawkbit-example-app/target/ +cf push +cd ../.. +java -jar hawkbit-mgmt-api-client/target/hawkbit-mgmt-api-client-0.2.0-SNAPSHOT.jar --hawkbit.url=hawkbit.eu-gb.mybluemix.net +cd hawkbit-device-simulator/target/ +cf push +cd ../../.. diff --git a/examples/README.md b/examples/README.md index 3ad5ecf66..0d6e0c18a 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,7 +1,9 @@ # Examples -Example projects that show how hawkBit can be used to create, run or access an hawkBit empowered update server. +Example projects that show how _hawkBit_ can be used to create, run or access an _hawkBit_ empowered update server. + +- `hawkbit-device-simulator` : Simulates device software updates, leveraging the hawkBit device integration options. +- `hawkbit-example-app` : Allows you to run a Spring Boot and hawkBit based update server. Includes all _hawkBit_ interfaces, i.e. DDI, DMF, Mgmt-API, Mgmt-UI. +- `hawkbit-custom-theme-example` : Example for a customized theme for Management UI. +- `hawkbit-mgmt-api-client` : Example client for the _hawkBit_ Management API. -`hawkbit-device-simulator` : Simulates device software updates, leveraging the hawkBit device integration options. -`hawkbit-example-app` : Allows you to run a Spring Boot and hawkBit based update server. -`hawkbit-mgmt-api-client` : Example client for the hawkBit management API. diff --git a/examples/hawkbit-custom-theme-example/README.md b/examples/hawkbit-custom-theme-example/README.md new file mode 100644 index 000000000..5a6a571c8 --- /dev/null +++ b/examples/hawkbit-custom-theme-example/README.md @@ -0,0 +1 @@ +Theme customization example for Eclipse hawkBit. See wiki for the theme customization guide. \ No newline at end of file diff --git a/examples/hawkbit-custom-theme-example/pom.xml b/examples/hawkbit-custom-theme-example/pom.xml new file mode 100644 index 000000000..7caa99ba2 --- /dev/null +++ b/examples/hawkbit-custom-theme-example/pom.xml @@ -0,0 +1,112 @@ + + + 4.0.0 + + org.eclipse.hawkbit + hawkbit-examples-parent + 0.2.0-SNAPSHOT + + hawkbit-custom-theme-example + hawkBit :: Custom Theme Example App + + + + + com.vaadin + vaadin-maven-plugin + ${vaadin.plugin.version} + + src/main/resources + + + + + update-theme + compile-theme + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + ${baseDir} + false + org.eclipse.hawkbit.app.Start + JAR + + + + + + + + + + + org.eclipse.hawkbit + hawkbit-autoconfigure + ${project.version} + + + org.eclipse.hawkbit + hawkbit-ui + ${project.version} + + + org.eclipse.hawkbit + hawkbit-security-integration + ${project.version} + + + org.eclipse.hawkbit + hawkbit-http-security + ${project.version} + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-logging + + + + + org.springframework.boot + spring-boot-starter-log4j2 + + + org.springframework.security + spring-security-aspects + + + com.h2database + h2 + + + + diff --git a/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/MyLoginUI.java b/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/MyLoginUI.java new file mode 100644 index 000000000..c31086a70 --- /dev/null +++ b/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/MyLoginUI.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.app; + +import org.eclipse.hawkbit.ui.login.HawkbitLoginUI; +import org.eclipse.hawkbit.ui.themes.HawkbitTheme; + +import com.vaadin.annotations.Theme; +import com.vaadin.annotations.Title; +import com.vaadin.spring.annotation.SpringUI; + +/** + * Example hawkBit login UI implementation. + * + * A {@link SpringUI} annotated class must be present in the classpath for the + * login path. The easiest way to get an hawkBit login UI running is to extend + * the {@link HawkbitLoginUI} and to annotated it with {@link SpringUI} as in + * this example to the defined {@link HawkbitTheme#LOGIN_UI_PATH}. + * + */ +@SpringUI(path = HawkbitTheme.LOGIN_UI_PATH) +@Title("hawkBit Theme example") +@Theme(value = "exampletheme") +public class MyLoginUI extends HawkbitLoginUI { + + private static final long serialVersionUID = 1L; + +} 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 new file mode 100644 index 000000000..5ef632d10 --- /dev/null +++ b/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/MyUI.java @@ -0,0 +1,45 @@ +package org.eclipse.hawkbit.app; +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +import org.eclipse.hawkbit.ui.HawkbitUI; +import org.eclipse.hawkbit.ui.UIEventProvider; +import org.eclipse.hawkbit.ui.push.DelayedEventBusPushStrategy; +import org.springframework.beans.factory.annotation.Autowired; + +import com.google.common.eventbus.EventBus; +import com.vaadin.annotations.Push; +import com.vaadin.annotations.Theme; +import com.vaadin.annotations.Title; +import com.vaadin.shared.communication.PushMode; +import com.vaadin.shared.ui.ui.Transport; +import com.vaadin.spring.annotation.SpringUI; + +/** + * Example hawkBit UI implementation. + * + * A {@link SpringUI} annotated class must be present in the classpath. The + * easiest way to get an hawkBit UI running is to extend the {@link HawkbitUI} + * and to annotated it with {@link SpringUI} as in this example. + * + */ +@SpringUI +@Push(value = PushMode.AUTOMATIC, transport = Transport.WEBSOCKET) +@Title("hawkBit Theme example") +@Theme(value = "exampletheme") +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)); + } +} diff --git a/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java b/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java new file mode 100644 index 000000000..1c4c5d32d --- /dev/null +++ b/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java @@ -0,0 +1,36 @@ +package org.eclipse.hawkbit.app; +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +import org.eclipse.hawkbit.RepositoryApplicationConfiguration; +import org.eclipse.hawkbit.autoconfigure.security.EnableHawkbitManagedSecurityConfiguration; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Import; + +/** + * A {@link SpringBootApplication} annotated class with a main method to start. + * The minimal configuration for the stand alone hawkBit server. + * + */ +@SpringBootApplication +@Import({ RepositoryApplicationConfiguration.class }) +@EnableHawkbitManagedSecurityConfiguration +public class Start { + + /** + * Main method to start the spring-boot application. + * + * @param args + * the VM arguments. + */ + public static void main(final String[] args) { + SpringApplication.run(Start.class, args); + } +} diff --git a/examples/hawkbit-custom-theme-example/src/main/resources/VAADIN/themes/exampletheme/.gitignore b/examples/hawkbit-custom-theme-example/src/main/resources/VAADIN/themes/exampletheme/.gitignore new file mode 100644 index 000000000..1cdd02b74 --- /dev/null +++ b/examples/hawkbit-custom-theme-example/src/main/resources/VAADIN/themes/exampletheme/.gitignore @@ -0,0 +1,2 @@ +/addons.scss +/styles.css diff --git a/examples/hawkbit-custom-theme-example/src/main/resources/VAADIN/themes/exampletheme/customstyles/examplevariables.scss b/examples/hawkbit-custom-theme-example/src/main/resources/VAADIN/themes/exampletheme/customstyles/examplevariables.scss new file mode 100644 index 000000000..6bf201f9c --- /dev/null +++ b/examples/hawkbit-custom-theme-example/src/main/resources/VAADIN/themes/exampletheme/customstyles/examplevariables.scss @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +$dark-gray: #848484; + +//Example color change +$hawkbit-primary-color: $dark-gray; +$hawkbit-primary-color-light: #D8D8D8; +$app-selection-item-selection-color: $dark-gray; +$app-focus-color: $dark-gray; +$app-selection-color: $dark-gray; +$tag-text-color: $dark-gray; +$tab-sheet-caption-color: $dark-gray; +$table-details-tab-font-color: $dark-gray; +$widget-caption-color: $dark-gray; +$accordion-action-history-title-color: $dark-gray; +$menu-title-bg-color: $dark-gray; +$button-icon-color: $dark-gray; \ No newline at end of file diff --git a/examples/hawkbit-custom-theme-example/src/main/resources/VAADIN/themes/exampletheme/images/profile-pic-57px.jpg b/examples/hawkbit-custom-theme-example/src/main/resources/VAADIN/themes/exampletheme/images/profile-pic-57px.jpg new file mode 100644 index 000000000..d730cb5f6 Binary files /dev/null and b/examples/hawkbit-custom-theme-example/src/main/resources/VAADIN/themes/exampletheme/images/profile-pic-57px.jpg differ diff --git a/examples/hawkbit-custom-theme-example/src/main/resources/VAADIN/themes/exampletheme/layouts/footer.html b/examples/hawkbit-custom-theme-example/src/main/resources/VAADIN/themes/exampletheme/layouts/footer.html new file mode 100644 index 000000000..f2ac781ba --- /dev/null +++ b/examples/hawkbit-custom-theme-example/src/main/resources/VAADIN/themes/exampletheme/layouts/footer.html @@ -0,0 +1,29 @@ + + + + + diff --git a/examples/hawkbit-custom-theme-example/src/main/resources/VAADIN/themes/exampletheme/styles.scss b/examples/hawkbit-custom-theme-example/src/main/resources/VAADIN/themes/exampletheme/styles.scss new file mode 100644 index 000000000..4b3f29814 --- /dev/null +++ b/examples/hawkbit-custom-theme-example/src/main/resources/VAADIN/themes/exampletheme/styles.scss @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +@import "../hawkbit/customstyles/hawkbitvariables"; +@import "customstyles/examplevariables"; +@import "../hawkbit/hawkbittheme"; +@import "addons"; + +// This file prefixes all rules with the theme name to avoid causing conflicts with other themes. +.exampletheme { + @include addons; + @include hawkbittheme; +} diff --git a/examples/hawkbit-custom-theme-example/src/main/resources/application.properties b/examples/hawkbit-custom-theme-example/src/main/resources/application.properties new file mode 100644 index 000000000..3ffb51bd0 --- /dev/null +++ b/examples/hawkbit-custom-theme-example/src/main/resources/application.properties @@ -0,0 +1,16 @@ +# +# Copyright (c) 2015 Bosch Software Innovations GmbH and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# + +# UI demo account +hawkbit.server.ui.demo.password=admin +hawkbit.server.ui.demo.user=admin +hawkbit.server.ui.demo.tenant=DEFAULT + +# UI help links +hawkbit.server.ui.links.documentation.root=https://github.com/eclipse/hawkbit diff --git a/examples/hawkbit-device-simulator/README.md b/examples/hawkbit-device-simulator/README.md index 869f80511..1ba29bb7e 100644 --- a/examples/hawkbit-device-simulator/README.md +++ b/examples/hawkbit-device-simulator/README.md @@ -2,7 +2,7 @@ The device simulator handles software update commands from the update server. -## Run +## Run on your own workstation ``` java -jar examples/hawkbit-device-simulator/target/hawkbit-device-simulator-*-SNAPSHOT.jar ``` @@ -11,6 +11,11 @@ Or: run org.eclipse.hawkbit.simulator.DeviceSimulator ``` +## Deploy to cloud foundry environment + +- Go to ```target``` subfolder. +- Run ```cf push``` + ## Notes The simulator has user authentication enabled in **cloud profile**. Default credentials: @@ -30,9 +35,9 @@ http://localhost:8083 ``` ![](src/main/images/generateScreenshot.png) - + ![](src/main/images/updateProcessScreenshot.png) - + ![](src/main/images/updateResultOverviewScreenshot.png) @@ -54,12 +59,12 @@ Example: for 20 simulated devices (default) http://localhost:8083/start ``` -Example: for 10 simulated devices that start with the name prefix "activeSim": +Example: for 10 simulated devices that start with the name prefix "activeSim": ``` http://localhost:8083/start?amount=10&name=activeSim ``` -Example: for 5 simulated devices that start with the name prefix "ddi" using the Direct Device Integration API (http): +Example: for 5 simulated devices that start with the name prefix "ddi" using the Direct Device Integration API (http): ``` http://localhost:8083/start?amount=5&name=ddi?api=ddi ``` diff --git a/examples/hawkbit-device-simulator/cf/manifest.yml b/examples/hawkbit-device-simulator/cf/manifest.yml new file mode 100644 index 000000000..51a43ace6 --- /dev/null +++ b/examples/hawkbit-device-simulator/cf/manifest.yml @@ -0,0 +1,22 @@ +# +# Copyright (c) 2015 Bosch Software Innovations GmbH and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# + +--- +applications: +- name: hawkbit-simulator + memory: 1024M + instances: 1 + buildpack: https://github.com/cloudfoundry/java-buildpack + path: ${project.build.finalName}.jar + services: + - dmf-rabbit + env: + SPRING_PROFILES_ACTIVE: cloud,amqp + CF_STAGING_TIMEOUT: 15 + CF_STARTUP_TIMEOUT: 15 diff --git a/examples/hawkbit-device-simulator/pom.xml b/examples/hawkbit-device-simulator/pom.xml index a2575e9db..a23051124 100644 --- a/examples/hawkbit-device-simulator/pom.xml +++ b/examples/hawkbit-device-simulator/pom.xml @@ -42,6 +42,19 @@ + + + src/main/resources + + + cf + true + ${project.build.directory} + + manifest.yml + + + diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java index b8b5011aa..afc3a2569 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java @@ -14,6 +14,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice.Protocol; import org.eclipse.hawkbit.simulator.amqp.SpSenderService; import org.eclipse.hawkbit.simulator.event.InitUpdate; import org.eclipse.hawkbit.simulator.event.ProgressUpdate; @@ -34,6 +35,9 @@ public class DeviceSimulatorUpdater { @Autowired private SpSenderService spSenderService; + @Autowired + private SimulatedDeviceFactory deviceFactory; + @Autowired private EventBus eventbus; @@ -58,7 +62,13 @@ public class DeviceSimulatorUpdater { */ public void startUpdate(final String tenant, final String id, final long actionId, final String swVersion, final UpdaterCallback callback) { - final AbstractSimulatedDevice device = repository.get(tenant, id); + AbstractSimulatedDevice device = repository.get(tenant, id); + + // plug and play - non existing device will be auto created + if (device == null) { + device = repository.add(deviceFactory.createSimulatedDevice(id, tenant, Protocol.DMF_AMQP, -1, null, null)); + } + device.setProgress(0.0); device.setSwversion(swVersion); eventbus.post(new InitUpdate(device)); diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java index c1f358d89..426860d8b 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java @@ -55,7 +55,7 @@ public class SimulationController { * number of delay in milliseconds to delay polling of DDI * devices * @param gatewayToken - * the hawkbit-update-server gatwaytoken in case authentication + * the hawkbit-update-server gatewaytoken in case authentication * is enforced in hawkbit * @return a response string that devices has been created * @throws MalformedURLException @@ -68,7 +68,7 @@ public class SimulationController { @RequestParam(value = "endpoint", defaultValue = "http://localhost:8080") final String endpoint, @RequestParam(value = "polldelay", defaultValue = "30") final int pollDelay, @RequestParam(value = "gatewaytoken", defaultValue = "") final String gatewayToken) - throws MalformedURLException { + throws MalformedURLException { final Protocol protocol; switch (api.toLowerCase()) { diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationProperties.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationProperties.java new file mode 100644 index 000000000..354263934 --- /dev/null +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationProperties.java @@ -0,0 +1,136 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.simulator; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice.Protocol; +import org.hibernate.validator.constraints.NotEmpty; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * General simulator service properties. + * + */ +@Component +@ConfigurationProperties("hawkbit.device.simulator") +public class SimulationProperties { + + /** + * List of tenants where the simulator should auto start simulations after + * startup. + */ + private final List autostarts = new ArrayList<>(); + + public List getAutostarts() { + return this.autostarts; + } + + /** + * Auto start configuration for simulation setups that the simulator begins + * after startup. + * + */ + public static class Autostart { + /** + * Name prefix of simulated devices, followed by counter, e.g. + * simulated0, simulated1, simulated2.... + */ + private String name = "simulated"; + + /** + * Amount of simulated devices. + */ + private int amount = 20; + + /** + * Tenant name for the simulation. + */ + @NotEmpty + private String tenant; + + /** + * API for simulation. + */ + private Protocol api = Protocol.DMF_AMQP; + + /** + * Endpoint in case of DDI API based simulation. + */ + private String endpoint = "http://localhost:8080"; + + /** + * Poll time in case of DDI API based simulation. + */ + private int pollDelay = 30; + + /** + * Optional gateway token for DDI API based simulation. + */ + private String gatewayToken = ""; + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public int getAmount() { + return amount; + } + + public void setAmount(final int amount) { + this.amount = amount; + } + + public String getTenant() { + return tenant; + } + + public void setTenant(final String tenant) { + this.tenant = tenant; + } + + public Protocol getApi() { + return api; + } + + public void setApi(final Protocol api) { + this.api = api; + } + + public String getEndpoint() { + return endpoint; + } + + public void setEndpoint(final String endpoint) { + this.endpoint = endpoint; + } + + public int getPollDelay() { + return pollDelay; + } + + public void setPollDelay(final int pollDelay) { + this.pollDelay = pollDelay; + } + + public String getGatewayToken() { + return gatewayToken; + } + + public void setGatewayToken(final String gatewayToken) { + this.gatewayToken = gatewayToken; + } + } +} diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java new file mode 100644 index 000000000..faff1cc6c --- /dev/null +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.simulator; + +import java.net.URL; + +import org.eclipse.hawkbit.simulator.amqp.SpSenderService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationListener; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.stereotype.Component; + +/** + * Execution of operations after startup. Set up of simulations. + * + */ +@Component +public class SimulatorStartup implements ApplicationListener { + private static final Logger LOGGER = LoggerFactory.getLogger(SimulatorStartup.class); + + @Autowired + private SimulationProperties simulationProperties; + + @Autowired + private SpSenderService spSenderService; + + @Autowired + private DeviceSimulatorRepository repository; + + @Autowired + private SimulatedDeviceFactory deviceFactory; + + @Override + public void onApplicationEvent(final ContextRefreshedEvent event) { + simulationProperties.getAutostarts().forEach(autostart -> { + for (int i = 0; i < autostart.getAmount(); i++) { + final String deviceId = autostart.getName() + i; + try { + repository.add(deviceFactory.createSimulatedDevice(deviceId, autostart.getTenant(), + autostart.getApi(), autostart.getPollDelay(), new URL(autostart.getEndpoint()), + autostart.getGatewayToken())); + } catch (final Exception e) { + LOGGER.error("Creation of simulated device at startup failed.", e); + } + + spSenderService.createOrUpdateThing(autostart.getTenant(), deviceId); + } + }); + } + +} 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 492bb3857..bf5d723a8 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 @@ -59,7 +59,8 @@ public class AmqpConfiguration { } /** - * Create the receiver queue from sp. Receive messages from sp. + * Creates the receiver queue from update server for receiving message from + * update server. * * @return the queue */ @@ -70,7 +71,7 @@ public class AmqpConfiguration { } /** - * Create the recevier exchange. Sp send messages to this exchange. + * Creates the receiver exchange for sending messages to update server. * * @return the exchange */ diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpProperties.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpProperties.java index f9e6ab23d..f58355980 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpProperties.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpProperties.java @@ -19,26 +19,25 @@ import org.springframework.stereotype.Component; @Component @ConfigurationProperties("hawkbit.device.simulator.amqp") public class AmqpProperties { - /** * Queue for receiving DMF messages from update server. */ - private String receiverConnectorQueueFromSp; + private String receiverConnectorQueueFromSp = "simulator_receiver"; /** * Exchange for sending DMF messages to update server. */ - private String senderForSpExchange; + private String senderForSpExchange = "simulator.replyTo"; /** * Simulator dead letter queue. */ - private String deadLetterQueue; + private String deadLetterQueue = "simulator_deadletter"; /** * Simulator dead letter exchange. */ - private String deadLetterExchange; + private String deadLetterExchange = "simulator.deadletter"; public String getReceiverConnectorQueueFromSp() { return receiverConnectorQueueFromSp; diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SpReceiverService.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SpReceiverService.java index 1c314d56f..f22839422 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SpReceiverService.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SpReceiverService.java @@ -26,14 +26,11 @@ import org.springframework.messaging.handler.annotation.Header; import org.springframework.stereotype.Component; /** - * Handle all incoming Messages from SP. - * - * + * Handle all incoming Messages from hawkBit update server. * */ @Component public class SpReceiverService extends ReceiverService { - private static final Logger LOGGER = LoggerFactory.getLogger(ReceiverService.class); public static final String SOFTWARE_MODULE_FIRMWARE = "firmware"; @@ -44,17 +41,6 @@ public class SpReceiverService extends ReceiverService { /** * Constructor. - * - * @param rabbitTemplate - * the rabbit template - * @param amqpProperties - * the amqp properties - * @param lwm2mSenderService - * the lwm2mSenderService - * @param spSenderService - * the spSenderService - * @param deviceUpdater - * the updater service to simulate update process */ @Autowired public SpReceiverService(final RabbitTemplate rabbitTemplate, final AmqpProperties amqpProperties, @@ -62,12 +48,11 @@ public class SpReceiverService extends ReceiverService { super(rabbitTemplate, amqpProperties); this.spSenderService = spSenderService; this.deviceUpdater = deviceUpdater; - } /** * Handle the incoming Message from Queue with the property - * (com.bosch.sp.lwm2m.connector.amqp.receiverConnectorQueueFromSp). + * (hawkbit.device.simulator.amqp.receiverConnectorQueueFromSp). * * @param message * the incoming message diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/ui/SimulatorView.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/ui/SimulatorView.java index e1d6bd15b..28ad0eaa9 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/ui/SimulatorView.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/ui/SimulatorView.java @@ -154,6 +154,7 @@ public class SimulatorView extends VerticalLayout implements View { public void pollCounterUpdate(final NextPollCounterUpdate update) { final List devices = update.getDevices(); this.getUI().access(new Runnable() { + @Override public void run() { devices.forEach(device -> { @@ -176,6 +177,7 @@ public class SimulatorView extends VerticalLayout implements View { public void initUpdate(final InitUpdate update) { final AbstractSimulatedDevice device = update.getDevice(); this.getUI().access(new Runnable() { + @Override public void run() { final BeanItem item = beanContainer.getItem(device.getId()); diff --git a/examples/hawkbit-device-simulator/src/main/resources/application.properties b/examples/hawkbit-device-simulator/src/main/resources/application.properties index 56d0190a7..fbe7261be 100644 --- a/examples/hawkbit-device-simulator/src/main/resources/application.properties +++ b/examples/hawkbit-device-simulator/src/main/resources/application.properties @@ -7,18 +7,17 @@ # http://www.eclipse.org/legal/epl-v10.html # - -######################################################################################### -# PUBLIC configuration, i.e. can be changed by users at runtime (defaults provided here) -######################################################################################### -## Configuration for RabbitMQ communication +## Configuration for DMF communication hawkbit.device.simulator.amqp.receiverConnectorQueueFromSp=simulator_receiver hawkbit.device.simulator.amqp.deadLetterQueue=simulator_deadletter hawkbit.device.simulator.amqp.deadLetterExchange=simulator.deadletter hawkbit.device.simulator.amqp.senderForSpExchange=simulator.replyTo +## Configuration for simulations +hawkbit.device.simulator.autostarts.[0].tenant=DEFAULT -## Configuration for RabbitMQ integration + +## Configuration for local RabbitMQ integration spring.rabbitmq.username=guest spring.rabbitmq.password=guest spring.rabbitmq.virtualHost=/ diff --git a/examples/hawkbit-example-app/README.md b/examples/hawkbit-example-app/README.md index eaf30f306..ecbec93c3 100644 --- a/examples/hawkbit-example-app/README.md +++ b/examples/hawkbit-example-app/README.md @@ -1,7 +1,15 @@ # hawkBit Example Application -The hawkBit example application is a standalone spring-boot application with an embedded servlet container to start the hawkBit. +The hawkBit example application is a standalone spring-boot application with an embedded servlet container to host the hawkBit Update Server. -## Run +We have have described several options for you to get access to the example. + +## Try out the example application in our hawkBit sandbox on Bluemix +- try out Management UI https://hawkbit.eu-gb.mybluemix.net/UI +- try out Management API https://hawkbit.eu-gb.mybluemix.net/rest/v1/targets (don't forget basic auth header) +- try out DDI API https://hawkbit.eu-gb.mybluemix.net/DEFAULT/controller/v1/MYTESTDEVICE + +## On your own workstation +### Run ``` java -jar examples/hawkbit-example-app/target/hawkbit-example-app-*-SNAPSHOT.jar ``` @@ -10,6 +18,14 @@ Or: run org eclipse.hawkbit.app.Start ``` -## Usage -The UI can be accessed via _http://localhost:8080/UI_. -The REST API can be accessed via _http://localhost:8080/rest/v1_. +### Usage +The Management UI can be accessed via http://localhost:8080/UI +The Management API can be accessed via http://localhost:8080/rest/v1 + +## Deploy example app to Cloud Foundry + +- Go to ```target``` subfolder. +- Select one of the two manifests + - **manifest-simple.yml** for a standalone hawkBit installation with embedded H2. + - **manifest.yml** for a standalone hawkBit installation with embedded H2 and RabbitMQ service binding for DMF integration (note: this manifest is used for the sandbox above). +- Run ```cf push``` against you cloud foundry environment. diff --git a/examples/hawkbit-example-app/cf/manifest-simple.yml b/examples/hawkbit-example-app/cf/manifest-simple.yml new file mode 100644 index 000000000..c87a533f4 --- /dev/null +++ b/examples/hawkbit-example-app/cf/manifest-simple.yml @@ -0,0 +1,20 @@ +# +# Copyright (c) 2015 Bosch Software Innovations GmbH and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# + +--- +applications: +- name: hawkbit-simple + memory: 1024M + instances: 1 + buildpack: https://github.com/cloudfoundry/java-buildpack + path: ${project.build.finalName}.jar + env: + SPRING_PROFILES_ACTIVE: cloudsandbox + CF_STAGING_TIMEOUT: 15 + CF_STARTUP_TIMEOUT: 15 diff --git a/examples/hawkbit-example-app/cf/manifest.yml b/examples/hawkbit-example-app/cf/manifest.yml new file mode 100644 index 000000000..2145f467d --- /dev/null +++ b/examples/hawkbit-example-app/cf/manifest.yml @@ -0,0 +1,22 @@ +# +# Copyright (c) 2015 Bosch Software Innovations GmbH and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# + +--- +applications: +- name: hawkbit + memory: 1024M + instances: 1 + buildpack: https://github.com/cloudfoundry/java-buildpack + path: ${project.build.finalName}.jar + services: + - dmf-rabbit + env: + SPRING_PROFILES_ACTIVE: cloudsandbox,amqp + CF_STAGING_TIMEOUT: 15 + CF_STARTUP_TIMEOUT: 15 diff --git a/examples/hawkbit-example-app/pom.xml b/examples/hawkbit-example-app/pom.xml index 33624ffd7..a5c0f864d 100644 --- a/examples/hawkbit-example-app/pom.xml +++ b/examples/hawkbit-example-app/pom.xml @@ -39,6 +39,20 @@ + + + src/main/resources + + + cf + true + ${project.build.directory} + + manifest.yml + manifest-simple.yml + + + 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 e55cb02d2..68d3b2fd9 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 @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.app; import org.eclipse.hawkbit.ui.HawkbitUI; +import org.eclipse.hawkbit.ui.UIEventProvider; import org.eclipse.hawkbit.ui.push.DelayedEventBusPushStrategy; import org.springframework.beans.factory.annotation.Autowired; @@ -33,7 +34,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) { - super(new DelayedEventBusPushStrategy(eventBus, systemEventBus)); + public MyUI(final EventBus systemEventBus, final org.vaadin.spring.events.EventBus.SessionEventBus eventBus, + final UIEventProvider provider) { + super(new DelayedEventBusPushStrategy(eventBus, systemEventBus, provider)); } } diff --git a/examples/hawkbit-example-app/src/main/resources/application-cloudsandbox.properties b/examples/hawkbit-example-app/src/main/resources/application-cloudsandbox.properties new file mode 100644 index 000000000..ecf71da41 --- /dev/null +++ b/examples/hawkbit-example-app/src/main/resources/application-cloudsandbox.properties @@ -0,0 +1,10 @@ +# +# Copyright (c) 2015 Bosch Software Innovations GmbH and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# + +vaadin.servlet.productionMode=true diff --git a/examples/hawkbit-mgmt-api-client/README.md b/examples/hawkbit-mgmt-api-client/README.md index eff301e20..ac8e7a4cd 100644 --- a/examples/hawkbit-mgmt-api-client/README.md +++ b/examples/hawkbit-mgmt-api-client/README.md @@ -1,4 +1,4 @@ -# HawkBit management API example +# hawkBit Management API example client Example client that shows how to efficiently use the hawkBit management API. @@ -36,4 +36,3 @@ In rollout mode: * assigning software modules to distribution sets * creating a rollout * starting a rollout - diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetResourceClient.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetResourceClient.java index 00a9b3fba..5ac11e012 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetResourceClient.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetResourceClient.java @@ -14,7 +14,7 @@ import org.springframework.cloud.netflix.feign.FeignClient; /** * Client binding for the DistributionSet resource of the management API. */ -@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/distributionsets") +@FeignClient(url = "${hawkbit.url:localhost:8080}/rest/v1/distributionsets") public interface DistributionSetResourceClient extends DistributionSetRestApi { } diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetTagResourceClient.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetTagResourceClient.java index ea9f5d28a..5fbdaf857 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetTagResourceClient.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetTagResourceClient.java @@ -14,7 +14,7 @@ import org.springframework.cloud.netflix.feign.FeignClient; /** * Client binding for the DistributionSetTag resource of the management API. */ -@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/distributionsettags") +@FeignClient(url = "${hawkbit.url:localhost:8080}/rest/v1/distributionsettags") public interface DistributionSetTagResourceClient extends DistributionSetTagRestApi { } diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetTypeResourceClient.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetTypeResourceClient.java index 08d40dfa5..300f8ddcb 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetTypeResourceClient.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetTypeResourceClient.java @@ -15,7 +15,7 @@ import org.springframework.cloud.netflix.feign.FeignClient; * Client binding for the DistributionSetType resource of the management API. * */ -@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/distributionsettypes") +@FeignClient(url = "${hawkbit.url:localhost:8080}/rest/v1/distributionsettypes") public interface DistributionSetTypeResourceClient extends DistributionSetTypeRestApi { } diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/RolloutResourceClient.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/RolloutResourceClient.java index 78b7413e7..aed3af7a2 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/RolloutResourceClient.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/RolloutResourceClient.java @@ -14,7 +14,7 @@ import org.springframework.cloud.netflix.feign.FeignClient; /** * Client binding for the Rollout resource of the management API. */ -@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/rollouts") +@FeignClient(url = "${hawkbit.url:localhost:8080}/rest/v1/rollouts") public interface RolloutResourceClient extends RolloutRestApi { } diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/SoftwareModuleResourceClient.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/SoftwareModuleResourceClient.java index 88e664d78..8610643ef 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/SoftwareModuleResourceClient.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/SoftwareModuleResourceClient.java @@ -14,7 +14,7 @@ import org.springframework.cloud.netflix.feign.FeignClient; /** * Client binding for the SoftwareModule resource of the management API. */ -@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/softwaremodules") +@FeignClient(url = "${hawkbit.url:localhost:8080}/rest/v1/softwaremodules") public interface SoftwareModuleResourceClient extends SoftwareModuleRestAPI { } diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/SoftwareModuleTypeResourceClient.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/SoftwareModuleTypeResourceClient.java index 4896cb8d8..46410dd6c 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/SoftwareModuleTypeResourceClient.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/SoftwareModuleTypeResourceClient.java @@ -14,7 +14,7 @@ import org.springframework.cloud.netflix.feign.FeignClient; /** * Client binding for the oftwareModuleType resource of the management API. */ -@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/softwaremoduletypes") +@FeignClient(url = "${hawkbit.url:localhost:8080}/rest/v1/softwaremoduletypes") public interface SoftwareModuleTypeResourceClient extends SoftwareModuleTypeRestApi { } diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/TargetResourceClient.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/TargetResourceClient.java index a82aa5443..79385fea4 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/TargetResourceClient.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/TargetResourceClient.java @@ -14,7 +14,7 @@ import org.springframework.cloud.netflix.feign.FeignClient; /** * Client binding for the Target resource of the management API. */ -@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/targets") +@FeignClient(url = "${hawkbit.url:localhost:8080}/rest/v1/targets") public interface TargetResourceClient extends TargetRestApi { } diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/TargetTagResourceClient.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/TargetTagResourceClient.java index fee30c686..930931a87 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/TargetTagResourceClient.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/TargetTagResourceClient.java @@ -14,7 +14,7 @@ import org.springframework.cloud.netflix.feign.FeignClient; /** * Client binding for the TargetTag resource of the management API. */ -@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/targettags") +@FeignClient(url = "${hawkbit.url:localhost:8080}/rest/v1/targettags") public interface TargetTagResourceClient extends TargetTagRestApi { } diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java index c821b106c..358cff0db 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java @@ -16,11 +16,7 @@ import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRe import com.google.common.collect.Lists; /** - * * Builder pattern for building {@link DistributionSetRequestBodyPost}. - * - * @author Jonathan Knoblauch - * */ public class DistributionSetBuilder { diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetTypeBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetTypeBuilder.java index e1da1f048..752834c7d 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetTypeBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetTypeBuilder.java @@ -19,8 +19,6 @@ import com.google.common.collect.Lists; /** * * Builder pattern for building {@link DistributionSetTypeRequestBodyPost}. - * - * @author Jonathan Knoblauch * */ public class DistributionSetTypeBuilder { diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/RolloutBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/RolloutBuilder.java index bea0fd9a4..2e01e0ba2 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/RolloutBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/RolloutBuilder.java @@ -15,8 +15,6 @@ import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutRestRequestBody; /** * * Builder pattern for building {@link RolloutRestRequestBody}. - * - * @author Jonathan Knoblauch * */ public class RolloutBuilder { diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleAssigmentBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleAssigmentBuilder.java index b209dbe8b..8d69db619 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleAssigmentBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleAssigmentBuilder.java @@ -16,8 +16,6 @@ import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleAssi /** * * Builder pattern for building {@link SoftwareModuleAssigmentRest}. - * - * @author Jonathan Knoblauch * */ public class SoftwareModuleAssigmentBuilder { diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleBuilder.java index 30b85d901..4bbfd92b4 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleBuilder.java @@ -19,8 +19,6 @@ import com.google.common.collect.Lists; /** * * Builder pattern for building {@link SoftwareModuleRequestBodyPost}. - * - * @author Jonathan Knoblauch * */ public class SoftwareModuleBuilder { diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleTypeBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleTypeBuilder.java index ce128d592..a6472f0a0 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleTypeBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleTypeBuilder.java @@ -19,8 +19,6 @@ import com.google.common.collect.Lists; /** * * Builder pattern for building {@link SoftwareModuleRequestBodyPost}. - * - * @author Jonathan Knoblauch * */ public class SoftwareModuleTypeBuilder { diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TagBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TagBuilder.java index f3888de54..6f2eb3248 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TagBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TagBuilder.java @@ -17,8 +17,6 @@ import com.google.common.collect.Lists; /** * Builder pattern for building {@link TagRequestBodyPut}. - * - * @author Jonathan Knoblauch * */ public class TagBuilder { diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetBuilder.java index 5123903d9..e496407e1 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetBuilder.java @@ -19,8 +19,6 @@ import com.google.common.collect.Lists; /** * * Builder pattern for building {@link TargetRequestBody}. - * - * @author Jonathan Knoblauch * */ public class TargetBuilder { diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/CreateStartedRolloutExample.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/CreateStartedRolloutExample.java index 35b0f31ea..cd74c0474 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/CreateStartedRolloutExample.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/CreateStartedRolloutExample.java @@ -8,6 +8,8 @@ */ package org.eclipse.hawkbit.mgmt.client.scenarios; +import java.util.List; + import org.eclipse.hawkbit.mgmt.client.resource.DistributionSetResourceClient; import org.eclipse.hawkbit.mgmt.client.resource.DistributionSetTypeResourceClient; import org.eclipse.hawkbit.mgmt.client.resource.RolloutResourceClient; @@ -21,10 +23,10 @@ import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleAssigmentB import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleBuilder; import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleTypeBuilder; import org.eclipse.hawkbit.mgmt.client.resource.builder.TargetBuilder; -import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest; +import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRest; import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutResponseBody; -import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModulesRest; -import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypesRest; +import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleRest; +import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -39,7 +41,7 @@ public class CreateStartedRolloutExample { private static final String SM_MODULE_TYPE = "firmware"; /* known distribution set type name and key */ - private static final String DS_MODULE_TYPE = "firmware"; + private static final String DS_MODULE_TYPE = SM_MODULE_TYPE; @Autowired private DistributionSetResourceClient distributionSetResource; @@ -65,8 +67,9 @@ public class CreateStartedRolloutExample { public void run() { // create three SoftwareModuleTypes - final SoftwareModuleTypesRest createdSoftwareModuleTypes = softwareModuleTypeResource.createSoftwareModuleTypes( - new SoftwareModuleTypeBuilder().key(SM_MODULE_TYPE).name(SM_MODULE_TYPE).maxAssignments(1).build()) + final List createdSoftwareModuleTypes = softwareModuleTypeResource + .createSoftwareModuleTypes(new SoftwareModuleTypeBuilder().key(SM_MODULE_TYPE).name(SM_MODULE_TYPE) + .maxAssignments(1).build()) .getBody(); // create one DistributionSetType @@ -75,12 +78,12 @@ public class CreateStartedRolloutExample { .getBody(); // create one DistributionSet - final DistributionSetsRest distributionSetsRest = distributionSetResource.createDistributionSets( + final List distributionSetsRest = distributionSetResource.createDistributionSets( new DistributionSetBuilder().name("rollout-example").version("1.0.0").type(DS_MODULE_TYPE).build()) .getBody(); // create three SoftwareModules - final SoftwareModulesRest softwareModulesRest = softwareModuleResource + final List softwareModulesRest = softwareModuleResource .createSoftwareModules( new SoftwareModuleBuilder().name("firmware").version("1.0.0").type(SM_MODULE_TYPE).build()) .getBody(); diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/GettingStartedDefaultScenario.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/GettingStartedDefaultScenario.java index 5767ab9e7..5873403f0 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/GettingStartedDefaultScenario.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/GettingStartedDefaultScenario.java @@ -8,6 +8,8 @@ */ package org.eclipse.hawkbit.mgmt.client.scenarios; +import java.util.List; + import org.eclipse.hawkbit.mgmt.client.resource.DistributionSetResourceClient; import org.eclipse.hawkbit.mgmt.client.resource.DistributionSetTypeResourceClient; import org.eclipse.hawkbit.mgmt.client.resource.SoftwareModuleResourceClient; @@ -17,9 +19,9 @@ import org.eclipse.hawkbit.mgmt.client.resource.builder.DistributionSetTypeBuild import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleAssigmentBuilder; import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleBuilder; import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleTypeBuilder; -import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest; -import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModulesRest; -import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypesRest; +import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRest; +import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleRest; +import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -39,13 +41,13 @@ public class GettingStartedDefaultScenario { private static final String SM_MODULE_TYPE = "gettingstarted"; /* known distribution set type name and key */ - private static final String DS_MODULE_TYPE = "gettingstarted"; + private static final String DS_MODULE_TYPE = SM_MODULE_TYPE; /* known distribution name of this getting started example */ private static final String SM_EXAMPLE_NAME = "gettingstarted-example"; /* known distribution name of this getting started example */ - private static final String DS_EXAMPLE_NAME = "gettingstarted-example"; + private static final String DS_EXAMPLE_NAME = SM_EXAMPLE_NAME; @Autowired private DistributionSetResourceClient distributionSetResource; @@ -68,8 +70,9 @@ public class GettingStartedDefaultScenario { // create one SoftwareModuleTypes LOGGER.info("Creating software module type {}", SM_MODULE_TYPE); - final SoftwareModuleTypesRest createdSoftwareModuleTypes = softwareModuleTypeResource.createSoftwareModuleTypes( - new SoftwareModuleTypeBuilder().key(SM_MODULE_TYPE).name(SM_MODULE_TYPE).maxAssignments(1).build()) + final List createdSoftwareModuleTypes = softwareModuleTypeResource + .createSoftwareModuleTypes(new SoftwareModuleTypeBuilder().key(SM_MODULE_TYPE).name(SM_MODULE_TYPE) + .maxAssignments(1).build()) .getBody(); // create one DistributionSetType @@ -83,17 +86,17 @@ public class GettingStartedDefaultScenario { final String dsVersion3 = "2.1.0"; LOGGER.info("Creating distribution set {}:{}", DS_EXAMPLE_NAME, dsVersion1); - final DistributionSetsRest distributionSetsRest1 = distributionSetResource.createDistributionSets( + final List distributionSetsRest1 = distributionSetResource.createDistributionSets( new DistributionSetBuilder().name(DS_EXAMPLE_NAME).version(dsVersion1).type(DS_MODULE_TYPE).build()) .getBody(); LOGGER.info("Creating distribution set {}:{}", DS_EXAMPLE_NAME, dsVersion2); - final DistributionSetsRest distributionSetsRest2 = distributionSetResource.createDistributionSets( + final List distributionSetsRest2 = distributionSetResource.createDistributionSets( new DistributionSetBuilder().name(DS_EXAMPLE_NAME).version(dsVersion2).type(DS_MODULE_TYPE).build()) .getBody(); LOGGER.info("Creating distribution set {}:{}", DS_EXAMPLE_NAME, dsVersion3); - final DistributionSetsRest distributionSetsRest3 = distributionSetResource.createDistributionSets( + final List distributionSetsRest3 = distributionSetResource.createDistributionSets( new DistributionSetBuilder().name(DS_EXAMPLE_NAME).version(dsVersion3).type(DS_MODULE_TYPE).build()) .getBody(); @@ -103,15 +106,15 @@ public class GettingStartedDefaultScenario { final String swVersion3 = "3"; LOGGER.info("Creating distribution set {}:{}", SM_EXAMPLE_NAME, swVersion1); - final SoftwareModulesRest softwareModulesRest1 = softwareModuleResource.createSoftwareModules( + final List softwareModulesRest1 = softwareModuleResource.createSoftwareModules( new SoftwareModuleBuilder().name(SM_EXAMPLE_NAME).version(swVersion1).type(SM_MODULE_TYPE).build()) .getBody(); LOGGER.info("Creating distribution set {}:{}", SM_EXAMPLE_NAME, swVersion2); - final SoftwareModulesRest softwareModulesRest2 = softwareModuleResource.createSoftwareModules( + final List softwareModulesRest2 = softwareModuleResource.createSoftwareModules( new SoftwareModuleBuilder().name(SM_EXAMPLE_NAME).version(swVersion2).type(SM_MODULE_TYPE).build()) .getBody(); LOGGER.info("Creating distribution set {}:{}", SM_EXAMPLE_NAME, swVersion3); - final SoftwareModulesRest softwareModulesRest3 = softwareModuleResource.createSoftwareModules( + final List softwareModulesRest3 = softwareModuleResource.createSoftwareModules( new SoftwareModuleBuilder().name(SM_EXAMPLE_NAME).version(swVersion3).type(SM_MODULE_TYPE).build()) .getBody(); diff --git a/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStore.java b/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStore.java index 78658da91..6981834b4 100644 --- a/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStore.java +++ b/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStore.java @@ -38,10 +38,7 @@ import com.mongodb.gridfs.GridFSDBFile; import com.mongodb.gridfs.GridFSFile; /** - * The file management which looks up all the file in the filestore. - * - * - * + * The file management which looks up all the file in the file tore. * */ public class ArtifactStore implements ArtifactRepository { @@ -60,7 +57,7 @@ public class ArtifactStore implements ArtifactRepository { private static final String MD5 = "md5"; /** - * The mongoDB field which holds the SHA1 hash, stored in the metadata + * The mongoDB field which holds the SHA1 hash, stored in the meta data * object. */ private static final String SHA1 = "sha1"; @@ -75,11 +72,10 @@ public class ArtifactStore implements ArtifactRepository { /** * Retrieves a {@link GridFSDBFile} from the store by it's SHA1 hash. * - * @param tenant - * the tenant to retrieve the artifacts from, ignore case. * @param sha1Hash * the sha1-hash of the file to lookup. - * @return The gridfs file object or {@code null} if no file exists. + * + * @return The DbArtifact object or {@code null} if no file exists. */ @Override public DbArtifact getArtifactBySha1(final String sha1Hash) { @@ -226,8 +222,7 @@ public class ArtifactStore implements ArtifactRepository { * @return a paged list of artifacts mapped from the given dbFiles */ private List map(final List dbFiles) { - final List collect = dbFiles.stream().map(dbFile -> map(dbFile)).collect(Collectors.toList()); - return collect; + return dbFiles.stream().map(dbFile -> map(dbFile)).collect(Collectors.toList()); } /** @@ -238,7 +233,7 @@ public class ArtifactStore implements ArtifactRepository { * the tenant to retrieve the artifacts from, ignore case. * @param sha1Hashes * the sha1-hashes of the files to lookup. - * @return list of artfiacts + * @return list of artifacts */ @Override public List getArtifactsBySha1(final List sha1Hashes) { diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/ui/UIAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/ui/UIAutoConfiguration.java index ff73eff7b..be66904d5 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/ui/UIAutoConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/ui/UIAutoConfiguration.java @@ -9,6 +9,9 @@ package org.eclipse.hawkbit.autoconfigure.ui; import org.eclipse.hawkbit.DistributedResourceBundleMessageSource; +import org.eclipse.hawkbit.ui.HawkbitEventProvider; +import org.eclipse.hawkbit.ui.UIEventProvider; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.vaadin.spring.annotation.EnableVaadinExtensions; @@ -17,9 +20,6 @@ import org.vaadin.spring.security.annotation.EnableVaadinSecurity; /** * The hawkbit-ui autoconfiguration. - * - * - * */ @Configuration @EnableVaadinSecurity @@ -37,4 +37,15 @@ public class UIAutoConfiguration { return new DistributedResourceBundleMessageSource(); } + /** + * A event provider bean which hold the supported events for the UI. + * + * @return the provider bean + */ + @Bean + @ConditionalOnMissingBean + public UIEventProvider eventProvider() { + return new HawkbitEventProvider(); + } + } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/ControllerPollProperties.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/ControllerPollProperties.java index c923963d2..0d70ae69d 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/ControllerPollProperties.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/ControllerPollProperties.java @@ -31,7 +31,7 @@ public class ControllerPollProperties { * Maximum polling time that can be configured by a tenant in HH:MM:SS * notation. */ - private String maxPollingTime = "23:59:00"; + private String maxPollingTime = "23:59:59"; /** * Minimum polling time that can be configured by a tenant in HH:MM:SS diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/DbArtifact.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/DbArtifact.java index b4c2dcdba..2385e0dfa 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/DbArtifact.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/DbArtifact.java @@ -14,9 +14,6 @@ import java.io.OutputStream; /** * Database representation of artifact. * - * - * - * */ public class DbArtifact { diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/DbArtifactHash.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/DbArtifactHash.java index c16d3a620..5619a2292 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/DbArtifactHash.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/DbArtifactHash.java @@ -11,9 +11,6 @@ package org.eclipse.hawkbit.artifact.repository.model; /** * Database representation of artifact hash. * - * - * - * */ public class DbArtifactHash { diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/DurationHelper.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/DurationHelper.java index 8e7c46223..5968f4420 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/DurationHelper.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/DurationHelper.java @@ -36,8 +36,15 @@ public final class DurationHelper { this.max = max; } + /** + * Checks if the requested duration is in the defined min/max range. + * + * @param duration + * to checked + * @return true if in time range + */ public boolean isWithinRange(final Duration duration) { - return duration.compareTo(min) > 0 && duration.compareTo(max) < 0; + return duration.compareTo(min) >= 0 && duration.compareTo(max) <= 0; } } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/TenantConfigurationKey.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/TenantConfigurationKey.java index 32a7a8376..402185be3 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/TenantConfigurationKey.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/TenantConfigurationKey.java @@ -30,45 +30,60 @@ public enum TenantConfigurationKey { /** * boolean value {@code true} {@code false}. */ - AUTHENTICATION_MODE_HEADER_ENABLED("authentication.header.enabled", "hawkbit.server.ddi.security.authentication.header.enabled", Boolean.class, Boolean.FALSE.toString(), TenantConfigurationBooleanValidator.class), + AUTHENTICATION_MODE_HEADER_ENABLED("authentication.header.enabled", + "hawkbit.server.ddi.security.authentication.header.enabled", Boolean.class, Boolean.FALSE.toString(), + TenantConfigurationBooleanValidator.class), /** * */ - AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME("authentication.header.authority", "hawkbit.server.ddi.security.authentication.header.authority", String.class, Boolean.FALSE.toString(), TenantConfigurationStringValidator.class), + AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME("authentication.header.authority", + "hawkbit.server.ddi.security.authentication.header.authority", String.class, Boolean.FALSE.toString(), + TenantConfigurationStringValidator.class), /** * boolean value {@code true} {@code false}. */ - AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED("authentication.targettoken.enabled", "hawkbit.server.ddi.security.authentication.targettoken.enabled", Boolean.class, Boolean.FALSE.toString(), TenantConfigurationBooleanValidator.class), + AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED("authentication.targettoken.enabled", + "hawkbit.server.ddi.security.authentication.targettoken.enabled", Boolean.class, Boolean.FALSE.toString(), + TenantConfigurationBooleanValidator.class), /** * boolean value {@code true} {@code false}. */ - AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED("authentication.gatewaytoken.enabled", "hawkbit.server.ddi.security.authentication.gatewaytoken.enabled", Boolean.class, Boolean.FALSE.toString(), TenantConfigurationBooleanValidator.class), + AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED("authentication.gatewaytoken.enabled", + "hawkbit.server.ddi.security.authentication.gatewaytoken.enabled", Boolean.class, Boolean.FALSE.toString(), + TenantConfigurationBooleanValidator.class), /** * string value which holds the name of the security token key. */ - AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME("authentication.gatewaytoken.name", "hawkbit.server.ddi.security.authentication.gatewaytoken.name", String.class, null, TenantConfigurationStringValidator.class), + AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME("authentication.gatewaytoken.name", + "hawkbit.server.ddi.security.authentication.gatewaytoken.name", String.class, null, + TenantConfigurationStringValidator.class), /** * string value which holds the actual security-key of the gateway security * token. */ - AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY("authentication.gatewaytoken.key", "hawkbit.server.ddi.security.authentication.gatewaytoken.key", String.class, null, TenantConfigurationStringValidator.class), + AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY("authentication.gatewaytoken.key", + "hawkbit.server.ddi.security.authentication.gatewaytoken.key", String.class, null, + TenantConfigurationStringValidator.class), /** * string value which holds the polling time interval in the format HH:mm:ss */ - POLLING_TIME_INTERVAL("pollingOverdueTime", "hawkbit.controller.pollingOverdueTime", String.class, null, TenantConfigurationPollingDurationValidator.class), + POLLING_TIME_INTERVAL("pollingTime", "hawkbit.controller.pollingTime", String.class, null, + TenantConfigurationPollingDurationValidator.class), /** * string value which holds the polling time interval in the format HH:mm:ss */ - POLLING_OVERDUE_TIME_INTERVAL("pollingTime", "hawkbit.controller.pollingTime", String.class, null, TenantConfigurationPollingDurationValidator.class), + POLLING_OVERDUE_TIME_INTERVAL("pollingOverdueTime", "hawkbit.controller.pollingOverdueTime", String.class, null, + TenantConfigurationPollingDurationValidator.class), /** * boolean value {@code true} {@code false}. */ - ANONYMOUS_DOWNLOAD_MODE_ENABLED("anonymous.download.enabled", "hawkbit.server.download.anonymous.enabled", Boolean.class, Boolean.FALSE.toString(), TenantConfigurationBooleanValidator.class); + ANONYMOUS_DOWNLOAD_MODE_ENABLED("anonymous.download.enabled", "hawkbit.server.download.anonymous.enabled", + Boolean.class, Boolean.FALSE.toString(), TenantConfigurationBooleanValidator.class); private final String keyName; private final String defaultKeyName; diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpSenderService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpSenderService.java index 6cb3dd9be..f44e2e9bb 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpSenderService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpSenderService.java @@ -24,10 +24,10 @@ public interface AmqpSenderService { * * @param message * the amqp message - * @param uri + * @param replyTo * the reply to uri */ - void sendMessage(Message message, URI uri); + void sendMessage(Message message, URI replyTo); /** * Extract the exchange from the uri. Default implementation removes the diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/BaseAmqpService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/BaseAmqpService.java index 8a054165b..76870ac93 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/BaseAmqpService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/BaseAmqpService.java @@ -59,7 +59,7 @@ public class BaseAmqpService { */ @SuppressWarnings("unchecked") public T convertMessage(final Message message, final Class clazz) { - if (message == null || message.getBody() == null) { + if (isMessageBodyEmpty(message)) { return null; } message.getMessageProperties().getHeaders().put(AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME, @@ -67,6 +67,10 @@ public class BaseAmqpService { return (T) rabbitTemplate.getMessageConverter().fromMessage(message); } + private boolean isMessageBodyEmpty(final Message message) { + return message == null || message.getBody() == null || message.getBody().length == 0; + } + /** * Is needed to convert a incoming message to is originally list object * type. @@ -79,7 +83,7 @@ public class BaseAmqpService { */ @SuppressWarnings("unchecked") public List convertMessageList(final Message message, final Class clazz) { - if (message == null || message.getBody() == null) { + if (isMessageBodyEmpty(message)) { return Collections.emptyList(); } message.getMessageProperties().getHeaders().put(AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME, @@ -105,7 +109,7 @@ public class BaseAmqpService { } protected final void logAndThrowMessageError(final Message message, final String error) { - LOGGER.error("Error \"{}\" reported by message {}", error, message.getMessageProperties().getMessageId()); + LOGGER.warn("Error \"{}\" reported by message: {}", error, message); throw new IllegalArgumentException(error); } diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/DefaultAmqpSenderService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/DefaultAmqpSenderService.java index 9586633bf..244544b64 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/DefaultAmqpSenderService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/DefaultAmqpSenderService.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.amqp; import java.net.URI; +import org.eclipse.hawkbit.util.IpUtil; import org.springframework.amqp.core.Message; import org.springframework.amqp.rabbit.core.RabbitTemplate; @@ -33,8 +34,12 @@ public class DefaultAmqpSenderService implements AmqpSenderService { } @Override - public void sendMessage(final Message message, final URI uri) { - internalAmqpTemplate.send(extractExchange(uri), null, message); + public void sendMessage(final Message message, final URI replyTo) { + if (!IpUtil.isAmqpUri(replyTo)) { + return; + } + + internalAmqpTemplate.send(extractExchange(replyTo), null, message); } } diff --git a/hawkbit-http-security/src/test/java/org/eclipse/hawkbit/security/PreAuthTokenSourceTrustAuthenticationProviderTest.java b/hawkbit-http-security/src/test/java/org/eclipse/hawkbit/security/PreAuthTokenSourceTrustAuthenticationProviderTest.java index fb961f9b2..eb4cacf33 100644 --- a/hawkbit-http-security/src/test/java/org/eclipse/hawkbit/security/PreAuthTokenSourceTrustAuthenticationProviderTest.java +++ b/hawkbit-http-security/src/test/java/org/eclipse/hawkbit/security/PreAuthTokenSourceTrustAuthenticationProviderTest.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.security; import static org.fest.assertions.Assertions.assertThat; +import static org.junit.Assert.fail; import static org.mockito.Mockito.when; import org.junit.Test; @@ -20,6 +21,7 @@ import org.springframework.security.authentication.InsufficientAuthenticationExc import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; +import ru.yandex.qatools.allure.annotations.Description; import ru.yandex.qatools.allure.annotations.Features; import ru.yandex.qatools.allure.annotations.Stories; @@ -38,11 +40,8 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest { @Mock private TenantAwareWebAuthenticationDetails webAuthenticationDetailsMock; - /** - * Testing in case the containing controllerId in the URI request path does - * not accord with the controllerId in the request header. - */ - @Test(expected = BadCredentialsException.class) + @Test + @Description("Testing in case the containing controllerId in the URI request path does not accord with the controllerId in the request header.") public void principalAndCredentialsNotTheSameThrowsAuthenticationException() { final String principal = "controllerIdURL"; final String credentials = "controllerIdHeader"; @@ -51,15 +50,17 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest { token.setDetails(webAuthenticationDetailsMock); // test, should throw authentication exception - underTestWithoutSourceIpCheck.authenticate(token); + try { + underTestWithoutSourceIpCheck.authenticate(token); + fail("Should not work with wrong credentials"); + } catch (final BadCredentialsException e) { + + } + } - /** - * Testing that the controllerId within the URI request path is the same - * with the controllerId within the request header and no source IP check is - * in place. - */ @Test + @Description("Testing that the controllerId within the URI request path is the same with the controllerId within the request header and no source IP check is in place.") public void principalAndCredentialsAreTheSameWithNoSourceIpCheckIsSuccessful() { final String principal = "controllerId"; final String credentials = "controllerId"; @@ -71,12 +72,8 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest { assertThat(authenticate.isAuthenticated()).isTrue(); } - /** - * Testing that the controllerId in the URI request match with the - * controllerId in the request header but the request are not coming from a - * trustful source. - */ - @Test(expected = InsufficientAuthenticationException.class) + @Test + @Description("Testing that the controllerId in the URI request match with the controllerId in the request header but the request are not coming from a trustful source.") public void priniciapAndCredentialsAreTheSameButSourceIpRequestNotMatching() { final String remoteAddress = "192.168.1.1"; final String principal = "controllerId"; @@ -88,16 +85,17 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest { when(webAuthenticationDetailsMock.getRemoteAddress()).thenReturn(remoteAddress); // test, should throw authentication exception - final Authentication authenticate = underTestWithSourceIpCheck.authenticate(token); - assertThat(authenticate.isAuthenticated()).isTrue(); + + try { + underTestWithSourceIpCheck.authenticate(token); + fail("as source is not trusted."); + } catch (final InsufficientAuthenticationException e) { + + } } - /** - * Testing that the controllerId in the URI request match with the - * controllerId in the request header and the source Ip is matching the - * allowed remote IP address. - */ - @Test() + @Test + @Description("Testing that the controllerId in the URI request match with the controllerId in the request header and the source Ip is matching the allowed remote IP address.") public void priniciapAndCredentialsAreTheSameAndSourceIpIsTrusted() { final String principal = "controllerId"; final String credentials = "controllerId"; @@ -112,7 +110,7 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest { assertThat(authenticate.isAuthenticated()).isTrue(); } - @Test() + @Test public void priniciapAndCredentialsAreTheSameAndSourceIpIsWithinList() { final String[] trustedIPAddresses = new String[] { "192.168.1.1", "192.168.1.2", REQUEST_SOURCE_IP, "192.168.1.3" }; @@ -148,6 +146,11 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest { // test, should throw authentication exception final Authentication authenticate = underTestWithList.authenticate(token); - assertThat(authenticate.isAuthenticated()).isTrue(); + try { + assertThat(authenticate.isAuthenticated()).isTrue(); + fail("as source is not trusted."); + } catch (final InsufficientAuthenticationException e) { + + } } } diff --git a/hawkbit-repository/pom.xml b/hawkbit-repository/pom.xml index 7259262de..b70e00f28 100644 --- a/hawkbit-repository/pom.xml +++ b/hawkbit-repository/pom.xml @@ -67,6 +67,10 @@ org.hibernate hibernate-validator + + javax.validation + validation-api + com.google.guava guava diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/Constants.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/Constants.java index 5f3f772b0..ef0b70438 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/Constants.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/Constants.java @@ -11,9 +11,6 @@ package org.eclipse.hawkbit; /** * A constant class which holds only static constants used within the SP server. * - * - * - * */ public final class Constants { @@ -27,7 +24,7 @@ public final class Constants { public static final int MAX_ENTRIES_IN_STATEMENT = 999; /** - * constant class only private constructor. + * Constant class only private constructor. */ private Constants() { diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java index bf805f3dd..8ef427dcf 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java @@ -13,8 +13,8 @@ import java.util.Map; import org.eclipse.hawkbit.aspects.ExceptionMappingAspectHandler; import org.eclipse.hawkbit.repository.SystemManagement; -import org.eclipse.hawkbit.repository.model.helper.AfterTransactionCommitExecutorHolder; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; +import org.eclipse.hawkbit.repository.model.helper.AfterTransactionCommitExecutorHolder; import org.eclipse.hawkbit.repository.model.helper.CacheManagerHolder; import org.eclipse.hawkbit.repository.model.helper.SecurityTokenGeneratorHolder; import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder; @@ -127,23 +127,11 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { return new ExceptionMappingAspectHandler(); } - /* - * (non-Javadoc) - * - * @see org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration# - * createJpaVendorAdapter() - */ @Override protected AbstractJpaVendorAdapter createJpaVendorAdapter() { return new EclipseLinkJpaVendorAdapter(); } - /* - * (non-Javadoc) - * - * @see org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration# - * getVendorProperties() - */ @Override protected Map getVendorProperties() { diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/aspects/ExceptionMappingAspectHandler.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/aspects/ExceptionMappingAspectHandler.java index 75145778e..3824ae80f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/aspects/ExceptionMappingAspectHandler.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/aspects/ExceptionMappingAspectHandler.java @@ -167,11 +167,6 @@ public class ExceptionMappingAspectHandler implements Ordered { return null; } - /* - * (non-Javadoc) - * - * @see org.springframework.core.Ordered#getOrder() - */ @Override public int getOrder() { return 1; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java index b25a72fbc..0a19d2edb 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java @@ -20,7 +20,7 @@ import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent; import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.TargetRepository; -import org.eclipse.hawkbit.repository.model.BaseEntity; +import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.tenancy.TenantAware; @@ -31,7 +31,7 @@ import com.google.common.eventbus.EventBus; /** * An aspect implementation which wraps the necessary repository services for - * saving {@link BaseEntity}s to publish create or update events. + * saving {@link TenantAwareBaseEntity}s to publish create or update events. * * * diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityPropertyChangeListener.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityPropertyChangeListener.java index 8b632ee6a..28b5e677c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityPropertyChangeListener.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityPropertyChangeListener.java @@ -18,9 +18,9 @@ import org.eclipse.hawkbit.eventbus.event.RolloutGroupPropertyChangeEvent; import org.eclipse.hawkbit.eventbus.event.RolloutPropertyChangeEvent; import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.model.Action; -import org.eclipse.hawkbit.repository.model.BaseEntity; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; import org.eclipse.hawkbit.repository.model.helper.AfterTransactionCommitExecutorHolder; import org.eclipse.hawkbit.repository.model.helper.EventBusHolder; import org.eclipse.persistence.descriptors.DescriptorEvent; @@ -36,13 +36,7 @@ import com.google.common.eventbus.EventBus; * */ public class EntityPropertyChangeListener extends DescriptorEventAdapter { - /* - * (non-Javadoc) - * - * @see - * org.eclipse.persistence.descriptors.DescriptorEventAdapter#postInsert - * (org.eclipse.persistence.descriptors.DescriptorEvent) - */ + @Override public void postInsert(final DescriptorEvent event) { if (event.getObject().getClass().equals(Action.class)) { @@ -56,45 +50,30 @@ public class EntityPropertyChangeListener extends DescriptorEventAdapter { } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.persistence.descriptors.DescriptorEventAdapter#postUpdate - * (org.eclipse.persistence.descriptors.DescriptorEvent) - */ @Override public void postUpdate(final DescriptorEvent event) { if (event.getObject().getClass().equals(Action.class)) { - getAfterTransactionCommmitExecutor().afterCommit( - () -> getEventBus() - .post(new ActionPropertyChangeEvent((Action) event.getObject(), getChangeSet(Action.class, - event)))); + getAfterTransactionCommmitExecutor().afterCommit(() -> getEventBus().post( + new ActionPropertyChangeEvent((Action) event.getObject(), getChangeSet(Action.class, event)))); } else if (event.getObject().getClass().equals(Rollout.class)) { - getAfterTransactionCommmitExecutor().afterCommit( - () -> getEventBus().post( - new RolloutPropertyChangeEvent((Rollout) event.getObject(), getChangeSet(Rollout.class, - event)))); + getAfterTransactionCommmitExecutor().afterCommit(() -> getEventBus().post( + new RolloutPropertyChangeEvent((Rollout) event.getObject(), getChangeSet(Rollout.class, event)))); } else if (event.getObject().getClass().equals(RolloutGroup.class)) { getAfterTransactionCommmitExecutor().afterCommit( - () -> getEventBus().post( - new RolloutGroupPropertyChangeEvent((RolloutGroup) event.getObject(), getChangeSet( - RolloutGroup.class, event)))); + () -> getEventBus().post(new RolloutGroupPropertyChangeEvent((RolloutGroup) event.getObject(), + getChangeSet(RolloutGroup.class, event)))); } } - private Map.Values> getChangeSet( + private Map.Values> getChangeSet( final Class clazz, final DescriptorEvent event) { final T rolloutGroup = clazz.cast(event.getObject()); final ObjectChangeSet changeSet = ((UpdateObjectQuery) event.getQuery()).getObjectChangeSet(); - return changeSet - .getChanges() - .stream() - .filter(record -> record instanceof DirectToFieldChangeRecord) + return changeSet.getChanges().stream().filter(record -> record instanceof DirectToFieldChangeRecord) .map(record -> (DirectToFieldChangeRecord) record) - .collect( - Collectors.toMap(record -> record.getAttribute(), record -> new AbstractPropertyChangeEvent( - rolloutGroup, null).new Values(record.getOldValue(), record.getNewValue()))); + .collect(Collectors.toMap(record -> record.getAttribute(), + record -> new AbstractPropertyChangeEvent(rolloutGroup, null).new Values( + record.getOldValue(), record.getNewValue()))); } private AfterTransactionCommitExecutor getAfterTransactionCommmitExecutor() { diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractBaseEntityEvent.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractBaseEntityEvent.java index 7d0973f74..d27669ade 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractBaseEntityEvent.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractBaseEntityEvent.java @@ -8,18 +8,19 @@ */ package org.eclipse.hawkbit.eventbus.event; -import org.eclipse.hawkbit.repository.model.BaseEntity; +import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; /** - * An abstract definition class for {@link EntityEvent} for {@link BaseEntity}s, - * which holds the {@link BaseEntity}. + * An abstract definition class for {@link EntityEvent} for + * {@link TenantAwareBaseEntity}s, which holds the {@link TenantAwareBaseEntity} + * . * * * * @param - * the type of the {@link BaseEntity} + * the type of the {@link TenantAwareBaseEntity} */ -public abstract class AbstractBaseEntityEvent extends AbstractDistributedEvent +public abstract class AbstractBaseEntityEvent extends AbstractDistributedEvent implements EntityEvent { /** @@ -37,33 +38,16 @@ public abstract class AbstractBaseEntityEvent extends Abst this.entity = baseEntity; } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.eventbus.event.EntityEvent#getEntity() - */ @Override public E getEntity() { return entity; } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.eventbus.event.EntityEvent#getEntity(java.lang - * .Class) - */ @Override public T getEntity(final Class entityClass) { return entityClass.cast(entity); } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.eventbus.event.EntityEvent#getTenant() - */ @Override public String getTenant() { return entity.getTenant(); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractEntityBulkEvent.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractEntityBulkEvent.java index 0a0ce88ce..56f3e585a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractEntityBulkEvent.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractEntityBulkEvent.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.eventbus.event; import java.util.Arrays; import java.util.List; -import org.eclipse.hawkbit.repository.model.BaseEntity; +import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; /** * @@ -19,7 +19,7 @@ import org.eclipse.hawkbit.repository.model.BaseEntity; * * @param */ -public abstract class AbstractEntityBulkEvent implements EntityBulkEvent { +public abstract class AbstractEntityBulkEvent implements EntityBulkEvent { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java index 8a596eeb5..795f6ff88 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java @@ -10,14 +10,14 @@ package org.eclipse.hawkbit.eventbus.event; import java.util.Map; -import org.eclipse.hawkbit.repository.model.BaseEntity; +import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; /** * Property change event. * * @param */ -public class AbstractPropertyChangeEvent extends AbstractBaseEntityEvent { +public class AbstractPropertyChangeEvent extends AbstractBaseEntityEvent { private static final long serialVersionUID = -3671601415138242311L; private final transient Map changeSet; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagAssigmentResultEvent.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagAssigmentResultEvent.java index 9a8a485b4..e10b9a51f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagAssigmentResultEvent.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagAssigmentResultEvent.java @@ -8,14 +8,14 @@ */ package org.eclipse.hawkbit.eventbus.event; -import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult; +import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; /** * A event for assignment target tag. */ public class DistributionSetTagAssigmentResultEvent { - private final DistributionSetTagAssigmentResult assigmentResult; + private final DistributionSetTagAssignmentResult assigmentResult; /** * Constructor. @@ -23,11 +23,11 @@ public class DistributionSetTagAssigmentResultEvent { * @param assigmentResult * the assignment result- */ - public DistributionSetTagAssigmentResultEvent(final DistributionSetTagAssigmentResult assigmentResult) { + public DistributionSetTagAssigmentResultEvent(final DistributionSetTagAssignmentResult assigmentResult) { this.assigmentResult = assigmentResult; } - public DistributionSetTagAssigmentResult getAssigmentResult() { + public DistributionSetTagAssignmentResult getAssigmentResult() { return assigmentResult; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/EntityBulkEvent.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/EntityBulkEvent.java index 2004d3017..eac1b6bb9 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/EntityBulkEvent.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/EntityBulkEvent.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.eventbus.event; import java.io.Serializable; import java.util.List; -import org.eclipse.hawkbit.repository.model.BaseEntity; +import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; /** * An event interface which declares event types that an entities has been @@ -20,7 +20,7 @@ import org.eclipse.hawkbit.repository.model.BaseEntity; * @param * the entity type */ -public interface EntityBulkEvent extends Serializable, Event { +public interface EntityBulkEvent extends Serializable, Event { /** * A typesafe way to retrieve the the entities from the event, which might diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagAssigmentResultEvent.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagAssigmentResultEvent.java index 405595de0..6bdc3aebd 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagAssigmentResultEvent.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagAssigmentResultEvent.java @@ -8,14 +8,14 @@ */ package org.eclipse.hawkbit.eventbus.event; -import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult; +import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; /** * A event for assignment target tag. */ public class TargetTagAssigmentResultEvent { - private final TargetTagAssigmentResult assigmentResult; + private final TargetTagAssignmentResult assigmentResult; /** * Constructor. @@ -23,11 +23,11 @@ public class TargetTagAssigmentResultEvent { * @param assigmentResult * the assignment result- */ - public TargetTagAssigmentResultEvent(final TargetTagAssigmentResult assigmentResult) { + public TargetTagAssigmentResultEvent(final TargetTagAssignmentResult assigmentResult) { this.assigmentResult = assigmentResult; } - public TargetTagAssigmentResult getAssigmentResult() { + public TargetTagAssignmentResult getAssigmentResult() { return assigmentResult; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/BaseEntityRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/BaseEntityRepository.java index 539d20f71..2b4de2b81 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/BaseEntityRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/BaseEntityRepository.java @@ -10,14 +10,14 @@ package org.eclipse.hawkbit.repository; import java.io.Serializable; -import org.eclipse.hawkbit.repository.model.BaseEntity; +import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.repository.NoRepositoryBean; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.transaction.annotation.Transactional; /** - * Command repository operations for all {@link BaseEntity}s. + * Command repository operations for all {@link TenantAwareBaseEntity}s. * * * @@ -29,11 +29,11 @@ import org.springframework.transaction.annotation.Transactional; */ @NoRepositoryBean @Transactional(readOnly = true) -public interface BaseEntityRepository +public interface BaseEntityRepository extends PagingAndSortingRepository { /** - * Deletes all {@link BaseEntity} of a given tenant. + * Deletes all {@link TenantAwareBaseEntity} of a given tenant. * * @param tenant * to delete data from diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java index 7131bbe0a..0bb94bd72 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java @@ -376,16 +376,9 @@ public class ControllerManagement { switch (actionStatus.getStatus()) { case ERROR: mergedTarget = deploymentManagement.updateTargetInfo(mergedTarget, TargetUpdateStatus.ERROR, false); - // set action inactive - mergedAction.setActive(false); - mergedAction.setStatus(Status.ERROR); - mergedTarget.setAssignedDistributionSet(null); - targetManagement.updateTarget(mergedTarget); + handleErrorOnAction(mergedAction, mergedTarget); break; case FINISHED: - // set action inactive - mergedAction.setActive(false); - mergedAction.setStatus(Status.FINISHED); handleFinishedAndStoreInTargetStatus(mergedTarget, mergedAction); break; case CANCELED: @@ -404,6 +397,13 @@ public class ControllerManagement { return actionRepository.save(mergedAction); } + private void handleErrorOnAction(final Action mergedAction, final Target mergedTarget) { + mergedAction.setActive(false); + mergedAction.setStatus(Status.ERROR); + mergedTarget.setAssignedDistributionSet(null); + targetManagement.updateTarget(mergedTarget); + } + private void checkForToManyStatusEntries(final Action action) { if (securityProperties.getDos().getMaxStatusEntriesPerAction() > 0) { @@ -420,6 +420,8 @@ public class ControllerManagement { } private void handleFinishedAndStoreInTargetStatus(final Target target, final Action action) { + action.setActive(false); + action.setStatus(Status.FINISHED); final TargetInfo targetInfo = target.getTargetInfo(); final DistributionSet ds = entityManager.merge(action.getDistributionSet()); targetInfo.setInstalledDistributionSet(ds); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java index 3e61e4499..8b1df00da 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java @@ -55,7 +55,7 @@ public class DistributionSetAssignmentResult extends AssignmentResult { * @return the assignedTargets */ public List getAssignedTargets() { - return targetManagement.findTargetsByControllerID(assignedTargets); + return targetManagement.findTargetByControllerID(assignedTargets); } /** diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java index 8b07c9bf8..8bee7c703 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java @@ -38,7 +38,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata_; import org.eclipse.hawkbit.repository.model.DistributionSetTag; -import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult; +import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.DistributionSetTypeElement; import org.eclipse.hawkbit.repository.model.DistributionSet_; @@ -68,9 +68,6 @@ import com.google.common.eventbus.EventBus; /** * Business facade for managing the {@link DistributionSet}s. * - * - * - * */ @Transactional(readOnly = true) @Validated @@ -140,15 +137,15 @@ public class DistributionSetManagement { * @param sets * to toggle for * @param tag - * to toogle - * @return {@link DistributionSetTagAssigmentResult} with all metadata of + * to toggle + * @return {@link DistributionSetTagAssignmentResult} with all meta data of * the assignment outcome. */ @Modifying @Transactional @NotNull @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public DistributionSetTagAssigmentResult toggleTagAssignment(@NotEmpty final List sets, + public DistributionSetTagAssignmentResult toggleTagAssignment(@NotEmpty final List sets, @NotNull final DistributionSetTag tag) { return toggleTagAssignment(sets.stream().map(ds -> ds.getId()).collect(Collectors.toList()), tag.getName()); } @@ -163,44 +160,44 @@ public class DistributionSetManagement { * to toggle for * @param tagName * to toggle - * @return {@link DistributionSetTagAssigmentResult} with all metadata of + * @return {@link DistributionSetTagAssignmentResult} with all meta data of * the assignment outcome. */ @Modifying @Transactional @NotNull @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public DistributionSetTagAssigmentResult toggleTagAssignment(@NotEmpty final Collection dsIds, + public DistributionSetTagAssignmentResult toggleTagAssignment(@NotEmpty final Collection dsIds, @NotNull final String tagName) { final Iterable sets = findDistributionSetListWithDetails(dsIds); final DistributionSetTag myTag = tagManagement.findDistributionSetTag(tagName); - DistributionSetTagAssigmentResult result = null; - final List allDSs = new ArrayList<>(); + DistributionSetTagAssignmentResult result; + final List toBeChangedDSs = new ArrayList<>(); for (final DistributionSet set : sets) { if (set.getTags().add(myTag)) { - allDSs.add(set); + toBeChangedDSs.add(set); } } - // unassigment case - if (allDSs.isEmpty()) { + // un-assignment case + if (toBeChangedDSs.isEmpty()) { for (final DistributionSet set : sets) { if (set.getTags().remove(myTag)) { - allDSs.add(set); + toBeChangedDSs.add(set); } } - result = new DistributionSetTagAssigmentResult(dsIds.size() - allDSs.size(), 0, allDSs.size(), - Collections.emptyList(), distributionSetRepository.save(allDSs), myTag); + result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), 0, + toBeChangedDSs.size(), Collections.emptyList(), distributionSetRepository.save(toBeChangedDSs), + myTag); } else { - result = new DistributionSetTagAssigmentResult(dsIds.size() - allDSs.size(), allDSs.size(), 0, - distributionSetRepository.save(allDSs), Collections.emptyList(), myTag); + result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), toBeChangedDSs.size(), + 0, distributionSetRepository.save(toBeChangedDSs), Collections.emptyList(), myTag); } - final DistributionSetTagAssigmentResult resultAssignment = result; - afterCommit - .afterCommit(() -> eventBus.post(new DistributionSetTagAssigmentResultEvent(resultAssignment))); + final DistributionSetTagAssignmentResult resultAssignment = result; + afterCommit.afterCommit(() -> eventBus.post(new DistributionSetTagAssigmentResultEvent(resultAssignment))); // no reason to persist the tag entityManager.detach(myTag); @@ -352,6 +349,9 @@ public class DistributionSetManagement { public List createDistributionSets(@NotNull final Iterable distributionSets) { for (final DistributionSet ds : distributionSets) { prepareDsSave(ds); + if (ds.getType() == null) { + ds.setType(systemManagement.getTenantMetadata().getDefaultDsType()); + } } return distributionSetRepository.save(distributionSets); } @@ -437,7 +437,7 @@ public class DistributionSetManagement { * @param spec * of the search * @param pageable - * parametsr for paging + * parameter for paging * * @return the found {@link SoftwareModuleType}s */ @@ -762,7 +762,7 @@ public class DistributionSetManagement { if (distributionSetMetadataRepository.exists(metadata.getId())) { throwMetadataKeyAlreadyExists(metadata.getId().getKey()); } - // merge base software module so optLockRevision gets updated and audit + // merge base distribution set so optLockRevision gets updated and audit // log written because // modifying metadata is modifying the base distribution set itself for // auditing purposes. @@ -870,7 +870,7 @@ public class DistributionSetManagement { cb) -> cb.and( cb.equal(root.get(DistributionSetMetadata_.distributionSet) .get(DistributionSet_.id), distributionSetId), - spec.toPredicate(root, query, cb)), + spec.toPredicate(root, query, cb)), pageable); } @@ -916,7 +916,7 @@ public class DistributionSetManagement { @Transactional @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) public List createDistributionSetTypes(@NotNull final Collection types) { - return types.stream().map(type -> createDistributionSetType(type)).collect(Collectors.toList()); + return types.stream().map(this::createDistributionSetType).collect(Collectors.toList()); } /** @@ -1060,7 +1060,7 @@ public class DistributionSetManagement { afterCommit.afterCommit(() -> { - final DistributionSetTagAssigmentResult result = new DistributionSetTagAssigmentResult(0, save.size(), 0, + final DistributionSetTagAssignmentResult result = new DistributionSetTagAssignmentResult(0, save.size(), 0, save, Collections.emptyList(), tag); eventBus.post(new DistributionSetTagAssigmentResultEvent(result)); }); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/NoCountPagingRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/NoCountPagingRepository.java index 79f54a3f0..0624f269a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/NoCountPagingRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/NoCountPagingRepository.java @@ -29,9 +29,6 @@ import org.springframework.stereotype.Repository; * Workaround as spring data does not provide a {@link Slice} based * {@link JpaRepository#findAll()}. * - * - * - * */ @Repository public class NoCountPagingRepository { @@ -104,15 +101,6 @@ public class NoCountPagingRepository { super(domainClass, em); } - /* - * (non-Javadoc) - * - * @see - * org.springframework.data.jpa.repository.support.SimpleJpaRepository# - * readPage(javax.persistence .TypedQuery, - * org.springframework.data.domain.Pageable, - * org.springframework.data.jpa.domain.Specification) - */ @Override protected Page readPage(final TypedQuery query, final Pageable pageable, final Specification spec) { query.setFirstResult(pageable.getOffset()); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java index eab926b4b..b95664d8f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java @@ -458,11 +458,6 @@ public class ReportManagement { return name; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { final int prime = 31; @@ -471,11 +466,6 @@ public class ReportManagement { return result; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(final Object obj) { // NOSONAR - as this is // generated @@ -499,11 +489,6 @@ public class ReportManagement { return true; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ @Override public String toString() { return "DSName [name=" + name + "]"; @@ -523,9 +508,6 @@ public class ReportManagement { /** * Return DateTypes. - * - * - * */ public static final class DateTypes implements Serializable { /** @@ -585,12 +567,6 @@ public class ReportManagement { private static final long serialVersionUID = 1L; private static final String DATE_PATTERN = "yyyy-MM"; - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.repository.ReportManagement.DateType# - * format(java. lang.String) - */ @Override public LocalDate format(final String s) { final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_PATTERN); @@ -598,23 +574,11 @@ public class ReportManagement { return ym.atDay(1); } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.repository.ReportManagement.DateType# - * h2Format() - */ @Override public String h2Format() { return DATE_PATTERN; } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.repository.ReportManagement.DateType# - * mySqlFormat( ) - */ @Override public String mySqlFormat() { return "%Y-%m"; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java index 1f610d29c..384353b8e 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java @@ -59,11 +59,7 @@ import com.google.common.base.Strings; import com.google.common.collect.Sets; /** - * Business facade for managing the deployable {@link SoftwareModule}s. - * - * - * - * + * Business facade for managing {@link SoftwareModule}s. * */ @Transactional(readOnly = true) @@ -99,7 +95,7 @@ public class SoftwareManagement { private ArtifactManagement artifactManagement; /** - * Updates existing {@link SoftwareModule}. Updateable values are + * Updates existing {@link SoftwareModule}. Update-able values are * {@link SoftwareModule#getDescription()} * {@link SoftwareModule#getVendor()}. * @@ -119,17 +115,21 @@ public class SoftwareManagement { final SoftwareModule module = softwareModuleRepository.findOne(sm.getId()); + boolean updated = false; if (null == sm.getDescription() || !sm.getDescription().equals(module.getDescription())) { module.setDescription(sm.getDescription()); + updated = true; } if (null == sm.getVendor() || !sm.getVendor().equals(module.getVendor())) { module.setVendor(sm.getVendor()); + updated = true; } - return softwareModuleRepository.save(module); + + return updated ? softwareModuleRepository.save(module) : module; } /** - * Updates existing {@link SoftwareModuleType}. Updatable value is + * Updates existing {@link SoftwareModuleType}. Update-able value is * {@link SoftwareModuleType#getDescription()} and * {@link SoftwareModuleType#getColour()}. * @@ -145,13 +145,16 @@ public class SoftwareManagement { final SoftwareModuleType type = softwareModuleTypeRepository.findOne(sm.getId()); + boolean updated = false; if (sm.getDescription() != null && !sm.getDescription().equals(type.getDescription())) { type.setDescription(sm.getDescription()); + updated = true; } if (sm.getColour() != null && !sm.getColour().equals(type.getColour())) { type.setColour(sm.getColour()); + updated = true; } - return softwareModuleTypeRepository.save(type); + return updated ? softwareModuleTypeRepository.save(type) : type; } /** @@ -256,19 +259,21 @@ public class SoftwareManagement { } /** - * retrieves {@link SoftwareModule}s by their name AND version. + * retrieves {@link SoftwareModule} by their name AND version AND type.. * * @param name * of the {@link SoftwareModule} * @param version * of the {@link SoftwareModule} - * @return the found {@link SoftwareModule}s + * @param type + * of the {@link SoftwareModule} + * @return the found {@link SoftwareModule} or null */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public List findSoftwareModuleByNameAndVersion(@NotEmpty final String name, - @NotEmpty final String version) { + public SoftwareModule findSoftwareModuleByNameAndVersion(@NotEmpty final String name, + @NotEmpty final String version, @NotNull final SoftwareModuleType type) { - return softwareModuleRepository.findByNameAndVersion(name, version); + return softwareModuleRepository.findOneByNameAndVersionAndType(name, version, type); } /** @@ -491,21 +496,27 @@ public class SoftwareManagement { /** * Filter {@link SoftwareModule}s with given * {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()} - * and {@link SoftwareModule#getType()} that are not marked as deleted. + * search text and {@link SoftwareModule#getType()} that are not marked as + * deleted and sort them by means of given distribution set related modules + * on top of the list. + * + * After that the modules are sorted by {@link SoftwareModule#getName()} and + * {@link SoftwareModule#getVersion()} in ascending order. * * @param pageable * page parameter * @param orderByDistributionId - * the ID of distribution set to be order by + * the ID of distribution set to be ordered on top * @param searchText - * to be filtered as "like" on {@link SoftwareModule#getName()} + * filtered as "like" on {@link SoftwareModule#getName()} * @param type - * to be filtered as "like" on {@link SoftwareModule#getType()} + * filtered as "equal" on {@link SoftwareModule#getType()} * @return the page of found {@link SoftwareModule} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Slice findSoftwareModuleOrderByDistribution(@NotNull final Pageable pageable, - @NotNull final Long orderByDistributionId, final String searchText, final SoftwareModuleType type) { + public Slice findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( + @NotNull final Pageable pageable, @NotNull final Long orderByDistributionId, final String searchText, + final SoftwareModuleType type) { final List resultList = new ArrayList<>(); final int pageSize = pageable.getPageSize(); @@ -522,7 +533,7 @@ public class SoftwareManagement { assignedRoot, assignedQuery, cb, cb.equal(assignedDsJoin.get(DistributionSet_.id), orderByDistributionId)); // if we have some predicates then add it to the where clause of the - // multiselect + // multi select assignedQuery.where(specPredicate); assignedQuery.orderBy(cb.asc(assignedRoot.get(SoftwareModule_.name)), cb.asc(assignedRoot.get(SoftwareModule_.version))); @@ -546,7 +557,7 @@ public class SoftwareManagement { unassignedQuery.distinct(true); final Root unassignedRoot = unassignedQuery.from(SoftwareModule.class); - Predicate[] unassignedSpec = null; + Predicate[] unassignedSpec; if (!assignedSoftwareModules.isEmpty()) { unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, type), unassignedRoot, unassignedQuery, cb, cb.not(unassignedRoot.get(SoftwareModule_.id) @@ -709,8 +720,8 @@ public class SoftwareManagement { @Modifying @Transactional @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - public List createSoftwareModuleTypes(@NotNull final Collection types) { - return types.stream().map(type -> createSoftwareModuleType(type)).collect(Collectors.toList()); + public List createSoftwareModuleType(@NotNull final Collection types) { + return types.stream().map(this::createSoftwareModuleType).collect(Collectors.toList()); } /** @@ -826,7 +837,7 @@ public class SoftwareManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) public SoftwareModuleMetadata updateSoftwareModuleMetadata(@NotNull final SoftwareModuleMetadata metadata) { // check if exists otherwise throw entity not found exception - findOne(metadata.getId()); + findSoftwareModuleMetadata(metadata.getId()); // touch it to update the lock revision because we are modifying the // software module // indirectly @@ -884,7 +895,7 @@ public class SoftwareManagement { cb) -> cb.and( cb.equal(root.get(SoftwareModuleMetadata_.softwareModule) .get(SoftwareModule_.id), softwareModuleId), - spec.toPredicate(root, query, cb)), + spec.toPredicate(root, query, cb)), pageable); } @@ -899,7 +910,7 @@ public class SoftwareManagement { * in case the meta data does not exists for the given key */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public SoftwareModuleMetadata findOne(@NotNull final SwMetadataCompositeKey id) { + public SoftwareModuleMetadata findSoftwareModuleMetadata(@NotNull final SwMetadataCompositeKey id) { final SoftwareModuleMetadata findOne = softwareModuleMetadataRepository.findOne(id); if (findOne == null) { throw new EntityNotFoundException("Metadata with key '" + id.getKey() + "' does not exist"); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleRepository.java index ccadb028a..d70e8226f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleRepository.java @@ -43,15 +43,19 @@ public interface SoftwareModuleRepository Long countByType(SoftwareModuleType type); /** - * Retrieves {@link SoftwareModule}s by filtering on name AND version. + * Retrieves {@link SoftwareModule} by filtering on name AND version AND + * type (which is unique per tenant. * * @param name * to be filtered on * @param version * to be filtered on - * @return the found {@link SoftwareModule}s with the given name AND verion + * @param type + * to be filtered on + * @return the found {@link SoftwareModule} with the given name AND version + * AND type */ - List findByNameAndVersion(String name, String version); + SoftwareModule findOneByNameAndVersionAndType(String name, String version, SoftwareModuleType type); /** * deletes the {@link SoftwareModule}s with the given IDs. @@ -81,6 +85,8 @@ public interface SoftwareModuleRepository Page findByAssignedTo(Pageable pageable, DistributionSet set); /** + * + * * @param set * to search for * @return all {@link SoftwareModule}s that are assigned to given diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java index 77b48a3cd..5577e1d61 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java @@ -310,8 +310,6 @@ public class SystemManagement { } private DistributionSetType createStandardSoftwareDataSetup() { - - // Edge Controller Linux standard setup final SoftwareModuleType eclApp = softwareModuleTypeRepository.save(new SoftwareModuleType("application", "ECL Application", "Edge Controller Linux base application type", 1)); final SoftwareModuleType eclOs = softwareModuleTypeRepository @@ -327,13 +325,11 @@ public class SystemManagement { "Standard Edge Controller Linux distribution set type. OS only.").addMandatoryModuleType(eclOs) .addOptionalModuleType(eclApp)); - final DistributionSetType defaultType = distributionSetTypeRepository + return distributionSetTypeRepository .save(new DistributionSetType("ecl_os_app_jvm", "OS with optional app and jvm", "Standard Edge Controller Linux distribution set type. OS with optional application.") .addMandatoryModuleType(eclOs).addOptionalModuleType(eclApp) .addOptionalModuleType(eclJvm)); - - return defaultType; } /** @@ -343,18 +339,8 @@ public class SystemManagement { * default types we need to use the tenant the current tenant which is * currently created and not the one currently in the {@link TenantAware}. * - * - * */ private class CurrentTenantKeyGenerator implements KeyGenerator { - - /* - * (non-Javadoc) - * - * @see - * org.springframework.cache.interceptor.KeyGenerator#generate(java.lang - * .Object, java.lang.reflect.Method, java.lang.Object[]) - */ @Override public Object generate(final Object target, final Method method, final Object... params) { final String initialTenantCreation = createInitialTenant.get(); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java index e790d0a5e..0e0e474b2 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java @@ -43,7 +43,7 @@ import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetInfo_; import org.eclipse.hawkbit.repository.model.TargetTag; -import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult; +import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.Target_; import org.eclipse.hawkbit.repository.rsql.RSQLUtility; @@ -53,7 +53,6 @@ import org.hibernate.validator.constraints.NotEmpty; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.data.domain.SliceImpl; @@ -74,8 +73,6 @@ import com.google.common.eventbus.EventBus; /** * Business service facade for managing {@link Target}s. * - * - * */ @Transactional(readOnly = true) @Validated @@ -157,7 +154,7 @@ public class TargetManagement { * @return List of found{@link Target}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public List findTargetsByControllerID(@NotEmpty final Collection controllerIDs) { + public List findTargetByControllerID(@NotEmpty final Collection controllerIDs) { return targetRepository.findAll(TargetSpecifications.byControllerIdWithStatusAndAssignedInJoin(controllerIDs)); } @@ -333,10 +330,10 @@ public class TargetManagement { } /** - * retrieves {@link Target}s by the assigned {@link DistributionSet} without + * Retrieves {@link Target}s by the assigned {@link DistributionSet} without * details, i.e. NO {@link Target#getTags()} and - * {@link Target#getActiveActions()} possible including the filtering based - * on the given {@code spec}. + * {@link Target#getActiveActions()} possible including additional filtering + * based on the given {@code spec}. * * @param distributionSetID * the ID of the {@link DistributionSet} @@ -376,7 +373,8 @@ public class TargetManagement { /** * retrieves {@link Target}s by the installed {@link DistributionSet}without * details, i.e. NO {@link Target#getTags()} and - * {@link Target#getActiveActions()} possible. + * {@link Target#getActiveActions()} possible including additional filtering + * based on the given {@code spec}. * * @param distributionSetId * the ID of the {@link DistributionSet} @@ -492,7 +490,7 @@ public class TargetManagement { if (!Strings.isNullOrEmpty(searchText)) { specList.add(TargetSpecifications.likeNameOrDescriptionOrIp(searchText)); } - if (selectTargetWithNoTag || (tagNames != null && tagNames.length > 0)) { + if (selectTargetWithNoTag != null && (selectTargetWithNoTag || (tagNames != null && tagNames.length > 0))) { specList.add(TargetSpecifications.hasTags(tagNames, selectTargetWithNoTag)); } return specList; @@ -536,7 +534,7 @@ public class TargetManagement { @Transactional @NotNull @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - public TargetTagAssigmentResult toggleTagAssignment(@NotEmpty final List targets, + public TargetTagAssignmentResult toggleTagAssignment(@NotEmpty final List targets, @NotNull final TargetTag tag) { return toggleTagAssignment( targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), tag.getName()); @@ -558,7 +556,7 @@ public class TargetManagement { @Transactional @NotNull @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - public TargetTagAssigmentResult toggleTagAssignment(@NotEmpty final Collection targetIds, + public TargetTagAssignmentResult toggleTagAssignment(@NotEmpty final Collection targetIds, @NotNull final String tagName) { final TargetTag tag = targetTagRepository.findByNameEquals(tagName); final List alreadyAssignedTargets = targetRepository.findByTagNameAndControllerIdIn(tagName, targetIds); @@ -568,7 +566,7 @@ public class TargetManagement { // all are already assigned -> unassign if (alreadyAssignedTargets.size() == allTargets.size()) { alreadyAssignedTargets.forEach(target -> target.getTags().remove(tag)); - final TargetTagAssigmentResult result = new TargetTagAssigmentResult(0, 0, alreadyAssignedTargets.size(), + final TargetTagAssignmentResult result = new TargetTagAssignmentResult(0, 0, alreadyAssignedTargets.size(), Collections.emptyList(), alreadyAssignedTargets, tag); afterCommit.afterCommit(() -> eventBus.post(new TargetTagAssigmentResultEvent(result))); @@ -578,7 +576,7 @@ public class TargetManagement { allTargets.removeAll(alreadyAssignedTargets); // some or none are assigned -> assign allTargets.forEach(target -> target.getTags().add(tag)); - final TargetTagAssigmentResult result = new TargetTagAssigmentResult(alreadyAssignedTargets.size(), + final TargetTagAssignmentResult result = new TargetTagAssignmentResult(alreadyAssignedTargets.size(), allTargets.size(), 0, targetRepository.save(allTargets), Collections.emptyList(), tag); afterCommit.afterCommit(() -> eventBus.post(new TargetTagAssigmentResultEvent(result))); @@ -609,7 +607,7 @@ public class TargetManagement { final List save = targetRepository.save(allTargets); afterCommit.afterCommit(() -> { - final TargetTagAssigmentResult assigmentResult = new TargetTagAssigmentResult(0, save.size(), 0, save, + final TargetTagAssignmentResult assigmentResult = new TargetTagAssignmentResult(0, save.size(), 0, save, Collections.emptyList(), tag); eventBus.post(new TargetTagAssigmentResultEvent(assigmentResult)); }); @@ -622,7 +620,7 @@ public class TargetManagement { final List save = targetRepository.save(targets); afterCommit.afterCommit(() -> { - final TargetTagAssigmentResult assigmentResult = new TargetTagAssigmentResult(0, 0, save.size(), + final TargetTagAssignmentResult assigmentResult = new TargetTagAssignmentResult(0, 0, save.size(), Collections.emptyList(), save, tag); eventBus.post(new TargetTagAssigmentResultEvent(assigmentResult)); }); @@ -812,14 +810,12 @@ public class TargetManagement { } /** - * finds all {@link Target#getControllerId()} for all the given parameters. + * Finds all targets for all the given parameters but returns not the full + * target but {@link TargetIdName}. * * @param pageRequest * the pageRequest to enhance the query for paging and sorting - * @param filterByDistributionId - * to find targets having the {@link DistributionSet} as - * installed or assigned. Set to null in case this - * is not required. + * * @param filterByStatus * find targets having this {@link TargetUpdateStatus}s. Set to * null in case this is not required. @@ -827,28 +823,38 @@ public class TargetManagement { * to find targets having the text anywhere in name or * description. Set null in case this is not * required. + * @param installedOrAssignedDistributionSetId + * to find targets having the {@link DistributionSet} as + * installed or assigned. Set to null in case this + * is not required. * @param filterByTagNames * to find targets which are having any one in this tag names. * Set null in case this is not required. * @param selectTargetWithNoTag * flag to select targets with no tag assigned * - * @return the found {@link Target}s + * @return the found {@link TargetIdName}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public List findAllTargetIdsByFilters(final PageRequest pageRequest, - final Long filterByDistributionId, final Collection filterByStatus, - final String filterBySearchText, final Boolean selectTargetWithNoTag, final String... filterByTagNames) { + public List findAllTargetIdsByFilters(@NotNull final Pageable pageRequest, + final Collection filterByStatus, final String filterBySearchText, + final Long installedOrAssignedDistributionSetId, final Boolean selectTargetWithNoTag, + final String... filterByTagNames) { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final CriteriaQuery query = cb.createQuery(Object[].class); final Root targetRoot = query.from(Target.class); List resultList; + + String sortProperty = Target_.id.getName(); + if (pageRequest.getSort() != null && pageRequest.getSort().iterator().hasNext()) { + sortProperty = pageRequest.getSort().iterator().next().getProperty(); + } + final CriteriaQuery multiselect = query.multiselect(targetRoot.get(Target_.id), - targetRoot.get(Target_.controllerId), targetRoot.get(Target_.name), - targetRoot.get(pageRequest.getSort().iterator().next().getProperty())); + targetRoot.get(Target_.controllerId), targetRoot.get(Target_.name), targetRoot.get(sortProperty)); final Predicate[] specificationsForMultiSelect = specificationsToPredicate( - buildSpecificationList(filterByStatus, filterBySearchText, filterByDistributionId, + buildSpecificationList(filterByStatus, filterBySearchText, installedOrAssignedDistributionSetId, selectTargetWithNoTag, false, filterByTagNames), targetRoot, multiselect, cb); @@ -864,24 +870,29 @@ public class TargetManagement { } /** - * Finds all {@link Target#getControllerId()} for all the given parameter - * {@link TargetFilterQuery}. + * Finds all targets for all the given parameter {@link TargetFilterQuery} + * and returns not the full target but {@link TargetIdName}. * * @param pageRequest * the pageRequest to enhance the query for paging and sorting * @param targetFilterQuery * {@link TargetFilterQuery} - * @return the found {@link Target}s + * @return the found {@link TargetIdName}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public List findAllTargetIdsByTargetFilterQuery(final PageRequest pageRequest, + public List findAllTargetIdsByTargetFilterQuery(final Pageable pageRequest, @NotNull final TargetFilterQuery targetFilterQuery) { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final CriteriaQuery query = cb.createQuery(Object[].class); final Root targetRoot = query.from(Target.class); + + String sortProperty = Target_.id.getName(); + if (pageRequest.getSort() != null && pageRequest.getSort().iterator().hasNext()) { + sortProperty = pageRequest.getSort().iterator().next().getProperty(); + } + final CriteriaQuery multiselect = query.multiselect(targetRoot.get(Target_.id), - targetRoot.get(Target_.controllerId), targetRoot.get(Target_.name), - targetRoot.get(pageRequest.getSort().iterator().next().getProperty())); + targetRoot.get(Target_.controllerId), targetRoot.get(Target_.name), targetRoot.get(sortProperty)); final Specification spec = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class); final List> specList = new ArrayList<>(); @@ -1074,7 +1085,7 @@ public class TargetManagement { return targetRepository.count(specs); } - private List getTargetIdNameResultSet(final PageRequest pageRequest, final CriteriaBuilder cb, + private List getTargetIdNameResultSet(final Pageable pageRequest, final CriteriaBuilder cb, final Root targetRoot, final CriteriaQuery multiselect) { List resultList; if (pageRequest.getSort() != null) { diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java index f6b6afcfc..e311cf288 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java @@ -150,7 +150,7 @@ public class TenantConfigurationManagement implements EnvironmentAware { * @param configurationKey * the key of the configuration * @return the converted configuration value either from the tenant specific - * configuration stored or from the fallback default values or + * configuration stored or from the fall back default values or * {@code null} in case key has not been configured and not default * value exists * @throws TenantConfigurationValidatorException diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationRepository.java index d8973f275..dd741697b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationRepository.java @@ -16,9 +16,6 @@ import org.springframework.transaction.annotation.Transactional; /** * The spring-data repository for the entity {@link TenantConfiguration}. * - * - * - * */ @Transactional(readOnly = true) public interface TenantConfigurationRepository extends BaseEntityRepository { @@ -32,11 +29,6 @@ public interface TenantConfigurationRepository extends BaseEntityRepository findAll(); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantKeyGenerator.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantKeyGenerator.java index d0a2b4ea7..3265b622c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantKeyGenerator.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantKeyGenerator.java @@ -18,9 +18,6 @@ import org.springframework.stereotype.Service; /** * {@link KeyGenerator} for tenant related caches. * - * - * - * */ @Service public class TenantKeyGenerator implements KeyGenerator { @@ -28,13 +25,6 @@ public class TenantKeyGenerator implements KeyGenerator { @Autowired private TenantAware tenantAware; - /* - * (non-Javadoc) - * - * @see - * org.springframework.cache.interceptor.KeyGenerator#generate(java.lang. - * Object, java.lang.reflect.Method, java.lang.Object[]) - */ @Override public Object generate(final Object target, final Method method, final Object... params) { return tenantAware.getCurrentTenant().toUpperCase(); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java index c19b947de..eedb36037 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java @@ -50,9 +50,9 @@ import org.eclipse.persistence.annotations.CascadeOnDelete; @Index(name = "sp_idx_action_prim", columnList = "tenant,id") }) @NamedEntityGraphs({ @NamedEntityGraph(name = "Action.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }), @NamedEntityGraph(name = "Action.all", attributeNodes = { @NamedAttributeNode("distributionSet"), - @NamedAttributeNode(value = "target", subgraph = "target.ds") }, subgraphs = @NamedSubgraph(name = "target.ds", attributeNodes = @NamedAttributeNode("assignedDistributionSet") ) ) }) + @NamedAttributeNode(value = "target", subgraph = "target.ds") }, subgraphs = @NamedSubgraph(name = "target.ds", attributeNodes = @NamedAttributeNode("assignedDistributionSet"))) }) @Entity -public class Action extends BaseEntity implements Comparable { +public class Action extends TenantAwareBaseEntity { private static final long serialVersionUID = 1L; /** @@ -64,11 +64,11 @@ public class Action extends BaseEntity implements Comparable { * the {@link DistributionSet} which should be installed by this action. */ @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "distribution_set", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_ds") ) + @JoinColumn(name = "distribution_set", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_ds")) private DistributionSet distributionSet; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "target", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_target") ) + @JoinColumn(name = "target", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_target")) private Target target; @Column(name = "active") @@ -90,11 +90,11 @@ public class Action extends BaseEntity implements Comparable { private List actionStatus; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "rolloutgroup", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_rolloutgroup") ) + @JoinColumn(name = "rolloutgroup", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_rolloutgroup")) private RolloutGroup rolloutGroup; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "rollout", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_rollout") ) + @JoinColumn(name = "rollout", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_rollout")) private Rollout rollout; /** @@ -127,55 +127,30 @@ public class Action extends BaseEntity implements Comparable { return status == Status.CANCELING || status == Status.CANCELED; } - /** - * @param active - * the active to set - */ public void setActive(final boolean active) { this.active = active; } - /** - * @return the status - */ public Status getStatus() { return status; } - /** - * @param status - * the status to set - */ public void setStatus(final Status status) { this.status = status; } - /** - * @return the downloadProgressPercent - */ public int getDownloadProgressPercent() { return downloadProgressPercent; } - /** - * @param downloadProgressPercent - * the downloadProgressPercent to set - */ public void setDownloadProgressPercent(final int downloadProgressPercent) { this.downloadProgressPercent = downloadProgressPercent; } - /** - * @return the active - */ public boolean isActive() { return active; } - /** - * @param actionType - * the actionType to set - */ public void setActionType(final ActionType actionType) { this.actionType = actionType; } @@ -187,81 +162,42 @@ public class Action extends BaseEntity implements Comparable { return actionType; } - /** - * @return the actionStatus - */ public List getActionStatus() { return actionStatus; } - /** - * @param target - * the target to set - */ public void setTarget(final Target target) { this.target = target; } - /** - * @return the target - */ public Target getTarget() { return target; } - /** - * @return the forcedTime - */ public long getForcedTime() { return forcedTime; } - /** - * @param forcedTime - * the forcedTime to set - */ public void setForcedTime(final long forcedTime) { this.forcedTime = forcedTime; } - /** - * @return the rolloutGroup - */ public RolloutGroup getRolloutGroup() { return rolloutGroup; } - /** - * @param rolloutGroup - * the rolloutGroup to set - */ public void setRolloutGroup(final RolloutGroup rolloutGroup) { this.rolloutGroup = rolloutGroup; } - /** - * @return the rollout - */ public Rollout getRollout() { return rollout; } - /** - * @param rollout - * the rollout to set - */ public void setRollout(final Rollout rollout) { this.rollout = rollout; } - @Override - public int compareTo(final Action o) { - if (super.getId() == null || o == null || o.getId() == null) { - return 0; - } - return super.getId().compareTo(o.getId()); - } - /** * checks if the {@link #forcedTime} is hit by the given * {@code hitTimeMillis}, by means if the given milliseconds are greater @@ -305,66 +241,11 @@ public class Action extends BaseEntity implements Comparable { return actionType == ActionType.FORCED; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ @Override public String toString() { return "Action [distributionSet=" + distributionSet + ", getId()=" + getId() + "]"; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { // NOSONAR - as this is generated - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((actionType == null) ? 0 : actionType.hashCode()); - result = prime * result + (active ? 1231 : 1237); - result = prime * result + (int) (forcedTime ^ (forcedTime >>> 32)); - result = prime * result + ((status == null) ? 0 : status.hashCode()); - result = prime * result + (isHitAutoForceTime(System.currentTimeMillis()) ? 1231 : 1237); - return result; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object obj) { // NOSONAR - as this is generated - - if (this == obj) { - return true; - } - if (!super.equals(obj)) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final Action other = (Action) obj; - if (actionType != other.actionType) { - return false; - } - if (active != other.active) { - return false; - } - if (forcedTime != other.forcedTime) { - return false; - } - if (status != other.status) { - return false; - } - return true; - } - /** * Action status as reported by the controller. * @@ -424,9 +305,6 @@ public class Action extends BaseEntity implements Comparable { /** * The action type for this action relation. * - * - * - * */ public enum ActionType { FORCED, SOFT, TIMEFORCED; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java index 2b0effae9..c8d320abd 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java @@ -32,27 +32,20 @@ import com.google.common.base.Splitter; /** * Entity to store the status for a specific action. - * - * - * */ @Table(name = "sp_action_status", indexes = { @Index(name = "sp_idx_action_status_01", columnList = "tenant,action"), @Index(name = "sp_idx_action_status_02", columnList = "tenant,action,status"), @Index(name = "sp_idx_action_status_prim", columnList = "tenant,id") }) @NamedEntityGraph(name = "ActionStatus.withMessages", attributeNodes = { @NamedAttributeNode("messages") }) @Entity -public class ActionStatus extends BaseEntity { - - /** - * - */ +public class ActionStatus extends TenantAwareBaseEntity { private static final long serialVersionUID = 1L; @Column(name = "target_occurred_at") private Long occurredAt; @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "action", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_act_stat_action") ) + @JoinColumn(name = "action", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_act_stat_action")) private Action action; @Column(name = "status") @@ -60,14 +53,14 @@ public class ActionStatus extends BaseEntity { @CascadeOnDelete @ElementCollection(fetch = FetchType.LAZY, targetClass = String.class) - @CollectionTable(name = "sp_action_status_messages", joinColumns = @JoinColumn(name = "action_status_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_stat_msg_act_stat") ) , indexes = { + @CollectionTable(name = "sp_action_status_messages", joinColumns = @JoinColumn(name = "action_status_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_stat_msg_act_stat")), indexes = { @Index(name = "sp_idx_action_status_msgs_01", columnList = "action_status_id") }) @Column(name = "detail_message", length = 512) private final List messages = new ArrayList<>(); /** * Creates a new {@link ActionStatus} object. - * + * * @param action * the action for this action status * @param status @@ -83,7 +76,7 @@ public class ActionStatus extends BaseEntity { /** * Creates a new {@link ActionStatus} object. - * + * * @param action * the action for this action status * @param status @@ -103,67 +96,48 @@ public class ActionStatus extends BaseEntity { } /** - * - */ + * JPA default constructor. + */ public ActionStatus() { + // JPA default constructor. } - /** - * @return the occurredAt - */ public Long getOccurredAt() { return occurredAt; } - /** - * @param occurredAt - * the occurredAt to set - */ public void setOccurredAt(final Long occurredAt) { this.occurredAt = occurredAt; } /** - * Adds message. + * Adds message including splitting in case it exceeds 512 length. * * @param message * to add */ public final void addMessage(final String message) { - Splitter.fixedLength(512).split(message).forEach(chunk -> messages.add(chunk)); + Splitter.fixedLength(512).split(message).forEach(messages::add); } public List getMessages() { return messages; } - /** - * @return the action - */ public Action getAction() { return action; } - /** - * @param action - * the action to set - */ public void setAction(final Action action) { this.action = action; } - /** - * @return the status - */ public Status getStatus() { return status; } - /** - * @param status - * the status to set - */ public void setStatus(final Status status) { this.status = status; } + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java index 7d01b9dd2..73eab32f9 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java @@ -15,9 +15,6 @@ import org.eclipse.hawkbit.repository.model.Action.Status; * Custom JPA Model for querying {@link Action} include the count of the * action's {@link ActionStatus}. * - * - * - * */ public class ActionWithStatusCount { private final Long actionStatusCount; @@ -37,7 +34,7 @@ public class ActionWithStatusCount { /** * JPA constructor, the parameter are the result set columns of the custom * query. - * + * * @param actionId * the ID of the action * @param actionType @@ -70,9 +67,9 @@ public class ActionWithStatusCount { final String rolloutName) { this.actionId = actionId; this.actionType = actionType; - this.actionActive = active; - this.actionForceTime = forcedTime; - this.actionStatus = status; + actionActive = active; + actionForceTime = forcedTime; + actionStatus = status; this.actionCreatedAt = actionCreatedAt; this.actionLastModifiedAt = actionLastModifiedAt; this.dsId = dsId; @@ -81,101 +78,62 @@ public class ActionWithStatusCount { this.actionStatusCount = actionStatusCount; this.rolloutName = rolloutName; - this.action = new Action(); - this.action.setActionType(actionType); - this.action.setActive(actionActive); - this.action.setForcedTime(actionForceTime); - this.action.setStatus(actionStatus); - this.action.setId(actionId); + action = new Action(); + action.setActionType(actionType); + action.setActive(actionActive); + action.setForcedTime(actionForceTime); + action.setStatus(actionStatus); + action.setId(actionId); } - /** - * @return the action - */ public Action getAction() { return action; } - /** - * @return the actionId - */ public Long getActionId() { return actionId; } - /** - * @return the actionType - */ public ActionType getActionType() { return actionType; } - /** - * @return the actionActive - */ public boolean isActionActive() { return actionActive; } - /** - * @return the actionForceTime - */ public long getActionForceTime() { return actionForceTime; } - /** - * @return the actionStatus - */ public Status getActionStatus() { return actionStatus; } - /** - * @return the actionCreatedAt - */ public Long getActionCreatedAt() { return actionCreatedAt; } - /** - * @return the actionLastModifiedAt - */ public Long getActionLastModifiedAt() { return actionLastModifiedAt; } - /** - * @return the dsId - */ public Long getDsId() { return dsId; } - /** - * @return the dsName - */ public String getDsName() { return dsName; } - /** - * @return the dsVersion - */ public String getDsVersion() { return dsVersion; } - /** - * @return the actionStatusCount - */ public Long getActionStatusCount() { return actionStatusCount; } - /** - * @return the rolloutName - */ public String getRolloutName() { return rolloutName; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java index 4b868f9a2..b384a3100 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java @@ -13,14 +13,10 @@ import javax.persistence.MappedSuperclass; /** * Tenant specific locally stored artifact representation that is used by - * {@link SoftwareModule} . - * - * - * - * + * {@link SoftwareModule}. */ @MappedSuperclass -public abstract class Artifact extends BaseEntity { +public abstract class Artifact extends TenantAwareBaseEntity { private static final long serialVersionUID = 1L; @Column(name = "sha1_hash", length = 40, nullable = true) @@ -34,49 +30,27 @@ public abstract class Artifact extends BaseEntity { public abstract SoftwareModule getSoftwareModule(); - /** - * @return the md5Hash - */ public String getMd5Hash() { return md5Hash; } - /** - * @return the sha1Hash - */ public String getSha1Hash() { return sha1Hash; } - /** - * @param md5Hash - * the md5Hash to set - */ public void setMd5Hash(final String md5Hash) { this.md5Hash = md5Hash; } - /** - * @param sha1Hash - * the sha1Hash to set - */ public void setSha1Hash(final String sha1Hash) { this.sha1Hash = sha1Hash; } - /** - * @return the size - */ public Long getSize() { return size; } - /** - * @param size - * the size to set - */ public void setSize(final Long size) { this.size = size; } - } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java index 05f812b06..eda0bb9bd 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java @@ -9,10 +9,7 @@ package org.eclipse.hawkbit.repository.model; /** - * Generic assigment result bean. - * - * - * + * Generic assignment result bean. * */ public class AssignmentResult { @@ -36,23 +33,14 @@ public class AssignmentResult { total = assigned + alreadyAssigned; } - /** - * @return the assignedTargets - */ public int getAssigned() { return assigned; } - /** - * @return the total - */ public int getTotal() { return total; } - /** - * @return the alreadyAssigned - */ public int getAlreadyAssigned() { return alreadyAssigned; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java index 72d25be6c..65300c6c4 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java @@ -18,17 +18,10 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.MappedSuperclass; -import javax.persistence.PrePersist; import javax.persistence.Version; import org.eclipse.hawkbit.eventbus.CacheFieldEntityListener; import org.eclipse.hawkbit.eventbus.EntityPropertyChangeListener; -import org.eclipse.hawkbit.repository.exception.TenantNotExistException; -import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder; -import org.eclipse.hawkbit.repository.model.helper.TenantAwareHolder; -import org.eclipse.persistence.annotations.Multitenant; -import org.eclipse.persistence.annotations.MultitenantType; -import org.eclipse.persistence.annotations.TenantDiscriminatorColumn; import org.springframework.data.annotation.CreatedBy; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedBy; @@ -37,18 +30,12 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.hateoas.Identifiable; /** - * Holder of all base attributes common to all entities. - * - * - * - * + * Holder of the base attributes common to all entities. * */ @MappedSuperclass @Access(AccessType.FIELD) @EntityListeners({ AuditingEntityListener.class, CacheFieldEntityListener.class, EntityPropertyChangeListener.class }) -@TenantDiscriminatorColumn(name = "tenant", length = 40) -@Multitenant(MultitenantType.SINGLE_TABLE) public abstract class BaseEntity implements Serializable, Identifiable { private static final long serialVersionUID = 1L; @@ -66,44 +53,11 @@ public abstract class BaseEntity implements Serializable, Identifiable { @Column(name = "optlock_revision") private long optLockRevision; - @Column(name = "tenant", nullable = false, insertable = false, updatable = false, length = 40) - private String tenant; - /** - * - */ + * Default constructor needed for JPA entities. + */ public BaseEntity() { - - } - - /** - * @param entity - * the entity to copy - */ - public BaseEntity(final BaseEntity entity) { - id = entity.id; - createdAt = entity.createdAt; - createdBy = entity.createdBy; - lastModifiedAt = entity.lastModifiedAt; - lastModifiedBy = entity.lastModifiedBy; - optLockRevision = entity.optLockRevision; - } - - /** - * PrePersist listener method for all {@link BaseEntity} entities. - */ - @PrePersist - public void prePersist() { - // before persisting the entity check the current ID of the tenant by - // using the TenantAware - // service - final String currentTenant = SystemManagementHolder.getInstance().currentTenant(); - if (currentTenant == null) { - throw new TenantNotExistException("Tenant " - + TenantAwareHolder.getInstance().getTenantAware().getCurrentTenant() - + " does not exists, cannot create entity " + this.getClass() + " with id " + id); - } - setTenant(currentTenant.toUpperCase()); + // Default constructor needed for JPA entities. } @Access(AccessType.PROPERTY) @@ -130,37 +84,21 @@ public abstract class BaseEntity implements Serializable, Identifiable { return lastModifiedBy; } - /** - * @param createdBy - * the createdBy to set - */ @CreatedBy public void setCreatedBy(final String createdBy) { this.createdBy = createdBy; } - /** - * @param lastModifiedBy - * the lastModifiedBy to set - */ @LastModifiedBy public void setLastModifiedBy(final String lastModifiedBy) { this.lastModifiedBy = lastModifiedBy; } - /** - * @param createdAt - * the createdAt to set - */ @CreatedDate public void setCreatedAt(final Long createdAt) { this.createdAt = createdAt; } - /** - * @param lastModifiedAt - * the lastModifiedAt to set - */ @LastModifiedDate public void setLastModifiedAt(final Long lastModifiedAt) { this.lastModifiedAt = lastModifiedAt; @@ -170,49 +108,29 @@ public abstract class BaseEntity implements Serializable, Identifiable { return optLockRevision; } - /** - * @return the tenant - */ - public String getTenant() { - return tenant; + // for test purposes only + void setOptLockRevision(final long optLockRevision) { + this.optLockRevision = optLockRevision; } - /** - * @param tenant - * the tenant to set - */ - public void setTenant(final String tenant) { - this.tenant = tenant; - } - - /** - * @return the id - */ @Override public Long getId() { return id; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ @Override public String toString() { return "BaseEntity [id=" + id + "]"; } - /** - * @param id - * the id to set - */ public void setId(final Long id) { this.id = id; } - /* - * (non-Javadoc) + /** + * Defined equals/hashcode strategy for the repository in general is that an + * entity is equal if it has the same {@link #getId()} and + * {@link #getOptLockRevision()} and class. * * @see java.lang.Object#hashCode() */ @@ -222,11 +140,14 @@ public abstract class BaseEntity implements Serializable, Identifiable { int result = 1; result = prime * result + (id == null ? 0 : id.hashCode()); result = prime * result + (int) (optLockRevision ^ optLockRevision >>> 32); + result = prime * result + this.getClass().getName().hashCode(); return result; } - /* - * (non-Javadoc) + /** + * Defined equals/hashcode strategy for the repository in general is that an + * entity is equal if it has the same {@link #getId()} and + * {@link #getOptLockRevision()} and class. * * @see java.lang.Object#equals(java.lang.Object) */ @@ -239,7 +160,7 @@ public abstract class BaseEntity implements Serializable, Identifiable { if (obj == null) { return false; } - if (getClass() != obj.getClass()) { + if (!(this.getClass().isInstance(obj))) { return false; } final BaseEntity other = (BaseEntity) obj; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/CustomSoftwareModule.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/CustomSoftwareModule.java index 96c7cdd62..34aa8345a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/CustomSoftwareModule.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/CustomSoftwareModule.java @@ -13,9 +13,6 @@ import java.io.Serializable; /** * Use to display software modules for the selected distribution. * - * - * - * */ public class CustomSoftwareModule implements Serializable { @@ -39,17 +36,51 @@ public class CustomSoftwareModule implements Serializable { this.assigned = assigned; } - /** - * @return the softwareModule - */ public SoftwareModule getSoftwareModule() { return softwareModule; } - /** - * @return the assigned - */ public boolean isAssigned() { return assigned; } + + @Override + public String toString() { + return "CustomSoftwareModule [softwareModule=" + softwareModule + ", assigned=" + assigned + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (assigned ? 1231 : 1237); + result = prime * result + (softwareModule == null ? 0 : softwareModule.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof CustomSoftwareModule)) { + return false; + } + final CustomSoftwareModule other = (CustomSoftwareModule) obj; + if (assigned != other.assigned) { + return false; + } + if (softwareModule == null) { + if (other.softwareModule != null) { + return false; + } + } else if (!softwareModule.equals(other.softwareModule)) { + return false; + } + return true; + } + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java index e0444bc28..a9d390284 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java @@ -46,10 +46,6 @@ import org.eclipse.persistence.annotations.CascadeOnDelete; * A {@link Target} has exactly one target {@link DistributionSet} assigned. *

* - * - * - * - * */ @Entity @Table(name = "sp_distribution_set", uniqueConstraints = { @@ -67,14 +63,14 @@ public class DistributionSet extends NamedVersionedEntity { @ManyToMany(targetEntity = SoftwareModule.class, fetch = FetchType.LAZY) @JoinTable(name = "sp_ds_module", joinColumns = { - @JoinColumn(name = "ds_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_ds") ) }, inverseJoinColumns = { - @JoinColumn(name = "module_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_module") ) }) + @JoinColumn(name = "ds_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_ds")) }, inverseJoinColumns = { + @JoinColumn(name = "module_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_module")) }) private final Set modules = new HashSet<>(); @ManyToMany(targetEntity = DistributionSetTag.class) @JoinTable(name = "sp_ds_dstag", joinColumns = { - @JoinColumn(name = "ds", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_ds") ) }, inverseJoinColumns = { - @JoinColumn(name = "TAG", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_tag") ) }) + @JoinColumn(name = "ds", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_ds")) }, inverseJoinColumns = { + @JoinColumn(name = "TAG", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_tag")) }) private Set tags = new HashSet<>(); @Column(name = "deleted") @@ -95,7 +91,7 @@ public class DistributionSet extends NamedVersionedEntity { private final List metadata = new ArrayList<>(); @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "ds_id", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstype_ds") ) + @JoinColumn(name = "ds_id", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstype_ds")) private DistributionSetType type; @Column(name = "complete") @@ -130,75 +126,34 @@ public class DistributionSet extends NamedVersionedEntity { if (moduleList != null) { moduleList.forEach(this::addModule); } - complete = type.checkComplete(this); + if (this.type != null) { + complete = this.type.checkComplete(this); + } } public Set getTags() { return tags; } - /** - * @return the deleted - */ public boolean isDeleted() { return deleted; } /** - * @return the metadata + * @return immutable list of meta data elements. */ public List getMetadata() { - return metadata; + return Collections.unmodifiableList(metadata); } - /** - * @return the actions - */ public List getActions() { return actions; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof DistributionSet)) { - return false; - } - - return true; - } - public boolean isRequiredMigrationStep() { return requiredMigrationStep; } - /** - * @param deleted - * the deleted to set - */ public DistributionSet setDeleted(final boolean deleted) { this.deleted = deleted; return this; @@ -209,10 +164,6 @@ public class DistributionSet extends NamedVersionedEntity { return this; } - /** - * @param tags - * the tags to set - */ public DistributionSet setTags(final Set tags) { this.tags = tags; return this; @@ -232,11 +183,6 @@ public class DistributionSet extends NamedVersionedEntity { return installedAtTargets; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ @Override public String toString() { return "DistributionSet [getName()=" + getName() + ", getOptLockRevision()=" + getOptLockRevision() @@ -322,7 +268,7 @@ public class DistributionSet extends NamedVersionedEntity { * Searches through modules for the given type. * * @param type - * to seach for + * to search for * @return SoftwareModule of given type or null if not in the * list. */ @@ -337,26 +283,15 @@ public class DistributionSet extends NamedVersionedEntity { return null; } - /** - * @return the type - */ public DistributionSetType getType() { return type; } - /** - * @param type - * the type to set - */ public void setType(final DistributionSetType type) { this.type = type; } - /** - * @return the complete - */ public boolean isComplete() { return complete; } - } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetIdName.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetIdName.java index a7eb8e517..f8662567a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetIdName.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetIdName.java @@ -15,9 +15,6 @@ import java.io.Serializable; * */ public class DistributionSetIdName implements Serializable { - /** - * - */ private static final long serialVersionUID = 1L; private final Long id; @@ -39,9 +36,6 @@ public class DistributionSetIdName implements Serializable { this.version = version; } - /** - * @return the id - */ public Long getId() { return id; } @@ -50,40 +44,27 @@ public class DistributionSetIdName implements Serializable { return version; } - /** - * @return the name - */ public String getName() { return name; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ @Override - public int hashCode() { // NOSONAR - as this is generated + public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (id == null ? 0 : id.hashCode()); return result; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ @Override - public boolean equals(final Object obj) { // NOSONAR - as this is generated + public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } - if (getClass() != obj.getClass()) { + if (!(obj instanceof DistributionSetIdName)) { return false; } final DistributionSetIdName other = (DistributionSetIdName) obj; @@ -97,11 +78,6 @@ public class DistributionSetIdName implements Serializable { return true; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ @Override public String toString() { // only return the ID because it's used in vaadin for setting the item diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java index b0627f0db..7b2e637b9 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java @@ -23,20 +23,13 @@ import javax.persistence.ManyToOne; import javax.persistence.Table; /** - * Metadata for {@link DistributionSet}. - * - * - * + * Meta data for {@link DistributionSet}. * */ @IdClass(DsMetadataCompositeKey.class) @Entity @Table(name = "sp_ds_metadata") public class DistributionSetMetadata implements Serializable { - - /** - * - */ private static final long serialVersionUID = 1L; @Id @@ -49,11 +42,11 @@ public class DistributionSetMetadata implements Serializable { @Id @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "ds_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_metadata_ds") ) + @JoinColumn(name = "ds_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_metadata_ds")) private DistributionSet distributionSet; public DistributionSetMetadata() { - + // Default constructor for JPA. } /** @@ -73,49 +66,66 @@ public class DistributionSetMetadata implements Serializable { return new DsMetadataCompositeKey(distributionSet, key); } - /** - * @return the key - */ public String getKey() { return key; } - /** - * @param key - * the key to set - */ public void setKey(final String key) { this.key = key; } - /** - * @param distributionSet - * the distributionSet to set - */ public void setDistributionSet(final DistributionSet distributionSet) { this.distributionSet = distributionSet; } - /** - * @return the value - */ public String getValue() { return value; } - /** - * @param value - * the value to set - */ public void setValue(final String value) { this.value = value; } - /** - * @return the distributionSet - */ public DistributionSet getDistributionSet() { return distributionSet; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (distributionSet == null ? 0 : distributionSet.hashCode()); + result = prime * result + (key == null ? 0 : key.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof DistributionSetMetadata)) { + return false; + } + final DistributionSetMetadata other = (DistributionSetMetadata) obj; + if (distributionSet == null) { + if (other.distributionSet != null) { + return false; + } + } else if (!distributionSet.equals(other.distributionSet)) { + return false; + } + if (key == null) { + if (other.key != null) { + return false; + } + } else if (!key.equals(other.key)) { + return false; + } + return true; + } + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java index 63a858a7d..137fde5b9 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java @@ -21,16 +21,11 @@ import javax.persistence.UniqueConstraint; * A {@link DistributionSetTag} is used to describe DistributionSet attributes * and use them also for filtering the DistributionSet list. * - * - * - * - * - * */ @Entity @Table(name = "sp_distributionset_tag", indexes = { @Index(name = "sp_idx_distribution_set_tag_prim", columnList = "tenant,id") }, uniqueConstraints = @UniqueConstraint(columnNames = { - "name", "tenant" }, name = "uk_ds_tag") ) + "name", "tenant" }, name = "uk_ds_tag")) public class DistributionSetTag extends Tag { private static final long serialVersionUID = 1L; @@ -69,11 +64,6 @@ public class DistributionSetTag extends Tag { return assignedToDistributionSet; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { final int prime = 31; @@ -82,16 +72,8 @@ public class DistributionSetTag extends Tag { return result; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(final Object obj) { // NOSONAR - as this is generated - if (this == obj) { - return true; - } if (!super.equals(obj)) { return false; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssigmentResult.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssignmentResult.java similarity index 80% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssigmentResult.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssignmentResult.java index d7ed57305..eddd10c1b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssigmentResult.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssignmentResult.java @@ -11,10 +11,10 @@ package org.eclipse.hawkbit.repository.model; import java.util.List; /** - * Result object for {@link DistributionSetTag} assigments. + * Result object for {@link DistributionSetTag} assignments. * */ -public class DistributionSetTagAssigmentResult extends AssignmentResult { +public class DistributionSetTagAssignmentResult extends AssignmentResult { private final int unassigned; private final List assignedDs; @@ -37,7 +37,7 @@ public class DistributionSetTagAssigmentResult extends AssignmentResult { * @param distributionSetTag * the assigned or unassigned tag */ - public DistributionSetTagAssigmentResult(final int alreadyAssigned, final int assigned, final int unassigned, + public DistributionSetTagAssignmentResult(final int alreadyAssigned, final int assigned, final int unassigned, final List assignedDs, final List unassignedDs, final DistributionSetTag distributionSetTag) { super(assigned, alreadyAssigned); @@ -47,30 +47,18 @@ public class DistributionSetTagAssigmentResult extends AssignmentResult { this.distributionSetTag = distributionSetTag; } - /** - * @return the unassigned - */ public int getUnassigned() { return unassigned; } - /** - * @return the distributionSetTag - */ public DistributionSetTag getDistributionSetTag() { return distributionSetTag; } - /** - * @return the assignedDs - */ public List getAssignedDs() { return assignedDs; } - /** - * @return the unassignedDs - */ public List getUnassignedDs() { return unassignedDs; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java index e1c7e61ea..61d2fc58c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java @@ -27,9 +27,6 @@ import javax.persistence.UniqueConstraint; * A distribution set type defines which software module types can or have to be * {@link DistributionSet}. * - * - * - * */ @Entity @Table(name = "sp_distribution_set_type", indexes = { @@ -38,10 +35,6 @@ import javax.persistence.UniqueConstraint; @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_dst_name"), @UniqueConstraint(columnNames = { "type_key", "tenant" }, name = "uk_dst_key") }) public class DistributionSetType extends NamedEntity { - - /** - * - */ private static final long serialVersionUID = 1L; @OneToMany(targetEntity = DistributionSetTypeElement.class, cascade = { @@ -59,7 +52,7 @@ public class DistributionSetType extends NamedEntity { private boolean deleted = false; public DistributionSetType() { - // default public constructor + // default public constructor for JPA } /** @@ -91,7 +84,7 @@ public class DistributionSetType extends NamedEntity { public DistributionSetType(final String key, final String name, final String description, final String color) { super(name, description); this.key = key; - this.colour = color; + colour = color; } /** @@ -256,17 +249,10 @@ public class DistributionSetType extends NamedEntity { return this; } - /** - * @return the key - */ public String getKey() { return key; } - /** - * @param key - * the key to set - */ public void setKey(final String key) { this.key = key; } @@ -282,19 +268,10 @@ public class DistributionSetType extends NamedEntity { .containsAll(getMandatoryModuleTypes()); } - /** - * - * @return the DistributionSet type color - */ public String getColour() { return colour; } - /** - * - * @param colour - * the col - */ public void setColour(final String colour) { this.colour = colour; } @@ -303,11 +280,6 @@ public class DistributionSetType extends NamedEntity { return elements; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ @Override public String toString() { return "DistributionSetType [key=" + key + ", isDeleted()=" + isDeleted() + ", getId()=" + getId() + "]"; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTypeElement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTypeElement.java index 0d892f6da..8414a6f1a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTypeElement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTypeElement.java @@ -25,17 +25,10 @@ import javax.persistence.Table; * Relation element between a {@link DistributionSetType} and its * {@link SoftwareModuleType} elements. * - * - * - * */ @Entity @Table(name = "sp_ds_type_element") public class DistributionSetTypeElement implements Serializable { - - /** - * - */ private static final long serialVersionUID = 1L; @EmbeddedId @@ -46,18 +39,16 @@ public class DistributionSetTypeElement implements Serializable { @MapsId("dsType") @ManyToOne(optional = false, fetch = FetchType.LAZY) - @JoinColumn(name = "distribution_set_type", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_type_element_dstype") ) + @JoinColumn(name = "distribution_set_type", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_type_element_dstype")) private DistributionSetType dsType; @MapsId("smType") @ManyToOne(optional = false, fetch = FetchType.LAZY) - @JoinColumn(name = "software_module_type", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_type_element_smtype") ) + @JoinColumn(name = "software_module_type", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_type_element_smtype")) private SoftwareModuleType smType; - /** - * Default constructor. - */ public DistributionSetTypeElement() { + // Default constructor for JPA } /** @@ -74,38 +65,30 @@ public class DistributionSetTypeElement implements Serializable { public DistributionSetTypeElement(final DistributionSetType dsType, final SoftwareModuleType smType, final boolean mandatory) { super(); - this.key = new DistributionSetTypeElementCompositeKey(dsType, smType); + key = new DistributionSetTypeElementCompositeKey(dsType, smType); this.dsType = dsType; this.smType = smType; this.mandatory = mandatory; } - /** - * @return the mandatory - */ public boolean isMandatory() { return mandatory; } - /** - * @return the dsType - */ public DistributionSetType getDsType() { return dsType; } - /** - * @return the smType - */ public SoftwareModuleType getSmType() { return smType; } - /** - * @return the key - */ public DistributionSetTypeElementCompositeKey getKey() { return key; } + @Override + public String toString() { + return "DistributionSetTypeElement [mandatory=" + mandatory + ", dsType=" + dsType + ", smType=" + smType + "]"; + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTypeElementCompositeKey.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTypeElementCompositeKey.java index c819d4e52..2ee1aba0d 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTypeElementCompositeKey.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTypeElementCompositeKey.java @@ -15,17 +15,9 @@ import javax.persistence.Embeddable; /** * Composite key for {@link DistributionSetTypeElement}. - * - * - * - * */ @Embeddable public class DistributionSetTypeElementCompositeKey implements Serializable { - - /** - * - */ private static final long serialVersionUID = 1L; @Column(name = "distribution_set_type", nullable = false) @@ -54,34 +46,19 @@ public class DistributionSetTypeElementCompositeKey implements Serializable { this.smType = smType.getId(); } - /** - * @return the dsType - */ public Long getDsType() { return dsType; } - /** - * @param dsType - * the dsType to set - */ public void setDsType(final Long dsType) { this.dsType = dsType; } - /** - * @return the smType - */ public Long getSmType() { return smType; } - /** - * @param smType - * the smType to set - */ public void setSmType(final Long smType) { this.smType = smType; } - } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DsMetadataCompositeKey.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DsMetadataCompositeKey.java index f26a66ab9..adc37d65a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DsMetadataCompositeKey.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DsMetadataCompositeKey.java @@ -13,24 +13,17 @@ import java.io.Serializable; /** * The DistributionSet Metadata composite key which contains the meta data key * and the ID of the DistributionSet itself. - * - * * */ public final class DsMetadataCompositeKey implements Serializable { - /** - * - */ private static final long serialVersionUID = 1L; private String key; private Long distributionSet; - /** - * - */ public DsMetadataCompositeKey() { + // Default constructor for JPA. } /** @@ -44,55 +37,31 @@ public final class DsMetadataCompositeKey implements Serializable { this.key = key; } - /** - * @return the key - */ public String getKey() { return key; } - /** - * @param key - * the key to set - */ public void setKey(final String key) { this.key = key; } - /** - * @return the distributionSet - */ public Long getDistributionSet() { return distributionSet; } - /** - * @param distributionSet - * the distributionSet to set - */ public void setDistributionSet(final Long distributionSet) { this.distributionSet = distributionSet; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((distributionSet == null) ? 0 : distributionSet.hashCode()); - result = prime * result + ((key == null) ? 0 : key.hashCode()); + result = prime * result + (distributionSet == null ? 0 : distributionSet.hashCode()); + result = prime * result + (key == null ? 0 : key.hashCode()); return result; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(final Object obj) { // NOSONAR - as this is generated // code diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java index 35e0c4e99..898c685a5 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java @@ -22,12 +22,9 @@ import javax.persistence.Table; import javax.validation.constraints.NotNull; /** - * External artifact representation with all the necessray informattion to + * External artifact representation with all the necessary information to * generate an artifact {@link URL} at runtime. * - * - * - * */ @Table(name = "sp_external_artifact", indexes = { @Index(name = "sp_idx_external_artifact_prim", columnList = "id,tenant") }) @@ -36,7 +33,7 @@ public class ExternalArtifact extends Artifact { private static final long serialVersionUID = 1L; @ManyToOne - @JoinColumn(name = "provider", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_art_to_ext_provider") ) + @JoinColumn(name = "provider", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_art_to_ext_provider")) private ExternalArtifactProvider externalArtifactProvider; @Column(name = "url_suffix", length = 512) @@ -44,7 +41,7 @@ public class ExternalArtifact extends Artifact { // CascadeType.PERSIST as we register ourself at the BSM @ManyToOne(optional = false, cascade = { CascadeType.PERSIST }) - @JoinColumn(name = "software_module", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_external_assigned_sm") ) + @JoinColumn(name = "software_module", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_external_assigned_sm")) private SoftwareModule softwareModule; /** @@ -84,18 +81,11 @@ public class ExternalArtifact extends Artifact { return softwareModule; } - /** - * @param softwareModule - * the softwareModule to set - */ public final void setSoftwareModule(final SoftwareModule softwareModule) { this.softwareModule = softwareModule; this.softwareModule.addArtifact(this); } - /** - * @return the externalArtifactProvider - */ public ExternalArtifactProvider getExternalArtifactProvider() { return externalArtifactProvider; } @@ -104,17 +94,10 @@ public class ExternalArtifact extends Artifact { return new StringBuilder().append(externalArtifactProvider.getBasePath()).append(urlSuffix).toString(); } - /** - * @return the urlSuffix - */ public String getUrlSuffix() { return urlSuffix; } - /** - * @param externalArtifactProvider - * the externalArtifactProvider to set - */ public void setExternalArtifactProvider(final ExternalArtifactProvider externalArtifactProvider) { this.externalArtifactProvider = externalArtifactProvider; } @@ -127,11 +110,6 @@ public class ExternalArtifact extends Artifact { this.urlSuffix = urlSuffix; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { // NOSONAR - as this is generated final int prime = 31; @@ -140,16 +118,8 @@ public class ExternalArtifact extends Artifact { return result; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(final Object obj) { // NOSONAR - as this is generated - if (this == obj) { - return true; - } if (!super.equals(obj)) { return false; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java index 56d92c8e1..9fa8714ac 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java @@ -15,11 +15,8 @@ import javax.persistence.Table; /** * External repositories for artifact storage. The SP server provides URLs for - * the targets to download rom these external ressources but does not access - * thenm itself. - * - * - * + * the targets to download from these external resources but does not access + * them itself. * */ @Table(name = "sp_external_provider", indexes = { @@ -60,67 +57,20 @@ public class ExternalArtifactProvider extends NamedEntity { basePath = ""; } - /** - * @return the basePath - */ public String getBasePath() { return basePath; } - /** - * @return the defaultSuffix - */ public String getDefaultSuffix() { return defaultSuffix; } - /** - * @param basePath - * the basePath to set - */ public void setBasePath(final String basePath) { this.basePath = basePath; } - /** - * @param defaultSuffix - * the defaultSuffix to set - */ public void setDefaultSuffix(final String defaultSuffix) { this.defaultSuffix = defaultSuffix; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { // NOSONAR - as this is generated - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object obj) { // NOSONAR - as this is generated - if (this == obj) { - return true; - } - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof ExternalArtifactProvider)) { - return false; - } - - return true; - } - } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java index baa4ee1f0..8afcdc168 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java @@ -46,7 +46,7 @@ public class LocalArtifact extends Artifact { private String filename; @ManyToOne(optional = false, cascade = { CascadeType.PERSIST }) - @JoinColumn(name = "software_module", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_assigned_sm") ) + @JoinColumn(name = "software_module", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_assigned_sm")) private SoftwareModule softwareModule; /** @@ -73,11 +73,6 @@ public class LocalArtifact extends Artifact { this.filename = filename; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { // NOSONAR - as this is generated final int prime = 31; @@ -86,16 +81,8 @@ public class LocalArtifact extends Artifact { return result; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(final Object obj) { // NOSONAR - as this is generated - if (this == obj) { - return true; - } if (!super.equals(obj)) { return false; } @@ -106,33 +93,20 @@ public class LocalArtifact extends Artifact { return true; } - /** - * @return the softwareModule - */ @Override public SoftwareModule getSoftwareModule() { return softwareModule; } - /** - * @param softwareModule - * the softwareModule to set - */ public final void setSoftwareModule(final SoftwareModule softwareModule) { this.softwareModule = softwareModule; this.softwareModule.addArtifact(this); } - /** - * @return the gridFsFileName - */ public String getGridFsFileName() { return gridFsFileName; } - /** - * @return the filename - */ public String getFilename() { return filename; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java index 0cebd0362..e14d88161 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java @@ -12,17 +12,11 @@ import javax.persistence.Column; import javax.persistence.MappedSuperclass; /** - * {@link BaseEntity} extension for all entities that are named in addition to - * their technical ID. - * - * - * - * - * - * + * {@link TenantAwareBaseEntity} extension for all entities that are named in + * addition to their technical ID. */ @MappedSuperclass -public abstract class NamedEntity extends BaseEntity { +public abstract class NamedEntity extends TenantAwareBaseEntity { private static final long serialVersionUID = 1L; @Column(name = "name", nullable = false, length = 64) @@ -40,7 +34,7 @@ public abstract class NamedEntity extends BaseEntity { /** * Parameterized constructor. - * + * * @param name * of the {@link NamedEntity} * @param description @@ -66,5 +60,4 @@ public abstract class NamedEntity extends BaseEntity { public void setName(final String name) { this.name = name; } - } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java index 77819ed46..fa56da197 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java @@ -14,11 +14,6 @@ import javax.persistence.MappedSuperclass; /** * Extension for {@link NamedEntity} that are versioned. * - * - * - * - * - * */ @MappedSuperclass public abstract class NamedVersionedEntity extends NamedEntity { @@ -29,7 +24,7 @@ public abstract class NamedVersionedEntity extends NamedEntity { /** * parameterized constructor. - * + * * @param name * of the entity * @param version @@ -52,5 +47,4 @@ public abstract class NamedVersionedEntity extends NamedEntity { public void setVersion(final String version) { this.version = version; } - } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java index 83e541ed5..a7f9b10cb 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java @@ -36,20 +36,20 @@ import org.eclipse.hawkbit.repository.model.Action.ActionType; @Entity @Table(name = "sp_rollout", indexes = { @Index(name = "sp_idx_rollout_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { - "name", "tenant" }, name = "uk_rollout") ) + "name", "tenant" }, name = "uk_rollout")) public class Rollout extends NamedEntity { private static final long serialVersionUID = 1L; @OneToMany(targetEntity = RolloutGroup.class) - @JoinColumn(name = "rollout", insertable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rollout_rolloutgroup") ) + @JoinColumn(name = "rollout", insertable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rollout_rolloutgroup")) private List rolloutGroups; @Column(name = "target_filter", length = 1024, nullable = false) private String targetFilterQuery; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "distribution_set", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rolltout_ds") ) + @JoinColumn(name = "distribution_set", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rolltout_ds")) private DistributionSet distributionSet; @Column(name = "status") @@ -79,159 +79,86 @@ public class Rollout extends NamedEntity { @Transient private transient TotalTargetCountStatus totalTargetCountStatus; - /** - * @return the distributionSet - */ public DistributionSet getDistributionSet() { return distributionSet; } - /** - * @param distributionSet - * the distributionSet to set - */ public void setDistributionSet(final DistributionSet distributionSet) { this.distributionSet = distributionSet; } - /** - * @return the rolloutGroups - */ public List getRolloutGroups() { return rolloutGroups; } - /** - * @param rolloutGroups - * the rolloutGroups to set - */ public void setRolloutGroups(final List rolloutGroups) { this.rolloutGroups = rolloutGroups; } - /** - * @return the targetFilterQuery - */ public String getTargetFilterQuery() { return targetFilterQuery; } - /** - * @param targetFilterQuery - * the targetFilterQuery to set - */ public void setTargetFilterQuery(final String targetFilterQuery) { this.targetFilterQuery = targetFilterQuery; } - /** - * @return the status - */ public RolloutStatus getStatus() { return status; } - /** - * @param status - * the status to set - */ public void setStatus(final RolloutStatus status) { this.status = status; } - /** - * @return the lastCheck - */ public long getLastCheck() { return lastCheck; } - /** - * @param lastCheck - * the lastCheck to set - */ public void setLastCheck(final long lastCheck) { this.lastCheck = lastCheck; } - /** - * @return the actionType - */ public ActionType getActionType() { return actionType; } - /** - * @param actionType - * the actionType to set - */ public void setActionType(final ActionType actionType) { this.actionType = actionType; } - /** - * @return the forcedTime - */ public long getForcedTime() { return forcedTime; } - /** - * @param forcedTime - * the forcedTime to set - */ public void setForcedTime(final long forcedTime) { this.forcedTime = forcedTime; } - /** - * @return the totalTargets - */ public long getTotalTargets() { return totalTargets; } - /** - * @param totalTargets - * the totalTargets to set - */ public void setTotalTargets(final long totalTargets) { this.totalTargets = totalTargets; } - /** - * @return the rolloutGroupsTotal - */ public int getRolloutGroupsTotal() { return rolloutGroupsTotal; } - /** - * @param rolloutGroupsTotal - * the rolloutGroupsTotal to set - */ public void setRolloutGroupsTotal(final int rolloutGroupsTotal) { this.rolloutGroupsTotal = rolloutGroupsTotal; } - /** - * @return the rolloutGroupsCreated - */ public int getRolloutGroupsCreated() { return rolloutGroupsCreated; } - /** - * @param rolloutGroupsCreated - * the rolloutGroupsCreated to set - */ public void setRolloutGroupsCreated(final int rolloutGroupsCreated) { this.rolloutGroupsCreated = rolloutGroupsCreated; } - /** - * @return the totalTargetCountStatus - */ public TotalTargetCountStatus getTotalTargetCountStatus() { if (totalTargetCountStatus == null) { totalTargetCountStatus = new TotalTargetCountStatus(totalTargets); @@ -239,10 +166,6 @@ public class Rollout extends NamedEntity { return totalTargetCountStatus; } - /** - * @param totalTargetCountStatus - * the totalTargetCountStatus to set - */ public void setTotalTargetCountStatus(final TotalTargetCountStatus totalTargetCountStatus) { this.totalTargetCountStatus = totalTargetCountStatus; } @@ -256,7 +179,7 @@ public class Rollout extends NamedEntity { /** * - * @author Michael Hirsch + * State machine for rollout. * */ public enum RolloutStatus { diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java index dcb95b254..5aa30126c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java @@ -34,13 +34,13 @@ import javax.persistence.UniqueConstraint; @Entity @Table(name = "sp_rolloutgroup", indexes = { @Index(name = "sp_idx_rolloutgroup_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { - "name", "rollout", "tenant" }, name = "uk_rolloutgroup") ) + "name", "rollout", "tenant" }, name = "uk_rolloutgroup")) public class RolloutGroup extends NamedEntity { private static final long serialVersionUID = 1L; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "rollout", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rolloutgroup_rollout") ) + @JoinColumn(name = "rollout", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rolloutgroup_rollout")) private Rollout rollout; @Column(name = "status") @@ -210,8 +210,7 @@ public class RolloutGroup extends NamedEntity { } /** - * - * @author Michael Hirsch + * Rollout goup state machine. * */ public enum RolloutGroupStatus { @@ -477,5 +476,4 @@ public class RolloutGroup extends NamedEntity { return this; } } - } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroupId.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroupId.java index 41850424b..88226142a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroupId.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroupId.java @@ -12,14 +12,9 @@ import java.io.Serializable; /** * Combined unique key of the table {@link RolloutTargetGroup}. - * - * @author Michael Hirsch * */ public class RolloutTargetGroupId implements Serializable { - /** - * - */ private static final long serialVersionUID = 1L; private Long rolloutGroup; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java index 49e73f749..327bff3db 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java @@ -33,17 +33,12 @@ import org.eclipse.persistence.annotations.CascadeOnDelete; /** * Base Software Module that is supported by OS level provisioning mechanism on - * the edge controller, e.g. OS, JVM, AgentHub - * - * - * - * - * + * the edge controller, e.g. OS, JVM, AgentHub. * */ @Entity @Table(name = "sp_base_software_module", uniqueConstraints = @UniqueConstraint(columnNames = { "module_type", "name", - "version", "tenant" }, name = "uk_base_sw_mod") , indexes = { + "version", "tenant" }, name = "uk_base_sw_mod"), indexes = { @Index(name = "sp_idx_base_sw_module_01", columnList = "tenant,deleted,name,version"), @Index(name = "sp_idx_base_sw_module_02", columnList = "tenant,deleted,module_type"), @Index(name = "sp_idx_base_sw_module_prim", columnList = "tenant,id") }) @@ -52,7 +47,7 @@ public class SoftwareModule extends NamedVersionedEntity { private static final long serialVersionUID = 1L; @ManyToOne - @JoinColumn(name = "module_type", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_module_type") ) + @JoinColumn(name = "module_type", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_module_type")) private SoftwareModuleType type; @ManyToMany(mappedBy = "modules", targetEntity = DistributionSet.class, fetch = FetchType.LAZY) @@ -213,17 +208,10 @@ public class SoftwareModule extends NamedVersionedEntity { return type; } - /** - * @return the deleted - */ public boolean isDeleted() { return deleted; } - /** - * @param deleted - * the deleted to set - */ public void setDeleted(final boolean deleted) { this.deleted = deleted; } @@ -233,55 +221,16 @@ public class SoftwareModule extends NamedVersionedEntity { } /** - * @return the metadata + * @return immutable list of meta data elements. */ public List getMetadata() { - return metadata; + return Collections.unmodifiableList(metadata); } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ @Override public String toString() { - return "SoftwareModule [type=" + type + ", deleted=" + deleted + ", getVersion()=" + getVersion() - + ", getOptLockRevision()=" + getOptLockRevision() + ", getId()=" + getId() + ", getType()=" - + getType().getName() + "]"; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { // NOSONAR - as this is generated - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object obj) { // NOSONAR - as this is generated - if (this == obj) { - return true; - } - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof SoftwareModule)) { - return false; - } - - return true; + return "SoftwareModule [deleted=" + deleted + ", name=" + getName() + ", version=" + getVersion() + + ", revision=" + getOptLockRevision() + ", Id=" + getId() + ", type=" + getType().getName() + "]"; } /** diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleIdName.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleIdName.java index 8658de3c8..c59d42c5f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleIdName.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleIdName.java @@ -13,8 +13,6 @@ import java.io.Serializable; /** * To hold software module name and Id. * - * - * */ public class SoftwareModuleIdName implements Serializable { @@ -35,25 +33,14 @@ public class SoftwareModuleIdName implements Serializable { this.name = name; } - /** - * @return the id - */ public Long getId() { return id; } - /** - * @return the name - */ public String getName() { return name; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() {// NOSONAR - as this is generated final int prime = 31; @@ -62,11 +49,6 @@ public class SoftwareModuleIdName implements Serializable { return result; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(final Object obj) {// NOSONAR - as this is generated if (this == obj) { diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java index dfc1ecfa7..c7af1f2ae 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java @@ -24,18 +24,11 @@ import javax.persistence.Table; /** * Metadata for {@link SoftwareModule}. * - * - * - * */ @IdClass(SwMetadataCompositeKey.class) @Entity @Table(name = "sp_sw_metadata") public class SoftwareModuleMetadata implements Serializable { - - /** - * - */ private static final long serialVersionUID = 1L; @Id @@ -50,18 +43,21 @@ public class SoftwareModuleMetadata implements Serializable { @JoinColumn(name = "sw_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_metadata_sw")) private SoftwareModule softwareModule; + /** + * Default constructor for JPA. + */ public SoftwareModuleMetadata() { - + // default constructor for JPA. } /** * Standard constructor. * * @param key - * of the metadata element + * of the meta data element * @param softwareModule * @param value - * of the metadata element + * of the meta data element */ public SoftwareModuleMetadata(final String key, final SoftwareModule softwareModule, final String value) { this.key = key; @@ -69,56 +65,75 @@ public class SoftwareModuleMetadata implements Serializable { this.value = value; } - /** - * @return the id - */ public SwMetadataCompositeKey getId() { return new SwMetadataCompositeKey(softwareModule, key); } - /** - * @return the value - */ public String getValue() { return value; } - /** - * @param value - * the value to set - */ public void setValue(final String value) { this.value = value; } - /** - * @return the softwareModule - */ public SoftwareModule getSoftwareModule() { return softwareModule; } - /** - * @param softwareModule - * the softwareModule to set - */ public void setSoftwareModule(final SoftwareModule softwareModule) { this.softwareModule = softwareModule; } - /** - * @return the key - */ public String getKey() { return key; } - /** - * @param key - * the key to set - */ public void setKey(final String key) { this.key = key; } + @Override + public String toString() { + return "SoftwareModuleMetadata [key=" + key + ", value=" + value + ", softwareModule=" + softwareModule + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((key == null) ? 0 : key.hashCode()); + result = prime * result + ((softwareModule == null) ? 0 : softwareModule.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof SoftwareModuleMetadata)) { + return false; + } + final SoftwareModuleMetadata other = (SoftwareModuleMetadata) obj; + if (key == null) { + if (other.key != null) { + return false; + } + } else if (!key.equals(other.key)) { + return false; + } + if (softwareModule == null) { + if (other.softwareModule != null) { + return false; + } + } else if (!softwareModule.equals(other.softwareModule)) { + return false; + } + return true; + } + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java index 49427b9ea..f31b74ff6 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java @@ -17,9 +17,6 @@ import javax.persistence.UniqueConstraint; /** * Type of a software modules. * - * - * - * */ @Entity @Table(name = "sp_software_module_type", indexes = { @@ -28,9 +25,6 @@ import javax.persistence.UniqueConstraint; @UniqueConstraint(columnNames = { "type_key", "tenant" }, name = "uk_smt_type_key"), @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_smt_name") }) public class SoftwareModuleType extends NamedEntity { - /** - * - */ private static final long serialVersionUID = 1L; @Column(name = "type_key", nullable = false, length = 64) @@ -92,48 +86,26 @@ public class SoftwareModuleType extends NamedEntity { super(); } - /** - * @return the key - */ public String getKey() { return key; } - /** - * @return the max - */ public int getMaxAssignments() { return maxAssignments; } - /** - * @return the deleted - */ public boolean isDeleted() { return deleted; } - /** - * @param deleted - * the deleted to set - */ public void setDeleted(final boolean deleted) { this.deleted = deleted; } - /** - * - * @return the software type color - */ public String getColour() { return colour; } - /** - * - * @param colour - * the col - */ public void setColour(final String colour) { this.colour = colour; } @@ -142,5 +114,4 @@ public class SoftwareModuleType extends NamedEntity { public String toString() { return "SoftwareModuleType [key=" + key + ", getName()=" + getName() + ", getId()=" + getId() + "]"; } - } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SwMetadataCompositeKey.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SwMetadataCompositeKey.java index 2518e4b1b..90b3779a1 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SwMetadataCompositeKey.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SwMetadataCompositeKey.java @@ -11,16 +11,10 @@ package org.eclipse.hawkbit.repository.model; import java.io.Serializable; /** - * The Software Module Metadata composite key which contains the meta data key + * The Software Module meta data composite key which contains the meta data key * and the ID of the software module itself. - * - * - * */ public final class SwMetadataCompositeKey implements Serializable { - /** - * - */ private static final long serialVersionUID = 1L; private String key; @@ -28,9 +22,10 @@ public final class SwMetadataCompositeKey implements Serializable { private Long softwareModule; /** - * - */ + * Default constructor for JPA. + */ public SwMetadataCompositeKey() { + // Default constructor for JPA. } /** @@ -74,25 +69,15 @@ public final class SwMetadataCompositeKey implements Serializable { this.softwareModule = softwareModule; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); - result = prime * result + ((softwareModule == null) ? 0 : softwareModule.hashCode()); + result = prime * result + (key == null ? 0 : key.hashCode()); + result = prime * result + (softwareModule == null ? 0 : softwareModule.hashCode()); return result; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(final Object obj) { // NOSONAR - as this is generated // code diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java index c03a02f3e..23489ea12 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java @@ -14,14 +14,9 @@ import javax.persistence.MappedSuperclass; import org.springframework.hateoas.Identifiable; /** - * A Tag can be used as describing and organisational meta information for any + * A Tag can be used as describing and organizational meta information for any * kind of entity. * - * - * - * - * - * */ @MappedSuperclass public abstract class Tag extends NamedEntity implements Identifiable { @@ -57,14 +52,8 @@ public abstract class Tag extends NamedEntity implements Identifiable { this.colour = colour; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ @Override public String toString() { return "Tag [getOptLockRevision()=" + getOptLockRevision() + ", getId()=" + getId() + "]"; } - } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Target.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Target.java index 07a97ebcf..5f37fb653 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Target.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Target.java @@ -56,11 +56,6 @@ import org.springframework.data.domain.Persistable; * {@link TargetStatus#REGISTERED}, i.e. a target {@link DistributionSet} . *

* - * - * - * - * - * */ @Entity @Table(name = "sp_target", indexes = { @@ -117,7 +112,7 @@ public class Target extends NamedEntity implements Persistable { /** * Constructor. - * + * * @param controllerId * controller ID of the {@link Target} */ @@ -136,28 +131,6 @@ public class Target extends NamedEntity implements Persistable { securityToken = null; } - @Override - public boolean equals(final Object obj) {// NOSONAR - as this is generated - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final Target other = (Target) obj; - if (controllerId == null) { - if (other.controllerId != null) { - return false; - } - } else if (!controllerId.equals(other.controllerId)) { - return false; - } - return true; - } - public DistributionSet getAssignedDistributionSet() { return assignedDistributionSet; } @@ -170,37 +143,18 @@ public class Target extends NamedEntity implements Persistable { return tags; } - @Override - public int hashCode() { // NOSONAR - as this is generated - final int prime = 31; - int result = 1; - result = prime * result + (controllerId == null ? 0 : controllerId.hashCode()); - return result; - } - public void setAssignedDistributionSet(final DistributionSet assignedDistributionSet) { this.assignedDistributionSet = assignedDistributionSet; } - /** - * @param controllerId - * the controllerId to set - */ public void setControllerId(final String controllerId) { this.controllerId = controllerId; } - /** - * @param tags - * the tags to set - */ public void setTags(final Set tags) { this.tags = tags; } - /** - * @return the actions - */ public List getActions() { return actions; } @@ -209,11 +163,6 @@ public class Target extends NamedEntity implements Persistable { return new TargetIdName(getId(), getControllerId(), getName()); } - /* - * (non-Javadoc) - * - * @see org.springframework.data.domain.Persistable#isNew() - */ @Override @Transient public boolean isNew() { @@ -261,11 +210,6 @@ public class Target extends NamedEntity implements Persistable { this.securityToken = securityToken; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ @Override public String toString() { return "Target [controllerId=" + controllerId + ", getId()=" + getId() + "]"; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java index 8d76b7ae5..021b9ca7f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java @@ -15,18 +15,14 @@ import javax.persistence.Table; import javax.persistence.UniqueConstraint; /** - * + * Stored target filter. * */ @Entity @Table(name = "sp_target_filter_query", indexes = { @Index(name = "sp_idx_target_filter_query_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { - "name", "tenant" }, name = "uk_tenant_custom_filter_name") ) -public class TargetFilterQuery extends BaseEntity { - /** - * - * - */ + "name", "tenant" }, name = "uk_tenant_custom_filter_name")) +public class TargetFilterQuery extends TenantAwareBaseEntity { private static final long serialVersionUID = 7493966984413479089L; @Column(name = "name", length = 64) @@ -36,8 +32,7 @@ public class TargetFilterQuery extends BaseEntity { private String query; public TargetFilterQuery() { - name = null; - query = null; + // Default constructor for JPA. } public TargetFilterQuery(final String name, final String query) { @@ -45,63 +40,19 @@ public class TargetFilterQuery extends BaseEntity { this.query = query; } - /** - * @return the name - */ public String getName() { return name; } - /** - * @param name - * the name to set - */ public void setName(final String name) { this.name = name; } - /** - * @return the query - */ public String getQuery() { return query; } - /** - * @param query - * the query to set - */ public void setQuery(final String query) { this.query = query; } - - @Override - public boolean equals(final Object obj) {// NOSONAR - as this is generated - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final TargetFilterQuery other = (TargetFilterQuery) obj; - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { - return false; - } - return true; - } - - @Override - public int hashCode() { // NOSONAR - as this is generated - final int prime = 31; - int result = 1; - result = prime * result + (name == null ? 0 : name.hashCode()); - return result; - } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetIdName.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetIdName.java index f7a63b775..26a74e9bb 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetIdName.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetIdName.java @@ -13,19 +13,12 @@ import java.io.Serializable; /** * ID class of the {@link Target} which contains the * {@link Target#getControllerId()} and the {@link Target#getName()} in one - * object. Often it's necessary to remeber the IDs of the {@link Target} and the - * resolve for e.g. the UI the name of the target, this is very costly + * object. Often it's necessary to remember the IDs of the {@link Target} and + * the resolve for e.g. the UI the name of the target, this is very costly * operation, so it's much better if the ID and the name of the {@link Target} * is already in memory available. - * - * - * - * */ public class TargetIdName implements Serializable { - /** - * - */ private static final long serialVersionUID = 1L; private final long targetId; @@ -46,61 +39,34 @@ public class TargetIdName implements Serializable { this.name = name; } - /** - * @return the controller id - */ public String getControllerId() { return controllerId; } - /** - * @return the name - */ public String getName() { return name; } - /** - * @param id - * the id to set - */ public void setControllerId(final String id) { - this.controllerId = id; + controllerId = id; } - /** - * @param name - * the name to set - */ public void setName(final String name) { this.name = name; } - /** - * @return the targetId - */ public long getTargetId() { return targetId; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + (int) (targetId ^ (targetId >>> 32)); + result = prime * result + (int) (targetId ^ targetId >>> 32); return result; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(final Object obj) { if (this == obj) { @@ -119,11 +85,6 @@ public class TargetIdName implements Serializable { return true; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ @Override public String toString() { // only return the ID because it's used in vaadin for setting the item diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java index 09d9fed28..47f52579a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java @@ -54,19 +54,11 @@ import org.springframework.data.domain.Persistable; * modifying the {@link Target} itself when a controller reports it's * {@link #lastTargetQuery} for example. * - * - * - * */ @Table(name = "sp_target_info", indexes = { @Index(name = "sp_idx_target_info_02", columnList = "target_id,update_status") }) @Entity -// @DynamicUpdate public class TargetInfo implements Persistable, Serializable { - - /** - * - */ private static final long serialVersionUID = 1L; private static final Logger LOG = LoggerFactory.getLogger(TargetInfo.class); @@ -81,9 +73,6 @@ public class TargetInfo implements Persistable, Serializable { @OneToOne(cascade = { CascadeType.MERGE, CascadeType.REMOVE }, fetch = FetchType.LAZY, targetEntity = Target.class) @JoinColumn(name = "target_id", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_stat_targ")) @MapsId - // use deprecated annotation until HHH-8862 is fixed - // @SuppressWarnings( "deprecation" ) - // @org.hibernate.annotations.ForeignKey( name = "fk_targ_stat_targ" ) private Target target; @Column(name = "address", length = 512) @@ -111,9 +100,7 @@ public class TargetInfo implements Persistable, Serializable { @MapKeyColumn(name = "attribute_key", nullable = false, length = 32) @CollectionTable(name = "sp_target_attributes", joinColumns = { @JoinColumn(name = "target_id") }, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_attrib_target")) - // use deprecated annotation until HHH-8862 is fixed - // @org.hibernate.annotations.ForeignKey( name = "fk_targ_attrib_target" ) private final Map controllerAttributes = Collections.synchronizedMap(new HashMap()); // set default request controller attributes to true, because we want to @@ -124,7 +111,7 @@ public class TargetInfo implements Persistable, Serializable { /** * Constructor for {@link TargetStatus}. - * + * * @param target * related to this status. */ @@ -138,21 +125,11 @@ public class TargetInfo implements Persistable, Serializable { targetId = null; } - /* - * (non-Javadoc) - * - * @see org.springframework.data.domain.Persistable#getId() - */ @Override public Long getId() { return targetId; } - /* - * (non-Javadoc) - * - * @see org.springframework.data.domain.Persistable#isNew() - */ @Override @Transient public boolean isNew() { @@ -198,114 +175,62 @@ public class TargetInfo implements Persistable, Serializable { this.address = address; } - /** - * @return the targetId - */ public Long getTargetId() { return targetId; } - /** - * @param targetId - * the targetId to set - */ public void setTargetId(final Long targetId) { this.targetId = targetId; } - /** - * @return the target - */ public Target getTarget() { return target; } - /** - * @param target - * the target to set - */ public void setTarget(final Target target) { this.target = target; } - /** - * @return the lastTargetQuery - */ public Long getLastTargetQuery() { return lastTargetQuery; } - /** - * @param lastTargetQuery - * the lastTargetQuery to set - */ public void setLastTargetQuery(final Long lastTargetQuery) { this.lastTargetQuery = lastTargetQuery; } - /** - * @param requestControllerAttributes - * the requestControllerAttributes to set - */ public void setRequestControllerAttributes(final boolean requestControllerAttributes) { this.requestControllerAttributes = requestControllerAttributes; } - /** - * @return the controllerAttributes - */ public Map getControllerAttributes() { return controllerAttributes; } - /** - * @return the requestControllerAttributes - */ public boolean isRequestControllerAttributes() { return requestControllerAttributes; } - /** - * @return the installationDate - */ public Long getInstallationDate() { return installationDate; } - /** - * @param installationDate - * the installationDate to set - */ public void setInstallationDate(final Long installationDate) { this.installationDate = installationDate; } - /** - * @return the updateStatus - */ public TargetUpdateStatus getUpdateStatus() { return updateStatus; } - /** - * @param updateStatus - * the updateStatus to set - */ public void setUpdateStatus(final TargetUpdateStatus updateStatus) { this.updateStatus = updateStatus; } - /** - * @return the installedDistributionSet - */ public DistributionSet getInstalledDistributionSet() { return installedDistributionSet; } - /** - * @param installedDistributionSet - * the installedDistributionSet to set - */ public void setInstalledDistributionSet(final DistributionSet installedDistributionSet) { this.installedDistributionSet = installedDistributionSet; } @@ -338,8 +263,6 @@ public class TargetInfo implements Persistable, Serializable { * The poll time object which holds all the necessary information around the * target poll time, e.g. the last poll time, the next poll time and the * overdue poll time. - * - * * */ public static final class PollStatus { @@ -359,7 +282,7 @@ public class TargetInfo implements Persistable, Serializable { /** * calculates if the target poll time is overdue and the target has not * been polled in the configured poll time interval. - * + * * @return {@code true} if the current time is after the poll time * overdue date otherwise {@code false}. */ @@ -386,15 +309,48 @@ public class TargetInfo implements Persistable, Serializable { return currentDate; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ @Override public String toString() { return "PollTime [lastPollDate=" + lastPollDate + ", nextPollDate=" + nextPollDate + ", overdueDate=" + overdueDate + ", currentDate=" + currentDate + "]"; } } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((target == null) ? 0 : target.hashCode()); + result = prime * result + ((targetId == null) ? 0 : targetId.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof TargetInfo)) { + return false; + } + final TargetInfo other = (TargetInfo) obj; + if (target == null) { + if (other.target != null) { + return false; + } + } else if (!target.equals(other.target)) { + return false; + } + if (targetId == null) { + if (other.targetId != null) { + return false; + } + } else if (!targetId.equals(other.targetId)) { + return false; + } + return true; + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java index 781bf9d16..5a5a310d0 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java @@ -21,16 +21,11 @@ import javax.persistence.UniqueConstraint; * A {@link TargetTag} is used to describe Target attributes and use them also * for filtering the target list. * - * - * - * - * - * */ @Entity @Table(name = "sp_target_tag", indexes = { @Index(name = "sp_idx_target_tag_prim", columnList = "tenant,id") }, uniqueConstraints = @UniqueConstraint(columnNames = { - "name", "tenant" }, name = "uk_targ_tag") ) + "name", "tenant" }, name = "uk_targ_tag")) public class TargetTag extends Tag { private static final long serialVersionUID = 1L; @@ -65,18 +60,10 @@ public class TargetTag extends Tag { super(); } - /** - * @return the assignedToTargets - */ public List getAssignedToTargets() { return assignedToTargets; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { final int prime = 31; @@ -85,16 +72,8 @@ public class TargetTag extends Tag { return result; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(final Object obj) { - if (this == obj) { - return true; - } if (!super.equals(obj)) { return false; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTagAssigmentResult.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTagAssignmentResult.java similarity index 82% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTagAssigmentResult.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTagAssignmentResult.java index b12b80d58..789e6adf2 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTagAssigmentResult.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTagAssignmentResult.java @@ -11,13 +11,10 @@ package org.eclipse.hawkbit.repository.model; import java.util.List; /** - * Result object for {@link TargetTag} assigments. - * - * - * + * Result object for {@link TargetTag} assignments. * */ -public class TargetTagAssigmentResult extends AssignmentResult { +public class TargetTagAssignmentResult extends AssignmentResult { private final int unassigned; private final List assignedTargets; @@ -40,7 +37,7 @@ public class TargetTagAssigmentResult extends AssignmentResult { * @param targetTag * the assigned or unassigned tag */ - public TargetTagAssigmentResult(final int alreadyAssigned, final int assigned, final int unassigned, + public TargetTagAssignmentResult(final int alreadyAssigned, final int assigned, final int unassigned, final List assignedTargets, final List unassignedTargets, final TargetTag targetTag) { super(assigned, alreadyAssigned); this.unassigned = unassigned; @@ -49,23 +46,14 @@ public class TargetTagAssigmentResult extends AssignmentResult { this.targetTag = targetTag; } - /** - * @return the unassigned - */ public int getUnassigned() { return unassigned; } - /** - * @return the assignedTargets - */ public List getAssignedTargets() { return assignedTargets; } - /** - * @return the unassignedTargets - */ public List getUnassignedTargets() { return unassignedTargets; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetUpdateStatus.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetUpdateStatus.java index cecbf8339..7721dabda 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetUpdateStatus.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetUpdateStatus.java @@ -13,11 +13,6 @@ package org.eclipse.hawkbit.repository.model; * status. A {@link Target} can have only one status. independent of the number * of {@link UpdateAction}s that have to be applied. * - * - * - * - * - * */ public enum TargetUpdateStatus { diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java index a75141658..ec09da3d5 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java @@ -30,32 +30,18 @@ public class TargetWithActionStatus { this.target = target; } - /** - * @return the target - */ public Target getTarget() { return target; } - /** - * @return the status - */ public Status getStatus() { return status; } - /** - * @param target - * the target to set - */ public void setTarget(final Target target) { this.target = target; } - /** - * @param status - * the status to set - */ public void setStatus(final Status status) { this.status = status; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java new file mode 100644 index 000000000..d03a4938a --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java @@ -0,0 +1,113 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.model; + +import javax.persistence.Column; +import javax.persistence.MappedSuperclass; +import javax.persistence.PrePersist; + +import org.eclipse.hawkbit.repository.exception.TenantNotExistException; +import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder; +import org.eclipse.hawkbit.repository.model.helper.TenantAwareHolder; +import org.eclipse.persistence.annotations.Multitenant; +import org.eclipse.persistence.annotations.MultitenantType; +import org.eclipse.persistence.annotations.TenantDiscriminatorColumn; + +/** + * Holder of the base attributes common to all tenant aware entities. + * + */ +@MappedSuperclass +@TenantDiscriminatorColumn(name = "tenant", length = 40) +@Multitenant(MultitenantType.SINGLE_TABLE) +public abstract class TenantAwareBaseEntity extends BaseEntity { + private static final long serialVersionUID = 1L; + + @Column(name = "tenant", nullable = false, insertable = false, updatable = false, length = 40) + private String tenant; + + /** + * Default constructor needed for JPA entities. + */ + public TenantAwareBaseEntity() { + // Default constructor needed for JPA entities. + } + + /** + * PrePersist listener method for all {@link TenantAwareBaseEntity} + * entities. + */ + @PrePersist + public void prePersist() { + // before persisting the entity check the current ID of the tenant by + // using the TenantAware + // service + final String currentTenant = SystemManagementHolder.getInstance().currentTenant(); + if (currentTenant == null) { + throw new TenantNotExistException("Tenant " + + TenantAwareHolder.getInstance().getTenantAware().getCurrentTenant() + + " does not exists, cannot create entity " + this.getClass() + " with id " + super.getId()); + } + setTenant(currentTenant.toUpperCase()); + } + + public String getTenant() { + return tenant; + } + + public void setTenant(final String tenant) { + this.tenant = tenant; + } + + @Override + public String toString() { + return "BaseEntity [id=" + super.getId() + "]"; + } + + /** + * Tenant aware entities extend the equals/hashcode strategy with the tenant + * name. That would allow for instance in a multi-schema based data + * separation setup to have the same primary key for different entities of + * different tenants. + * + * @see org.eclipse.hawkbit.repository.model.BaseEntity#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (tenant == null ? 0 : tenant.hashCode()); + return result; + } + + /** + * Tenant aware entities extend the equals/hashcode strategy with the tenant + * name. That would allow for instance in a multi-schema based data + * separation setup to have the same primary key for different entities of + * different tenants. + * + * @see org.eclipse.hawkbit.repository.model.BaseEntity#equals(java.lang.Object) + */ + @Override + public boolean equals(final Object obj) { + if (!super.equals(obj)) { + return false; + } + final TenantAwareBaseEntity other = (TenantAwareBaseEntity) obj; + if (tenant == null) { + if (other.tenant != null) { + return false; + } + } else if (!tenant.equals(other.tenant)) { + return false; + } + return true; + } + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java index d571a2ea7..5a938563b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java @@ -19,18 +19,11 @@ import javax.persistence.UniqueConstraint; /** * A JPA entity which stores the tenant specific configuration. * - * - * - * */ @Entity @Table(name = "sp_tenant_configuration", uniqueConstraints = @UniqueConstraint(columnNames = { "conf_key", - "tenant" }, name = "uk_tenant_key") ) -public class TenantConfiguration extends BaseEntity implements Serializable { - - /** - * - */ + "tenant" }, name = "uk_tenant_key")) +public class TenantConfiguration extends TenantAwareBaseEntity implements Serializable { private static final long serialVersionUID = 1L; @Column(name = "conf_key", length = 128) @@ -44,7 +37,7 @@ public class TenantConfiguration extends BaseEntity implements Serializable { * JPA default constructor. */ public TenantConfiguration() { - + // JPA default constructor. } /** @@ -59,75 +52,20 @@ public class TenantConfiguration extends BaseEntity implements Serializable { } - /** - * @return the key - */ public String getKey() { return key; } - /** - * @param key - * the key to set - */ public void setKey(final String key) { this.key = key; } - /** - * @return the value - */ public String getValue() { return value; } - /** - * @param value - * the value to set - */ public void setValue(final String value) { this.value = value; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); - return result; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object obj) { // NOSONAR - as this is generated - // code - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final TenantConfiguration other = (TenantConfiguration) obj; - if (key == null) { - if (other.key != null) { - return false; - } - } else if (!key.equals(other.key)) { - return false; - } - return true; - } - } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java index d8483e12f..37e00e247 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java @@ -89,7 +89,7 @@ public class TenantConfigurationValue { */ public static TenantConfigurationValueBuilder builder() { - return new TenantConfigurationValueBuilder(); + return new TenantConfigurationValueBuilder<>(); } /** diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java index e86bfe8a4..a9572c21c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java @@ -8,76 +8,45 @@ */ package org.eclipse.hawkbit.repository.model; -import java.io.Serializable; - -import javax.persistence.Access; -import javax.persistence.AccessType; import javax.persistence.Column; import javax.persistence.ConstraintMode; import javax.persistence.Entity; +import javax.persistence.EntityManager; import javax.persistence.FetchType; import javax.persistence.ForeignKey; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; import javax.persistence.Index; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.UniqueConstraint; -import javax.persistence.Version; - -import org.springframework.data.annotation.CreatedBy; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.annotation.LastModifiedBy; -import org.springframework.data.annotation.LastModifiedDate; /** - * Tenant metadata that is configured globally for the entire tenant. This - * entity is - * - * + * Tenant entity with meta data that is configured globally for the entire + * tenant. This entity is not tenant aware to allow the system to access it + * through the {@link EntityManager} even before the actual tenant exists. * + * Entities owned by the tenant are based on {@link TenantAwareBaseEntity}. * */ -@Access(AccessType.FIELD) @Table(name = "sp_tenant", indexes = { @Index(name = "sp_idx_tenant_prim", columnList = "tenant,id") }, uniqueConstraints = { @UniqueConstraint(columnNames = { "tenant" }, name = "uk_tenantmd_tenant") }) @Entity -public class TenantMetaData implements Serializable { - - /** - * - */ +public class TenantMetaData extends BaseEntity { private static final long serialVersionUID = 1L; - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id") - private Long id; - @Column(name = "tenant", nullable = false, length = 40) private String tenant; - private String createdBy; - private String lastModifiedBy; - private Long createdAt; - private Long lastModifiedAt; - - @Version - @Column(name = "optlock_revision") - private long optLockRevision; - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "default_ds_type", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_tenant_md_default_ds_type") ) - // use deprecated annotation until HHH-8862 is fixed - @SuppressWarnings("deprecation") - // @org.hibernate.annotations.ForeignKey( name = - // "fk_tenant_md_default_ds_type" ) + @JoinColumn(name = "default_ds_type", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_tenant_md_default_ds_type")) private DistributionSetType defaultDsType; + /** + * Default constructor needed for JPA entities. + */ public TenantMetaData() { + // Default constructor needed for JPA entities. } /** @@ -93,167 +62,39 @@ public class TenantMetaData implements Serializable { this.tenant = tenant; } - /** - * @return the defaultDsType - */ public DistributionSetType getDefaultDsType() { return defaultDsType; } - /** - * Set the DistributionSet for a tenant. - * - * @param defaultDsType - * the new default DistributionSet - */ public void setDefaultDsType(final DistributionSetType defaultDsType) { this.defaultDsType = defaultDsType; } - /** - * @return the id - */ - public Long getId() { - return id; - } - - /** - * @param id - * the id to set - */ - public void setId(final Long id) { - this.id = id; - } - - @Access(AccessType.PROPERTY) - @Column(name = "created_at", insertable = true, updatable = false) - public Long getCreatedAt() { - return createdAt; - } - - @Access(AccessType.PROPERTY) - @Column(name = "created_by", insertable = true, updatable = false, length = 40) - public String getCreatedBy() { - return createdBy; - } - - @Access(AccessType.PROPERTY) - @Column(name = "last_modified_at", insertable = false, updatable = true) - public Long getLastModifiedAt() { - return lastModifiedAt; - } - - @Access(AccessType.PROPERTY) - @Column(name = "last_modified_by", insertable = false, updatable = true, length = 40) - public String getLastModifiedBy() { - return lastModifiedBy; - } - - /** - * @param createdBy - * the createdBy to set - */ - @CreatedBy - public void setCreatedBy(final String createdBy) { - this.createdBy = createdBy; - } - - /** - * @param lastModifiedBy - * the lastModifiedBy to set - */ - @LastModifiedBy - public void setLastModifiedBy(final String lastModifiedBy) { - this.lastModifiedBy = lastModifiedBy; - } - - /** - * @param createdAt - * the createdAt to set - */ - @CreatedDate - public void setCreatedAt(final Long createdAt) { - this.createdAt = createdAt; - } - - /** - * @param lastModifiedAt - * the lastModifiedAt to set - */ - @LastModifiedDate - public void setLastModifiedAt(final Long lastModifiedAt) { - this.lastModifiedAt = lastModifiedAt; - } - - /** - * @return the optLockRevision - */ - public long getOptLockRevision() { - return optLockRevision; - } - - /** - * @param optLockRevision - * the optLockRevision to set - */ - public void setOptLockRevision(final long optLockRevision) { - this.optLockRevision = optLockRevision; - } - - /** - * @return the tenant - */ public String getTenant() { return tenant; } - /** - * @param tenant - * the tenant to set - */ public void setTenant(final String tenant) { this.tenant = tenant; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); + int result = super.hashCode(); + result = prime * result + this.getClass().getName().hashCode(); return result; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ @Override - public boolean equals(final Object obj) { // NOSONAR - as this is generated - // code - if (this == obj) { - return true; - } - if (obj == null) { + public boolean equals(final Object obj) { + if (!super.equals(obj)) { return false; } - if (getClass() != obj.getClass()) { - return false; - } - final TenantMetaData other = (TenantMetaData) obj; - if (id == null) { - if (other.id != null) { - return false; - } - } else if (!id.equals(other.id)) { + if (!(obj instanceof TenantMetaData)) { return false; } + return true; } - } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/rsql/RSQLUtility.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/rsql/RSQLUtility.java index 03f213fef..c2ed5f900 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/rsql/RSQLUtility.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/rsql/RSQLUtility.java @@ -139,14 +139,6 @@ public final class RSQLUtility { this.enumType = enumType; } - /* - * (non-Javadoc) - * - * @see - * org.springframework.data.jpa.domain.Specification#toPredicate(javax. - * persistence.criteria .Root, javax.persistence.criteria.CriteriaQuery, - * javax.persistence.criteria.CriteriaBuilder) - */ @Override public Predicate toPredicate(final Root root, final CriteriaQuery query, final CriteriaBuilder cb) { diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/DistributionSetSpecification.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/DistributionSetSpecification.java index 4150229c6..b95f0b8e7 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/DistributionSetSpecification.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/DistributionSetSpecification.java @@ -11,13 +11,11 @@ package org.eclipse.hawkbit.repository.specifications; import java.util.Collection; import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Join; import javax.persistence.criteria.JoinType; import javax.persistence.criteria.ListJoin; import javax.persistence.criteria.Path; import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; import javax.persistence.criteria.SetJoin; import org.eclipse.hawkbit.repository.model.DistributionSet; @@ -33,9 +31,7 @@ import org.springframework.data.jpa.domain.Specification; /** * Specifications class for {@link DistributionSet}s. The class provides Spring - * Data JPQL Specifications - * - * + * Data JPQL Specifications. * */ public final class DistributionSetSpecification { @@ -53,16 +49,8 @@ public final class DistributionSetSpecification { * @return the {@link DistributionSet} {@link Specification} */ public static Specification isDeleted(final Boolean isDeleted) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final Predicate predicate = cb.equal(targetRoot. get(DistributionSet_.deleted), isDeleted); - return predicate; - } - }; + return (targetRoot, query, cb) -> cb.equal(targetRoot. get(DistributionSet_.deleted), isDeleted); - return spec; } /** @@ -75,16 +63,8 @@ public final class DistributionSetSpecification { * @return the {@link DistributionSet} {@link Specification} */ public static Specification isCompleted(final Boolean isCompleted) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final Predicate predicate = cb.equal(targetRoot. get(DistributionSet_.complete), isCompleted); - return predicate; - } - }; + return (targetRoot, query, cb) -> cb.equal(targetRoot. get(DistributionSet_.complete), isCompleted); - return spec; } /** @@ -96,21 +76,15 @@ public final class DistributionSetSpecification { * @return the {@link DistributionSet} {@link Specification} */ public static Specification byId(final Long distid) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { + return (targetRoot, query, cb) -> { + final Predicate predicate = cb.equal(targetRoot. get(DistributionSet_.id), distid); + targetRoot.fetch(DistributionSet_.modules, JoinType.LEFT); + targetRoot.fetch(DistributionSet_.tags, JoinType.LEFT); + targetRoot.fetch(DistributionSet_.type, JoinType.LEFT); + query.distinct(true); - final Predicate predicate = cb.equal(targetRoot. get(DistributionSet_.id), distid); - targetRoot.fetch(DistributionSet_.modules, JoinType.LEFT); - targetRoot.fetch(DistributionSet_.tags, JoinType.LEFT); - targetRoot.fetch(DistributionSet_.type, JoinType.LEFT); - query.distinct(true); - - return predicate; - } + return predicate; }; - return spec; } /** @@ -122,20 +96,14 @@ public final class DistributionSetSpecification { * @return the {@link DistributionSet} {@link Specification} */ public static Specification byIds(final Collection distids) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - - final Predicate predicate = targetRoot. get(DistributionSet_.id).in(distids); - targetRoot.fetch(DistributionSet_.modules, JoinType.LEFT); - targetRoot.fetch(DistributionSet_.tags, JoinType.LEFT); - targetRoot.fetch(DistributionSet_.type, JoinType.LEFT); - query.distinct(true); - return predicate; - } + return (targetRoot, query, cb) -> { + final Predicate predicate = targetRoot. get(DistributionSet_.id).in(distids); + targetRoot.fetch(DistributionSet_.modules, JoinType.LEFT); + targetRoot.fetch(DistributionSet_.tags, JoinType.LEFT); + targetRoot.fetch(DistributionSet_.type, JoinType.LEFT); + query.distinct(true); + return predicate; }; - return spec; } /** @@ -147,21 +115,10 @@ public final class DistributionSetSpecification { * @return the {@link DistributionSet} {@link Specification} */ public static Specification likeNameOrDescriptionOrVersion(final String subString) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final Predicate predicate = cb - .or(cb.like(cb.lower(targetRoot. get(DistributionSet_.name)), subString.toLowerCase()), - cb.like(cb.lower(targetRoot. get(DistributionSet_.version)), - subString.toLowerCase()), - cb.like(cb.lower(targetRoot. get(DistributionSet_.description)), - subString.toLowerCase())); - return predicate; - } - }; - - return spec; + return (targetRoot, query, cb) -> cb.or( + cb.like(cb.lower(targetRoot. get(DistributionSet_.name)), subString.toLowerCase()), + cb.like(cb.lower(targetRoot. get(DistributionSet_.version)), subString.toLowerCase()), + cb.like(cb.lower(targetRoot. get(DistributionSet_.description)), subString.toLowerCase())); } /** @@ -176,19 +133,13 @@ public final class DistributionSetSpecification { */ public static Specification hasTags(final Collection tagNames, final Boolean selectDSWithNoTag) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final SetJoin tags = targetRoot.join(DistributionSet_.tags, - JoinType.LEFT); - final Predicate predicate = getPredicate(tags, tagNames, selectDSWithNoTag, cb); - query.distinct(true); - return predicate; - } + return (targetRoot, query, cb) -> { + final SetJoin tags = targetRoot.join(DistributionSet_.tags, + JoinType.LEFT); + final Predicate predicate = getPredicate(tags, tagNames, selectDSWithNoTag, cb); + query.distinct(true); + return predicate; }; - - return spec; } private static Predicate getPredicate(final SetJoin tags, @@ -218,20 +169,10 @@ public final class DistributionSetSpecification { */ public static Specification equalsNameAndVersionIgnoreCase(final String name, final String version) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final Predicate predicate = cb.and( - // formatter:off - cb.equal(cb.lower(targetRoot. get(DistributionSet_.name)), name.toLowerCase()), - cb.equal(cb.lower(targetRoot. get(DistributionSet_.version)), version.toLowerCase())); - // formatter:on - return predicate; - } - }; + return (targetRoot, query, cb) -> cb.and( + cb.equal(cb.lower(targetRoot. get(DistributionSet_.name)), name.toLowerCase()), + cb.equal(cb.lower(targetRoot. get(DistributionSet_.version)), version.toLowerCase())); - return spec; } /** @@ -243,16 +184,8 @@ public final class DistributionSetSpecification { * @return the {@link DistributionSet} {@link Specification} */ public static Specification byType(final DistributionSetType type) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final Predicate predicate = cb.equal(targetRoot. get(DistributionSet_.type), type); - return predicate; - } - }; + return (targetRoot, query, cb) -> cb.equal(targetRoot. get(DistributionSet_.type), type); - return spec; } /** @@ -263,18 +196,12 @@ public final class DistributionSetSpecification { * installed to the given targetId */ public static Specification installedTarget(final String installedTargetId) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root dsRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final ListJoin installedTargetJoin = dsRoot - .join(DistributionSet_.installedAtTargets, JoinType.INNER); - final Join targetJoin = installedTargetJoin.join(TargetInfo_.target); - return cb.equal(targetJoin.get(Target_.controllerId), installedTargetId); - } + return (dsRoot, query, cb) -> { + final ListJoin installedTargetJoin = dsRoot + .join(DistributionSet_.installedAtTargets, JoinType.INNER); + final Join targetJoin = installedTargetJoin.join(TargetInfo_.target); + return cb.equal(targetJoin.get(Target_.controllerId), installedTargetId); }; - - return spec; } /** @@ -285,16 +212,11 @@ public final class DistributionSetSpecification { * assigned to the given targetId */ public static Specification assignedTarget(final String assignedTargetId) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root dsRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final ListJoin assignedTargetJoin = dsRoot - .join(DistributionSet_.assignedToTargets, JoinType.INNER); - return cb.equal(assignedTargetJoin.get(Target_.controllerId), assignedTargetId); - } + return (dsRoot, query, cb) -> { + final ListJoin assignedTargetJoin = dsRoot.join(DistributionSet_.assignedToTargets, + JoinType.INNER); + return cb.equal(assignedTargetJoin.get(Target_.controllerId), assignedTargetId); }; - return spec; } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/DistributionSetTypeSpecification.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/DistributionSetTypeSpecification.java index 1caa5ef59..13776deb0 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/DistributionSetTypeSpecification.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/DistributionSetTypeSpecification.java @@ -8,22 +8,14 @@ */ package org.eclipse.hawkbit.repository.specifications; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; - import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.DistributionSetType_; import org.springframework.data.jpa.domain.Specification; /** - * - * - * - * - * + * Specifications class for {@link DistributionSetType}s. The class provides + * Spring Data JPQL Specifications. */ public final class DistributionSetTypeSpecification { private DistributionSetTypeSpecification() { @@ -40,16 +32,7 @@ public final class DistributionSetTypeSpecification { * @return the {@link DistributionSetType} {@link Specification} */ public static Specification isDeleted(final Boolean isDeleted) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final Predicate predicate = cb.equal(targetRoot. get(DistributionSetType_.deleted), isDeleted); - return predicate; - } - }; - - return spec; + return (targetRoot, query, cb) -> cb.equal(targetRoot. get(DistributionSetType_.deleted), isDeleted); } /** @@ -62,16 +45,7 @@ public final class DistributionSetTypeSpecification { * @return the {@link DistributionSet} {@link Specification} */ public static Specification byId(final Long distid) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - - final Predicate predicate = cb.equal(targetRoot. get(DistributionSetType_.id), distid); - return predicate; - } - }; - return spec; + return (targetRoot, query, cb) -> cb.equal(targetRoot. get(DistributionSetType_.id), distid); } /** @@ -84,16 +58,7 @@ public final class DistributionSetTypeSpecification { * @return the {@link DistributionSet} {@link Specification} */ public static Specification byName(final String name) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - - final Predicate predicate = cb.equal(targetRoot. get(DistributionSetType_.name), name); - return predicate; - } - }; - return spec; + return (targetRoot, query, cb) -> cb.equal(targetRoot. get(DistributionSetType_.name), name); } /** @@ -106,16 +71,7 @@ public final class DistributionSetTypeSpecification { * @return the {@link DistributionSet} {@link Specification} */ public static Specification byKey(final String key) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - - final Predicate predicate = cb.equal(targetRoot. get(DistributionSetType_.key), key); - return predicate; - } - }; - return spec; + return (targetRoot, query, cb) -> cb.equal(targetRoot. get(DistributionSetType_.key), key); } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/SoftwareModuleSpecification.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/SoftwareModuleSpecification.java index 2311f59f6..680f97778 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/SoftwareModuleSpecification.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/SoftwareModuleSpecification.java @@ -8,10 +8,7 @@ */ package org.eclipse.hawkbit.repository.specifications; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; @@ -22,8 +19,6 @@ import org.springframework.data.jpa.domain.Specification; * Specifications class for {@link SoftwareModule}s. The class provides Spring * Data JPQL Specifications * - * - * */ public final class SoftwareModuleSpecification { private SoftwareModuleSpecification() { @@ -39,38 +34,21 @@ public final class SoftwareModuleSpecification { * @return the {@link SoftwareModule} {@link Specification} */ public static Specification byId(final Long moduleId) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - - final Predicate predicate = cb.equal(targetRoot. get(SoftwareModule_.id), moduleId); - targetRoot.fetch(SoftwareModule_.type); - return predicate; - } + return (targetRoot, query, cb) -> { + final Predicate predicate = cb.equal(targetRoot. get(SoftwareModule_.id), moduleId); + targetRoot.fetch(SoftwareModule_.type); + return predicate; }; - return spec; } /** - * {@link Specification} for retrieving {@link SoftwareModule}s by its - * DELETED attribute. + * {@link Specification} for retrieving {@link SoftwareModule}s where its + * DELETED attribute is false. * - * @param isDeleted - * TRUE/FALSE are compared to the attribute DELETED. If NULL the - * attribute is ignored * @return the {@link SoftwareModule} {@link Specification} */ public static Specification isDeletedFalse() { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root swRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final Predicate predicate = cb.equal(swRoot. get(SoftwareModule_.deleted), Boolean.FALSE); - return predicate; - } - }; - return spec; + return (swRoot, query, cb) -> cb.equal(swRoot. get(SoftwareModule_.deleted), Boolean.FALSE); } /** @@ -82,18 +60,9 @@ public final class SoftwareModuleSpecification { * @return the {@link SoftwareModule} {@link Specification} */ public static Specification likeNameOrVersion(final String subString) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final Predicate predicate = cb.or( - cb.like(cb.lower(targetRoot. get(SoftwareModule_.name)), subString.toLowerCase()), - cb.like(cb.lower(targetRoot. get(SoftwareModule_.version)), subString.toLowerCase())); - return predicate; - } - }; - - return spec; + return (targetRoot, query, cb) -> cb.or( + cb.like(cb.lower(targetRoot. get(SoftwareModule_.name)), subString.toLowerCase()), + cb.like(cb.lower(targetRoot. get(SoftwareModule_.version)), subString.toLowerCase())); } /** @@ -105,16 +74,7 @@ public final class SoftwareModuleSpecification { * @return the {@link SoftwareModule} {@link Specification} */ public static Specification equalType(final SoftwareModuleType type) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final Predicate predicate = cb.equal(targetRoot. get(SoftwareModule_.type), type); - return predicate; - } - }; - - return spec; + return (targetRoot, query, cb) -> cb.equal(targetRoot. get(SoftwareModule_.type), type); } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/TargetFilterQuerySpecification.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/TargetFilterQuerySpecification.java index c92da7ed1..0b600c849 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/TargetFilterQuerySpecification.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/TargetFilterQuerySpecification.java @@ -8,17 +8,13 @@ */ package org.eclipse.hawkbit.repository.specifications; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; - import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.repository.model.TargetFilterQuery_; import org.springframework.data.jpa.domain.Specification; /** - * + * Specifications class for {@link TargetFilterQuery}s. The class provides + * Spring Data JPQL Specifications. * */ public class TargetFilterQuerySpecification { @@ -27,16 +23,9 @@ public class TargetFilterQuerySpecification { } public static Specification likeName(final String searchText) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetFilterQueryRoot, - final CriteriaQuery query, final CriteriaBuilder cb) { - final String searchTextToLower = searchText.toLowerCase(); - final Predicate predicate = cb.like(cb.lower(targetFilterQueryRoot.get(TargetFilterQuery_.name)), - searchTextToLower); - return predicate; - } + return (targetFilterQueryRoot, query, cb) -> { + final String searchTextToLower = searchText.toLowerCase(); + return cb.like(cb.lower(targetFilterQueryRoot.get(TargetFilterQuery_.name)), searchTextToLower); }; - return spec; } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/TargetSpecifications.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/TargetSpecifications.java index fb0e5740e..de894d3a3 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/TargetSpecifications.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/TargetSpecifications.java @@ -12,7 +12,6 @@ import java.util.Collection; import java.util.List; import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Join; import javax.persistence.criteria.JoinType; import javax.persistence.criteria.Path; @@ -36,8 +35,6 @@ import org.springframework.data.jpa.domain.Specification; * Specifications class for {@link Target}s. The class provides Spring Data JPQL * Specifications. * - * - * */ public final class TargetSpecifications { private TargetSpecifications() { @@ -54,18 +51,12 @@ public final class TargetSpecifications { * @return the {@link Target} {@link Specification} */ public static Specification byControllerIdWithStatusAndTagsInJoin(final Collection controllerIDs) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final Predicate predicate = targetRoot.get(Target_.controllerId).in(controllerIDs); - targetRoot.fetch(Target_.tags, JoinType.LEFT); - query.distinct(true); - return predicate; - } + return (targetRoot, query, cb) -> { + final Predicate predicate = targetRoot.get(Target_.controllerId).in(controllerIDs); + targetRoot.fetch(Target_.tags, JoinType.LEFT); + query.distinct(true); + return predicate; }; - - return spec; } /** @@ -79,18 +70,12 @@ public final class TargetSpecifications { */ public static Specification byControllerIdWithStatusAndAssignedInJoin( final Collection controllerIDs) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { + return (targetRoot, query, cb) -> { - final Predicate predicate = targetRoot.get(Target_.controllerId).in(controllerIDs); - targetRoot.fetch(Target_.assignedDistributionSet); - return predicate; - } + final Predicate predicate = targetRoot.get(Target_.controllerId).in(controllerIDs); + targetRoot.fetch(Target_.assignedDistributionSet); + return predicate; }; - - return spec; } /** @@ -106,24 +91,18 @@ public final class TargetSpecifications { */ public static Specification hasTargetUpdateStatus(final Collection updateStatus, final boolean fetch) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - if (!query.getResultType().isAssignableFrom(Long.class)) { - if (fetch) { - targetRoot.fetch(Target_.targetInfo); - } else { - targetRoot.join(Target_.targetInfo); - } - return targetRoot.get(Target_.targetInfo).get(TargetInfo_.updateStatus).in(updateStatus); + return (targetRoot, query, cb) -> { + if (!query.getResultType().isAssignableFrom(Long.class)) { + if (fetch) { + targetRoot.fetch(Target_.targetInfo); + } else { + targetRoot.join(Target_.targetInfo); } - final Join targetInfoJoin = targetRoot.join(Target_.targetInfo); - return targetInfoJoin.get(TargetInfo_.updateStatus).in(updateStatus); + return targetRoot.get(Target_.targetInfo).get(TargetInfo_.updateStatus).in(updateStatus); } + final Join targetInfoJoin = targetRoot.join(Target_.targetInfo); + return targetInfoJoin.get(TargetInfo_.updateStatus).in(updateStatus); }; - - return spec; } /** @@ -135,18 +114,11 @@ public final class TargetSpecifications { * @return the {@link Target} {@link Specification} */ public static Specification likeNameOrDescriptionOrIp(final String searchText) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final String searchTextToLower = searchText.toLowerCase(); - final Predicate predicate = cb.or(cb.like(cb.lower(targetRoot.get(Target_.name)), searchTextToLower), - cb.like(cb.lower(targetRoot.get(Target_.description)), searchTextToLower)); - return predicate; - } + return (targetRoot, query, cb) -> { + final String searchTextToLower = searchText.toLowerCase(); + return cb.or(cb.like(cb.lower(targetRoot.get(Target_.name)), searchTextToLower), + cb.like(cb.lower(targetRoot.get(Target_.description)), searchTextToLower)); }; - - return spec; } /** @@ -158,21 +130,14 @@ public final class TargetSpecifications { * @return the {@link Target} {@link Specification} */ public static Specification hasInstalledOrAssignedDistributionSet(@NotNull final Long distributionId) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final Join targetInfoJoin = targetRoot.join(Target_.targetInfo); - final Predicate predicate = cb.or( - cb.equal(targetInfoJoin.get(TargetInfo_.installedDistributionSet).get(DistributionSet_.id), - distributionId), - cb.equal(targetRoot. get(Target_.assignedDistributionSet) - .get(DistributionSet_.id), distributionId)); - return predicate; - } + return (targetRoot, query, cb) -> { + final Join targetInfoJoin = targetRoot.join(Target_.targetInfo); + return cb.or( + cb.equal(targetInfoJoin.get(TargetInfo_.installedDistributionSet).get(DistributionSet_.id), + distributionId), + cb.equal(targetRoot. get(Target_.assignedDistributionSet).get(DistributionSet_.id), + distributionId)); }; - - return spec; } /** @@ -187,18 +152,11 @@ public final class TargetSpecifications { */ public static Specification hasControllerIdAndAssignedDistributionSetIdNot(final List tIDs, @NotNull final Long distributionId) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final Predicate predicate = cb.and(targetRoot.get(Target_.controllerId).in(tIDs), + return (targetRoot, query, cb) -> cb + .and(targetRoot.get(Target_.controllerId).in(tIDs), cb.or(cb.notEqual(targetRoot. get(Target_.assignedDistributionSet) .get(DistributionSet_.id), distributionId), - cb.isNull(targetRoot. get(Target_.assignedDistributionSet)))); - return predicate; - } - }; - return spec; + cb.isNull(targetRoot. get(Target_.assignedDistributionSet)))); } /** @@ -212,16 +170,11 @@ public final class TargetSpecifications { * @return the {@link Target} {@link Specification} */ public static Specification hasTags(final String[] tagNames, final Boolean selectTargetWithNoTag) { - final Specification spec = new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final Predicate predicate = getPredicate(targetRoot, cb, selectTargetWithNoTag, tagNames); - query.distinct(true); - return predicate; - } + return (targetRoot, query, cb) -> { + final Predicate predicate = getPredicate(targetRoot, cb, selectTargetWithNoTag, tagNames); + query.distinct(true); + return predicate; }; - return spec; } private static Predicate getPredicate(final Root targetRoot, final CriteriaBuilder cb, @@ -248,15 +201,9 @@ public final class TargetSpecifications { * @return the {@link Target} {@link Specification} */ public static Specification hasAssignedDistributionSet(final Long distributionSetId) { - return new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - return cb.equal( - targetRoot. get(Target_.assignedDistributionSet).get(DistributionSet_.id), - distributionSetId); - } - }; + return (targetRoot, query, cb) -> cb.equal( + targetRoot. get(Target_.assignedDistributionSet).get(DistributionSet_.id), + distributionSetId); } /** @@ -268,14 +215,10 @@ public final class TargetSpecifications { * @return the {@link Target} {@link Specification} */ public static Specification hasInstalledDistributionSet(final Long distributionSetId) { - return new Specification() { - @Override - public Predicate toPredicate(final Root targetRoot, final CriteriaQuery query, - final CriteriaBuilder cb) { - final Join targetInfoJoin = targetRoot.join(Target_.targetInfo); - return cb.equal(targetInfoJoin.get(TargetInfo_.installedDistributionSet).get(DistributionSet_.id), - distributionSetId); - } + return (targetRoot, query, cb) -> { + final Join targetInfoJoin = targetRoot.join(Target_.targetInfo); + return cb.equal(targetInfoJoin.get(TargetInfo_.installedDistributionSet).get(DistributionSet_.id), + distributionSetId); }; } } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java index befcd6a8a..1787d29e4 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java @@ -95,7 +95,7 @@ public class TestDataUtil { return distributionSetManagement.createDistributionSet( buildDistributionSet(suffix != null && suffix.length() > 0 ? suffix : "DS", version, findOrCreateDistributionSetType(distributionSetManagement, "ecl_os_app_jvm", - "OC mandatory App/JVM optional", mand, opt), + "OS mandatory App/JVM optional", mand, opt), os, jvm, ah).setRequiredMigrationStep(isRequiredMigrationStep)); } @@ -143,7 +143,7 @@ public class TestDataUtil { } public static List generateDistributionSetTags(final int number) { - final List result = new ArrayList(); + final List result = new ArrayList<>(); for (int i = 0; i < number; i++) { result.add(new DistributionSetTag("tag" + i, "tagdesc" + i, "" + i)); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ActionTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ActionTest.java index 9bd532b5e..937a544a7 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ActionTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ActionTest.java @@ -33,12 +33,10 @@ public class ActionTest { final Action timeforcedAction = new Action(); timeforcedAction.setActionType(ActionType.TIMEFORCED); timeforcedAction.setForcedTime(timeForceTimeAt); - final int knownHashCode = timeforcedAction.hashCode(); assertThat(timeforcedAction.isForce()).isFalse(); // wait until timeforce time is hit Thread.sleep(sleepTime + 100); assertThat(timeforcedAction.isForce()).isTrue(); - assertThat(timeforcedAction.hashCode()).isNotEqualTo(knownHashCode); } } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementNoMongoDbTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementNoMongoDbTest.java index dd1e171ca..30f4093c2 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementNoMongoDbTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementNoMongoDbTest.java @@ -8,6 +8,8 @@ */ package org.eclipse.hawkbit.repository; +import static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; import java.io.IOException; @@ -37,7 +39,7 @@ public class ArtifactManagementNoMongoDbTest extends AbstractIntegrationTest { System.setProperty("spring.data.mongodb.port", "1020"); } - @Test(expected = ArtifactUploadFailedException.class) + @Test @Description("Checks if the expected ArtifactUploadFailedException is thrown in case of MongoDB down") public void createLocalArtifactWithMongoDbDown() throws IOException { SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", @@ -46,7 +48,12 @@ public class ArtifactManagementNoMongoDbTest extends AbstractIntegrationTest { final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); + try { + artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); + fail("Should not have worked with MongoDb down."); + } catch (final ArtifactUploadFailedException e) { + + } } } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementTest.java index 2929110dd..7c801a571 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementTest.java @@ -352,11 +352,16 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { artifactManagement.loadLocalArtifactBinary(result).getFileInputStream())); } - @Test(expected = InsufficientPermissionException.class) + @Test @WithUser(allSpPermissions = true, removeFromAllPermission = { SpPermission.DOWNLOAD_REPOSITORY_ARTIFACT }) @Description("Trys and fails to load an artifact without required permission. Checks if expected InsufficientPermissionException is thrown.") public void loadLocalArtifactBinaryWithoutDownloadArtifactThrowsPermissionDenied() { - artifactManagement.loadLocalArtifactBinary(new LocalArtifact()); + try { + artifactManagement.loadLocalArtifactBinary(new LocalArtifact()); + fail("Should not have worked with missing permission."); + } catch (final InsufficientPermissionException e) { + + } } @Test diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java index a3913da2b..d77c137b1 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java @@ -43,7 +43,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest { distributionSetManagement); Target savedTarget = targetManagement.createTarget(target); - final List toAssign = new ArrayList(); + final List toAssign = new ArrayList<>(); toAssign.add(savedTarget); assertThat(savedTarget.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN); @@ -75,7 +75,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest { } @Test - @Description("Register a controller which not exist") + @Description("Register a controller which does not exist") public void testfindOrRegisterTargetIfItDoesNotexist() { final Target target = controllerManagament.findOrRegisterTargetIfItDoesNotexist("AA", null); assertThat(target).as("target should not be null").isNotNull(); @@ -84,11 +84,12 @@ public class ControllerManagementTest extends AbstractIntegrationTest { assertThat(target).as("Target should be the equals").isEqualTo(sameTarget); assertThat(targetRepository.count()).as("Only 1 target should be registred").isEqualTo(1L); + // throws exception try { controllerManagament.findOrRegisterTargetIfItDoesNotexist("", null); - fail("target with empty controller id should not be registred"); + fail("should fail as target does not exist"); } catch (final ConstraintViolationException e) { - // ok + } } @@ -101,7 +102,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest { final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); Target savedTarget = targetManagement.createTarget(target); - final List toAssign = new ArrayList(); + final List toAssign = new ArrayList<>(); toAssign.add(savedTarget); savedTarget = deploymentManagement.assignDistributionSet(ds, toAssign).getAssignedTargets().iterator().next(); Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); @@ -124,7 +125,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest { final ActionStatus actionStatusMessage3 = new ActionStatus(savedAction, Action.Status.FINISHED, System.currentTimeMillis()); actionStatusMessage3.addMessage("finish"); - savedAction = controllerManagament.addUpdateActionStatus(actionStatusMessage3, savedAction); + controllerManagament.addUpdateActionStatus(actionStatusMessage3, savedAction); targetManagement.findTargetByControllerID("Rabbit").getTargetInfo().getUpdateStatus(); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java index dd674d3a3..83db4ed96 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java @@ -18,6 +18,7 @@ import java.util.LinkedList; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.Constants; @@ -386,7 +387,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { .createTargets(TestDataUtil.buildTargetFixtures(10, myCtrlIDPref, "first description")); final String myDeployedCtrlIDPref = "myDeployedCtrlID"; - final List savedDeployedTargets = targetManagement + List savedDeployedTargets = targetManagement .createTargets(TestDataUtil.buildTargetFixtures(20, myDeployedCtrlIDPref, "first description")); final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, @@ -399,6 +400,10 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { final Iterable allFoundTargets = targetManagement.findTargetsAll(pageReq).getContent(); + // get final updated version of targets + savedDeployedTargets = targetManagement.findTargetByControllerID( + savedDeployedTargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())); + assertThat(allFoundTargets).as("founded targets are wrong").containsAll(savedDeployedTargets) .containsAll(savedNakedTargets); assertThat(savedDeployedTargets).as("saved target are wrong") @@ -602,8 +607,12 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { .assignDistributionSet(dsA, deployResWithDsB.getDeployedTargets()).getAssignedTargets(); actionRepository.findByDistributionSet(pageRequest, dsA).getContent().get(1); - assertThat(deployed2DS).as("deployed ds is wrong").containsAll(deployResWithDsB.getDeployedTargets()); - assertThat(deployed2DS).as("deployed ds is wrong").hasSameSizeAs(deployResWithDsB.getDeployedTargets()); + // get final updated version of targets + final List deployResWithDsBTargets = targetManagement.findTargetByControllerID(deployResWithDsB + .getDeployedTargets().stream().map(target -> target.getControllerId()).collect(Collectors.toList())); + + assertThat(deployed2DS).as("deployed ds is wrong").containsAll(deployResWithDsBTargets); + assertThat(deployed2DS).as("deployed ds is wrong").hasSameSizeAs(deployResWithDsBTargets); for (final Target t_ : deployed2DS) { final Target t = targetManagement.findTargetByControllerID(t_.getControllerId()); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementForDSTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java similarity index 91% rename from hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementForDSTest.java rename to hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java index 30f4a8cb0..90cecfc14 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementForDSTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java @@ -33,6 +33,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; +import org.fest.assertions.core.Condition; import org.junit.Test; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -44,15 +45,12 @@ import ru.yandex.qatools.allure.annotations.Features; import ru.yandex.qatools.allure.annotations.Stories; /** - * {@link SoftwareManagement} test focused on {@link DistributionSet} and - * {@link DistributionSetType} related stuff. - * - * + * {@link DistributionSetManagement} tests. * */ @Features("Component Tests - Repository") -@Stories("Software Management") -public class SoftwareManagementForDSTest extends AbstractIntegrationTest { +@Stories("DistributionSet Management") +public class DistributionSetManagementTest extends AbstractIntegrationTest { @Test @Description("Tests the successfull module update of unused distribution set type which is in fact allowed.") @@ -102,7 +100,7 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest { .isEqualTo("test123"); } - @Test(expected = EntityReadOnlyException.class) + @Test @Description("Tests the unsuccessfull update of used distribution set type (module addition).") public void addModuleToAssignedDistributionSetTypeFails() { final DistributionSetType nonUpdatableType = distributionSetManagement @@ -113,10 +111,17 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest { .createDistributionSet(new DistributionSet("newtypesoft", "1", "", nonUpdatableType, null)); nonUpdatableType.addMandatoryModuleType(osType); - distributionSetManagement.updateDistributionSetType(nonUpdatableType); + + try { + distributionSetManagement.updateDistributionSetType(nonUpdatableType); + fail("Should not have worked as DS is in use."); + } catch (final EntityReadOnlyException e) { + + } + } - @Test(expected = EntityReadOnlyException.class) + @Test @Description("Tests the unsuccessfull update of used distribution set type (module removal).") public void removeModuleToAssignedDistributionSetTypeFails() { DistributionSetType nonUpdatableType = distributionSetManagement @@ -130,7 +135,12 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest { .createDistributionSet(new DistributionSet("newtypesoft", "1", "", nonUpdatableType, null)); nonUpdatableType.removeModuleType(osType.getId()); - nonUpdatableType = distributionSetManagement.updateDistributionSetType(nonUpdatableType); + try { + distributionSetManagement.updateDistributionSetType(nonUpdatableType); + fail("Should not have worked as DS is in use."); + } catch (final EntityReadOnlyException e) { + + } } @Test @@ -152,22 +162,68 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest { .createDistributionSetType(new DistributionSetType("softdeleted", "to be deletd", "")); assertThat(distributionSetTypeRepository.findAll()).contains(softDelete); - final DistributionSet dsNewType = distributionSetManagement - .createDistributionSet(new DistributionSet("newtypesoft", "1", "", softDelete, null)); + distributionSetManagement.createDistributionSet(new DistributionSet("newtypesoft", "1", "", softDelete, null)); distributionSetManagement.deleteDistributionSetType(softDelete); assertThat(distributionSetManagement.findDistributionSetTypeByKey("softdeleted").isDeleted()).isEqualTo(true); } - // TODO: kzimmerm: test N+1 - - @Test(expected = EntityAlreadyExistsException.class) + @Test @Description("Ensures that it is not possible to create a DS that already exists (unique constraint is on name,version for DS).") public void createDuplicateDistributionSetsFailsWithException() { TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement); - TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement); + try { + TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement); + fail("Should not have worked as DS with same UK already exists."); + } catch (final EntityAlreadyExistsException e) { + } + } + + @Test + @Description("Verfies that a DS is of default type if not specified explicitly at creation time.") + public void createDistributionSetWithImplicitType() { + final DistributionSet set = distributionSetManagement + .createDistributionSet(new DistributionSet("newtypesoft", "1", "", null, null)); + + assertThat(set.getType()).as("Type should be equal to default type of tenant") + .isEqualTo(systemManagement.getTenantMetadata().getDefaultDsType()); + + } + + @Test + @Description("Verfies that multiple DS are of default type if not specified explicitly at creation time.") + public void createMultipleDistributionSetsWithImplicitType() { + + List sets = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + sets.add(new DistributionSet("another DS" + i, "X" + i, "", null, null)); + } + + sets = distributionSetManagement.createDistributionSets(sets); + + assertThat(sets).as("Type should be equal to default type of tenant").are(new Condition() { + @Override + public boolean matches(final DistributionSet value) { + return value.getType().equals(systemManagement.getTenantMetadata().getDefaultDsType()); + } + }); + + } + + @Test + @Description("Verfies that a DS entity cannot be used for creation.") + public void createDistributionSetFailsOnExistingEntity() { + final DistributionSet set = distributionSetManagement + .createDistributionSet(new DistributionSet("newtypesoft", "1", "", null, null)); + + try { + distributionSetManagement.createDistributionSet(set); + fail("Should not have worked to create based on a persisted entity."); + } catch (final EntityAlreadyExistsException e) { + + } } @Test @@ -244,17 +300,22 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest { } } - @Test(expected = DistributionSetTypeUndefinedException.class) + @Test @Description("Ensures that it is not possible to add a software module to a set that has no type defined.") public void updateDistributionSetModuleWithUndefinedTypeFails() { final DistributionSet testSet = new DistributionSet(); final SoftwareModule module = new SoftwareModule(appType, "agent-hub2", "1.0.5", null, ""); // update data - testSet.addModule(module); + try { + testSet.addModule(module); + fail("Should not have worked as DS type is undefined."); + } catch (final DistributionSetTypeUndefinedException e) { + + } } - @Test(expected = UnsupportedSoftwareModuleForThisDistributionSetException.class) + @Test @Description("Ensures that it is not possible to add a software module that is not defined of the DS's type.") public void updateDistributionSetUnsupportedModuleFails() { final DistributionSet set = new DistributionSet("agent-hub2", "1.0.5", "desc", @@ -262,7 +323,12 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest { final SoftwareModule module = new SoftwareModule(appType, "agent-hub2", "1.0.5", null, ""); // update data - set.addModule(module); + try { + set.addModule(module); + fail("Should not have worked as module type is not in DS type."); + } catch (final UnsupportedSoftwareModuleForThisDistributionSetException e) { + + } } @Test @@ -561,7 +627,7 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest { .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0); // combine deleted and complete and type - expected = new ArrayList(); + expected = new ArrayList<>(); expected.addAll(ds100Group1); expected.addAll(ds100Group2); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.FALSE) @@ -570,7 +636,7 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest { .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(200) .containsOnly(expected.toArray(new DistributionSet[0])); - expected = new ArrayList(); + expected = new ArrayList<>(); expected.add(dsDeleted); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE) .setType(standardDsType).setIsDeleted(Boolean.TRUE); @@ -583,7 +649,7 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest { assertThat(distributionSetManagement .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0); - expected = new ArrayList(); + expected = new ArrayList<>(); expected.add(dsNewType); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE).setType(newType); assertThat(distributionSetManagement @@ -591,7 +657,7 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest { .containsOnly(expected.toArray(new DistributionSet[0])); // combine deleted and complete and type and text - expected = new ArrayList(); + expected = new ArrayList<>(); expected.addAll(ds100Group2); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE) .setType(standardDsType).setSearchText("%test2"); @@ -615,7 +681,7 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest { .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0); // combine deleted and complete and type and text and tag - expected = new ArrayList(); + expected = new ArrayList<>(); expected.addAll(ds100Group2); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true).setType(standardDsType) .setSearchText("%test2").setTagNames(Lists.newArrayList(dsTagA.getName())); @@ -637,7 +703,7 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest { private List sendUpdateActionStatusToTargets(final DistributionSet dsA, final Iterable targs, final Status status, final String... msgs) { - final List result = new ArrayList(); + final List result = new ArrayList<>(); for (final Target t : targs) { final List findByTarget = actionRepository.findByTarget(t); for (final Action action : findByTarget) { @@ -730,7 +796,7 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest { dsAssigned.getVersion()); final Target target = new Target("4712"); final Target savedTarget = targetManagement.createTarget(target); - final List toAssign = new ArrayList(); + final List toAssign = new ArrayList<>(); toAssign.add(savedTarget); deploymentManagement.assignDistributionSet(dsAssigned, toAssign); @@ -744,38 +810,6 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest { .getTotalElements()).isEqualTo(2); } - /** - * helper method which re-orders a list as expected. Re-orders the given - * distribution set in the order as given and returns a new list with the - * new order. - * - * @param dsThree - * @param buildDistributionSets - * @return - */ - private List reOrderDSList(final Iterable buildDistributionSets, - final DistributionSet... ds) { - final List reOrderedList = new ArrayList<>(); - - final Iterator iterator = buildDistributionSets.iterator(); - while (iterator.hasNext()) { - final DistributionSet next = iterator.next(); - int reorder = -1; - for (int index = 0; index < ds.length; index++) { - if (next.equals(ds[index])) { - reorder = index; - } - } - if (reorder >= 0) { - reOrderedList.add(reorder, next); - } else { - reOrderedList.add(next); - } - } - - return reOrderedList; - } - private Target sendUpdateActionStatusToTarget(final Status status, final Action updActA, final Target t, final String... msgs) { updActA.setStatus(status); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java index 49776e392..849cf8e30 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java @@ -10,11 +10,11 @@ package org.eclipse.hawkbit.repository; import static org.fest.assertions.api.Assertions.assertThat; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -24,14 +24,18 @@ import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB; import org.eclipse.hawkbit.RandomGeneratedInputStream; import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.WithUser; +import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Artifact; +import org.eclipse.hawkbit.repository.model.CustomSoftwareModule; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSetTag; +import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.hawkbit.repository.model.SwMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.junit.Test; @@ -51,6 +55,165 @@ import ru.yandex.qatools.allure.annotations.Stories; @Stories("Software Management") public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { + @Test + @Description("Try to update non updatable fields results in repository doing nothing.") + public void updateTypeNonUpdateableFieldsFails() { + final SoftwareModuleType created = softwareManagement + .createSoftwareModuleType(new SoftwareModuleType("test-key", "test-name", "test-desc", 1)); + + created.setName("a new name"); + final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(created); + + assertThat(updated.getOptLockRevision()) + .as("Expected version number of updated entitity to be equal to created version") + .isEqualTo(created.getOptLockRevision()); + } + + @Test + @Description("Calling update without changing fields results in no recorded change in the repository including unchanged audit fields.") + public void updateNothingResultsInUnchangedRepositoryForType() { + final SoftwareModuleType created = softwareManagement + .createSoftwareModuleType(new SoftwareModuleType("test-key", "test-name", "test-desc", 1)); + + final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(created); + + assertThat(updated.getOptLockRevision()) + .as("Expected version number of updated entitity to be equal to created version") + .isEqualTo(created.getOptLockRevision()); + } + + @Test + @Description("Calling update for changed fields results in change in the repository.") + public void updateSoftareModuleTypeFieldsToNewValue() { + final SoftwareModuleType created = softwareManagement + .createSoftwareModuleType(new SoftwareModuleType("test-key", "test-name", "test-desc", 1)); + + created.setDescription("changed"); + created.setColour("changed"); + + final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(created); + + assertThat(updated.getOptLockRevision()).as("Expected version number of updated entitity is") + .isEqualTo(created.getOptLockRevision() + 1); + assertThat(updated.getDescription()).as("Updated description is").isEqualTo("changed"); + assertThat(updated.getColour()).as("Updated vendor is").isEqualTo("changed"); + } + + @Test + @Description("Try to update non updatable fields results in repository doing nothing.") + public void updateNonUpdateableFieldsFails() { + final SoftwareModule ah = softwareManagement + .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + + ah.setName("a new name"); + final SoftwareModule updated = softwareManagement.updateSoftwareModule(ah); + + assertThat(updated.getOptLockRevision()) + .as("Expected version number of updated entitity to be equal to created version") + .isEqualTo(ah.getOptLockRevision()); + } + + @Test + @Description("Calling update without changing fields results in no recorded change in the repository including unchanged audit fields.") + public void updateNothingResultsInUnchangedRepository() { + final SoftwareModule ah = softwareManagement + .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + + final SoftwareModule updated = softwareManagement.updateSoftwareModule(ah); + + assertThat(updated.getOptLockRevision()) + .as("Expected version number of updated entitity to be equal to created version") + .isEqualTo(ah.getOptLockRevision()); + } + + @Test + @Description("Calling update for changed fields results in change in the repository.") + public void updateSoftareModuleFieldsToNewValue() { + final SoftwareModule ah = softwareManagement + .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor")); + + ah.setDescription("changed"); + ah.setVendor("changed"); + final SoftwareModule updated = softwareManagement.updateSoftwareModule(ah); + + assertThat(updated.getOptLockRevision()).as("Expected version number of updated entitity is") + .isEqualTo(ah.getOptLockRevision() + 1); + assertThat(updated.getDescription()).as("Updated description is").isEqualTo("changed"); + assertThat(updated.getVendor()).as("Updated vendor is").isEqualTo("changed"); + } + + @Test + @Description("Create Software Module call fails when called for existing entity.") + public void createModuleCallFailsForExistingModule() { + final SoftwareModule ah = softwareManagement + .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor")); + try { + softwareManagement.createSoftwareModule(ah); + fail("Should not have worked as module already exists."); + } catch (final EntityAlreadyExistsException e) { + + } + } + + @Test + @Description("Create Software Modules call fails when called for existing entities.") + public void createModulesCallFailsForExistingModule() { + final List modules = softwareManagement.createSoftwareModule( + Lists.newArrayList(new SoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor"), + new SoftwareModule(appType, "agent-hub", "1.0.2", "test desc", "test vendor"))); + try { + softwareManagement.createSoftwareModule(modules); + fail("Should not have worked as module already exists."); + } catch (final EntityAlreadyExistsException e) { + + } + } + + @Test + @Description("Create Software Module Type call fails when called for existing entity.") + public void createModuleTypeCallFailsForExistingType() { + final SoftwareModuleType created = softwareManagement + .createSoftwareModuleType(new SoftwareModuleType("test-key", "test-name", "test-desc", 1)); + + try { + softwareManagement.createSoftwareModuleType(created); + fail("Should not have worked as module already exists."); + } catch (final EntityAlreadyExistsException e) { + + } + } + + @Test + @Description("Create Software Module Types call fails when called for existing entities.") + public void createModuleTypesCallFailsForExistingTypes() { + final List created = softwareManagement.createSoftwareModuleType( + Lists.newArrayList(new SoftwareModuleType("test-key-bumlux", "test-name", "test-desc", 1), + new SoftwareModuleType("test-key-bumlux2", "test-name2", "test-desc", 1))); + + try { + softwareManagement.createSoftwareModuleType(created); + fail("Should not have worked as module already exists."); + } catch (final EntityAlreadyExistsException e) { + + } + } + + @Test + @Description("Calling update for changing fields to null results in change in the repository.") + public void eraseSoftareModuleFields() { + final SoftwareModule ah = softwareManagement + .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor")); + + ah.setDescription(null); + ah.setVendor(null); + final SoftwareModule updated = softwareManagement.updateSoftwareModule(ah); + + assertThat(updated.getOptLockRevision()).as("Expected version number of updated entitity is") + .isEqualTo(ah.getOptLockRevision() + 1); + assertThat(updated.getDescription()).as("Updated description is").isNull(); + assertThat(updated.getVendor()).as("Updated vendor is").isNull(); + } + @Test @Description("searched for software modules based on the various filter options, e.g. name,desc,type, version.") public void findSoftwareModuleByFilters() { @@ -105,7 +268,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Test @Description("Searches for software modules based on a list of IDs.") - public void findSoftwareModulesByIdAndType() { + public void findSoftwareModulesById() { final List modules = new ArrayList(); @@ -118,6 +281,54 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { assertThat(softwareManagement.findSoftwareModulesById(modules)).hasSize(2); } + @Test + @Description("Searches for software modules by type.") + public void findSoftwareModulesByType() { + // found in test + final SoftwareModule one = softwareManagement + .createSoftwareModule(new SoftwareModule(osType, "one", "one", null, "")); + final SoftwareModule two = softwareManagement + .createSoftwareModule(new SoftwareModule(osType, "two", "two", null, "")); + // ignored + softwareManagement.deleteSoftwareModule( + softwareManagement.createSoftwareModule(new SoftwareModule(osType, "deleted", "deleted", null, ""))); + softwareManagement.createSoftwareModule(new SoftwareModule(appType, "three", "3.0.2", null, "")); + + assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent()) + .as("Expected to find the following number of modules:").hasSize(2).as("with the following elements") + .contains(two, one); + } + + @Test + @Description("Counts all software modules in the repsitory that are not marked as deleted.") + public void countSoftwareModulesAll() { + // found in test + softwareManagement.createSoftwareModule(new SoftwareModule(osType, "one", "one", null, "")); + softwareManagement.createSoftwareModule(new SoftwareModule(appType, "two", "two", null, "")); + // ignored + softwareManagement.deleteSoftwareModule( + softwareManagement.createSoftwareModule(new SoftwareModule(osType, "deleted", "deleted", null, ""))); + + assertThat(softwareManagement.countSoftwareModulesAll()).as("Expected to find the following number of modules:") + .isEqualTo(2); + } + + @Test + @Description("Counts for software modules by type.") + public void countSoftwareModulesByType() { + // found in test + softwareManagement.createSoftwareModule(new SoftwareModule(osType, "one", "one", null, "")); + softwareManagement.createSoftwareModule(new SoftwareModule(osType, "two", "two", null, "")); + + // ignored + softwareManagement.deleteSoftwareModule( + softwareManagement.createSoftwareModule(new SoftwareModule(osType, "deleted", "deleted", null, ""))); + softwareManagement.createSoftwareModule(new SoftwareModule(appType, "three", "3.0.2", null, "")); + + assertThat(softwareManagement.countSoftwareModulesByType(osType)) + .as("Expected to find the following number of modules:").isEqualTo(2); + } + @Test @Description("Tests the successfull deletion of software module types. Both unused (hard delete) and used ones (soft delete).") public void deleteAssignedAndUnassignedSoftwareModuleTypes() { @@ -419,32 +630,194 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { } } - /** - * - * @param findAll - * @return - */ - @SuppressWarnings("rawtypes") - private Collection iterable2Collection(final Iterable iterable) { - final Collection col = new ArrayList(); - for (final Object o : iterable) { - col.add(o); - } - return col; + @Test + @Description("Test verfies that results are returned based on given filter parameters and in the specified order.") + public void findSoftwareModuleOrderByDistributionModuleNameAscModuleVersionAsc() { + // test meta data + final SoftwareModuleType testType = softwareManagement + .createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100)); + final DistributionSetType testDsType = distributionSetManagement + .createDistributionSetType(new DistributionSetType("key", "name", "desc").addMandatoryModuleType(osType) + .addOptionalModuleType(testType)); + + // found in test + final SoftwareModule unassigned = softwareManagement + .createSoftwareModule(new SoftwareModule(testType, "asis", "found", null, "")); + final SoftwareModule one = softwareManagement + .createSoftwareModule(new SoftwareModule(testType, "found", "b", null, "")); + final SoftwareModule two = softwareManagement + .createSoftwareModule(new SoftwareModule(testType, "found", "c", null, "")); + final SoftwareModule differentName = softwareManagement + .createSoftwareModule(new SoftwareModule(testType, "differentname", "d", null, "")); + + // ignored + final SoftwareModule deleted = softwareManagement + .createSoftwareModule(new SoftwareModule(testType, "deleted", "deleted", null, "")); + final SoftwareModule four = softwareManagement + .createSoftwareModule(new SoftwareModule(osType, "sdfjhsdj", "e", null, "")); + + final DistributionSet set = distributionSetManagement.createDistributionSet(new DistributionSet("set", "1", + "desc", testDsType, Lists.newArrayList(one, two, deleted, four, differentName))); + softwareManagement.deleteSoftwareModule(deleted); + + // with filter on name, version and module type + assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq, + set.getId(), "found", testType).getContent()) + .as("Found modules with given name, given module type and the assigned ones first") + .containsExactly(new CustomSoftwareModule(one, true), new CustomSoftwareModule(two, true), + new CustomSoftwareModule(unassigned, false)); + + // with filter on module type only + assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq, + set.getId(), null, testType).getContent()) + .as("Found modules with given module type and the assigned ones first").containsExactly( + new CustomSoftwareModule(differentName, true), new CustomSoftwareModule(one, true), + new CustomSoftwareModule(two, true), new CustomSoftwareModule(unassigned, false)); + + // without any filter + assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq, + set.getId(), null, null).getContent()).as("Found modules with the assigned ones first").containsExactly( + new CustomSoftwareModule(differentName, true), new CustomSoftwareModule(one, true), + new CustomSoftwareModule(two, true), new CustomSoftwareModule(four, true), + new CustomSoftwareModule(unassigned, false)); } - /** - * - */ - private void printDSTags() { - System.out.println("=============================================================================="); - for (final DistributionSet d : distributionSetRepository.findAll()) { - System.out.printf("%s\t[", d.getName()); - for (final DistributionSetTag t : d.getTags()) { - System.out.printf("%s ", t.getName()); - } - System.out.println("]"); + @Test + @Description("Checks that number of modules is returned as expected based on given filters.") + public void countSoftwareModuleByFilters() { + + // test meta data + final SoftwareModuleType testType = softwareManagement + .createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100)); + final DistributionSetType testDsType = distributionSetManagement + .createDistributionSetType(new DistributionSetType("key", "name", "desc").addMandatoryModuleType(osType) + .addOptionalModuleType(testType)); + + // test modules + softwareManagement.createSoftwareModule(new SoftwareModule(testType, "asis", "found", null, "")); + final SoftwareModule one = softwareManagement + .createSoftwareModule(new SoftwareModule(testType, "found", "b", null, "")); + final SoftwareModule two = softwareManagement + .createSoftwareModule(new SoftwareModule(testType, "found", "c", null, "")); + final SoftwareModule differentName = softwareManagement + .createSoftwareModule(new SoftwareModule(testType, "differentname", "d", null, "")); + final SoftwareModule four = softwareManagement + .createSoftwareModule(new SoftwareModule(osType, "found", "3.0.2", null, "")); + + // one soft deleted + final SoftwareModule deleted = softwareManagement + .createSoftwareModule(new SoftwareModule(testType, "deleted", "deleted", null, "")); + distributionSetManagement.createDistributionSet(new DistributionSet("set", "1", "desc", testDsType, + Lists.newArrayList(one, two, deleted, four, differentName))); + softwareManagement.deleteSoftwareModule(deleted); + + // test + assertThat(softwareManagement.countSoftwareModuleByFilters("found", testType)) + .as("Number of modules with given name or version and type").isEqualTo(3); + assertThat(softwareManagement.countSoftwareModuleByFilters(null, testType)) + .as("Number of modules with given type").isEqualTo(4); + assertThat(softwareManagement.countSoftwareModuleByFilters(null, null)).as("Number of modules overall") + .isEqualTo(5); + } + + @Test + @Description("Verfies that all undeleted software modules are found in the repository.") + public void countSoftwareModuleTypesAll() { + final SoftwareModuleType testType = softwareManagement + .createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100)); + final DistributionSetType testDsType = distributionSetManagement + .createDistributionSetType(new DistributionSetType("key", "name", "desc").addMandatoryModuleType(osType) + .addOptionalModuleType(testType)); + final SoftwareModule four = softwareManagement + .createSoftwareModule(new SoftwareModule(osType, "found", "3.0.2", null, "")); + + // one soft deleted + final SoftwareModule deleted = softwareManagement + .createSoftwareModule(new SoftwareModule(testType, "deleted", "deleted", null, "")); + distributionSetManagement.createDistributionSet( + new DistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(deleted, four))); + softwareManagement.deleteSoftwareModule(deleted); + + assertThat(softwareManagement.countSoftwareModulesAll()).as("Number of undeleted modules").isEqualTo(1); + assertThat(softwareModuleRepository.count()).as("Number of all modules").isEqualTo(2); + } + + @Test + @Description("Checks that software module typeis found based on given name.") + public void findSoftwareModuleTypeByName() { + final SoftwareModuleType found = softwareManagement + .createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100)); + softwareManagement.createSoftwareModuleType(new SoftwareModuleType("thetype2", "anothername", "desc", 100)); + + assertThat(softwareManagement.findSoftwareModuleTypeByName("thename")).as("Type with given name") + .isEqualTo(found); + } + + @Test + @Description("Verfies that it is not possible to create a type that alrady exists.") + public void createSoftwareModuleTypeFailsWithExistingEntity() { + final SoftwareModuleType created = softwareManagement + .createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100)); + try { + softwareManagement.createSoftwareModuleType(created); + fail("should not have worked as module type already exists"); + } catch (final EntityAlreadyExistsException e) { + } + + } + + @Test + @Description("Verfies that it is not possible to create a list of types where one already exists.") + public void createSoftwareModuleTypesFailsWithExistingEntity() { + final SoftwareModuleType created = softwareManagement + .createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100)); + try { + softwareManagement.createSoftwareModuleType( + Lists.newArrayList(created, new SoftwareModuleType("anothertype", "anothername", "desc", 100))); + fail("should not have worked as module type already exists"); + } catch (final EntityAlreadyExistsException e) { + + } + } + + @Test + @Description("Verfies that multiple types are created as requested.") + public void createMultipleoftwareModuleTypes() { + final List created = softwareManagement + .createSoftwareModuleType(Lists.newArrayList(new SoftwareModuleType("thetype", "thename", "desc", 100), + new SoftwareModuleType("thetype2", "thename2", "desc2", 100))); + + assertThat(created.size()).as("Number of created types").isEqualTo(2); + assertThat(softwareManagement.countSoftwareModuleTypesAll()).as("Number of types in repository").isEqualTo(5); + } + + @Test + @Description("Verfies that sofwtare modules are resturned that are assigned to given DS.") + public void findSoftwareModuleByAssignedTo() { + // test meta data + final SoftwareModuleType testType = softwareManagement + .createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100)); + final DistributionSetType testDsType = distributionSetManagement + .createDistributionSetType(new DistributionSetType("key", "name", "desc").addMandatoryModuleType(osType) + .addOptionalModuleType(testType)); + + // test modules + softwareManagement.createSoftwareModule(new SoftwareModule(testType, "asis", "found", null, "")); + final SoftwareModule one = softwareManagement + .createSoftwareModule(new SoftwareModule(testType, "found", "b", null, "")); + final SoftwareModule two = softwareManagement + .createSoftwareModule(new SoftwareModule(testType, "found", "c", null, "")); + + // one soft deleted + final SoftwareModule deleted = softwareManagement + .createSoftwareModule(new SoftwareModule(testType, "deleted", "deleted", null, "")); + final DistributionSet set = distributionSetManagement.createDistributionSet( + new DistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(one, deleted))); + softwareManagement.deleteSoftwareModule(deleted); + + assertThat(softwareManagement.findSoftwareModuleByAssignedTo(pageReq, set).getContent()) + .as("Found this number of modules").hasSize(2); } @Test @@ -479,6 +852,27 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { assertThat(softwareModuleMetadata.get(0).getSoftwareModule().getId()).isEqualTo(ah.getId()); } + @Test + @Description("Checks that metadata for a software module cannot be created for an existing key.") + public void createSoftwareModuleMetadataFailsIfKeyExists() { + + final String knownKey1 = "myKnownKey1"; + final String knownValue1 = "myKnownValue1"; + final String knownValue2 = "myKnownValue2"; + + final SoftwareModule ah = softwareManagement + .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + + softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey1, ah, knownValue1)); + + try { + softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey1, ah, knownValue2)); + fail("should not have worked as module metadata already exists"); + } catch (final EntityAlreadyExistsException e) { + + } + } + @Test @WithUser(allSpPermissions = true) @Description("Checks that metadata for a software module can be updated.") @@ -525,6 +919,47 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { assertThat(updated.getSoftwareModule().getId()).isEqualTo(ah.getId()); } + @Test + @Description("Verfies that existing metadata can be deleted.") + public void deleteSoftwareModuleMetadata() { + final String knownKey1 = "myKnownKey1"; + final String knownValue1 = "myKnownValue1"; + + SoftwareModule ah = softwareManagement + .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + + ah = softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey1, ah, knownValue1)) + .getSoftwareModule(); + + assertThat(softwareManagement.findSoftwareModuleById(ah.getId()).getMetadata()) + .as("Contains the created metadata element") + .containsExactly(new SoftwareModuleMetadata(knownKey1, ah, knownValue1)); + + softwareManagement.deleteSoftwareModuleMetadata(new SwMetadataCompositeKey(ah, knownKey1)); + assertThat(softwareManagement.findSoftwareModuleById(ah.getId()).getMetadata()).as("Metadata elemenets are") + .isEmpty(); + } + + @Test + @Description("Verfies that non existing metadata find results in exception.") + public void findSoftwareModuleMetadataFailsIfEntryDoesNotExist() { + final String knownKey1 = "myKnownKey1"; + final String knownValue1 = "myKnownValue1"; + + SoftwareModule ah = softwareManagement + .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + + ah = softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey1, ah, knownValue1)) + .getSoftwareModule(); + + try { + softwareManagement.findSoftwareModuleMetadata(new SwMetadataCompositeKey(ah, "doesnotexist")); + fail("should not have worked as module metadata with that key does not exist"); + } catch (final EntityNotFoundException e) { + + } + } + @Test @Description("Queries and loads the metadata related to a given software module.") public void findAllSoftwareModuleMetadataBySwId() { diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java index eb263b242..73244871f 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java @@ -12,7 +12,10 @@ import static org.fest.assertions.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; @@ -20,9 +23,11 @@ import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilte import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; +import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetTag; +import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.junit.Before; import org.junit.Test; import org.slf4j.LoggerFactory; @@ -158,6 +163,98 @@ public class TagManagementTest extends AbstractIntegrationTest { return new DistributionSetFilterBuilder(); } + @Test + @Description("Verifies the toogle mechanism by means on assigning tag if at least on DS in the list does not have" + + "the tag yet. Unassign if all of them have the tag already.") + public void assignAndUnassignDistributionSetTags() { + final List groupA = TestDataUtil.generateDistributionSets(20, softwareManagement, + distributionSetManagement); + final List groupB = TestDataUtil.generateDistributionSets("unassigned", 20, softwareManagement, + distributionSetManagement); + + final DistributionSetTag tag = tagManagement + .createDistributionSetTag(new DistributionSetTag("tag1", "tagdesc1", "")); + + // toggle A only -> A is now assigned + DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(groupA, tag); + assertThat(result.getAlreadyAssigned()).isEqualTo(0); + assertThat(result.getAssigned()).isEqualTo(20); + assertThat(result.getAssignedDs()).containsAll(distributionSetManagement.findDistributionSetListWithDetails( + groupA.stream().map(set -> set.getId()).collect(Collectors.toList()))); + assertThat(result.getUnassigned()).isEqualTo(0); + assertThat(result.getUnassignedDs()).isEmpty(); + assertThat(result.getDistributionSetTag()).isEqualTo(tag); + + // toggle A+B -> A is still assigned and B is assigned as well + result = distributionSetManagement.toggleTagAssignment(concat(groupA, groupB), tag); + assertThat(result.getAlreadyAssigned()).isEqualTo(20); + assertThat(result.getAssigned()).isEqualTo(20); + assertThat(result.getAssignedDs()).containsAll(distributionSetManagement.findDistributionSetListWithDetails( + groupB.stream().map(set -> set.getId()).collect(Collectors.toList()))); + assertThat(result.getUnassigned()).isEqualTo(0); + assertThat(result.getUnassignedDs()).isEmpty(); + assertThat(result.getDistributionSetTag()).isEqualTo(tag); + + // toggle A+B -> both unassigned + result = distributionSetManagement.toggleTagAssignment(concat(groupA, groupB), tag); + assertThat(result.getAlreadyAssigned()).isEqualTo(0); + assertThat(result.getAssigned()).isEqualTo(0); + assertThat(result.getAssignedDs()).isEmpty(); + assertThat(result.getUnassigned()).isEqualTo(40); + assertThat(result.getUnassignedDs()).containsAll(distributionSetManagement.findDistributionSetListWithDetails( + concat(groupB, groupA).stream().map(set -> set.getId()).collect(Collectors.toList()))); + assertThat(result.getDistributionSetTag()).isEqualTo(tag); + + } + + @Test + @Description("Verifies the toogle mechanism by means on assigning tag if at least on target in the list does not have" + + "the tag yet. Unassign if all of them have the tag already.") + public void assignAndUnassignTargetTags() { + final List groupA = targetManagement.createTargets(TestDataUtil.generateTargets(20, "")); + final List groupB = targetManagement.createTargets(TestDataUtil.generateTargets(20, "groupb")); + + final TargetTag tag = tagManagement.createTargetTag(new TargetTag("tag1", "tagdesc1", "")); + + // toggle A only -> A is now assigned + TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(groupA, tag); + assertThat(result.getAlreadyAssigned()).isEqualTo(0); + assertThat(result.getAssigned()).isEqualTo(20); + assertThat(result.getAssignedTargets()).containsAll(targetManagement.findTargetsByControllerIDsWithTags( + groupA.stream().map(target -> target.getControllerId()).collect(Collectors.toList()))); + assertThat(result.getUnassigned()).isEqualTo(0); + assertThat(result.getUnassignedTargets()).isEmpty(); + assertThat(result.getTargetTag()).isEqualTo(tag); + + // toggle A+B -> A is still assigned and B is assigned as well + result = targetManagement.toggleTagAssignment(concat(groupA, groupB), tag); + assertThat(result.getAlreadyAssigned()).isEqualTo(20); + assertThat(result.getAssigned()).isEqualTo(20); + assertThat(result.getAssignedTargets()).containsAll(targetManagement.findTargetsByControllerIDsWithTags( + groupB.stream().map(target -> target.getControllerId()).collect(Collectors.toList()))); + assertThat(result.getUnassigned()).isEqualTo(0); + assertThat(result.getUnassignedTargets()).isEmpty(); + assertThat(result.getTargetTag()).isEqualTo(tag); + + // toggle A+B -> both unassigned + result = targetManagement.toggleTagAssignment(concat(groupA, groupB), tag); + assertThat(result.getAlreadyAssigned()).isEqualTo(0); + assertThat(result.getAssigned()).isEqualTo(0); + assertThat(result.getAssignedTargets()).isEmpty(); + assertThat(result.getUnassigned()).isEqualTo(40); + assertThat(result.getUnassignedTargets()).containsAll(targetManagement.findTargetsByControllerIDsWithTags( + concat(groupB, groupA).stream().map(target -> target.getControllerId()).collect(Collectors.toList()))); + assertThat(result.getTargetTag()).isEqualTo(tag); + + } + + @SafeVarargs + private final List concat(final List... targets) { + final List result = new ArrayList<>(); + Arrays.asList(targets).forEach(result::addAll); + return result; + } + @Test @Description("Ensures that all tags are retrieved through repository.") public void findAllTargetTags() { @@ -266,47 +363,58 @@ public class TagManagementTest extends AbstractIntegrationTest { } } + @Test @Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).") public void failedDuplicateTargetTagNameException() { tagManagement.createTargetTag(new TargetTag("A")); + try { tagManagement.createTargetTag(new TargetTag("A")); - fail("Expected EntityAlreadyExistsException"); + fail("should not have worked as tag already exists"); } catch (final EntityAlreadyExistsException e) { + } } + @Test @Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).") public void failedDuplicateTargetTagNameExceptionAfterUpdate() { tagManagement.createTargetTag(new TargetTag("A")); final TargetTag tag = tagManagement.createTargetTag(new TargetTag("B")); tag.setName("A"); + try { tagManagement.updateTargetTag(tag); - fail("Expected EntityAlreadyExistsException"); + fail("should not have worked as tag already exists"); } catch (final EntityAlreadyExistsException e) { + } } + @Test @Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).") public void failedDuplicateDsTagNameException() { tagManagement.createDistributionSetTag(new DistributionSetTag("A")); try { tagManagement.createDistributionSetTag(new DistributionSetTag("A")); - fail("Expected EntityAlreadyExistsException"); + fail("should not have worked as tag already exists"); } catch (final EntityAlreadyExistsException e) { + } } + @Test @Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).") public void failedDuplicateDsTagNameExceptionAfterUpdate() { tagManagement.createDistributionSetTag(new DistributionSetTag("A")); final DistributionSetTag tag = tagManagement.createDistributionSetTag(new DistributionSetTag("B")); tag.setName("A"); + try { tagManagement.updateDistributionSetTag(tag); - fail("Expected EntityAlreadyExistsException"); + fail("should not have worked as tag already exists"); } catch (final EntityAlreadyExistsException e) { + } } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java index 73528ca5b..99e08f331 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.repository; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; @@ -22,10 +23,7 @@ import ru.yandex.qatools.allure.annotations.Stories; /** * Test class for {@link TargetFilterQueryManagement}. * - * - * */ - @Features("Component Tests - Repository") @Stories("Target Filter Query Management") public class TargetFilterQueryManagenmentTest extends AbstractIntegrationTest { @@ -40,15 +38,20 @@ public class TargetFilterQueryManagenmentTest extends AbstractIntegrationTest { targetFilterQueryManagement.findTargetFilterQueryByName(filterName)); } - @Test(expected = EntityAlreadyExistsException.class) + @Test @Description("Checks if the EntityAlreadyExistsException is thrown if a targetfilterquery with the same name are created more than once.") public void createDuplicateTargetFilterQuery() { final String filterName = "new target filter duplicate"; targetFilterQueryManagement .createTargetFilterQuery(new TargetFilterQuery(filterName, "name==PendingTargets001")); - targetFilterQueryManagement - .createTargetFilterQuery(new TargetFilterQuery(filterName, "name==PendingTargets001")); + try { + targetFilterQueryManagement + .createTargetFilterQuery(new TargetFilterQuery(filterName, "name==PendingTargets001")); + fail("should not have worked as query already exists"); + } catch (final EntityAlreadyExistsException e) { + + } } @Test diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java index 34aa223c3..0c33a651f 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java @@ -11,28 +11,34 @@ package org.eclipse.hawkbit.repository; import static org.fest.assertions.api.Assertions.assertThat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; -import org.eclipse.hawkbit.repository.model.BaseEntity; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetFilterQuery; +import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; +import org.eclipse.hawkbit.repository.specifications.TargetSpecifications; import org.junit.Test; -import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Slice; +import com.google.common.collect.Lists; import com.google.common.primitives.Ints; import ru.yandex.qatools.allure.annotations.Description; import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Step; import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @@ -40,152 +46,634 @@ import ru.yandex.qatools.allure.annotations.Stories; public class TargetManagementSearchTest extends AbstractIntegrationTest { @Test - @Description("Tests different parameter combinations for target search operations. That includes both the test itself as a count operation with the same filters.") + @Description("Tests different parameter combinations for target search operations. " + + "That includes both the test itself, as a count operation with the same filters " + + "and query definitions by RSQL (named and un-named).") public void targetSearchWithVariousFilterCombinations() { - final TargetTag targTagA = tagManagement.createTargetTag(new TargetTag("TargTag-A")); - final TargetTag targTagB = tagManagement.createTargetTag(new TargetTag("TargTag-B")); - final TargetTag targTagC = tagManagement.createTargetTag(new TargetTag("TargTag-C")); - final TargetTag targTagD = tagManagement.createTargetTag(new TargetTag("TargTag-D")); - - // TODO kaizimmerm: test also installedDS (not only assignedDS) + final TargetTag targTagX = tagManagement.createTargetTag(new TargetTag("TargTag-X")); + final TargetTag targTagY = tagManagement.createTargetTag(new TargetTag("TargTag-Y")); + final TargetTag targTagZ = tagManagement.createTargetTag(new TargetTag("TargTag-Z")); + final TargetTag targTagW = tagManagement.createTargetTag(new TargetTag("TargTag-W")); final DistributionSet setA = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); + final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement, + distributionSetManagement); + final String targetDsAIdPref = "targ-A"; List targAs = targetManagement.createTargets( TestDataUtil.buildTargetFixtures(100, targetDsAIdPref, targetDsAIdPref.concat(" description"))); - targAs = targetManagement.toggleTagAssignment(targAs, targTagA).getAssignedTargets(); + targAs = targetManagement.toggleTagAssignment(targAs, targTagX).getAssignedTargets(); final String targetDsBIdPref = "targ-B"; List targBs = targetManagement.createTargets( TestDataUtil.buildTargetFixtures(100, targetDsBIdPref, targetDsBIdPref.concat(" description"))); - targBs = targetManagement.toggleTagAssignment(targBs, targTagB).getAssignedTargets(); - targBs = targetManagement.toggleTagAssignment(targBs, targTagD).getAssignedTargets(); + targBs = targetManagement.toggleTagAssignment(targBs, targTagY).getAssignedTargets(); + targBs = targetManagement.toggleTagAssignment(targBs, targTagW).getAssignedTargets(); final String targetDsCIdPref = "targ-C"; List targCs = targetManagement.createTargets( TestDataUtil.buildTargetFixtures(100, targetDsCIdPref, targetDsCIdPref.concat(" description"))); - targCs = targetManagement.toggleTagAssignment(targCs, targTagC).getAssignedTargets(); - targCs = targetManagement.toggleTagAssignment(targCs, targTagD).getAssignedTargets(); + targCs = targetManagement.toggleTagAssignment(targCs, targTagZ).getAssignedTargets(); + targCs = targetManagement.toggleTagAssignment(targCs, targTagW).getAssignedTargets(); final String targetDsDIdPref = "targ-D"; - final Iterable targDs = targetManagement.createTargets( + final List targDs = targetManagement.createTargets( TestDataUtil.buildTargetFixtures(100, targetDsDIdPref, targetDsDIdPref.concat(" description"))); - deploymentManagement.assignDistributionSet(setA.getId(), targCs.iterator().next().getControllerId()); - deploymentManagement.assignDistributionSet(setA.getId(), targAs.iterator().next().getControllerId()); - deploymentManagement.assignDistributionSet(setA.getId(), targBs.iterator().next().getControllerId()); + final String assignedC = targCs.iterator().next().getControllerId(); + deploymentManagement.assignDistributionSet(setA.getId(), assignedC); + final String assignedA = targAs.iterator().next().getControllerId(); + deploymentManagement.assignDistributionSet(setA.getId(), assignedA); + final String assignedB = targBs.iterator().next().getControllerId(); + deploymentManagement.assignDistributionSet(setA.getId(), assignedB); + final String installedC = targCs.iterator().next().getControllerId(); + final Long actionId = deploymentManagement.assignDistributionSet(installedSet.getId(), assignedC).getActions() + .get(0); - final List unknown = new ArrayList(); + // set one installed DS also + final Action action = deploymentManagement.findActionWithDetails(actionId); + action.setStatus(Status.FINISHED); + controllerManagament.addUpdateActionStatus( + new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"), action); + deploymentManagement.assignDistributionSet(setA.getId(), installedC); + + final List unknown = new ArrayList<>(); unknown.add(TargetUpdateStatus.UNKNOWN); - final List pending = new ArrayList(); + final List pending = new ArrayList<>(); pending.add(TargetUpdateStatus.PENDING); - final List both = new ArrayList(); + final List both = new ArrayList<>(); both.add(TargetUpdateStatus.UNKNOWN); both.add(TargetUpdateStatus.PENDING); - final PageRequest pageReq = new PageRequest(0, 500); + // get final updated version of targets + targAs = targetManagement.findTargetByControllerID( + targAs.stream().map(target -> target.getControllerId()).collect(Collectors.toList())); + targBs = targetManagement.findTargetByControllerID( + targBs.stream().map(target -> target.getControllerId()).collect(Collectors.toList())); + targCs = targetManagement.findTargetByControllerID( + targCs.stream().map(target -> target.getControllerId()).collect(Collectors.toList())); + // try to find several targets with different filter settings + verifyThatRepositoryContains400Targets(); + verifyThat200TargetsHaveTagD(targTagW, concat(targBs, targCs)); + verifyThat100TargetsContainsGivenTextAndHaveTagAssigned(targTagY, targTagW, targBs); + verifyThat1TargetHasTagHasDescOrNameAndDs(targTagW, setA, targetManagement.findTargetByControllerID(assignedC)); + verifyThat0TargetsWithTagAndDescOrNameHasDS(targTagW, setA); + verifyThat0TargetsWithNameOrdescAndDSHaveTag(targTagX, setA); + verifyThat3TargetsHaveDSAssigned(setA, + targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC))); + verifyThat1TargetWithDescOrNameHasDS(setA, targetManagement.findTargetByControllerID(assignedA)); + List expected = concat(targAs, targBs, targCs, targDs); + expected.removeAll( + targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC))); + verifyThat397TargetsAreInStatusUnknown(unknown, expected); + expected = concat(targBs, targCs); + expected.removeAll(targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC))); + verifyThat198TargetsAreInStatusUnknownAndHaveGivenTags(targTagY, targTagW, unknown, expected); + verfyThat0TargetsAreInStatusUnknownAndHaveDSAssigned(setA, unknown); + expected = concat(targAs); + expected.remove(targetManagement.findTargetByControllerID(assignedA)); + verifyThat99TargetsWithNameOrDescriptionAreInGivenStatus(unknown, expected); + expected = concat(targBs); + expected.remove(targetManagement.findTargetByControllerID(assignedB)); + verifyThat99TargetsWithGivenNameOrDescAndTagAreInStatusUnknown(targTagW, unknown, expected); + verifyThat3TargetsAreInStatusPending(pending, + targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC))); + verifyThat3TargetsWithGivenDSAreInPending(setA, pending, + targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC))); + verifyThat1TargetWithGivenNameOrDescAndDSIsInPending(setA, pending, + targetManagement.findTargetByControllerID(assignedA)); + verifyThat1TargetWithGivenNameOrDescAndTagAndDSIsInPending(targTagW, setA, pending, + targetManagement.findTargetByControllerID(assignedB)); + verifyThat2TargetsWithGivenTagAndDSIsInPending(targTagW, setA, pending, + targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC))); + verifyThat2TargetsWithGivenTagAreInPending(targTagW, pending, + targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC))); + verifyThat200targetsWithGivenTagAreInStatusPendingorUnknown(targTagW, both, concat(targBs, targCs)); + verfiyThat1TargetAIsInStatusPendingAndHasDSInstalled(installedSet, pending, + targetManagement.findTargetByControllerID(installedC)); + } - // TODO kaizimmerm: comment and check also the content itself, not only - // the numbers - // (containsOnly) - assertThat(targetManagement.countTargetsAll()).isEqualTo(400); + @Step + private void verfiyThat1TargetAIsInStatusPendingAndHasDSInstalled(final DistributionSet installedSet, + final List pending, final Target expected) { + final TargetIdName expectedIdName = convertToIdName(expected); + final String query = "updatestatus==pending and installedds.name==" + installedSet.getName(); - assertThat(targetManagement.findTargetByFilters(pageReq, null, null, null, Boolean.FALSE, targTagD.getName()) - .getNumberOfElements()).isEqualTo(200).isEqualTo(Ints.saturatedCast( - targetManagement.countTargetByFilters(null, null, null, Boolean.FALSE, targTagD.getName()))); + assertThat(targetManagement + .findTargetByFilters(pageReq, pending, null, installedSet.getId(), Boolean.FALSE, new String[0]) + .getContent()).as("has number of elements").hasSize(1) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, + installedSet.getId(), Boolean.FALSE, new String[0]))) + .as("and contains the following elements").containsExactly(expected) + .as("and filter query returns the same result") + .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); - Slice x = targetManagement.findTargetByFilters(pageReq, null, "%targ-B%", null, Boolean.FALSE, - targTagB.getName(), targTagD.getName()); - assertThat(x.getNumberOfElements()).isEqualTo(100).isEqualTo(Ints.saturatedCast(targetManagement - .countTargetByFilters(null, "%targ-B%", null, Boolean.FALSE, targTagB.getName(), targTagD.getName()))); - - x = targetManagement.findTargetByFilters(pageReq, null, "%targ-C%", setA.getId(), Boolean.FALSE, - targTagD.getName()); - assertThat(x.getNumberOfElements()).isEqualTo(1).isEqualTo(Ints.saturatedCast(targetManagement - .countTargetByFilters(null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagD.getName()))); - - x = targetManagement.findTargetByFilters(pageReq, null, "%targ-A%", setA.getId(), Boolean.FALSE, - targTagD.getName()); - assertThat(x.getNumberOfElements()).isEqualTo(0).isEqualTo(Ints.saturatedCast(targetManagement - .countTargetByFilters(null, "%targ-A%", setA.getId(), Boolean.FALSE, targTagD.getName()))); - - x = targetManagement.findTargetByFilters(pageReq, null, "%targ-C%", setA.getId(), Boolean.FALSE, - targTagA.getName()); - assertThat(x.getNumberOfElements()).isEqualTo(0).isEqualTo(Ints.saturatedCast(targetManagement - .countTargetByFilters(null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagA.getName()))); - - x = targetManagement.findTargetByFilters(pageReq, null, null, setA.getId(), Boolean.FALSE, null); - assertThat(x.getNumberOfElements()).isEqualTo(3).isEqualTo(Ints - .saturatedCast(targetManagement.countTargetByFilters(null, null, setA.getId(), Boolean.FALSE, null))); - - x = targetManagement.findTargetByFilters(pageReq, null, "%targ-A%", setA.getId(), Boolean.FALSE, null); - assertThat(x.getNumberOfElements()).isEqualTo(1).isEqualTo(Ints.saturatedCast( - targetManagement.countTargetByFilters(null, "%targ-A%", setA.getId(), Boolean.FALSE, null))); - - x = targetManagement.findTargetByFilters(pageReq, unknown, null, null, Boolean.FALSE, null); - assertThat(x.getNumberOfElements()).isEqualTo(397).isEqualTo( - Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, null, Boolean.FALSE, null))); - - x = targetManagement.findTargetByFilters(pageReq, unknown, null, null, Boolean.FALSE, targTagB.getName(), - targTagD.getName()); - assertThat(x.getNumberOfElements()).isEqualTo(198).isEqualTo(Ints.saturatedCast(targetManagement - .countTargetByFilters(unknown, null, null, Boolean.FALSE, targTagB.getName(), targTagD.getName()))); - - x = targetManagement.findTargetByFilters(pageReq, unknown, null, setA.getId(), Boolean.FALSE, null); - assertThat(x.getNumberOfElements()).isEqualTo(0).isEqualTo(Ints.saturatedCast( - targetManagement.countTargetByFilters(unknown, null, setA.getId(), Boolean.FALSE, null))); - - x = targetManagement.findTargetByFilters(pageReq, unknown, "%targ-A%", null, Boolean.FALSE, null); - assertThat(x.getNumberOfElements()).isEqualTo(99).isEqualTo(Ints - .saturatedCast(targetManagement.countTargetByFilters(unknown, "%targ-A%", null, Boolean.FALSE, null))); - - x = targetManagement.findTargetByFilters(pageReq, unknown, "%targ-B%", null, Boolean.FALSE, targTagD.getName()); - assertThat(x.getNumberOfElements()).isEqualTo(99).isEqualTo(Ints.saturatedCast( - targetManagement.countTargetByFilters(unknown, "%targ-B%", null, Boolean.FALSE, targTagD.getName()))); - - x = targetManagement.findTargetByFilters(pageReq, unknown, null, null, Boolean.FALSE, targTagD.getName()); - assertThat(x.getNumberOfElements()).isEqualTo(198).isEqualTo(Ints.saturatedCast( - targetManagement.countTargetByFilters(unknown, null, null, Boolean.FALSE, targTagD.getName()))); - - x = targetManagement.findTargetByFilters(pageReq, pending, null, null, Boolean.FALSE, null); - assertThat(x.getNumberOfElements()).isEqualTo(3).isEqualTo( - Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null, Boolean.FALSE, null))); - - x = targetManagement.findTargetByFilters(pageReq, pending, null, setA.getId(), Boolean.FALSE, null); - assertThat(x.getNumberOfElements()).isEqualTo(3).isEqualTo(Ints.saturatedCast( - targetManagement.countTargetByFilters(pending, null, setA.getId(), Boolean.FALSE, null))); - - x = targetManagement.findTargetByFilters(pageReq, pending, "%targ-A%", setA.getId(), Boolean.FALSE, null); - assertThat(x.getNumberOfElements()).isEqualTo(1).isEqualTo(Ints.saturatedCast( - targetManagement.countTargetByFilters(pending, "%targ-A%", setA.getId(), Boolean.FALSE, null))); - - x = targetManagement.findTargetByFilters(pageReq, pending, "%targ-B%", setA.getId(), Boolean.FALSE, - targTagD.getName()); - assertThat(x.getNumberOfElements()).isEqualTo(1).isEqualTo(Ints.saturatedCast(targetManagement - .countTargetByFilters(pending, "%targ-B%", setA.getId(), Boolean.FALSE, targTagD.getName()))); - - x = targetManagement.findTargetByFilters(pageReq, pending, null, setA.getId(), Boolean.FALSE, - targTagD.getName()); - assertThat(x.getNumberOfElements()).isEqualTo(2).isEqualTo(Ints.saturatedCast( - targetManagement.countTargetByFilters(pending, null, setA.getId(), Boolean.FALSE, targTagD.getName()))); - - x = targetManagement.findTargetByFilters(pageReq, pending, null, null, Boolean.FALSE, targTagD.getName()); - assertThat(x.getNumberOfElements()).isEqualTo(2).isEqualTo(Ints.saturatedCast( - targetManagement.countTargetByFilters(pending, null, null, Boolean.FALSE, targTagD.getName()))); - - // Both status: 2 pending and 198 unknown - assertThat(targetManagement.findTargetByFilters(pageReq, both, null, null, Boolean.FALSE, targTagD.getName()) - .getNumberOfElements()).isEqualTo(200).isEqualTo(Ints.saturatedCast( - targetManagement.countTargetByFilters(both, null, null, Boolean.FALSE, targTagD.getName()))); + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, installedSet.getId(), + Boolean.FALSE, new String[0])).as("has number of elements").hasSize(1) + .as("and contains the following elements").containsExactly(expectedIdName) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query))); + + } + + @Step + private void verifyThat200targetsWithGivenTagAreInStatusPendingorUnknown(final TargetTag targTagW, + final List both, final List expected) { + final List expectedIdNames = convertToIdNames(expected); + + final String query = "(updatestatus==pending or updatestatus==unknown) and tag==" + targTagW.getName(); + + assertThat(targetManagement.findTargetByFilters(pageReq, both, null, null, Boolean.FALSE, targTagW.getName()) + .getContent()).as("has number of elements").hasSize(200) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(both, null, null, + Boolean.FALSE, targTagW.getName()))) + .as("and contains the following elements").containsAll(expected) + .as("and filter query returns the same result") + .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, both, null, null, Boolean.FALSE, + targTagW.getName())).as("has number of elements").hasSize(200).as("and contains the following elements") + .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") + .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, + new TargetFilterQuery("test", query))); + } + + private static List convertToIdNames(final List expected) { + return expected.stream() + .map(target -> new TargetIdName(target.getId(), target.getControllerId(), target.getName())) + .collect(Collectors.toList()); + } + + private static TargetIdName convertToIdName(final Target target) { + return new TargetIdName(target.getId(), target.getControllerId(), target.getName()); + } + + @Step + private void verifyThat2TargetsWithGivenTagAreInPending(final TargetTag targTagW, + final List pending, final List expected) { + final List expectedIdNames = convertToIdNames(expected); + final String query = "updatestatus==pending and tag==" + targTagW.getName(); + + assertThat(targetManagement.findTargetByFilters(pageReq, pending, null, null, Boolean.FALSE, targTagW.getName()) + .getContent()).as("has number of elements").hasSize(2) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null, + Boolean.FALSE, targTagW.getName()))) + .as("and contains the following elements").containsAll(expected) + .as("and filter query returns the same result") + .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, null, Boolean.FALSE, + targTagW.getName())).as("has number of elements").hasSize(2).as("and contains the following elements") + .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") + .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, + new TargetFilterQuery("test", query))); + } + + @Step + private void verifyThat2TargetsWithGivenTagAndDSIsInPending(final TargetTag targTagW, final DistributionSet setA, + final List pending, final List expected) { + final List expectedIdNames = convertToIdNames(expected); + final String query = "updatestatus==pending and (assignedds.name==" + setA.getName() + " or installedds.name==" + + setA.getName() + ") and tag==" + targTagW.getName(); + + assertThat(targetManagement + .findTargetByFilters(pageReq, pending, null, setA.getId(), Boolean.FALSE, targTagW.getName()) + .getContent()).as("has number of elements").hasSize(2) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, setA.getId(), + Boolean.FALSE, targTagW.getName()))) + .as("and contains the following elements").containsAll(expected) + .as("and filter query returns the same result") + .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, null, Boolean.FALSE, + targTagW.getName())).as("has number of elements").hasSize(2).as("and contains the following elements") + .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") + .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, + new TargetFilterQuery("test", query))); + } + + @Step + private void verifyThat1TargetWithGivenNameOrDescAndTagAndDSIsInPending(final TargetTag targTagW, + final DistributionSet setA, final List pending, final Target expected) { + final TargetIdName expectedIdName = convertToIdName(expected); + final String query = "updatestatus==pending and (assignedds.name==" + setA.getName() + " or installedds.name==" + + setA.getName() + ") and (name==*targ-B* or description==*targ-B*) and tag==" + targTagW.getName(); + + assertThat(targetManagement + .findTargetByFilters(pageReq, pending, "%targ-B%", setA.getId(), Boolean.FALSE, targTagW.getName()) + .getContent()).as("has number of elements").hasSize(1) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, "%targ-B%", + setA.getId(), Boolean.FALSE, targTagW.getName()))) + .as("and contains the following elements").containsExactly(expected) + .as("and filter query returns the same result") + .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, "%targ-B%", setA.getId(), Boolean.FALSE, + targTagW.getName())).as("has number of elements").hasSize(1).as("and contains the following elements") + .containsExactly(expectedIdName).as("and NAMED filter query returns the same result") + .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, + new TargetFilterQuery("test", query))); + } + + @Step + private void verifyThat1TargetWithGivenNameOrDescAndDSIsInPending(final DistributionSet setA, + final List pending, final Target expected) { + final TargetIdName expectedIdName = convertToIdName(expected); + final String query = "updatestatus==pending and (assignedds.name==" + setA.getName() + " or installedds.name==" + + setA.getName() + ") and (name==*targ-A* or description==*targ-A*)"; + + assertThat(targetManagement + .findTargetByFilters(pageReq, pending, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0]) + .getContent()).as("has number of elements").hasSize(1) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, "%targ-A%", + setA.getId(), Boolean.FALSE, new String[0]))) + .as("and contains the following elements").containsExactly(expected) + .as("and filter query returns the same result") + .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, "%targ-A%", setA.getId(), Boolean.FALSE, + new String[0])).as("has number of elements").hasSize(1).as("and contains the following elements") + .containsExactly(expectedIdName).as("and NAMED filter query returns the same result") + .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, + new TargetFilterQuery("test", query))); + } + + @Step + private void verifyThat3TargetsWithGivenDSAreInPending(final DistributionSet setA, + final List pending, final List expected) { + final List expectedIdNames = convertToIdNames(expected); + final String query = "updatestatus==pending and (assignedds.name==" + setA.getName() + " or installedds.name==" + + setA.getName() + ")"; + + assertThat(targetManagement + .findTargetByFilters(pageReq, pending, null, setA.getId(), Boolean.FALSE, new String[0]).getContent()) + .as("has number of elements").hasSize(3).as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, setA.getId(), + Boolean.FALSE, new String[0]))) + .as("and contains the following elements").containsAll(expected) + .as("and filter query returns the same result") + .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, setA.getId(), Boolean.FALSE, + new String[0])).as("has number of elements").hasSize(3).as("and contains the following elements") + .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") + .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, + new TargetFilterQuery("test", query))); + } + + @Step + private void verifyThat3TargetsAreInStatusPending(final List pending, + final List expected) { + final List expectedIdNames = convertToIdNames(expected); + final String query = "updatestatus==pending"; + + assertThat(targetManagement.findTargetByFilters(pageReq, pending, null, null, Boolean.FALSE, new String[0]) + .getContent()).as("has number of elements").hasSize(3) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null, + Boolean.FALSE, new String[0]))) + .as("and contains the following elements").containsAll(expected) + .as("and filter query returns the same result") + .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + + assertThat( + targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, null, Boolean.FALSE, new String[0])) + .as("has number of elements").hasSize(3).as("and contains the following elements") + .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") + .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, + new TargetFilterQuery("test", query))); + } + + @Step + private void verifyThat99TargetsWithGivenNameOrDescAndTagAreInStatusUnknown(final TargetTag targTagW, + final List unknown, final List expected) { + final List expectedIdNames = convertToIdNames(expected); + final String query = "updatestatus==unknown and (name==*targ-B* or description==*targ-B*) and tag==" + + targTagW.getName(); + + assertThat(targetManagement + .findTargetByFilters(pageReq, unknown, "%targ-B%", null, Boolean.FALSE, targTagW.getName()) + .getContent()).as("has number of elements").hasSize(99) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, "%targ-B%", null, + Boolean.FALSE, targTagW.getName()))) + .as("and contains the following elements").containsAll(expected) + .as("and filter query returns the same result") + .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, "%targ-B%", null, Boolean.FALSE, + targTagW.getName())).as("has number of elements").hasSize(99).as("and contains the following elements") + .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") + .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, + new TargetFilterQuery("test", query))); + } + + @Step + private void verifyThat99TargetsWithNameOrDescriptionAreInGivenStatus(final List unknown, + final List expected) { + final List expectedIdNames = convertToIdNames(expected); + final String query = "updatestatus==unknown and (name==*targ-A* or description==*targ-A*)"; + + assertThat(targetManagement + .findTargetByFilters(pageReq, unknown, "%targ-A%", null, Boolean.FALSE, new String[0]).getContent()) + .as("has number of elements").hasSize(99).as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, "%targ-A%", null, + Boolean.FALSE, new String[0]))) + .as("and contains the following elements").containsAll(expected) + .as("and filter query returns the same result") + .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, "%targ-A%", null, Boolean.FALSE, + new String[0])).as("has number of elements").hasSize(99).as("and contains the following elements") + .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") + .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, + new TargetFilterQuery("test", query))); + } + + @Step + private void verfyThat0TargetsAreInStatusUnknownAndHaveDSAssigned(final DistributionSet setA, + final List unknown) { + final String query = "updatestatus==unknown and (assignedds.name==" + setA.getName() + " or installedds.name==" + + setA.getName() + ")"; + + assertThat(targetManagement + .findTargetByFilters(pageReq, unknown, null, setA.getId(), Boolean.FALSE, new String[0]).getContent()) + .as("has number of elements").hasSize(0).as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, setA.getId(), + Boolean.FALSE, new String[0]))) + .as("and filter query returns the same result") + .hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size()) + .as("and NAMED filter query returns the same result").hasSize(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent().size()); + + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, null, setA.getId(), Boolean.FALSE, + new String[0])).as("has number of elements").hasSize(0) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query))); + } + + @Step + private void verifyThat198TargetsAreInStatusUnknownAndHaveGivenTags(final TargetTag targTagY, + final TargetTag targTagW, final List unknown, final List expected) { + final List expectedIdNames = convertToIdNames(expected); + final String query = "updatestatus==unknown and (tag==" + targTagY.getName() + " or tag==" + targTagW.getName() + + ")"; + + assertThat(targetManagement.findTargetByFilters(pageReq, unknown, null, null, Boolean.FALSE, targTagY.getName(), + targTagW.getName()).getContent()).as("has number of elements").hasSize(198) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, null, + Boolean.FALSE, targTagY.getName(), targTagW.getName()))) + .as("and contains the following elements").containsAll(expected) + .as("and filter query returns the same result") + .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, null, null, Boolean.FALSE, + targTagY.getName(), targTagW.getName())).as("has number of elements").hasSize(198) + .as("and contains the following elements").containsAll(expectedIdNames) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query))); + } + + @Step + private void verifyThat397TargetsAreInStatusUnknown(final List unknown, + final List expected) { + final List expectedIdNames = convertToIdNames(expected); + final String query = "updatestatus==unknown"; + + assertThat(targetManagement.findTargetByFilters(pageReq, unknown, null, null, Boolean.FALSE, new String[0]) + .getContent()).as("has number of elements").hasSize(397) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, null, + Boolean.FALSE, new String[0]))) + .as("and contains the following elements").containsAll(expected) + .as("and filter query returns the same result") + .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + + assertThat( + targetManagement.findAllTargetIdsByFilters(pageReq, unknown, null, null, Boolean.FALSE, new String[0])) + .as("has number of elements").hasSize(397).as("and contains the following elements") + .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") + .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, + new TargetFilterQuery("test", query))); + } + + @Step + private void verifyThat1TargetWithDescOrNameHasDS(final DistributionSet setA, final Target expected) { + final TargetIdName expectedIdName = convertToIdName(expected); + final String query = "(name==*targ-A* or description==*targ-A*) and (assignedds.name==" + setA.getName() + + " or installedds.name==" + setA.getName() + ")"; + + assertThat(targetManagement + .findTargetByFilters(pageReq, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0]) + .getContent()).as("has number of elements").hasSize(1) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, "%targ-A%", + setA.getId(), Boolean.FALSE, new String[0]))) + .as("and contains the following elements").containsExactly(expected) + .as("and filter query returns the same result") + .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, "%targ-A%", setA.getId(), Boolean.FALSE, + new String[0])).as("has number of elements").hasSize(1).as("and contains the following elements") + .containsExactly(expectedIdName).as("and NAMED filter query returns the same result") + .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, + new TargetFilterQuery("test", query))); + } + + @Step + private void verifyThat3TargetsHaveDSAssigned(final DistributionSet setA, final List expected) { + final List expectedIdNames = convertToIdNames(expected); + final String query = "assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName(); + + assertThat(targetManagement.findTargetByFilters(pageReq, null, null, setA.getId(), Boolean.FALSE, new String[0]) + .getContent()).as("has number of elements").hasSize(3) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, setA.getId(), + Boolean.FALSE, new String[0]))) + .as("and contains the following elements").containsAll(expected) + .as("and filter query returns the same result") + .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, null, setA.getId(), Boolean.FALSE, + new String[0])).as("has number of elements").hasSize(3).as("and contains the following elements") + .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") + .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, + new TargetFilterQuery("test", query))); + } + + @Step + private void verifyThat0TargetsWithNameOrdescAndDSHaveTag(final TargetTag targTagX, final DistributionSet setA) { + final String query = "(name==*targ-C* or description==*targ-C*) and tag==" + targTagX.getName() + + " and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ")"; + assertThat(targetManagement + .findTargetByFilters(pageReq, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagX.getName()) + .getContent()).as("has number of elements").hasSize(0) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, "%targ-C%", + setA.getId(), Boolean.FALSE, targTagX.getName()))) + .as("and filter query returns the same result") + .hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size()) + .as("and NAMED filter query returns the same result").hasSize(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent().size()); + + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, "%targ-C%", setA.getId(), Boolean.FALSE, + targTagX.getName())).as("has number of elements").hasSize(0) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query))); + } + + @Step + private void verifyThat0TargetsWithTagAndDescOrNameHasDS(final TargetTag targTagW, final DistributionSet setA) { + final String query = "(name==*targ-A* or description==*targ-A*) and tag==" + targTagW.getName() + + " and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ")"; + assertThat(targetManagement + .findTargetByFilters(pageReq, null, "%targ-A%", setA.getId(), Boolean.FALSE, targTagW.getName()) + .getContent()).as("has number of elements").hasSize(0) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, "%targ-A%", + setA.getId(), Boolean.FALSE, targTagW.getName()))) + .as("and filter query returns the same result") + .hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size()) + .as("and NAMED filter query returns the same result").hasSize(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent().size()); + + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, "%targ-A%", setA.getId(), Boolean.FALSE, + targTagW.getName())).as("has number of elements").hasSize(0) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query))); + } + + @Step + private void verifyThat1TargetHasTagHasDescOrNameAndDs(final TargetTag targTagW, final DistributionSet setA, + final Target expected) { + final TargetIdName expectedIdName = convertToIdName(expected); + final String query = "(name==*targ-c* or description==*targ-C*) and tag==" + targTagW.getName() + + " and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ")"; + assertThat(targetManagement + .findTargetByFilters(pageReq, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagW.getName()) + .getContent()).as("has number of elements").hasSize(1) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, "%targ-C%", + setA.getId(), Boolean.FALSE, targTagW.getName()))) + .as("and contains the following elements").containsExactly(expected) + .as("and filter query returns the same result") + .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, "%targ-C%", setA.getId(), Boolean.FALSE, + targTagW.getName())).as("has number of elements").hasSize(1).as("and contains the following elements") + .containsExactly(expectedIdName).as("and NAMED filter query returns the same result") + .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, + new TargetFilterQuery("test", query))); + } + + @Step + private void verifyThat100TargetsContainsGivenTextAndHaveTagAssigned(final TargetTag targTagY, + final TargetTag targTagW, final List expected) { + final List expectedIdNames = convertToIdNames(expected); + final String query = "(name==*targ-B* or description==*targ-B*) and (tag==" + targTagY.getName() + " or tag==" + + targTagW.getName() + ")"; + assertThat(targetManagement.findTargetByFilters(pageReq, null, "%targ-B%", null, Boolean.FALSE, + targTagY.getName(), targTagW.getName()).getContent()).as("has number of elements").hasSize(100) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, "%targ-B%", null, + Boolean.FALSE, targTagY.getName(), targTagW.getName()))) + .as("and contains the following elements").containsAll(expected) + .as("and filter query returns the same result") + .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, "%targ-B%", null, Boolean.FALSE, + targTagY.getName(), targTagW.getName())).as("has number of elements").hasSize(100) + .as("and contains the following elements").containsAll(expectedIdNames) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query))); + + } + + @SafeVarargs + private final List concat(final List... targets) { + final List result = new ArrayList<>(); + Arrays.asList(targets).forEach(result::addAll); + return result; + } + + @Step + private void verifyThat200TargetsHaveTagD(final TargetTag targTagD, final List expected) { + final List expectedIdNames = convertToIdNames(expected); + final String query = "tag==" + targTagD.getName(); + assertThat(targetManagement.findTargetByFilters(pageReq, null, null, null, Boolean.FALSE, targTagD.getName()) + .getContent()).as("Expected number of results is").hasSize(200) + .as("and is expected number of results is equal to ") + .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, null, + Boolean.FALSE, targTagD.getName()))) + .as("and contains the following elements").containsAll(expected) + .as("and filter query returns the same result") + .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) + .as("and NAMED filter query returns the same result").containsAll(targetManagement + .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + + assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, null, null, Boolean.FALSE, + targTagD.getName())).as("has number of elements").hasSize(200).as("and contains the following elements") + .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") + .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, + new TargetFilterQuery("test", query))); + + } + + @Step + private void verifyThatRepositoryContains400Targets() { + assertThat(targetManagement.findTargetByFilters(pageReq, null, null, null, null, new String[0]).getContent()) + .as("Overall we expect that many targets in the repository").hasSize(400) + .as("which is also reflected by repository count") + .hasSize(Ints.saturatedCast(targetManagement.countTargetsAll())) + .as("which is also reflected by call without specification") + .containsAll(targetManagement.findTargetsAll(pageReq).getContent()); } - // TODO kaizimmerm: add filter tests @Test @Description("Tests the correct order of targets based on selected distribution set. The system expects to have an order based on installed, assigned DS.") public void targetSearchWithVariousFilterCombinationsAndOrderByDistributionSet() { @@ -205,9 +693,9 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { targInstalled = sendUpdateActionStatusToTargets(ds, targInstalled, Status.FINISHED, "installed"); final Slice result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(pageReq, ds.getId(), - null, null, null, Boolean.FALSE, null); + null, null, null, Boolean.FALSE, new String[0]); - final Comparator byId = (e1, e2) -> Long.compare(e2.getId(), e1.getId()); + final Comparator byId = (e1, e2) -> Long.compare(e2.getId(), e1.getId()); assertThat(result.getNumberOfElements()).isEqualTo(9); final List expected = new ArrayList(); @@ -222,6 +710,113 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { } + @Test + @Description("Verfies that targets with given assigned DS are returned from repository.") + public void findTargetByAssignedDistributionSet() { + final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement, + distributionSetManagement); + targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned")); + List assignedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned")); + + deploymentManagement.assignDistributionSet(assignedSet, assignedtargets); + + // get final updated version of targets + assignedtargets = targetManagement.findTargetByControllerID( + assignedtargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())); + + assertThat(targetManagement.findTargetByAssignedDistributionSet(assignedSet.getId(), pageReq)) + .as("Contains the assigned targets").containsAll(assignedtargets) + .as("and that means the following expected amount").hasSize(10); + + } + + @Test + @Description("Verfies that targets with given assigned DS and additonal specification are returned from repository.") + public void findTargetByAssignedDistributionSetWithAdditonalSpecification() { + final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement, + distributionSetManagement); + final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement, + distributionSetManagement); + targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned")); + List assignedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned")); + + // set on installed and assign another one + deploymentManagement.assignDistributionSet(installedSet, assignedtargets).getActions().forEach(actionId -> { + final Action action = deploymentManagement.findActionWithDetails(actionId); + action.setStatus(Status.FINISHED); + controllerManagament.addUpdateActionStatus( + new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"), action); + }); + deploymentManagement.assignDistributionSet(assignedSet, assignedtargets); + + assignedtargets = targetManagement.findTargetByControllerID( + assignedtargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())); + + assertThat(targetManagement.findTargetByAssignedDistributionSet(assignedSet.getId(), + TargetSpecifications.hasInstalledDistributionSet(installedSet.getId()), pageReq)) + .as("Contains the assigned targets").containsAll(assignedtargets) + .as("and that means the following expected amount").hasSize(10); + } + + @Test + @Description("Verfies that targets with given installed DS are returned from repository.") + public void findTargetByInstalledDistributionSet() { + final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement, + distributionSetManagement); + final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement, + distributionSetManagement); + targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned")); + List installedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned")); + + // set on installed and assign another one + deploymentManagement.assignDistributionSet(installedSet, installedtargets).getActions().forEach(actionId -> { + final Action action = deploymentManagement.findActionWithDetails(actionId); + action.setStatus(Status.FINISHED); + controllerManagament.addUpdateActionStatus( + new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"), action); + }); + deploymentManagement.assignDistributionSet(assignedSet, installedtargets); + + // get final updated version of targets + installedtargets = targetManagement.findTargetByControllerID( + installedtargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())); + + assertThat(targetManagement.findTargetByInstalledDistributionSet(installedSet.getId(), pageReq)) + .as("Contains the assigned targets").containsAll(installedtargets) + .as("and that means the following expected amount").hasSize(10); + + } + + @Test + @Description("Verfies that targets with given installed DS and additonal specification are returned from repository.") + public void findTargetByInstalledDistributionSetWithAdditonalSpecification() { + final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement, + distributionSetManagement); + final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement, + distributionSetManagement); + targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned")); + List installedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned")); + + // set on installed and assign another one + deploymentManagement.assignDistributionSet(installedSet, installedtargets).getActions().forEach(actionId -> { + final Action action = deploymentManagement.findActionWithDetails(actionId); + action.setStatus(Status.FINISHED); + controllerManagament.addUpdateActionStatus( + new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"), action); + }); + deploymentManagement.assignDistributionSet(assignedSet, installedtargets); + + // get final updated version of targets + installedtargets = targetManagement.findTargetByControllerID( + installedtargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())); + + assertThat(targetManagement.findTargetByInstalledDistributionSet(installedSet.getId(), + TargetSpecifications.hasAssignedDistributionSet(assignedSet.getId()), pageReq)) + .as("Contains the assigned targets").containsAll(installedtargets) + .as("and that means the following expected amount").hasSize(10); + + } + private List sendUpdateActionStatusToTargets(final DistributionSet dsA, final Iterable targs, final Status status, final String... msgs) { final List result = new ArrayList(); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java index 20dffde29..36fd2754b 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java @@ -60,8 +60,9 @@ public class TargetManagementTest extends AbstractIntegrationTest { public void createTargetForTenantWhichDoesNotExistThrowsTenantNotExistException() { try { targetManagement.createTarget(new Target("targetId123")); - fail("tenant not exist"); + fail("should not be possible as the tenant does not exist"); } catch (final TenantNotExistException e) { + // ok } } @@ -206,6 +207,12 @@ public class TargetManagementTest extends AbstractIntegrationTest { } + @Test + @Description("Ensures that repositoy returns null if given controller ID does not exist without exception.") + public void findTargetByControllerIDWithDetailsReturnsNullForNonexisting() { + assertThat(targetManagement.findTargetByControllerIDWithDetails("dsfsdfsdfsd")).as("Expected as").isNull(); + } + @Test @Description("Checks if the EntityAlreadyExistsException is thrown if the targets with the same controller ID are created twice.") public void createMultipleTargetsDuplicate() { diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TenantConfigurationManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TenantConfigurationManagementTest.java index 3425c6479..1427df25b 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TenantConfigurationManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TenantConfigurationManagementTest.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.repository; import static org.fest.assertions.api.Assertions.assertThat; +import static org.junit.Assert.fail; import java.time.Duration; import java.util.Arrays; @@ -91,13 +92,19 @@ public class TenantConfigurationManagementTest extends AbstractIntegrationTestWi .isEqualTo(value2); } - @Test(expected = TenantConfigurationValidatorException.class) + @Test @Description("Tests that the get configuration throws exception in case the value cannot be automatically converted from String to Boolean") public void wrongTenantConfigurationValueTypeThrowsException() { final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED; final String value1 = "thisIsNotABoolean"; + // add value as String - tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value1); + try { + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value1); + fail("should not have worked as string is not a boolean"); + } catch (final TenantConfigurationValidatorException e) { + + } } @Test @@ -128,46 +135,71 @@ public class TenantConfigurationManagementTest extends AbstractIntegrationTestWi assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue()).isNull(); } - @Test(expected = TenantConfigurationValidatorException.class) + @Test @Description("Test that an Exception is thrown, when an integer is stored but a string expected.") public void storesIntegerWhenStringIsExpected() { final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME; final Integer wrongDataype = 123; - tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype); + try { + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype); + fail("should not have worked as integer is not a string"); + } catch (final TenantConfigurationValidatorException e) { + + } } - @Test(expected = TenantConfigurationValidatorException.class) + @Test @Description("Test that an Exception is thrown, when an integer is stored but a boolean expected.") public void storesIntegerWhenBooleanIsExpected() { final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED; final Integer wrongDataype = 123; - tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype); + try { + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype); + fail("should not have worked as integer is not a boolean"); + } catch (final TenantConfigurationValidatorException e) { + + } } - @Test(expected = TenantConfigurationValidatorException.class) + @Test @Description("Test that an Exception is thrown, when an integer is stored as PollingTime.") public void storesIntegerWhenPollingIntervalIsExpected() { final TenantConfigurationKey configKey = TenantConfigurationKey.POLLING_TIME_INTERVAL; final Integer wrongDataype = 123; - tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype); + try { + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype); + fail("should not have worked as integer is not a time field"); + } catch (final TenantConfigurationValidatorException e) { + + } } - @Test(expected = TenantConfigurationValidatorException.class) + @Test @Description("Test that an Exception is thrown, when an invalid formatted string is stored as PollingTime.") public void storesWrongFormattedStringAsPollingInterval() { final TenantConfigurationKey configKey = TenantConfigurationKey.POLLING_TIME_INTERVAL; final String wrongFormatted = "wrongFormatted"; - tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongFormatted); + try { + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongFormatted); + fail("should not have worked as string is not a time field"); + } catch (final TenantConfigurationValidatorException e) { + + } } - @Test(expected = TenantConfigurationValidatorException.class) + @Test @Description("Test that an Exception is thrown, when an invalid formatted string is stored as PollingTime.") public void storesTooSmallDurationAsPollingInterval() { final TenantConfigurationKey configKey = TenantConfigurationKey.POLLING_TIME_INTERVAL; final String tooSmallDuration = DurationHelper .durationToFormattedString(DurationHelper.getDurationByTimeValues(0, 0, 1)); - tenantConfigurationManagement.addOrUpdateConfiguration(configKey, tooSmallDuration); + try { + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, tooSmallDuration); + fail("should not have worked as string has an invalid format"); + } catch (final TenantConfigurationValidatorException e) { + + } } @Test diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/model/ModelEqualsHashcodeTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/model/ModelEqualsHashcodeTest.java new file mode 100644 index 000000000..45e56167a --- /dev/null +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/model/ModelEqualsHashcodeTest.java @@ -0,0 +1,102 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.model; + +import static org.fest.assertions.api.Assertions.assertThat; + +import org.eclipse.hawkbit.AbstractIntegrationTest; +import org.junit.Test; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +@Features("Unit Tests - Repository") +@Stories("Repository Model") +public class ModelEqualsHashcodeTest extends AbstractIntegrationTest { + + @Test + @Description("Verfies that different objects even with identical primary key, version and tenant " + + "return different hash codes.") + public void differentEntitiesReturnDifferentHashCodes() { + assertThat(new Action().hashCode()).as("action should have different hashcode than action status") + .isNotEqualTo(new ActionStatus().hashCode()); + assertThat(new DistributionSet().hashCode()) + .as("Distribution set should have different hashcode than software module") + .isNotEqualTo(new SoftwareModule().hashCode()); + assertThat(new DistributionSet().hashCode()) + .as("Distribution set should have different hashcode than action status") + .isNotEqualTo(new ActionStatus().hashCode()); + assertThat(new DistributionSetType().hashCode()) + .as("Distribution set type should have different hashcode than action status") + .isNotEqualTo(new ActionStatus().hashCode()); + } + + @Test + @Description("Verfies that different object even with identical primary key, version and tenant " + + "are not equal.") + public void differentEntitiesAreNotEqual() { + assertThat(new Action().equals(new ActionStatus())).as("action equals action status").isFalse(); + assertThat(new DistributionSet().equals(new SoftwareModule())).as("Distribution set equals software module") + .isFalse(); + assertThat(new DistributionSet().equals(new ActionStatus())).as("Distribution set equals action status") + .isFalse(); + assertThat(new DistributionSetType().equals(new ActionStatus())) + .as("Distribution set type equals action status").isFalse(); + } + + @Test + @Description("Verfies that updated entities are not equal.") + public void changedEntitiesAreNotEqual() { + final SoftwareModuleType type = softwareManagement + .createSoftwareModuleType(new SoftwareModuleType("test", "test", "test", 1)); + assertThat(type).as("persited entity is not equal to regular object") + .isNotEqualTo(new SoftwareModuleType("test", "test", "test", 1)); + + type.setDescription("another"); + final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(type); + assertThat(type).as("Changed entity is not equal to the previous version").isNotEqualTo(updated); + } + + @Test + @Description("Verify that no proxy of the entity manager has an influence on the equals or hashcode result.") + public void managedEntityIsEqualToUnamangedObjectWithSameKey() { + final SoftwareModuleType type = softwareManagement + .createSoftwareModuleType(new SoftwareModuleType("test", "test", "test", 1)); + + final SoftwareModuleType mock = new SoftwareModuleType("test", "test", "test", 1); + mock.setId(type.getId()); + mock.setOptLockRevision(type.getOptLockRevision()); + mock.setTenant(type.getTenant()); + + assertThat(type).as("managed entity is equal to regular object with same content").isEqualTo(mock); + assertThat(type.hashCode()).as("managed entity has same hash code as regular object with same content") + .isEqualTo(mock.hashCode()); + } + + @Test + @Description("Verfies that updated entities do not have the same hashcode.") + public void updatedEntitiesHaveDifferentHashcodes() { + final SoftwareModuleType type = softwareManagement + .createSoftwareModuleType(new SoftwareModuleType("test", "test", "test", 1)); + assertThat(type.hashCode()).as("persited entity does not have same hashcode as regular object") + .isNotEqualTo(new SoftwareModuleType("test", "test", "test", 1).hashCode()); + + final int beforeChange = type.hashCode(); + type.setDescription("another"); + assertThat(type.hashCode()) + .as("Changed entity has no different hashcode than the previous version until updated in repository") + .isEqualTo(beforeChange); + + final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(type); + assertThat(type.hashCode()).as("Updated entity has different hashcode than the previous version") + .isNotEqualTo(updated.hashCode()); + } + +} diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetFieldTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetFieldTest.java index ea1db0ed8..6b1682820 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetFieldTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetFieldTest.java @@ -35,18 +35,18 @@ public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest { @Before public void seuptBeforeTest() { - final DistributionSet ds = TestDataUtil.generateDistributionSet("DS", softwareManagement, - distributionSetManagement); + DistributionSet ds = TestDataUtil.generateDistributionSet("DS", softwareManagement, distributionSetManagement); ds.setDescription("DS"); - ds.getMetadata().add(new DistributionSetMetadata("metaKey", ds, "metaValue")); - distributionSetManagement.updateDistributionSet(ds); + ds = distributionSetManagement.updateDistributionSet(ds); + distributionSetManagement + .createDistributionSetMetadata(new DistributionSetMetadata("metaKey", ds, "metaValue")); - final DistributionSet ds2 = TestDataUtil + DistributionSet ds2 = TestDataUtil .generateDistributionSets("NewDS", 3, softwareManagement, distributionSetManagement).get(0); ds2.setDescription("DS%"); - ds2.getMetadata().add(new DistributionSetMetadata("metaKey", ds2, "value")); - distributionSetManagement.updateDistributionSet(ds2); + ds2 = distributionSetManagement.updateDistributionSet(ds2); + distributionSetManagement.createDistributionSetMetadata(new DistributionSetMetadata("metaKey", ds2, "value")); final DistributionSetTag targetTag = tagManagement.createDistributionSetTag(new DistributionSetTag("Tag1")); tagManagement.createDistributionSetTag(new DistributionSetTag("Tag2")); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetMetadataFieldsTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetMetadataFieldsTest.java index 1d1e8b7f3..755e5a61f 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetMetadataFieldsTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetMetadataFieldsTest.java @@ -10,6 +10,9 @@ package org.eclipse.hawkbit.repository.rsql; import static org.fest.assertions.api.Assertions.assertThat; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.DistributionSetMetadataFields; @@ -35,13 +38,13 @@ public class RSQLDistributionSetMetadataFieldsTest extends AbstractIntegrationTe final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("DS", softwareManagement, distributionSetManagement); distributionSetId = distributionSet.getId(); + + final List metadata = new ArrayList<>(); for (int i = 0; i < 5; i++) { - final DistributionSetMetadata distributionSetMetadata = new DistributionSetMetadata("" + i, distributionSet, - "" + i); - distributionSet.getMetadata().add(distributionSetMetadata); + metadata.add(new DistributionSetMetadata("" + i, distributionSet, "" + i)); } - distributionSetManagement.updateDistributionSet(distributionSet); + distributionSetManagement.createDistributionSetMetadata(metadata); } @Test diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleFieldTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleFieldTest.java index 88f0817f7..0c113fd2b 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleFieldTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleFieldTest.java @@ -28,8 +28,7 @@ import ru.yandex.qatools.allure.annotations.Stories; public class RSQLSoftwareModuleFieldTest extends AbstractIntegrationTest { @Before - public void seuptBeforeTest() { - + public void setupBeforeTest() { final SoftwareModule ah = softwareManagement .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", "agent-hub", "")); softwareManagement.createSoftwareModule(new SoftwareModule(runtimeType, "oracle-jre", "1.7.2", "aa", "")); @@ -40,14 +39,9 @@ public class RSQLSoftwareModuleFieldTest extends AbstractIntegrationTest { final SoftwareModuleMetadata softwareModuleMetadata = new SoftwareModuleMetadata("metaKey", ah, "metaValue"); softwareManagement.createSoftwareModuleMetadata(softwareModuleMetadata); - ah.getMetadata().add(softwareModuleMetadata); - softwareManagement.updateSoftwareModule(ah); final SoftwareModuleMetadata softwareModuleMetadata2 = new SoftwareModuleMetadata("metaKey", ah2, "value"); softwareManagement.createSoftwareModuleMetadata(softwareModuleMetadata2); - ah2.getMetadata().add(softwareModuleMetadata2); - softwareManagement.updateSoftwareModule(ah2); - } @Test diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleMetadataFieldsTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleMetadataFieldsTest.java index c863c1460..44fa3e3cd 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleMetadataFieldsTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleMetadataFieldsTest.java @@ -10,6 +10,9 @@ package org.eclipse.hawkbit.repository.rsql; import static org.fest.assertions.api.Assertions.assertThat; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields; @@ -37,13 +40,13 @@ public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractIntegrationTes "application", "1.0.0", "Desc", "vendor Limited, California")); softwareModuleId = softwareModule.getId(); + final List metadata = new ArrayList<>(); for (int i = 0; i < 5; i++) { - final SoftwareModuleMetadata metadata = new SoftwareModuleMetadata("" + i, softwareModule, "" + i); - softwareModule.getMetadata().add(metadata); - softwareModuleMetadataRepository.save(metadata); + metadata.add(new SoftwareModuleMetadata("" + i, softwareModule, "" + i)); } - softwareManagement.updateSoftwareModule(softwareModule); + softwareManagement.createSoftwareModuleMetadata(metadata); + } @Test diff --git a/hawkbit-repository/src/test/resources/application-test.properties b/hawkbit-repository/src/test/resources/application-test.properties index b1904f911..0882d901c 100644 --- a/hawkbit-repository/src/test/resources/application-test.properties +++ b/hawkbit-repository/src/test/resources/application-test.properties @@ -13,7 +13,7 @@ spring.data.mongodb.port=28017 hawkbit.server.ddi.security.authentication.header.enabled=true hawkbit.server.ddi.security.authentication.gatewaytoken.name=TestToken -hawkbit.server.artifact.repo.upload.maxFileSize=5MB +multipart.max-file-size=5MB hawkbit.server.security.dos.maxStatusEntriesPerAction=100 @@ -26,7 +26,6 @@ spring.datasource.username=sa spring.datasource.password=sa flyway.enabled=true -flyway.initOnMigrate=true flyway.sqlMigrationSuffix=${spring.jpa.database}.sql #spring.jpa.show-sql=true diff --git a/hawkbit-rest-api/pom.xml b/hawkbit-rest-api/pom.xml index be9abafac..703d6caf3 100644 --- a/hawkbit-rest-api/pom.xml +++ b/hawkbit-rest-api/pom.xml @@ -24,7 +24,6 @@ javax.validation validation-api - 1.1.0.Final org.springframework.hateoas diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/DistributionSetRestApi.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/DistributionSetRestApi.java index 05d377950..80caefc94 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/DistributionSetRestApi.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/DistributionSetRestApi.java @@ -13,17 +13,15 @@ import java.util.List; import org.eclipse.hawkbit.rest.resource.RestConstants; import org.eclipse.hawkbit.rest.resource.model.MetadataRest; -import org.eclipse.hawkbit.rest.resource.model.MetadataRestPageList; -import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetPagedList; +import org.eclipse.hawkbit.rest.resource.model.PagedList; import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyPost; import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyPut; import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRest; -import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest; import org.eclipse.hawkbit.rest.resource.model.distributionset.TargetAssignmentRequestBody; import org.eclipse.hawkbit.rest.resource.model.distributionset.TargetAssignmentResponseBody; import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleAssigmentRest; -import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModulePagedList; -import org.eclipse.hawkbit.rest.resource.model.target.TargetPagedList; +import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleRest; +import org.eclipse.hawkbit.rest.resource.model.target.TargetRest; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -58,7 +56,7 @@ public interface DistributionSetRestApi { * JsonResponseExceptionHandler is handling the response. */ @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity getDistributionSets( + public ResponseEntity> getDistributionSets( @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, @@ -93,7 +91,7 @@ public interface DistributionSetRestApi { */ @RequestMapping(method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity createDistributionSets( + public ResponseEntity> createDistributionSets( @RequestBody final List sets); /** @@ -148,7 +146,7 @@ public interface DistributionSetRestApi { */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/assignedTargets", produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) - public ResponseEntity getAssignedTargets( + public ResponseEntity> getAssignedTargets( @PathVariable("distributionSetId") final Long distributionSetId, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @@ -179,7 +177,7 @@ public interface DistributionSetRestApi { */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/installedTargets", produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) - public ResponseEntity getInstalledTargets( + public ResponseEntity> getInstalledTargets( @PathVariable("distributionSetId") final Long distributionSetId, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @@ -228,7 +226,7 @@ public interface DistributionSetRestApi { */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/metadata", produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) - public ResponseEntity getMetadata( + public ResponseEntity> getMetadata( @PathVariable("distributionSetId") final Long distributionSetId, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @@ -357,7 +355,7 @@ public interface DistributionSetRestApi { */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/assignedSM", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity getAssignedSoftwareModules( + public ResponseEntity> getAssignedSoftwareModules( @PathVariable("distributionSetId") final Long distributionSetId, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/DistributionSetTagRestApi.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/DistributionSetTagRestApi.java index d99368dc2..83f29bb17 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/DistributionSetTagRestApi.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/DistributionSetTagRestApi.java @@ -11,13 +11,12 @@ package org.eclipse.hawkbit.rest.resource.api; import java.util.List; import org.eclipse.hawkbit.rest.resource.RestConstants; -import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest; +import org.eclipse.hawkbit.rest.resource.model.PagedList; +import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRest; import org.eclipse.hawkbit.rest.resource.model.tag.AssignedDistributionSetRequestBody; import org.eclipse.hawkbit.rest.resource.model.tag.DistributionSetTagAssigmentResultRest; -import org.eclipse.hawkbit.rest.resource.model.tag.TagPagedList; import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut; import org.eclipse.hawkbit.rest.resource.model.tag.TagRest; -import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -53,7 +52,7 @@ public interface DistributionSetTagRestApi { * JsonResponseExceptionHandler is handling the response. */ @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity getDistributionSetTags( + public ResponseEntity> getDistributionSetTags( @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, @@ -87,7 +86,7 @@ public interface DistributionSetTagRestApi { */ @RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity createDistributionSetTags(@RequestBody final List tags); + public ResponseEntity> createDistributionSetTags(@RequestBody final List tags); /** * @@ -137,7 +136,7 @@ public interface DistributionSetTagRestApi { * exists. */ @RequestMapping(method = RequestMethod.GET, value = RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING) - public ResponseEntity getAssignedDistributionSets( + public ResponseEntity> getAssignedDistributionSets( @PathVariable("distributionsetTagId") final Long distributionsetTagId); /** @@ -175,7 +174,7 @@ public interface DistributionSetTagRestApi { * exists. */ @RequestMapping(method = RequestMethod.POST, value = RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING) - public ResponseEntity assignDistributionSets( + public ResponseEntity> assignDistributionSets( @PathVariable("distributionsetTagId") final Long distributionsetTagId, @RequestBody final List assignedDSRequestBodies); diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/DistributionSetTypeRestApi.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/DistributionSetTypeRestApi.java index 9bed7f4f8..1900d8d7d 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/DistributionSetTypeRestApi.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/DistributionSetTypeRestApi.java @@ -12,13 +12,11 @@ import java.util.List; import org.eclipse.hawkbit.rest.resource.RestConstants; import org.eclipse.hawkbit.rest.resource.model.IdRest; -import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypePagedList; +import org.eclipse.hawkbit.rest.resource.model.PagedList; import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRequestBodyPost; import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRequestBodyPut; import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRest; -import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypesRest; import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRest; -import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypesRest; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -57,7 +55,7 @@ public interface DistributionSetTypeRestApi { * response. */ @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity getDistributionSetTypes( + public ResponseEntity> getDistributionSetTypes( @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, @@ -119,7 +117,7 @@ public interface DistributionSetTypeRestApi { */ @RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity createDistributionSetTypes( + public ResponseEntity> createDistributionSetTypes( @RequestBody final List distributionSetTypes); /** @@ -133,7 +131,7 @@ public interface DistributionSetTypeRestApi { @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}/" + RestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity getMandatoryModules( + public ResponseEntity> getMandatoryModules( @PathVariable("distributionSetTypeId") final Long distributionSetTypeId); /** @@ -181,7 +179,7 @@ public interface DistributionSetTypeRestApi { @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}/" + RestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity getOptionalModules( + public ResponseEntity> getOptionalModules( @PathVariable("distributionSetTypeId") final Long distributionSetTypeId); /** diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/RolloutRestApi.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/RolloutRestApi.java index fe1c7caa5..9f76b6bce 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/RolloutRestApi.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/RolloutRestApi.java @@ -9,12 +9,11 @@ package org.eclipse.hawkbit.rest.resource.api; import org.eclipse.hawkbit.rest.resource.RestConstants; -import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutPagedList; +import org.eclipse.hawkbit.rest.resource.model.PagedList; import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutResponseBody; import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutRestRequestBody; -import org.eclipse.hawkbit.rest.resource.model.rolloutgroup.RolloutGroupPagedList; import org.eclipse.hawkbit.rest.resource.model.rolloutgroup.RolloutGroupResponseBody; -import org.eclipse.hawkbit.rest.resource.model.target.TargetPagedList; +import org.eclipse.hawkbit.rest.resource.model.target.TargetRest; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -50,7 +49,7 @@ public interface RolloutRestApi { * JsonResponseExceptionHandler is handling the response. */ @RequestMapping(method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) - public ResponseEntity getRollouts( + public ResponseEntity> getRollouts( @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, @@ -154,7 +153,8 @@ public interface RolloutRestApi { */ @RequestMapping(method = RequestMethod.GET, value = "/{rolloutId}/deploygroups", produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) - public ResponseEntity getRolloutGroups(@PathVariable("rolloutId") final Long rolloutId, + public ResponseEntity> getRolloutGroups( + @PathVariable("rolloutId") final Long rolloutId, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, @@ -200,7 +200,7 @@ public interface RolloutRestApi { */ @RequestMapping(method = RequestMethod.GET, value = "/{rolloutId}/deploygroups/{groupId}/targets", produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) - public ResponseEntity getRolloutGroupTargets(@PathVariable("rolloutId") final Long rolloutId, + public ResponseEntity> getRolloutGroupTargets(@PathVariable("rolloutId") final Long rolloutId, @PathVariable("groupId") final Long groupId, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/SoftwareModuleRestAPI.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/SoftwareModuleRestAPI.java index 0662c43ba..0eb874489 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/SoftwareModuleRestAPI.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/SoftwareModuleRestAPI.java @@ -12,14 +12,11 @@ import java.util.List; import org.eclipse.hawkbit.rest.resource.RestConstants; import org.eclipse.hawkbit.rest.resource.model.MetadataRest; -import org.eclipse.hawkbit.rest.resource.model.MetadataRestPageList; +import org.eclipse.hawkbit.rest.resource.model.PagedList; import org.eclipse.hawkbit.rest.resource.model.artifact.ArtifactRest; -import org.eclipse.hawkbit.rest.resource.model.artifact.ArtifactsRest; -import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModulePagedList; import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleRequestBodyPost; import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleRequestBodyPut; import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleRest; -import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModulesRest; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -79,7 +76,8 @@ public interface SoftwareModuleRestAPI { @RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/artifacts", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) @ResponseBody - public ResponseEntity getArtifacts(@PathVariable("softwareModuleId") final Long softwareModuleId); + public ResponseEntity> getArtifacts( + @PathVariable("softwareModuleId") final Long softwareModuleId); /** * Handles the GET request of retrieving a single Artifact meta data @@ -134,7 +132,7 @@ public interface SoftwareModuleRestAPI { * JsonResponseExceptionHandler is handling the response. */ @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity getSoftwareModules( + public ResponseEntity> getSoftwareModules( @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, @@ -168,7 +166,7 @@ public interface SoftwareModuleRestAPI { */ @RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity createSoftwareModules( + public ResponseEntity> createSoftwareModules( @RequestBody final List softwareModules); /** @@ -187,7 +185,7 @@ public interface SoftwareModuleRestAPI { @RequestBody final SoftwareModuleRequestBodyPut restSoftwareModule); /** - * Handles the DELETE request for a single softwaremodule. + * Handles the DELETE request for a single software module. * * @param softwareModuleId * the ID of the module to retrieve @@ -219,7 +217,7 @@ public interface SoftwareModuleRestAPI { */ @RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/metadata", produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) - public ResponseEntity getMetadata( + public ResponseEntity> getMetadata( @PathVariable("softwareModuleId") final Long softwareModuleId, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/SoftwareModuleTypeRestApi.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/SoftwareModuleTypeRestApi.java index 0c4756a04..a98e35a32 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/SoftwareModuleTypeRestApi.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/SoftwareModuleTypeRestApi.java @@ -11,11 +11,10 @@ package org.eclipse.hawkbit.rest.resource.api; import java.util.List; import org.eclipse.hawkbit.rest.resource.RestConstants; -import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypePagedList; +import org.eclipse.hawkbit.rest.resource.model.PagedList; import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRequestBodyPost; import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRequestBodyPut; import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRest; -import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypesRest; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -52,7 +51,7 @@ public interface SoftwareModuleTypeRestApi { * JsonResponseExceptionHandler is handling the response. */ @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity getTypes( + public ResponseEntity> getTypes( @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, @@ -113,7 +112,7 @@ public interface SoftwareModuleTypeRestApi { */ @RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity createSoftwareModuleTypes( + public ResponseEntity> createSoftwareModuleTypes( @RequestBody final List softwareModuleTypes); } diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/TargetRestApi.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/TargetRestApi.java index 9d63a520f..48e242f81 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/TargetRestApi.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/TargetRestApi.java @@ -11,16 +11,14 @@ package org.eclipse.hawkbit.rest.resource.api; import java.util.List; import org.eclipse.hawkbit.rest.resource.RestConstants; -import org.eclipse.hawkbit.rest.resource.model.action.ActionPagedList; +import org.eclipse.hawkbit.rest.resource.model.PagedList; import org.eclipse.hawkbit.rest.resource.model.action.ActionRest; -import org.eclipse.hawkbit.rest.resource.model.action.ActionStatusPagedList; +import org.eclipse.hawkbit.rest.resource.model.action.ActionStatusRest; import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRest; import org.eclipse.hawkbit.rest.resource.model.target.DistributionSetAssigmentRest; import org.eclipse.hawkbit.rest.resource.model.target.TargetAttributes; -import org.eclipse.hawkbit.rest.resource.model.target.TargetPagedList; import org.eclipse.hawkbit.rest.resource.model.target.TargetRequestBody; import org.eclipse.hawkbit.rest.resource.model.target.TargetRest; -import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -70,7 +68,7 @@ public interface TargetRestApi { */ @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity getTargets( + public ResponseEntity> getTargets( @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, @@ -89,7 +87,7 @@ public interface TargetRestApi { */ @RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity createTargets(@RequestBody final List targets); + public ResponseEntity> createTargets(@RequestBody final List targets); /** * Handles the PUT request of updating a target. The ID is within the URL @@ -160,7 +158,7 @@ public interface TargetRestApi { */ @RequestMapping(method = RequestMethod.GET, value = "/{targetId}/actions", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity getActionHistory(@PathVariable("targetId") final String targetId, + public ResponseEntity> getActionHistory(@PathVariable("targetId") final String targetId, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, @@ -225,8 +223,8 @@ public interface TargetRestApi { */ @RequestMapping(method = RequestMethod.GET, value = "/{targetId}/actions/{actionId}/status", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity getActionStatusList(@PathVariable("targetId") final String targetId, - @PathVariable("actionId") final Long actionId, + public ResponseEntity> getActionStatusList( + @PathVariable("targetId") final String targetId, @PathVariable("actionId") final Long actionId, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam); diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/TargetTagRestApi.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/TargetTagRestApi.java index 59770db08..940b578d4 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/TargetTagRestApi.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/api/TargetTagRestApi.java @@ -11,13 +11,12 @@ package org.eclipse.hawkbit.rest.resource.api; import java.util.List; import org.eclipse.hawkbit.rest.resource.RestConstants; +import org.eclipse.hawkbit.rest.resource.model.PagedList; import org.eclipse.hawkbit.rest.resource.model.tag.AssignedTargetRequestBody; -import org.eclipse.hawkbit.rest.resource.model.tag.TagPagedList; import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut; import org.eclipse.hawkbit.rest.resource.model.tag.TagRest; -import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest; import org.eclipse.hawkbit.rest.resource.model.tag.TargetTagAssigmentResultRest; -import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest; +import org.eclipse.hawkbit.rest.resource.model.target.TargetRest; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -53,7 +52,7 @@ public interface TargetTagRestApi { * JsonResponseExceptionHandler is handling the response. */ @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity getTargetTags( + public ResponseEntity> getTargetTags( @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, @@ -85,7 +84,7 @@ public interface TargetTagRestApi { */ @RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity createTargetTags(@RequestBody final List tags); + public ResponseEntity> createTargetTags(@RequestBody final List tags); /** * @@ -129,7 +128,7 @@ public interface TargetTagRestApi { * in case the given {@code targetTagId} doesn't exists. */ @RequestMapping(method = RequestMethod.GET, value = RestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING) - public ResponseEntity getAssignedTargets(@PathVariable("targetTagId") final Long targetTagId); + public ResponseEntity> getAssignedTargets(@PathVariable("targetTagId") final Long targetTagId); /** * Handles the POST request to toggle the assignment of targets by the given @@ -163,7 +162,7 @@ public interface TargetTagRestApi { * in case the given {@code targetTagId} doesn't exists. */ @RequestMapping(method = RequestMethod.POST, value = RestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING) - public ResponseEntity assignTargets(@PathVariable("targetTagId") final Long targetTagId, + public ResponseEntity> assignTargets(@PathVariable("targetTagId") final Long targetTagId, @RequestBody final List assignedTargetRequestBodies); /** diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/MetadataRestPageList.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/MetadataRestPageList.java deleted file mode 100644 index 0d375c582..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/MetadataRestPageList.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model; - -import java.util.List; - -/** - * The rest model for a paged meta data list. - * - */ -public class MetadataRestPageList extends PagedList { - - private final List content; - - /** - * @param content - * the meta data rest model list as content - * @param total - * the total number of the meta data - */ - public MetadataRestPageList(final List content, final long total) { - super(content, total); - this.content = content; - } - - /** - * @return the content of this paged list - */ - public List getContent() { - return content; - } -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/PagedList.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/PagedList.java index 082015b5c..880ee0c16 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/PagedList.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/PagedList.java @@ -20,19 +20,18 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; /** * A list representation with meta data for pagination, e.g. containing the - * total elements. The content of the acutal list is stored in the - * {@link #content} field. + * total elements and size of content. The content of the actual list is stored + * in the {@link #content} field. * * @param * the type of elements in this list * - * - * */ @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(Include.NON_NULL) public class PagedList extends ResourceSupport { + private final List content; private final long totalElements; private final int size; @@ -50,6 +49,7 @@ public class PagedList extends ResourceSupport { public PagedList(@NotNull final List content, final long total) { this.size = content.size(); this.totalElements = total; + this.content = content; } /** @@ -65,4 +65,9 @@ public class PagedList extends ResourceSupport { public long getTotal() { return totalElements; } + + public List getContent() { + return content; + } + } diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionPagedList.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionPagedList.java deleted file mode 100644 index 27b36779a..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionPagedList.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model.action; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.hawkbit.rest.resource.model.PagedList; - -/** - * Paged list rest model for {@link ErrorAction} to RESTful API representation. - * - */ -public class ActionPagedList extends PagedList { - - private final List content; - - /** - * Empty default constructor. - */ - public ActionPagedList() { - super(Collections.emptyList(), 0); - this.content = Collections.emptyList(); - } - - /** - * @param content - * @param total - */ - public ActionPagedList(final List content, final long total) { - super(content, total); - this.content = content; - } - - /** - * @return the content of the paged list. Never {@code null}. - */ - public List getContent() { - return content; - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionRest.java index 3bd57ab20..630bcb993 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionRest.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionRest.java @@ -18,9 +18,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; /** * A json annotated rest model for Action to RESTful API representation. * - * - * - * */ @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionStatusPagedList.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionStatusPagedList.java deleted file mode 100644 index d9f19b98e..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionStatusPagedList.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model.action; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.hawkbit.rest.resource.model.PagedList; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -/** - * Paged list rest model for ActionStatus to RESTful API representation. - * - * - * - * - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class ActionStatusPagedList extends PagedList { - - private final List content; - - /** - * @param content - * @param total - */ - public ActionStatusPagedList(final List content, final long total) { - super(content, total); - this.content = content; - } - - /** - * Default constructor. - */ - public ActionStatusPagedList() { - super(Collections.emptyList(), 0); - this.content = Collections.emptyList(); - } - - /** - * @return the content of the paged list. Never {@code null}. - */ - public List getContent() { - return content; - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionStatusRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionStatusRest.java index 1f08afe49..e5af39bac 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionStatusRest.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionStatusRest.java @@ -18,9 +18,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; /** * A json annotated rest model for ActionStatus to RESTful API representation. * - * - * - * */ @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionStatussRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionStatussRest.java deleted file mode 100644 index b3f3207b4..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionStatussRest.java +++ /dev/null @@ -1,277 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model.action; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.springframework.hateoas.ResourceSupport; - -/** - * A list representation of the ActionStatus because Spring MVC cannot handle - * plain lists interfaces as request body. - * - * - * - * - */ -public class ActionStatussRest extends ResourceSupport implements List { - - private final List delegate = new ArrayList<>(); - - /** - * @return - * @see java.util.List#size() - */ - @Override - public int size() { - return delegate.size(); - } - - /** - * @return - * @see java.util.List#isEmpty() - */ - @Override - public boolean isEmpty() { - return delegate.isEmpty(); - } - - /** - * @param o - * @return - * @see java.util.List#contains(java.lang.Object) - */ - @Override - public boolean contains(final Object o) { - return delegate.contains(o); - } - - /** - * @return - * @see java.util.List#iterator() - */ - @Override - public Iterator iterator() { - return delegate.iterator(); - } - - /** - * @return - * @see java.util.List#toArray() - */ - @Override - public Object[] toArray() { - return delegate.toArray(); - } - - /** - * @param a - * @return - * @see java.util.List#toArray(java.lang.Object[]) - */ - @Override - public T[] toArray(final T[] a) { - return delegate.toArray(a); - } - - /** - * @param e - * @return - * @see java.util.List#add(java.lang.Object) - */ - @Override - public boolean add(final ActionStatusRest e) { - return delegate.add(e); - } - - /** - * @param o - * @return - * @see java.util.List#remove(java.lang.Object) - */ - @Override - public boolean remove(final Object o) { - return delegate.remove(o); - } - - /** - * @param c - * @return - * @see java.util.List#containsAll(java.util.Collection) - */ - @Override - public boolean containsAll(final Collection c) { - return delegate.containsAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#addAll(java.util.Collection) - */ - @Override - public boolean addAll(final Collection c) { - return delegate.addAll(c); - } - - /** - * @param index - * @param c - * @return - * @see java.util.List#addAll(int, java.util.Collection) - */ - @Override - public boolean addAll(final int index, final Collection c) { - return delegate.addAll(index, c); - } - - /** - * @param c - * @return - * @see java.util.List#removeAll(java.util.Collection) - */ - @Override - public boolean removeAll(final Collection c) { - return delegate.removeAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#retainAll(java.util.Collection) - */ - @Override - public boolean retainAll(final Collection c) { - return delegate.retainAll(c); - } - - /** - * - * @see java.util.List#clear() - */ - @Override - public void clear() { - delegate.clear(); - } - - /** - * @param o - * @return - * @see java.util.List#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object o) { - return delegate.equals(o); - } - - /** - * @return - * @see java.util.List#hashCode() - */ - @Override - public int hashCode() { - return delegate.hashCode(); - } - - /** - * @param index - * @return - * @see java.util.List#get(int) - */ - @Override - public ActionStatusRest get(final int index) { - return delegate.get(index); - } - - /** - * @param index - * @param element - * @return - * @see java.util.List#set(int, java.lang.Object) - */ - @Override - public ActionStatusRest set(final int index, final ActionStatusRest element) { - return delegate.set(index, element); - } - - /** - * @param index - * @param element - * @see java.util.List#add(int, java.lang.Object) - */ - @Override - public void add(final int index, final ActionStatusRest element) { - delegate.add(index, element); - } - - /** - * @param index - * @return - * @see java.util.List#remove(int) - */ - @Override - public ActionStatusRest remove(final int index) { - return delegate.remove(index); - } - - /** - * @param o - * @return - * @see java.util.List#indexOf(java.lang.Object) - */ - @Override - public int indexOf(final Object o) { - return delegate.indexOf(o); - } - - /** - * @param o - * @return - * @see java.util.List#lastIndexOf(java.lang.Object) - */ - @Override - public int lastIndexOf(final Object o) { - return delegate.lastIndexOf(o); - } - - /** - * @return - * @see java.util.List#listIterator() - */ - @Override - public ListIterator listIterator() { - return delegate.listIterator(); - } - - /** - * @param index - * @return - * @see java.util.List#listIterator(int) - */ - @Override - public ListIterator listIterator(final int index) { - return delegate.listIterator(index); - } - - /** - * @param fromIndex - * @param toIndex - * @return - * @see java.util.List#subList(int, int) - */ - @Override - public List subList(final int fromIndex, final int toIndex) { - return delegate.subList(fromIndex, toIndex); - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionsRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionsRest.java deleted file mode 100644 index 9c3659f30..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/action/ActionsRest.java +++ /dev/null @@ -1,276 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model.action; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.springframework.hateoas.ResourceSupport; - -/** - * A json annotated rest model for Actions to RESTful API representation. - * - * - * - * - */ -public class ActionsRest extends ResourceSupport implements List { - - private final List delegate = new ArrayList<>(); - - /** - * @return - * @see java.util.List#size() - */ - @Override - public int size() { - return delegate.size(); - } - - /** - * @return - * @see java.util.List#isEmpty() - */ - @Override - public boolean isEmpty() { - return delegate.isEmpty(); - } - - /** - * @param o - * @return - * @see java.util.List#contains(java.lang.Object) - */ - @Override - public boolean contains(final Object o) { - return delegate.contains(o); - } - - /** - * @return - * @see java.util.List#iterator() - */ - @Override - public Iterator iterator() { - return delegate.iterator(); - } - - /** - * @return - * @see java.util.List#toArray() - */ - @Override - public Object[] toArray() { - return delegate.toArray(); - } - - /** - * @param a - * @return - * @see java.util.List#toArray(java.lang.Object[]) - */ - @Override - public T[] toArray(final T[] a) { - return delegate.toArray(a); - } - - /** - * @param e - * @return - * @see java.util.List#add(java.lang.Object) - */ - @Override - public boolean add(final ActionRest e) { - return delegate.add(e); - } - - /** - * @param o - * @return - * @see java.util.List#remove(java.lang.Object) - */ - @Override - public boolean remove(final Object o) { - return delegate.remove(o); - } - - /** - * @param c - * @return - * @see java.util.List#containsAll(java.util.Collection) - */ - @Override - public boolean containsAll(final Collection c) { - return delegate.containsAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#addAll(java.util.Collection) - */ - @Override - public boolean addAll(final Collection c) { - return delegate.addAll(c); - } - - /** - * @param index - * @param c - * @return - * @see java.util.List#addAll(int, java.util.Collection) - */ - @Override - public boolean addAll(final int index, final Collection c) { - return delegate.addAll(index, c); - } - - /** - * @param c - * @return - * @see java.util.List#removeAll(java.util.Collection) - */ - @Override - public boolean removeAll(final Collection c) { - return delegate.removeAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#retainAll(java.util.Collection) - */ - @Override - public boolean retainAll(final Collection c) { - return delegate.retainAll(c); - } - - /** - * - * @see java.util.List#clear() - */ - @Override - public void clear() { - delegate.clear(); - } - - /** - * @param o - * @return - * @see java.util.List#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object o) { - return delegate.equals(o); - } - - /** - * @return - * @see java.util.List#hashCode() - */ - @Override - public int hashCode() { - return delegate.hashCode(); - } - - /** - * @param index - * @return - * @see java.util.List#get(int) - */ - @Override - public ActionRest get(final int index) { - return delegate.get(index); - } - - /** - * @param index - * @param element - * @return - * @see java.util.List#set(int, java.lang.Object) - */ - @Override - public ActionRest set(final int index, final ActionRest element) { - return delegate.set(index, element); - } - - /** - * @param index - * @param element - * @see java.util.List#add(int, java.lang.Object) - */ - @Override - public void add(final int index, final ActionRest element) { - delegate.add(index, element); - } - - /** - * @param index - * @return - * @see java.util.List#remove(int) - */ - @Override - public ActionRest remove(final int index) { - return delegate.remove(index); - } - - /** - * @param o - * @return - * @see java.util.List#indexOf(java.lang.Object) - */ - @Override - public int indexOf(final Object o) { - return delegate.indexOf(o); - } - - /** - * @param o - * @return - * @see java.util.List#lastIndexOf(java.lang.Object) - */ - @Override - public int lastIndexOf(final Object o) { - return delegate.lastIndexOf(o); - } - - /** - * @return - * @see java.util.List#listIterator() - */ - @Override - public ListIterator listIterator() { - return delegate.listIterator(); - } - - /** - * @param index - * @return - * @see java.util.List#listIterator(int) - */ - @Override - public ListIterator listIterator(final int index) { - return delegate.listIterator(index); - } - - /** - * @param fromIndex - * @param toIndex - * @return - * @see java.util.List#subList(int, int) - */ - @Override - public List subList(final int fromIndex, final int toIndex) { - return delegate.subList(fromIndex, toIndex); - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/artifact/ArtifactsRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/artifact/ArtifactsRest.java deleted file mode 100644 index 172e4d315..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/artifact/ArtifactsRest.java +++ /dev/null @@ -1,273 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model.artifact; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.springframework.hateoas.ResourceSupport; - -/** - * List representation of the {@link ArtifactRest}. - * - */ -public class ArtifactsRest extends ResourceSupport implements List { - - private final List delegate = new ArrayList<>(); - - /** - * @return - * @see java.util.List#size() - */ - @Override - public int size() { - return delegate.size(); - } - - /** - * @return - * @see java.util.List#isEmpty() - */ - @Override - public boolean isEmpty() { - return delegate.isEmpty(); - } - - /** - * @param o - * @return - * @see java.util.List#contains(java.lang.Object) - */ - @Override - public boolean contains(final Object o) { - return delegate.contains(o); - } - - /** - * @return - * @see java.util.List#iterator() - */ - @Override - public Iterator iterator() { - return delegate.iterator(); - } - - /** - * @return - * @see java.util.List#toArray() - */ - @Override - public Object[] toArray() { - return delegate.toArray(); - } - - /** - * @param a - * @return - * @see java.util.List#toArray(java.lang.Object[]) - */ - @Override - public T[] toArray(final T[] a) { - return delegate.toArray(a); - } - - /** - * @param e - * @return - * @see java.util.List#add(java.lang.Object) - */ - @Override - public boolean add(final ArtifactRest e) { - return delegate.add(e); - } - - /** - * @param o - * @return - * @see java.util.List#remove(java.lang.Object) - */ - @Override - public boolean remove(final Object o) { - return delegate.remove(o); - } - - /** - * @param c - * @return - * @see java.util.List#containsAll(java.util.Collection) - */ - @Override - public boolean containsAll(final Collection c) { - return delegate.containsAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#addAll(java.util.Collection) - */ - @Override - public boolean addAll(final Collection c) { - return delegate.addAll(c); - } - - /** - * @param index - * @param c - * @return - * @see java.util.List#addAll(int, java.util.Collection) - */ - @Override - public boolean addAll(final int index, final Collection c) { - return delegate.addAll(index, c); - } - - /** - * @param c - * @return - * @see java.util.List#removeAll(java.util.Collection) - */ - @Override - public boolean removeAll(final Collection c) { - return delegate.removeAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#retainAll(java.util.Collection) - */ - @Override - public boolean retainAll(final Collection c) { - return delegate.retainAll(c); - } - - /** - * - * @see java.util.List#clear() - */ - @Override - public void clear() { - delegate.clear(); - } - - /** - * @param o - * @return - * @see java.util.List#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object o) { - return delegate.equals(o); - } - - /** - * @return - * @see java.util.List#hashCode() - */ - @Override - public int hashCode() { - return delegate.hashCode(); - } - - /** - * @param index - * @return - * @see java.util.List#get(int) - */ - @Override - public ArtifactRest get(final int index) { - return delegate.get(index); - } - - /** - * @param index - * @param element - * @return - * @see java.util.List#set(int, java.lang.Object) - */ - @Override - public ArtifactRest set(final int index, final ArtifactRest element) { - return delegate.set(index, element); - } - - /** - * @param index - * @param element - * @see java.util.List#add(int, java.lang.Object) - */ - @Override - public void add(final int index, final ArtifactRest element) { - delegate.add(index, element); - } - - /** - * @param index - * @return - * @see java.util.List#remove(int) - */ - @Override - public ArtifactRest remove(final int index) { - return delegate.remove(index); - } - - /** - * @param o - * @return - * @see java.util.List#indexOf(java.lang.Object) - */ - @Override - public int indexOf(final Object o) { - return delegate.indexOf(o); - } - - /** - * @param o - * @return - * @see java.util.List#lastIndexOf(java.lang.Object) - */ - @Override - public int lastIndexOf(final Object o) { - return delegate.lastIndexOf(o); - } - - /** - * @return - * @see java.util.List#listIterator() - */ - @Override - public ListIterator listIterator() { - return delegate.listIterator(); - } - - /** - * @param index - * @return - * @see java.util.List#listIterator(int) - */ - @Override - public ListIterator listIterator(final int index) { - return delegate.listIterator(index); - } - - /** - * @param fromIndex - * @param toIndex - * @return - * @see java.util.List#subList(int, int) - */ - @Override - public List subList(final int fromIndex, final int toIndex) { - return delegate.subList(fromIndex, toIndex); - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/distributionset/DistributionSetPagedList.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/distributionset/DistributionSetPagedList.java deleted file mode 100644 index b7ad1eddb..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/distributionset/DistributionSetPagedList.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model.distributionset; - -import java.util.List; - -import org.eclipse.hawkbit.rest.resource.model.PagedList; - -/** - * Paged list for SoftwareModule. - * - */ -public class DistributionSetPagedList extends PagedList { - - private final List content; - - /** - * @param content - * @param total - */ - public DistributionSetPagedList(final List content, final long total) { - super(content, total); - this.content = content; - } - - /** - * @return the content of the paged list. Never {@code null}. - */ - public List getContent() { - return content; - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/distributionset/DistributionSetsRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/distributionset/DistributionSetsRest.java deleted file mode 100644 index ce7b4d1f1..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/distributionset/DistributionSetsRest.java +++ /dev/null @@ -1,277 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model.distributionset; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.springframework.hateoas.ResourceSupport; - -/** - * List representation of the {@link DistributionSetRest} because Spring MVC - * cannot handle plain lists interfaces as request body. - * - * - * - * - */ -public class DistributionSetsRest extends ResourceSupport implements List { - - private final List delegate = new ArrayList<>(); - - /** - * @return - * @see java.util.List#size() - */ - @Override - public int size() { - return delegate.size(); - } - - /** - * @return - * @see java.util.List#isEmpty() - */ - @Override - public boolean isEmpty() { - return delegate.isEmpty(); - } - - /** - * @param o - * @return - * @see java.util.List#contains(java.lang.Object) - */ - @Override - public boolean contains(final Object o) { - return delegate.contains(o); - } - - /** - * @return - * @see java.util.List#iterator() - */ - @Override - public Iterator iterator() { - return delegate.iterator(); - } - - /** - * @return - * @see java.util.List#toArray() - */ - @Override - public Object[] toArray() { - return delegate.toArray(); - } - - /** - * @param a - * @return - * @see java.util.List#toArray(java.lang.Object[]) - */ - @Override - public T[] toArray(final T[] a) { - return delegate.toArray(a); - } - - /** - * @param e - * @return - * @see java.util.List#add(java.lang.Object) - */ - @Override - public boolean add(final DistributionSetRest e) { - return delegate.add(e); - } - - /** - * @param o - * @return - * @see java.util.List#remove(java.lang.Object) - */ - @Override - public boolean remove(final Object o) { - return delegate.remove(o); - } - - /** - * @param c - * @return - * @see java.util.List#containsAll(java.util.Collection) - */ - @Override - public boolean containsAll(final Collection c) { - return delegate.containsAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#addAll(java.util.Collection) - */ - @Override - public boolean addAll(final Collection c) { - return delegate.addAll(c); - } - - /** - * @param index - * @param c - * @return - * @see java.util.List#addAll(int, java.util.Collection) - */ - @Override - public boolean addAll(final int index, final Collection c) { - return delegate.addAll(index, c); - } - - /** - * @param c - * @return - * @see java.util.List#removeAll(java.util.Collection) - */ - @Override - public boolean removeAll(final Collection c) { - return delegate.removeAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#retainAll(java.util.Collection) - */ - @Override - public boolean retainAll(final Collection c) { - return delegate.retainAll(c); - } - - /** - * - * @see java.util.List#clear() - */ - @Override - public void clear() { - delegate.clear(); - } - - /** - * @param o - * @return - * @see java.util.List#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object o) { - return delegate.equals(o); - } - - /** - * @return - * @see java.util.List#hashCode() - */ - @Override - public int hashCode() { - return delegate.hashCode(); - } - - /** - * @param index - * @return - * @see java.util.List#get(int) - */ - @Override - public DistributionSetRest get(final int index) { - return delegate.get(index); - } - - /** - * @param index - * @param element - * @return - * @see java.util.List#set(int, java.lang.Object) - */ - @Override - public DistributionSetRest set(final int index, final DistributionSetRest element) { - return delegate.set(index, element); - } - - /** - * @param index - * @param element - * @see java.util.List#add(int, java.lang.Object) - */ - @Override - public void add(final int index, final DistributionSetRest element) { - delegate.add(index, element); - } - - /** - * @param index - * @return - * @see java.util.List#remove(int) - */ - @Override - public DistributionSetRest remove(final int index) { - return delegate.remove(index); - } - - /** - * @param o - * @return - * @see java.util.List#indexOf(java.lang.Object) - */ - @Override - public int indexOf(final Object o) { - return delegate.indexOf(o); - } - - /** - * @param o - * @return - * @see java.util.List#lastIndexOf(java.lang.Object) - */ - @Override - public int lastIndexOf(final Object o) { - return delegate.lastIndexOf(o); - } - - /** - * @return - * @see java.util.List#listIterator() - */ - @Override - public ListIterator listIterator() { - return delegate.listIterator(); - } - - /** - * @param index - * @return - * @see java.util.List#listIterator(int) - */ - @Override - public ListIterator listIterator(final int index) { - return delegate.listIterator(index); - } - - /** - * @param fromIndex - * @param toIndex - * @return - * @see java.util.List#subList(int, int) - */ - @Override - public List subList(final int fromIndex, final int toIndex) { - return delegate.subList(fromIndex, toIndex); - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/distributionsettype/DistributionSetTypePagedList.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/distributionsettype/DistributionSetTypePagedList.java deleted file mode 100644 index 57b15f5e8..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/distributionsettype/DistributionSetTypePagedList.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model.distributionsettype; - -import java.util.List; - -import org.eclipse.hawkbit.rest.resource.model.PagedList; - -/** - * Paged list for DistributionSetType. - * - * - */ -public class DistributionSetTypePagedList extends PagedList { - - private final List content; - - /** - * @param content - * @param total - */ - public DistributionSetTypePagedList(final List content, final long total) { - super(content, total); - this.content = content; - } - - /** - * @return the content of the paged list. Never {@code null}. - */ - public List getContent() { - return content; - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/distributionsettype/DistributionSetTypesRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/distributionsettype/DistributionSetTypesRest.java deleted file mode 100644 index f3cd42a85..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/distributionsettype/DistributionSetTypesRest.java +++ /dev/null @@ -1,274 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model.distributionsettype; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.springframework.hateoas.ResourceSupport; - -/** - * List representation of the {@link DistributionSetTypeRest} because Spring MVC - * cannot handle plain lists interfaces as request body. - * - */ -public class DistributionSetTypesRest extends ResourceSupport implements List { - - private final List delegate = new ArrayList<>(); - - /** - * @return - * @see java.util.List#size() - */ - @Override - public int size() { - return delegate.size(); - } - - /** - * @return - * @see java.util.List#isEmpty() - */ - @Override - public boolean isEmpty() { - return delegate.isEmpty(); - } - - /** - * @param o - * @return - * @see java.util.List#contains(java.lang.Object) - */ - @Override - public boolean contains(final Object o) { - return delegate.contains(o); - } - - /** - * @return - * @see java.util.List#iterator() - */ - @Override - public Iterator iterator() { - return delegate.iterator(); - } - - /** - * @return - * @see java.util.List#toArray() - */ - @Override - public Object[] toArray() { - return delegate.toArray(); - } - - /** - * @param a - * @return - * @see java.util.List#toArray(java.lang.Object[]) - */ - @Override - public T[] toArray(final T[] a) { - return delegate.toArray(a); - } - - /** - * @param e - * @return - * @see java.util.List#add(java.lang.Object) - */ - @Override - public boolean add(final DistributionSetTypeRest e) { - return delegate.add(e); - } - - /** - * @param o - * @return - * @see java.util.List#remove(java.lang.Object) - */ - @Override - public boolean remove(final Object o) { - return delegate.remove(o); - } - - /** - * @param c - * @return - * @see java.util.List#containsAll(java.util.Collection) - */ - @Override - public boolean containsAll(final Collection c) { - return delegate.containsAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#addAll(java.util.Collection) - */ - @Override - public boolean addAll(final Collection c) { - return delegate.addAll(c); - } - - /** - * @param index - * @param c - * @return - * @see java.util.List#addAll(int, java.util.Collection) - */ - @Override - public boolean addAll(final int index, final Collection c) { - return delegate.addAll(index, c); - } - - /** - * @param c - * @return - * @see java.util.List#removeAll(java.util.Collection) - */ - @Override - public boolean removeAll(final Collection c) { - return delegate.removeAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#retainAll(java.util.Collection) - */ - @Override - public boolean retainAll(final Collection c) { - return delegate.retainAll(c); - } - - /** - * - * @see java.util.List#clear() - */ - @Override - public void clear() { - delegate.clear(); - } - - /** - * @param o - * @return - * @see java.util.List#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object o) { - return delegate.equals(o); - } - - /** - * @return - * @see java.util.List#hashCode() - */ - @Override - public int hashCode() { - return delegate.hashCode(); - } - - /** - * @param index - * @return - * @see java.util.List#get(int) - */ - @Override - public DistributionSetTypeRest get(final int index) { - return delegate.get(index); - } - - /** - * @param index - * @param element - * @return - * @see java.util.List#set(int, java.lang.Object) - */ - @Override - public DistributionSetTypeRest set(final int index, final DistributionSetTypeRest element) { - return delegate.set(index, element); - } - - /** - * @param index - * @param element - * @see java.util.List#add(int, java.lang.Object) - */ - @Override - public void add(final int index, final DistributionSetTypeRest element) { - delegate.add(index, element); - } - - /** - * @param index - * @return - * @see java.util.List#remove(int) - */ - @Override - public DistributionSetTypeRest remove(final int index) { - return delegate.remove(index); - } - - /** - * @param o - * @return - * @see java.util.List#indexOf(java.lang.Object) - */ - @Override - public int indexOf(final Object o) { - return delegate.indexOf(o); - } - - /** - * @param o - * @return - * @see java.util.List#lastIndexOf(java.lang.Object) - */ - @Override - public int lastIndexOf(final Object o) { - return delegate.lastIndexOf(o); - } - - /** - * @return - * @see java.util.List#listIterator() - */ - @Override - public ListIterator listIterator() { - return delegate.listIterator(); - } - - /** - * @param index - * @return - * @see java.util.List#listIterator(int) - */ - @Override - public ListIterator listIterator(final int index) { - return delegate.listIterator(index); - } - - /** - * @param fromIndex - * @param toIndex - * @return - * @see java.util.List#subList(int, int) - */ - @Override - public List subList(final int fromIndex, final int toIndex) { - return delegate.subList(fromIndex, toIndex); - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/rollout/RolloutPagedList.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/rollout/RolloutPagedList.java deleted file mode 100644 index ea1544991..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/rollout/RolloutPagedList.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model.rollout; - -import java.util.List; - -import org.eclipse.hawkbit.rest.resource.model.PagedList; - -/** - * Paged list for Rollout. - * - * - */ -public class RolloutPagedList extends PagedList { - - private final List content; - - public RolloutPagedList(final List content, final long total) { - super(content, total); - this.content = content; - } - - /** - * @return the content of the paged list. Never {@code null}. - */ - public List getContent() { - return content; - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/rolloutgroup/RolloutGroupPagedList.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/rolloutgroup/RolloutGroupPagedList.java deleted file mode 100644 index a341ac6ba..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/rolloutgroup/RolloutGroupPagedList.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model.rolloutgroup; - -import java.util.List; - -import org.eclipse.hawkbit.rest.resource.model.PagedList; - -/** - * Paged list for Rollout. - * - */ -public class RolloutGroupPagedList extends PagedList { - - private final List content; - - public RolloutGroupPagedList(final List content, final long total) { - super(content, total); - this.content = content; - } - - /** - * @return the content of the paged list. Never {@code null}. - */ - public List getContent() { - return content; - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/softwaremodule/SoftwareModulePagedList.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/softwaremodule/SoftwareModulePagedList.java deleted file mode 100644 index a49f41dc9..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/softwaremodule/SoftwareModulePagedList.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model.softwaremodule; - -import java.util.List; - -import org.eclipse.hawkbit.rest.resource.model.PagedList; - -/** - * Paged list for SoftwareModule. - * - */ -public class SoftwareModulePagedList extends PagedList { - - private final List content; - - /** - * @param content - * @param total - */ - public SoftwareModulePagedList(final List content, final long total) { - super(content, total); - this.content = content; - } - - /** - * @return the content of the paged list. Never {@code null}. - */ - public List getContent() { - return content; - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/softwaremodule/SoftwareModulesRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/softwaremodule/SoftwareModulesRest.java deleted file mode 100644 index b40c98d36..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/softwaremodule/SoftwareModulesRest.java +++ /dev/null @@ -1,277 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model.softwaremodule; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.springframework.hateoas.ResourceSupport; - -/** - * List representation of the {@link SoftwareModuleRest} because Spring MVC - * cannot handle plain lists interfaces as request body. - * - * - * - * - */ -public class SoftwareModulesRest extends ResourceSupport implements List { - - private final List delegate = new ArrayList<>(); - - /** - * @return - * @see java.util.List#size() - */ - @Override - public int size() { - return delegate.size(); - } - - /** - * @return - * @see java.util.List#isEmpty() - */ - @Override - public boolean isEmpty() { - return delegate.isEmpty(); - } - - /** - * @param o - * @return - * @see java.util.List#contains(java.lang.Object) - */ - @Override - public boolean contains(final Object o) { - return delegate.contains(o); - } - - /** - * @return - * @see java.util.List#iterator() - */ - @Override - public Iterator iterator() { - return delegate.iterator(); - } - - /** - * @return - * @see java.util.List#toArray() - */ - @Override - public Object[] toArray() { - return delegate.toArray(); - } - - /** - * @param a - * @return - * @see java.util.List#toArray(java.lang.Object[]) - */ - @Override - public T[] toArray(final T[] a) { - return delegate.toArray(a); - } - - /** - * @param e - * @return - * @see java.util.List#add(java.lang.Object) - */ - @Override - public boolean add(final SoftwareModuleRest e) { - return delegate.add(e); - } - - /** - * @param o - * @return - * @see java.util.List#remove(java.lang.Object) - */ - @Override - public boolean remove(final Object o) { - return delegate.remove(o); - } - - /** - * @param c - * @return - * @see java.util.List#containsAll(java.util.Collection) - */ - @Override - public boolean containsAll(final Collection c) { - return delegate.containsAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#addAll(java.util.Collection) - */ - @Override - public boolean addAll(final Collection c) { - return delegate.addAll(c); - } - - /** - * @param index - * @param c - * @return - * @see java.util.List#addAll(int, java.util.Collection) - */ - @Override - public boolean addAll(final int index, final Collection c) { - return delegate.addAll(index, c); - } - - /** - * @param c - * @return - * @see java.util.List#removeAll(java.util.Collection) - */ - @Override - public boolean removeAll(final Collection c) { - return delegate.removeAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#retainAll(java.util.Collection) - */ - @Override - public boolean retainAll(final Collection c) { - return delegate.retainAll(c); - } - - /** - * - * @see java.util.List#clear() - */ - @Override - public void clear() { - delegate.clear(); - } - - /** - * @param o - * @return - * @see java.util.List#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object o) { - return delegate.equals(o); - } - - /** - * @return - * @see java.util.List#hashCode() - */ - @Override - public int hashCode() { - return delegate.hashCode(); - } - - /** - * @param index - * @return - * @see java.util.List#get(int) - */ - @Override - public SoftwareModuleRest get(final int index) { - return delegate.get(index); - } - - /** - * @param index - * @param element - * @return - * @see java.util.List#set(int, java.lang.Object) - */ - @Override - public SoftwareModuleRest set(final int index, final SoftwareModuleRest element) { - return delegate.set(index, element); - } - - /** - * @param index - * @param element - * @see java.util.List#add(int, java.lang.Object) - */ - @Override - public void add(final int index, final SoftwareModuleRest element) { - delegate.add(index, element); - } - - /** - * @param index - * @return - * @see java.util.List#remove(int) - */ - @Override - public SoftwareModuleRest remove(final int index) { - return delegate.remove(index); - } - - /** - * @param o - * @return - * @see java.util.List#indexOf(java.lang.Object) - */ - @Override - public int indexOf(final Object o) { - return delegate.indexOf(o); - } - - /** - * @param o - * @return - * @see java.util.List#lastIndexOf(java.lang.Object) - */ - @Override - public int lastIndexOf(final Object o) { - return delegate.lastIndexOf(o); - } - - /** - * @return - * @see java.util.List#listIterator() - */ - @Override - public ListIterator listIterator() { - return delegate.listIterator(); - } - - /** - * @param index - * @return - * @see java.util.List#listIterator(int) - */ - @Override - public ListIterator listIterator(final int index) { - return delegate.listIterator(index); - } - - /** - * @param fromIndex - * @param toIndex - * @return - * @see java.util.List#subList(int, int) - */ - @Override - public List subList(final int fromIndex, final int toIndex) { - return delegate.subList(fromIndex, toIndex); - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/softwaremoduletype/SoftwareModuleTypePagedList.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/softwaremoduletype/SoftwareModuleTypePagedList.java deleted file mode 100644 index 7e85cdca9..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/softwaremoduletype/SoftwareModuleTypePagedList.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model.softwaremoduletype; - -import java.util.List; - -import org.eclipse.hawkbit.rest.resource.model.PagedList; - -/** - * Paged list for SoftwareModuleType. - * - */ -public class SoftwareModuleTypePagedList extends PagedList { - - private final List content; - - /** - * @param content - * @param total - */ - public SoftwareModuleTypePagedList(final List content, final long total) { - super(content, total); - this.content = content; - } - - /** - * @return the content of the paged list. Never {@code null}. - */ - public List getContent() { - return content; - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/softwaremoduletype/SoftwareModuleTypeRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/softwaremoduletype/SoftwareModuleTypeRest.java index 6478eb790..ed05c1ee4 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/softwaremoduletype/SoftwareModuleTypeRest.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/softwaremoduletype/SoftwareModuleTypeRest.java @@ -19,9 +19,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; * A json annotated rest model for SoftwareModuleType to RESTful API * representation. * - * - * - * */ @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/softwaremoduletype/SoftwareModuleTypesRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/softwaremoduletype/SoftwareModuleTypesRest.java deleted file mode 100644 index 91f440187..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/softwaremoduletype/SoftwareModuleTypesRest.java +++ /dev/null @@ -1,274 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model.softwaremoduletype; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.springframework.hateoas.ResourceSupport; - -/** - * List representation of the {@link SoftwareModuleTypeRest} because Spring MVC - * cannot handle plain lists interfaces as request body. - * - */ -public class SoftwareModuleTypesRest extends ResourceSupport implements List { - - private final List delegate = new ArrayList<>(); - - /** - * @return - * @see java.util.List#size() - */ - @Override - public int size() { - return delegate.size(); - } - - /** - * @return - * @see java.util.List#isEmpty() - */ - @Override - public boolean isEmpty() { - return delegate.isEmpty(); - } - - /** - * @param o - * @return - * @see java.util.List#contains(java.lang.Object) - */ - @Override - public boolean contains(final Object o) { - return delegate.contains(o); - } - - /** - * @return - * @see java.util.List#iterator() - */ - @Override - public Iterator iterator() { - return delegate.iterator(); - } - - /** - * @return - * @see java.util.List#toArray() - */ - @Override - public Object[] toArray() { - return delegate.toArray(); - } - - /** - * @param a - * @return - * @see java.util.List#toArray(java.lang.Object[]) - */ - @Override - public T[] toArray(final T[] a) { - return delegate.toArray(a); - } - - /** - * @param e - * @return - * @see java.util.List#add(java.lang.Object) - */ - @Override - public boolean add(final SoftwareModuleTypeRest e) { - return delegate.add(e); - } - - /** - * @param o - * @return - * @see java.util.List#remove(java.lang.Object) - */ - @Override - public boolean remove(final Object o) { - return delegate.remove(o); - } - - /** - * @param c - * @return - * @see java.util.List#containsAll(java.util.Collection) - */ - @Override - public boolean containsAll(final Collection c) { - return delegate.containsAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#addAll(java.util.Collection) - */ - @Override - public boolean addAll(final Collection c) { - return delegate.addAll(c); - } - - /** - * @param index - * @param c - * @return - * @see java.util.List#addAll(int, java.util.Collection) - */ - @Override - public boolean addAll(final int index, final Collection c) { - return delegate.addAll(index, c); - } - - /** - * @param c - * @return - * @see java.util.List#removeAll(java.util.Collection) - */ - @Override - public boolean removeAll(final Collection c) { - return delegate.removeAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#retainAll(java.util.Collection) - */ - @Override - public boolean retainAll(final Collection c) { - return delegate.retainAll(c); - } - - /** - * - * @see java.util.List#clear() - */ - @Override - public void clear() { - delegate.clear(); - } - - /** - * @param o - * @return - * @see java.util.List#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object o) { - return delegate.equals(o); - } - - /** - * @return - * @see java.util.List#hashCode() - */ - @Override - public int hashCode() { - return delegate.hashCode(); - } - - /** - * @param index - * @return - * @see java.util.List#get(int) - */ - @Override - public SoftwareModuleTypeRest get(final int index) { - return delegate.get(index); - } - - /** - * @param index - * @param element - * @return - * @see java.util.List#set(int, java.lang.Object) - */ - @Override - public SoftwareModuleTypeRest set(final int index, final SoftwareModuleTypeRest element) { - return delegate.set(index, element); - } - - /** - * @param index - * @param element - * @see java.util.List#add(int, java.lang.Object) - */ - @Override - public void add(final int index, final SoftwareModuleTypeRest element) { - delegate.add(index, element); - } - - /** - * @param index - * @return - * @see java.util.List#remove(int) - */ - @Override - public SoftwareModuleTypeRest remove(final int index) { - return delegate.remove(index); - } - - /** - * @param o - * @return - * @see java.util.List#indexOf(java.lang.Object) - */ - @Override - public int indexOf(final Object o) { - return delegate.indexOf(o); - } - - /** - * @param o - * @return - * @see java.util.List#lastIndexOf(java.lang.Object) - */ - @Override - public int lastIndexOf(final Object o) { - return delegate.lastIndexOf(o); - } - - /** - * @return - * @see java.util.List#listIterator() - */ - @Override - public ListIterator listIterator() { - return delegate.listIterator(); - } - - /** - * @param index - * @return - * @see java.util.List#listIterator(int) - */ - @Override - public ListIterator listIterator(final int index) { - return delegate.listIterator(index); - } - - /** - * @param fromIndex - * @param toIndex - * @return - * @see java.util.List#subList(int, int) - */ - @Override - public List subList(final int fromIndex, final int toIndex) { - return delegate.subList(fromIndex, toIndex); - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/tag/DistributionSetTagAssigmentResultRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/tag/DistributionSetTagAssigmentResultRest.java index 1d0b51e72..2078fe891 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/tag/DistributionSetTagAssigmentResultRest.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/tag/DistributionSetTagAssigmentResultRest.java @@ -8,7 +8,9 @@ */ package org.eclipse.hawkbit.rest.resource.model.tag; -import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest; +import java.util.List; + +import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRest; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; @@ -25,24 +27,24 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class DistributionSetTagAssigmentResultRest { @JsonProperty - private DistributionSetsRest assignedDistributionSets; + private List assignedDistributionSets; @JsonProperty - private DistributionSetsRest unassignedDistributionSets; + private List unassignedDistributionSets; - public DistributionSetsRest getAssignedDistributionSets() { + public List getAssignedDistributionSets() { return assignedDistributionSets; } - public DistributionSetsRest getUnassignedDistributionSets() { + public List getUnassignedDistributionSets() { return unassignedDistributionSets; } - public void setAssignedDistributionSets(final DistributionSetsRest assignedDistributionSets) { + public void setAssignedDistributionSets(final List assignedDistributionSets) { this.assignedDistributionSets = assignedDistributionSets; } - public void setUnassignedDistributionSets(final DistributionSetsRest unassignedDistributionSets) { + public void setUnassignedDistributionSets(final List unassignedDistributionSets) { this.unassignedDistributionSets = unassignedDistributionSets; } diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/tag/TagPagedList.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/tag/TagPagedList.java deleted file mode 100644 index d549a9efa..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/tag/TagPagedList.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model.tag; - -import java.util.List; - -import org.eclipse.hawkbit.rest.resource.model.PagedList; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Paged list for tags. - * - */ -public class TagPagedList extends PagedList { - - private final List content; - - /** - * @param content - * @param total - */ - @JsonCreator - public TagPagedList(@JsonProperty("content") final List content, @JsonProperty("total") final long total) { - super(content, total); - this.content = content; - } - - /** - * @return the content of the paged list. Never {@code null}. - */ - public List getContent() { - return content; - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/tag/TagsRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/tag/TagsRest.java deleted file mode 100644 index df0638358..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/tag/TagsRest.java +++ /dev/null @@ -1,275 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.rest.resource.model.tag; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.springframework.hateoas.ResourceSupport; - -/** - * List representation of the {@link TagRest} because Spring MVC cannot handle - * plain lists interfaces as request body. - * - * - */ -public class TagsRest extends ResourceSupport implements List { - - private final List delegate = new ArrayList<>(); - - /** - * @return - * @see java.util.List#size() - */ - @Override - public int size() { - return delegate.size(); - } - - /** - * @return - * @see java.util.List#isEmpty() - */ - @Override - public boolean isEmpty() { - return delegate.isEmpty(); - } - - /** - * @param o - * @return - * @see java.util.List#contains(java.lang.Object) - */ - @Override - public boolean contains(final Object o) { - return delegate.contains(o); - } - - /** - * @return - * @see java.util.List#iterator() - */ - @Override - public Iterator iterator() { - return delegate.iterator(); - } - - /** - * @return - * @see java.util.List#toArray() - */ - @Override - public Object[] toArray() { - return delegate.toArray(); - } - - /** - * @param a - * @return - * @see java.util.List#toArray(java.lang.Object[]) - */ - @Override - public T[] toArray(final T[] a) { - return delegate.toArray(a); - } - - /** - * @param e - * @return - * @see java.util.List#add(java.lang.Object) - */ - @Override - public boolean add(final TagRest e) { - return delegate.add(e); - } - - /** - * @param o - * @return - * @see java.util.List#remove(java.lang.Object) - */ - @Override - public boolean remove(final Object o) { - return delegate.remove(o); - } - - /** - * @param c - * @return - * @see java.util.List#containsAll(java.util.Collection) - */ - @Override - public boolean containsAll(final Collection c) { - return delegate.containsAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#addAll(java.util.Collection) - */ - @Override - public boolean addAll(final Collection c) { - return delegate.addAll(c); - } - - /** - * @param index - * @param c - * @return - * @see java.util.List#addAll(int, java.util.Collection) - */ - @Override - public boolean addAll(final int index, final Collection c) { - return delegate.addAll(index, c); - } - - /** - * @param c - * @return - * @see java.util.List#removeAll(java.util.Collection) - */ - @Override - public boolean removeAll(final Collection c) { - return delegate.removeAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#retainAll(java.util.Collection) - */ - @Override - public boolean retainAll(final Collection c) { - return delegate.retainAll(c); - } - - /** - * - * @see java.util.List#clear() - */ - @Override - public void clear() { - delegate.clear(); - } - - /** - * @param o - * @return - * @see java.util.List#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object o) { - return delegate.equals(o); - } - - /** - * @return - * @see java.util.List#hashCode() - */ - @Override - public int hashCode() { - return delegate.hashCode(); - } - - /** - * @param index - * @return - * @see java.util.List#get(int) - */ - @Override - public TagRest get(final int index) { - return delegate.get(index); - } - - /** - * @param index - * @param element - * @return - * @see java.util.List#set(int, java.lang.Object) - */ - @Override - public TagRest set(final int index, final TagRest element) { - return delegate.set(index, element); - } - - /** - * @param index - * @param element - * @see java.util.List#add(int, java.lang.Object) - */ - @Override - public void add(final int index, final TagRest element) { - delegate.add(index, element); - } - - /** - * @param index - * @return - * @see java.util.List#remove(int) - */ - @Override - public TagRest remove(final int index) { - return delegate.remove(index); - } - - /** - * @param o - * @return - * @see java.util.List#indexOf(java.lang.Object) - */ - @Override - public int indexOf(final Object o) { - return delegate.indexOf(o); - } - - /** - * @param o - * @return - * @see java.util.List#lastIndexOf(java.lang.Object) - */ - @Override - public int lastIndexOf(final Object o) { - return delegate.lastIndexOf(o); - } - - /** - * @return - * @see java.util.List#listIterator() - */ - @Override - public ListIterator listIterator() { - return delegate.listIterator(); - } - - /** - * @param index - * @return - * @see java.util.List#listIterator(int) - */ - @Override - public ListIterator listIterator(final int index) { - return delegate.listIterator(index); - } - - /** - * @param fromIndex - * @param toIndex - * @return - * @see java.util.List#subList(int, int) - */ - @Override - public List subList(final int fromIndex, final int toIndex) { - return delegate.subList(fromIndex, toIndex); - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/tag/TargetTagAssigmentResultRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/tag/TargetTagAssigmentResultRest.java index 928a72460..30d47cc90 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/tag/TargetTagAssigmentResultRest.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/tag/TargetTagAssigmentResultRest.java @@ -8,7 +8,9 @@ */ package org.eclipse.hawkbit.rest.resource.model.tag; -import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest; +import java.util.List; + +import org.eclipse.hawkbit.rest.resource.model.target.TargetRest; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; @@ -25,24 +27,24 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class TargetTagAssigmentResultRest { @JsonProperty - private TargetsRest assignedTargets; + private List assignedTargets; @JsonProperty - private TargetsRest unassignedTargets; + private List unassignedTargets; - public void setAssignedTargets(final TargetsRest assignedTargets) { + public void setAssignedTargets(final List assignedTargets) { this.assignedTargets = assignedTargets; } - public TargetsRest getAssignedTargets() { + public List getAssignedTargets() { return assignedTargets; } - public void setUnassignedTargets(final TargetsRest unassignedTargets) { + public void setUnassignedTargets(final List unassignedTargets) { this.unassignedTargets = unassignedTargets; } - public TargetsRest getUnassignedTargets() { + public List getUnassignedTargets() { return unassignedTargets; } diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/target/TargetPagedList.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/target/TargetPagedList.java deleted file mode 100644 index d7bb5ccca..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/target/TargetPagedList.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright (c) 2011-2015 Bosch Software Innovations GmbH, Germany. All rights reserved. - */ -package org.eclipse.hawkbit.rest.resource.model.target; - -import java.util.List; - -import org.eclipse.hawkbit.rest.resource.model.PagedList; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Paged list for targets. - * - */ -public class TargetPagedList extends PagedList { - - private final List content; - - /** - * @param content - * @param total - */ - @JsonCreator - public TargetPagedList(@JsonProperty("content") final List content, - @JsonProperty("total") final long total) { - super(content, total); - this.content = content; - } - - /** - * @return the content of the paged list. Never {@code null}. - */ - public List getContent() { - return content; - } - -} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/target/TargetsRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/target/TargetsRest.java deleted file mode 100644 index 6344ee93b..000000000 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/target/TargetsRest.java +++ /dev/null @@ -1,269 +0,0 @@ -/** - * Copyright (c) 2011-2015 Bosch Software Innovations GmbH, Germany. All rights reserved. - */ -package org.eclipse.hawkbit.rest.resource.model.target; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.springframework.hateoas.ResourceSupport; - -/** - * A list representation of the {@link TargetRest} because Spring MVC cannot - * handle plain lists interfaces as request body. - * - */ -public class TargetsRest extends ResourceSupport implements List { - - private final List delegate = new ArrayList<>(); - - /** - * @return - * @see java.util.List#size() - */ - @Override - public int size() { - return delegate.size(); - } - - /** - * @return - * @see java.util.List#isEmpty() - */ - @Override - public boolean isEmpty() { - return delegate.isEmpty(); - } - - /** - * @param o - * @return - * @see java.util.List#contains(java.lang.Object) - */ - @Override - public boolean contains(final Object o) { - return delegate.contains(o); - } - - /** - * @return - * @see java.util.List#iterator() - */ - @Override - public Iterator iterator() { - return delegate.iterator(); - } - - /** - * @return - * @see java.util.List#toArray() - */ - @Override - public Object[] toArray() { - return delegate.toArray(); - } - - /** - * @param a - * @return - * @see java.util.List#toArray(java.lang.Object[]) - */ - @Override - public T[] toArray(final T[] a) { - return delegate.toArray(a); - } - - /** - * @param e - * @return - * @see java.util.List#add(java.lang.Object) - */ - @Override - public boolean add(final TargetRest e) { - return delegate.add(e); - } - - /** - * @param o - * @return - * @see java.util.List#remove(java.lang.Object) - */ - @Override - public boolean remove(final Object o) { - return delegate.remove(o); - } - - /** - * @param c - * @return - * @see java.util.List#containsAll(java.util.Collection) - */ - @Override - public boolean containsAll(final Collection c) { - return delegate.containsAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#addAll(java.util.Collection) - */ - @Override - public boolean addAll(final Collection c) { - return delegate.addAll(c); - } - - /** - * @param index - * @param c - * @return - * @see java.util.List#addAll(int, java.util.Collection) - */ - @Override - public boolean addAll(final int index, final Collection c) { - return delegate.addAll(index, c); - } - - /** - * @param c - * @return - * @see java.util.List#removeAll(java.util.Collection) - */ - @Override - public boolean removeAll(final Collection c) { - return delegate.removeAll(c); - } - - /** - * @param c - * @return - * @see java.util.List#retainAll(java.util.Collection) - */ - @Override - public boolean retainAll(final Collection c) { - return delegate.retainAll(c); - } - - /** - * - * @see java.util.List#clear() - */ - @Override - public void clear() { - delegate.clear(); - } - - /** - * @param o - * @return - * @see java.util.List#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object o) { - return delegate.equals(o); - } - - /** - * @return - * @see java.util.List#hashCode() - */ - @Override - public int hashCode() { - return delegate.hashCode(); - } - - /** - * @param index - * @return - * @see java.util.List#get(int) - */ - @Override - public TargetRest get(final int index) { - return delegate.get(index); - } - - /** - * @param index - * @param element - * @return - * @see java.util.List#set(int, java.lang.Object) - */ - @Override - public TargetRest set(final int index, final TargetRest element) { - return delegate.set(index, element); - } - - /** - * @param index - * @param element - * @see java.util.List#add(int, java.lang.Object) - */ - @Override - public void add(final int index, final TargetRest element) { - delegate.add(index, element); - } - - /** - * @param index - * @return - * @see java.util.List#remove(int) - */ - @Override - public TargetRest remove(final int index) { - return delegate.remove(index); - } - - /** - * @param o - * @return - * @see java.util.List#indexOf(java.lang.Object) - */ - @Override - public int indexOf(final Object o) { - return delegate.indexOf(o); - } - - /** - * @param o - * @return - * @see java.util.List#lastIndexOf(java.lang.Object) - */ - @Override - public int lastIndexOf(final Object o) { - return delegate.lastIndexOf(o); - } - - /** - * @return - * @see java.util.List#listIterator() - */ - @Override - public ListIterator listIterator() { - return delegate.listIterator(); - } - - /** - * @param index - * @return - * @see java.util.List#listIterator(int) - */ - @Override - public ListIterator listIterator(final int index) { - return delegate.listIterator(index); - } - - /** - * @param fromIndex - * @param toIndex - * @return - * @see java.util.List#subList(int, int) - */ - @Override - public List subList(final int fromIndex, final int toIndex) { - return delegate.subList(fromIndex, toIndex); - } - -} diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java index 358448dfd..f704acd5e 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java @@ -65,10 +65,6 @@ import org.springframework.web.bind.annotation.RestController; * * Transactional (read-write) as all queries at least update the last poll time. * - * - * - * - * */ @RestController @RequestMapping(ControllerConstants.BASE_V1_REQUEST_MAPPING) diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetMapper.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetMapper.java index 9ae133dd5..8051146a1 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetMapper.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetMapper.java @@ -27,7 +27,6 @@ import org.eclipse.hawkbit.rest.resource.api.DistributionSetTypeRestApi; import org.eclipse.hawkbit.rest.resource.model.MetadataRest; import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyPost; import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRest; -import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest; import org.eclipse.hawkbit.rest.resource.model.distributionset.TargetAssignmentResponseBody; /** @@ -193,8 +192,8 @@ public final class DistributionSetMapper { return result; } - static DistributionSetsRest toResponseDistributionSets(final Iterable sets) { - final DistributionSetsRest response = new DistributionSetsRest(); + static List toResponseDistributionSets(final Iterable sets) { + final List response = new ArrayList<>(); if (sets != null) { for (final DistributionSet set : sets) { diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java index a4c71378d..27231308b 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java @@ -33,17 +33,15 @@ import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.rest.resource.api.DistributionSetRestApi; import org.eclipse.hawkbit.rest.resource.helper.RestResourceConversionHelper; import org.eclipse.hawkbit.rest.resource.model.MetadataRest; -import org.eclipse.hawkbit.rest.resource.model.MetadataRestPageList; -import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetPagedList; +import org.eclipse.hawkbit.rest.resource.model.PagedList; import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyPost; import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyPut; import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRest; -import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest; import org.eclipse.hawkbit.rest.resource.model.distributionset.TargetAssignmentRequestBody; import org.eclipse.hawkbit.rest.resource.model.distributionset.TargetAssignmentResponseBody; import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleAssigmentRest; -import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModulePagedList; -import org.eclipse.hawkbit.rest.resource.model.target.TargetPagedList; +import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleRest; +import org.eclipse.hawkbit.rest.resource.model.target.TargetRest; import org.eclipse.hawkbit.tenancy.TenantAware; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -81,7 +79,7 @@ public class DistributionSetResource implements DistributionSetRestApi { private DistributionSetManagement distributionSetManagement; @Override - public ResponseEntity getDistributionSets(final int pagingOffsetParam, + public ResponseEntity> getDistributionSets(final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) { final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); @@ -98,7 +96,7 @@ public class DistributionSetResource implements DistributionSetRestApi { } final List rest = DistributionSetMapper.toResponseFromDsList(findDsPage.getContent()); - return new ResponseEntity<>(new DistributionSetPagedList(rest, findDsPage.getTotalElements()), HttpStatus.OK); + return new ResponseEntity<>(new PagedList<>(rest, findDsPage.getTotalElements()), HttpStatus.OK); } @Override @@ -109,7 +107,7 @@ public class DistributionSetResource implements DistributionSetRestApi { } @Override - public ResponseEntity createDistributionSets( + public ResponseEntity> createDistributionSets( final List sets) { LOG.debug("creating {} distribution sets", sets.size()); @@ -155,8 +153,8 @@ public class DistributionSetResource implements DistributionSetRestApi { } @Override - public ResponseEntity getAssignedTargets(final Long distributionSetId, final int pagingOffsetParam, - final int pagingLimitParam, final String sortParam, final String rsqlParam) { + public ResponseEntity> getAssignedTargets(final Long distributionSetId, + final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) { // check if distribution set exists otherwise throw exception // immediately @@ -175,12 +173,12 @@ public class DistributionSetResource implements DistributionSetRestApi { targetsAssignedDS = this.targetManagement.findTargetByAssignedDistributionSet(distributionSetId, pageable); } - return new ResponseEntity<>(new TargetPagedList(TargetMapper.toResponse(targetsAssignedDS.getContent()), + return new ResponseEntity<>(new PagedList<>(TargetMapper.toResponse(targetsAssignedDS.getContent()), targetsAssignedDS.getTotalElements()), HttpStatus.OK); } @Override - public ResponseEntity getInstalledTargets(final Long distributionSetId, + public ResponseEntity> getInstalledTargets(final Long distributionSetId, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) { // check if distribution set exists otherwise throw exception // immediately @@ -200,7 +198,7 @@ public class DistributionSetResource implements DistributionSetRestApi { pageable); } - return new ResponseEntity<>(new TargetPagedList(TargetMapper.toResponse(targetsInstalledDS.getContent()), + return new ResponseEntity<>(new PagedList(TargetMapper.toResponse(targetsInstalledDS.getContent()), targetsInstalledDS.getTotalElements()), HttpStatus.OK); } @@ -219,8 +217,8 @@ public class DistributionSetResource implements DistributionSetRestApi { } @Override - public ResponseEntity getMetadata(final Long distributionSetId, final int pagingOffsetParam, - final int pagingLimitParam, final String sortParam, final String rsqlParam) { + public ResponseEntity> getMetadata(final Long distributionSetId, + final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) { // check if distribution set exists otherwise throw exception // immediately @@ -242,7 +240,7 @@ public class DistributionSetResource implements DistributionSetRestApi { } return new ResponseEntity<>( - new MetadataRestPageList(DistributionSetMapper.toResponseDsMetadata(metaDataPage.getContent()), + new PagedList<>(DistributionSetMapper.toResponseDsMetadata(metaDataPage.getContent()), metaDataPage.getTotalElements()), HttpStatus.OK); @@ -323,7 +321,7 @@ public class DistributionSetResource implements DistributionSetRestApi { } @Override - public ResponseEntity getAssignedSoftwareModules(final Long distributionSetId, + public ResponseEntity> getAssignedSoftwareModules(final Long distributionSetId, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) { // check if distribution set exists otherwise throw exception // immediately @@ -334,10 +332,8 @@ public class DistributionSetResource implements DistributionSetRestApi { final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); final Page softwaremodules = this.softwareManagement.findSoftwareModuleByAssignedTo(pageable, foundDs); - return new ResponseEntity<>( - new SoftwareModulePagedList(SoftwareModuleMapper.toResponse(softwaremodules.getContent()), - softwaremodules.getTotalElements()), - HttpStatus.OK); + return new ResponseEntity<>(new PagedList<>(SoftwareModuleMapper.toResponse(softwaremodules.getContent()), + softwaremodules.getTotalElements()), HttpStatus.OK); } private DistributionSet findDistributionSetWithExceptionIfNotFound(final Long distributionSetId) { diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTagResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTagResource.java index c395863ab..01a446947 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTagResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTagResource.java @@ -17,16 +17,15 @@ import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; -import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult; +import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.rest.resource.api.DistributionSetTagRestApi; -import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest; +import org.eclipse.hawkbit.rest.resource.model.PagedList; +import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRest; import org.eclipse.hawkbit.rest.resource.model.tag.AssignedDistributionSetRequestBody; import org.eclipse.hawkbit.rest.resource.model.tag.DistributionSetTagAssigmentResultRest; -import org.eclipse.hawkbit.rest.resource.model.tag.TagPagedList; import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut; import org.eclipse.hawkbit.rest.resource.model.tag.TagRest; -import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -53,8 +52,8 @@ public class DistributionSetTagResource implements DistributionSetTagRestApi { private DistributionSetManagement distributionSetManagement; @Override - public ResponseEntity getDistributionSetTags(final int pagingOffsetParam, final int pagingLimitParam, - final String sortParam, final String rsqlParam) { + public ResponseEntity> getDistributionSetTags(final int pagingOffsetParam, + final int pagingLimitParam, final String sortParam, final String rsqlParam) { final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); @@ -76,7 +75,7 @@ public class DistributionSetTagResource implements DistributionSetTagRestApi { } final List rest = TagMapper.toResponseDistributionSetTag(findTargetsAll.getContent()); - return new ResponseEntity<>(new TagPagedList(rest, countTargetsAll), HttpStatus.OK); + return new ResponseEntity<>(new PagedList<>(rest, countTargetsAll), HttpStatus.OK); } @Override @@ -86,7 +85,7 @@ public class DistributionSetTagResource implements DistributionSetTagRestApi { } @Override - public ResponseEntity createDistributionSetTags(final List tags) { + public ResponseEntity> createDistributionSetTags(final List tags) { LOG.debug("creating {} ds tags", tags.size()); final List createdTags = this.tagManagement @@ -121,7 +120,7 @@ public class DistributionSetTagResource implements DistributionSetTagRestApi { } @Override - public ResponseEntity getAssignedDistributionSets(final Long distributionsetTagId) { + public ResponseEntity> getAssignedDistributionSets(final Long distributionsetTagId) { final DistributionSetTag tag = findDistributionTagById(distributionsetTagId); return new ResponseEntity<>( DistributionSetMapper.toResponseDistributionSets(tag.getAssignedToDistributionSet()), HttpStatus.OK); @@ -135,7 +134,7 @@ public class DistributionSetTagResource implements DistributionSetTagRestApi { final DistributionSetTag tag = findDistributionTagById(distributionsetTagId); - final DistributionSetTagAssigmentResult assigmentResult = this.distributionSetManagement + final DistributionSetTagAssignmentResult assigmentResult = this.distributionSetManagement .toggleTagAssignment(findDistributionSetIds(assignedDSRequestBodies), tag.getName()); final DistributionSetTagAssigmentResultRest tagAssigmentResultRest = new DistributionSetTagAssigmentResultRest(); @@ -151,7 +150,7 @@ public class DistributionSetTagResource implements DistributionSetTagRestApi { } @Override - public ResponseEntity assignDistributionSets(final Long distributionsetTagId, + public ResponseEntity> assignDistributionSets(final Long distributionsetTagId, final List assignedDSRequestBodies) { LOG.debug("Assign DistributionSet {} for ds tag {}", assignedDSRequestBodies.size(), distributionsetTagId); final DistributionSetTag tag = findDistributionTagById(distributionsetTagId); diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeMapper.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeMapper.java index b32302705..409caf01d 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeMapper.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeMapper.java @@ -21,15 +21,11 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.rest.resource.api.DistributionSetTypeRestApi; import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRequestBodyPost; import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRest; -import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypesRest; /** * A mapper which maps repository model to RESTful model representation and * back. * - * - * - * */ final class DistributionSetTypeMapper { @@ -63,7 +59,7 @@ final class DistributionSetTypeMapper { } return smType; - }).forEach(softmType -> result.addMandatoryModuleType(softmType)); + }).forEach(result::addMandatoryModuleType); // Add optional smsRest.getOptionalmodules().stream().map(opt -> { @@ -74,13 +70,13 @@ final class DistributionSetTypeMapper { } return smType; - }).forEach(softmType -> result.addOptionalModuleType(softmType)); + }).forEach(result::addOptionalModuleType); return result; } - static DistributionSetTypesRest toTypesResponse(final List types) { - final DistributionSetTypesRest response = new DistributionSetTypesRest(); + static List toTypesResponse(final List types) { + final List response = new ArrayList<>(); for (final DistributionSetType dsType : types) { response.add(toResponse(dsType)); } diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java index a5c8544fb..f7346a6ff 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java @@ -21,13 +21,11 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.rest.resource.api.DistributionSetTypeRestApi; import org.eclipse.hawkbit.rest.resource.model.IdRest; -import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypePagedList; +import org.eclipse.hawkbit.rest.resource.model.PagedList; import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRequestBodyPost; import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRequestBodyPut; import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRest; -import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypesRest; import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRest; -import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypesRest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -56,7 +54,7 @@ public class DistributionSetTypeResource implements DistributionSetTypeRestApi { private DistributionSetManagement distributionSetManagement; @Override - public ResponseEntity getDistributionSetTypes( + public ResponseEntity> getDistributionSetTypes( @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, @@ -81,7 +79,7 @@ public class DistributionSetTypeResource implements DistributionSetTypeRestApi { final List rest = DistributionSetTypeMapper .toListResponse(findModuleTypessAll.getContent()); - return new ResponseEntity<>(new DistributionSetTypePagedList(rest, countModulesAll), HttpStatus.OK); + return new ResponseEntity<>(new PagedList<>(rest, countModulesAll), HttpStatus.OK); } @Override @@ -119,7 +117,7 @@ public class DistributionSetTypeResource implements DistributionSetTypeRestApi { } @Override - public ResponseEntity createDistributionSetTypes( + public ResponseEntity> createDistributionSetTypes( @RequestBody final List distributionSetTypes) { final List createdSoftwareModules = distributionSetManagement.createDistributionSetTypes( @@ -139,14 +137,12 @@ public class DistributionSetTypeResource implements DistributionSetTypeRestApi { } @Override - public ResponseEntity getMandatoryModules(@PathVariable final Long distributionSetTypeId) { + public ResponseEntity> getMandatoryModules( + @PathVariable final Long distributionSetTypeId) { final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId); - - final SoftwareModuleTypesRest rest = new SoftwareModuleTypesRest(); - - rest.addAll(SoftwareModuleTypeMapper.toListResponse(foundType.getMandatoryModuleTypes())); - return new ResponseEntity<>(rest, HttpStatus.OK); + return new ResponseEntity<>(SoftwareModuleTypeMapper.toListResponse(foundType.getMandatoryModuleTypes()), + HttpStatus.OK); } @Override @@ -182,14 +178,13 @@ public class DistributionSetTypeResource implements DistributionSetTypeRestApi { } @Override - public ResponseEntity getOptionalModules(@PathVariable final Long distributionSetTypeId) { + public ResponseEntity> getOptionalModules( + @PathVariable final Long distributionSetTypeId) { final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId); - final SoftwareModuleTypesRest rest = new SoftwareModuleTypesRest(); - - rest.addAll(SoftwareModuleTypeMapper.toListResponse(foundType.getOptionalModuleTypes())); - return new ResponseEntity<>(rest, HttpStatus.OK); + return new ResponseEntity<>(SoftwareModuleTypeMapper.toListResponse(foundType.getOptionalModuleTypes()), + HttpStatus.OK); } @Override diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RestModelMapper.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RestModelMapper.java index 52668f1f1..9616d0e86 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RestModelMapper.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RestModelMapper.java @@ -8,8 +8,8 @@ */ package org.eclipse.hawkbit.rest.resource; -import org.eclipse.hawkbit.repository.model.BaseEntity; import org.eclipse.hawkbit.repository.model.NamedEntity; +import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; import org.eclipse.hawkbit.rest.resource.model.BaseEntityRest; import org.eclipse.hawkbit.rest.resource.model.NamedEntityRest; @@ -28,7 +28,7 @@ final class RestModelMapper { } - static void mapBaseToBase(final BaseEntityRest response, final BaseEntity base) { + static void mapBaseToBase(final BaseEntityRest response, final TenantAwareBaseEntity base) { response.setCreatedBy(base.getCreatedBy()); response.setLastModifiedBy(base.getLastModifiedBy()); if (base.getCreatedAt() != null) { diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RolloutResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RolloutResource.java index e00d07191..78cfefa0d 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RolloutResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RolloutResource.java @@ -28,12 +28,10 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCond import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.rest.resource.api.RolloutRestApi; -import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutPagedList; +import org.eclipse.hawkbit.rest.resource.model.PagedList; import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutResponseBody; import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutRestRequestBody; -import org.eclipse.hawkbit.rest.resource.model.rolloutgroup.RolloutGroupPagedList; import org.eclipse.hawkbit.rest.resource.model.rolloutgroup.RolloutGroupResponseBody; -import org.eclipse.hawkbit.rest.resource.model.target.TargetPagedList; import org.eclipse.hawkbit.rest.resource.model.target.TargetRest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; @@ -64,8 +62,8 @@ public class RolloutResource implements RolloutRestApi { private DistributionSetManagement distributionSetManagement; @Override - public ResponseEntity getRollouts(final int pagingOffsetParam, final int pagingLimitParam, - final String sortParam, final String rsqlParam) { + public ResponseEntity> getRollouts(final int pagingOffsetParam, + final int pagingLimitParam, final String sortParam, final String rsqlParam) { final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); @@ -82,7 +80,7 @@ public class RolloutResource implements RolloutRestApi { } final List rest = RolloutMapper.toResponseRollout(findModulesAll.getContent()); - return new ResponseEntity<>(new RolloutPagedList(rest, findModulesAll.getTotalElements()), HttpStatus.OK); + return new ResponseEntity<>(new PagedList<>(rest, findModulesAll.getTotalElements()), HttpStatus.OK); } @Override @@ -168,8 +166,8 @@ public class RolloutResource implements RolloutRestApi { } @Override - public ResponseEntity getRolloutGroups(final Long rolloutId, final int pagingOffsetParam, - final int pagingLimitParam, final String sortParam, final String rsqlParam) { + public ResponseEntity> getRolloutGroups(final Long rolloutId, + final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) { final Rollout rollout = findRolloutOrThrowException(rolloutId); final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); @@ -188,8 +186,7 @@ public class RolloutResource implements RolloutRestApi { final List rest = RolloutMapper .toResponseRolloutGroup(findRolloutGroupsAll.getContent()); - return new ResponseEntity<>(new RolloutGroupPagedList(rest, findRolloutGroupsAll.getTotalElements()), - HttpStatus.OK); + return new ResponseEntity<>(new PagedList<>(rest, findRolloutGroupsAll.getTotalElements()), HttpStatus.OK); } @Override @@ -200,7 +197,7 @@ public class RolloutResource implements RolloutRestApi { } @Override - public ResponseEntity getRolloutGroupTargets(final Long rolloutId, final Long groupId, + public ResponseEntity> getRolloutGroupTargets(final Long rolloutId, final Long groupId, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) { findRolloutOrThrowException(rolloutId); final RolloutGroup rolloutGroup = findRolloutGroupOrThrowException(groupId); @@ -222,7 +219,8 @@ public class RolloutResource implements RolloutRestApi { rolloutGroupTargets = pageTargets; } final List rest = TargetMapper.toResponse(rolloutGroupTargets.getContent()); - return new ResponseEntity<>(new TargetPagedList(rest, rolloutGroupTargets.getTotalElements()), HttpStatus.OK); + return new ResponseEntity<>(new PagedList(rest, rolloutGroupTargets.getTotalElements()), + HttpStatus.OK); } private Rollout findRolloutOrThrowException(final Long rolloutId) { diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleMapper.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleMapper.java index 1a3ce603f..01dfae9cd 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleMapper.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleMapper.java @@ -26,18 +26,13 @@ import org.eclipse.hawkbit.rest.resource.api.SoftwareModuleTypeRestApi; import org.eclipse.hawkbit.rest.resource.model.MetadataRest; import org.eclipse.hawkbit.rest.resource.model.artifact.ArtifactHash; import org.eclipse.hawkbit.rest.resource.model.artifact.ArtifactRest; -import org.eclipse.hawkbit.rest.resource.model.artifact.ArtifactsRest; import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleRequestBodyPost; import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleRest; -import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModulesRest; /** * A mapper which maps repository model to RESTful model representation and * back. * - * - * - * */ public final class SoftwareModuleMapper { private SoftwareModuleMapper() { @@ -102,8 +97,8 @@ public final class SoftwareModuleMapper { return mappedList; } - static SoftwareModulesRest toResponseSoftwareModules(final Iterable softwareModules) { - final SoftwareModulesRest response = new SoftwareModulesRest(); + static List toResponseSoftwareModules(final Iterable softwareModules) { + final List response = new ArrayList<>(); for (final SoftwareModule softwareModule : softwareModules) { response.add(toResponse(softwareModule)); } @@ -192,8 +187,8 @@ public final class SoftwareModuleMapper { return artifactRest; } - static ArtifactsRest artifactsToResponse(final List artifacts) { - final ArtifactsRest mappedList = new ArtifactsRest(); + static List artifactsToResponse(final List artifacts) { + final List mappedList = new ArrayList<>(); if (artifacts != null) { for (final Artifact artifact : artifacts) { diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java index dfbac1a6f..830443cbd 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java @@ -23,14 +23,11 @@ import org.eclipse.hawkbit.repository.model.SwMetadataCompositeKey; import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.rest.resource.api.SoftwareModuleRestAPI; import org.eclipse.hawkbit.rest.resource.model.MetadataRest; -import org.eclipse.hawkbit.rest.resource.model.MetadataRestPageList; +import org.eclipse.hawkbit.rest.resource.model.PagedList; import org.eclipse.hawkbit.rest.resource.model.artifact.ArtifactRest; -import org.eclipse.hawkbit.rest.resource.model.artifact.ArtifactsRest; -import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModulePagedList; import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleRequestBodyPost; import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleRequestBodyPut; import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleRest; -import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModulesRest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -93,7 +90,7 @@ public class SoftwareModuleResource implements SoftwareModuleRestAPI { } @Override - public ResponseEntity getArtifacts(@PathVariable final Long softwareModuleId) { + public ResponseEntity> getArtifacts(@PathVariable final Long softwareModuleId) { final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); return new ResponseEntity<>(SoftwareModuleMapper.artifactsToResponse(module.getArtifacts()), HttpStatus.OK); @@ -120,7 +117,7 @@ public class SoftwareModuleResource implements SoftwareModuleRestAPI { } @Override - public ResponseEntity getSoftwareModules( + public ResponseEntity> getSoftwareModules( @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, @@ -144,7 +141,7 @@ public class SoftwareModuleResource implements SoftwareModuleRestAPI { } final List rest = SoftwareModuleMapper.toResponse(findModulesAll.getContent()); - return new ResponseEntity<>(new SoftwareModulePagedList(rest, countModulesAll), HttpStatus.OK); + return new ResponseEntity<>(new PagedList<>(rest, countModulesAll), HttpStatus.OK); } @Override @@ -155,7 +152,7 @@ public class SoftwareModuleResource implements SoftwareModuleRestAPI { } @Override - public ResponseEntity createSoftwareModules( + public ResponseEntity> createSoftwareModules( @RequestBody final List softwareModules) { LOG.debug("creating {} softwareModules", softwareModules.size()); final Iterable createdSoftwareModules = softwareManagement @@ -193,7 +190,7 @@ public class SoftwareModuleResource implements SoftwareModuleRestAPI { } @Override - public ResponseEntity getMetadata(@PathVariable final Long softwareModuleId, + public ResponseEntity> getMetadata(@PathVariable final Long softwareModuleId, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, @@ -217,7 +214,7 @@ public class SoftwareModuleResource implements SoftwareModuleRestAPI { } return new ResponseEntity<>( - new MetadataRestPageList(SoftwareModuleMapper.toResponseSwMetadata(metaDataPage.getContent()), + new PagedList<>(SoftwareModuleMapper.toResponseSwMetadata(metaDataPage.getContent()), metaDataPage.getTotalElements()), HttpStatus.OK); } @@ -228,7 +225,7 @@ public class SoftwareModuleResource implements SoftwareModuleRestAPI { // check if distribution set exists otherwise throw exception // immediately final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); - final SoftwareModuleMetadata findOne = softwareManagement.findOne(new SwMetadataCompositeKey(sw, metadataKey)); + final SoftwareModuleMetadata findOne = softwareManagement.findSoftwareModuleMetadata(new SwMetadataCompositeKey(sw, metadataKey)); return ResponseEntity. ok(SoftwareModuleMapper.toResponseSwMetadata(findOne)); } diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeMapper.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeMapper.java index bd2c5f1c1..b6525948c 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeMapper.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeMapper.java @@ -19,7 +19,6 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.rest.resource.api.SoftwareModuleTypeRestApi; import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRequestBodyPost; import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRest; -import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypesRest; /** * A mapper which maps repository model to RESTful model representation and @@ -50,8 +49,8 @@ final class SoftwareModuleTypeMapper { smsRest.getMaxAssignments()); } - static SoftwareModuleTypesRest toTypesResponse(final List types) { - final SoftwareModuleTypesRest response = new SoftwareModuleTypesRest(); + static List toTypesResponse(final List types) { + final List response = new ArrayList<>(); for (final SoftwareModuleType softwareModule : types) { response.add(toResponse(softwareModule)); } diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java index 4259dcc90..e3498f141 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java @@ -18,11 +18,10 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.rest.resource.api.SoftwareModuleTypeRestApi; -import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypePagedList; +import org.eclipse.hawkbit.rest.resource.model.PagedList; import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRequestBodyPost; import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRequestBodyPut; import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRest; -import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypesRest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -43,8 +42,8 @@ public class SoftwareModuleTypeResource implements SoftwareModuleTypeRestApi { private SoftwareManagement softwareManagement; @Override - public ResponseEntity getTypes(final int pagingOffsetParam, final int pagingLimitParam, - final String sortParam, final String rsqlParam) { + public ResponseEntity> getTypes(final int pagingOffsetParam, + final int pagingLimitParam, final String sortParam, final String rsqlParam) { final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); @@ -65,7 +64,7 @@ public class SoftwareModuleTypeResource implements SoftwareModuleTypeRestApi { final List rest = SoftwareModuleTypeMapper .toListResponse(findModuleTypessAll.getContent()); - return new ResponseEntity<>(new SoftwareModuleTypePagedList(rest, countModulesAll), HttpStatus.OK); + return new ResponseEntity<>(new PagedList<>(rest, countModulesAll), HttpStatus.OK); } @Override @@ -99,11 +98,11 @@ public class SoftwareModuleTypeResource implements SoftwareModuleTypeRestApi { } @Override - public ResponseEntity createSoftwareModuleTypes( + public ResponseEntity> createSoftwareModuleTypes( final List softwareModuleTypes) { final List createdSoftwareModules = this.softwareManagement - .createSoftwareModuleTypes(SoftwareModuleTypeMapper.smFromRequest(softwareModuleTypes)); + .createSoftwareModuleType(SoftwareModuleTypeMapper.smFromRequest(softwareModuleTypes)); return new ResponseEntity<>(SoftwareModuleTypeMapper.toTypesResponse(createdSoftwareModules), HttpStatus.CREATED); diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java index b3a461915..27cfdb924 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java @@ -88,7 +88,7 @@ public class SystemManagementResource { .setOverallTargets(report.getOverallTargets()).setOverallTenants(report.getTenants().size()); result.setTenantStats( - report.getTenants().stream().map(tenant -> convertTenant(tenant)).collect(Collectors.toList())); + report.getTenants().stream().map(SystemManagementResource::convertTenant).collect(Collectors.toList())); return ResponseEntity.ok(result); } @@ -104,7 +104,7 @@ public class SystemManagementResource { } /** - * Returns a list of all caches containing currently. + * Returns a list of all caches. * * @return a list of caches for all tenants */ @@ -112,8 +112,8 @@ public class SystemManagementResource { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN) public ResponseEntity> getCaches() { final Collection cacheNames = cacheManager.getCacheNames(); - return ResponseEntity.ok(cacheNames.stream().map(cacheName -> cacheManager.getCache(cacheName)) - .map(cache -> cacheRest(cache)).collect(Collectors.toList())); + return ResponseEntity + .ok(cacheNames.stream().map(cacheManager::getCache).map(this::cacheRest).collect(Collectors.toList())); } /** diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TagMapper.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TagMapper.java index b5e84abe8..f9f0caba0 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TagMapper.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TagMapper.java @@ -21,7 +21,6 @@ import org.eclipse.hawkbit.rest.resource.api.DistributionSetTagRestApi; import org.eclipse.hawkbit.rest.resource.api.TargetTagRestApi; import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut; import org.eclipse.hawkbit.rest.resource.model.tag.TagRest; -import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest; /** * A mapper which maps repository model to RESTful model representation and @@ -33,8 +32,8 @@ final class TagMapper { // Utility class } - static TagsRest toResponse(final List targetTags) { - final TagsRest tagsRest = new TagsRest(); + static List toResponse(final List targetTags) { + final List tagsRest = new ArrayList<>(); if (targetTags == null) { return tagsRest; } @@ -63,8 +62,8 @@ final class TagMapper { return response; } - static TagsRest toResponseDistributionSetTag(final List distributionSetTags) { - final TagsRest tagsRest = new TagsRest(); + static List toResponseDistributionSetTag(final List distributionSetTags) { + final List tagsRest = new ArrayList<>(); if (distributionSetTags == null) { return tagsRest; } @@ -131,7 +130,5 @@ final class TagMapper { if (response.getName() != null) { tag.setName(response.getName()); } - } - } diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetMapper.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetMapper.java index b6c6c1539..c8a39a2f3 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetMapper.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetMapper.java @@ -27,18 +27,15 @@ import org.eclipse.hawkbit.rest.resource.api.TargetRestApi; import org.eclipse.hawkbit.rest.resource.model.PollStatusRest; import org.eclipse.hawkbit.rest.resource.model.action.ActionRest; import org.eclipse.hawkbit.rest.resource.model.action.ActionStatusRest; -import org.eclipse.hawkbit.rest.resource.model.action.ActionStatussRest; -import org.eclipse.hawkbit.rest.resource.model.action.ActionsRest; import org.eclipse.hawkbit.rest.resource.model.target.TargetRequestBody; import org.eclipse.hawkbit.rest.resource.model.target.TargetRest; -import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest; /** * A mapper which maps repository model to RESTful model representation and * back. * */ -final public class TargetMapper { +public final class TargetMapper { private TargetMapper() { // Utility class @@ -64,7 +61,7 @@ final public class TargetMapper { } /** - * Add the pollstatus to a target response. + * Add the poll status to a target response. * * @param target * the target @@ -91,8 +88,8 @@ final public class TargetMapper { * the targets * @return the response */ - public static TargetsRest toResponseWithLinksAndPollStatus(final Iterable targets) { - final TargetsRest mappedList = new TargetsRest(); + public static List toResponseWithLinksAndPollStatus(final Iterable targets) { + final List mappedList = new ArrayList<>(); if (targets != null) { for (final Target target : targets) { final TargetRest response = toResponse(target); @@ -111,8 +108,8 @@ final public class TargetMapper { * list of targets * @return the response */ - public static TargetsRest toResponse(final Iterable targets) { - final TargetsRest mappedList = new TargetsRest(); + public static List toResponse(final Iterable targets) { + final List mappedList = new ArrayList<>(); if (targets != null) { for (final Target target : targets) { final TargetRest response = toResponse(target); @@ -184,12 +181,12 @@ final public class TargetMapper { return target; } - static ActionStatussRest toActionStatusRestResponse(final Action action, final List actionStatus) { - final ActionStatussRest mappedList = new ActionStatussRest(); + static List toActionStatusRestResponse(final List actionStatus) { + final List mappedList = new ArrayList<>(); if (actionStatus != null) { for (final ActionStatus status : actionStatus) { - final ActionStatusRest response = toResponse(action, status); + final ActionStatusRest response = toResponse(status); mappedList.add(response); } } @@ -216,8 +213,8 @@ final public class TargetMapper { return result; } - static ActionsRest toResponse(final String targetId, final List actions) { - final ActionsRest mappedList = new ActionsRest(); + static List toResponse(final String targetId, final List actions) { + final List mappedList = new ArrayList<>(); for (final Action action : actions) { final ActionRest response = toResponse(targetId, action, action.isActive()); @@ -293,7 +290,7 @@ final public class TargetMapper { return result; } - private static ActionStatusRest toResponse(final Action action, final ActionStatus actionStatus) { + private static ActionStatusRest toResponse(final ActionStatus actionStatus) { final ActionStatusRest result = new ActionStatusRest(); result.setMessages(actionStatus.getMessages()); diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java index faa31a7cc..3c79c936c 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java @@ -29,16 +29,14 @@ import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.rest.resource.api.DistributionSetRestApi; import org.eclipse.hawkbit.rest.resource.api.TargetRestApi; import org.eclipse.hawkbit.rest.resource.helper.RestResourceConversionHelper; -import org.eclipse.hawkbit.rest.resource.model.action.ActionPagedList; +import org.eclipse.hawkbit.rest.resource.model.PagedList; import org.eclipse.hawkbit.rest.resource.model.action.ActionRest; -import org.eclipse.hawkbit.rest.resource.model.action.ActionStatusPagedList; +import org.eclipse.hawkbit.rest.resource.model.action.ActionStatusRest; import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRest; import org.eclipse.hawkbit.rest.resource.model.target.DistributionSetAssigmentRest; import org.eclipse.hawkbit.rest.resource.model.target.TargetAttributes; -import org.eclipse.hawkbit.rest.resource.model.target.TargetPagedList; import org.eclipse.hawkbit.rest.resource.model.target.TargetRequestBody; import org.eclipse.hawkbit.rest.resource.model.target.TargetRest; -import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -77,7 +75,7 @@ public class TargetResource implements TargetRestApi { } @Override - public ResponseEntity getTargets(final int pagingOffsetParam, final int pagingLimitParam, + public ResponseEntity> getTargets(final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) { final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); @@ -98,11 +96,11 @@ public class TargetResource implements TargetRestApi { } final List rest = TargetMapper.toResponse(findTargetsAll.getContent()); - return new ResponseEntity<>(new TargetPagedList(rest, countTargetsAll), HttpStatus.OK); + return new ResponseEntity<>(new PagedList(rest, countTargetsAll), HttpStatus.OK); } @Override - public ResponseEntity createTargets(final List targets) { + public ResponseEntity> createTargets(final List targets) { LOG.debug("creating {} targets", targets.size()); final Iterable createdTargets = this.targetManagement.createTargets(TargetMapper.fromRequest(targets)); LOG.debug("{} targets created, return status {}", targets.size(), HttpStatus.CREATED); @@ -147,7 +145,7 @@ public class TargetResource implements TargetRestApi { } @Override - public ResponseEntity getActionHistory(final String targetId, final int pagingOffsetParam, + public ResponseEntity> getActionHistory(final String targetId, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) { final Target foundTarget = findTargetWithExceptionIfNotFound(targetId); @@ -169,7 +167,7 @@ public class TargetResource implements TargetRestApi { } return new ResponseEntity<>( - new ActionPagedList(TargetMapper.toResponse(targetId, activeActions.getContent()), totalActionCount), + new PagedList<>(TargetMapper.toResponse(targetId, activeActions.getContent()), totalActionCount), HttpStatus.OK); } @@ -220,7 +218,7 @@ public class TargetResource implements TargetRestApi { } @Override - public ResponseEntity getActionStatusList(final String targetId, final Long actionId, + public ResponseEntity> getActionStatusList(final String targetId, final Long actionId, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) { final Target target = findTargetWithExceptionIfNotFound(targetId); @@ -238,10 +236,8 @@ public class TargetResource implements TargetRestApi { final Page statusList = this.deploymentManagement.findActionStatusByAction( new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting), action, true); - return new ResponseEntity<>( - new ActionStatusPagedList(TargetMapper.toActionStatusRestResponse(action, statusList.getContent()), - statusList.getTotalElements()), - HttpStatus.OK); + return new ResponseEntity<>(new PagedList<>(TargetMapper.toActionStatusRestResponse(statusList.getContent()), + statusList.getTotalElements()), HttpStatus.OK); } diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetTagResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetTagResource.java index 76209a958..9990fb35a 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetTagResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetTagResource.java @@ -17,16 +17,15 @@ import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetTag; -import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult; +import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.rest.resource.api.TargetTagRestApi; +import org.eclipse.hawkbit.rest.resource.model.PagedList; import org.eclipse.hawkbit.rest.resource.model.tag.AssignedTargetRequestBody; -import org.eclipse.hawkbit.rest.resource.model.tag.TagPagedList; import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut; import org.eclipse.hawkbit.rest.resource.model.tag.TagRest; -import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest; import org.eclipse.hawkbit.rest.resource.model.tag.TargetTagAssigmentResultRest; -import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest; +import org.eclipse.hawkbit.rest.resource.model.target.TargetRest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -54,7 +53,7 @@ public class TargetTagResource implements TargetTagRestApi { private TargetManagement targetManagement; @Override - public ResponseEntity getTargetTags(final int pagingOffsetParam, final int pagingLimitParam, + public ResponseEntity> getTargetTags(final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) { final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); @@ -77,7 +76,7 @@ public class TargetTagResource implements TargetTagRestApi { } final List rest = TagMapper.toResponse(findTargetsAll.getContent()); - return new ResponseEntity<>(new TagPagedList(rest, countTargetsAll), HttpStatus.OK); + return new ResponseEntity<>(new PagedList<>(rest, countTargetsAll), HttpStatus.OK); } @Override @@ -87,7 +86,7 @@ public class TargetTagResource implements TargetTagRestApi { } @Override - public ResponseEntity createTargetTags(@RequestBody final List tags) { + public ResponseEntity> createTargetTags(@RequestBody final List tags) { LOG.debug("creating {} target tags", tags.size()); final List createdTargetTags = this.tagManagement .createTargetTags(TagMapper.mapTargeTagFromRequest(tags)); @@ -118,7 +117,7 @@ public class TargetTagResource implements TargetTagRestApi { } @Override - public ResponseEntity getAssignedTargets(final Long targetTagId) { + public ResponseEntity> getAssignedTargets(final Long targetTagId) { final TargetTag targetTag = findTargetTagById(targetTagId); return new ResponseEntity<>(TargetMapper.toResponseWithLinksAndPollStatus(targetTag.getAssignedToTargets()), HttpStatus.OK); @@ -130,7 +129,7 @@ public class TargetTagResource implements TargetTagRestApi { LOG.debug("Toggle Target assignment {} for target tag {}", assignedTargetRequestBodies.size(), targetTagId); final TargetTag targetTag = findTargetTagById(targetTagId); - final TargetTagAssigmentResult assigmentResult = this.targetManagement + final TargetTagAssignmentResult assigmentResult = this.targetManagement .toggleTagAssignment(findTargetControllerIds(assignedTargetRequestBodies), targetTag.getName()); final TargetTagAssigmentResultRest tagAssigmentResultRest = new TargetTagAssigmentResultRest(); @@ -140,7 +139,7 @@ public class TargetTagResource implements TargetTagRestApi { } @Override - public ResponseEntity assignTargets(final Long targetTagId, + public ResponseEntity> assignTargets(final Long targetTagId, final List assignedTargetRequestBodies) { LOG.debug("Assign Targets {} for target tag {}", assignedTargetRequestBodies.size(), targetTagId); final TargetTag targetTag = findTargetTagById(targetTagId); diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResourceTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResourceTest.java index 0b8503d6b..1d2222c9a 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResourceTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResourceTest.java @@ -169,7 +169,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo artifactManagement .loadLocalArtifactBinary((LocalArtifact) softwareManagement .findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0)) - .getFileInputStream())); + .getFileInputStream())); // hashes assertThat(artifactManagement.findLocalArtifactByFilename("origFilename").get(0).getSha1Hash()) @@ -773,12 +773,12 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo .andExpect(jsonPath("[2].createdBy", equalTo("uploadTester"))) .andExpect(jsonPath("[2].createdAt", not(equalTo(0)))).andReturn(); - final SoftwareModule osCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name1", "version1") - .get(0); - final SoftwareModule jvmCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name2", "version1") - .get(0); - final SoftwareModule ahCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name3", "version1") - .get(0); + final SoftwareModule osCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name1", "version1", + osType); + final SoftwareModule jvmCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name2", "version1", + runtimeType); + final SoftwareModule ahCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name3", "version1", + appType); assertThat( JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) @@ -930,8 +930,10 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo .andExpect(jsonPath("[1]key", equalTo(knownKey2))) .andExpect(jsonPath("[1]value", equalTo(knownValue2))); - final SoftwareModuleMetadata metaKey1 = softwareManagement.findOne(new SwMetadataCompositeKey(sm, knownKey1)); - final SoftwareModuleMetadata metaKey2 = softwareManagement.findOne(new SwMetadataCompositeKey(sm, knownKey2)); + final SoftwareModuleMetadata metaKey1 = softwareManagement + .findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey1)); + final SoftwareModuleMetadata metaKey2 = softwareManagement + .findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey2)); assertThat(metaKey1.getValue()).as("Metadata key is wrong").isEqualTo(knownValue1); assertThat(metaKey2.getValue()).as("Metadata key is wrong").isEqualTo(knownValue2); @@ -957,7 +959,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue))); - final SoftwareModuleMetadata assertDS = softwareManagement.findOne(new SwMetadataCompositeKey(sm, knownKey)); + final SoftwareModuleMetadata assertDS = softwareManagement + .findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey)); assertThat(assertDS.getValue()).as("Metadata is wrong").isEqualTo(updateValue); } @@ -976,7 +979,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); try { - softwareManagement.findOne(new SwMetadataCompositeKey(sm, knownKey)); + softwareManagement.findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey)); fail("expected EntityNotFoundException but didn't throw"); } catch (final EntityNotFoundException e) { // ok as expected diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/PagedListTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/PagedListTest.java index 49e13c0b4..68ce570a1 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/PagedListTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/PagedListTest.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.rest.resource.model; import static org.fest.assertions.Assertions.assertThat; +import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.List; @@ -23,10 +24,14 @@ import ru.yandex.qatools.allure.annotations.Stories; @Stories("Paged List Handling") public class PagedListTest { - @Test(expected = NullPointerException.class) + @Test @Description("Ensures that a null payload entitiy throws an exception.") public void createListWithNullContentThrowsException() { - new PagedList<>(null, 0); + try { + new PagedList<>(null, 0); + fail("as content is null"); + } catch (final NullPointerException e) { + } } @Test diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitEventProvider.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitEventProvider.java new file mode 100644 index 000000000..12bcaacbc --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitEventProvider.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent; +import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent; +import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent; +import org.eclipse.hawkbit.eventbus.event.Event; +import org.eclipse.hawkbit.eventbus.event.RolloutChangeEvent; +import org.eclipse.hawkbit.eventbus.event.RolloutGroupChangeEvent; +import org.eclipse.hawkbit.eventbus.event.TargetCreatedEvent; +import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent; +import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; +import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; + +/** + * The default hawkbit event provider. + */ +public class HawkbitEventProvider implements UIEventProvider { + + private static final Set> SINGLE_EVENTS = new HashSet<>(6); + private static final Set> BULK_EVENTS = new HashSet<>(3); + + static { + SINGLE_EVENTS.add(TargetTagCreatedBulkEvent.class); + SINGLE_EVENTS.add(DistributionSetTagCreatedBulkEvent.class); + SINGLE_EVENTS.add(DistributionSetTagDeletedEvent.class); + SINGLE_EVENTS.add(DistributionSetTagUpdateEvent.class); + SINGLE_EVENTS.add(RolloutGroupChangeEvent.class); + SINGLE_EVENTS.add(RolloutChangeEvent.class); + + BULK_EVENTS.add(TargetCreatedEvent.class); + BULK_EVENTS.add(TargetInfoUpdateEvent.class); + BULK_EVENTS.add(TargetDeletedEvent.class); + } + + @Override + public Set> getSingleEvents() { + return SINGLE_EVENTS; + } + + @Override + public Set> getBulkEvents() { + return BULK_EVENTS; + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/UIEventProvider.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/UIEventProvider.java new file mode 100644 index 000000000..5663ce897 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/UIEventProvider.java @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui; + +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import org.eclipse.hawkbit.eventbus.event.Event; + +/** + * The UI event provider hold all supported repository events which will + * delegated to the UI. A event type can delegated as single event or bulk + * event. Bulk event means, that all events from one type is collected by the + * provider. The delegater and delegated as a list of this events. + */ +public interface UIEventProvider { + + /** + * Return all supported repository single event types. All events which this + * type are delegated to the UI as single event. + * + * @return list of provided event types. Should not be null + */ + default Set> getSingleEvents() { + return Collections.emptySet(); + } + + /** + * Return all supported repository bulk event types. All events which this + * type are delegated to the UI as a list. This list contains all collected + * events from one type. + * + * @return list of provided bulk event types. Should not be null + */ + default Set> getBulkEvents() { + return Collections.emptySet(); + } + + /** + * Return all filtered bulk event types by the given events. The default + * maps the events by class. + * + * @param allEvents + * the events + * @return list of provided bulk event types which are filtered. Should not + * be null + */ + default Set> getFilteredBulkEventsType(final List allEvents) { + return allEvents.stream().map(Event::getClass).filter(getBulkEvents()::contains).collect(Collectors.toSet()); + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java index 3cc5c8dc1..7e05e8c63 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java @@ -28,8 +28,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.spring.events.EventBus; -import com.vaadin.event.FieldEvents.TextChangeEvent; -import com.vaadin.event.FieldEvents.TextChangeListener; import com.vaadin.server.FontAwesome; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; @@ -245,27 +243,21 @@ public class SoftwareModuleAddUpdateWindow implements Serializable { } private void addDescriptionTextChangeListener() { - descTextArea.addTextChangeListener(new TextChangeListener() { - @Override - public void textChange(final TextChangeEvent event) { - if (event.getText().equals(oldDescriptionValue) && vendorTextField.getValue().equals(oldVendorValue)) { - saveSoftware.setEnabled(false); - } else { - saveSoftware.setEnabled(true); - } + descTextArea.addTextChangeListener(event -> { + if (event.getText().equals(oldDescriptionValue) && vendorTextField.getValue().equals(oldVendorValue)) { + saveSoftware.setEnabled(false); + } else { + saveSoftware.setEnabled(true); } }); } private void addVendorTextChangeListener() { - vendorTextField.addTextChangeListener(new TextChangeListener() { - @Override - public void textChange(final TextChangeEvent event) { - if (event.getText().equals(oldVendorValue) && descTextArea.getValue().equals(oldDescriptionValue)) { - saveSoftware.setEnabled(false); - } else { - saveSoftware.setEnabled(true); - } + vendorTextField.addTextChangeListener(event -> { + if (event.getText().equals(oldVendorValue) && descTextArea.getValue().equals(oldDescriptionValue)) { + saveSoftware.setEnabled(false); + } else { + saveSoftware.setEnabled(true); } }); } @@ -280,7 +272,7 @@ public class SoftwareModuleAddUpdateWindow implements Serializable { final String description = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null; if (mandatoryCheck(name, version, type)) { - if (HawkbitCommonUtil.isDuplicate(name, version)) { + if (HawkbitCommonUtil.isDuplicate(name, version, type)) { uiNotifcation.displayValidationError( i18n.get("message.duplicate.softwaremodule", new Object[] { name, version })); } else { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterButtons.java index 9f2aa9602..857b27a7e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterButtons.java @@ -97,9 +97,9 @@ public class SMTypeFilterButtons extends AbstractFilterButtons { } @Override - protected boolean isClickedByDefault(final Long buttonId) { + protected boolean isClickedByDefault(final String typeName) { return artifactUploadState.getSoftwareModuleFilters().getSoftwareModuleType().isPresent() && artifactUploadState - .getSoftwareModuleFilters().getSoftwareModuleType().get().getId().equals(buttonId); + .getSoftwareModuleFilters().getSoftwareModuleType().get().getName().equals(typeName); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java index 8def18034..40acb6581 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java @@ -161,7 +161,6 @@ public class SoftwareModuleDetailsTable extends Table { if (null != distributionSet) { if (isUnassignSoftModAllowed && permissionChecker.hasUpdateDistributionPermission()) { try { - distributionSetManagement.checkDistributionSetAlreadyUse(distributionSet); isTargetAssigned = false; } catch (final EntityLockedException exception) { isTargetAssigned = true; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterButtons.java index 6ed10166f..e95797fb4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterButtons.java @@ -114,7 +114,7 @@ public abstract class AbstractFilterButtons extends Table { typeButton.addClickListener(event -> filterButtonClickBehaviour.processFilterButtonClick(event)); if (typeButton.getData().equals(SPUIDefinitions.NO_TAG_BUTTON_ID) && isNoTagSateSelected()) { filterButtonClickBehaviour.setDefaultClickedButton(typeButton); - } else if (id != null && isClickedByDefault(id)) { + } else if (id != null && isClickedByDefault(name)) { filterButtonClickBehaviour.setDefaultClickedButton(typeButton); } final DragAndDropWrapper wrapper = createDragAndDropWrapper(typeButton, name, id); @@ -205,10 +205,11 @@ public abstract class AbstractFilterButtons extends Table { /** * Check if button should be displayed as clicked by default. * - * @param id - * @return + * @param buttonCaption + * button caption + * @return true if button is clicked */ - protected abstract boolean isClickedByDefault(final Long buttonId); + protected abstract boolean isClickedByDefault(final String buttonCaption); /** * Get filter button Id. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGrid.java index 7cd276258..6ac205cf2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGrid.java @@ -12,10 +12,7 @@ import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import com.vaadin.data.Container; import com.vaadin.data.Container.Indexed; -import com.vaadin.shared.ui.grid.HeightMode; import com.vaadin.ui.Grid; -import com.vaadin.ui.Label; -import com.vaadin.ui.themes.ValoTheme; /** * Abstract table class. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java index c8824e455..d6d37d5c0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java @@ -26,7 +26,7 @@ import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; -import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult; +import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; @@ -100,7 +100,7 @@ public class DistributionTagToken extends AbstractTagToken { @Override protected void assignTag(final String tagNameSelected) { if (tagNameSelected != null) { - final DistributionSetTagAssigmentResult result = toggleAssignment(tagNameSelected); + final DistributionSetTagAssignmentResult result = toggleAssignment(tagNameSelected); if (result.getAssigned() >= 1 && NOTAGS_SELECTED) { eventBus.publish(this, ManagementUIEvent.ASSIGN_DISTRIBUTION_TAG); } @@ -109,10 +109,10 @@ public class DistributionTagToken extends AbstractTagToken { } } - private DistributionSetTagAssigmentResult toggleAssignment(final String tagNameSelected) { + private DistributionSetTagAssignmentResult toggleAssignment(final String tagNameSelected) { final Set distributionList = new HashSet<>(); distributionList.add(selectedDS.getId()); - final DistributionSetTagAssigmentResult result = distributionSetManagement.toggleTagAssignment(distributionList, + final DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(distributionList, tagNameSelected); uinotification.displaySuccess(HawkbitCommonUtil.getDistributionTagAssignmentMsg(tagNameSelected, result, i18n)); return result; @@ -120,7 +120,7 @@ public class DistributionTagToken extends AbstractTagToken { @Override protected void unassignTag(final String tagName) { - final DistributionSetTagAssigmentResult result = toggleAssignment(tagName); + final DistributionSetTagAssignmentResult result = toggleAssignment(tagName); if (result.getUnassigned() >= 1 && (isClickedTagListEmpty() || getClickedTagList().contains(tagName))) { eventBus.publish(this, ManagementUIEvent.UNASSIGN_DISTRIBUTION_TAG); } @@ -202,7 +202,7 @@ public class DistributionTagToken extends AbstractTagToken { @EventBusListenerMethod(scope = EventScope.SESSION) void onTargetTagAssigmentResultEvent(final DistributionSetTagAssigmentResultEvent event) { - final DistributionSetTagAssigmentResult assignmentResult = event.getAssigmentResult(); + final DistributionSetTagAssignmentResult assignmentResult = event.getAssigmentResult(); final DistributionSetTag tag = assignmentResult.getDistributionSetTag(); if (isAssign(assignmentResult)) { addNewToken(tag.getId()); @@ -212,7 +212,7 @@ public class DistributionTagToken extends AbstractTagToken { } - protected boolean isAssign(final DistributionSetTagAssigmentResult assignmentResult) { + protected boolean isAssign(final DistributionSetTagAssignmentResult assignmentResult) { if (assignmentResult.getAssigned() > 0) { final List assignedDsNames = assignmentResult.getAssignedDs().stream().map(t -> t.getId()) .collect(Collectors.toList()); @@ -223,7 +223,7 @@ public class DistributionTagToken extends AbstractTagToken { return false; } - protected boolean isUnassign(final DistributionSetTagAssigmentResult assignmentResult) { + protected boolean isUnassign(final DistributionSetTagAssignmentResult assignmentResult) { if (assignmentResult.getUnassigned() > 0) { final List assignedDsNames = assignmentResult.getUnassignedDs().stream().map(t -> t.getId()) .collect(Collectors.toList()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java index 8982be759..b21b8f075 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java @@ -19,7 +19,7 @@ import org.eclipse.hawkbit.eventbus.event.TargetTagUpdateEvent; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetTag; -import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult; +import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; @@ -68,7 +68,7 @@ public class TargetTagToken extends AbstractTargetTagToken { @Override protected void assignTag(final String tagNameSelected) { if (tagNameSelected != null) { - final TargetTagAssigmentResult result = toggleAssignment(tagNameSelected); + final TargetTagAssignmentResult result = toggleAssignment(tagNameSelected); if (result.getAssigned() >= 1 && NOTAGS_SELECTED) { eventBus.publish(this, ManagementUIEvent.ASSIGN_TARGET_TAG); } @@ -77,17 +77,17 @@ public class TargetTagToken extends AbstractTargetTagToken { } } - private TargetTagAssigmentResult toggleAssignment(final String tagNameSelected) { + private TargetTagAssignmentResult toggleAssignment(final String tagNameSelected) { final Set targetList = new HashSet<>(); targetList.add(selectedTarget.getControllerId()); - final TargetTagAssigmentResult result = targetManagement.toggleTagAssignment(targetList, tagNameSelected); + final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, tagNameSelected); uinotification.displaySuccess(HawkbitCommonUtil.getTargetTagAssigmentMsg(tagNameSelected, result, i18n)); return result; } @Override protected void unassignTag(final String tagName) { - final TargetTagAssigmentResult result = toggleAssignment(tagName); + final TargetTagAssignmentResult result = toggleAssignment(tagName); if (result.getUnassigned() >= 1 && (isClickedTagListEmpty() || getClickedTagList().contains(tagName))) { eventBus.publish(this, ManagementUIEvent.UNASSIGN_TARGET_TAG); } @@ -139,7 +139,7 @@ public class TargetTagToken extends AbstractTargetTagToken { @EventBusListenerMethod(scope = EventScope.SESSION) void onTargetTagAssigmentResultEvent(final TargetTagAssigmentResultEvent event) { - final TargetTagAssigmentResult assignmentResult = event.getAssigmentResult(); + final TargetTagAssignmentResult assignmentResult = event.getAssigmentResult(); final TargetTag targetTag = assignmentResult.getTargetTag(); if (isAssign(assignmentResult)) { addNewToken(targetTag.getId()); @@ -149,7 +149,7 @@ public class TargetTagToken extends AbstractTargetTagToken { } - protected boolean isAssign(final TargetTagAssigmentResult assignmentResult) { + protected boolean isAssign(final TargetTagAssignmentResult assignmentResult) { if (assignmentResult.getAssigned() > 0) { final List assignedTargetNames = assignmentResult.getAssignedTargets().stream() .map(t -> t.getControllerId()).collect(Collectors.toList()); @@ -160,7 +160,7 @@ public class TargetTagToken extends AbstractTargetTagToken { return false; } - protected boolean isUnassign(final TargetTagAssigmentResult assignmentResult) { + protected boolean isUnassign(final TargetTagAssignmentResult assignmentResult) { if (assignmentResult.getUnassigned() > 0) { final List unassignedTargetNamesList = assignmentResult.getUnassignedTargets().stream() .map(t -> t.getControllerId()).collect(Collectors.toList()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterButtons.java index cd36918e8..aa35c0622 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterButtons.java @@ -79,10 +79,9 @@ public class DSTypeFilterButtons extends AbstractFilterButtons { } @Override - protected boolean isClickedByDefault(final Long buttonId) { - + protected boolean isClickedByDefault(final String typeName) { return manageDistUIState.getManageDistFilters().getClickedDistSetType() != null - && manageDistUIState.getManageDistFilters().getClickedDistSetType().getId().equals(buttonId); + && manageDistUIState.getManageDistFilters().getClickedDistSetType().getName().equals(typeName); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java index 859febbce..5419cc1bf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java @@ -22,8 +22,6 @@ import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; import org.springframework.data.domain.Slice; -import org.springframework.data.domain.Sort; -import org.springframework.data.domain.Sort.Direction; import org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery; import org.vaadin.addons.lazyquerycontainer.QueryDefinition; @@ -79,9 +77,8 @@ public class SwModuleBeanQuery extends AbstractBeanQuery final Slice swModuleBeans; final List proxyBeans = new ArrayList<>(); - swModuleBeans = getSoftwareManagement().findSoftwareModuleOrderByDistribution( - new OffsetBasedPageRequest(startIndex, count, new Sort(Direction.ASC, "name", "version")), - orderByDistId, searchText, type); + swModuleBeans = getSoftwareManagement().findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( + new OffsetBasedPageRequest(startIndex, count), orderByDistId, searchText, type); for (final CustomSoftwareModule swModule : swModuleBeans) { proxyBeans.add(getProxyBean(swModule)); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtons.java index d3251cf9b..f086fed2c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtons.java @@ -82,10 +82,9 @@ public class DistSMTypeFilterButtons extends AbstractFilterButtons { } @Override - protected boolean isClickedByDefault(final Long buttonId) { - + protected boolean isClickedByDefault(final String typeName) { return manageDistUIState.getSoftwareModuleFilters().getSoftwareModuleType().isPresent() - && manageDistUIState.getSoftwareModuleFilters().getSoftwareModuleType().get().getId().equals(buttonId); + && manageDistUIState.getSoftwareModuleFilters().getSoftwareModuleType().get().getName().equals(typeName); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index 4f4aa8b2f..0cc857c30 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -25,7 +25,7 @@ import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; -import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult; +import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.ui.common.table.AbstractTable; @@ -360,7 +360,7 @@ public class DistributionTable extends AbstractTable { final String distTagName = HawkbitCommonUtil.removePrefix(event.getTransferable().getSourceComponent().getId(), SPUIDefinitions.DISTRIBUTION_TAG_ID_PREFIXS); - final DistributionSetTagAssigmentResult result = distributionSetManagement.toggleTagAssignment(distList, + final DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(distList, distTagName); notification.displaySuccess(HawkbitCommonUtil.getDistributionTagAssignmentMsg(distTagName, result, i18n)); @@ -564,7 +564,7 @@ public class DistributionTable extends AbstractTable { .getItemProperty(SPUILabelDefinitions.VAR_DIST_ID_NAME).getValue(); final Button pinBtn = getPinBtn(itemId, dist.getName(), dist.getVersion()); saveDistributionPinnedBtn(pinBtn); - pinBtn.addClickListener(event -> addPinClickListener(event)); + pinBtn.addClickListener(this::addPinClickListener); rePinDistribution(pinBtn, dist.getId()); return pinBtn; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java index 98c48d235..287071fe8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java @@ -16,7 +16,6 @@ import javax.annotation.PreDestroy; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtonClickBehaviour; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtons; @@ -58,9 +57,6 @@ public class DistributionTagButtons extends AbstractFilterButtons { @Autowired private DistributionTagDropEvent spDistTagDropEvent; - @Autowired - private transient TagManagement tagMgmtService; - @Autowired private ManagementUIState managementUIState; @@ -121,10 +117,9 @@ public class DistributionTagButtons extends AbstractFilterButtons { } @Override - protected boolean isClickedByDefault(final Long buttonId) { - final DistributionSetTag dsTagObject = tagMgmtService.findDistributionSetTagById(buttonId); + protected boolean isClickedByDefault(final String tagName) { return null != managementUIState.getDistributionTableFilters().getDistSetTags() - && managementUIState.getDistributionTableFilters().getDistSetTags().contains(dsTagObject.getName()); + && managementUIState.getDistributionTableFilters().getDistSetTags().contains(tagName); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java index 21013a55e..f8d53bdef 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java @@ -16,7 +16,7 @@ import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; -import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult; +import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.ui.management.state.DistributionTableFilters; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.I18N; @@ -147,7 +147,7 @@ public class DistributionTagDropEvent implements DropHandler { SPUIDefinitions.DISTRIBUTION_TAG_ID_PREFIXS); final List tagsClickedList = distFilterParameters.getDistSetTags(); - final DistributionSetTagAssigmentResult result = distributionSetManagement.toggleTagAssignment(distributionList, + final DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(distributionList, distTagName); notification.displaySuccess(HawkbitCommonUtil.getDistributionTagAssignmentMsg(distTagName, result, i18n)); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index 960553a6a..3df8fe6a4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -15,7 +15,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -33,7 +32,7 @@ import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetInfo; -import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult; +import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.filter.FilterExpression; @@ -105,12 +104,11 @@ import com.vaadin.ui.themes.ValoTheme; @ViewScope public class TargetTable extends AbstractTable implements Handler { + private static final Logger LOG = LoggerFactory.getLogger(TargetTable.class); private static final String TARGET_PINNED = "targetPinned"; private static final long serialVersionUID = -2300392868806614568L; - private static final Logger LOG = LoggerFactory.getLogger(TargetTable.class); - private static final int PROPERTY_DEPT = 3; private static final String ITEMID = "itemId"; private static final String ACTION_NOT_ALLOWED_MSG = "message.action.not.allowed"; @@ -141,8 +139,6 @@ public class TargetTable extends AbstractTable implements Handler { private Boolean isTargetPinned = Boolean.FALSE; private ShortcutAction actionSelectAll; private ShortcutAction actionUnSelectAll; - - @Override @PostConstruct @@ -329,38 +325,20 @@ public class TargetTable extends AbstractTable implements Handler { (source, itemId, columnId) -> getTagetPollTime(itemId)); } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.common.table.AbstractTable# - * isFirstRowSelectedOnLoad () - */ @Override protected boolean isFirstRowSelectedOnLoad() { return !managementUIState.getSelectedTargetIdName().isPresent() || managementUIState.getSelectedTargetIdName().get().isEmpty(); } - /* - * (non-Javadoc) - * - * @see hawkbit.server.ui.common.table.AbstractTable#getItemIdToSelect() - */ @Override protected Object getItemIdToSelect() { if (managementUIState.getSelectedTargetIdName().isPresent()) { - setCurrentPageFirstItemId(managementUIState.getLastSelectedTargetIdName()); return managementUIState.getSelectedTargetIdName().get(); } return null; } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.table.AbstractTable#onValueChange() - */ @Override protected void onValueChange() { eventBus.publish(this, DragEvent.HIDE_DROP_HINT); @@ -380,23 +358,11 @@ public class TargetTable extends AbstractTable implements Handler { } } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.table.AbstractTable#isMaximized() - */ @Override protected boolean isMaximized() { return managementUIState.isTargetTableMaximized(); } - /* - * (non-Javadoc) - * - * @see hawkbit.server.ui.common.table.AbstractTable#getTableVisibleColumns - * () - */ @Override protected List getTableVisibleColumns() { final List columnList = new ArrayList<>(); @@ -453,13 +419,29 @@ public class TargetTable extends AbstractTable implements Handler { } else { shouldRefreshTargets = true; } - unselect(targetIdName); } + if (shouldRefreshTargets) { refreshOnDelete(); } else { targetContainer.commit(); - selectRow(); + } + reSelectItemsAfterDeletionEvent(); + } + + private void reSelectItemsAfterDeletionEvent() { + Set values = new HashSet<>(); + if (isMultiSelect()) { + values = new HashSet<>((Set) getValue()); + } else { + values.add(getValue()); + } + unSelectAll(); + + for (final Object value : values) { + if (getVisibleItemIds().contains(value)) { + select(value); + } } } @@ -659,7 +641,7 @@ public class TargetTable extends AbstractTable implements Handler { } final String targTagName = HawkbitCommonUtil.removePrefix(event.getTransferable().getSourceComponent().getId(), SPUIDefinitions.TARGET_TAG_ID_PREFIXS); - final TargetTagAssigmentResult result = targetManagement.toggleTagAssignment(targetList, targTagName); + final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, targTagName); final List tagsClickedList = managementUIState.getTargetTableFilters().getClickedTargetTags(); notification.displaySuccess(HawkbitCommonUtil.getTargetTagAssigmentMsg(targTagName, result, i18n)); @@ -1038,7 +1020,7 @@ public class TargetTable extends AbstractTable implements Handler { final String[] tagArray = tagList.toArray(new String[tagList.size()]); List targetIdList; - targetIdList = targetManagement.findAllTargetIdsByFilters(pageRequest, filterByDistId, statusList, searchText, + targetIdList = targetManagement.findAllTargetIdsByFilters(pageRequest, statusList, searchText, filterByDistId, noTagSelected, tagList.toArray(tagArray)); Collections.reverse(targetIdList); return targetIdList; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java index 9d93962da..169573f39 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java @@ -19,11 +19,10 @@ import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagUpdateEvent; import org.eclipse.hawkbit.repository.SpPermissionChecker; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetTag; -import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult; +import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtons; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; @@ -70,9 +69,6 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { @Autowired private ManagementUIState managementUIState; - @Autowired - private transient TagManagement tagMgmtService; - @Autowired private ManagementViewAcceptCriteria managementViewAcceptCriteria; @@ -139,10 +135,9 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { } @Override - protected boolean isClickedByDefault(final Long buttonId) { - final TargetTag newTagClickedObj = tagMgmtService.findTargetTagById(buttonId); - return managementUIState.getTargetTableFilters().getClickedTargetTags() != null && managementUIState - .getTargetTableFilters().getClickedTargetTags().contains(newTagClickedObj.getName()); + protected boolean isClickedByDefault(final String tagName) { + return managementUIState.getTargetTableFilters().getClickedTargetTags() != null + && managementUIState.getTargetTableFilters().getClickedTargetTags().contains(tagName); } @Override @@ -248,7 +243,7 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { final List tagsClickedList = managementUIState.getTargetTableFilters().getClickedTargetTags(); - final TargetTagAssigmentResult result = targetManagement.toggleTagAssignment(targetList, targTagName); + final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, targTagName); notification.displaySuccess(HawkbitCommonUtil.getTargetTagAssigmentMsg(targTagName, result, i18n)); if (result.getAssigned() >= 1 && managementUIState.getTargetTableFilters().isNoTagSelected()) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java index 87fcbe922..023979ead 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java @@ -19,15 +19,9 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.EntityEvent; -import org.eclipse.hawkbit.eventbus.event.RolloutChangeEvent; -import org.eclipse.hawkbit.eventbus.event.RolloutGroupChangeEvent; -import org.eclipse.hawkbit.eventbus.event.TargetCreatedEvent; -import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent; -import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; -import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails; +import org.eclipse.hawkbit.ui.UIEventProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.core.context.SecurityContext; @@ -36,7 +30,6 @@ import org.springframework.security.web.context.HttpSessionSecurityContextReposi import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus.SessionEventBus; -import com.google.common.collect.Sets; import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.Subscribe; import com.vaadin.server.VaadinSession; @@ -49,15 +42,15 @@ import com.vaadin.ui.UI; * {@link com.google.common.eventbus.EventBus} and store them first in an queue * where they will dispatched every 2 seconds to the {@link EventBus} in a * Vaadin access thread {@link UI#access(Runnable)}. - * + * * This strategy avoids blocking UIs when too many events are fired and * dispatched to the UI thread. The UI will freeze in the time. To avoid that * all events are collected first and same events are merged to a list of events * before they dispatched to the UI thread. - * + * * The strategy also verifies the current tenant in the session with the tenant * in the event and only forwards event from the right tenant to the UI. - * + * */ public class DelayedEventBusPushStrategy implements EventPushStrategy { @@ -71,16 +64,11 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy { private ScheduledFuture jobHandle; - /** - * only events defined in the set are dispatched to the session event bus. - */ - private static final Set> UI_EVENTS = Sets.newHashSet(TargetInfoUpdateEvent.class, - TargetCreatedEvent.class, TargetDeletedEvent.class, RolloutChangeEvent.class, RolloutGroupChangeEvent.class, - TargetTagCreatedBulkEvent.class, DistributionSetTagCreatedBulkEvent.class); + private final UIEventProvider eventProvider; /** * Constructor. - * + * * @param eventBus * the session event bus to where the events should be dispatched * @param systemEventBus @@ -88,9 +76,10 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy { * back-end */ public DelayedEventBusPushStrategy(final SessionEventBus eventBus, - final com.google.common.eventbus.EventBus systemEventBus) { + final com.google.common.eventbus.EventBus systemEventBus, final UIEventProvider eventProvider) { this.eventBus = eventBus; this.systemEventBus = systemEventBus; + this.eventProvider = eventProvider; } /** @@ -105,12 +94,22 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy { @AllowConcurrentEvents public void dispatch(final org.eclipse.hawkbit.eventbus.event.Event event) { // to dispatch too many events which are not interested on the UI - if (UI_EVENTS.contains(event.getClass()) && !queue.offer(event)) { + if (!isEventProvided(event)) { + LOG.trace("Event is not supported in the UI!!! Dropped event is {}", event); + return; + } + + if (!queue.offer(event)) { LOG.warn("Deque limit is reached, cannot add more events!!! Dropped event is {}", event); return; } } + private boolean isEventProvided(final org.eclipse.hawkbit.eventbus.event.Event event) { + return eventProvider.getSingleEvents().contains(event.getClass()) + || eventProvider.getBulkEvents().contains(event.getClass()); + } + @Override public void init(final UI vaadinUI) { LOG.debug("Initialize delayed event push strategy"); @@ -131,7 +130,7 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy { /** * Checks if the tenant within the event is equal with the current tenant in * the context. - * + * * @param userContext * the security context of the current session * @param event @@ -206,37 +205,43 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy { final SecurityContext oldContext = SecurityContextHolder.getContext(); try { SecurityContextHolder.setContext(userContext); + vaadinUI.access(() -> { if (vaadinSession.getState() != State.OPEN) { return; } - fowardEvents(events, userContext); - - // send a list of events, because ui performance issues - publishEventAsList(events, userContext, TargetInfoUpdateEvent.class); - publishEventAsList(events, userContext, TargetCreatedEvent.class); - publishEventAsList(events, userContext, TargetDeletedEvent.class); + fowardSingleEvents(events, userContext); + fowardBulkEvents(events, userContext); }); } finally { SecurityContextHolder.setContext(oldContext); } } - private void publishEventAsList(final List events, - final SecurityContext userContext, final Class eventType) { - final List bulkEvents = events.stream() - .filter(event -> DelayedEventBusPushStrategy.this.eventSecurityCheck(userContext, event) - && eventType.isInstance(event)) - .collect(Collectors.toList()); - if (bulkEvents.isEmpty()) { - return; - } - eventBus.publish(vaadinUI, bulkEvents); + private void fowardBulkEvents(final List events, + final SecurityContext userContext) { + final Set> filterBulkEvenTypes = eventProvider.getFilteredBulkEventsType(events); + publishBulkEvent(events, userContext, filterBulkEvenTypes); } - private void fowardEvents(final List events, + private void publishBulkEvent(final List events, + final SecurityContext userContext, final Set> filterBulkEvenTypes) { + for (final Class bulkType : filterBulkEvenTypes) { + final List listBulkEvents = events.stream() + .filter(event -> DelayedEventBusPushStrategy.this.eventSecurityCheck(userContext, event) + && bulkType.isInstance(event)) + .collect(Collectors.toList()); + if (!listBulkEvents.isEmpty()) { + eventBus.publish(vaadinUI, listBulkEvents); + } + } + } + + private void fowardSingleEvents(final List events, final SecurityContext userContext) { - events.stream().filter(event -> DelayedEventBusPushStrategy.this.eventSecurityCheck(userContext, event)) + events.stream() + .filter(event -> DelayedEventBusPushStrategy.this.eventSecurityCheck(userContext, event) + && eventProvider.getSingleEvents().contains(event.getClass())) .forEach(event -> eventBus.publish(vaadinUI, event)); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java index e697e220e..3f947cfd0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java @@ -25,13 +25,13 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.im.authentication.UserPrincipal; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; -import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult; +import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetInfo.PollStatus; -import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult; +import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus.Status; @@ -802,13 +802,16 @@ public final class HawkbitCommonUtil { * as string * @param version * as string + * @param type + * key as string * @return boolean as flag */ - public static boolean isDuplicate(final String name, final String version) { + public static boolean isDuplicate(final String name, final String version, final String type) { final SoftwareManagement swMgmtService = SpringContextHelper.getBean(SoftwareManagement.class); - final List swModulesList = swMgmtService.findSoftwareModuleByNameAndVersion(name, version); + final SoftwareModule swModule = swMgmtService.findSoftwareModuleByNameAndVersion(name, version, + swMgmtService.findSoftwareModuleTypeByName(type)); boolean duplicate = false; - if (swModulesList != null && !swModulesList.isEmpty()) { + if (swModule != null) { duplicate = true; } return duplicate; @@ -875,7 +878,7 @@ public final class HawkbitCommonUtil { * I18N * @return message */ - public static String getTargetTagAssigmentMsg(final String targTagName, final TargetTagAssigmentResult result, + public static String getTargetTagAssigmentMsg(final String targTagName, final TargetTagAssignmentResult result, final I18N i18n) { final StringBuilder formMsg = new StringBuilder(); final int assignedCount = result.getAssigned(); @@ -922,7 +925,7 @@ public final class HawkbitCommonUtil { * @return message */ public static String getDistributionTagAssignmentMsg(final String targTagName, - final DistributionSetTagAssigmentResult result, final I18N i18n) { + final DistributionSetTagAssignmentResult result, final I18N i18n) { final StringBuilder formMsg = new StringBuilder(); final int assignedCount = result.getAssigned(); final int alreadyAssignedCount = result.getAlreadyAssigned(); @@ -1359,12 +1362,12 @@ public final class HawkbitCommonUtil { * details of status and count * @return String */ - public static String getFormattedString(Map details) { - StringBuilder val = new StringBuilder(); + public static String getFormattedString(final Map details) { + final StringBuilder val = new StringBuilder(); if (details == null || details.isEmpty()) { return null; } - for (Entry entry : details.entrySet()) { + for (final Entry entry : details.entrySet()) { val.append(entry.getKey()).append(":").append(entry.getValue()).append(","); } return val.substring(0, val.length() - 1); @@ -1382,8 +1385,8 @@ public final class HawkbitCommonUtil { * label id * @return */ - public static String getStatusLabelDetailsInString(String value, String style, String id) { - StringBuilder val = new StringBuilder(); + public static String getStatusLabelDetailsInString(final String value, final String style, final String id) { + final StringBuilder val = new StringBuilder(); if (!Strings.isNullOrEmpty(value)) { val.append("value:").append(value).append(","); } diff --git a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/images/profile-pic-300px.jpg b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/images/profile-pic-300px.jpg deleted file mode 100644 index 664afaa35..000000000 Binary files a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/images/profile-pic-300px.jpg and /dev/null differ diff --git a/pom.xml b/pom.xml index 2415b9935..0c3207c13 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ 1.0.0 0.0.6.RELEASE - 7.6.3 + 7.6.4 ${vaadin.version} 7.4.0.1 2.2.0 @@ -84,6 +84,7 @@ + 1.1.0.Final 1.4 2.0M10 1.4.22 @@ -419,6 +420,11 @@ + + javax.validation + validation-api + ${validation-api.version} + javax.el javax.el-api