Modified EOL from windows to unix.

This commit is contained in:
Gaurav
2016-07-29 12:33:10 +02:00
parent f2853e6d9f
commit e32d6b1b3e
9 changed files with 3388 additions and 3388 deletions

View File

@@ -1,199 +1,199 @@
/** /**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others. * Copyright (c) 2015 Bosch Software Innovations GmbH and others.
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
*/ */
package org.eclipse.hawkbit.repository.jpa.model; package org.eclipse.hawkbit.repository.jpa.model;
import java.util.List; import java.util.List;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.ConstraintMode; import javax.persistence.ConstraintMode;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EnumType; import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.ForeignKey; import javax.persistence.ForeignKey;
import javax.persistence.Index; import javax.persistence.Index;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.NamedAttributeNode; import javax.persistence.NamedAttributeNode;
import javax.persistence.NamedEntityGraph; import javax.persistence.NamedEntityGraph;
import javax.persistence.NamedEntityGraphs; import javax.persistence.NamedEntityGraphs;
import javax.persistence.NamedSubgraph; import javax.persistence.NamedSubgraph;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.hawkbit.repository.eventbus.event.ActionCreatedEvent; import org.eclipse.hawkbit.repository.eventbus.event.ActionCreatedEvent;
import org.eclipse.hawkbit.repository.eventbus.event.ActionPropertyChangeEvent; import org.eclipse.hawkbit.repository.eventbus.event.ActionPropertyChangeEvent;
import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityPropertyChangeHelper; import org.eclipse.hawkbit.repository.jpa.model.helper.EntityPropertyChangeHelper;
import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder;
import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.persistence.annotations.CascadeOnDelete; import org.eclipse.persistence.annotations.CascadeOnDelete;
import org.eclipse.persistence.descriptors.DescriptorEvent; import org.eclipse.persistence.descriptors.DescriptorEvent;
/** /**
* JPA implementation of {@link Action}. * JPA implementation of {@link Action}.
*/ */
@Table(name = "sp_action", indexes = { @Index(name = "sp_idx_action_01", columnList = "tenant,distribution_set"), @Table(name = "sp_action", indexes = { @Index(name = "sp_idx_action_01", columnList = "tenant,distribution_set"),
@Index(name = "sp_idx_action_02", columnList = "tenant,target,active"), @Index(name = "sp_idx_action_02", columnList = "tenant,target,active"),
@Index(name = "sp_idx_action_prim", columnList = "tenant,id") }) @Index(name = "sp_idx_action_prim", columnList = "tenant,id") })
@NamedEntityGraphs({ @NamedEntityGraph(name = "Action.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }), @NamedEntityGraphs({ @NamedEntityGraph(name = "Action.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }),
@NamedEntityGraph(name = "Action.all", 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 @Entity
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for // exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
// sub entities // sub entities
@SuppressWarnings("squid:S2160") @SuppressWarnings("squid:S2160")
public class JpaAction extends AbstractJpaTenantAwareBaseEntity implements Action,EventAwareEntity<JpaAction> { public class JpaAction extends AbstractJpaTenantAwareBaseEntity implements Action,EventAwareEntity<JpaAction> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ManyToOne(fetch = FetchType.LAZY) @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 JpaDistributionSet distributionSet; private JpaDistributionSet distributionSet;
@ManyToOne(fetch = FetchType.LAZY) @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 JpaTarget target; private JpaTarget target;
@Column(name = "active") @Column(name = "active")
private boolean active; private boolean active;
@Column(name = "action_type", nullable = false) @Column(name = "action_type", nullable = false)
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private ActionType actionType; private ActionType actionType;
@Column(name = "forced_time") @Column(name = "forced_time")
private long forcedTime; private long forcedTime;
@Column(name = "status") @Column(name = "status")
private Status status; private Status status;
@CascadeOnDelete @CascadeOnDelete
@OneToMany(mappedBy = "action", targetEntity = JpaActionStatus.class, fetch = FetchType.LAZY, cascade = { @OneToMany(mappedBy = "action", targetEntity = JpaActionStatus.class, fetch = FetchType.LAZY, cascade = {
CascadeType.REMOVE }) CascadeType.REMOVE })
private List<ActionStatus> actionStatus; private List<ActionStatus> actionStatus;
@ManyToOne(fetch = FetchType.LAZY) @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 JpaRolloutGroup rolloutGroup; private JpaRolloutGroup rolloutGroup;
@ManyToOne(fetch = FetchType.LAZY) @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 JpaRollout rollout; private JpaRollout rollout;
@Override @Override
public DistributionSet getDistributionSet() { public DistributionSet getDistributionSet() {
return distributionSet; return distributionSet;
} }
@Override @Override
public void setDistributionSet(final DistributionSet distributionSet) { public void setDistributionSet(final DistributionSet distributionSet) {
this.distributionSet = (JpaDistributionSet) distributionSet; this.distributionSet = (JpaDistributionSet) distributionSet;
} }
public void setActive(final boolean active) { public void setActive(final boolean active) {
this.active = active; this.active = active;
} }
@Override @Override
public Status getStatus() { public Status getStatus() {
return status; return status;
} }
@Override @Override
public void setStatus(final Status status) { public void setStatus(final Status status) {
this.status = status; this.status = status;
} }
@Override @Override
public boolean isActive() { public boolean isActive() {
return active; return active;
} }
public void setActionType(final ActionType actionType) { public void setActionType(final ActionType actionType) {
this.actionType = actionType; this.actionType = actionType;
} }
@Override @Override
public ActionType getActionType() { public ActionType getActionType() {
return actionType; return actionType;
} }
@Override @Override
public List<ActionStatus> getActionStatus() { public List<ActionStatus> getActionStatus() {
return actionStatus; return actionStatus;
} }
@Override @Override
public void setTarget(final Target target) { public void setTarget(final Target target) {
this.target = (JpaTarget) target; this.target = (JpaTarget) target;
} }
@Override @Override
public Target getTarget() { public Target getTarget() {
return target; return target;
} }
@Override @Override
public long getForcedTime() { public long getForcedTime() {
return forcedTime; return forcedTime;
} }
public void setForcedTime(final long forcedTime) { public void setForcedTime(final long forcedTime) {
this.forcedTime = forcedTime; this.forcedTime = forcedTime;
} }
@Override @Override
public RolloutGroup getRolloutGroup() { public RolloutGroup getRolloutGroup() {
return rolloutGroup; return rolloutGroup;
} }
public void setRolloutGroup(final RolloutGroup rolloutGroup) { public void setRolloutGroup(final RolloutGroup rolloutGroup) {
this.rolloutGroup = (JpaRolloutGroup) rolloutGroup; this.rolloutGroup = (JpaRolloutGroup) rolloutGroup;
} }
@Override @Override
public Rollout getRollout() { public Rollout getRollout() {
return rollout; return rollout;
} }
public void setRollout(final Rollout rollout) { public void setRollout(final Rollout rollout) {
this.rollout = (JpaRollout) rollout; this.rollout = (JpaRollout) rollout;
} }
@Override @Override
public String toString() { public String toString() {
return "Action [distributionSet=" + distributionSet + ", getId()=" + getId() + "]"; return "Action [distributionSet=" + distributionSet + ", getId()=" + getId() + "]";
} }
@Override @Override
public void fireCreateEvent(final JpaAction jpaAction, final DescriptorEvent descriptorEvent) { public void fireCreateEvent(final JpaAction jpaAction, final DescriptorEvent descriptorEvent) {
AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit( () ->EventBusHolder.getInstance().getEventBus().post(new ActionCreatedEvent(jpaAction))); AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit( () ->EventBusHolder.getInstance().getEventBus().post(new ActionCreatedEvent(jpaAction)));
} }
@Override @Override
public void fireUpdateEvent(final JpaAction jpaAction, final DescriptorEvent descriptorEvent) { public void fireUpdateEvent(final JpaAction jpaAction, final DescriptorEvent descriptorEvent) {
AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit( () ->EventBusHolder.getInstance().getEventBus(). AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit( () ->EventBusHolder.getInstance().getEventBus().
post(new ActionPropertyChangeEvent(jpaAction, EntityPropertyChangeHelper.getChangeSet(Action.class, descriptorEvent)))); post(new ActionPropertyChangeEvent(jpaAction, EntityPropertyChangeHelper.getChangeSet(Action.class, descriptorEvent))));
} }
@Override @Override
public void fireDeleteEvent(final JpaAction jpaAction, final DescriptorEvent descriptorEvent) { public void fireDeleteEvent(final JpaAction jpaAction, final DescriptorEvent descriptorEvent) {
} }
} }

View File

@@ -1,320 +1,320 @@
/** /**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others. * Copyright (c) 2015 Bosch Software Innovations GmbH and others.
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
*/ */
package org.eclipse.hawkbit.repository.jpa.model; package org.eclipse.hawkbit.repository.jpa.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.ConstraintMode; import javax.persistence.ConstraintMode;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.ForeignKey; import javax.persistence.ForeignKey;
import javax.persistence.Index; import javax.persistence.Index;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.JoinTable; import javax.persistence.JoinTable;
import javax.persistence.ManyToMany; import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.NamedAttributeNode; import javax.persistence.NamedAttributeNode;
import javax.persistence.NamedEntityGraph; import javax.persistence.NamedEntityGraph;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.eclipse.hawkbit.repository.eventbus.event.AbstractPropertyChangeEvent; import org.eclipse.hawkbit.repository.eventbus.event.AbstractPropertyChangeEvent;
import org.eclipse.hawkbit.repository.eventbus.event.DistributionCreatedEvent; import org.eclipse.hawkbit.repository.eventbus.event.DistributionCreatedEvent;
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetUpdateEvent; import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetUpdateEvent;
import org.eclipse.hawkbit.repository.exception.DistributionSetTypeUndefinedException; import org.eclipse.hawkbit.repository.exception.DistributionSetTypeUndefinedException;
import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException; import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException;
import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityPropertyChangeHelper; import org.eclipse.hawkbit.repository.jpa.model.helper.EntityPropertyChangeHelper;
import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder;
import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.DistributionSet; 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.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetInfo;
import org.eclipse.persistence.annotations.CascadeOnDelete; import org.eclipse.persistence.annotations.CascadeOnDelete;
import org.eclipse.persistence.descriptors.DescriptorEvent; import org.eclipse.persistence.descriptors.DescriptorEvent;
/** /**
* Jpa implementation of {@link DistributionSet}. * Jpa implementation of {@link DistributionSet}.
* *
*/ */
@Entity @Entity
@Table(name = "sp_distribution_set", uniqueConstraints = { @Table(name = "sp_distribution_set", uniqueConstraints = {
@UniqueConstraint(columnNames = { "name", "version", "tenant" }, name = "uk_distrib_set") }, indexes = { @UniqueConstraint(columnNames = { "name", "version", "tenant" }, name = "uk_distrib_set") }, indexes = {
@Index(name = "sp_idx_distribution_set_01", columnList = "tenant,deleted,name,complete"), @Index(name = "sp_idx_distribution_set_01", columnList = "tenant,deleted,name,complete"),
@Index(name = "sp_idx_distribution_set_02", columnList = "tenant,required_migration_step"), @Index(name = "sp_idx_distribution_set_02", columnList = "tenant,required_migration_step"),
@Index(name = "sp_idx_distribution_set_prim", columnList = "tenant,id") }) @Index(name = "sp_idx_distribution_set_prim", columnList = "tenant,id") })
@NamedEntityGraph(name = "DistributionSet.detail", attributeNodes = { @NamedAttributeNode("modules"), @NamedEntityGraph(name = "DistributionSet.detail", attributeNodes = { @NamedAttributeNode("modules"),
@NamedAttributeNode("tags"), @NamedAttributeNode("type") }) @NamedAttributeNode("tags"), @NamedAttributeNode("type") })
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for // exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
// sub entities // sub entities
@SuppressWarnings("squid:S2160") @SuppressWarnings("squid:S2160")
public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implements DistributionSet,EventAwareEntity<JpaDistributionSet> { public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implements DistributionSet,EventAwareEntity<JpaDistributionSet> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final String COMPLETE = "complete"; private static final String COMPLETE = "complete";
@Column(name = "required_migration_step") @Column(name = "required_migration_step")
private boolean requiredMigrationStep; private boolean requiredMigrationStep;
@ManyToMany(targetEntity = JpaSoftwareModule.class, fetch = FetchType.LAZY) @ManyToMany(targetEntity = JpaSoftwareModule.class, fetch = FetchType.LAZY)
@JoinTable(name = "sp_ds_module", joinColumns = { @JoinTable(name = "sp_ds_module", joinColumns = {
@JoinColumn(name = "ds_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_ds")) }, inverseJoinColumns = { @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 = "module_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_module")) })
private final Set<SoftwareModule> modules = new HashSet<>(); private final Set<SoftwareModule> modules = new HashSet<>();
@ManyToMany(targetEntity = JpaDistributionSetTag.class) @ManyToMany(targetEntity = JpaDistributionSetTag.class)
@JoinTable(name = "sp_ds_dstag", joinColumns = { @JoinTable(name = "sp_ds_dstag", joinColumns = {
@JoinColumn(name = "ds", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_ds")) }, inverseJoinColumns = { @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 = "TAG", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_tag")) })
private Set<DistributionSetTag> tags = new HashSet<>(); private Set<DistributionSetTag> tags = new HashSet<>();
@Column(name = "deleted") @Column(name = "deleted")
private boolean deleted; private boolean deleted;
@OneToMany(mappedBy = "assignedDistributionSet", targetEntity = JpaTarget.class, fetch = FetchType.LAZY) @OneToMany(mappedBy = "assignedDistributionSet", targetEntity = JpaTarget.class, fetch = FetchType.LAZY)
private List<Target> assignedToTargets; private List<Target> assignedToTargets;
@OneToMany(mappedBy = "installedDistributionSet", targetEntity = JpaTargetInfo.class, fetch = FetchType.LAZY) @OneToMany(mappedBy = "installedDistributionSet", targetEntity = JpaTargetInfo.class, fetch = FetchType.LAZY)
private List<TargetInfo> installedAtTargets; private List<TargetInfo> installedAtTargets;
@OneToMany(mappedBy = "distributionSet", targetEntity = JpaAction.class, fetch = FetchType.LAZY) @OneToMany(mappedBy = "distributionSet", targetEntity = JpaAction.class, fetch = FetchType.LAZY)
private List<Action> actions; private List<Action> actions;
@CascadeOnDelete @CascadeOnDelete
@OneToMany(fetch = FetchType.LAZY, targetEntity = JpaDistributionSetMetadata.class, cascade = { @OneToMany(fetch = FetchType.LAZY, targetEntity = JpaDistributionSetMetadata.class, cascade = {
CascadeType.REMOVE }) CascadeType.REMOVE })
@JoinColumn(name = "ds_id", insertable = false, updatable = false) @JoinColumn(name = "ds_id", insertable = false, updatable = false)
private final List<DistributionSetMetadata> metadata = new ArrayList<>(); private final List<DistributionSetMetadata> metadata = new ArrayList<>();
@ManyToOne(fetch = FetchType.LAZY, targetEntity = JpaDistributionSetType.class) @ManyToOne(fetch = FetchType.LAZY, targetEntity = JpaDistributionSetType.class)
@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; private DistributionSetType type;
@Column(name = "complete") @Column(name = "complete")
private boolean complete; private boolean complete;
/** /**
* Default constructor. * Default constructor.
*/ */
public JpaDistributionSet() { public JpaDistributionSet() {
super(); super();
} }
/** /**
* Parameterized constructor. * Parameterized constructor.
* *
* @param name * @param name
* of the {@link DistributionSet} * of the {@link DistributionSet}
* @param version * @param version
* of the {@link DistributionSet} * of the {@link DistributionSet}
* @param description * @param description
* of the {@link DistributionSet} * of the {@link DistributionSet}
* @param type * @param type
* of the {@link DistributionSet} * of the {@link DistributionSet}
* @param moduleList * @param moduleList
* {@link SoftwareModule}s of the {@link DistributionSet} * {@link SoftwareModule}s of the {@link DistributionSet}
*/ */
public JpaDistributionSet(final String name, final String version, final String description, public JpaDistributionSet(final String name, final String version, final String description,
final DistributionSetType type, final Collection<SoftwareModule> moduleList) { final DistributionSetType type, final Collection<SoftwareModule> moduleList) {
super(name, version, description); super(name, version, description);
this.type = type; this.type = type;
if (moduleList != null) { if (moduleList != null) {
moduleList.forEach(this::addModule); moduleList.forEach(this::addModule);
} }
if (this.type != null) { if (this.type != null) {
complete = this.type.checkComplete(this); complete = this.type.checkComplete(this);
} }
} }
@Override @Override
public Set<DistributionSetTag> getTags() { public Set<DistributionSetTag> getTags() {
return tags; return tags;
} }
@Override @Override
public boolean isDeleted() { public boolean isDeleted() {
return deleted; return deleted;
} }
@Override @Override
public List<DistributionSetMetadata> getMetadata() { public List<DistributionSetMetadata> getMetadata() {
return Collections.unmodifiableList(metadata); return Collections.unmodifiableList(metadata);
} }
public List<Action> getActions() { public List<Action> getActions() {
return actions; return actions;
} }
@Override @Override
public boolean isRequiredMigrationStep() { public boolean isRequiredMigrationStep() {
return requiredMigrationStep; return requiredMigrationStep;
} }
@Override @Override
public DistributionSet setDeleted(final boolean deleted) { public DistributionSet setDeleted(final boolean deleted) {
this.deleted = deleted; this.deleted = deleted;
return this; return this;
} }
@Override @Override
public DistributionSet setRequiredMigrationStep(final boolean isRequiredMigrationStep) { public DistributionSet setRequiredMigrationStep(final boolean isRequiredMigrationStep) {
requiredMigrationStep = isRequiredMigrationStep; requiredMigrationStep = isRequiredMigrationStep;
return this; return this;
} }
public DistributionSet setTags(final Set<DistributionSetTag> tags) { public DistributionSet setTags(final Set<DistributionSetTag> tags) {
this.tags = tags; this.tags = tags;
return this; return this;
} }
@Override @Override
public List<Target> getAssignedTargets() { public List<Target> getAssignedTargets() {
return assignedToTargets; return assignedToTargets;
} }
@Override @Override
public List<TargetInfo> getInstalledTargets() { public List<TargetInfo> getInstalledTargets() {
return installedAtTargets; return installedAtTargets;
} }
@Override @Override
public String toString() { public String toString() {
return "DistributionSet [getName()=" + getName() + ", getOptLockRevision()=" + getOptLockRevision() return "DistributionSet [getName()=" + getName() + ", getOptLockRevision()=" + getOptLockRevision()
+ ", getId()=" + getId() + "]"; + ", getId()=" + getId() + "]";
} }
@Override @Override
public Set<SoftwareModule> getModules() { public Set<SoftwareModule> getModules() {
return Collections.unmodifiableSet(modules); return Collections.unmodifiableSet(modules);
} }
@Override @Override
public boolean addModule(final SoftwareModule softwareModule) { public boolean addModule(final SoftwareModule softwareModule) {
// we cannot allow that modules are added without a type defined // we cannot allow that modules are added without a type defined
if (type == null) { if (type == null) {
throw new DistributionSetTypeUndefinedException(); throw new DistributionSetTypeUndefinedException();
} }
// check if it is allowed to such a module to this DS type // check if it is allowed to such a module to this DS type
if (!type.containsModuleType(softwareModule.getType())) { if (!type.containsModuleType(softwareModule.getType())) {
throw new UnsupportedSoftwareModuleForThisDistributionSetException(); throw new UnsupportedSoftwareModuleForThisDistributionSetException();
} }
final Optional<SoftwareModule> found = modules.stream() final Optional<SoftwareModule> found = modules.stream()
.filter(module -> module.getId().equals(softwareModule.getId())).findFirst(); .filter(module -> module.getId().equals(softwareModule.getId())).findFirst();
if (found.isPresent()) { if (found.isPresent()) {
return false; return false;
} }
final long allready = modules.stream() final long allready = modules.stream()
.filter(module -> module.getType().getKey().equals(softwareModule.getType().getKey())).count(); .filter(module -> module.getType().getKey().equals(softwareModule.getType().getKey())).count();
if (allready >= softwareModule.getType().getMaxAssignments()) { if (allready >= softwareModule.getType().getMaxAssignments()) {
final Optional<SoftwareModule> sameKey = modules.stream() final Optional<SoftwareModule> sameKey = modules.stream()
.filter(module -> module.getType().getKey().equals(softwareModule.getType().getKey())).findFirst(); .filter(module -> module.getType().getKey().equals(softwareModule.getType().getKey())).findFirst();
modules.remove(sameKey.get()); modules.remove(sameKey.get());
} }
if (modules.add(softwareModule)) { if (modules.add(softwareModule)) {
complete = type.checkComplete(this); complete = type.checkComplete(this);
return true; return true;
} }
return false; return false;
} }
@Override @Override
public boolean removeModule(final SoftwareModule softwareModule) { public boolean removeModule(final SoftwareModule softwareModule) {
final Optional<SoftwareModule> found = modules.stream() final Optional<SoftwareModule> found = modules.stream()
.filter(module -> module.getId().equals(softwareModule.getId())).findFirst(); .filter(module -> module.getId().equals(softwareModule.getId())).findFirst();
if (found.isPresent()) { if (found.isPresent()) {
modules.remove(found.get()); modules.remove(found.get());
complete = type.checkComplete(this); complete = type.checkComplete(this);
return true; return true;
} }
return false; return false;
} }
@Override @Override
public SoftwareModule findFirstModuleByType(final SoftwareModuleType type) { public SoftwareModule findFirstModuleByType(final SoftwareModuleType type) {
final Optional<SoftwareModule> result = modules.stream().filter(module -> module.getType().equals(type)) final Optional<SoftwareModule> result = modules.stream().filter(module -> module.getType().equals(type))
.findFirst(); .findFirst();
if (result.isPresent()) { if (result.isPresent()) {
return result.get(); return result.get();
} }
return null; return null;
} }
@Override @Override
public DistributionSetType getType() { public DistributionSetType getType() {
return type; return type;
} }
@Override @Override
public void setType(final DistributionSetType type) { public void setType(final DistributionSetType type) {
this.type = type; this.type = type;
} }
@Override @Override
public boolean isComplete() { public boolean isComplete() {
return complete; return complete;
} }
@Override @Override
public void fireCreateEvent(final JpaDistributionSet jpaDistributionSet, final DescriptorEvent descriptorEvent) { public void fireCreateEvent(final JpaDistributionSet jpaDistributionSet, final DescriptorEvent descriptorEvent) {
AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit( () -> EventBusHolder.getInstance().getEventBus().post(new DistributionCreatedEvent(jpaDistributionSet))); AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit( () -> EventBusHolder.getInstance().getEventBus().post(new DistributionCreatedEvent(jpaDistributionSet)));
} }
@Override @Override
public void fireUpdateEvent(final JpaDistributionSet jpaDistributionSet, final DescriptorEvent descriptorEvent) { public void fireUpdateEvent(final JpaDistributionSet jpaDistributionSet, final DescriptorEvent descriptorEvent) {
final Map<String, AbstractPropertyChangeEvent<JpaDistributionSet>.Values> changeSet = EntityPropertyChangeHelper.getChangeSet( final Map<String, AbstractPropertyChangeEvent<JpaDistributionSet>.Values> changeSet = EntityPropertyChangeHelper.getChangeSet(
JpaDistributionSet.class, descriptorEvent); JpaDistributionSet.class, descriptorEvent);
if (changeSet.containsKey(COMPLETE) if (changeSet.containsKey(COMPLETE)
&& changeSet.get(COMPLETE).getOldValue().equals(false) && changeSet.get(COMPLETE).getOldValue().equals(false)
&& changeSet.get(COMPLETE).getNewValue().equals(true)) { && changeSet.get(COMPLETE).getNewValue().equals(true)) {
AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit( AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit(
() -> EventBusHolder.getInstance().getEventBus().post( () -> EventBusHolder.getInstance().getEventBus().post(
new DistributionCreatedEvent(jpaDistributionSet))); new DistributionCreatedEvent(jpaDistributionSet)));
} }
AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit( AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit(
() -> EventBusHolder.getInstance().getEventBus().post(new DistributionSetUpdateEvent(jpaDistributionSet))); () -> EventBusHolder.getInstance().getEventBus().post(new DistributionSetUpdateEvent(jpaDistributionSet)));
} }
@Override @Override
public void fireDeleteEvent(final JpaDistributionSet jpaDistributionSet, final DescriptorEvent descriptorEvent) { public void fireDeleteEvent(final JpaDistributionSet jpaDistributionSet, final DescriptorEvent descriptorEvent) {
} }
} }

View File

@@ -1,223 +1,223 @@
/** /**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others. * Copyright (c) 2015 Bosch Software Innovations GmbH and others.
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
*/ */
package org.eclipse.hawkbit.repository.jpa.model; package org.eclipse.hawkbit.repository.jpa.model;
import java.util.List; import java.util.List;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.ConstraintMode; import javax.persistence.ConstraintMode;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EnumType; import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.ForeignKey; import javax.persistence.ForeignKey;
import javax.persistence.Index; import javax.persistence.Index;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient; import javax.persistence.Transient;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.eclipse.hawkbit.repository.eventbus.event.RolloutPropertyChangeEvent; import org.eclipse.hawkbit.repository.eventbus.event.RolloutPropertyChangeEvent;
import org.eclipse.hawkbit.repository.jpa.cache.CacheField; import org.eclipse.hawkbit.repository.jpa.cache.CacheField;
import org.eclipse.hawkbit.repository.jpa.cache.CacheKeys; import org.eclipse.hawkbit.repository.jpa.cache.CacheKeys;
import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityPropertyChangeHelper; import org.eclipse.hawkbit.repository.jpa.model.helper.EntityPropertyChangeHelper;
import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder;
import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.ActionType;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus;
import org.eclipse.persistence.descriptors.DescriptorEvent; import org.eclipse.persistence.descriptors.DescriptorEvent;
/** /**
* JPA implementation of a {@link Rollout}. * JPA implementation of a {@link Rollout}.
* *
*/ */
@Entity @Entity
@Table(name = "sp_rollout", indexes = { @Table(name = "sp_rollout", indexes = {
@Index(name = "sp_idx_rollout_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { @Index(name = "sp_idx_rollout_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = {
"name", "tenant" }, name = "uk_rollout")) "name", "tenant" }, name = "uk_rollout"))
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for // exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
// sub entities // sub entities
@SuppressWarnings("squid:S2160") @SuppressWarnings("squid:S2160")
public class JpaRollout extends AbstractJpaNamedEntity implements Rollout,EventAwareEntity<JpaRollout> { public class JpaRollout extends AbstractJpaNamedEntity implements Rollout,EventAwareEntity<JpaRollout> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@OneToMany(targetEntity = JpaRolloutGroup.class) @OneToMany(targetEntity = JpaRolloutGroup.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<RolloutGroup> rolloutGroups; private List<RolloutGroup> rolloutGroups;
@Column(name = "target_filter", length = 1024, nullable = false) @Column(name = "target_filter", length = 1024, nullable = false)
private String targetFilterQuery; private String targetFilterQuery;
@ManyToOne(fetch = FetchType.LAZY) @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 JpaDistributionSet distributionSet; private JpaDistributionSet distributionSet;
@Column(name = "status") @Column(name = "status")
private RolloutStatus status = RolloutStatus.CREATING; private RolloutStatus status = RolloutStatus.CREATING;
@Column(name = "last_check") @Column(name = "last_check")
private long lastCheck; private long lastCheck;
@Column(name = "action_type", nullable = false) @Column(name = "action_type", nullable = false)
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private ActionType actionType = ActionType.FORCED; private ActionType actionType = ActionType.FORCED;
@Column(name = "forced_time") @Column(name = "forced_time")
private long forcedTime; private long forcedTime;
@Column(name = "total_targets") @Column(name = "total_targets")
private long totalTargets; private long totalTargets;
@Transient @Transient
@CacheField(key = CacheKeys.ROLLOUT_GROUP_TOTAL) @CacheField(key = CacheKeys.ROLLOUT_GROUP_TOTAL)
private int rolloutGroupsTotal; private int rolloutGroupsTotal;
@Transient @Transient
@CacheField(key = CacheKeys.ROLLOUT_GROUP_CREATED) @CacheField(key = CacheKeys.ROLLOUT_GROUP_CREATED)
private int rolloutGroupsCreated; private int rolloutGroupsCreated;
@Transient @Transient
private transient TotalTargetCountStatus totalTargetCountStatus; private transient TotalTargetCountStatus totalTargetCountStatus;
@Override @Override
public DistributionSet getDistributionSet() { public DistributionSet getDistributionSet() {
return distributionSet; return distributionSet;
} }
@Override @Override
public void setDistributionSet(final DistributionSet distributionSet) { public void setDistributionSet(final DistributionSet distributionSet) {
this.distributionSet = (JpaDistributionSet) distributionSet; this.distributionSet = (JpaDistributionSet) distributionSet;
} }
@Override @Override
public List<RolloutGroup> getRolloutGroups() { public List<RolloutGroup> getRolloutGroups() {
return rolloutGroups; return rolloutGroups;
} }
public void setRolloutGroups(final List<RolloutGroup> rolloutGroups) { public void setRolloutGroups(final List<RolloutGroup> rolloutGroups) {
this.rolloutGroups = rolloutGroups; this.rolloutGroups = rolloutGroups;
} }
@Override @Override
public String getTargetFilterQuery() { public String getTargetFilterQuery() {
return targetFilterQuery; return targetFilterQuery;
} }
@Override @Override
public void setTargetFilterQuery(final String targetFilterQuery) { public void setTargetFilterQuery(final String targetFilterQuery) {
this.targetFilterQuery = targetFilterQuery; this.targetFilterQuery = targetFilterQuery;
} }
@Override @Override
public RolloutStatus getStatus() { public RolloutStatus getStatus() {
return status; return status;
} }
public void setStatus(final RolloutStatus status) { public void setStatus(final RolloutStatus status) {
this.status = status; this.status = status;
} }
public long getLastCheck() { public long getLastCheck() {
return lastCheck; return lastCheck;
} }
public void setLastCheck(final long lastCheck) { public void setLastCheck(final long lastCheck) {
this.lastCheck = lastCheck; this.lastCheck = lastCheck;
} }
@Override @Override
public ActionType getActionType() { public ActionType getActionType() {
return actionType; return actionType;
} }
@Override @Override
public void setActionType(final ActionType actionType) { public void setActionType(final ActionType actionType) {
this.actionType = actionType; this.actionType = actionType;
} }
@Override @Override
public long getForcedTime() { public long getForcedTime() {
return forcedTime; return forcedTime;
} }
@Override @Override
public void setForcedTime(final long forcedTime) { public void setForcedTime(final long forcedTime) {
this.forcedTime = forcedTime; this.forcedTime = forcedTime;
} }
@Override @Override
public long getTotalTargets() { public long getTotalTargets() {
return totalTargets; return totalTargets;
} }
public void setTotalTargets(final long totalTargets) { public void setTotalTargets(final long totalTargets) {
this.totalTargets = totalTargets; this.totalTargets = totalTargets;
} }
public int getRolloutGroupsTotal() { public int getRolloutGroupsTotal() {
return rolloutGroupsTotal; return rolloutGroupsTotal;
} }
public void setRolloutGroupsTotal(final int rolloutGroupsTotal) { public void setRolloutGroupsTotal(final int rolloutGroupsTotal) {
this.rolloutGroupsTotal = rolloutGroupsTotal; this.rolloutGroupsTotal = rolloutGroupsTotal;
} }
@Override @Override
public int getRolloutGroupsCreated() { public int getRolloutGroupsCreated() {
return rolloutGroupsCreated; return rolloutGroupsCreated;
} }
public void setRolloutGroupsCreated(final int rolloutGroupsCreated) { public void setRolloutGroupsCreated(final int rolloutGroupsCreated) {
this.rolloutGroupsCreated = rolloutGroupsCreated; this.rolloutGroupsCreated = rolloutGroupsCreated;
} }
@Override @Override
public TotalTargetCountStatus getTotalTargetCountStatus() { public TotalTargetCountStatus getTotalTargetCountStatus() {
if (totalTargetCountStatus == null) { if (totalTargetCountStatus == null) {
totalTargetCountStatus = new TotalTargetCountStatus(totalTargets); totalTargetCountStatus = new TotalTargetCountStatus(totalTargets);
} }
return totalTargetCountStatus; return totalTargetCountStatus;
} }
public void setTotalTargetCountStatus(final TotalTargetCountStatus totalTargetCountStatus) { public void setTotalTargetCountStatus(final TotalTargetCountStatus totalTargetCountStatus) {
this.totalTargetCountStatus = totalTargetCountStatus; this.totalTargetCountStatus = totalTargetCountStatus;
} }
@Override @Override
public String toString() { public String toString() {
return "Rollout [rolloutGroups=" + rolloutGroups + ", targetFilterQuery=" + targetFilterQuery return "Rollout [rolloutGroups=" + rolloutGroups + ", targetFilterQuery=" + targetFilterQuery
+ ", distributionSet=" + distributionSet + ", status=" + status + ", lastCheck=" + lastCheck + ", distributionSet=" + distributionSet + ", status=" + status + ", lastCheck=" + lastCheck
+ ", getName()=" + getName() + ", getId()=" + getId() + "]"; + ", getName()=" + getName() + ", getId()=" + getId() + "]";
} }
@Override @Override
public void fireCreateEvent(final JpaRollout jpaRollout, final DescriptorEvent descriptorEvent) { public void fireCreateEvent(final JpaRollout jpaRollout, final DescriptorEvent descriptorEvent) {
} }
@Override @Override
public void fireUpdateEvent(final JpaRollout jpaRollout, final DescriptorEvent descriptorEvent) { public void fireUpdateEvent(final JpaRollout jpaRollout, final DescriptorEvent descriptorEvent) {
AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit(() -> EventBusHolder.getInstance().getEventBus(). AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit(() -> EventBusHolder.getInstance().getEventBus().
post(new RolloutPropertyChangeEvent(jpaRollout, EntityPropertyChangeHelper.getChangeSet( post(new RolloutPropertyChangeEvent(jpaRollout, EntityPropertyChangeHelper.getChangeSet(
Rollout.class, descriptorEvent)))); Rollout.class, descriptorEvent))));
} }
@Override @Override
public void fireDeleteEvent(final JpaRollout jpaRollout, final DescriptorEvent descriptorEvent) { public void fireDeleteEvent(final JpaRollout jpaRollout, final DescriptorEvent descriptorEvent) {
} }
} }

View File

@@ -1,261 +1,261 @@
/** /**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others. * Copyright (c) 2015 Bosch Software Innovations GmbH and others.
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
*/ */
package org.eclipse.hawkbit.repository.jpa.model; package org.eclipse.hawkbit.repository.jpa.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.ConstraintMode; import javax.persistence.ConstraintMode;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.ForeignKey; import javax.persistence.ForeignKey;
import javax.persistence.Index; import javax.persistence.Index;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient; import javax.persistence.Transient;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupPropertyChangeEvent; import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupPropertyChangeEvent;
import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityPropertyChangeHelper; import org.eclipse.hawkbit.repository.jpa.model.helper.EntityPropertyChangeHelper;
import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder;
import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus;
import org.eclipse.persistence.descriptors.DescriptorEvent; import org.eclipse.persistence.descriptors.DescriptorEvent;
/** /**
* JPA entity definition of persisting a group of an rollout. * JPA entity definition of persisting a group of an rollout.
* *
*/ */
@Entity @Entity
@Table(name = "sp_rolloutgroup", indexes = { @Table(name = "sp_rolloutgroup", indexes = {
@Index(name = "sp_idx_rolloutgroup_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { @Index(name = "sp_idx_rolloutgroup_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = {
"name", "rollout", "tenant" }, name = "uk_rolloutgroup")) "name", "rollout", "tenant" }, name = "uk_rolloutgroup"))
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for // exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
// sub entities // sub entities
@SuppressWarnings("squid:S2160") @SuppressWarnings("squid:S2160")
public class JpaRolloutGroup extends AbstractJpaNamedEntity implements RolloutGroup,EventAwareEntity<JpaRolloutGroup> { public class JpaRolloutGroup extends AbstractJpaNamedEntity implements RolloutGroup,EventAwareEntity<JpaRolloutGroup> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ManyToOne(fetch = FetchType.LAZY) @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 JpaRollout rollout; private JpaRollout rollout;
@Column(name = "status") @Column(name = "status")
private RolloutGroupStatus status = RolloutGroupStatus.READY; private RolloutGroupStatus status = RolloutGroupStatus.READY;
@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST }, targetEntity = RolloutTargetGroup.class) @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST }, targetEntity = RolloutTargetGroup.class)
@JoinColumn(name = "rolloutGroup_Id", insertable = false, updatable = false) @JoinColumn(name = "rolloutGroup_Id", insertable = false, updatable = false)
private final List<RolloutTargetGroup> rolloutTargetGroup = new ArrayList<>(); private final List<RolloutTargetGroup> rolloutTargetGroup = new ArrayList<>();
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
private JpaRolloutGroup parent; private JpaRolloutGroup parent;
@Column(name = "success_condition", nullable = false) @Column(name = "success_condition", nullable = false)
private RolloutGroupSuccessCondition successCondition = RolloutGroupSuccessCondition.THRESHOLD; private RolloutGroupSuccessCondition successCondition = RolloutGroupSuccessCondition.THRESHOLD;
@Column(name = "success_condition_exp", length = 512, nullable = false) @Column(name = "success_condition_exp", length = 512, nullable = false)
private String successConditionExp; private String successConditionExp;
@Column(name = "success_action", nullable = false) @Column(name = "success_action", nullable = false)
private RolloutGroupSuccessAction successAction = RolloutGroupSuccessAction.NEXTGROUP; private RolloutGroupSuccessAction successAction = RolloutGroupSuccessAction.NEXTGROUP;
@Column(name = "success_action_exp", length = 512, nullable = false) @Column(name = "success_action_exp", length = 512, nullable = false)
private String successActionExp; private String successActionExp;
@Column(name = "error_condition") @Column(name = "error_condition")
private RolloutGroupErrorCondition errorCondition; private RolloutGroupErrorCondition errorCondition;
@Column(name = "error_condition_exp", length = 512) @Column(name = "error_condition_exp", length = 512)
private String errorConditionExp; private String errorConditionExp;
@Column(name = "error_action") @Column(name = "error_action")
private RolloutGroupErrorAction errorAction; private RolloutGroupErrorAction errorAction;
@Column(name = "error_action_exp", length = 512) @Column(name = "error_action_exp", length = 512)
private String errorActionExp; private String errorActionExp;
@Column(name = "total_targets") @Column(name = "total_targets")
private long totalTargets; private long totalTargets;
@Transient @Transient
private transient TotalTargetCountStatus totalTargetCountStatus; private transient TotalTargetCountStatus totalTargetCountStatus;
@Override @Override
public Rollout getRollout() { public Rollout getRollout() {
return rollout; return rollout;
} }
@Override @Override
public void setRollout(final Rollout rollout) { public void setRollout(final Rollout rollout) {
this.rollout = (JpaRollout) rollout; this.rollout = (JpaRollout) rollout;
} }
@Override @Override
public RolloutGroupStatus getStatus() { public RolloutGroupStatus getStatus() {
return status; return status;
} }
@Override @Override
public void setStatus(final RolloutGroupStatus status) { public void setStatus(final RolloutGroupStatus status) {
this.status = status; this.status = status;
} }
public List<RolloutTargetGroup> getRolloutTargetGroup() { public List<RolloutTargetGroup> getRolloutTargetGroup() {
return rolloutTargetGroup; return rolloutTargetGroup;
} }
@Override @Override
public RolloutGroup getParent() { public RolloutGroup getParent() {
return parent; return parent;
} }
public void setParent(final RolloutGroup parent) { public void setParent(final RolloutGroup parent) {
this.parent = (JpaRolloutGroup) parent; this.parent = (JpaRolloutGroup) parent;
} }
@Override @Override
public RolloutGroupSuccessCondition getSuccessCondition() { public RolloutGroupSuccessCondition getSuccessCondition() {
return successCondition; return successCondition;
} }
@Override @Override
public void setSuccessCondition(final RolloutGroupSuccessCondition finishCondition) { public void setSuccessCondition(final RolloutGroupSuccessCondition finishCondition) {
successCondition = finishCondition; successCondition = finishCondition;
} }
@Override @Override
public String getSuccessConditionExp() { public String getSuccessConditionExp() {
return successConditionExp; return successConditionExp;
} }
@Override @Override
public void setSuccessConditionExp(final String finishExp) { public void setSuccessConditionExp(final String finishExp) {
successConditionExp = finishExp; successConditionExp = finishExp;
} }
@Override @Override
public RolloutGroupErrorCondition getErrorCondition() { public RolloutGroupErrorCondition getErrorCondition() {
return errorCondition; return errorCondition;
} }
@Override @Override
public void setErrorCondition(final RolloutGroupErrorCondition errorCondition) { public void setErrorCondition(final RolloutGroupErrorCondition errorCondition) {
this.errorCondition = errorCondition; this.errorCondition = errorCondition;
} }
@Override @Override
public String getErrorConditionExp() { public String getErrorConditionExp() {
return errorConditionExp; return errorConditionExp;
} }
@Override @Override
public void setErrorConditionExp(final String errorExp) { public void setErrorConditionExp(final String errorExp) {
errorConditionExp = errorExp; errorConditionExp = errorExp;
} }
@Override @Override
public RolloutGroupErrorAction getErrorAction() { public RolloutGroupErrorAction getErrorAction() {
return errorAction; return errorAction;
} }
@Override @Override
public void setErrorAction(final RolloutGroupErrorAction errorAction) { public void setErrorAction(final RolloutGroupErrorAction errorAction) {
this.errorAction = errorAction; this.errorAction = errorAction;
} }
@Override @Override
public String getErrorActionExp() { public String getErrorActionExp() {
return errorActionExp; return errorActionExp;
} }
@Override @Override
public void setErrorActionExp(final String errorActionExp) { public void setErrorActionExp(final String errorActionExp) {
this.errorActionExp = errorActionExp; this.errorActionExp = errorActionExp;
} }
@Override @Override
public RolloutGroupSuccessAction getSuccessAction() { public RolloutGroupSuccessAction getSuccessAction() {
return successAction; return successAction;
} }
@Override @Override
public String getSuccessActionExp() { public String getSuccessActionExp() {
return successActionExp; return successActionExp;
} }
@Override @Override
public long getTotalTargets() { public long getTotalTargets() {
return totalTargets; return totalTargets;
} }
public void setTotalTargets(final long totalTargets) { public void setTotalTargets(final long totalTargets) {
this.totalTargets = totalTargets; this.totalTargets = totalTargets;
} }
public void setSuccessAction(final RolloutGroupSuccessAction successAction) { public void setSuccessAction(final RolloutGroupSuccessAction successAction) {
this.successAction = successAction; this.successAction = successAction;
} }
public void setSuccessActionExp(final String successActionExp) { public void setSuccessActionExp(final String successActionExp) {
this.successActionExp = successActionExp; this.successActionExp = successActionExp;
} }
/** /**
* @return the totalTargetCountStatus * @return the totalTargetCountStatus
*/ */
@Override @Override
public TotalTargetCountStatus getTotalTargetCountStatus() { public TotalTargetCountStatus getTotalTargetCountStatus() {
if (totalTargetCountStatus == null) { if (totalTargetCountStatus == null) {
totalTargetCountStatus = new TotalTargetCountStatus(totalTargets); totalTargetCountStatus = new TotalTargetCountStatus(totalTargets);
} }
return totalTargetCountStatus; return totalTargetCountStatus;
} }
/** /**
* @param totalTargetCountStatus * @param totalTargetCountStatus
* the totalTargetCountStatus to set * the totalTargetCountStatus to set
*/ */
@Override @Override
public void setTotalTargetCountStatus(final TotalTargetCountStatus totalTargetCountStatus) { public void setTotalTargetCountStatus(final TotalTargetCountStatus totalTargetCountStatus) {
this.totalTargetCountStatus = totalTargetCountStatus; this.totalTargetCountStatus = totalTargetCountStatus;
} }
@Override @Override
public String toString() { public String toString() {
return "RolloutGroup [rollout=" + rollout + ", status=" + status + ", rolloutTargetGroup=" + rolloutTargetGroup return "RolloutGroup [rollout=" + rollout + ", status=" + status + ", rolloutTargetGroup=" + rolloutTargetGroup
+ ", parent=" + parent + ", finishCondition=" + successCondition + ", finishExp=" + successConditionExp + ", parent=" + parent + ", finishCondition=" + successCondition + ", finishExp=" + successConditionExp
+ ", errorCondition=" + errorCondition + ", errorExp=" + errorConditionExp + ", getName()=" + getName() + ", errorCondition=" + errorCondition + ", errorExp=" + errorConditionExp + ", getName()=" + getName()
+ ", getId()=" + getId() + "]"; + ", getId()=" + getId() + "]";
} }
@Override @Override
public void fireCreateEvent(final JpaRolloutGroup jpaRolloutGroup, final DescriptorEvent descriptorEvent) { public void fireCreateEvent(final JpaRolloutGroup jpaRolloutGroup, final DescriptorEvent descriptorEvent) {
} }
@Override @Override
public void fireUpdateEvent(final JpaRolloutGroup jpaRolloutGroup, final DescriptorEvent descriptorEvent) { public void fireUpdateEvent(final JpaRolloutGroup jpaRolloutGroup, final DescriptorEvent descriptorEvent) {
AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit(() -> EventBusHolder.getInstance().getEventBus(). AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit(() -> EventBusHolder.getInstance().getEventBus().
post(new RolloutGroupPropertyChangeEvent(jpaRolloutGroup, post(new RolloutGroupPropertyChangeEvent(jpaRolloutGroup,
EntityPropertyChangeHelper.getChangeSet(RolloutGroup.class, descriptorEvent)))); EntityPropertyChangeHelper.getChangeSet(RolloutGroup.class, descriptorEvent))));
} }
@Override @Override
public void fireDeleteEvent(final JpaRolloutGroup jpaRolloutGroup, final DescriptorEvent descriptorEvent) { public void fireDeleteEvent(final JpaRolloutGroup jpaRolloutGroup, final DescriptorEvent descriptorEvent) {
} }
} }

View File

@@ -1,257 +1,257 @@
/** /**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others. * Copyright (c) 2015 Bosch Software Innovations GmbH and others.
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
*/ */
package org.eclipse.hawkbit.repository.jpa.model; package org.eclipse.hawkbit.repository.jpa.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.ConstraintMode; import javax.persistence.ConstraintMode;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.ForeignKey; import javax.persistence.ForeignKey;
import javax.persistence.Index; import javax.persistence.Index;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.JoinTable; import javax.persistence.JoinTable;
import javax.persistence.ManyToMany; import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.NamedAttributeNode; import javax.persistence.NamedAttributeNode;
import javax.persistence.NamedEntityGraph; import javax.persistence.NamedEntityGraph;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn; import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient; import javax.persistence.Transient;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.repository.eventbus.event.TargetCreatedEvent; import org.eclipse.hawkbit.repository.eventbus.event.TargetCreatedEvent;
import org.eclipse.hawkbit.repository.eventbus.event.TargetUpdatedEvent; import org.eclipse.hawkbit.repository.eventbus.event.TargetUpdatedEvent;
import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityChecker; import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityChecker;
import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder;
import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
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.TargetTag;
import org.eclipse.persistence.annotations.CascadeOnDelete; import org.eclipse.persistence.annotations.CascadeOnDelete;
import org.eclipse.persistence.descriptors.DescriptorEvent; import org.eclipse.persistence.descriptors.DescriptorEvent;
import org.springframework.data.domain.Persistable; import org.springframework.data.domain.Persistable;
/** /**
* JPA implementation of {@link Target}. * JPA implementation of {@link Target}.
* *
*/ */
@Entity @Entity
@Table(name = "sp_target", indexes = { @Table(name = "sp_target", indexes = {
@Index(name = "sp_idx_target_01", columnList = "tenant,name,assigned_distribution_set"), @Index(name = "sp_idx_target_01", columnList = "tenant,name,assigned_distribution_set"),
@Index(name = "sp_idx_target_02", columnList = "tenant,name"), @Index(name = "sp_idx_target_02", columnList = "tenant,name"),
@Index(name = "sp_idx_target_03", columnList = "tenant,controller_id,assigned_distribution_set"), @Index(name = "sp_idx_target_03", columnList = "tenant,controller_id,assigned_distribution_set"),
@Index(name = "sp_idx_target_04", columnList = "tenant,created_at"), @Index(name = "sp_idx_target_04", columnList = "tenant,created_at"),
@Index(name = "sp_idx_target_prim", columnList = "tenant,id") }, uniqueConstraints = @UniqueConstraint(columnNames = { @Index(name = "sp_idx_target_prim", columnList = "tenant,id") }, uniqueConstraints = @UniqueConstraint(columnNames = {
"controller_id", "tenant" }, name = "uk_tenant_controller_id")) "controller_id", "tenant" }, name = "uk_tenant_controller_id"))
@NamedEntityGraph(name = "Target.detail", attributeNodes = { @NamedAttributeNode("tags"), @NamedEntityGraph(name = "Target.detail", attributeNodes = { @NamedAttributeNode("tags"),
@NamedAttributeNode(value = "assignedDistributionSet"), @NamedAttributeNode(value = "targetInfo") }) @NamedAttributeNode(value = "assignedDistributionSet"), @NamedAttributeNode(value = "targetInfo") })
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for // exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
// sub entities // sub entities
@SuppressWarnings("squid:S2160") @SuppressWarnings("squid:S2160")
public class JpaTarget extends AbstractJpaNamedEntity implements Persistable<Long>, Target, EventAwareEntity<JpaTarget> { public class JpaTarget extends AbstractJpaNamedEntity implements Persistable<Long>, Target, EventAwareEntity<JpaTarget> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Column(name = "controller_id", length = 64) @Column(name = "controller_id", length = 64)
@Size(min = 1) @Size(min = 1)
@NotNull @NotNull
private String controllerId; private String controllerId;
@Transient @Transient
private boolean entityNew; private boolean entityNew;
@ManyToMany(targetEntity = JpaTargetTag.class) @ManyToMany(targetEntity = JpaTargetTag.class)
@JoinTable(name = "sp_target_target_tag", joinColumns = { @JoinTable(name = "sp_target_target_tag", joinColumns = {
@JoinColumn(name = "target", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_targtag_target")) }, inverseJoinColumns = { @JoinColumn(name = "target", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_targtag_target")) }, inverseJoinColumns = {
@JoinColumn(name = "tag", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_targtag_tag")) }) @JoinColumn(name = "tag", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_targtag_tag")) })
private Set<TargetTag> tags = new HashSet<>(); private Set<TargetTag> tags = new HashSet<>();
@CascadeOnDelete @CascadeOnDelete
@OneToMany(fetch = FetchType.LAZY, orphanRemoval = true, cascade = { @OneToMany(fetch = FetchType.LAZY, orphanRemoval = true, cascade = {
CascadeType.REMOVE }, targetEntity = JpaAction.class) CascadeType.REMOVE }, targetEntity = JpaAction.class)
@JoinColumn(name = "target", insertable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_act_hist_targ")) @JoinColumn(name = "target", insertable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_act_hist_targ"))
private final List<Action> actions = new ArrayList<>(); private final List<Action> actions = new ArrayList<>();
@ManyToOne(optional = true, fetch = FetchType.LAZY, targetEntity = JpaDistributionSet.class) @ManyToOne(optional = true, fetch = FetchType.LAZY, targetEntity = JpaDistributionSet.class)
@JoinColumn(name = "assigned_distribution_set", nullable = true, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_target_assign_ds")) @JoinColumn(name = "assigned_distribution_set", nullable = true, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_target_assign_ds"))
private JpaDistributionSet assignedDistributionSet; private JpaDistributionSet assignedDistributionSet;
@CascadeOnDelete @CascadeOnDelete
@OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, targetEntity = JpaTargetInfo.class) @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, targetEntity = JpaTargetInfo.class)
@PrimaryKeyJoinColumn @PrimaryKeyJoinColumn
private JpaTargetInfo targetInfo; private JpaTargetInfo targetInfo;
/** /**
* the security token of the target which allows if enabled to authenticate * the security token of the target which allows if enabled to authenticate
* with this security token. * with this security token.
*/ */
@Column(name = "sec_token", insertable = true, updatable = true, nullable = false, length = 128) @Column(name = "sec_token", insertable = true, updatable = true, nullable = false, length = 128)
private String securityToken; private String securityToken;
@CascadeOnDelete @CascadeOnDelete
@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE, CascadeType.PERSIST }) @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE, CascadeType.PERSIST })
@JoinColumn(name = "target_Id", insertable = false, updatable = false) @JoinColumn(name = "target_Id", insertable = false, updatable = false)
private final List<RolloutTargetGroup> rolloutTargetGroup = new ArrayList<>(); private final List<RolloutTargetGroup> rolloutTargetGroup = new ArrayList<>();
/** /**
* Constructor. * Constructor.
* *
* @param controllerId * @param controllerId
* controller ID of the {@link Target} * controller ID of the {@link Target}
*/ */
public JpaTarget(final String controllerId) { public JpaTarget(final String controllerId) {
this(controllerId, SecurityTokenGeneratorHolder.getInstance().generateToken()); this(controllerId, SecurityTokenGeneratorHolder.getInstance().generateToken());
} }
/** /**
* Constructor. * Constructor.
* *
* @param controllerId * @param controllerId
* controller ID of the {@link Target} * controller ID of the {@link Target}
* @param securityToken * @param securityToken
* for target authentication if enabled * for target authentication if enabled
*/ */
public JpaTarget(final String controllerId, final String securityToken) { public JpaTarget(final String controllerId, final String securityToken) {
this.controllerId = controllerId; this.controllerId = controllerId;
setName(controllerId); setName(controllerId);
this.securityToken = securityToken; this.securityToken = securityToken;
targetInfo = new JpaTargetInfo(this); targetInfo = new JpaTargetInfo(this);
} }
/** /**
* empty constructor for JPA. * empty constructor for JPA.
*/ */
JpaTarget() { JpaTarget() {
controllerId = null; controllerId = null;
securityToken = null; securityToken = null;
} }
@Override @Override
public DistributionSet getAssignedDistributionSet() { public DistributionSet getAssignedDistributionSet() {
return assignedDistributionSet; return assignedDistributionSet;
} }
@Override @Override
public String getControllerId() { public String getControllerId() {
return controllerId; return controllerId;
} }
@Override @Override
public Set<TargetTag> getTags() { public Set<TargetTag> getTags() {
return tags; return tags;
} }
public void setAssignedDistributionSet(final DistributionSet assignedDistributionSet) { public void setAssignedDistributionSet(final DistributionSet assignedDistributionSet) {
this.assignedDistributionSet = (JpaDistributionSet) assignedDistributionSet; this.assignedDistributionSet = (JpaDistributionSet) assignedDistributionSet;
} }
public void setControllerId(final String controllerId) { public void setControllerId(final String controllerId) {
this.controllerId = controllerId; this.controllerId = controllerId;
} }
public void setTags(final Set<TargetTag> tags) { public void setTags(final Set<TargetTag> tags) {
this.tags = tags; this.tags = tags;
} }
@Override @Override
public List<Action> getActions() { public List<Action> getActions() {
return actions; return actions;
} }
@Override @Override
@Transient @Transient
public boolean isNew() { public boolean isNew() {
return entityNew; return entityNew;
} }
/** /**
* @param isNew * @param isNew
* the isNew to set * the isNew to set
*/ */
public void setNew(final boolean entityNew) { public void setNew(final boolean entityNew) {
this.entityNew = entityNew; this.entityNew = entityNew;
} }
/** /**
* @return the targetInfo * @return the targetInfo
*/ */
@Override @Override
public TargetInfo getTargetInfo() { public TargetInfo getTargetInfo() {
return targetInfo; return targetInfo;
} }
/** /**
* @param targetInfo * @param targetInfo
* the targetInfo to set * the targetInfo to set
*/ */
public void setTargetInfo(final TargetInfo targetInfo) { public void setTargetInfo(final TargetInfo targetInfo) {
this.targetInfo = (JpaTargetInfo) targetInfo; this.targetInfo = (JpaTargetInfo) targetInfo;
} }
/** /**
* @return the securityToken if the current security context contains the * @return the securityToken if the current security context contains the
* necessary permission {@link SpPermission#READ_TARGET_SEC_TOKEN} * necessary permission {@link SpPermission#READ_TARGET_SEC_TOKEN}
* or the current context is executed as system code, otherwise * or the current context is executed as system code, otherwise
* {@code null}. * {@code null}.
*/ */
@Override @Override
public String getSecurityToken() { public String getSecurityToken() {
if (SystemSecurityContextHolder.getInstance().getSystemSecurityContext().isCurrentThreadSystemCode() if (SystemSecurityContextHolder.getInstance().getSystemSecurityContext().isCurrentThreadSystemCode()
|| SecurityChecker.hasPermission(SpPermission.READ_TARGET_SEC_TOKEN)) { || SecurityChecker.hasPermission(SpPermission.READ_TARGET_SEC_TOKEN)) {
return securityToken; return securityToken;
} }
return null; return null;
} }
/** /**
* @param securityToken * @param securityToken
* the securityToken to set * the securityToken to set
*/ */
@Override @Override
public void setSecurityToken(final String securityToken) { public void setSecurityToken(final String securityToken) {
this.securityToken = securityToken; this.securityToken = securityToken;
} }
@Override @Override
public String toString() { public String toString() {
return "Target [controllerId=" + controllerId + ", getId()=" + getId() + "]"; return "Target [controllerId=" + controllerId + ", getId()=" + getId() + "]";
} }
@Override @Override
public void fireCreateEvent(final JpaTarget jpaTarget, final DescriptorEvent descriptorEvent) { public void fireCreateEvent(final JpaTarget jpaTarget, final DescriptorEvent descriptorEvent) {
AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit( () ->EventBusHolder.getInstance().getEventBus().post(new TargetCreatedEvent(jpaTarget))); AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit( () ->EventBusHolder.getInstance().getEventBus().post(new TargetCreatedEvent(jpaTarget)));
} }
@Override @Override
public void fireUpdateEvent(final JpaTarget jpaTarget,final DescriptorEvent descriptorEvent) { public void fireUpdateEvent(final JpaTarget jpaTarget,final DescriptorEvent descriptorEvent) {
AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit( () -> EventBusHolder.getInstance().getEventBus().post(new TargetUpdatedEvent(jpaTarget))); AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit( () -> EventBusHolder.getInstance().getEventBus().post(new TargetUpdatedEvent(jpaTarget)));
} }
@Override @Override
public void fireDeleteEvent(final JpaTarget jpaTarget, final DescriptorEvent descriptorEvent) { public void fireDeleteEvent(final JpaTarget jpaTarget, final DescriptorEvent descriptorEvent) {
} }
} }

View File

@@ -1,344 +1,344 @@
/** /**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others. * Copyright (c) 2015 Bosch Software Innovations GmbH and others.
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
*/ */
package org.eclipse.hawkbit.repository.jpa.model; package org.eclipse.hawkbit.repository.jpa.model;
import java.net.URI; import java.net.URI;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.CollectionTable; import javax.persistence.CollectionTable;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.ConstraintMode; import javax.persistence.ConstraintMode;
import javax.persistence.ElementCollection; import javax.persistence.ElementCollection;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EntityListeners; import javax.persistence.EntityListeners;
import javax.persistence.EnumType; import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.ForeignKey; import javax.persistence.ForeignKey;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Index; import javax.persistence.Index;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.MapKeyColumn; import javax.persistence.MapKeyColumn;
import javax.persistence.MapsId; import javax.persistence.MapsId;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient; import javax.persistence.Transient;
import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent; import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent;
import org.eclipse.hawkbit.repository.exception.InvalidTargetAddressException; import org.eclipse.hawkbit.repository.exception.InvalidTargetAddressException;
import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.TenantConfigurationManagementHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.TenantConfigurationManagementHolder;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.PollStatus; import org.eclipse.hawkbit.repository.model.PollStatus;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetInfo;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper; import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.eclipse.persistence.annotations.CascadeOnDelete; import org.eclipse.persistence.annotations.CascadeOnDelete;
import org.eclipse.persistence.descriptors.DescriptorEvent; import org.eclipse.persistence.descriptors.DescriptorEvent;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Persistable; import org.springframework.data.domain.Persistable;
/** /**
* A table which contains all the information inserted, updated by the * A table which contains all the information inserted, updated by the
* controller itself. So this entity does not provide audit information because * controller itself. So this entity does not provide audit information because
* changes on this entity are mostly only done by controller requests. That's * changes on this entity are mostly only done by controller requests. That's
* the reason that we store these information in a separated table so we don't * the reason that we store these information in a separated table so we don't
* modifying the {@link Target} itself when a controller reports it's * modifying the {@link Target} itself when a controller reports it's
* {@link #lastTargetQuery} for example. * {@link #lastTargetQuery} for example.
* *
*/ */
@Table(name = "sp_target_info", indexes = { @Table(name = "sp_target_info", indexes = {
@Index(name = "sp_idx_target_info_02", columnList = "target_id,update_status") }) @Index(name = "sp_idx_target_info_02", columnList = "target_id,update_status") })
@Entity @Entity
@EntityListeners(EntityPropertyChangeListener.class) @EntityListeners(EntityPropertyChangeListener.class)
public class JpaTargetInfo implements Persistable<Long>, TargetInfo, EventAwareEntity<JpaTargetInfo> { public class JpaTargetInfo implements Persistable<Long>, TargetInfo, EventAwareEntity<JpaTargetInfo> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Logger LOG = LoggerFactory.getLogger(TargetInfo.class); private static final Logger LOG = LoggerFactory.getLogger(TargetInfo.class);
@Id @Id
private Long targetId; private Long targetId;
@Transient @Transient
private boolean entityNew; private boolean entityNew;
@CascadeOnDelete @CascadeOnDelete
@OneToOne(cascade = { CascadeType.MERGE, @OneToOne(cascade = { CascadeType.MERGE,
CascadeType.REMOVE }, fetch = FetchType.LAZY, targetEntity = JpaTarget.class) CascadeType.REMOVE }, fetch = FetchType.LAZY, targetEntity = JpaTarget.class)
@JoinColumn(name = "target_id", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_stat_targ")) @JoinColumn(name = "target_id", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_stat_targ"))
@MapsId @MapsId
private JpaTarget target; private JpaTarget target;
@Column(name = "address", length = 512) @Column(name = "address", length = 512)
private String address; private String address;
@Column(name = "last_target_query") @Column(name = "last_target_query")
private Long lastTargetQuery; private Long lastTargetQuery;
@Column(name = "install_date") @Column(name = "install_date")
private Long installationDate; private Long installationDate;
@Column(name = "update_status", nullable = false, length = 255) @Column(name = "update_status", nullable = false, length = 255)
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private TargetUpdateStatus updateStatus = TargetUpdateStatus.UNKNOWN; private TargetUpdateStatus updateStatus = TargetUpdateStatus.UNKNOWN;
@ManyToOne(optional = true, fetch = FetchType.LAZY) @ManyToOne(optional = true, fetch = FetchType.LAZY)
@JoinColumn(name = "installed_distribution_set", nullable = true, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_target_inst_ds")) @JoinColumn(name = "installed_distribution_set", nullable = true, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_target_inst_ds"))
private JpaDistributionSet installedDistributionSet; private JpaDistributionSet installedDistributionSet;
/** /**
* Read only on management API. Are commited by controller. * Read only on management API. Are commited by controller.
*/ */
@ElementCollection @ElementCollection
@Column(name = "attribute_value", length = 128) @Column(name = "attribute_value", length = 128)
@MapKeyColumn(name = "attribute_key", nullable = false, length = 32) @MapKeyColumn(name = "attribute_key", nullable = false, length = 32)
@CollectionTable(name = "sp_target_attributes", joinColumns = { @CollectionTable(name = "sp_target_attributes", joinColumns = {
@JoinColumn(name = "target_id") }, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_attrib_target")) @JoinColumn(name = "target_id") }, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_attrib_target"))
private final Map<String, String> controllerAttributes = Collections.synchronizedMap(new HashMap<String, String>()); private final Map<String, String> controllerAttributes = Collections.synchronizedMap(new HashMap<String, String>());
// set default request controller attributes to true, because we want to // set default request controller attributes to true, because we want to
// request them the first // request them the first
// time // time
@Column(name = "request_controller_attributes", nullable = false) @Column(name = "request_controller_attributes", nullable = false)
private boolean requestControllerAttributes = true; private boolean requestControllerAttributes = true;
/** /**
* Constructor for {@link TargetStatus}. * Constructor for {@link TargetStatus}.
* *
* @param target * @param target
* related to this status. * related to this status.
*/ */
public JpaTargetInfo(final JpaTarget target) { public JpaTargetInfo(final JpaTarget target) {
this.target = target; this.target = target;
targetId = target.getId(); targetId = target.getId();
} }
JpaTargetInfo() { JpaTargetInfo() {
target = null; target = null;
targetId = null; targetId = null;
} }
@Override @Override
public Long getId() { public Long getId() {
return targetId; return targetId;
} }
@Override @Override
@Transient @Transient
public boolean isNew() { public boolean isNew() {
return entityNew; return entityNew;
} }
/** /**
* @param isNew * @param isNew
* the isNew to set * the isNew to set
*/ */
public void setNew(final boolean entityNew) { public void setNew(final boolean entityNew) {
this.entityNew = entityNew; this.entityNew = entityNew;
} }
/** /**
* @return the ipAddress * @return the ipAddress
*/ */
@Override @Override
public URI getAddress() { public URI getAddress() {
if (address == null) { if (address == null) {
return null; return null;
} }
try { try {
return URI.create(address); return URI.create(address);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
LOG.warn("Invalid address provided. Cloud not be configured to URI", e); LOG.warn("Invalid address provided. Cloud not be configured to URI", e);
return null; return null;
} }
} }
/** /**
* @param address * @param address
* the target address to set * the target address to set
* *
* @throws IllegalArgumentException * @throws IllegalArgumentException
* If the given string violates RFC&nbsp;2396 * If the given string violates RFC&nbsp;2396
*/ */
@Override @Override
public void setAddress(final String address) { public void setAddress(final String address) {
// check if this is a real URI // check if this is a real URI
if (address != null) { if (address != null) {
try { try {
URI.create(address); URI.create(address);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
throw new InvalidTargetAddressException( throw new InvalidTargetAddressException(
"The given address " + address + " violates the RFC-2396 specification", e); "The given address " + address + " violates the RFC-2396 specification", e);
} }
} }
this.address = address; this.address = address;
} }
public Long getTargetId() { public Long getTargetId() {
return targetId; return targetId;
} }
public void setTargetId(final Long targetId) { public void setTargetId(final Long targetId) {
this.targetId = targetId; this.targetId = targetId;
} }
@Override @Override
public Target getTarget() { public Target getTarget() {
return target; return target;
} }
public void setTarget(final JpaTarget target) { public void setTarget(final JpaTarget target) {
this.target = target; this.target = target;
} }
@Override @Override
public Long getLastTargetQuery() { public Long getLastTargetQuery() {
return lastTargetQuery; return lastTargetQuery;
} }
public void setLastTargetQuery(final Long lastTargetQuery) { public void setLastTargetQuery(final Long lastTargetQuery) {
this.lastTargetQuery = lastTargetQuery; this.lastTargetQuery = lastTargetQuery;
} }
public void setRequestControllerAttributes(final boolean requestControllerAttributes) { public void setRequestControllerAttributes(final boolean requestControllerAttributes) {
this.requestControllerAttributes = requestControllerAttributes; this.requestControllerAttributes = requestControllerAttributes;
} }
@Override @Override
public Map<String, String> getControllerAttributes() { public Map<String, String> getControllerAttributes() {
return controllerAttributes; return controllerAttributes;
} }
@Override @Override
public boolean isRequestControllerAttributes() { public boolean isRequestControllerAttributes() {
return requestControllerAttributes; return requestControllerAttributes;
} }
@Override @Override
public Long getInstallationDate() { public Long getInstallationDate() {
return installationDate; return installationDate;
} }
public void setInstallationDate(final Long installationDate) { public void setInstallationDate(final Long installationDate) {
this.installationDate = installationDate; this.installationDate = installationDate;
} }
@Override @Override
public TargetUpdateStatus getUpdateStatus() { public TargetUpdateStatus getUpdateStatus() {
return updateStatus; return updateStatus;
} }
public void setUpdateStatus(final TargetUpdateStatus updateStatus) { public void setUpdateStatus(final TargetUpdateStatus updateStatus) {
this.updateStatus = updateStatus; this.updateStatus = updateStatus;
} }
@Override @Override
public DistributionSet getInstalledDistributionSet() { public DistributionSet getInstalledDistributionSet() {
return installedDistributionSet; return installedDistributionSet;
} }
public void setInstalledDistributionSet(final JpaDistributionSet installedDistributionSet) { public void setInstalledDistributionSet(final JpaDistributionSet installedDistributionSet) {
this.installedDistributionSet = installedDistributionSet; this.installedDistributionSet = installedDistributionSet;
} }
/** /**
* @return the poll time which holds the last poll time of the target, the * @return the poll time which holds the last poll time of the target, the
* next poll time and the overdue time. In case the * next poll time and the overdue time. In case the
* {@link #lastTargetQuery} is not set e.g. the target never polled * {@link #lastTargetQuery} is not set e.g. the target never polled
* before this method returns {@code null} * before this method returns {@code null}
*/ */
@Override @Override
public PollStatus getPollStatus() { public PollStatus getPollStatus() {
if (lastTargetQuery == null) { if (lastTargetQuery == null) {
return null; return null;
} }
return SystemSecurityContextHolder.getInstance().getSystemSecurityContext().runAsSystem(() -> { return SystemSecurityContextHolder.getInstance().getSystemSecurityContext().runAsSystem(() -> {
final Duration pollTime = DurationHelper.formattedStringToDuration(TenantConfigurationManagementHolder final Duration pollTime = DurationHelper.formattedStringToDuration(TenantConfigurationManagementHolder
.getInstance().getTenantConfigurationManagement() .getInstance().getTenantConfigurationManagement()
.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class).getValue()); .getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class).getValue());
final Duration overdueTime = DurationHelper.formattedStringToDuration( final Duration overdueTime = DurationHelper.formattedStringToDuration(
TenantConfigurationManagementHolder.getInstance().getTenantConfigurationManagement() TenantConfigurationManagementHolder.getInstance().getTenantConfigurationManagement()
.getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class) .getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class)
.getValue()); .getValue());
final LocalDateTime currentDate = LocalDateTime.now(); final LocalDateTime currentDate = LocalDateTime.now();
final LocalDateTime lastPollDate = LocalDateTime.ofInstant(Instant.ofEpochMilli(lastTargetQuery), final LocalDateTime lastPollDate = LocalDateTime.ofInstant(Instant.ofEpochMilli(lastTargetQuery),
ZoneId.systemDefault()); ZoneId.systemDefault());
final LocalDateTime nextPollDate = lastPollDate.plus(pollTime); final LocalDateTime nextPollDate = lastPollDate.plus(pollTime);
final LocalDateTime overdueDate = nextPollDate.plus(overdueTime); final LocalDateTime overdueDate = nextPollDate.plus(overdueTime);
return new PollStatus(lastPollDate, nextPollDate, overdueDate, currentDate); return new PollStatus(lastPollDate, nextPollDate, overdueDate, currentDate);
}); });
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((target == null) ? 0 : target.hashCode()); result = prime * result + ((target == null) ? 0 : target.hashCode());
result = prime * result + ((targetId == null) ? 0 : targetId.hashCode()); result = prime * result + ((targetId == null) ? 0 : targetId.hashCode());
return result; return result;
} }
@Override @Override
public boolean equals(final Object obj) { public boolean equals(final Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
if (obj == null) { if (obj == null) {
return false; return false;
} }
if (!(obj instanceof TargetInfo)) { if (!(obj instanceof TargetInfo)) {
return false; return false;
} }
final JpaTargetInfo other = (JpaTargetInfo) obj; final JpaTargetInfo other = (JpaTargetInfo) obj;
if (target == null) { if (target == null) {
if (other.target != null) { if (other.target != null) {
return false; return false;
} }
} else if (!target.equals(other.target)) { } else if (!target.equals(other.target)) {
return false; return false;
} }
if (targetId == null) { if (targetId == null) {
if (other.targetId != null) { if (other.targetId != null) {
return false; return false;
} }
} else if (!targetId.equals(other.targetId)) { } else if (!targetId.equals(other.targetId)) {
return false; return false;
} }
return true; return true;
} }
@Override @Override
public void fireCreateEvent(final JpaTargetInfo jpaTargetInfo,final DescriptorEvent descriptorEvent) { public void fireCreateEvent(final JpaTargetInfo jpaTargetInfo,final DescriptorEvent descriptorEvent) {
// there is no target info created event // there is no target info created event
} }
@Override @Override
public void fireUpdateEvent(final JpaTargetInfo jpaTargetInfo, final DescriptorEvent descriptorEvent) { public void fireUpdateEvent(final JpaTargetInfo jpaTargetInfo, final DescriptorEvent descriptorEvent) {
AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit( () -> EventBusHolder.getInstance().getEventBus().post(new TargetInfoUpdateEvent(jpaTargetInfo))); AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit( () -> EventBusHolder.getInstance().getEventBus().post(new TargetInfoUpdateEvent(jpaTargetInfo)));
} }
@Override @Override
public void fireDeleteEvent(final JpaTargetInfo jpaTargetInfo, final DescriptorEvent descriptorEvent) { public void fireDeleteEvent(final JpaTargetInfo jpaTargetInfo, final DescriptorEvent descriptorEvent) {
} }
} }