Skip to content

Commit

Permalink
BZ-1192148 - TaskData object not storing Comments, CreatedOn, Expirat…
Browse files Browse the repository at this point in the history
…ionTime
  • Loading branch information
Marco Rietveld committed Feb 17, 2015
1 parent defbee6 commit b386338
Show file tree
Hide file tree
Showing 19 changed files with 773 additions and 721 deletions.
Expand Up @@ -4,6 +4,7 @@
*/
package org.jbpm.services.task.audit.impl.model;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
Expand All @@ -29,7 +30,7 @@
@Entity
@Table(name = "TaskEvent")
@SequenceGenerator(name = "taskEventIdSeq", sequenceName = "TASK_EVENT_ID_SEQ")
public class TaskEventImpl implements TaskEvent {
public class TaskEventImpl implements TaskEvent, Externalizable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "taskEventIdSeq")
Expand Down Expand Up @@ -137,7 +138,6 @@ public void readExternal(ObjectInput in) throws IOException,
if (in.readBoolean()) {
logTime = new Date(in.readLong());
}

}

@Override
Expand Down
Expand Up @@ -15,7 +15,7 @@
*/
package org.jbpm.services.task.commands;

import static org.jbpm.services.task.impl.model.xml.JaxbOrganizationalEntity.convertListFromInterfaceToJaxbImpl;
import static org.jbpm.services.task.impl.model.xml.AbstractJaxbTaskObject.convertListFromInterfaceToJaxbImpl;
import static org.jbpm.services.task.impl.model.xml.JaxbOrganizationalEntity.convertListFromJaxbImplToInterface;

import java.util.List;
Expand Down Expand Up @@ -58,7 +58,7 @@ public NominateTaskCommand(long taskId, String userId, List<OrganizationalEntity
}

public void setPotentialOwners(List<OrganizationalEntity> potentialOwners) {
this.potentialOwners = convertListFromInterfaceToJaxbImpl(potentialOwners);
this.potentialOwners = convertListFromInterfaceToJaxbImpl(potentialOwners, OrganizationalEntity.class, JaxbOrganizationalEntity.class);
}

public Void execute(Context cntxt) {
Expand Down
@@ -1,15 +1,14 @@
package org.jbpm.services.task.impl.model.xml;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlTransient;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.kie.api.task.model.Group;
import org.kie.api.task.model.User;

@JsonIgnoreProperties({"realClass"})
Expand All @@ -22,11 +21,11 @@ public AbstractJaxbTaskObject() {
throw new UnsupportedOperationException("No-arg constructor must be implemented by the concrete class.");
}

public AbstractJaxbTaskObject(Class<?> realClass) {
protected AbstractJaxbTaskObject(Class<?> realClass) {
this.realClass = realClass;
}

public AbstractJaxbTaskObject(T taskObject, Class<?> objectInterface) {
protected AbstractJaxbTaskObject(T taskObject, Class<?> objectInterface) {
this(objectInterface);
if (taskObject != null) {
for (Method getIsMethod : objectInterface.getDeclaredMethods() ) {
Expand Down Expand Up @@ -59,51 +58,46 @@ public AbstractJaxbTaskObject(T taskObject, Class<?> objectInterface) {
}
}
}

/**
* I was forced to do this because we put the interfaces to our *ENTITIES* in the *PUBLIC* API.
*/
static class GetterUser implements User {

private final String id;
public GetterUser(String id) {
this.id = id;
}

@Override
public String getId() {
return this.id;
}

public void writeExternal(ObjectOutput out) throws IOException { unsupported(User.class); }
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { unsupported(User.class); }
}

static class GetterGroup implements Group {
private final String id;
public GetterGroup(String id) {
this.id = id;
}

@Override
public String getId() {
return this.id;
}

public void writeExternal(ObjectOutput out) throws IOException { unsupported(User.class); }
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { unsupported(User.class); }
}

public void readExternal(ObjectInput arg0) throws IOException, ClassNotFoundException {
unsupported(realClass);
}

public void writeExternal(ObjectOutput arg0) throws IOException {
unsupported(realClass);
}

static Object unsupported(Class<?> realClass) {
String methodName = (new Throwable()).getStackTrace()[1].getMethodName();
throw new UnsupportedOperationException(methodName + " is not supported on the JAXB " + realClass.getSimpleName() + " implementation.");
}

public static <I,J extends I> List<J> convertListFromInterfaceToJaxbImpl(List<I> interfacelList, Class<I> interfaceClass, Class<J> jaxbClass) {
List<J> jaxbList;
if( interfacelList != null ) {
jaxbList = new ArrayList<J>(interfacelList.size());
for( I interfaze : interfacelList ) {
if( jaxbClass.isAssignableFrom(interfaze.getClass()) ) {
jaxbList.add((J) interfaze);
} else {
jaxbList.add(jaxbConstructorWithInternalAsArgument(jaxbClass, interfaceClass, interfaze));
}
}
} else {
jaxbList = new ArrayList<J>();
}
return jaxbList;
}

private static <J,I> J jaxbConstructorWithInternalAsArgument(Class<J> jaxbClass, Class<I> interfaze, I argument) {
Class [] cnstrArgs = { interfaze };
try {
Constructor<J> cnstr = jaxbClass.getConstructor(cnstrArgs);
return cnstr.newInstance(argument);
} catch( Exception e ) {
throw new RuntimeException("Unable to create " + jaxbClass.getName() + " using constructor with " + interfaze.getName() + " argument.", e);
}
}

@SuppressWarnings("unchecked")
static <T> T whenNull(Object value, T defaultValue) {
if (value == null) {
return defaultValue;
}

return (T) value;
}
}
@@ -0,0 +1,83 @@
package org.jbpm.services.task.impl.model.xml;

import static org.jbpm.services.task.impl.model.xml.AbstractJaxbTaskObject.unsupported;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

import org.kie.api.task.model.Group;
import org.kie.api.task.model.I18NText;
import org.kie.api.task.model.User;

/**
* This class is used to produce Task API objects.
*
* The class (and all subclasses) are deliberately package-scoped because there are interfaces for these objects.
*/
class InternalJaxbWrapper {

static class GetterUser implements User {

private final String id;
public GetterUser(String id) {
this.id = id;
}

@Override
public String getId() {
return this.id;
}

@Override
public void writeExternal( ObjectOutput out ) throws IOException { unsupported(User.class); }
@Override
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { unsupported(User.class); }
}

static class GetterGroup implements Group {

private final String id;

public GetterGroup(String id) {
this.id = id;
}

@Override
public String getId() {
return this.id;
}

@Override
public void writeExternal( ObjectOutput out ) throws IOException { unsupported(Group.class); }
@Override
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { unsupported(Group.class); }
}

static class GetterI18NText implements I18NText {

private final Long id;
private final String lang;
private final String text;

public GetterI18NText(Long id, String lang, String text) {
this.id = id;
this.lang = lang;
this.text = text;
}

@Override
public Long getId() { return this.id; }

@Override
public String getLanguage() { return this.lang; }

@Override
public String getText() { return this.text; }

@Override
public void writeExternal( ObjectOutput out ) throws IOException { unsupported(I18NText.class); }
@Override
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { unsupported(I18NText.class); };
}
}
@@ -1,18 +1,22 @@
package org.jbpm.services.task.impl.model.xml;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Date;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.jbpm.services.task.impl.model.xml.InternalJaxbWrapper.GetterUser;
import org.kie.api.task.model.Attachment;
import org.kie.api.task.model.User;

@XmlRootElement(name="attachment")
@XmlType(name="attachment")
@XmlAccessorType(XmlAccessType.FIELD)
@JsonAutoDetect(getterVisibility=JsonAutoDetect.Visibility.NONE, setterVisibility=JsonAutoDetect.Visibility.NONE, fieldVisibility=JsonAutoDetect.Visibility.ANY)
public class JaxbAttachment extends AbstractJaxbTaskObject<Attachment> implements Attachment {
Expand Down Expand Up @@ -82,14 +86,28 @@ public User getAttachedBy() {
return new GetterUser(this.attachedBy);
}

public String getAttachedById() {
return this.attachedBy;
}

@Override
public int getSize() {
return size;
return whenNull(size, -1);
}

@Override
public long getAttachmentContentId() {
return attachmentContentId;
return whenNull(attachmentContentId, -1l);
}

@Override
public void writeExternal( ObjectOutput out ) throws IOException {
unsupported(Attachment.class);
}

@Override
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {
unsupported(Attachment.class);
}

}
@@ -1,18 +1,22 @@
package org.jbpm.services.task.impl.model.xml;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Date;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.jbpm.services.task.impl.model.xml.InternalJaxbWrapper.GetterUser;
import org.kie.api.task.model.Comment;
import org.kie.api.task.model.User;

@XmlRootElement(name="comment")
@XmlType(name="comment")
@XmlAccessorType(XmlAccessType.FIELD)
@JsonAutoDetect(getterVisibility=JsonAutoDetect.Visibility.NONE, setterVisibility=JsonAutoDetect.Visibility.NONE, fieldVisibility=JsonAutoDetect.Visibility.ANY)
public class JaxbComment extends AbstractJaxbTaskObject<Comment> implements Comment {
Expand Down Expand Up @@ -62,8 +66,22 @@ public User getAddedBy() {
return new GetterUser(this.addedBy);
}

public String getAddedById() {
return this.addedBy;
}

@Override
public Date getAddedAt() {
return addedAt;
}

@Override
public void writeExternal( ObjectOutput out ) throws IOException {
unsupported(Comment.class);
}

@Override
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {
unsupported(Comment.class);
}
}
Expand Up @@ -12,10 +12,10 @@
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.jbpm.services.task.utils.ContentMarshallerHelper;
import org.kie.api.task.model.Content;
import org.kie.internal.jaxb.StringKeyObjectValueMapXmlAdapter;
Expand Down Expand Up @@ -44,6 +44,7 @@ public JaxbContent(Content content) {
initialize(content);
}

@SuppressWarnings("unchecked")
public void initialize(Content content) {
if( content == null || content.getId() == -1) {
return;
Expand Down Expand Up @@ -84,13 +85,16 @@ public long getId() {

public void setId(Long id) {
this.id = id;
}

public void readExternal(ObjectInput arg0) throws IOException, ClassNotFoundException {
unsupported(Content.class);
}

public void writeExternal(ObjectOutput arg0) throws IOException {
@Override
public void writeExternal( ObjectOutput out ) throws IOException {
unsupported(Content.class);
}

@Override
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {
unsupported(Content.class);
}

}

0 comments on commit b386338

Please sign in to comment.