@Override
  public void activateKaleoDefinition(
      long kaleoDefinitionId, long startKaleoNodeId, ServiceContext serviceContext)
      throws PortalException {

    KaleoDefinition kaleoDefinition =
        kaleoDefinitionPersistence.findByPrimaryKey(kaleoDefinitionId);

    try {
      KaleoDefinition previousKaleoDefinition =
          getLatestKaleoDefinition(kaleoDefinition.getName(), serviceContext);

      previousKaleoDefinition.setModifiedDate(new Date());
      previousKaleoDefinition.setActive(false);

      kaleoDefinitionPersistence.update(previousKaleoDefinition);
    } catch (NoSuchDefinitionException nsde) {
    }

    kaleoDefinition.setStartKaleoNodeId(startKaleoNodeId);
    kaleoDefinition.setModifiedDate(new Date());
    kaleoDefinition.setActive(true);

    kaleoDefinitionPersistence.update(kaleoDefinition);
  }
  @Override
  public KaleoDefinition addKaleoDefinition(
      String name,
      String title,
      String description,
      String content,
      int version,
      ServiceContext serviceContext)
      throws PortalException {

    User user = userPersistence.findByPrimaryKey(serviceContext.getGuestOrUserId());
    Date now = new Date();

    long kaleoDefinitionId = counterLocalService.increment();

    KaleoDefinition kaleoDefinition = kaleoDefinitionPersistence.create(kaleoDefinitionId);

    kaleoDefinition.setCompanyId(user.getCompanyId());
    kaleoDefinition.setUserId(user.getUserId());
    kaleoDefinition.setUserName(user.getFullName());
    kaleoDefinition.setCreateDate(now);
    kaleoDefinition.setModifiedDate(now);
    kaleoDefinition.setName(name);
    kaleoDefinition.setTitle(title);
    kaleoDefinition.setDescription(description);
    kaleoDefinition.setContent(content);
    kaleoDefinition.setVersion(version);
    kaleoDefinition.setActive(false);

    kaleoDefinitionPersistence.update(kaleoDefinition);

    return kaleoDefinition;
  }
  @Override
  public void activateKaleoDefinition(String name, int version, ServiceContext serviceContext)
      throws PortalException {

    KaleoDefinition kaleoDefinition =
        kaleoDefinitionPersistence.findByC_N_V(serviceContext.getCompanyId(), name, version);

    kaleoDefinition.setModifiedDate(new Date());
    kaleoDefinition.setActive(true);

    kaleoDefinitionPersistence.update(kaleoDefinition);
  }
  @Override
  public void activateKaleoDefinition(long kaleoDefinitionId, ServiceContext serviceContext)
      throws PortalException {

    KaleoDefinition kaleoDefinition =
        kaleoDefinitionPersistence.findByPrimaryKey(kaleoDefinitionId);

    kaleoDefinition.setModifiedDate(new Date());
    kaleoDefinition.setActive(true);

    kaleoDefinitionPersistence.update(kaleoDefinition);
  }
  /**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static KaleoDefinition toModel(KaleoDefinitionSoap soapModel) {
    if (soapModel == null) {
      return null;
    }

    KaleoDefinition model = new KaleoDefinitionImpl();

    model.setKaleoDefinitionId(soapModel.getKaleoDefinitionId());
    model.setGroupId(soapModel.getGroupId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setUserId(soapModel.getUserId());
    model.setUserName(soapModel.getUserName());
    model.setCreateDate(soapModel.getCreateDate());
    model.setModifiedDate(soapModel.getModifiedDate());
    model.setName(soapModel.getName());
    model.setTitle(soapModel.getTitle());
    model.setDescription(soapModel.getDescription());
    model.setContent(soapModel.getContent());
    model.setVersion(soapModel.getVersion());
    model.setActive(soapModel.getActive());
    model.setStartKaleoNodeId(soapModel.getStartKaleoNodeId());

    return model;
  }