Searching for Business Objects

The Infinity Process Platform QueryService provides a business object search method to get specific Business Objects.

BusinessObjects getAllBusinessObjects(BusinessObjectQuery query);

The business objects can be created via the BusinessObjectQuery class.

Retrieving Business Objects for a specific Business Object Query

The following Infinity Process Platform QueryService method returns a list of business objects for a specific business object query:

BusinessObjects getAllBusinessObjects(BusinessObjectQuery query);

Example Implementation

    /**
     * Returns the business objects satisfying the query.
     *
     * @param query the business objects query.
     *
     * @return a list of business objects, possibly empty.
     *
     * @throws org.eclipse.stardust.common.error.WorkflowException as a wrapper for
     *         org.eclipse.stardust.common.error.PublicExceptions and org.eclipse.stardust.common.error.ResourceExceptions
     *
     * @see org.eclipse.stardust.engine.api.runtime.QueryService#getAllBusinessObjects(
     *     org.eclipse.stardust.engine.api.query.BusinessObjectQuery query)
     */
    public org.eclipse.stardust.engine.api.query.BusinessObjects
         getAllBusinessObjects(
         org.eclipse.stardust.engine.api.query.BusinessObjectQuery query)
         throws org.eclipse.stardust.common.error.WorkflowException
    {
      try
      {
         return ((org.eclipse.stardust.engine.api.runtime.QueryService)
            service).getAllBusinessObjects(query);
      }
      catch(org.eclipse.stardust.common.error.PublicException e)
      {
         throw new org.eclipse.stardust.common.error.WorkflowException(e);
      }
      catch(org.eclipse.stardust.common.error.ResourceException e)
      {
         throw new org.eclipse.stardust.common.error.WorkflowException(e);
      }
    }

Creating Query Object for Searching Business Objects

The BusinessObjectQuery class provides the following options to create specific Query objects for a business object search:

Finding all Business Objects

To create a query for finding all business objects, use findAll():

   public static BusinessObjectQuery findAll()
   {
      return new BusinessObjectQuery();
   }

The method returns the configured BusinessObjectQuery.

Finding all Business Objects in a Model

To create a query to find all business objects in a model with a specified model Id, use the following method:

   public static BusinessObjectQuery findInModel(String modelId)
   {
      BusinessObjectQuery query = findAll();
      query.where(MODEL_ID.isEqual(modelId));
      return query;
   }

Finding Business Objects with a specific qualified Id

To create a query to find business objects with a specific qualified business object Id, use the following method:

   public static BusinessObjectQuery findForBusinessObject(String qualifiedBusinessObjectId)
   {
      QName qname = QName.valueOf(qualifiedBusinessObjectId);
      BusinessObjectQuery query = BusinessObjectQuery.findInModel(qname.getNamespaceURI());
      query.where(BUSINESS_OBJECT_ID.isEqual(qname.getLocalPart()));
      return query;
   }

Finding Business Objects with a specific qualified Id and Primary Key

To create a query to find business objects with a specific qualified business object Id and primary key, use the following method:

   public static BusinessObjectQuery findWithPrimaryKey(String qualifiedBusinessObjectId, Object pk)
   {
      BusinessObjectQuery query = BusinessObjectQuery.findForBusinessObject(qualifiedBusinessObjectId);
      query.where(pk instanceof Number
            ? PRIMARY_KEY.isEqual(((Number) pk).longValue())
            : PRIMARY_KEY.isEqual(pk.toString()));
      return query;
   }

Finding all Business Objects in a Model with a specific OID

To create a query to find all business objects in a model with a specified model OID, use the following method:

   public static BusinessObjectQuery findInModel(long modelOid)
   {
      BusinessObjectQuery query = findAll();
      query.where(MODEL_OID.isEqual(modelOid));
      return query;
   }

Finding Business Objects with a specific Id in a Model

To create a query to find business objects with a specific business object Id in a model with a specified model OID, use the following method:

   public static BusinessObjectQuery findForBusinessObject(long modelOid, String businessObjectId)
   {
      QName qname = QName.valueOf(businessObjectId);
      BusinessObjectQuery query = BusinessObjectQuery.findInModel(modelOid);
      if (!StringUtils.isEmpty(qname.getNamespaceURI()))
      {
         query.where(MODEL_ID.isEqual(qname.getNamespaceURI()));
      }
      query.where(BUSINESS_OBJECT_ID.isEqual(qname.getLocalPart()));
      return query;
   }

Finding Business Objects with a specific Id and Primary Key in a specific Model

To create a query to find business objects with a specific business object Id and a specific primary key, use the following method:

   public static BusinessObjectQuery findWithPrimaryKey(long modelOid, String businessObjectId, Object pk)
   {
      BusinessObjectQuery query = BusinessObjectQuery.findForBusinessObject(modelOid, businessObjectId);
      query.where(pk instanceof Number
            ? PRIMARY_KEY.isEqual(((Number) pk).longValue())
            : PRIMARY_KEY.isEqual(pk.toString()));
      return query;
   }

Filtering for Business Objects

Filtering for business object attributes is possible through several filterable attributes in the QueryService.

Filtering for Business Object ID

To define a filter on the Business Object ID (ID) use:

private static final FilterableAttribute BUSINESS_OBJECT_ID = new FilterableAttributeImpl(
         BusinessObjectQuery.class, ID_ATTRIBUTE);

Filtering on Business Object Primary Key

To define a filter on the Business Object Primary Key use:

private static final FilterableAttribute PRIMARY_KEY = new FilterableAttributeImpl(
         BusinessObjectQuery.class, PK_ATTRIBUTE);

Filtering for a specific Model ID

To define a filter for a specific model use:

private static final FilterableAttribute MODEL_ID = new FilterableAttributeImpl(
         BusinessObjectQuery.class, MODEL_ID_ATTRIBUTE);

Note that currently only one single Operator.isEqual(modelId) term is supported to filter for exactly one modelId.

Filtering for a specific Model OID

To define a filter for a specific model use:

private static final FilterableAttribute MODEL_OID = new FilterableAttributeImpl(
         BusinessObjectQuery.class, ModelAwareQueryPredicate.INTERNAL_MODEL_OID_ATTRIBUTE);

Note that currently only one single Operator.isEqual(modelOid) term is supported to filter for exactly one modelOid.