TSK-1090 Refactored AttachmentImpl

This commit is contained in:
Sofie Hofmann 2020-02-07 12:40:21 +01:00
parent 2924eda82e
commit 1ecb613526
3 changed files with 40 additions and 192 deletions

View File

@ -6,56 +6,7 @@ import java.util.Map;
import pro.taskana.classification.api.ClassificationSummary; import pro.taskana.classification.api.ClassificationSummary;
/** Attachment-Interface to specify Attachment Attributes. */ /** Attachment-Interface to specify Attachment Attributes. */
public interface Attachment { public interface Attachment extends AttachmentSummary {
/**
* Returns the current id of the attachment.
*
* @return ID of attachment
*/
String getId();
/**
* Returns the id of the associated task.
*
* @return taskId
*/
String getTaskId();
/**
* Returns the time when the attachment was created.
*
* @return the created time as {@link Instant}
*/
Instant getCreated();
/**
* Returns the time when the attachment was last modified.
*
* @return modified {@link Instant} of the attachment
*/
Instant getModified();
/**
* Returns the classification summary of the attachment.
*
* @return the {@link ClassificationSummary} of this attachment
*/
ClassificationSummary getClassificationSummary();
/**
* Set the classification summary for this attachment.
*
* @param classificationSummary the {@link ClassificationSummary} for this attachment
*/
void setClassificationSummary(ClassificationSummary classificationSummary);
/**
* Returns the {@link ObjectReference primaryObjectReference} of the attachment.
*
* @return {@link ObjectReference primaryObjectReference} of the attachment
*/
ObjectReference getObjectReference();
/** /**
* Sets the {@link ObjectReference primaryObjectReference} of the attachment. * Sets the {@link ObjectReference primaryObjectReference} of the attachment.
@ -65,25 +16,11 @@ public interface Attachment {
void setObjectReference(ObjectReference objectReference); void setObjectReference(ObjectReference objectReference);
/** /**
* Returns the Channel on which the attachment was received. * Set the classification summary for this attachment.
* *
* @return the Channel on which the attachment was received. * @param classificationSummary the {@link ClassificationSummary} for this attachment
*/ */
String getChannel(); void setClassificationSummary(ClassificationSummary classificationSummary);
/**
* Sets the Channel on which the attachment was received.
*
* @param channel the channel on which the attachment was received
*/
void setChannel(String channel);
/**
* Returns the time when this attachment was received.
*
* @return received time as exact {@link Instant}
*/
Instant getReceived();
/** /**
* Sets the time when the attachment was received. * Sets the time when the attachment was received.
@ -92,6 +29,13 @@ public interface Attachment {
*/ */
void setReceived(Instant received); void setReceived(Instant received);
/**
* Sets the Channel on which the attachment was received.
*
* @param channel the channel on which the attachment was received
*/
void setChannel(String channel);
/** /**
* Returns the custom attributes of this attachment. * Returns the custom attributes of this attachment.
* *

View File

@ -1,111 +1,23 @@
package pro.taskana.task.internal; package pro.taskana.task.internal;
import java.time.Instant;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import pro.taskana.classification.api.ClassificationSummary;
import pro.taskana.classification.internal.ClassificationSummaryImpl;
import pro.taskana.task.api.Attachment; import pro.taskana.task.api.Attachment;
import pro.taskana.task.api.AttachmentSummary; import pro.taskana.task.api.AttachmentSummary;
import pro.taskana.task.api.ObjectReference;
/** /**
* Attachment entity. * Attachment entity.
* *
* @author bbr * @author bbr
*/ */
public class AttachmentImpl implements Attachment { public class AttachmentImpl extends AttachmentSummaryImpl implements Attachment {
private String id; private Map<String, String> customAttributes = new HashMap<>();
private String taskId;
private Instant created;
private Instant modified;
private ClassificationSummary classificationSummary;
private ObjectReference objectReference;
private String channel;
private Instant received;
private Map<String, String> customAttributes = new HashMap<String, String>();
public AttachmentImpl() {} public AttachmentImpl() {}
@Override
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Override
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
@Override
public Instant getCreated() {
return created;
}
public void setCreated(Instant created) {
this.created = created;
}
@Override
public Instant getModified() {
return modified;
}
public void setModified(Instant modified) {
this.modified = modified;
}
@Override
public ClassificationSummary getClassificationSummary() {
return classificationSummary;
}
@Override
public void setClassificationSummary(ClassificationSummary classificationSummary) {
this.classificationSummary = classificationSummary;
}
@Override
public ObjectReference getObjectReference() {
return objectReference;
}
@Override
public void setObjectReference(ObjectReference objectReference) {
this.objectReference = objectReference;
}
@Override
public String getChannel() {
return channel;
}
@Override
public void setChannel(String channel) {
this.channel = channel;
}
@Override
public Instant getReceived() {
return received;
}
@Override
public void setReceived(Instant received) {
this.received = received;
}
@Override @Override
public Map<String, String> getCustomAttributes() { public Map<String, String> getCustomAttributes() {
if (customAttributes == null) { if (customAttributes == null) {
@ -133,28 +45,13 @@ public class AttachmentImpl implements Attachment {
return summary; return summary;
} }
// auxiliary method to enable MyBatis access to classificationSummary protected boolean canEqual(Object other) {
public ClassificationSummaryImpl getClassificationSummaryImpl() { return (!(other instanceof AttachmentImpl));
return (ClassificationSummaryImpl) classificationSummary;
}
// auxiliary method to enable MyBatis access to classificationSummary
public void setClassificationSummaryImpl(ClassificationSummaryImpl classificationSummary) {
this.classificationSummary = classificationSummary;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash( return Objects.hash(super.hashCode(), customAttributes);
id,
taskId,
created,
modified,
classificationSummary,
objectReference,
channel,
received,
customAttributes);
} }
@Override @Override
@ -165,16 +62,14 @@ public class AttachmentImpl implements Attachment {
if (!(obj instanceof AttachmentImpl)) { if (!(obj instanceof AttachmentImpl)) {
return false; return false;
} }
if (!super.equals(obj)) {
return false;
}
AttachmentImpl other = (AttachmentImpl) obj; AttachmentImpl other = (AttachmentImpl) obj;
return Objects.equals(id, other.id) if (other.canEqual(this)) {
&& Objects.equals(taskId, other.taskId) return false;
&& Objects.equals(created, other.created) }
&& Objects.equals(modified, other.modified) return Objects.equals(customAttributes, other.customAttributes);
&& Objects.equals(classificationSummary, other.classificationSummary)
&& Objects.equals(objectReference, other.objectReference)
&& Objects.equals(channel, other.channel)
&& Objects.equals(received, other.received)
&& Objects.equals(customAttributes, other.customAttributes);
} }
@Override @Override

View File

@ -11,14 +11,14 @@ import pro.taskana.task.api.ObjectReference;
/** The most important fields of the Attachment entity. */ /** The most important fields of the Attachment entity. */
public class AttachmentSummaryImpl implements AttachmentSummary { public class AttachmentSummaryImpl implements AttachmentSummary {
private String id; protected String id;
private String taskId; protected String taskId;
private Instant created; protected Instant created;
private Instant modified; protected Instant modified;
private ClassificationSummary classificationSummary; protected ClassificationSummary classificationSummary;
private ObjectReference objectReference; protected ObjectReference objectReference;
private String channel; protected String channel;
private Instant received; protected Instant received;
AttachmentSummaryImpl() {} AttachmentSummaryImpl() {}
@ -127,15 +127,21 @@ public class AttachmentSummaryImpl implements AttachmentSummary {
} }
// auxiliary method to enable MyBatis access to classificationSummary // auxiliary method to enable MyBatis access to classificationSummary
@SuppressWarnings("unused")
public ClassificationSummaryImpl getClassificationSummaryImpl() { public ClassificationSummaryImpl getClassificationSummaryImpl() {
return (ClassificationSummaryImpl) classificationSummary; return (ClassificationSummaryImpl) classificationSummary;
} }
// auxiliary method to enable MyBatis access to classificationSummary // auxiliary method to enable MyBatis access to classificationSummary
@SuppressWarnings("unused")
public void setClassificationSummaryImpl(ClassificationSummaryImpl classificationSummary) { public void setClassificationSummaryImpl(ClassificationSummaryImpl classificationSummary) {
this.classificationSummary = classificationSummary; this.classificationSummary = classificationSummary;
} }
protected boolean canEqual(Object other) {
return (!(other instanceof AttachmentSummaryImpl));
}
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash( return Objects.hash(
@ -151,6 +157,9 @@ public class AttachmentSummaryImpl implements AttachmentSummary {
return false; return false;
} }
AttachmentSummaryImpl other = (AttachmentSummaryImpl) obj; AttachmentSummaryImpl other = (AttachmentSummaryImpl) obj;
if (other.canEqual(this)) {
return false;
}
return Objects.equals(id, other.id) return Objects.equals(id, other.id)
&& Objects.equals(taskId, other.taskId) && Objects.equals(taskId, other.taskId)
&& Objects.equals(created, other.created) && Objects.equals(created, other.created)