Removed boiler plate code. Added missing equals in model. Fixed sonar

issues.

Signed-off-by: Kai Zimmermann <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2016-03-26 09:26:48 +01:00
parent f237a1e508
commit 080f7d20e8
12 changed files with 247 additions and 113 deletions

View File

@@ -376,16 +376,10 @@ 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 +398,14 @@ public class ControllerManagement {
return actionRepository.save(mergedAction);
}
private void handleErrorOnAction(final Action mergedAction, final Target mergedTarget) {
// set action inactive
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 +422,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);

View File

@@ -534,7 +534,6 @@ public class DeploymentManagement {
return saveAction;
} else {
throw new CancelActionNotAllowedException(
"Action [id: " + action.getId() + "] is not active and cannot be canceled");
}
}

View File

@@ -915,7 +915,7 @@ public class DistributionSetManagement {
@Transactional
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
public List<DistributionSetType> createDistributionSetTypes(@NotNull final Collection<DistributionSetType> types) {
return types.stream().map(type -> createDistributionSetType(type)).collect(Collectors.toList());
return types.stream().map(this::createDistributionSetType).collect(Collectors.toList());
}
/**

View File

@@ -74,8 +74,6 @@ import com.google.common.eventbus.EventBus;
/**
* Business service facade for managing {@link Target}s.
*
*
*
*/
@Transactional(readOnly = true)
@Validated

View File

@@ -50,7 +50,7 @@ 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 TenantAwareBaseEntity implements Comparable<Action> {
private static final long serialVersionUID = 1L;
@@ -64,11 +64,11 @@ public class Action extends TenantAwareBaseEntity implements Comparable<Action>
* 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 TenantAwareBaseEntity implements Comparable<Action>
private List<ActionStatus> 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;
/**
@@ -305,21 +305,11 @@ public class Action extends TenantAwareBaseEntity implements Comparable<Action>
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;
@@ -332,11 +322,6 @@ public class Action extends TenantAwareBaseEntity implements Comparable<Action>
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(final Object obj) { // NOSONAR - as this is generated

View File

@@ -32,9 +32,6 @@ 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"),
@@ -42,10 +39,6 @@ import com.google.common.base.Splitter;
@NamedEntityGraph(name = "ActionStatus.withMessages", attributeNodes = { @NamedAttributeNode("messages") })
@Entity
public class ActionStatus extends TenantAwareBaseEntity {
/**
*
*/
private static final long serialVersionUID = 1L;
@Column(name = "target_occurred_at")
@@ -146,4 +139,55 @@ public class ActionStatus extends TenantAwareBaseEntity {
public void setStatus(final Status status) {
this.status = status;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((action == null) ? 0 : action.hashCode());
result = prime * result + ((messages == null) ? 0 : messages.hashCode());
result = prime * result + ((occurredAt == null) ? 0 : occurredAt.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final ActionStatus other = (ActionStatus) obj;
if (action == null) {
if (other.action != null) {
return false;
}
} else if (!action.equals(other.action)) {
return false;
}
if (messages == null) {
if (other.messages != null) {
return false;
}
} else if (!messages.equals(other.messages)) {
return false;
}
if (occurredAt == null) {
if (other.occurredAt != null) {
return false;
}
} else if (!occurredAt.equals(other.occurredAt)) {
return false;
}
if (status != other.status) {
return false;
}
return true;
}
}

View File

@@ -13,11 +13,7 @@ import javax.persistence.MappedSuperclass;
/**
* Tenant specific locally stored artifact representation that is used by
* {@link SoftwareModule} .
*
*
*
*
* {@link SoftwareModule}.
*/
@MappedSuperclass
public abstract class Artifact extends TenantAwareBaseEntity {
@@ -34,49 +30,73 @@ public abstract class Artifact extends TenantAwareBaseEntity {
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;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((md5Hash == null) ? 0 : md5Hash.hashCode());
result = prime * result + ((sha1Hash == null) ? 0 : sha1Hash.hashCode());
result = prime * result + ((size == null) ? 0 : size.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Artifact other = (Artifact) obj;
if (md5Hash == null) {
if (other.md5Hash != null) {
return false;
}
} else if (!md5Hash.equals(other.md5Hash)) {
return false;
}
if (sha1Hash == null) {
if (other.sha1Hash != null) {
return false;
}
} else if (!sha1Hash.equals(other.sha1Hash)) {
return false;
}
if (size == null) {
if (other.size != null) {
return false;
}
} else if (!size.equals(other.size)) {
return false;
}
return true;
}
}

View File

@@ -38,10 +38,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 = {
@@ -256,17 +252,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 +271,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,14 +283,58 @@ 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() + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((colour == null) ? 0 : colour.hashCode());
result = prime * result + (deleted ? 1231 : 1237);
result = prime * result + ((elements == null) ? 0 : elements.hashCode());
result = prime * result + ((key == null) ? 0 : key.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final DistributionSetType other = (DistributionSetType) obj;
if (colour == null) {
if (other.colour != null) {
return false;
}
} else if (!colour.equals(other.colour)) {
return false;
}
if (deleted != other.deleted) {
return false;
}
if (elements == null) {
if (other.elements != null) {
return false;
}
} else if (!elements.equals(other.elements)) {
return false;
}
if (key == null) {
if (other.key != null) {
return false;
}
} else if (!key.equals(other.key)) {
return false;
}
return true;
}
}

View File

@@ -12,14 +12,8 @@ import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
/**
* {@link TenantAwareBaseEntity} 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 TenantAwareBaseEntity {
@@ -67,4 +61,42 @@ public abstract class NamedEntity extends TenantAwareBaseEntity {
this.name = name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final NamedEntity other = (NamedEntity) obj;
if (description == null) {
if (other.description != null) {
return false;
}
} else if (!description.equals(other.description)) {
return false;
}
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
return true;
}
}

View File

@@ -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.
}
/**

View File

@@ -78,4 +78,41 @@ public class TenantMetaData extends BaseEntity {
this.tenant = tenant;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((defaultDsType == null) ? 0 : defaultDsType.hashCode());
result = prime * result + ((tenant == null) ? 0 : tenant.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final TenantMetaData other = (TenantMetaData) obj;
if (defaultDsType == null) {
if (other.defaultDsType != null) {
return false;
}
} else if (!defaultDsType.equals(other.defaultDsType)) {
return false;
}
if (tenant == null) {
if (other.tenant != null) {
return false;
}
} else if (!tenant.equals(other.tenant)) {
return false;
}
return true;
}
}

View File

@@ -54,15 +54,11 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Stories("Target Management")
public class TargetManagementTest extends AbstractIntegrationTest {
@Test
@Test(expected = TenantNotExistException.class)
@Description("Ensures that targets cannot be created e.g. in plug'n play scenarios when tenant does not exists.")
@WithUser(tenantId = "tenantWhichDoesNotExists", allSpPermissions = true, autoCreateTenant = false)
public void createTargetForTenantWhichDoesNotExistThrowsTenantNotExistException() {
try {
targetManagement.createTarget(new Target("targetId123"));
fail("tenant not exist");
} catch (final TenantNotExistException e) {
}
targetManagement.createTarget(new Target("targetId123"));
}
@Test