Skip to content

Commit

Permalink
Merge pull request #192 from NitorCreations/model-object
Browse files Browse the repository at this point in the history
add abstract base class for model objects
  • Loading branch information
jsyrjala committed Aug 26, 2016
2 parents c95d5c4 + 81cdd6f commit 785fece
Show file tree
Hide file tree
Showing 32 changed files with 111 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.nflow.engine.internal.config.NFlow;
import io.nflow.engine.internal.storage.db.SQLVariants;
import io.nflow.engine.model.ModelObject;
import io.nflow.engine.workflow.executor.WorkflowExecutor;
import io.nflow.engine.workflow.instance.WorkflowInstanceAction;

Expand Down Expand Up @@ -176,7 +177,7 @@ public InstanceInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
}
}

static final class InstanceInfo {
static final class InstanceInfo extends ModelObject {
public int id;
public String state;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.nflow.engine.internal.dao;

import static java.lang.String.format;
import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
Expand All @@ -15,14 +14,13 @@
import javax.inject.Inject;
import javax.inject.Named;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor;

import io.nflow.engine.internal.config.NFlow;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.nflow.engine.internal.config.NFlow;
import io.nflow.engine.model.ModelObject;

@Named
public class TableMetadataChecker {
Expand Down Expand Up @@ -93,7 +91,7 @@ private Map<String, String> typeAliases() {
}
}

private static class ColumnMetadata {
private static class ColumnMetadata extends ModelObject {
public final String columnName;
public final String typeName;
public final int size;
Expand All @@ -103,11 +101,6 @@ public ColumnMetadata(String columnName, String typeName, int size) {
this.typeName = typeName;
this.size = size;
}

@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, SHORT_PREFIX_STYLE);
}
}

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import io.nflow.engine.internal.config.NFlow;
import io.nflow.engine.internal.executor.WorkflowInstanceExecutor;
import io.nflow.engine.internal.storage.db.SQLVariants;
import io.nflow.engine.model.ModelObject;
import io.nflow.engine.workflow.instance.QueryWorkflowInstances;
import io.nflow.engine.workflow.instance.WorkflowInstance;
import io.nflow.engine.workflow.instance.WorkflowInstance.WorkflowInstanceStatus;
Expand Down Expand Up @@ -550,7 +551,7 @@ private void updateNextWorkflowInstancesWithBatchUpdate(List<OptimisticLockKey>
});
}

private static class OptimisticLockKey implements Comparable<OptimisticLockKey> {
private static class OptimisticLockKey extends ModelObject implements Comparable<OptimisticLockKey> {
public final int id;
public final Timestamp modified;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
import org.springframework.util.Assert;

import io.nflow.engine.internal.dao.WorkflowInstanceDao;
import io.nflow.engine.model.ModelObject;
import io.nflow.engine.workflow.definition.StateExecution;
import io.nflow.engine.workflow.definition.WorkflowState;
import io.nflow.engine.workflow.instance.QueryWorkflowInstances;
import io.nflow.engine.workflow.instance.WorkflowInstance;

public class StateExecutionImpl implements StateExecution {
public class StateExecutionImpl extends ModelObject implements StateExecution {

private static final Logger LOG = getLogger(StateExecutionImpl.class);
private final WorkflowInstance instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import java.util.List;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.nflow.engine.model.ModelObject;

public class StoredWorkflowDefinition {
public class StoredWorkflowDefinition extends ModelObject {
public String type;
public String description;
public String onError;
public List<State> states;

@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", justification = "used by nflow-rest")
public static class State implements Comparable<State> {
public static class State extends ModelObject implements Comparable<State> {

public State() {
// default constructor is required by Jackson deserializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import java.lang.reflect.Type;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.nflow.engine.model.ModelObject;

@SuppressFBWarnings(value="EI_EXPOSE_REP2", justification = "internal class, not important for security")
public class WorkflowStateMethod {
public class WorkflowStateMethod extends ModelObject {
public final Method method;
final StateParameter[] params;

static class StateParameter {
static class StateParameter extends ModelObject {
final String key;
final Type type;
final Object nullValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.joda.time.DateTime;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.nflow.engine.model.ModelObject;
import io.nflow.engine.workflow.definition.AbstractWorkflowDefinition;
import io.nflow.engine.workflow.definition.NextAction;
import io.nflow.engine.workflow.definition.StateExecution;
Expand All @@ -28,7 +29,7 @@ public interface WorkflowExecutorListener {
* life-cycle methods.
*/
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", justification = "listeners are implemented by business applications")
public class ListenerContext {
public class ListenerContext extends ModelObject {

/**
* The time when the listener context was created.
Expand Down
29 changes: 29 additions & 0 deletions nflow-engine/src/main/java/io/nflow/engine/model/ModelObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.nflow.engine.model;

import static org.apache.commons.lang3.builder.EqualsBuilder.reflectionEquals;
import static org.apache.commons.lang3.builder.HashCodeBuilder.reflectionHashCode;
import static org.apache.commons.lang3.builder.ToStringBuilder.reflectionToString;
import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE;

/**
* Inheriting ModelObject is an implementation detail only to provide toString/equals/hashCode for subclasses. We would use
* something more sensible method, but this is what Java allows. User code should never use ModelObject for anything.
*/
public abstract class ModelObject {

@Override
public String toString() {
return reflectionToString(this, SHORT_PREFIX_STYLE);
}

@Override
public boolean equals(Object obj) {
return reflectionEquals(this, obj);
}

@Override
public int hashCode() {
return reflectionHashCode(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Domain model classes.
*/
package io.nflow.engine.model;
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
import io.nflow.engine.internal.workflow.StateExecutionImpl;
import io.nflow.engine.internal.workflow.WorkflowDefinitionScanner;
import io.nflow.engine.internal.workflow.WorkflowStateMethod;
import io.nflow.engine.model.ModelObject;
import io.nflow.engine.workflow.instance.WorkflowInstance;

/**
* The base class for all workflow definitions.
*/
public abstract class AbstractWorkflowDefinition<S extends WorkflowState> {
public abstract class AbstractWorkflowDefinition<S extends WorkflowState> extends ModelObject {

private final String type;
private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import org.joda.time.DateTime;

import io.nflow.engine.internal.executor.InvalidNextActionException;
import io.nflow.engine.model.ModelObject;

public class NextAction {
public class NextAction extends ModelObject {

private final DateTime activation;
private final WorkflowState nextState;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.nflow.engine.workflow.definition;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.nflow.engine.model.ModelObject;

@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", justification = "used by nflow-rest")
public class WorkflowDefinitionStatistics {
public class WorkflowDefinitionStatistics extends ModelObject {
public long allInstances;
public long queuedInstances;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
import org.joda.time.DateTime;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.nflow.engine.model.ModelObject;

/**
* Configuration for the workflow execution.
*/
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", justification = "used by nflow-rest")
public class WorkflowSettings {
public class WorkflowSettings extends ModelObject {
/**
* Minimum delay on execution retry after an error. Unit is milliseconds.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import org.joda.time.DateTime;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.nflow.engine.model.ModelObject;

/**
* Describes one workflow executor.
*/
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", justification = "used by nflow-rest")
public class WorkflowExecutor {
public class WorkflowExecutor extends ModelObject {
/**
* Unique identifier of executor instance. Each time an executor is started it receives a new identifier.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import java.util.ArrayList;
import java.util.List;

import io.nflow.engine.model.ModelObject;
import io.nflow.engine.workflow.instance.WorkflowInstance.WorkflowInstanceStatus;

/**
* Parameters for workflow instance query.
*/
public class QueryWorkflowInstances {
public class QueryWorkflowInstances extends ModelObject {

/**
* Workflow instance identifiers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.joda.time.DateTime;

import io.nflow.engine.internal.workflow.ObjectStringMapper;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.nflow.engine.internal.workflow.ObjectStringMapper;
import io.nflow.engine.model.ModelObject;

/**
* An instance of a workflow.
*/
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", justification = "used by nflow-rest")
public class WorkflowInstance {
public class WorkflowInstance extends ModelObject {

/**
* Describes the status for workflow instance.
Expand Down Expand Up @@ -171,11 +169,6 @@ public static enum WorkflowInstanceStatus {
this.executorGroup = builder.executorGroup;
}

@Override
public String toString() {
return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
}

/**
* Return the state variables that have been added or modified during state processing.
* @return New and modified state variables.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

import org.joda.time.DateTime;

import io.nflow.engine.model.ModelObject;

/**
* An execution of a workflow instance state.
*/
public class WorkflowInstanceAction {
public class WorkflowInstanceAction extends ModelObject {
/**
* Describes the trigger for the action.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.nflow.engine.workflow.statistics;

import static org.apache.commons.lang3.builder.ToStringBuilder.reflectionToString;
import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.nflow.engine.model.ModelObject;

@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", justification = "used by nflow-rest")
public class Statistics {
public class Statistics extends ModelObject {

public final QueueStatistics queuedStatistics;
public final QueueStatistics executionStatistics;
Expand All @@ -17,7 +15,7 @@ public Statistics(QueueStatistics queuedStatistics, QueueStatistics executionSta
}

@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", justification = "used by nflow-rest")
public static class QueueStatistics {
public static class QueueStatistics extends ModelObject {
public final int count;
public final Long maxAgeMillis;
public final Long minAgeMillis;
Expand All @@ -27,14 +25,5 @@ public QueueStatistics(int count, Long maxAgeMillis, Long minAgeMillis) {
this.maxAgeMillis = maxAgeMillis;
this.minAgeMillis = minAgeMillis;
}
@Override
public String toString() {
return reflectionToString(this, SHORT_PREFIX_STYLE);
}
}

@Override
public String toString() {
return reflectionToString(this, SHORT_PREFIX_STYLE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

import javax.inject.Inject;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.joda.time.DateTime;
import org.junit.Test;
import org.springframework.dao.EmptyResultDataAccessException;

import io.nflow.engine.model.ModelObject;
import io.nflow.engine.workflow.instance.WorkflowInstance;
import io.nflow.engine.workflow.instance.WorkflowInstanceAction;

Expand Down Expand Up @@ -319,7 +319,7 @@ private void assertEqualsInAnyOrder(List<Integer> expected, List<Integer> actual
assertEquals(expectedCopy, actualCopy);
}

private static class StateKey {
private static class StateKey extends ModelObject {
public final int workflowId;
public final int actionId;
public final String stateKey;
Expand All @@ -329,10 +329,5 @@ public StateKey(int workflowId, int actionId, String stateKey) {
this.actionId = actionId;
this.stateKey = stateKey;
}

@Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
}
}
}
Loading

0 comments on commit 785fece

Please sign in to comment.