Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1509] Sync Target type with SW and DS types #1512

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@
* {@link Target}
*
*/
public interface TargetType extends NamedEntity {
public interface TargetType extends Type {

/**
* Maximum length of color in Management UI.
* Target type doesn't support soft-delete so all target type instandces re not deleted.
*
* @return <code>false</code>
*/
int COLOUR_MAX_SIZE = 16;
@Override
default boolean isDeleted() {
return false;
}

/**
* @return immutable set of optional {@link DistributionSetType}s
Expand All @@ -32,18 +38,6 @@ public interface TargetType extends NamedEntity {
*/
Set<Target> getTargets();

/**
* Checks if the given {@link DistributionSetType} is in
* {@link #getCompatibleDistributionSetTypes()}.
*
* @param distributionSetType
* search for
* @return <code>true</code> if found
*/
default boolean containsCompatibleDistributionSetType(final DistributionSetType distributionSetType) {
return containsCompatibleDistributionSetType(distributionSetType.getId());
}

/**
* Checks if the given {@link DistributionSetType} is in
* {@link #getCompatibleDistributionSetTypes()}.
Expand All @@ -64,9 +58,4 @@ default boolean containsCompatibleDistributionSetType(final Long distributionSet
* @return the resulting target type
*/
TargetType removeDistributionSetType(final Long dsTypeId);

/**
* @return get color code to be used in management UI views.
*/
String getColour();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;

import java.io.Serial;

/**
* {@link TenantAwareBaseEntity} extension for all entities that are named in
* addition to their technical ID.
Expand All @@ -26,15 +28,17 @@
// sub entities
@SuppressWarnings("squid:S2160")
public abstract class AbstractJpaNamedEntity extends AbstractJpaTenantAwareBaseEntity implements NamedEntity {

@Serial
private static final long serialVersionUID = 1L;

@Column(name = "name", nullable = false, length = NamedEntity.NAME_MAX_SIZE)
@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE)
@Column(name = "name", nullable = false, length = NAME_MAX_SIZE)
@Size(min = 1, max = NAME_MAX_SIZE)
@NotNull
private String name;

@Column(name = "description", length = NamedEntity.DESCRIPTION_MAX_SIZE)
@Size(max = NamedEntity.DESCRIPTION_MAX_SIZE)
@Column(name = "description", length = DESCRIPTION_MAX_SIZE)
@Size(max = DESCRIPTION_MAX_SIZE)
private String description;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.repository.jpa.model;

import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
import org.eclipse.hawkbit.repository.model.Type;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serial;

/**
* {@link TenantAwareBaseEntity} extension for all entities that are named in
* addition to their technical ID.
*/
@MappedSuperclass
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for sub entities
@SuppressWarnings("squid:S2160")
public abstract class AbstractJpaTypeEntity extends AbstractJpaNamedEntity implements Type {

@Serial
private static final long serialVersionUID = 1L;

@Column(name = "type_key", nullable = false, updatable = false, length = KEY_MAX_SIZE)
@Size(min = 1, max = KEY_MAX_SIZE)
@NotNull
private String key;

@Column(name = "colour", length = COLOUR_MAX_SIZE)
@Size(max = COLOUR_MAX_SIZE)
private String colour;

/**
* Default constructor.
*/
protected AbstractJpaTypeEntity() {
// Default constructor needed for JPA entities
}

/**
* Parameterized constructor.
*
* @param key
* of the {@link Type}
* @param colour
* of the {@link Type}
*/
AbstractJpaTypeEntity(final String name, final String description, final String key, final String colour) {
super(name, description);
this.key = key;
this.colour = colour;
}

@Override
public String getKey() {
return key;
}

@Override
public String getColour() {
return colour;
}

public void setKey(final String key) {
this.key = key;
}

public void setColour(final String colour) {
this.colour = colour;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serial;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand All @@ -54,23 +53,16 @@
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
// sub entities
@SuppressWarnings("squid:S2160")
public class JpaDistributionSetType extends AbstractJpaNamedEntity implements DistributionSetType, EventAwareEntity {
public class JpaDistributionSetType extends AbstractJpaTypeEntity implements DistributionSetType, EventAwareEntity {

@Serial
private static final long serialVersionUID = 1L;

@CascadeOnDelete
@OneToMany(mappedBy = "dsType", targetEntity = DistributionSetTypeElement.class, cascade = {
CascadeType.PERSIST }, fetch = FetchType.EAGER, orphanRemoval = true)
private Set<DistributionSetTypeElement> elements;

@Column(name = "type_key", nullable = false, updatable = false, length = DistributionSetType.KEY_MAX_SIZE)
@Size(min = 1, max = DistributionSetType.KEY_MAX_SIZE)
@NotNull
private String key;

@Column(name = "colour", nullable = true, length = DistributionSetType.COLOUR_MAX_SIZE)
@Size(max = DistributionSetType.COLOUR_MAX_SIZE)
private String colour;

@Column(name = "deleted")
private boolean deleted;

Expand Down Expand Up @@ -109,9 +101,7 @@ public JpaDistributionSetType(final String key, final String name, final String
* of the type. It will be null by default
*/
public JpaDistributionSetType(final String key, final String name, final String description, final String colour) {
super(name, description);
this.key = key;
this.colour = colour;
super(name, description, key, colour);
}

@Override
Expand Down Expand Up @@ -205,15 +195,6 @@ public JpaDistributionSetType removeModuleType(final Long smTypeId) {
return this;
}

@Override
public String getKey() {
return key;
}

public void setKey(final String key) {
this.key = key;
}

@Override
public boolean checkComplete(final DistributionSet distributionSet) {
final List<SoftwareModuleType> smTypes = distributionSet.getModules().stream().map(SoftwareModule::getType)
Expand All @@ -224,15 +205,6 @@ public boolean checkComplete(final DistributionSet distributionSet) {
return smTypes.containsAll(getMandatoryModuleTypes());
}

@Override
public String getColour() {
return colour;
}

public void setColour(final String colour) {
this.colour = colour;
}

public Set<DistributionSetTypeElement> getElements() {
if (elements == null) {
return Collections.emptySet();
Expand All @@ -243,7 +215,7 @@ public Set<DistributionSetTypeElement> getElements() {

@Override
public String toString() {
return "DistributionSetType [key=" + key + ", isDeleted()=" + isDeleted() + ", getId()=" + getId() + "]";
return "DistributionSetType [key=" + getKey() + ", isDeleted()=" + isDeleted() + ", getId()=" + getId() + "]";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.eclipse.hawkbit.repository.event.remote.SoftwareModuleTypeDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleTypeCreatedEvent;
Expand All @@ -25,6 +23,8 @@
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
import org.eclipse.persistence.descriptors.DescriptorEvent;

import java.io.Serial;

/**
* Type of a software modules.
*
Expand All @@ -38,22 +38,15 @@
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
// sub entities
@SuppressWarnings("squid:S2160")
public class JpaSoftwareModuleType extends AbstractJpaNamedEntity implements SoftwareModuleType, EventAwareEntity {
private static final long serialVersionUID = 1L;
public class JpaSoftwareModuleType extends AbstractJpaTypeEntity implements SoftwareModuleType, EventAwareEntity {

@Column(name = "type_key", nullable = false, length = SoftwareModuleType.KEY_MAX_SIZE)
@Size(min = 1, max = SoftwareModuleType.KEY_MAX_SIZE)
@NotNull
private String key;
@Serial
private static final long serialVersionUID = 1L;

@Column(name = "max_ds_assignments", nullable = false)
@Min(1)
private int maxAssignments;

@Column(name = "colour", nullable = true, length = SoftwareModuleType.COLOUR_MAX_SIZE)
@Size(max = SoftwareModuleType.COLOUR_MAX_SIZE)
private String colour;

@Column(name = "deleted")
private boolean deleted;

Expand Down Expand Up @@ -90,11 +83,8 @@ public JpaSoftwareModuleType(final String key, final String name, final String d
*/
public JpaSoftwareModuleType(final String key, final String name, final String description,
final int maxAssignments, final String colour) {
this.key = key;
super(name, description, key, colour);
this.maxAssignments = maxAssignments;
setDescription(description);
setName(name);
this.colour = colour;
}

/**
Expand All @@ -108,11 +98,6 @@ public void setMaxAssignments(final int maxAssignments) {
this.maxAssignments = maxAssignments;
}

@Override
public String getKey() {
return key;
}

@Override
public int getMaxAssignments() {
return maxAssignments;
Expand All @@ -127,22 +112,9 @@ public void setDeleted(final boolean deleted) {
this.deleted = deleted;
}

@Override
public String getColour() {
return colour;
}

public void setColour(final String colour) {
this.colour = colour;
}

@Override
public String toString() {
return "SoftwareModuleType [key=" + key + ", getName()=" + getName() + ", getId()=" + getId() + "]";
}

public void setKey(final String key) {
this.key = key;
return "SoftwareModuleType [key=" + getKey() + ", getName()=" + getName() + ", getId()=" + getId() + "]";
}

@Override
Expand Down
Loading