Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2010 JBoss Inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.jbpm.services.task.impl.model;
 
 
 import java.util.Date;
 import java.util.List;
 
 import  javax.persistence.CascadeType;
 import  javax.persistence.Embeddable;
 import  javax.persistence.EnumType;
 import  javax.persistence.Enumerated;
 import  javax.persistence.JoinColumn;
 import  javax.persistence.ManyToOne;
 import  javax.persistence.OneToMany;
 import  javax.persistence.Temporal;
 
 import  org.kie.api.task.model.Attachment;
 import  org.kie.api.task.model.Comment;
 import  org.kie.api.task.model.Status;
 import  org.kie.api.task.model.User;
 import  org.kie.internal.task.api.model.AccessType;
 import  org.kie.internal.task.api.model.ContentData;
 import  org.kie.internal.task.api.model.FaultData;
 import  org.kie.internal.task.api.model.InternalTaskData;
 
 @Embeddable
 public class TaskDataImpl implements InternalTaskData {
     @Enumerated(EnumType.STRING)
     private Status status = Status.Created;         // initial default state
 
     private Status previousStatus = null;
 
     @ManyToOne(targetEntity=UserImpl.class)
     private User actualOwner;
 
     @ManyToOne(targetEntity=UserImpl.class)
     private User createdBy;
 
     @Temporal(javax.persistence.TemporalType.TIMESTAMP)
     private Date createdOn;
 
     @Temporal(javax.persistence.TemporalType.TIMESTAMP)
     private Date activationTime;
 
     @Temporal(javax.persistence.TemporalType.TIMESTAMP)
     private Date expirationTime;
 
     private boolean skipable;
 
     private long workItemId = -1;
     
     private long processInstanceId = -1;
 
     private AccessType documentAccessType;
 
     private String documentType;
 
     private long documentContentId = -1;
 
     private AccessType outputAccessType;
 
     private String outputType;
 
     private long outputContentId = -1;
 
     private String faultName;
 
     private AccessType faultAccessType;
 
     private String faultType;
 
     private long faultContentId = -1;
 
     private long parentId = -1;
     
     private String processId;
     
     private String deploymentId;
    
    private int processSessionId;
    @OneToMany(cascade = CascadeType.ALL, targetEntity=CommentImpl.class)
    @JoinColumn(name = "TaskData_Comments_Id", nullable = true)
    private List<Comment> comments = Collections.emptyList();
    @OneToMany(cascade = CascadeType.ALL, targetEntity=AttachmentImpl.class)
    @JoinColumn(name = "TaskData_Attachments_Id", nullable = true)
    private List<Attachment> attachments = Collections.emptyList();
    public void writeExternal(ObjectOutput outthrows IOException {
        if ( != null) {
            out.writeBoolean(true);
            out.writeUTF(.toString());
        } else {
            out.writeBoolean(false);
        }
        if ( != null) {
            out.writeBoolean(true);
            out.writeUTF(.toString());
        } else {
            out.writeBoolean(false);
        }
        if ( != null) {
            out.writeBoolean(true);
            .writeExternal(out);
        } else {
            out.writeBoolean(false);
        }
        if ( != null) {
            out.writeBoolean(true);
            .writeExternal(out);
        } else {
            out.writeBoolean(false);
        }
        if ( != null) {
            out.writeBoolean(true);
            out.writeLong(.getTime());
        } else {
            out.writeBoolean(false);
        }
        if ( != null) {
            out.writeBoolean(true);
            out.writeLong(.getTime());
        } else {
            out.writeBoolean(false);
        }
        if ( != null) {
            out.writeBoolean(true);
            out.writeLong(.getTime());
        } else {
            out.writeBoolean(false);
        }
        out.writeBoolean();
        if ( != -1) {
            out.writeBoolean(true);
            out.writeLong();
        } else {
            out.writeBoolean(false);
        }
        if ( != -1) {
            out.writeBoolean(true);
            out.writeLong();
        } else {
            out.writeBoolean(false);
        }
        if ( != null) {
            out.writeBoolean(true);
            out.writeObject();
        } else {
            out.writeBoolean(false);
        }
        if ( != null) {
            out.writeBoolean(true);
            out.writeUTF();
        } else {
            out.writeBoolean(false);
        }
        if ( != -1) {
            out.writeBoolean(true);
            out.writeLong();
        } else {
            out.writeBoolean(false);
        }
        if ( != null) {
            out.writeBoolean(true);
            out.writeObject();
        } else {
            out.writeBoolean(false);
        }
        if ( != null) {
            out.writeBoolean(true);
            out.writeUTF();
        } else {
            out.writeBoolean(false);
        }
        if ( != -1) {
            out.writeBoolean(true);
            out.writeLong();
        } else {
            out.writeBoolean(false);
        }
        if ( != null) {
            out.writeBoolean(true);
            out.writeUTF();
        } else {
            out.writeBoolean(false);
        }
        if ( != null) {
            out.writeBoolean(true);
            out.writeObject();
        } else {
            out.writeBoolean(false);
        }
        if ( != null) {
            out.writeBoolean(true);
            out.writeUTF();
        } else {
            out.writeBoolean(false);
        }
        if ( != -1) {
            out.writeBoolean(true);
            out.writeLong();
        } else {
            out.writeBoolean(false);
        }
        if ( != -1) {
            out.writeBoolean(true);
            out.writeLong();
        } else {
            out.writeBoolean(false);
        }
        
        if ( != null) {
            out.writeBoolean(true);
            out.writeUTF();
        } else {
            out.writeBoolean(false);
        }
        
        if ( != -1) {
            out.writeBoolean(true);
            out.writeInt();
        } else {
            out.writeBoolean(false);
        }
        CollectionUtils.writeCommentList(,
                out);
        CollectionUtils.writeAttachmentList(,
                out);
    }
    public void readExternal(ObjectInput inthrows IOException,
            ClassNotFoundException {
        if (in.readBoolean()) {
             = Status.valueOf(in.readUTF());
        }
        if (in.readBoolean()) {
             = Status.valueOf(in.readUTF());
        }
        if (in.readBoolean()) {
             = new UserImpl();
            .readExternal(in);
        }
        if (in.readBoolean()) {
             = new UserImpl();
            .readExternal(in);
        }
        if (in.readBoolean()) {
             = new Date(in.readLong());
        }
        if (in.readBoolean()) {
             = new Date(in.readLong());
        }
        if (in.readBoolean()) {
             = new Date(in.readLong());
        }
         = in.readBoolean();
        if (in.readBoolean()) {
             = in.readLong();
        }
        if (in.readBoolean()) {
             = in.readLong();
        }
        if (in.readBoolean()) {
             = (AccessType) in.readObject();
        }
        if (in.readBoolean()) {
             = in.readUTF();
        }
        if (in.readBoolean()) {
             = in.readLong();
        }
        if (in.readBoolean()) {
             = (AccessType) in.readObject();
        }
        if (in.readBoolean()) {
             = in.readUTF();
        }
        if (in.readBoolean()) {
             = in.readLong();
        }
        if (in.readBoolean()) {
             = in.readUTF();
        }
        if (in.readBoolean()) {
             = (AccessType) in.readObject();
        }
        if (in.readBoolean()) {
             = in.readUTF();
        }
        if (in.readBoolean()) {
             = in.readLong();
        }
        if (in.readBoolean()) {
             = in.readLong();
        }
        
        if (in.readBoolean()) {
             = in.readUTF();
        }
        
        if (in.readBoolean()) {
             = in.readInt();
        }
        
         = CollectionUtils.readCommentList(in);
         = CollectionUtils.readAttachmentList(in);
    }

    
Initializes the state of the TaskData, i.e. sets the <field>createdOn</field>, <field>activationTime</field> and sets the state to Status.Created.

Returns:
returns the current state of the TaskData
    public Status initialize() {
        Date createdOn = getCreatedOn();
        // set the CreatedOn date if it's not already set
        if (createdOn == null) {
            createdOn = new Date();
            setCreatedOn(createdOn);
        }
        //@FIXME for now we activate on creation, unless date is supplied
        if (getActivationTime() == null) {
            setActivationTime(createdOn);
        }
        setStatus(Status.Created);
        return Status.Created;
    }
    public Status getStatus() {
        return ;
    }
    public void setStatus(Status status) {
         = this.;
        this. = status;
    }
    public Status getPreviousStatus() {
        return ;
    }
    public void setPreviousStatus(Status previousStatus) {
        this. = previousStatus;
    }
    public User getActualOwner() {
        return ;
    }
    public void setActualOwner(User actualOwner) {
        this. = convertToUserImpl(actualOwner);
    }
    public User getCreatedBy() {
        return ;
    }
    public void setCreatedBy(User createdBy) {
        this. = convertToUserImpl(createdBy);
    }
    public Date getCreatedOn() {
        return ;
    }
    public void setCreatedOn(Date createdOn) {
        this. = createdOn;
    }
    public Date getActivationTime() {
        return ;
    }
    public void setActivationTime(Date activationTime) {
        this. = activationTime;
    }
    public Date getExpirationTime() {
        return ;
    }
    public void setExpirationTime(Date expirationTime) {
        this. = expirationTime;
    }
    public boolean isSkipable() {
        return ;
    }
    public void setSkipable(boolean isSkipable) {
        this. = isSkipable;
    }
    public void setWorkItemId(long workItemId) {
        this. = workItemId;
    }
    public long getWorkItemId() {
        return ;
    }
    
    public void setProcessInstanceId(long processInstanceId) {
    	this. = processInstanceId;
    }
    
    public long getProcessInstanceId() {
    	return ;
    }
    
    public String getProcessId() {
		return ;
	}
	public void setProcessId(String processId) {
		this. = processId;
	}
	public int getProcessSessionId() {
	}
	public void setProcessSessionId(int processSessionId) {
		this. = processSessionId;
	}

Sets the document content data for this task data. It will set the <field>documentContentId</field> from the specified documentID, <field>documentAccessType</field>, <field>documentType</field> from the specified documentConentData.

Parameters:
documentID id of document content
documentConentData ContentData
    public void setDocument(long documentID, ContentData documentConentData) {
        setDocumentContentId(documentID);
        setDocumentAccessType(documentConentData.getAccessType());
        setDocumentType(documentConentData.getType());
    }
    public AccessType getDocumentAccessType() {
        return ;
    }
    public void setDocumentAccessType(AccessType accessType) {
        this. = accessType;
    }
    public String getDocumentType() {
        return ;
    }
    public long getDocumentContentId() {
        return ;
    }
    public void setDocumentContentId(long documentContentId) {
        this. = documentContentId;
    }
    public void setDocumentType(String documentType) {
        this. = documentType;
    }

    
Sets the content data for this task data. It will set the <field>outputContentId</field> from the specified outputContentId, <field>outputAccessType</field>, <field>outputType</field> from the specified outputContentData.

Parameters:
outputContentId id of output content
outputContentData contentData
    public void setOutput(long outputContentId, ContentData outputContentData) {
        setOutputContentId(outputContentId);
        setOutputAccessType(outputContentData.getAccessType());
        setOutputType(outputContentData.getType());
    }
    public AccessType getOutputAccessType() {
        return ;
    }
    public void setOutputAccessType(AccessType outputAccessType) {
        this. = outputAccessType;
    }
    public String getOutputType() {
        return ;
    }
    public void setOutputType(String outputType) {
        this. = outputType;
    }
    public long getOutputContentId() {
        return ;
    }
    public void setOutputContentId(long outputContentId) {
        this. = outputContentId;
    }

    
Sets the fault data for this task data. It will set the <field>faultContentId</field> from the specified faultContentId, <field>faultAccessType</field>, <field>faultType</field>, <field>faultName</field> from the specified faultData.

Parameters:
faultContentId id of fault content
faultData FaultData
    public void setFault(long faultContentId, FaultData faultData) {
        setFaultContentId(faultContentId);
        setFaultAccessType(faultData.getAccessType());
        setFaultType(faultData.getType());
        setFaultName(faultData.getFaultName());
    }
    public String getFaultName() {
        return ;
    }
    public void setFaultName(String faultName) {
        this. = faultName;
    }
    public AccessType getFaultAccessType() {
        return ;
    }
    public void setFaultAccessType(AccessType faultAccessType) {
        this. = faultAccessType;
    }
    public String getFaultType() {
        return ;
    }
    public void setFaultType(String faultType) {
        this. = faultType;
    }
    public long getFaultContentId() {
        return ;
    }
    public void setFaultContentId(long faultContentId) {
        this. = faultContentId;
    }
    public List<Comment> getComments() {
        return ;
    }

    
Adds the specified comment to our list of comments.

Parameters:
comment comment to add
    public void addComment(Comment comment) {
        if ( == null || .size() == 0) {
             = new ArrayList<Comment>();
        }
        .add((CommentImplcomment);
    }

    
Removes the Comment specified by the commentId.

Parameters:
commentId id of Comment to remove
Returns:
removed Comment or null if one was not found with the id
    public Comment removeComment(final long commentId) {
        Comment removedComment = null;
        if ( != null) {
            for (int index = .size() - 1; index >= 0; --index) {
                Comment currentComment = .get(index);
                if (currentComment.getId() == commentId) {
                    removedComment = .remove(index);
                    break;
                }
            }
        }
        return removedComment;
    }
    public void setComments(List<Comment> comments) {
        this. = comments;
    }
    public List<Attachment> getAttachments() {
        return ;
    }

    
Adds the specified attachment to our list of Attachments.

Parameters:
attachment attachment to add
    public void addAttachment(Attachment attachment) {
        if ( == null ||  == Collections.<Attachment>emptyList()) {
             = new ArrayList<Attachment>();
        }
        .add((AttachmentImplattachment);
    }

    
Removes the Attachment specified by the attachmentId.

Parameters:
attachmentId id of attachment to remove
Returns:
removed Attachment or null if one was not found with the id
    public Attachment removeAttachment(final long attachmentId) {
        Attachment removedAttachment = null;
        if ( != null) {
            for (int index = .size() - 1; index >= 0; --index) {
                Attachment currentAttachment = .get(index);
                if (currentAttachment.getId() == attachmentId) {
                    removedAttachment = .remove(index);
                    break;
                }
            }
        }
        return removedAttachment;
    }
    public void setAttachments(List<Attachment> attachments) {
        this. =  attachments;
    }
    public long getParentId() {
        return ;
    }
    public void setParentId(long parentId) {
        this. = parentId;
    }
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + CollectionUtils.hashCode();
        result = prime * result + CollectionUtils.hashCode();
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + ( ? 1231 : 1237);
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + (( == -1) ? 0 : (int);
        //Should I add parentId to this hashCode?
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == objreturn true;
        if (obj == nullreturn false;
        if (!(obj instanceof TaskDataImpl)) return false;
        TaskDataImpl other = (TaskDataImplobj;
        if ( == null) {
            if (other.actualOwner != nullreturn false;
        } else if (!.equals(other.actualOwner)) {
            return false;
        }
        if ( == null) {
            if (other.createdBy != nullreturn false;
        } else if (!.equals(other.createdBy)) {
            return false;
        }
        if ( == null) {
            if (other.createdOn != nullreturn false;
        } else if (.getTime() != other.createdOn.getTime()) return false;
        if ( == null) {
            if (other.expirationTime != nullreturn false;
        } else if (.getTime() != other.expirationTime.getTime()) return false;
        if ( != other.skipablereturn false;
        if ( != other.workItemIdreturn false;
        if ( == null) {
            if (other.status != nullreturn false;
        } else if (!.equals(other.status)) return false;
        if ( == null) {
            if (other.previousStatus != nullreturn false;
        } else if (!.equals(other.previousStatus)) return false;
        if ( == null) {
            if (other.activationTime != nullreturn false;
        } else if (.getTime() != other.activationTime.getTime()) return false;
        if ( != other.workItemIdreturn false;
        if ( == null) {
            if (other.documentAccessType != nullreturn false;
        } else if (!.equals(other.documentAccessType)) return false;
        if ( != other.documentContentIdreturn false;
        if ( == null) {
            if (other.documentType != nullreturn false;
        } else if (!.equals(other.documentType)) return false;
        // I think this is OK!
        if ( != other.parentIdreturn false;
        if ( == null) {
            if (other.processId != nullreturn false;
        } else if (!.equals(other.processId)) return false;
        if ( != other.processSessionIdreturn false;        
        if ( == null) {
            if (other.deploymentId != nullreturn false;
        } else if (!.equals(other.deploymentId)) return false;        
        return CollectionUtils.equals(,
                other.attachments) && CollectionUtils.equals(,
                other.comments);
    }
    @Override
    public String getDeploymentId() {
        return ;
    }
    @Override
    public void setDeploymentId(String deploymentId) {
        this. = deploymentId;
    }
    
    static UserImpl convertToUserImpl(User user) { 
        ifuser == null ) { 
            return null;
        }
        ifuser instanceof UserImpl ) { 
            return (UserImpluser;
        } else { 
            return new UserImpl(user.getId());
        }
    }
    static GroupImpl convertToGroupImpl(GroupImpl group) { 
        ifgroup == null ) { 
            return null;
        }
        ifgroup instanceof GroupImpl ) { 
            return (GroupImplgroup;
        } else { 
            return new GroupImpl(group.getId());
        }
    }
New to GrepCode? Check out our FAQ X