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/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/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-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-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/repository/SoftwareManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java index c6eab402a..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 @@ -259,7 +259,7 @@ 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} 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 afc6998ad..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 @@ -52,7 +52,7 @@ import org.eclipse.persistence.annotations.CascadeOnDelete; @NamedEntityGraph(name = "Action.all", attributeNodes = { @NamedAttributeNode("distributionSet"), @NamedAttributeNode(value = "target", subgraph = "target.ds") }, subgraphs = @NamedSubgraph(name = "target.ds", attributeNodes = @NamedAttributeNode("assignedDistributionSet"))) }) @Entity -public class Action extends TenantAwareBaseEntity implements Comparable { +public class Action extends TenantAwareBaseEntity { private static final long serialVersionUID = 1L; /** @@ -198,14 +198,6 @@ public class Action extends TenantAwareBaseEntity implements Comparable 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 @@ -254,26 +246,6 @@ public class Action extends TenantAwareBaseEntity implements Comparable return "Action [distributionSet=" + distributionSet + ", getId()=" + getId() + "]"; } - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof Action)) { - return false; - } - - return true; - } - /** * Action status as reported by the controller. * 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 f67229b69..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 @@ -140,24 +140,4 @@ public class ActionStatus extends TenantAwareBaseEntity { this.status = status; } - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof ActionStatus)) { - return false; - } - - return true; - } - } 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 709635095..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 @@ -53,24 +53,4 @@ public abstract class Artifact extends TenantAwareBaseEntity { public void setSize(final Long size) { this.size = size; } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof Artifact)) { - return false; - } - - return true; - } } 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 d0289acee..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 @@ -108,6 +108,11 @@ public abstract class BaseEntity implements Serializable, Identifiable { return optLockRevision; } + // for test purposes only + void setOptLockRevision(final long optLockRevision) { + this.optLockRevision = optLockRevision; + } + @Override public Long getId() { return id; @@ -135,6 +140,7 @@ 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; } @@ -154,7 +160,7 @@ public abstract class BaseEntity implements Serializable, Identifiable { if (obj == null) { return false; } - if (!(obj instanceof BaseEntity)) { + 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/DistributionSet.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java index 51b5e8074..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 @@ -150,26 +150,6 @@ public class DistributionSet extends NamedVersionedEntity { return actions; } - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof DistributionSet)) { - return false; - } - - return true; - } - public boolean isRequiredMigrationStep() { return requiredMigrationStep; } 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 f7dc791a4..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 @@ -285,24 +285,4 @@ public class DistributionSetType extends NamedEntity { return "DistributionSetType [key=" + key + ", isDeleted()=" + isDeleted() + ", getId()=" + getId() + "]"; } - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof DistributionSetType)) { - return false; - } - - return true; - } - } 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 d52e60e46..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 @@ -73,24 +73,4 @@ public class ExternalArtifactProvider extends NamedEntity { this.defaultSuffix = defaultSuffix; } - @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; - } - - @Override - public boolean equals(final Object obj) { // NOSONAR - as this is generated - 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/NamedEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java index d055c113e..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 @@ -60,24 +60,4 @@ public abstract class NamedEntity extends TenantAwareBaseEntity { public void setName(final String name) { this.name = name; } - - @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; - } - - @Override - public boolean equals(final Object obj) { // NOSONAR - as this is generated - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof NamedEntity)) { - return false; - } - - return true; - } } 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 2b126c72f..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 @@ -47,25 +47,4 @@ public abstract class NamedVersionedEntity extends NamedEntity { public void setVersion(final String version) { this.version = version; } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof NamedVersionedEntity)) { - return false; - } - - return true; - } - } 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 a596d10a9..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 @@ -231,24 +231,4 @@ public class Rollout extends NamedEntity { */ ERROR_STARTING; } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof Rollout)) { - return false; - } - - return true; - } } 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 97191b4f1..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 @@ -476,25 +476,4 @@ public class RolloutGroup extends NamedEntity { return this; } } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof RolloutGroup)) { - return false; - } - - return true; - } - } 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 8b58c5e3b..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 @@ -233,26 +233,6 @@ public class SoftwareModule extends NamedVersionedEntity { + ", revision=" + getOptLockRevision() + ", Id=" + getId() + ", type=" + getType().getName() + "]"; } - @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; - } - - @Override - public boolean equals(final Object obj) { // NOSONAR - as this is generated - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof SoftwareModule)) { - return false; - } - - return true; - } - /** * @return the assignedTo */ 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 59246d92e..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 @@ -114,24 +114,4 @@ public class SoftwareModuleType extends NamedEntity { public String toString() { return "SoftwareModuleType [key=" + key + ", getName()=" + getName() + ", getId()=" + getId() + "]"; } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof SoftwareModuleType)) { - return false; - } - - return true; - } } 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 8d5f5b832..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 @@ -56,24 +56,4 @@ public abstract class Tag extends NamedEntity implements Identifiable { public String toString() { return "Tag [getOptLockRevision()=" + getOptLockRevision() + ", getId()=" + getId() + "]"; } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof Tag)) { - return false; - } - - return true; - } } 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 f9e29118f..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 @@ -131,31 +131,6 @@ public class Target extends NamedEntity implements Persistable { securityToken = null; } - /** - * Note: For Target we extended the general strategy by adding controllerId - * as well. - * - * @see org.eclipse.hawkbit.repository.model.BaseEntity#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object obj) {// NOSONAR - as this is generated - if (obj == null) { - return false; - } - if (!(obj instanceof Target)) { - 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; } @@ -168,14 +143,6 @@ 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; } 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 c4e6fb1fe..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 @@ -55,24 +55,4 @@ public class TargetFilterQuery extends TenantAwareBaseEntity { public void setQuery(final String query) { this.query = query; } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof TargetFilterQuery)) { - return false; - } - - return true; - } } 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 index 97d757fb5..d03a4938a 100644 --- 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 @@ -99,9 +99,6 @@ public abstract class TenantAwareBaseEntity extends BaseEntity { if (!super.equals(obj)) { return false; } - if (!(obj instanceof TenantAwareBaseEntity)) { - return false; - } final TenantAwareBaseEntity other = (TenantAwareBaseEntity) obj; if (tenant == null) { if (other.tenant != null) { 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 efc82747a..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 @@ -52,54 +52,20 @@ public class TenantConfiguration extends TenantAwareBaseEntity implements Serial } - /** - * @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; } - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof TenantConfiguration)) { - return false; - } - - return true; - } - } 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/TargetManagementSearchTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java index 0438ac512..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 @@ -109,6 +109,14 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { both.add(TargetUpdateStatus.UNKNOWN); both.add(TargetUpdateStatus.PENDING); + // 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)); @@ -708,11 +716,14 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned")); - final List assignedtargets = targetManagement - .createTargets(TestDataUtil.generateTargets(10, "assigned")); + 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); @@ -727,8 +738,7 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement, distributionSetManagement); targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned")); - final List assignedtargets = targetManagement - .createTargets(TestDataUtil.generateTargets(10, "assigned")); + List assignedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned")); // set on installed and assign another one deploymentManagement.assignDistributionSet(installedSet, assignedtargets).getActions().forEach(actionId -> { @@ -739,11 +749,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { }); 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 @@ -754,8 +766,7 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement, distributionSetManagement); targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned")); - final List installedtargets = targetManagement - .createTargets(TestDataUtil.generateTargets(10, "assigned")); + List installedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned")); // set on installed and assign another one deploymentManagement.assignDistributionSet(installedSet, installedtargets).getActions().forEach(actionId -> { @@ -766,6 +777,10 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { }); 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); @@ -780,8 +795,7 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement, distributionSetManagement); targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned")); - final List installedtargets = targetManagement - .createTargets(TestDataUtil.generateTargets(10, "assigned")); + List installedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned")); // set on installed and assign another one deploymentManagement.assignDistributionSet(installedSet, installedtargets).getActions().forEach(actionId -> { @@ -792,6 +806,10 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { }); 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) 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-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-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 67e71ba4f..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 @@ -809,7 +809,7 @@ public final class HawkbitCommonUtil { public static boolean isDuplicate(final String name, final String version, final String type) { final SoftwareManagement swMgmtService = SpringContextHelper.getBean(SoftwareManagement.class); final SoftwareModule swModule = swMgmtService.findSoftwareModuleByNameAndVersion(name, version, - swMgmtService.findSoftwareModuleTypeByKey(type)); + swMgmtService.findSoftwareModuleTypeByName(type)); boolean duplicate = false; if (swModule != null) { duplicate = true; 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 f42236d07..0c3207c13 100644 --- a/pom.xml +++ b/pom.xml @@ -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