use of com.cloud.api.query.vo.EventJoinVO in project cosmic by MissionCriticalCloud.
the class QueryManagerImpl method searchForEventsInternal.
private Pair<List<EventJoinVO>, Integer> searchForEventsInternal(final ListEventsCmd cmd) {
final Account caller = CallContext.current().getCallingAccount();
final List<Long> permittedAccounts = new ArrayList<>();
final Long id = cmd.getId();
final String type = cmd.getType();
final String level = cmd.getLevel();
final Date startDate = cmd.getStartDate();
final Date endDate = cmd.getEndDate();
final String keyword = cmd.getKeyword();
final Integer entryTime = cmd.getEntryTime();
final Integer duration = cmd.getDuration();
final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(cmd.getDomainId(), cmd.isRecursive(), null);
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
final Long domainId = domainIdRecursiveListProject.first();
final Boolean isRecursive = domainIdRecursiveListProject.second();
final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
final Filter searchFilter = new Filter(EventJoinVO.class, "createDate", false, cmd.getStartIndex(), cmd.getPageSizeVal());
final SearchBuilder<EventJoinVO> sb = _eventJoinDao.createSearchBuilder();
_accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("levelL", sb.entity().getLevel(), SearchCriteria.Op.LIKE);
sb.and("levelEQ", sb.entity().getLevel(), SearchCriteria.Op.EQ);
sb.and("type", sb.entity().getType(), SearchCriteria.Op.EQ);
sb.and("createDateB", sb.entity().getCreateDate(), SearchCriteria.Op.BETWEEN);
sb.and("createDateG", sb.entity().getCreateDate(), SearchCriteria.Op.GTEQ);
sb.and("createDateL", sb.entity().getCreateDate(), SearchCriteria.Op.LTEQ);
sb.and("state", sb.entity().getState(), SearchCriteria.Op.NEQ);
sb.and("startId", sb.entity().getStartId(), SearchCriteria.Op.EQ);
sb.and("createDate", sb.entity().getCreateDate(), SearchCriteria.Op.BETWEEN);
sb.and("displayEvent", sb.entity().getDisplay(), SearchCriteria.Op.EQ);
sb.and("archived", sb.entity().getArchived(), SearchCriteria.Op.EQ);
final SearchCriteria<EventJoinVO> sc = sb.create();
// building ACL condition
_accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
// For end users display only enabled events
if (!_accountMgr.isRootAdmin(caller.getId())) {
sc.setParameters("displayEvent", true);
}
if (id != null) {
sc.setParameters("id", id);
}
if (keyword != null) {
final SearchCriteria<EventJoinVO> ssc = _eventJoinDao.createSearchCriteria();
ssc.addOr("type", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("level", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("level", SearchCriteria.Op.SC, ssc);
}
if (level != null) {
sc.setParameters("levelEQ", level);
}
if (type != null) {
sc.setParameters("type", type);
}
if (startDate != null && endDate != null) {
sc.setParameters("createDateB", startDate, endDate);
} else if (startDate != null) {
sc.setParameters("createDateG", startDate);
} else if (endDate != null) {
sc.setParameters("createDateL", endDate);
}
sc.setParameters("archived", false);
Pair<List<EventJoinVO>, Integer> eventPair = null;
// searchAndCount should be good enough.
if (entryTime != null && duration != null) {
// TODO: waiting for response from dev list, logic is mystery to
// me!!
/*
* if (entryTime <= duration) { throw new
* InvalidParameterValueException
* ("Entry time must be greater than duration"); } Calendar calMin =
* Calendar.getInstance(); Calendar calMax = Calendar.getInstance();
* calMin.add(Calendar.SECOND, -entryTime);
* calMax.add(Calendar.SECOND, -duration); Date minTime =
* calMin.getTime(); Date maxTime = calMax.getTime();
*
* sc.setParameters("state", com.cloud.event.Event.State.Completed);
* sc.setParameters("startId", 0); sc.setParameters("createDate",
* minTime, maxTime); List<EventJoinVO> startedEvents =
* _eventJoinDao.searchAllEvents(sc, searchFilter);
* List<EventJoinVO> pendingEvents = new ArrayList<EventJoinVO>();
* for (EventVO event : startedEvents) { EventVO completedEvent =
* _eventDao.findCompletedEvent(event.getId()); if (completedEvent
* == null) { pendingEvents.add(event); } } return pendingEvents;
*/
} else {
eventPair = _eventJoinDao.searchAndCount(sc, searchFilter);
}
return eventPair;
}
use of com.cloud.api.query.vo.EventJoinVO in project cloudstack by apache.
the class QueryManagerImpl method searchForEventsInternal.
private Pair<List<EventJoinVO>, Integer> searchForEventsInternal(ListEventsCmd cmd) {
Account caller = CallContext.current().getCallingAccount();
List<Long> permittedAccounts = new ArrayList<Long>();
Long id = cmd.getId();
String type = cmd.getType();
String level = cmd.getLevel();
Date startDate = cmd.getStartDate();
Date endDate = cmd.getEndDate();
String keyword = cmd.getKeyword();
Integer entryTime = cmd.getEntryTime();
Integer duration = cmd.getDuration();
Long startId = cmd.getStartId();
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(cmd.getDomainId(), cmd.isRecursive(), null);
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
Long domainId = domainIdRecursiveListProject.first();
Boolean isRecursive = domainIdRecursiveListProject.second();
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
Filter searchFilter = new Filter(EventJoinVO.class, "createDate", false, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchBuilder<EventJoinVO> sb = _eventJoinDao.createSearchBuilder();
_accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("levelL", sb.entity().getLevel(), SearchCriteria.Op.LIKE);
sb.and("levelEQ", sb.entity().getLevel(), SearchCriteria.Op.EQ);
sb.and("type", sb.entity().getType(), SearchCriteria.Op.EQ);
sb.and("createDateB", sb.entity().getCreateDate(), SearchCriteria.Op.BETWEEN);
sb.and("createDateG", sb.entity().getCreateDate(), SearchCriteria.Op.GTEQ);
sb.and("createDateL", sb.entity().getCreateDate(), SearchCriteria.Op.LTEQ);
sb.and("state", sb.entity().getState(), SearchCriteria.Op.NEQ);
sb.or("startId", sb.entity().getStartId(), SearchCriteria.Op.EQ);
sb.and("createDate", sb.entity().getCreateDate(), SearchCriteria.Op.BETWEEN);
sb.and("displayEvent", sb.entity().getDisplay(), SearchCriteria.Op.EQ);
sb.and("archived", sb.entity().getArchived(), SearchCriteria.Op.EQ);
SearchCriteria<EventJoinVO> sc = sb.create();
// building ACL condition
_accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
// For end users display only enabled events
if (!_accountMgr.isRootAdmin(caller.getId())) {
sc.setParameters("displayEvent", true);
}
if (id != null) {
sc.setParameters("id", id);
}
if (startId != null) {
sc.setParameters("startId", startId);
if (id == null) {
sc.setParameters("id", startId);
}
}
if (keyword != null) {
SearchCriteria<EventJoinVO> ssc = _eventJoinDao.createSearchCriteria();
ssc.addOr("type", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("level", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("level", SearchCriteria.Op.SC, ssc);
}
if (level != null) {
sc.setParameters("levelEQ", level);
}
if (type != null) {
sc.setParameters("type", type);
}
if (startDate != null && endDate != null) {
sc.setParameters("createDateB", startDate, endDate);
} else if (startDate != null) {
sc.setParameters("createDateG", startDate);
} else if (endDate != null) {
sc.setParameters("createDateL", endDate);
}
sc.setParameters("archived", false);
Pair<List<EventJoinVO>, Integer> eventPair = null;
// searchAndCount should be good enough.
if ((entryTime != null) && (duration != null)) {
// TODO: waiting for response from dev list, logic is mystery to
// me!!
/*
* if (entryTime <= duration) { throw new
* InvalidParameterValueException
* ("Entry time must be greater than duration"); } Calendar calMin =
* Calendar.getInstance(); Calendar calMax = Calendar.getInstance();
* calMin.add(Calendar.SECOND, -entryTime);
* calMax.add(Calendar.SECOND, -duration); Date minTime =
* calMin.getTime(); Date maxTime = calMax.getTime();
*
* sc.setParameters("state", com.cloud.event.Event.State.Completed);
* sc.setParameters("startId", 0); sc.setParameters("createDate",
* minTime, maxTime); List<EventJoinVO> startedEvents =
* _eventJoinDao.searchAllEvents(sc, searchFilter);
* List<EventJoinVO> pendingEvents = new ArrayList<EventJoinVO>();
* for (EventVO event : startedEvents) { EventVO completedEvent =
* _eventDao.findCompletedEvent(event.getId()); if (completedEvent
* == null) { pendingEvents.add(event); } } return pendingEvents;
*/
} else {
eventPair = _eventJoinDao.searchAndCount(sc, searchFilter);
}
return eventPair;
}
Aggregations