Commit c44d721e authored by Matija Obreza's avatar Matija Obreza
Browse files

Copyable interface changed

parent 0598634e
......@@ -28,7 +28,7 @@ import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
@MappedSuperclass
public abstract class AuditedVersionedModel extends VersionedModel {
public abstract class AuditedVersionedModel<T> extends VersionedModel<T> implements Copyable<T> {
private static final long serialVersionUID = 427752822365309989L;
......@@ -82,4 +82,15 @@ public abstract class AuditedVersionedModel extends VersionedModel {
public void setLastModifiedDate(final Date lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
public AuditedVersionedModel<?> apply(AuditedVersionedModel<?> source) {
super.apply(source);
this.createdBy = source.createdBy;
this.createdDate = source.createdDate;
this.lastModifiedBy = source.lastModifiedBy;
this.lastModifiedDate = source.lastModifiedDate;
return this;
}
}
......@@ -26,12 +26,13 @@ import javax.persistence.MappedSuperclass;
import com.fasterxml.jackson.annotation.JsonView;
@MappedSuperclass
public class BasicModel implements EntityId, Serializable {
public abstract class BasicModel<T> implements EntityId, Serializable, Copyable<T> {
private static final long serialVersionUID = 2709998920148999956L;
@JsonView({ JsonViews.Update.class, JsonViews.Protected.class })
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.TABLE)
@Column(name = "id", unique = true, nullable = false, length = 20)
private Long id = InMemoryIdGenerator.nextId();
......@@ -73,7 +74,7 @@ public class BasicModel implements EntityId, Serializable {
if (getClass() != obj.getClass()) {
return false;
}
final BasicModel other = (BasicModel) obj;
final BasicModel<?> other = (BasicModel<?>) obj;
if (id == null) {
if (other.id != null) {
return false;
......@@ -83,4 +84,9 @@ public class BasicModel implements EntityId, Serializable {
}
return true;
}
public BasicModel<?> apply(BasicModel<?> source) {
this.id = source.id;
return this;
}
}
......@@ -17,9 +17,9 @@ package org.genesys.blocks.model;
public interface Copyable<T> {
/**
* Make a deep copy of the object, with all new instances
* Apply changes from source to this object
*
* @return a deep copy
* @return this instance
*/
T copy();
T apply(T source);
}
......@@ -24,12 +24,12 @@ import javax.persistence.PrePersist;
import com.fasterxml.jackson.annotation.JsonView;
@MappedSuperclass
public abstract class UuidEntity extends AuditedVersionedModel implements IdUUID {
public abstract class UuidEntity<T> extends AuditedVersionedModel<T> implements IdUUID {
private static final long serialVersionUID = 2639238742778129554L;
@JsonView({ JsonViews.Update.class, JsonViews.Public.class })
@Column(unique = true, nullable = false, updatable = false)
protected UUID uuid;
@Column(unique = true, nullable = false, updatable = false, columnDefinition = "binary(16)")
private UUID uuid;
@PrePersist
private void prepersist() {
......@@ -48,4 +48,10 @@ public abstract class UuidEntity extends AuditedVersionedModel implements IdUUID
this.uuid = uuid;
}
public UuidEntity<?> apply(UuidEntity<?> source) {
super.apply(source);
this.uuid = source.uuid;
return this;
}
}
......@@ -22,17 +22,17 @@ import javax.persistence.Version;
import com.fasterxml.jackson.annotation.JsonView;
@MappedSuperclass
public abstract class VersionedModel extends BasicModel implements Activatable {
public abstract class VersionedModel<T> extends BasicModel<T> implements Activatable, Copyable<T> {
private static final long serialVersionUID = 6486704708017489425L;
@JsonView({ JsonViews.Update.class, JsonViews.Protected.class })
@Version
Integer version = null;
private Integer version = null;
/** Active by default! */
@Column(nullable = false)
boolean active = true;
private boolean active = true;
public Integer getVersion() {
return version;
......@@ -50,4 +50,13 @@ public abstract class VersionedModel extends BasicModel implements Activatable {
public void setActive(final boolean active) {
this.active = active;
}
public VersionedModel<?> apply(VersionedModel<?> source) {
super.apply(source);
this.active = source.active;
this.version = source.version;
return this;
}
}
......@@ -8,7 +8,7 @@ import org.genesys.blocks.model.BasicModel;
@Entity
@Table(name = "acl_class")
public class AclClass extends BasicModel {
public class AclClass extends BasicModel<AclClass> {
private static final long serialVersionUID = 7634040355879912092L;
@Column(name = "class", nullable = false, unique = true, length = 255)
......@@ -21,4 +21,12 @@ public class AclClass extends BasicModel {
public void setAclClass(final String aclClass) {
this.aclClass = aclClass;
}
@Override
public AclClass apply(AclClass source) {
super.apply((BasicModel<AclClass>) source);
this.aclClass = source.aclClass;
return this;
}
}
......@@ -13,7 +13,7 @@ import org.genesys.blocks.model.BasicModel;
@Entity
@Table(name = "acl_entry", uniqueConstraints = @UniqueConstraint(columnNames = { "acl_object_identity", "ace_order" }))
public class AclEntry extends BasicModel {
public class AclEntry extends BasicModel<AclEntry> {
private static final long serialVersionUID = -1047000445685485825L;
......@@ -95,4 +95,19 @@ public class AclEntry extends BasicModel {
public void setAuditFailure(final boolean auditFailure) {
this.auditFailure = auditFailure;
}
@Override
public AclEntry apply(AclEntry source) {
super.apply((BasicModel<AclEntry>) source);
this.aceOrder = source.aceOrder;
this.aclObjectIdentity = source.aclObjectIdentity;
this.aclSid = source.aclSid;
this.auditFailure = source.auditFailure;
this.auditSuccess = source.auditSuccess;
this.granting = source.granting;
this.mask = source.mask;
return this;
}
}
package org.genesys.blocks.security.model;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
......@@ -18,7 +19,7 @@ import org.genesys.blocks.model.BasicModel;
@Entity
@Table(name = "acl_object_identity", uniqueConstraints = @UniqueConstraint(columnNames = { "object_id_class", "object_id_identity" }))
public class AclObjectIdentity extends BasicModel {
public class AclObjectIdentity extends BasicModel<AclObjectIdentity> {
private static final long serialVersionUID = -8987281958564243010L;
......@@ -91,4 +92,18 @@ public class AclObjectIdentity extends BasicModel {
public void setAclEntries(final List<AclEntry> aclEntries) {
this.aclEntries = aclEntries;
}
@Override
public AclObjectIdentity apply(AclObjectIdentity source) {
super.apply((BasicModel<?>) source);
this.aclClass = source.aclClass;
this.aclEntries = new ArrayList<>(source.aclEntries);
this.entriesInheriting = source.entriesInheriting;
this.objectIdIdentity = source.objectIdIdentity;
this.ownerSid = source.ownerSid;
this.parentObject = source.parentObject;
return this;
}
}
package org.genesys.blocks.security.model;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
......@@ -15,7 +16,7 @@ import org.genesys.blocks.model.BasicModel;
@Entity
@Table(name = "acl_sid")
public class AclSid extends BasicModel {
public class AclSid extends BasicModel<AclSid> {
private static final long serialVersionUID = -8665345718313672678L;
......@@ -64,4 +65,16 @@ public class AclSid extends BasicModel {
public void setAclEntries(final List<AclEntry> aclEntries) {
this.aclEntries = aclEntries;
}
@Override
public AclSid apply(AclSid source) {
super.apply((BasicModel<?>) source);
this.aclEntries = new ArrayList<>(source.aclEntries);
this.objectIdentities = new ArrayList<>(source.objectIdentities);
this.principal = source.principal;
this.sid = source.sid;
return this;
}
}
......@@ -48,7 +48,7 @@ import org.springframework.security.core.userdetails.UserDetails;
//@Table(name = "user")
//@Audited
@MappedSuperclass
public abstract class BasicUser<R> extends AuditedVersionedModel implements UserDetails {
public abstract class BasicUser<R> extends AuditedVersionedModel<BasicUser<R>> implements UserDetails {
private static final long serialVersionUID = -5318892732608111516L;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment