Coverage Report - org.apache.camel.bam.model.ProcessInstance
 
Classes in this File Line Coverage Branch Coverage Complexity
ProcessInstance
96% 
100% 
0
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.bam.model;
 18  
 
 19  
 import org.apache.camel.bam.rules.ActivityRules;
 20  
 import org.apache.commons.logging.Log;
 21  
 import org.apache.commons.logging.LogFactory;
 22  
 
 23  
 import javax.persistence.CascadeType;
 24  
 import javax.persistence.Entity;
 25  
 import javax.persistence.FetchType;
 26  
 import javax.persistence.GeneratedValue;
 27  
 import javax.persistence.Id;
 28  
 import javax.persistence.ManyToOne;
 29  
 import javax.persistence.OneToMany;
 30  
 import java.util.Collection;
 31  
 import java.util.Date;
 32  
 import java.util.HashSet;
 33  
 
 34  
 /**
 35  
  * Represents a single business process
 36  
  *
 37  
  * @version $Revision: $
 38  
  */
 39  
 @Entity
 40  
 public class ProcessInstance extends TemporalEntity {
 41  1
     private static final transient Log log = LogFactory.getLog(ProcessInstance.class);
 42  
     private ProcessDefinition processDefinition;
 43  4
     private Collection<ActivityState> activityStates = new HashSet<ActivityState>();
 44  
     private String correlationKey;
 45  
 
 46  4
     public ProcessInstance() {
 47  4
         setTimeStarted(new Date());
 48  4
     }
 49  
 
 50  
     public String toString() {
 51  0
         return getClass().getName() + "[id: " + getId() + ", key: " + getCorrelationKey() + "]";
 52  
     }
 53  
 
 54  
     // This crap is required to work around a bug in hibernate
 55  
     @Override
 56  
     @Id
 57  
     @GeneratedValue
 58  
     public Long getId() {
 59  6
         return super.getId();
 60  
     }
 61  
 
 62  
     @ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST})
 63  
     public ProcessDefinition getProcessDefinition() {
 64  19
         return processDefinition;
 65  
     }
 66  
 
 67  
     public void setProcessDefinition(ProcessDefinition processDefinition) {
 68  2
         this.processDefinition = processDefinition;
 69  2
     }
 70  
 
 71  
     @OneToMany(mappedBy = "processInstance", fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
 72  
     public Collection<ActivityState> getActivityStates() {
 73  25
         return activityStates;
 74  
     }
 75  
 
 76  
     public void setActivityStates(Collection<ActivityState> activityStates) {
 77  2
         this.activityStates = activityStates;
 78  2
     }
 79  
 
 80  
     public String getCorrelationKey() {
 81  17
         return correlationKey;
 82  
     }
 83  
 
 84  
     public void setCorrelationKey(String correlationKey) {
 85  3
         this.correlationKey = correlationKey;
 86  3
     }
 87  
 
 88  
     // Helper methods
 89  
     //-------------------------------------------------------------------------
 90  
 
 91  
     /**
 92  
      * Returns the activity state for the given activity
 93  
      *
 94  
      * @param activityRules the activity to find the state for
 95  
      * @return the activity state or null if no state could be found for the
 96  
      *         given activity
 97  
      */
 98  
     public ActivityState getActivityState(ActivityRules activityRules) {
 99  3
         for (ActivityState activityState : getActivityStates()) {
 100  2
             if (activityState.isActivity(activityRules)) {
 101  1
                 return activityState;
 102  
             }
 103  1
         }
 104  2
         return null;
 105  
     }
 106  
 
 107  
     public ActivityState getOrCreateActivityState(ActivityRules activityRules) {
 108  2
         ActivityState state = getActivityState(activityRules);
 109  
 
 110  2
         if (state == null) {
 111  2
             state = createActivityState();
 112  2
             state.setProcessInstance(this);
 113  2
             state.setActivityDefinition(activityRules.getActivityDefinition());
 114  
             // we don't need to do: getTemplate().persist(state);
 115  
         }
 116  
 
 117  2
         return state;
 118  
     }
 119  
 
 120  
     protected ActivityState createActivityState() {
 121  2
         return new ActivityState();
 122  
     }
 123  
 }