@SuppressWarnings("unchecked") public File getWorkingFileById(String identifier) throws DotDataException { HibernateUtil hu = new HibernateUtil(File.class); hu.setSQLQuery( "select {file_asset.*} from file_asset, inode file_asset_1_, fileasset_version_info vi " + " where file_asset.identifier = ? and vi.identifier=file_asset.identifier and vi.working_inode=file_asset.inode " + "and file_asset_1_.inode = file_asset.inode"); hu.setParam(identifier); List<File> files = hu.list(); if (files.size() == 0) return null; return files.get(0); }
/** * Return all the CalendarReminders of the system * * @return * @throws DotDataException */ public List<CalendarReminder> getAll() { List<CalendarReminder> returnValue = new ArrayList<CalendarReminder>(); try { String query = "from calendar_reminder in class com.dotmarketing.portlets.calendar.model.CalendarReminder"; HibernateUtil dh = new HibernateUtil(CalendarReminder.class); dh.setQuery(query); returnValue = (List<CalendarReminder>) dh.list(); } catch (Exception ex) { Logger.warn(CalendarReminderFactoryImpl.class, "getAll failed:" + ex.getMessage(), ex); } return returnValue; }
/** * Return all the CalendarReminders of the system * * @return * @throws DotDataException */ public List<CalendarReminder> getAll() { List<CalendarReminder> returnValue = new ArrayList<CalendarReminder>(); try { String query = "from calendar_reminder in class com.dotmarketing.portlets.calendar.model.CalendarReminder"; HibernateUtil dh = new HibernateUtil(CalendarReminder.class); dh.setQuery(query); returnValue = (List<CalendarReminder>) dh.list(); } catch (Exception ex) { } finally { return returnValue; } }
@SuppressWarnings("unchecked") public static java.util.List<ClickstreamRequest> getClickstreamRequestsByClickStream( Clickstream cs) { HibernateUtil dh = new HibernateUtil(ClickstreamRequest.class); try { dh.setSQLQuery( "SELECT {clickstream_request.*} FROM clickstream_request WHERE clickstream_id = ? ORDER BY timestampper"); dh.setParam(cs.getClickstreamId()); return (List<ClickstreamRequest>) dh.list(); } catch (DotHibernateException e) { Logger.error( ClickstreamRequestFactory.class, "getClickstreamRequestsByClickStream: failed", e); throw new DotRuntimeException(e.getMessage(), e); } }
/** * Retrieve all the CalendarReminders before the specified date * * @param sendDate The Date used to retrieve the CalendarReminders * @return */ public List<CalendarReminder> getCalendarReminderBefore(Date sendDate) { List<CalendarReminder> returnValue = new ArrayList<CalendarReminder>(); try { String query = "from calendar_reminder in class com.dotmarketing.portlets.calendar.model.CalendarReminder where send_date <= ?"; HibernateUtil dh = new HibernateUtil(CalendarReminder.class); dh.setQuery(query); dh.setParam(sendDate); returnValue = (List<CalendarReminder>) dh.list(); } catch (Exception ex) { Logger.warn( CalendarReminderFactoryImpl.class, "getCalendareReminder failed:" + ex.getMessage(), ex); } finally { return returnValue; } }
@SuppressWarnings("unchecked") public List<File> getAllHostFiles(Host host, boolean live) throws DotDataException { HibernateUtil hu = new HibernateUtil(File.class); StringBuilder queryBuilder = new StringBuilder( "select {file_asset.*} from file_asset, inode file_asset_1_,identifier ident, fileasset_version_info vi " + "where file_asset.inode = file_asset_1_.inode and " + "file_asset.identifier = ident.id and asset_type='file_asset' and ident.id=vi.identifier " + " and ident.host_inode = ? "); if (live) queryBuilder.append(" and vi.live_inode=file_asset.inode "); else queryBuilder.append(" and vi.working_inode=file_asset.inode "); hu.setSQLQuery(queryBuilder.toString()); hu.setParam(host.getIdentifier()); return hu.list(); }
public List<File> findFiles( User user, boolean includeArchived, Map<String, Object> params, String hostId, String inode, String identifier, String parent, int offset, int limit, String orderBy) throws DotSecurityException, DotDataException { PaginatedArrayList<File> assets = new PaginatedArrayList<File>(); List<Permissionable> toReturn = new ArrayList<Permissionable>(); int internalLimit = 500; int internalOffset = 0; boolean done = false; StringBuilder conditionBuffer = new StringBuilder().append(" asset.inode=versioninfo.workingInode "); String condition = !includeArchived ? " and versioninfo.deleted = " + DbConnectionFactory.getDBFalse() : " "; conditionBuffer.append(condition); List<Object> paramValues = null; if (params != null && params.size() > 0) { conditionBuffer.append(" and ("); paramValues = new ArrayList<Object>(); int counter = 0; for (Map.Entry<String, Object> entry : params.entrySet()) { if (counter == 0) { if (entry.getValue() instanceof String) { if (entry.getKey().equalsIgnoreCase("inode")) { conditionBuffer .append(" asset.") .append(entry.getKey()) .append(" = '") .append(entry.getValue()) .append("'"); } else { conditionBuffer.append(" lower(asset.").append(entry.getKey()).append(") like ? "); paramValues.add("%" + ((String) entry.getValue()).toLowerCase() + "%"); } } else { conditionBuffer .append(" asset.") .append(entry.getKey()) .append(" = ") .append(entry.getValue()); } } else { if (entry.getValue() instanceof String) { if (entry.getKey().equalsIgnoreCase("inode")) { conditionBuffer .append(" OR asset.") .append(entry.getKey()) .append(" = '") .append(entry.getValue()) .append("'"); } else { conditionBuffer.append(" OR lower(asset.").append(entry.getKey()).append(") like ? "); paramValues.add("%" + ((String) entry.getValue()).toLowerCase() + "%"); } } else { conditionBuffer .append(" OR asset.") .append(entry.getKey()) .append(" = ") .append(entry.getValue()); } } counter += 1; } conditionBuffer.append(" ) "); } StringBuilder query = new StringBuilder(); query .append("select asset from asset in class ") .append(File.class.getName()) .append(", ") .append("inode in class ") .append(Inode.class.getName()) .append(", identifier in class ") .append(Identifier.class.getName()) .append(", versioninfo in class ") .append(FileAssetVersionInfo.class.getName()); if (UtilMethods.isSet(parent)) { query .append(" ,tree in class ") .append(Tree.class.getName()) .append(" where asset.inode=inode.inode ") .append("and asset.identifier = identifier.id and tree.parent = '") .append(parent) .append("' and tree.child=asset.inode"); } else { query.append(" where asset.inode=inode.inode and asset.identifier = identifier.id"); } query.append(" and versioninfo.identifier=identifier.id "); if (UtilMethods.isSet(hostId)) { query.append(" and identifier.hostId = '").append(hostId).append("'"); } if (UtilMethods.isSet(inode)) { query.append(" and asset.inode = '").append(inode).append("'"); } if (UtilMethods.isSet(identifier)) { query.append(" and asset.identifier = '").append(identifier).append("'"); } if (!UtilMethods.isSet(orderBy)) { orderBy = "modDate desc"; } List<File> resultList = new ArrayList<File>(); HibernateUtil dh = new HibernateUtil(File.class); String type; int countLimit = 100; int size = 0; try { type = ((Inode) File.class.newInstance()).getType(); query.append(" and asset.type='").append(type).append("' "); final String conditions = conditionBuffer.toString().trim(); if (conditions.length() > 0) query.append(" and ").append(conditions); query.append(" order by asset.").append(orderBy); dh.setQuery(query.toString()); if (paramValues != null && paramValues.size() > 0) { for (Object value : paramValues) { dh.setParam((String) value); } } while (!done) { dh.setFirstResult(internalOffset); dh.setMaxResults(internalLimit); resultList = dh.list(); PermissionAPI permAPI = APILocator.getPermissionAPI(); toReturn.addAll( permAPI.filterCollection(resultList, PermissionAPI.PERMISSION_READ, false, user)); if (countLimit > 0 && toReturn.size() >= countLimit + offset) done = true; else if (resultList.size() < internalLimit) done = true; internalOffset += internalLimit; } if (offset > toReturn.size()) { size = 0; } else if (countLimit > 0) { int toIndex = offset + countLimit > toReturn.size() ? toReturn.size() : offset + countLimit; size = toReturn.subList(offset, toIndex).size(); } else if (offset > 0) { size = toReturn.subList(offset, toReturn.size()).size(); } assets.setTotalResults(size); if (limit != -1) { int from = offset < toReturn.size() ? offset : 0; int pageLimit = 0; for (int i = from; i < toReturn.size(); i++) { if (pageLimit < limit) { assets.add((File) toReturn.get(i)); pageLimit += 1; } else { break; } } } else { for (int i = 0; i < toReturn.size(); i++) { assets.add((File) toReturn.get(i)); } } } catch (Exception e) { Logger.error(FileFactoryImpl.class, "findFiles failed:" + e, e); throw new DotRuntimeException(e.toString()); } return assets; }