Search in sources :

Example 21 with InstanceManagementException

use of org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException in project carbon-business-process by wso2.

the class Instance method getPaginatedInstanceList.

public PaginatedInstanceList getPaginatedInstanceList(String filter, final String order, final int limit, final int page) throws InstanceManagementException {
    String tFilter = filter;
    final PaginatedInstanceList instanceList = new PaginatedInstanceList();
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    TenantProcessStoreImpl tenantProcessStore = (TenantProcessStoreImpl) bpelServer.getMultiTenantProcessStore().getTenantsProcessStore(tenantId);
    if (tenantProcessStore.getProcessConfigMap().size() <= 0) {
        instanceList.setPages(0);
        return instanceList;
    }
    if (!tFilter.contains(" pid=")) {
        tFilter = tFilter + getTenantsProcessList(tenantProcessStore.getProcessConfigMap().keySet());
    }
    if (log.isDebugEnabled()) {
        log.debug("Instance Filter:" + tFilter);
    }
    final InstanceFilter instanceFilter = new InstanceFilter(tFilter, order, limit);
    try {
        BpelDatabase bpelDb = bpelServer.getODEBPELServer().getBpelDb();
        bpelDb.exec(new BpelDatabase.Callable<Object>() {

            public Object run(BpelDAOConnection conn) throws InstanceManagementException {
                Collection<ProcessInstanceDAO> instances = conn.instanceQuery(instanceFilter);
                int pageNum = page;
                if (pageNum < 0 || pageNum == Integer.MAX_VALUE) {
                    pageNum = 0;
                }
                int startIndexOfCurrentPage = pageNum * BPELConstants.ITEMS_PER_PAGE;
                int endIndexOfCurrentPage = (pageNum + 1) * BPELConstants.ITEMS_PER_PAGE;
                int instanceListSize = instances.size();
                int pages = (int) Math.ceil((double) instanceListSize / BPELConstants.ITEMS_PER_PAGE);
                instanceList.setPages(pages);
                ProcessInstanceDAO[] instanceArray = instances.toArray(new ProcessInstanceDAO[instanceListSize]);
                for (int i = startIndexOfCurrentPage; (i < endIndexOfCurrentPage && i < instanceListSize); i++) {
                    instanceList.addInstance(createLimitedInstanceInfoObject(instanceArray[i]));
                }
                return null;
            }
        });
    } catch (Exception e) {
        String errMsg = "Error querying instances from database. Instance Filter:" + instanceFilter.toString();
        log.error(errMsg, e);
        throw new InstanceManagementException(errMsg, e);
    }
    return instanceList;
}
Also used : InstanceFilter(org.apache.ode.bpel.common.InstanceFilter) BpelDatabase(org.apache.ode.bpel.engine.BpelDatabase) BpelDAOConnection(org.apache.ode.bpel.dao.BpelDAOConnection) TenantProcessStoreImpl(org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl) InstanceManagementException(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException) PaginatedInstanceList(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.PaginatedInstanceList) InstanceManagementException(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException) ProcessInstanceDAO(org.apache.ode.bpel.dao.ProcessInstanceDAO) Collection(java.util.Collection)

Aggregations

InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)16 BpelDAOConnection (org.apache.ode.bpel.dao.BpelDAOConnection)10 BpelDatabase (org.apache.ode.bpel.engine.BpelDatabase)10 ProcessInstanceDAO (org.apache.ode.bpel.dao.ProcessInstanceDAO)9 ProcessNotFoundException (org.apache.ode.bpel.pmapi.ProcessNotFoundException)6 ProcessingException (org.apache.ode.bpel.pmapi.ProcessingException)6 TenantProcessStoreImpl (org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl)6 Collection (java.util.Collection)5 InstanceFilter (org.apache.ode.bpel.common.InstanceFilter)5 LimitedInstanceInfoType (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.LimitedInstanceInfoType)5 ArrayList (java.util.ArrayList)3 DebuggerSupport (org.apache.ode.bpel.engine.DebuggerSupport)3 PaginatedInstanceList (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.PaginatedInstanceList)3 QName (javax.xml.namespace.QName)2 ActivityRecoveryDAO (org.apache.ode.bpel.dao.ActivityRecoveryDAO)2 LinkedList (java.util.LinkedList)1 AxisFault (org.apache.axis2.AxisFault)1 BpelEngineImpl (org.apache.ode.bpel.engine.BpelEngineImpl)1 BpelProcess (org.apache.ode.bpel.engine.BpelProcess)1 ProcessConf (org.apache.ode.bpel.iapi.ProcessConf)1