public PageList<Dashboard> findDashboardsByCriteria(Subject subject, DashboardCriteria criteria) { if (criteria.isInventoryManagerRequired()) { if (!authorizationManager.isInventoryManager(subject)) { throw new PermissionException( "Subject [" + subject.getName() + "] requires InventoryManager permission for requested query criteria."); } Integer ownerId = criteria.getFilterOwnerId(); if (null != ownerId && 0 == ownerId.intValue()) { criteria.addFilterOwnerId(null); } } else { criteria.addFilterOwnerId(subject.getId()); } if (null == criteria.getFilterCategory()) { criteria.addFilterCategory(DashboardCategory.INVENTORY); } CriteriaQueryGenerator generator = new CriteriaQueryGenerator(subject, criteria); CriteriaQueryRunner<Dashboard> queryRunner = new CriteriaQueryRunner<Dashboard>(criteria, generator, entityManager); return queryRunner.execute(); }
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public MeasurementBaseline calculateAutoBaselineForGroupInNewTransaction( Subject subject, int groupId, int definitionId, long startDate, long endDate, boolean save) throws BaselineCreationException, MeasurementNotFoundException { if (save && !authorizationManager.hasGroupPermission( subject, Permission.MANAGE_MEASUREMENTS, groupId)) { throw new PermissionException( "User[" + subject.getName() + "] does not have permission to calculate and set baselines for group[id=" + groupId + "]"); } MeasurementBaseline baseline; try { baseline = calculateBaselineForGroup(groupId, definitionId, true, startDate, endDate, save); if (save) { // We have changed the baseline information for the schedule, so remove the now outdated OOB // info. oobManager.removeOOBsForGroupAndDefinition(subject, groupId, definitionId); } } catch (DataNotAvailableException e) { throw new BaselineCreationException( "Error fetching data for baseline calculation for group[id=" + groupId + "], definition[id=" + definitionId + "]"); } return baseline; }
/** Throws a permission exception if the user is not allowed to access this functionality. */ private void hasPermission() { Subject subject = EnterpriseFacesContextUtility.getSubject(); if (!LookupUtil.getAuthorizationManager() .hasGlobalPermission(subject, Permission.MANAGE_INVENTORY)) { throw new PermissionException( "User [" + subject.getName() + "] does not have the proper permissions to view or manage agents"); } }
@SuppressWarnings("unchecked") public List<MeasurementBaseline> findBaselinesForResource(Subject subject, int resourceId) { if (authorizationManager.canViewResource(subject, resourceId) == false) { throw new PermissionException( "User[" + subject.getName() + " ] does not have permission to view baselines for resource[id=" + resourceId + "]"); } Query query = entityManager.createNamedQuery(MeasurementBaseline.QUERY_FIND_BY_RESOURCE); query.setParameter("resourceId", resourceId); List<MeasurementBaseline> results = query.getResultList(); return results; }