Notes
![]() ![]() Notes - notes.io |
package com.manageengine.ela.server.correlation.session.adapter;
import com.adventnet.ds.query.Column;
import com.adventnet.ds.query.Criteria;
import com.adventnet.ds.query.QueryConstants;
import com.adventnet.ds.query.Range;
import com.adventnet.ds.query.SelectQuery;
import com.adventnet.ds.query.SelectQueryImpl;
import com.adventnet.ds.query.Table;
import com.adventnet.la.TimePack;
import com.manageengine.ela.server.common.client.adapters.ClientDBArchiveAdapter;
import com.manageengine.ela.server.common.database.constants.TableNameConstants;
import com.manageengine.ela.server.common.ember.datasource.DefaultDataSource;
import com.manageengine.ela.server.correlation.session.auditdata.ActivityArchivedData;
import com.manageengine.ela.server.correlation.session.search.tablesearch.ActivityTableSearchHandler;
import com.manageengine.ela.server.correlation.session.util.ActivityUtil;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* @author afsal-5502
*/
public class ActivityArchiveAdapter implements ClientDBArchiveAdapter
{
private final TimePack timePack;
private final List<Map<String, Object>> archivedTableInfo;
private JSONObject searchData;
public ActivityArchiveAdapter(TimePack pack)
{
this.timePack = pack;
this.archivedTableInfo = ActivityArchivedData.get().getArchivedTablesInfo(pack);
}
@Override
public long getTotalCount(SelectQuery query)
{
if (archivedTableInfo != null && !archivedTableInfo.isEmpty())
{
Object ruleID = findRuleID(query.getCriteria());
return ActivityArchivedData.get().getHistoryCount(archivedTableInfo, ruleID, timePack);
}
else
{
return 0;
}
}
@Override
public LinkedList<HashMap<Column, Object>> page(SelectQuery query, int offset, int limit) throws Exception
{
if (limit == 0 || archivedTableInfo == null || archivedTableInfo.isEmpty())
{
return null;
}
if (limit > MAX_LIMIT)
{
limit = MAX_LIMIT;
}
LinkedList<HashMap<Column, Object>> outerTable = new LinkedList<>();
Column column = Column.getColumn(TableNameConstants.ACTIVITY_ARCHIVED_TABLE_INFO, "INIT_DOC_TABLE_ID"); //No I18N
Object providerID = findRuleID(query.getCriteria());
for (Map<String, Object> tableInfo : archivedTableInfo)
{
String archivedTableName = (String) tableInfo.get(TableNameConstants.ACTIVITY_HISTORY);
Long docIDArchiveTableID = ((Long) tableInfo.get("DOCID_ARCHIVED_TABLE_ID"));
long totalCount;
if (offset != 0 && (totalCount = ActivityArchivedData.get().getHistoryCount(archivedTableName, providerID, timePack)) < offset)
{
offset -= totalCount;
}
else
{
SelectQuery customQuery = new SelectQueryImpl(Table.getTable(archivedTableName));
customQuery.setRange(new Range(offset, limit));
List<Column> columns = query.getSelectColumns();
for (Column col : columns)
{
customQuery.addSelectColumn(Column.getColumn(archivedTableName, col.getColumnName(), col.getColumnAlias()));
}
Criteria timeCriteria = ActivityUtil.getTimeBasedCustomTableSuccessCriteria(archivedTableName, timePack);
Criteria combined = providerID != null ? timeCriteria.and(new Criteria(Column.getColumn(archivedTableName, "PROVIDER_ID"), providerID, QueryConstants.EQUAL)) : timeCriteria;
combined = combined.and(new Criteria(Column.getColumn(archivedTableName, "IS_PRIMARY"), true, QueryConstants.EQUAL));
if (this.searchData != null)
{
JSONObject extraInfo = searchData.getJSONObject("EXTRA_PARAMS");
boolean isFiltering = extraInfo.has("IS_FILTERING") && extraInfo.getBoolean("IS_FILTERING"); //No I18N
Criteria searchCriteria = ActivityTableSearchHandler.prepareSearchCriteria((Long) providerID, offset, limit, extraInfo.getString("UUID"), isFiltering, searchData.getJSONObject("SEARCH"), archivedTableName, timePack);
if (searchCriteria != null)
{
combined = combined.and(searchCriteria);
}
}
customQuery.setCriteria(combined);
LinkedList<HashMap<Column, Object>> archivedDataInfo = new LinkedList<>();
limit -= DefaultDataSource.loadArchiveRequestResult(TableNameConstants.ACTIVITY_HISTORY, customQuery, archivedDataInfo);
for (HashMap<Column, Object> map : archivedDataInfo)
{
map.put(column, docIDArchiveTableID);
outerTable.add(map);
}
if (limit <= 0)
{
break;
}
else
{
offset = 0;
}
}
}
return outerTable;
}
public void setSearchCriteria(JSONObject searchData)
{
this.searchData = searchData;
}
private Object findRuleID(Criteria parentCriteria)
{
if (parentCriteria == null)
{
return null;
}
if (parentCriteria.getLeftCriteria() != null && parentCriteria.getRightCriteria() != null)
{
Object ruleID = findRuleID(parentCriteria.getLeftCriteria());
if (ruleID != null)
{
return ruleID;
}
ruleID = findRuleID(parentCriteria.getRightCriteria());
if (ruleID != null)
{
return ruleID;
}
return null;
}
else
{
if (isValidCriteria(parentCriteria))
{
return parentCriteria.getValue();
}
else
{
return null;
}
}
}
private boolean isValidCriteria(Criteria result)
{
Column column = result.getColumn();
if (column != null)
{
return column.getTableAlias().equals(TableNameConstants.ACTIVITY_HISTORY) && column.getColumnName().equals("PROVIDER_ID");
}
else
{
return false;
}
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team