protected void _viewWebAssets(RenderRequest req, User user, Class className, String tableName, String countWebKey, String viewWebKey,
String queryWebKey, String showDeletedWebKey, String hostChangedWebKey, String parent) throws Exception {
com.liferay.portlet.RenderRequestImpl reqImpl = (com.liferay.portlet.RenderRequestImpl) req;
HttpServletRequest httpReq = reqImpl.getHttpServletRequest();
WebAssetFactory webAssetFactory = new WebAssetFactory();
// gets the session object for the messages
HttpSession session = httpReq.getSession();
String hostId = (String) session.getAttribute(WebKeys.SEARCH_HOST_ID);
//if (req.getParameter("host_id") != null)
// hostId = req.getParameter("host_id");
boolean hostChanged = false;
if (session.getAttribute(com.dotmarketing.util.WebKeys.CMS_SELECTED_HOST_ID) != null) {
if ((hostId != null) && !hostId.equals(session.getAttribute(com.dotmarketing.util.WebKeys.CMS_SELECTED_HOST_ID)))
hostChanged = true;
hostId = (String) session.getAttribute(com.dotmarketing.util.WebKeys.CMS_SELECTED_HOST_ID);
}
if (hostId != null){
Host host = null;
try{
host = hostAPI.find(hostId, user, false);
}
catch(Exception e){
Logger.error(this.getClass(), "Can't find host for assets. Looking for host " + hostId + ", error: " + e);
}
if(host != null){
session.setAttribute(WebKeys.SEARCH_HOST_ID, hostId);
}
else{
// this is a rig to set the host to something that will not return any pages, files, etc...
session.removeAttribute(WebKeys.SEARCH_HOST_ID);
hostId="no host";
}
}
String query = req.getParameter("query");
String resetQuery = req.getParameter("resetQuery");
PaginatedArrayList<PermissionAsset> results = new PaginatedArrayList<PermissionAsset>();
try {
// Gets roles
Role[] roles = (Role[]) com.dotmarketing.business.APILocator.getRoleAPI().loadRolesForUser(user.getUserId()).toArray(new Role[0]);
Logger.debug(this, "Inside _viewWebAssets Roles=" + roles.length);
String showDeleted = req.getParameter("showDeleted");
boolean showDel;
if ((showDeleted == null) && (resetQuery == null)) {
showDeleted = (String) session.getAttribute(showDeletedWebKey);
}
if ((showDeleted != null) && (showDeleted.equals("true"))) {
session.setAttribute(showDeletedWebKey, "true");
showDel = true;
} else {
session.setAttribute(showDeletedWebKey, "false");
showDel = false;
}
String orderBy = req.getParameter("orderby");
int pageNumber = 1;
if (!hostChanged && UtilMethods.isSet(req.getParameter("pageNumber"))) {
pageNumber = Integer.parseInt(req.getParameter("pageNumber"));
}
int limit = com.dotmarketing.util.Config.getIntProperty("PER_PAGE");
int offset = (pageNumber - 1) * limit;
String show = req.getParameter("show");
WebAssetFactory.Direction direction = null;
if ((show == null) || show.equals("next"))
direction = WebAssetFactory.Direction.NEXT;
else
direction = WebAssetFactory.Direction.PREVIOUS;
if ((query == null) && (resetQuery == null)) {
query = (String) session.getAttribute(queryWebKey);
}
if(InodeUtils.isSet(query)){
query = query.trim();
}
session.setAttribute(queryWebKey, query);
if(UtilMethods.isSet(resetQuery)){
offset = 0;
}
results = webAssetFactory.getAssetsAndPermissions(hostId, roles, showDel, limit, offset, orderBy, tableName, parent, query, user);
req.setAttribute(hostChangedWebKey, hostChanged);
req.setAttribute(countWebKey, results.getTotalResults());
req.setAttribute(viewWebKey, results);
} catch (Exception e) {