📄 contentservices.java
字号:
activeAssoc = delegator.findByPrimaryKey("ContentAssoc", UtilMisc.toMap("contentId", activeContentId, "contentIdTo", contentIdTo, "fromDate", fromDate, "contentAssocTypeId", contentAssocTypeId)); if (activeAssoc == null) { return ServiceUtil.returnError("No association found for contentId=" + activeContentId + " and contentIdTo=" + contentIdTo + " and contentAssocTypeId=" + contentAssocTypeId + " and fromDate=" + fromDate); } sequenceNum = (String) activeAssoc.get("sequenceNum"); } List exprList = new ArrayList(); exprList.add(new EntityExpr("mapKey", EntityOperator.EQUALS, mapKey)); if (sequenceNum != null) { exprList.add(new EntityExpr("sequenceNum", EntityOperator.EQUALS, sequenceNum)); } exprList.add(new EntityExpr("mapKey", EntityOperator.EQUALS, mapKey)); exprList.add(new EntityExpr("thruDate", EntityOperator.EQUALS, null)); exprList.add(new EntityExpr("contentIdTo", EntityOperator.EQUALS, contentIdTo)); exprList.add(new EntityExpr("contentAssocTypeId", EntityOperator.EQUALS, contentAssocTypeId)); if (UtilValidate.isNotEmpty(activeContentId)) { exprList.add(new EntityExpr("contentId", EntityOperator.NOT_EQUAL, activeContentId)); } if (UtilValidate.isNotEmpty(contentId)) { exprList.add(new EntityExpr("contentId", EntityOperator.EQUALS, contentId)); } EntityConditionList assocExprList = new EntityConditionList(exprList, EntityOperator.AND); List relatedAssocs = delegator.findByCondition("ContentAssoc", assocExprList, new ArrayList(), UtilMisc.toList("fromDate")); //if (Debug.infoOn()) Debug.logInfo("in deactivateAssocs, relatedAssocs:" + relatedAssocs, module); List filteredAssocs = EntityUtil.filterByDate(relatedAssocs); //if (Debug.infoOn()) Debug.logInfo("in deactivateAssocs, filteredAssocs:" + filteredAssocs, module); Iterator it = filteredAssocs.iterator(); while (it.hasNext()) { GenericValue val = (GenericValue) it.next(); val.set("thruDate", nowTimestamp); val.store(); //if (Debug.infoOn()) Debug.logInfo("in deactivateAssocs, val:" + val, module); } results.put("deactivatedList", filteredAssocs); } catch (GenericEntityException e) { return ServiceUtil.returnError(e.getMessage()); } return results; } /** * Get and render subcontent associated with template id and mapkey. If subContentId is supplied, that content will be rendered without searching for other * matching content. */ public static Map renderSubContentAsText(DispatchContext dctx, Map context) { Map results = new HashMap(); GenericDelegator delegator = dctx.getDelegator(); //LocalDispatcher dispatcher = dctx.getDispatcher(); Map templateContext = (Map) context.get("templateContext"); String contentId = (String) context.get("contentId"); Timestamp fromDate = (Timestamp) context.get("fromDate"); GenericValue userLogin = (GenericValue) context.get("userLogin"); if (templateContext != null && UtilValidate.isEmpty(contentId)) { contentId = (String) templateContext.get("contentId"); } String mapKey = (String) context.get("mapKey"); if (templateContext != null && UtilValidate.isEmpty(mapKey)) { mapKey = (String) templateContext.get("mapKey"); } //String subContentId = (String) context.get("subContentId"); //if (templateContext != null && UtilValidate.isEmpty(subContentId)) { //subContentId = (String) templateContext.get("subContentId"); //} String mimeTypeId = (String) context.get("mimeTypeId"); if (templateContext != null && UtilValidate.isEmpty(mimeTypeId)) { mimeTypeId = (String) templateContext.get("mimeTypeId"); } Locale locale = (Locale) context.get("locale"); if (templateContext != null && locale == null) { locale = (Locale) templateContext.get("locale"); } GenericValue subContentDataResourceView = (GenericValue) context.get("subContentDataResourceView"); if (subContentDataResourceView != null && subContentDataResourceView == null) { subContentDataResourceView = (GenericValue) templateContext.get("subContentDataResourceView"); } Writer out = (Writer) context.get("outWriter"); Writer outWriter = new StringWriter(); if (templateContext == null) { templateContext = new HashMap(); } try { results = ContentWorker.renderSubContentAsTextCache(delegator, contentId, outWriter, mapKey, subContentDataResourceView, templateContext, locale, mimeTypeId, userLogin, fromDate); out.write(outWriter.toString()); results.put("textData", outWriter.toString()); } catch (GeneralException e) { Debug.logError(e, "Error rendering sub-content text", module); return ServiceUtil.returnError(e.toString()); } catch (IOException e) { Debug.logError(e, "Error rendering sub-content text", module); return ServiceUtil.returnError(e.toString()); } return results; } /** * Get and render subcontent associated with template id and mapkey. If subContentId is supplied, that content will be rendered without searching for other * matching content. */ public static Map renderContentAsText(DispatchContext dctx, Map context) { Map results = new HashMap(); GenericDelegator delegator = dctx.getDelegator(); Writer out = (Writer) context.get("outWriter"); Map templateContext = (Map) context.get("templateContext"); //GenericValue userLogin = (GenericValue)context.get("userLogin"); String contentId = (String) context.get("contentId"); if (templateContext != null && UtilValidate.isEmpty(contentId)) { contentId = (String) templateContext.get("contentId"); } String mimeTypeId = (String) context.get("mimeTypeId"); if (templateContext != null && UtilValidate.isEmpty(mimeTypeId)) { mimeTypeId = (String) templateContext.get("mimeTypeId"); } Locale locale = (Locale) context.get("locale"); if (templateContext != null && locale == null) { locale = (Locale) templateContext.get("locale"); } if (templateContext == null) { templateContext = new HashMap(); } Writer outWriter = new StringWriter(); GenericValue view = (GenericValue)context.get("subContentDataResourceView"); try { Map thisResults = ContentWorker.renderContentAsTextCache(delegator, contentId, outWriter, templateContext, view, locale, mimeTypeId); out.write(outWriter.toString()); results.put("textData", outWriter.toString()); } catch (GeneralException e) { Debug.logError(e, "Error rendering sub-content text", module); return ServiceUtil.returnError(e.toString()); } catch (IOException e) { Debug.logError(e, "Error rendering sub-content text", module); return ServiceUtil.returnError(e.toString()); } return results; } public static Map linkContentToPubPt(DispatchContext dctx, Map context) { Map results = new HashMap(); GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); String contentId = (String) context.get("contentId"); String contentIdTo = (String) context.get("contentIdTo"); String contentAssocTypeId = (String) context.get("contentAssocTypeId"); String statusId = (String) context.get("statusId"); String privilegeEnumId = (String) context.get("privilegeEnumId"); GenericValue userLogin = (GenericValue) context.get("userLogin"); if (Debug.infoOn()) Debug.logInfo("in publishContent, statusId:" + statusId, module); if (Debug.infoOn()) Debug.logInfo("in publishContent, userLogin:" + userLogin, module); Map mapIn = new HashMap(); mapIn.put("contentId", contentId); mapIn.put("contentIdTo", contentIdTo); mapIn.put("contentAssocTypeId", contentAssocTypeId); String publish = (String) context.get("publish"); try { boolean isPublished = false; GenericValue contentAssocViewFrom = ContentWorker.getContentAssocViewFrom(delegator, contentIdTo, contentId, contentAssocTypeId, statusId, privilegeEnumId); if (contentAssocViewFrom != null) isPublished = true; if (Debug.infoOn()) Debug.logInfo("in publishContent, contentId:" + contentId + " contentIdTo:" + contentIdTo + " contentAssocTypeId:" + contentAssocTypeId + " publish:" + publish + " isPublished:" + isPublished, module); if (UtilValidate.isNotEmpty(publish) && publish.equalsIgnoreCase("Y")) { GenericValue content = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentId)); String contentStatusId = (String) content.get("statusId"); String contentPrivilegeEnumId = (String) content.get("privilegeEnumId"); if (Debug.infoOn()) Debug.logInfo("in publishContent, statusId:" + statusId + " contentStatusId:" + contentStatusId + " privilegeEnumId:" + privilegeEnumId + " contentPrivilegeEnumId:" + contentPrivilegeEnumId, module); // Don't do anything if link was already there if (!isPublished) { //Map thisResults = dispatcher.runSync("deactivateAssocs", mapIn); //String errorMsg = ServiceUtil.getErrorMessage(thisResults); //if (UtilValidate.isNotEmpty(errorMsg) ) { //Debug.logError( "Problem running deactivateAssocs. " + errorMsg, "ContentServices"); //return ServiceUtil.returnError(errorMsg); //} content.put("privilegeEnumId", privilegeEnumId); content.put("statusId", statusId); content.store(); mapIn = new HashMap(); mapIn.put("contentId", contentId); mapIn.put("contentIdTo", contentIdTo); mapIn.put("contentAssocTypeId", contentAssocTypeId); mapIn.put("mapKey", context.get("mapKey")); mapIn.put("fromDate", UtilDateTime.nowTimestamp()); mapIn.put("createdDate", UtilDateTime.nowTimestamp()); mapIn.put("lastModifiedDate", UtilDateTime.nowTimestamp()); mapIn.put("createdByUserLogin", userLogin.get("userLoginId")); mapIn.put("lastModifiedByUserLogin", userLogin.get("userLoginId")); delegator.create("ContentAssoc", mapIn); } } else { // Only deactive if currently published if (isPublished) { Map thisResults = dispatcher.runSync("deactivateAssocs", mapIn); String errorMsg = ServiceUtil.getErrorMessage(thisResults); if (UtilValidate.isNotEmpty(errorMsg)) { Debug.logError("Problem running deactivateAssocs. " + errorMsg, "ContentServices"); return ServiceUtil.returnError(errorMsg); } } } } catch (GenericEntityException e) { Debug.logError(e, "Problem getting existing content", "ContentServices"); return ServiceUtil.returnError(e.getMessage()); } catch (GenericServiceException e) { Debug.logError(e, "Problem running deactivateAssocs", "ContentServices"); return ServiceUtil.returnError(e.getMessage()); } return results; } public static Map publishContent(DispatchContext dctx, Map context) throws GenericServiceException{ Map result = new HashMap(); GenericDelegator delegator = dctx.getDelegator(); GenericValue content = (GenericValue)context.get("content"); GenericValue userLogin = (GenericValue)context.get("userLogin"); Security security = dctx.getSecurity(); if (!security.hasEntityPermission("CONTENTMGR", "_ADMIN", userLogin)) { return ServiceUtil.returnError("Permission denied."); } try { content.put("statusId", "BLOG_PUBLISHED"); content.store(); } catch(GenericEntityException e) { Debug.logError(e.getMessage(), module); return ServiceUtil.returnError(e.getMessage()); } return result; } public static Map getPrefixedMembers(DispatchContext dctx, Map context) throws GenericServiceException{ Map result = new HashMap(); Map mapIn = (Map)context.get("mapIn"); String prefix = (String)context.get("prefix"); Map mapOut = new HashMap(); result.put("mapOut", mapOut); if (mapIn != null) { Set entrySet = mapIn.entrySet(); Iterator iter = entrySet.iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry)iter.next(); String key = (String)entry.getKey(); if (key.startsWith(prefix)) { String keyBase = key.substring(prefix.length());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -