nl.vpro.domain.media.support.AbstractMediaObjectOwnableList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of media-domain Show documentation
Show all versions of media-domain Show documentation
The basic domain classes for 'media', the core of POMS. Also, the 'update' XML bindings for it.
It also contains some closely related domain classes like the enum to contain NICAM kijkwijzer settings.
package nl.vpro.domain.media.support;
import jakarta.persistence.*;
import jakarta.xml.bind.annotation.*;
import lombok.*;
import java.io.Serial;
import java.util.*;
import org.apache.commons.lang3.ObjectUtils;
import com.fasterxml.jackson.annotation.JsonProperty;
import nl.vpro.domain.DomainObject;
import nl.vpro.domain.media.MediaObject;
import static jakarta.persistence.CascadeType.ALL;
/**
*
* @author Michiel Meeuwissen
* @since 5.11
*/
@MappedSuperclass
@XmlAccessorType(XmlAccessType.NONE)
@XmlTransient
public abstract class AbstractMediaObjectOwnableList<
THIS extends AbstractMediaObjectOwnableList,
I extends MediaObjectOwnableListItem>
extends DomainObject
implements MediaObjectOwnableList {
@Serial
private static final long serialVersionUID = 4657694328901583730L;
@ManyToOne(targetEntity = MediaObject.class, fetch = FetchType.LAZY)
@XmlTransient
@Getter
@Setter
protected MediaObject parent;
@Enumerated(EnumType.STRING)
@XmlAttribute
@Setter(AccessLevel.PRIVATE)
@Getter
protected OwnerType owner;
@OneToMany(orphanRemoval = true, cascade = {ALL})
@JoinColumn(name = "parent_id")
@JsonProperty("values")
@OrderColumn(name = "list_index", nullable = true)
protected List values = new ArrayList<>();
@Override
public int hashCode() {
return Objects.hash(owner);
}
@Override
public int compareTo(THIS o) {
return ObjectUtils.compare(this.getOwner(), o.getOwner());
}
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
THIS list = (THIS) o;
if (getParent() == null || list.getParent() == null) {
// No parent, this is odd
return owner == list.owner;
} else {
return owner == list.owner && Objects.equals(getParent().getMid(), list.getParent().getMid());
}
}
@Override
public String toString() {
return getClass().getSimpleName() + ":" + owner + ":" + values;
}
@SuppressWarnings("unchecked")
@Override
public THIS clone() {
try {
THIS result = (THIS) super.clone();
result.parent = null;
for (I v : result.values) {
v.setParent(result);
}
return result;
} catch (CloneNotSupportedException cnse) {
throw new RuntimeException(cnse);
}
}
}