use of org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.PaginatedInstanceList in project carbon-business-process by wso2.
the class Instance method getInstanceInfoFromInstanceId.
@Override
public String[] getInstanceInfoFromInstanceId() {
StringBuffer buffer = new StringBuffer();
PaginatedInstanceList paginatedInstanceList;
String[] instanceInfoArray = null;
int arrayCount = 0;
try {
paginatedInstanceList = getPaginatedInstanceList(" ", "-last-active", 200, 0);
LimitedInstanceInfoType[] instanceArray = paginatedInstanceList.getInstance();
instanceInfoArray = new String[instanceArray.length];
for (LimitedInstanceInfoType instance : instanceArray) {
buffer.append("Instance id=" + instance.getIid());
buffer.append(" ");
buffer.append("Process id=" + instance.getPid());
buffer.append(" ");
buffer.append("Status =" + instance.getStatus());
buffer.append(" ");
buffer.append("Started Date=" + instance.getDateStarted().get(5));
buffer.append("-" + instance.getDateStarted().get(2));
buffer.append("-" + instance.getDateStarted().get(1));
buffer.append(" ");
buffer.append(instance.getDateStarted().get(11));
buffer.append(":" + instance.getDateStarted().get(12));
buffer.append(":" + instance.getDateStarted().get(13));
buffer.append(" ");
buffer.append("Date Last Activate=" + instance.getDateLastActive().get(5));
buffer.append("-" + instance.getDateLastActive().get(2));
buffer.append("-" + instance.getDateLastActive().get(1));
buffer.append(" ");
buffer.append(instance.getDateLastActive().get(11));
buffer.append(":" + instance.getDateLastActive().get(12));
buffer.append(":" + instance.getDateLastActive().get(13));
buffer.append(" ");
instanceInfoArray[arrayCount] = buffer.toString();
arrayCount++;
buffer.delete(0, buffer.length());
}
} catch (InstanceManagementException e) {
String errMsg = "failed to get instance information from instance id";
log.error(errMsg, e);
}
return instanceInfoArray;
}
use of org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.PaginatedInstanceList in project carbon-business-process by wso2.
the class BpelUIUtil method createLongRunningInstanceJSONString.
public static String createLongRunningInstanceJSONString(PaginatedInstanceList longRunningInstances) {
// LinkedHashMap is introduced instead of JSONObject, in-order to keep the order of the instances
LinkedHashMap<String, JSONObject> longRunning = new LinkedHashMap<String, JSONObject>();
if (longRunningInstances.isInstanceSpecified()) {
for (LimitedInstanceInfoType instance : longRunningInstances.getInstance()) {
JSONObject instanceJson = new JSONObject();
long instanceLifetimeTillLastActive = (instance.getDateLastActive().getTime().getTime() - instance.getDateStarted().getTime().getTime());
long instanceLifetimeFromLastActiveToNow = (new Date().getTime() - instance.getDateLastActive().getTime().getTime());
instanceJson.put(BPELUIConstant.INSTANCE_LIFETIME_TILL_LASTACTIVE, instanceLifetimeTillLastActive);
instanceJson.put(BPELUIConstant.INSTANCE_LIFETIME_FROM_LASTACTIVE_TO_NOW, instanceLifetimeFromLastActiveToNow);
longRunning.put(instance.getIid(), instanceJson);
}
}
return JSONObject.toJSONString(longRunning);
}
use of org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.PaginatedInstanceList in project carbon-business-process by wso2.
the class InstanceManagementServiceSkeleton method getPaginatedInstanceList.
/**
* Get paginated instance list
*
* @param filter Instance tFilter
* @param order The field on which to be ordered
* @param limit The maximum number of instances to be fetched
* @param page The page number
* @return Instances that are filtered through "tFilter", ordered by "order" that fits into
* 'page'th page
* @throws InstanceManagementException When an error occurs
*/
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;
}
use of org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.PaginatedInstanceList 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;
}
Aggregations