org.activiti.engine.impl.variable.VariableType Java Examples

The following examples show how to use org.activiti.engine.impl.variable.VariableType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HerdProcessEngineConfigurator.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * Inserts the variableType in variableTypes at the given index. If variableType already exists, then it replaces the type at the location where it already
 * exists.
 *
 * @param variableTypes the variableTypes
 * @param variableTypeToReplace the variableType to insert
 * @param indexToInsert the index to insert variableType
 *
 * @return the index where variableType was inserted.
 */
private int replaceVariableType(VariableTypes variableTypes, VariableType variableTypeToReplace, int indexToInsert)
{
    int indexToInsertReturn = indexToInsert;

    VariableType existingVariableType = variableTypes.getVariableType(variableTypeToReplace.getTypeName());
    if (existingVariableType != null)
    {
        indexToInsertReturn = variableTypes.getTypeIndex(existingVariableType.getTypeName());

        variableTypes.removeType(existingVariableType);
    }
    variableTypes.addType(variableTypeToReplace, indexToInsertReturn);

    return indexToInsertReturn;
}
 
Example #2
Source File: HerdProcessEngineConfigurator.java    From herd with Apache License 2.0 6 votes vote down vote up
@Override
public void configure(ProcessEngineConfigurationImpl processEngineConfiguration)
{
    // There is an issue when using Activiti with Oracle. When workflow variables have a length greater then 2000 and smaller than 4001,
    // Activiti tries to store that as a String column, but the Oracle database column length (ACT_RU_VARIABLE.TEXT_, ACT_HI_VARINST.TEXT_) is 2000.
    // Since Activiti uses NVARCHAR as the column type which requires 2 bytes for every character, the maximum size Oracle allows for the column is
    // 2000 (i.e. 4000 bytes).

    // Replace the StringType and LongType to store greater than 2000 length variables as blob.
    VariableTypes variableTypes = processEngineConfiguration.getVariableTypes();

    VariableType stringType = new StringType(2000);
    int indexToInsert = replaceVariableType(variableTypes, stringType, 0);

    VariableType longStringType = new LongStringType(2001);
    replaceVariableType(variableTypes, longStringType, ++indexToInsert);
}
 
Example #3
Source File: ProcessEngineConfigurationImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void initJpa() {
  if(jpaPersistenceUnitName!=null) {
    jpaEntityManagerFactory = JpaHelper.createEntityManagerFactory(jpaPersistenceUnitName);
  }
  if(jpaEntityManagerFactory!=null) {
    sessionFactories.put(EntityManagerSession.class, new EntityManagerSessionFactory(jpaEntityManagerFactory, jpaHandleTransaction, jpaCloseEntityManager));
    VariableType jpaType = variableTypes.getVariableType(JPAEntityVariableType.TYPE_NAME);
    // Add JPA-type
    if(jpaType == null) {
      // We try adding the variable right before SerializableType, if available
      int serializableIndex = variableTypes.getTypeIndex(SerializableType.TYPE_NAME);
      if(serializableIndex > -1) {
        variableTypes.addType(new JPAEntityVariableType(), serializableIndex);
      } else {
        variableTypes.addType(new JPAEntityVariableType());
      }   
    }
      
    jpaType = variableTypes.getVariableType(JPAEntityListVariableType.TYPE_NAME);
    
    // Add JPA-list type after regular JPA type if not already present
    if(jpaType == null) {
      variableTypes.addType(new JPAEntityListVariableType(), variableTypes.getTypeIndex(JPAEntityVariableType.TYPE_NAME));
    }        
  }
}
 
Example #4
Source File: AlfrescoProcessEngineConfiguration.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void initVariableTypes()
{
    super.initVariableTypes();
    // Add custom types before SerializableType
    if (customTypes != null)
    {
        int serializableIndex = variableTypes.getTypeIndex(SerializableType.TYPE_NAME);
        for (VariableType type : customTypes) 
        {
            variableTypes.addType(type, serializableIndex);
        }
    }
    
    // WOR-171: Replace string type by custom one to handle large text-values
    int stringIndex = variableTypes.getTypeIndex("string");
    variableTypes.removeType(variableTypes.getVariableType("string"));
    variableTypes.addType(new CustomStringVariableType(), stringIndex);
}
 
Example #5
Source File: VariableScopeImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected VariableInstanceEntity createVariableInstance(String variableName, Object value, ExecutionEntity sourceActivityExecution) {
  VariableTypes variableTypes = Context.getProcessEngineConfiguration().getVariableTypes();

  VariableType type = variableTypes.findVariableType(value);

  VariableInstanceEntity variableInstance =
      Context.getCommandContext()
          .getVariableInstanceEntityManager()
          .create(variableName, type, value);
  initializeVariableInstanceBackPointer(variableInstance);
  Context.getCommandContext().getVariableInstanceEntityManager().insert(variableInstance);
  
  if (variableInstances != null) {
    variableInstances.put(variableName, variableInstance);
  }

  // Record historic variable
  Context.getCommandContext().getHistoryManager().recordVariableCreate(variableInstance);

  // Record historic detail
  Context.getCommandContext().getHistoryManager().recordHistoricDetailVariableCreate(variableInstance, sourceActivityExecution, isActivityIdUsedForDetails());

  return variableInstance;
}
 
Example #6
Source File: VariableScopeImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void updateVariableInstance(VariableInstanceEntity variableInstance, Object value, ExecutionEntity sourceActivityExecution) {

    // Always check if the type should be altered. It's possible that the
    // previous type is lower in the type
    // checking chain (e.g. serializable) and will return true on
    // isAbleToStore(), even though another type
    // higher in the chain is eligible for storage.

    VariableTypes variableTypes = Context.getProcessEngineConfiguration().getVariableTypes();

    VariableType newType = variableTypes.findVariableType(value);

    if (newType != null && !newType.equals(variableInstance.getType())) {
      variableInstance.setValue(null);
      variableInstance.setType(newType);
      variableInstance.forceUpdate();
      variableInstance.setValue(value);
    } else {
      variableInstance.setValue(value);
    }

    Context.getCommandContext().getHistoryManager().recordHistoricDetailVariableCreate(variableInstance, sourceActivityExecution, isActivityIdUsedForDetails());

    Context.getCommandContext().getHistoryManager().recordVariableUpdate(variableInstance);
  }
 
Example #7
Source File: VariableScopeImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected VariableInstanceEntity createVariableInstance(String variableName, Object value, ExecutionEntity sourceActivityExecution) {
  VariableTypes variableTypes = Context
    .getProcessEngineConfiguration()
    .getVariableTypes();
  
  VariableType type = variableTypes.findVariableType(value);
 
  VariableInstanceEntity variableInstance = VariableInstanceEntity.createAndInsert(variableName, type, value);
  initializeVariableInstanceBackPointer(variableInstance);
  
  if (variableInstances != null) {
  	variableInstances.put(variableName, variableInstance);
  }
  
  // Record historic variable
  Context.getCommandContext().getHistoryManager()
    .recordVariableCreate(variableInstance);

  // Record historic detail
  Context.getCommandContext().getHistoryManager()
    .recordHistoricDetailVariableCreate(variableInstance, sourceActivityExecution, isActivityIdUsedForDetails());

  return variableInstance;
}
 
Example #8
Source File: HerdProcessEngineConfiguratorTest.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * Activiti by default configures StringType and LongStringType VariableType in configuration.
 * This method tests the scenarios where no StringType and LongStringType is already configured in configuration.
 */
@Test
public void testNoStringAndLongStringType() throws Exception
{
    SpringProcessEngineConfiguration configuration = new SpringProcessEngineConfiguration();
    configuration.setVariableTypes(new DefaultVariableTypes());
    
    herdProcessEngineConfigurator.configure(configuration);
    VariableType type = configuration.getVariableTypes().findVariableType(StringUtils.repeat("a", 2000));
    assertEquals(StringType.class, type.getClass());
    
    type = configuration.getVariableTypes().findVariableType(StringUtils.repeat("a", 2001));
    assertEquals(LongStringType.class, type.getClass());
}
 
Example #9
Source File: DefaultVariableTypes.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public int getTypeIndex(String typeName) {
  VariableType type = typesMap.get(typeName);
  if(type != null) {
    return getTypeIndex(type);
  } else {
    return -1;
  }
}
 
Example #10
Source File: DefaultVariableTypes.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public VariableType findVariableType(Object value) {
  for (VariableType type : typesList) {
    if (type.isAbleToStore(value)) {
      return type;
    }
  }
  throw new ActivitiException("couldn't find a variable type that is able to serialize " + value);
}
 
Example #11
Source File: DefaultVariableTypes.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void setTypesList(List<VariableType> typesList) {
  this.typesList.clear();
  this.typesList.addAll(typesList);
  this.typesMap.clear();
  for (VariableType type : typesList) {
    typesMap.put(type.getTypeName(), type);
  }
}
 
Example #12
Source File: ActivitiEventBuilder.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static ActivitiVariableEvent createVariableEvent(ActivitiEventType type, String variableName, Object variableValue, VariableType variableType, String taskId, 
		String executionId, String processInstanceId, String processDefinitionId) {
	ActivitiVariableEventImpl newEvent = new ActivitiVariableEventImpl(type);
	newEvent.setVariableName(variableName);
	newEvent.setVariableValue(variableValue);
	newEvent.setVariableType(variableType);
	newEvent.setTaskId(taskId);
	newEvent.setExecutionId(executionId);
	newEvent.setProcessDefinitionId(processDefinitionId);
	newEvent.setProcessInstanceId(processInstanceId);
	return newEvent;
}
 
Example #13
Source File: VariableScopeImpl.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void updateVariableInstance(VariableInstanceEntity variableInstance, Object value, ExecutionEntity sourceActivityExecution) {

   // Always check if the type should be altered. It's possible that the previous type is lower in the type
   // checking chain (e.g. serializable) and will return true on isAbleToStore(), even though another type
   // higher in the chain is eligible for storage.
   
   VariableTypes variableTypes = Context
       .getProcessEngineConfiguration()
       .getVariableTypes();
   
   VariableType newType = variableTypes.findVariableType(value);
   
   if (newType != null && !newType.equals(variableInstance.getType())) {
     variableInstance.setValue(null);
     variableInstance.setType(newType);
     variableInstance.forceUpdate();
     variableInstance.setValue(value);
   } else {
     variableInstance.setValue(value);
   }

   Context.getCommandContext().getHistoryManager()
     .recordHistoricDetailVariableCreate(variableInstance, sourceActivityExecution, isActivityIdUsedForDetails());
   
   Context.getCommandContext().getHistoryManager()
     .recordVariableUpdate(variableInstance);
 }
 
Example #14
Source File: VariableInstanceEntity.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static VariableInstanceEntity createAndInsert(String name, VariableType type, Object value) {
  VariableInstanceEntity variableInstance = create(name, type, value);
  variableInstance.setRevision(0);

  Context.getCommandContext()
    .getDbSqlSession()
    .insert(variableInstance);

  return variableInstance;
}
 
Example #15
Source File: VariableInstanceEntity.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static VariableInstanceEntity create(String name, VariableType type, Object value) {
  VariableInstanceEntity variableInstance = new VariableInstanceEntity();
  variableInstance.name = name;
  variableInstance.type = type;
  variableInstance.typeName = type.getTypeName();
  variableInstance.setValue(value);
  return variableInstance;
}
 
Example #16
Source File: IbatisVariableTypeHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public VariableType getResult(ResultSet rs, String columnName) throws SQLException {
  String typeName = rs.getString(columnName);
  VariableType type = getVariableTypes().getVariableType(typeName);
  if (type == null && typeName != null) {
    throw new ActivitiException("unknown variable type name " + typeName);
  }
  return type;
}
 
Example #17
Source File: IbatisVariableTypeHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public VariableType getResult(CallableStatement cs, int columnIndex) throws SQLException {
  String typeName = cs.getString(columnIndex);
  VariableType type = getVariableTypes().getVariableType(typeName);
  if (type == null) {
    throw new ActivitiException("unknown variable type name " + typeName);
  }
  return type;
}
 
Example #18
Source File: IbatisVariableTypeHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public VariableType getResult(ResultSet resultSet, int columnIndex) throws SQLException {
  String typeName = resultSet.getString(columnIndex);
  VariableType type = getVariableTypes().getVariableType(typeName);
  if (type == null) {
    throw new ActivitiException("unknown variable type name " + typeName);
  }
  return type;
}
 
Example #19
Source File: ActivitiEventBuilder.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static ActivitiVariableEvent createVariableEvent(ActivitiEventType type, String variableName, Object variableValue, VariableType variableType, String taskId, String executionId,
    String processInstanceId, String processDefinitionId) {
  ActivitiVariableEventImpl newEvent = new ActivitiVariableEventImpl(type);
  newEvent.setVariableName(variableName);
  newEvent.setVariableValue(variableValue);
  newEvent.setVariableType(variableType);
  newEvent.setTaskId(taskId);
  newEvent.setExecutionId(executionId);
  newEvent.setProcessDefinitionId(processDefinitionId);
  newEvent.setProcessInstanceId(processInstanceId);
  return newEvent;
}
 
Example #20
Source File: VariableInstanceEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public VariableInstanceEntity create(String name, VariableType type, Object value) {
  VariableInstanceEntity variableInstance = create();
  variableInstance.setName(name);
  variableInstance.setType(type);
  variableInstance.setTypeName(type.getTypeName());
  variableInstance.setValue(value);
  return variableInstance;
}
 
Example #21
Source File: IbatisVariableTypeHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public VariableType getResult(ResultSet rs, String columnName) throws SQLException {
  String typeName = rs.getString(columnName);
  VariableType type = getVariableTypes().getVariableType(typeName);
  if (type == null && typeName != null) {
    throw new ActivitiException("unknown variable type name " + typeName);
  }
  return type;
}
 
Example #22
Source File: IbatisVariableTypeHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public VariableType getResult(CallableStatement cs, int columnIndex) throws SQLException {
  String typeName = cs.getString(columnIndex);
  VariableType type = getVariableTypes().getVariableType(typeName);
  if (type == null) {
    throw new ActivitiException("unknown variable type name " + typeName);
  }
  return type;
}
 
Example #23
Source File: IbatisVariableTypeHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public VariableType getResult(ResultSet resultSet, int columnIndex) throws SQLException {
  String typeName = resultSet.getString(columnIndex);
  VariableType type = getVariableTypes().getVariableType(typeName);
  if (type == null) {
    throw new ActivitiException("unknown variable type name " + typeName);
  }
  return type;
}
 
Example #24
Source File: QueryVariableValue.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void initialize(VariableTypes types) {
  if (variableInstanceEntity == null) {
    VariableType type = types.findVariableType(value);
    if (type instanceof ByteArrayType) {
      throw new ActivitiIllegalArgumentException("Variables of type ByteArray cannot be used to query");
    } else if (type instanceof JPAEntityVariableType && operator != QueryOperator.EQUALS) {
      throw new ActivitiIllegalArgumentException("JPA entity variables can only be used in 'variableValueEquals'");
    } else if (type instanceof JPAEntityListVariableType) {
      throw new ActivitiIllegalArgumentException("Variables containing a list of JPA entities cannot be used to query");
    } else {
      // Type implementation determines which fields are set on the entity
      variableInstanceEntity = Context.getCommandContext().getVariableInstanceEntityManager().create(name, type, value);
    }
  }
}
 
Example #25
Source File: QueryVariableValue.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void initialize(VariableTypes types) {
  if(variableInstanceEntity == null) {
    VariableType type = types.findVariableType(value);
    if(type instanceof ByteArrayType) {
      throw new ActivitiIllegalArgumentException("Variables of type ByteArray cannot be used to query");
    } else if(type instanceof JPAEntityVariableType && operator != QueryOperator.EQUALS) {
      throw new ActivitiIllegalArgumentException("JPA entity variables can only be used in 'variableValueEquals'");
    } else if(type instanceof JPAEntityListVariableType) {
      throw new ActivitiIllegalArgumentException("Variables containing a list of JPA entities cannot be used to query");
    } else {
      // Type implementation determines which fields are set on the entity
      variableInstanceEntity = VariableInstanceEntity.create(name, type, value);
    }
  }
}
 
Example #26
Source File: DefaultVariableTypes.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public DefaultVariableTypes addType(VariableType type) {
  return addType(type, typesList.size());
}
 
Example #27
Source File: HistoricVariableInstanceEntityImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void setVariableType(VariableType variableType) {
  this.variableType = variableType;
}
 
Example #28
Source File: HistoricDetailVariableInstanceUpdateEntityImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void setVariableType(VariableType variableType) {
  this.variableType = variableType;
}
 
Example #29
Source File: HistoricDetailVariableInstanceUpdateEntityImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public VariableType getVariableType() {
  return variableType;
}
 
Example #30
Source File: DefaultVariableTypes.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public DefaultVariableTypes addType(VariableType type, int index) {
  typesList.add(index, type);
  typesMap.put(type.getTypeName(), type);      
  return this;
}