⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 layoutevents.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                imageDataResource.set("imageData", byteWrap.getBytes());
                imageDataResource.create();
            } else {
                imageDataResource.set("imageData", byteWrap.getBytes());
                imageDataResource.store();
            }
        } catch (GenericEntityException e3) {
            request.setAttribute("_ERROR_MESSAGE_", e3.getMessage());
            return "error";
        }
        return "success";
    }

    public static String replaceSubContent(HttpServletRequest request, HttpServletResponse response) {

        GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator");
        LocalDispatcher dispatcher = (LocalDispatcher)request.getAttribute("dispatcher");
        HttpSession session = request.getSession();
        Map context = new HashMap();
        Map paramMap = UtilHttp.getParameterMap(request);
        Debug.logVerbose("in replaceSubContent, paramMap:" + paramMap, module);
        String dataResourceId = (String)paramMap.get("dataResourceId");
        if (UtilValidate.isEmpty(dataResourceId)) {
            request.setAttribute("_ERROR_MESSAGE_", "DataResourceId is null.");
            return "error";
        }
        String contentIdTo = (String)paramMap.get("contentIdTo");
        if (UtilValidate.isEmpty(contentIdTo)) {
            request.setAttribute("_ERROR_MESSAGE_", "contentIdTo is null.");
            return "error";
        }
        String mapKey = (String)paramMap.get("mapKey");

        context.put("dataResourceId", dataResourceId);
        String contentId = (String)paramMap.get("contentId");
        context.put("userLogin", session.getAttribute("userLogin"));

/*
        // If contentId is missing
        if (UtilValidate.isEmpty(contentId)) {
            // Look for an existing associated Content
            try {
                List lst = delegator.findByAnd(
                                     "DataResourceContentView ", 
                                     UtilMisc.toMap("dataResourceId", dataResourceId)); 
                if (lst.size() > 0) {
                    GenericValue dataResourceContentView  = (GenericValue)lst.get(0);
                    contentId = (String)dataResourceContentView.get("coContentId");
                }
            } catch( GenericEntityException e) {
                request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
                return "error";
            }
            // Else, create and associate a Content
        } 
*/
        if (UtilValidate.isNotEmpty(contentId)) {
            context.put("contentId", contentId);
            context.put("contentIdTo", contentIdTo);
            context.put("mapKey", mapKey);
            context.put("contentAssocTypeId", "SUB_CONTENT");
    
            try {
                Map result = dispatcher.runSync("persistContentAndAssoc", context);
        //Debug.logVerbose("in replaceSubContent, result:" + result, module);
                request.setAttribute("contentId", contentIdTo);
                Map context2 = new HashMap();
                context2.put("activeContentId", contentId);
                //context2.put("dataResourceId", dataResourceId);
                context2.put("contentAssocTypeId", "SUB_CONTENT");
                context2.put("fromDate", result.get("fromDate"));
        
                request.setAttribute("drDataResourceId", null);
                request.setAttribute("currentEntityName", "ContentDataResourceView");
        
                context2.put("contentIdTo", contentIdTo);
                context2.put("mapKey", mapKey);
        
                //Debug.logVerbose("in replaceSubContent, context2:" + context2, module);
                Map result2 = dispatcher.runSync("deactivateAssocs", context2);
            } catch( GenericServiceException e) {
                request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
                return "error";
            }
        }

        return "success";
    }

    public static String cloneLayout(HttpServletRequest request, HttpServletResponse response) {

        GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator");
        LocalDispatcher dispatcher = (LocalDispatcher)request.getAttribute("dispatcher");
        HttpSession session = request.getSession();
        Map paramMap = UtilHttp.getParameterMap(request);
        String contentId = (String)paramMap.get("contentId");
        Debug.logVerbose("in cloneLayout, contentId:" + contentId, "");
        if (UtilValidate.isEmpty(contentId)) {
                request.setAttribute("_ERROR_MESSAGE_", "contentId is empty");
                return "error";
        }
        String contentIdTo = (String)paramMap.get("contentIdTo");
        Debug.logVerbose("in cloneLayout, contentIdTo:" + contentIdTo, "");
        GenericValue content = null;
        GenericValue newContent = null;
        GenericValue userLogin = (GenericValue)request.getSession().getAttribute("userLogin");
        String userLoginId = (String) userLogin.get("userLoginId");
        List entityList = null;
        String newId = null;
        String newDataResourceId = null;
        try {
            content = delegator.findByPrimaryKey("Content", 
                       UtilMisc.toMap("contentId", contentId));
        Debug.logVerbose("in cloneLayout, content:" + content, "");
            if (content == null) {
                request.setAttribute("_ERROR_MESSAGE_", "content is empty");
                return "error";
            }
            newContent = delegator.makeValue("Content", content);
            Debug.logVerbose("in cloneLayout, newContent:" + newContent, "");
            String oldName = (String)content.get("contentName");
            newId = delegator.getNextSeqId("Content").toString();
            newContent.set("contentId", newId);
            String dataResourceId = (String)content.get("dataResourceId");
            GenericValue dataResource = delegator.findByPrimaryKey("DataResource", 
                       UtilMisc.toMap("dataResourceId", dataResourceId));
            if (dataResource != null) {
                GenericValue newDataResource = delegator.makeValue("DataResource", dataResource);
                Debug.logVerbose("in cloneLayout, newDataResource:" + newDataResource, "");
                String dataResourceName = "Copy:" + (String)dataResource.get("dataResourceName");
                newDataResource.set("dataResourceName", dataResourceName);
                newDataResourceId = delegator.getNextSeqId("DataResource").toString();
                newDataResource.set("dataResourceId", newDataResourceId);
                newDataResource.set("createdDate", UtilDateTime.nowTimestamp());
                newDataResource.set("lastModifiedDate", UtilDateTime.nowTimestamp());
                newDataResource.set("createdByUserLogin", userLoginId);
                newDataResource.set("lastModifiedByUserLogin", userLoginId);
                newDataResource.create();
            }
            newContent.set("contentName", "Copy - " + oldName);
            newContent.set("createdDate", UtilDateTime.nowTimestamp());
            newContent.set("lastModifiedDate", UtilDateTime.nowTimestamp());
            newContent.set("createdByUserLogin", userLoginId);
            newContent.set("lastModifiedByUserLogin", userLoginId);
            newContent.create();
            Debug.logVerbose("in cloneLayout, newContent:" + newContent, "");

            GenericValue newContentAssoc = delegator.makeValue("ContentAssoc", null);
            newContentAssoc.set("contentId", newId);
            newContentAssoc.set("contentIdTo", "TEMPLATE_MASTER");
            newContentAssoc.set("contentAssocTypeId", "SUB_CONTENT");
            newContentAssoc.set("fromDate", UtilDateTime.nowTimestamp());
            newContentAssoc.create();
            Debug.logVerbose("in cloneLayout, newContentAssoc:" + newContentAssoc, "");
        } catch(GenericEntityException e) {
                request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
                return "error";
        }
        Map serviceIn = new HashMap();
        Map results = null;
        serviceIn.put("fromDate", UtilDateTime.nowTimestamp());
        serviceIn.put("contentId", contentId);
        serviceIn.put("userLogin", session.getAttribute("userLogin"));
        serviceIn.put("direction", "From");
        serviceIn.put("thruDate", null);
        serviceIn.put("assocTypes", UtilMisc.toList("SUB_CONTENT"));
        try {
            results = dispatcher.runSync("getAssocAndContentAndDataResource", serviceIn);
            entityList = (List)results.get("entityList");
            if (entityList == null || entityList.size() == 0) {
                request.setAttribute("_ERROR_MESSAGE_", "No subContent found");
            }
        } catch(GenericServiceException e) {
                request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
                return "error";
        }
        
        serviceIn = new HashMap();
        serviceIn.put("userLogin", session.getAttribute("userLogin"));

        // Can't count on records being unique
        Map beenThere = new HashMap();
        for (int i=0; i<entityList.size(); i++) {
            GenericValue view = (GenericValue)entityList.get(i);
            List errorMessages = new ArrayList();
            Locale loc = (Locale)request.getSession().getServletContext().getAttribute("locale");
            if (loc == null)
                loc = Locale.getDefault();
            try {
                SimpleMapProcessor.runSimpleMapProcessor(
                      "org/ofbiz/content/ContentManagementMapProcessors.xml", "contentAssocIn",
                      view, serviceIn, errorMessages, loc);
            } catch(IllegalArgumentException e) {
                request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
                return "error";
            } catch(MiniLangException e) {
                request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
                return "error";
            }
            String contentIdFrom = (String)view.get("contentId");
            String mapKey = (String)view.get("caMapKey");
            Timestamp fromDate = (Timestamp)view.get("caFromDate");
            Timestamp thruDate = (Timestamp)view.get("caThruDate");
            Debug.logVerbose("in cloneLayout, contentIdFrom:" + contentIdFrom 
                      + " fromDate:" + fromDate
                      + " thruDate:" + thruDate
                      + " mapKey:" + mapKey
                      , "");
            if (beenThere.get(contentIdFrom) == null) {
                serviceIn.put("contentIdFrom", contentIdFrom);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -