1 package com.dotmarketing.portlets.containers.action; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.List ; 6 7 import javax.portlet.PortletConfig; 8 import javax.portlet.RenderRequest; 9 import javax.portlet.RenderResponse; 10 import javax.portlet.WindowState; 11 import javax.servlet.http.HttpServletRequest ; 12 import javax.servlet.http.HttpSession ; 13 import javax.servlet.jsp.PageContext ; 14 15 import org.apache.struts.action.ActionForm; 16 import org.apache.struts.action.ActionForward; 17 import org.apache.struts.action.ActionMapping; 18 19 import com.dotmarketing.beans.Host; 20 import com.dotmarketing.beans.PermissionAsset; 21 import com.dotmarketing.factories.InodeFactory; 22 import com.dotmarketing.factories.RoleFactory; 23 import com.dotmarketing.factories.WebAssetFactory; 24 import com.dotmarketing.portal.struts.DotPortletAction; 25 import com.dotmarketing.portlets.containers.model.Container; 26 import com.dotmarketing.portlets.structure.model.Structure; 27 import com.dotmarketing.util.Config; 28 import com.dotmarketing.util.Logger; 29 import com.dotmarketing.util.UtilMethods; 30 import com.dotmarketing.util.WebKeys; 31 import com.liferay.portal.model.Role; 32 import com.liferay.portal.model.User; 33 import com.liferay.portal.util.Constants; 34 35 42 public class ViewContainersAction extends DotPortletAction { 43 44 49 public ActionForward render(ActionMapping mapping, ActionForm form, 50 PortletConfig config, RenderRequest req, RenderResponse res) 51 throws Exception { 52 53 Logger.debug(this, "Running ViewContainersAction!!!!"); 54 55 try { 56 User user = _getUser(req); 58 59 if (req.getWindowState().equals(WindowState.NORMAL)) { 60 return mapping.findForward("portlet.ext.containers.view"); 61 } else { 62 63 _viewContainers(req, user); 64 return mapping 65 .findForward("portlet.ext.containers.view_containers"); 66 } 67 } catch (Exception e) { 68 req.setAttribute(PageContext.EXCEPTION, e); 69 return mapping.findForward(Constants.COMMON_ERROR); 70 } 71 } 72 73 88 @SuppressWarnings ("unchecked") 89 protected void _viewContainers(RenderRequest req, User user) 90 throws Exception { 91 92 com.liferay.portlet.RenderRequestImpl reqImpl = (com.liferay.portlet.RenderRequestImpl) req; 93 HttpServletRequest httpReq = reqImpl.getHttpServletRequest(); 94 HttpSession session = httpReq.getSession(); 96 97 String hostId = (String ) session.getAttribute(WebKeys.SEARCH_HOST_ID); 98 if (req.getParameter("host_id") != null) 99 hostId = req.getParameter("host_id"); 100 if (hostId != null) 101 session.setAttribute(WebKeys.SEARCH_HOST_ID, hostId); 102 103 String structureId = (String ) session 104 .getAttribute(WebKeys.SEARCH_STRUCTURE_ID); 105 if (req.getParameter("structure_id") != null) 106 structureId = req.getParameter("structure_id"); 107 if (structureId != null) 108 session.setAttribute(WebKeys.SEARCH_STRUCTURE_ID, structureId); 109 110 String query = req.getParameter("query"); 111 String resetQuery = req.getParameter("resetQuery"); 112 113 List l = new java.util.ArrayList (); 114 115 try { 116 Role[] roles = (Role[]) RoleFactory.getAllRolesForUser( 118 user.getUserId()).toArray(new Role[0]); 119 Logger.debug(this, "Inside _viewWebAssets Roles=" + roles.length); 120 121 String condition = ""; 122 String showDeleted = req.getParameter("showDeleted"); 123 124 if ((showDeleted == null) && (resetQuery == null)) { 125 showDeleted = (String ) session 126 .getAttribute(WebKeys.CONTAINER_SHOW_DELETED); 127 } 128 if ((showDeleted != null) && (showDeleted.equals("true"))) { 129 condition = "working=" 130 + com.dotmarketing.db.DbConnectionFactory.getDBTrue(); 131 session.setAttribute(WebKeys.CONTAINER_SHOW_DELETED, "true"); 132 } else { 133 condition = "working=" 134 + com.dotmarketing.db.DbConnectionFactory.getDBTrue() 135 + " and deleted=" 136 + com.dotmarketing.db.DbConnectionFactory.getDBFalse(); 137 session.setAttribute(WebKeys.CONTAINER_SHOW_DELETED, "false"); 138 } 139 String orderby = req.getParameter("orderby"); 140 if (!UtilMethods.isSet(orderby)) { 141 orderby = "title"; 142 } 143 144 int pageNumber = 1; 145 146 if (UtilMethods.isSet(req.getParameter("pageNumber"))) { 147 pageNumber = Integer.parseInt(req.getParameter("pageNumber")); 148 } 149 150 int limit = com.dotmarketing.util.Config.getIntProperty("PER_PAGE"); 151 152 int offset = (pageNumber - 1) * limit; 153 154 if ((query == null) && (resetQuery == null)) { 155 query = (String ) session.getAttribute(WebKeys.CONTAINER_QUERY); 156 } 157 session.setAttribute(WebKeys.CONTAINER_QUERY, query); 158 159 int count = 0; 160 161 if ((query != null) && (query.length() != 0) ) { 163 condition += " and (lower(containers" 164 + "_condition.title) like '%" + query.toLowerCase() 165 + "%' or lower(containers" 166 + "_condition.friendly_name) like '%" 167 + query.toLowerCase() + "%')"; 168 Logger.debug(this, "Getting Assets based on condition=" 169 + condition); 170 limit = 0; 171 172 173 l = WebAssetFactory.getAssetsAndPermissionsPerRoleAndCondition( 174 roles, condition, limit, offset, orderby, 175 Container.class, "containers"); 176 count = WebAssetFactory 177 .getCountAssetsPerConditionWithPermission(condition, 178 Container.class, roles); 179 180 } else { 181 Logger.debug(this, "Getting all Assets=" + condition); 182 l = WebAssetFactory.getAssetsAndPermissionsPerRoleAndCondition( 183 roles, condition, limit, offset, orderby, 184 Container.class, "containers"); 185 count = WebAssetFactory 186 .getCountAssetsPerConditionWithPermission(condition, 187 Container.class, roles); 188 } 189 190 if (UtilMethods.isSet(hostId) && !hostId.equals("0")) { 192 List newList = new ArrayList (); 193 long hostIdL = Long.parseLong(hostId); 194 Iterator it = l.iterator(); 195 while (it.hasNext()) { 196 PermissionAsset permAsset = (PermissionAsset) it.next(); 197 Container container = (Container) permAsset.getAsset(); 198 Host contHost = (Host) InodeFactory 199 .getParentOfClass(container, Host.class); 200 if (contHost.getInode() == hostIdL) { 201 newList.add(permAsset); 202 } else { 203 count--; 204 } 205 } 206 l = newList; 207 } 208 209 if (UtilMethods.isSet(structureId) && !structureId.equals("0")) { 211 List newList = new ArrayList (); 212 long structureIdL = Long.parseLong(structureId); 213 Iterator it = l.iterator(); 214 while (it.hasNext()) { 215 PermissionAsset permAsset = (PermissionAsset) it.next(); 216 Container container = (Container) permAsset.getAsset(); 217 Structure contStructure = (Structure) InodeFactory 218 .getParentOfClass(container, Structure.class); 219 if (contStructure.getInode() == structureIdL) { 220 newList.add(permAsset); 221 } else { 222 count--; 223 } 224 } 225 l = newList; 226 } 227 228 req.setAttribute(WebKeys.CONTAINERS_VIEW_COUNT, new Integer (count)); 229 req.setAttribute(WebKeys.CONTAINERS_VIEW, l); 230 } catch (Exception e) { 231 req.setAttribute(WebKeys.CONTAINERS_VIEW, l); 232 Logger.error(this, "Exception e =" + e.getMessage(), e); 233 throw new Exception (e.getMessage()); 234 } 235 236 } 237 238 } | Popular Tags |