Search in sources :

Example 6 with BpelDatabase

use of org.apache.ode.bpel.engine.BpelDatabase 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

BpelDatabase (org.apache.ode.bpel.engine.BpelDatabase)6 BpelDAOConnection (org.apache.ode.bpel.dao.BpelDAOConnection)5 InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)5 Collection (java.util.Collection)4 InstanceFilter (org.apache.ode.bpel.common.InstanceFilter)4 ProcessInstanceDAO (org.apache.ode.bpel.dao.ProcessInstanceDAO)4 ProcessNotFoundException (org.apache.ode.bpel.pmapi.ProcessNotFoundException)4 ProcessingException (org.apache.ode.bpel.pmapi.ProcessingException)4 ArrayList (java.util.ArrayList)3 TenantProcessStoreImpl (org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl)3 PaginatedInstanceList (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.PaginatedInstanceList)2 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 AxisFault (org.apache.axis2.AxisFault)1 ActivityRecoveryDAO (org.apache.ode.bpel.dao.ActivityRecoveryDAO)1 ManagementException (org.apache.ode.bpel.pmapi.ManagementException)1 BPELServerImpl (org.wso2.carbon.bpel.core.ode.integration.BPELServerImpl)1 ActivityRecoveryInfoType (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.ActivityRecoveryInfoType)1 LimitedInstanceInfoType (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.LimitedInstanceInfoType)1