1 package org.ofbiz.content; 2 3 import java.sql.Timestamp ; 4 import java.util.HashMap ; 5 import java.util.Iterator ; 6 import java.util.List ; 7 import java.util.Map ; 8 import java.util.Set ; 9 import javax.servlet.ServletContext ; 10 import javax.servlet.http.HttpServletRequest ; 11 import javax.servlet.http.HttpServletResponse ; 12 import javax.servlet.http.HttpSession ; 13 14 import org.ofbiz.base.util.Debug; 15 import org.ofbiz.base.util.GeneralException; 16 import org.ofbiz.base.util.StringUtil; 17 import org.ofbiz.base.util.UtilDateTime; 18 import org.ofbiz.base.util.UtilHttp; 19 import org.ofbiz.base.util.UtilMisc; 20 import org.ofbiz.base.util.UtilValidate; 21 import org.ofbiz.entity.GenericDelegator; 22 import org.ofbiz.entity.GenericEntityException; 23 import org.ofbiz.entity.GenericValue; 24 import org.ofbiz.security.Security; 25 import org.ofbiz.service.GenericServiceException; 26 import org.ofbiz.service.LocalDispatcher; 27 import org.ofbiz.service.ModelService; 28 29 30 31 40 public class ContentManagementEvents { 41 42 public static final String module = ContentManagementEvents.class.getName(); 43 44 public static String updateStaticValues(HttpServletRequest request, HttpServletResponse response) { 45 46 HttpSession session = request.getSession(); 47 Security security = (Security)request.getAttribute("security"); 48 GenericValue userLogin = (GenericValue)session.getAttribute("userLogin"); 49 ServletContext servletContext = session.getServletContext(); 50 String webSiteId = (String ) servletContext.getAttribute("webSiteId"); 51 GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator"); 52 LocalDispatcher dispatcher = (LocalDispatcher)request.getAttribute("dispatcher"); 53 Map paramMap = UtilHttp.getParameterMap(request); 54 String parentPlaceholderId = (String )paramMap.get("ph"); 56 if ( UtilValidate.isEmpty(parentPlaceholderId)) { 57 request.setAttribute("_ERROR_MESSAGE_", "ParentPlaceholder is empty."); 58 return "error"; 59 } 60 List allPublishPointList = null; 61 List permittedPublishPointList = null; 62 List valueList = null; 63 try { 64 allPublishPointList = ContentManagementWorker.getAllPublishPoints(delegator, webSiteId); 65 permittedPublishPointList = ContentManagementWorker.getPermittedPublishPoints(delegator, allPublishPointList, userLogin, security, "_ADMIN", null, null); 66 valueList = ContentManagementWorker.getStaticValues(delegator, parentPlaceholderId, permittedPublishPointList); 67 } catch(GeneralException e) { 68 Debug.logError(e.getMessage(), module); 69 request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); 70 return "error"; 71 } 72 87 88 Iterator it = valueList.iterator(); 89 int counter = 0; 90 while (it.hasNext()) { 91 Map map = (Map )it.next(); 92 String contentId = (String )map.get("contentId"); 93 Iterator itPubPt = permittedPublishPointList.iterator(); 96 while (itPubPt.hasNext()) { 97 String [] pubArr = (String [])itPubPt.next(); 98 String pubContentId = (String )pubArr[0]; 99 String pubValue = (String )map.get(pubContentId); 100 String paramName = Integer.toString(counter) + "_" + pubContentId; 101 String paramValue = (String )paramMap.get(paramName); 102 Map serviceIn = new HashMap (); 104 serviceIn.put("userLogin", userLogin); 105 serviceIn.put("contentIdTo", contentId); 106 serviceIn.put("contentId", pubContentId); 107 serviceIn.put("contentAssocTypeId", "SUBSITE"); 108 try { 109 if (UtilValidate.isNotEmpty(paramValue)) { 110 if (!paramValue.equals(pubValue)) { 111 if (paramValue.equalsIgnoreCase("Y")) { 112 serviceIn.put("fromDate", UtilDateTime.nowTimestamp()); 113 Map results = dispatcher.runSync("createContentAssoc", serviceIn); 114 } else if (paramValue.equalsIgnoreCase("N") && pubValue.equalsIgnoreCase("Y")) { 115 serviceIn.put("thruDate", UtilDateTime.nowTimestamp()); 116 Timestamp fromDate = (Timestamp )map.get(pubContentId + "FromDate"); 117 serviceIn.put("fromDate", fromDate); 118 Map results = dispatcher.runSync("updateContentAssoc", serviceIn); 119 } 120 } 121 } else if ( UtilValidate.isNotEmpty(pubValue)) { 122 if (pubValue.equalsIgnoreCase("Y")) { 123 serviceIn.put("thruDate", UtilDateTime.nowTimestamp()); 124 Timestamp fromDate = (Timestamp )map.get(pubContentId + "FromDate"); 125 serviceIn.put("fromDate", fromDate); 126 Map results = dispatcher.runSync("updateContentAssoc", serviceIn); 127 } 128 } 129 } catch(GenericServiceException e) { 130 Debug.logError(e.getMessage(), module); 131 request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); 132 return "error"; 133 } 134 } 135 counter++; 136 } 137 return "success"; 138 } 139 140 public static String createStaticValue(HttpServletRequest request, HttpServletResponse response) { 141 String retValue = "success"; 142 return retValue; 143 } 144 145 public static String updatePublishLinks(HttpServletRequest request, HttpServletResponse response) { 146 147 HttpSession session = request.getSession(); 148 Security security = (Security)request.getAttribute("security"); 149 GenericValue userLogin = (GenericValue)session.getAttribute("userLogin"); 150 ServletContext servletContext = session.getServletContext(); 151 String webSiteId = (String ) servletContext.getAttribute("webSiteId"); 152 GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator"); 153 LocalDispatcher dispatcher = (LocalDispatcher)request.getAttribute("dispatcher"); 154 Map paramMap = UtilHttp.getParameterMap(request); 155 String targContentId = (String )paramMap.get("contentId"); String roles = null; 158 String authorId = null; 159 GenericValue authorContent = ContentManagementWorker.getAuthorContent(delegator, targContentId); 160 if (authorContent != null) { 161 authorId = authorContent.getString("contentId"); 162 } else { 163 request.setAttribute("_ERROR_MESSAGE_", "authorContent is empty."); 164 return "error"; 165 } 166 167 String userLoginId = userLogin.getString("userLoginId"); 169 List roleTypeList = null; 171 if (authorId != null && userLoginId != null && authorId.equals(userLoginId)) { 172 roles = "OWNER"; 173 roleTypeList = StringUtil.split(roles, "|"); 174 } 175 List targetOperationList = UtilMisc.toList("CONTENT_PUBLISH"); 176 List contentPurposeList = null; String permittedAction = (String )paramMap.get("permittedAction"); String permittedOperations = (String )paramMap.get("permittedOperations"); if ( UtilValidate.isEmpty(targContentId)) { 181 request.setAttribute("_ERROR_MESSAGE_", "targContentId is empty."); 182 return "error"; 183 } 184 185 List origPublishedLinkList = null; 187 try { 188 GenericValue authorUserLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", authorId)); 190 origPublishedLinkList = ContentManagementWorker.getPublishedLinks(delegator, targContentId, webSiteId, userLogin, security, permittedAction, permittedOperations, roles ); 191 } catch(GenericEntityException e) { 192 request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); 193 return "error"; 194 } catch(GeneralException e2) { 195 request.setAttribute("_ERROR_MESSAGE_", e2.getMessage()); 196 return "error"; 197 } 198 200 Set keySet = paramMap.keySet(); 203 Iterator itKeySet = keySet.iterator(); 204 Map siteIdLookup = new HashMap (); 205 while (itKeySet.hasNext()) { 206 String param = (String )itKeySet.next(); 207 int pos = param.indexOf("select_"); 208 if (pos >= 0) { 210 String siteId = param.substring(7); 211 String subSiteVal = (String )paramMap.get(param); 212 siteIdLookup.put(siteId, subSiteVal); 213 } 214 } 215 216 218 Iterator it = origPublishedLinkList.iterator(); 220 Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); 221 int counter = 0; 222 String responseMessage = null; 223 String errorMessage = null; 224 String permissionMessage = null; 225 boolean statusIdUpdated = false; 226 Map results = null; 227 while (it.hasNext()) { 228 Object [] arr = (Object [])it.next(); 229 String contentId = (String )arr[0]; String origSubContentId = null; 232 List origSubList = (List )arr[1]; 233 Timestamp topFromDate = (Timestamp )arr[3]; 234 Timestamp origFromDate = null; 235 Iterator itOrigSubPt = origSubList.iterator(); 236 while (itOrigSubPt.hasNext()) { 238 Object [] pubArr = (Object [])itOrigSubPt.next(); 239 Timestamp fromDate = (Timestamp )pubArr[2]; 241 origSubContentId = null; 242 if (fromDate != null) { 243 origSubContentId = (String )pubArr[0]; 244 origFromDate = fromDate; 245 break; 246 } 247 } 248 249 String currentSubContentId = (String )siteIdLookup.get(contentId); 250 try { 253 if (UtilValidate.isNotEmpty(currentSubContentId)) { 254 if (!currentSubContentId.equals(origSubContentId)) { 255 if (UtilValidate.isNotEmpty(origSubContentId) && origFromDate != null) { 257 List oldActiveValues = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", targContentId, "contentIdTo", origSubContentId, "contentAssocTypeId", "PUBLISH_LINK", "thruDate", null)); 258 Iterator iterOldActive = oldActiveValues.iterator(); 259 while (iterOldActive.hasNext()) { 260 GenericValue cAssoc = (GenericValue)iterOldActive.next(); 261 cAssoc.set("thruDate", nowTimestamp); 262 cAssoc.store(); 263 } 265 } 266 Map serviceIn = new HashMap (); 268 serviceIn.put("userLogin", userLogin); 269 serviceIn.put("contentId", targContentId); 270 serviceIn.put("contentAssocTypeId", "PUBLISH_LINK"); 271 serviceIn.put("fromDate", nowTimestamp); 272 serviceIn.put("contentIdTo", currentSubContentId); 273 serviceIn.put("roleTypeList", roleTypeList); 274 serviceIn.put("targetOperationList", targetOperationList); 275 serviceIn.put("contentPurposeList", contentPurposeList); 276 results = dispatcher.runSync("createContentAssoc", serviceIn); 277 responseMessage = (String )results.get(ModelService.RESPONSE_MESSAGE); 278 if (UtilValidate.isNotEmpty(responseMessage)) { 279 errorMessage = (String )results.get(ModelService.ERROR_MESSAGE); 280 Debug.logError("in updatePublishLinks, serviceIn:" + serviceIn , module); 281 Debug.logError(errorMessage, module); 282 request.setAttribute("_ERROR_MESSAGE_", errorMessage); 283 return "error"; 284 } 285 286 serviceIn = new HashMap (); 287 serviceIn.put("userLogin", userLogin); 288 serviceIn.put("contentId", targContentId); 289 serviceIn.put("contentAssocTypeId", "PUBLISH_LINK"); 290 serviceIn.put("fromDate", nowTimestamp); 291 serviceIn.put("contentIdTo", contentId); 292 serviceIn.put("roleTypeList", roleTypeList); 293 serviceIn.put("targetOperationList", targetOperationList); 294 serviceIn.put("contentPurposeList", contentPurposeList); 295 results = dispatcher.runSync("createContentAssoc", serviceIn); 297 if (!statusIdUpdated) { 299 try { 300 GenericValue targContent = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", targContentId)); 301 targContent.set("statusId", "BLOG_PUBLISHED"); 302 targContent.store(); 303 statusIdUpdated = true; 304 } catch(GenericEntityException e) { 305 Debug.logError(e.getMessage(), module); 306 request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); 307 return "error"; 308 } 309 } 310 } 311 } else if ( UtilValidate.isNotEmpty(origSubContentId)) { 312 List oldActiveValues = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", targContentId, "contentIdTo", origSubContentId, "contentAssocTypeId", "PUBLISH_LINK", "thruDate", null)); 314 Iterator iterOldActive = oldActiveValues.iterator(); 315 while (iterOldActive.hasNext()) { 316 GenericValue cAssoc = (GenericValue)iterOldActive.next(); 317 cAssoc.set("thruDate", nowTimestamp); 318 cAssoc.store(); 319 } 320 oldActiveValues = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", targContentId, "contentIdTo", contentId, "contentAssocTypeId", "PUBLISH_LINK", "thruDate", null)); 321 iterOldActive = oldActiveValues.iterator(); 322 while (iterOldActive.hasNext()) { 323 GenericValue cAssoc = (GenericValue)iterOldActive.next(); 324 cAssoc.set("thruDate", nowTimestamp); 325 cAssoc.store(); 326 } 327 } 328 } catch(GenericEntityException e) { 329 Debug.logError(e.getMessage(), module); 330 request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); 331 return "error"; 332 } catch(GenericServiceException e2) { 333 Debug.logError(e2, module); 334 request.setAttribute("_ERROR_MESSAGE_", e2.getMessage()); 335 return "error"; 336 } 337 } 338 return "success"; 339 } 340 341 } 342 343 | Popular Tags |