* @throws StoreException
*/
public WorkflowsInfo getWorkflowsInfo(final Map<String, List<String>> filter, final int start, final int len)
throws StoreException {
WorkflowsInfo workFlowsInfo = doOperation("getWorkflowsInfo", new Callable<WorkflowsInfo>() {
@SuppressWarnings("unchecked")
public WorkflowsInfo call() throws SQLException, StoreException {
List<String> orArray = new ArrayList<String>();
List<String> colArray = new ArrayList<String>();
List<String> valArray = new ArrayList<String>();
StringBuilder sb = new StringBuilder("");
boolean isStatus = false;
boolean isGroup = false;
boolean isAppName = false;
boolean isUser = false;
boolean isEnabled = false;
int index = 0;
for (Map.Entry<String, List<String>> entry : filter.entrySet()) {
String colName = null;
String colVar = null;
if (entry.getKey().equals(OozieClient.FILTER_GROUP)) {
List<String> values = filter.get(OozieClient.FILTER_GROUP);
colName = "group";
for (int i = 0; i < values.size(); i++) {
colVar = "group";
colVar = colVar + index;
if (!isEnabled && !isGroup) {
sb.append(seletStr).append(" where w.group IN (:group" + index);
isGroup = true;
isEnabled = true;
}
else {
if (isEnabled && !isGroup) {
sb.append(" and w.group IN (:group" + index);
isGroup = true;
}
else {
if (isGroup) {
sb.append(", :group" + index);
}
}
}
if (i == values.size() - 1) {
sb.append(")");
}
index++;
valArray.add(values.get(i));
orArray.add(colName);
colArray.add(colVar);
}
}
else {
if (entry.getKey().equals(OozieClient.FILTER_STATUS)) {
List<String> values = filter.get(OozieClient.FILTER_STATUS);
colName = "status";
for (int i = 0; i < values.size(); i++) {
colVar = "status";
colVar = colVar + index;
if (!isEnabled && !isStatus) {
sb.append(seletStr).append(" where w.status IN (:status" + index);
isStatus = true;
isEnabled = true;
}
else {
if (isEnabled && !isStatus) {
sb.append(" and w.status IN (:status" + index);
isStatus = true;
}
else {
if (isStatus) {
sb.append(", :status" + index);
}
}
}
if (i == values.size() - 1) {
sb.append(")");
}
index++;
valArray.add(values.get(i));
orArray.add(colName);
colArray.add(colVar);
}
}
else {
if (entry.getKey().equals(OozieClient.FILTER_NAME)) {
List<String> values = filter.get(OozieClient.FILTER_NAME);
colName = "appName";
for (int i = 0; i < values.size(); i++) {
colVar = "appName";
colVar = colVar + index;
if (!isEnabled && !isAppName) {
sb.append(seletStr).append(" where w.appName IN (:appName" + index);
isAppName = true;
isEnabled = true;
}
else {
if (isEnabled && !isAppName) {
sb.append(" and w.appName IN (:appName" + index);
isAppName = true;
}
else {
if (isAppName) {
sb.append(", :appName" + index);
}
}
}
if (i == values.size() - 1) {
sb.append(")");
}
index++;
valArray.add(values.get(i));
orArray.add(colName);
colArray.add(colVar);
}
}
else {
if (entry.getKey().equals(OozieClient.FILTER_USER)) {
List<String> values = filter.get(OozieClient.FILTER_USER);
colName = "user";
for (int i = 0; i < values.size(); i++) {
colVar = "user";
colVar = colVar + index;
if (!isEnabled && !isUser) {
sb.append(seletStr).append(" where w.user IN (:user" + index);
isUser = true;
isEnabled = true;
}
else {
if (isEnabled && !isUser) {
sb.append(" and w.user IN (:user" + index);
isUser = true;
}
else {
if (isUser) {
sb.append(", :user" + index);
}
}
}
if (i == values.size() - 1) {
sb.append(")");
}
index++;
valArray.add(values.get(i));
orArray.add(colName);
colArray.add(colVar);
}
}
}
}
}
}
int realLen = 0;
Query q = null;
Query qTotal = null;
if (orArray.size() == 0) {
q = entityManager.createNamedQuery("GET_WORKFLOWS_COLUMNS");
q.setFirstResult(start - 1);
q.setMaxResults(len);
qTotal = entityManager.createNamedQuery("GET_WORKFLOWS_COUNT");
}
else {
if (orArray.size() > 0) {
StringBuilder sbTotal = new StringBuilder(sb);
sb.append(" order by w.startTimestamp desc ");
XLog.getLog(getClass()).debug("Created String is **** " + sb.toString());
q = entityManager.createQuery(sb.toString());
q.setFirstResult(start - 1);
q.setMaxResults(len);
qTotal = entityManager.createQuery(sbTotal.toString().replace(seletStr, countStr));
for (int i = 0; i < orArray.size(); i++) {
q.setParameter(colArray.get(i), valArray.get(i));
qTotal.setParameter(colArray.get(i), valArray.get(i));
}
}
}
OpenJPAQuery kq = OpenJPAPersistence.cast(q);
JDBCFetchPlan fetch = (JDBCFetchPlan) kq.getFetchPlan();
fetch.setFetchBatchSize(20);
fetch.setResultSetType(ResultSetType.SCROLL_INSENSITIVE);
fetch.setFetchDirection(FetchDirection.FORWARD);
fetch.setLRSSizeAlgorithm(LRSSizeAlgorithm.LAST);
List<?> resultList = q.getResultList();
List<Object[]> objectArrList = (List<Object[]>) resultList;
List<WorkflowJobBean> wfBeansList = new ArrayList<WorkflowJobBean>();
for (Object[] arr : objectArrList) {
WorkflowJobBean ww = getBeanForWorkflowFromArray(arr);
wfBeansList.add(ww);
}
realLen = ((Long) qTotal.getSingleResult()).intValue();
return new WorkflowsInfo(wfBeansList, start, len, realLen);
}
});
return workFlowsInfo;
}