001: package org.ofbiz.content.layout;
002:
003: import java.sql.Timestamp;
004: import java.util.ArrayList;
005: import java.util.HashMap;
006: import java.util.Collection;
007: import java.util.Iterator;
008: import java.util.List;
009: import java.util.Map;
010: import java.util.Locale;
011:
012: import org.ofbiz.base.util.Debug;
013: import org.ofbiz.base.util.UtilDateTime;
014: import org.ofbiz.base.util.UtilMisc;
015: import org.ofbiz.base.util.UtilProperties;
016: import org.ofbiz.base.util.UtilValidate;
017: import org.ofbiz.base.util.UtilHttp;
018: import org.ofbiz.entity.GenericDelegator;
019: import org.ofbiz.entity.GenericEntityException;
020: import org.ofbiz.entity.GenericValue;
021: import org.ofbiz.entity.GenericPK;
022: import org.ofbiz.entity.condition.EntityCondition;
023: import org.ofbiz.entity.condition.EntityConditionList;
024: import org.ofbiz.entity.condition.EntityExpr;
025: import org.ofbiz.entity.condition.EntityOperator;
026: import org.ofbiz.entity.util.ByteWrapper;
027: import org.ofbiz.security.Security;
028: import org.ofbiz.service.DispatchContext;
029: import org.ofbiz.service.ServiceUtil;
030: import org.ofbiz.service.GenericServiceException;
031: import org.ofbiz.service.LocalDispatcher;
032: import org.ofbiz.service.ModelService;
033: import org.ofbiz.minilang.MiniLangException;
034: import org.ofbiz.minilang.SimpleMapProcessor;
035: import org.ofbiz.content.ContentManagementWorker;
036:
037: import org.apache.commons.fileupload.*;
038: import javax.servlet.http.HttpServletRequest;
039: import javax.servlet.http.HttpServletResponse;
040: import javax.servlet.http.HttpSession;
041:
042: /**
043: * LayoutEvents Class
044: *
045: * @author <a href="mailto:byersa@automationgroups.com">Al Byers</a>
046: * @version $Revision: 1.10 $
047: * @since 3.0
048: *
049: *
050: */
051: public class LayoutEvents {
052:
053: public static final String module = LayoutEvents.class.getName();
054:
055: public static String createLayoutImage(HttpServletRequest request,
056: HttpServletResponse response) {
057:
058: try {
059: GenericDelegator delegator = (GenericDelegator) request
060: .getAttribute("delegator");
061: LocalDispatcher dispatcher = (LocalDispatcher) request
062: .getAttribute("dispatcher");
063: HttpSession session = request.getSession();
064: Map uploadResults = LayoutWorker.uploadImageAndParameters(
065: request, "imageData");
066: //Debug.logVerbose("in createLayoutImage(java), uploadResults:" + uploadResults, "");
067: Map formInput = (Map) uploadResults.get("formInput");
068: Map context = new HashMap();
069: ByteWrapper byteWrap = (ByteWrapper) uploadResults
070: .get("imageData");
071: if (byteWrap == null) {
072: request.setAttribute("_ERROR_MESSAGE_",
073: "Image data is null.");
074: return "error";
075: }
076: //Debug.logVerbose("in createLayoutImage, byteWrap(0):" + byteWrap, module);
077: String imageFileName = (String) uploadResults
078: .get("imageFileName");
079: //Debug.logVerbose("in createLayoutImage(java), context:" + context, "");
080:
081: List errorMessages = new ArrayList();
082: Locale loc = (Locale) request.getSession()
083: .getServletContext().getAttribute("locale");
084: if (loc == null)
085: loc = Locale.getDefault();
086: context.put("locale", loc);
087:
088: try {
089: SimpleMapProcessor
090: .runSimpleMapProcessor(
091: "org/ofbiz/content/ContentManagementMapProcessors.xml",
092: "contentIn", formInput, context,
093: errorMessages, loc);
094: SimpleMapProcessor
095: .runSimpleMapProcessor(
096: "org/ofbiz/content/ContentManagementMapProcessors.xml",
097: "dataResourceIn", formInput, context,
098: errorMessages, loc);
099: SimpleMapProcessor
100: .runSimpleMapProcessor(
101: "org/ofbiz/content/ContentManagementMapProcessors.xml",
102: "contentAssocIn", formInput, context,
103: errorMessages, loc);
104: } catch (MiniLangException e) {
105: request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
106: return "error";
107: }
108:
109: context.put("dataResourceName", context.get("contentName"));
110: context.put("userLogin", session.getAttribute("userLogin"));
111: context.put("dataResourceTypeId", "IMAGE_OBJECT");
112: context.put("contentAssocTypeId", "SUB_CONTENT");
113: context.put("contentTypeId", "DOCUMENT");
114: context.put("contentIdTo", formInput.get("contentIdTo"));
115: context.put("textData", formInput.get("textData"));
116: String contentPurposeTypeId = (String) formInput
117: .get("contentPurposeTypeId");
118: if (UtilValidate.isNotEmpty(contentPurposeTypeId)) {
119: context.put("contentPurposeList", UtilMisc
120: .toList(contentPurposeTypeId));
121: }
122:
123: Map result = dispatcher.runSync("persistContentAndAssoc",
124: context);
125: //Debug.logVerbose("in createLayoutImage, result:" + result, module);
126:
127: String dataResourceId = (String) result
128: .get("dataResourceId");
129: String activeContentId = (String) result.get("contentId");
130: if (UtilValidate.isNotEmpty(activeContentId)) {
131: Map context2 = new HashMap();
132: context2.put("activeContentId", activeContentId);
133: //context2.put("dataResourceId", dataResourceId);
134: context2.put("contentAssocTypeId", result
135: .get("contentAssocTypeId"));
136: context2.put("fromDate", result.get("fromDate"));
137:
138: request.setAttribute("contentId", result
139: .get("contentId"));
140: request
141: .setAttribute("drDataResourceId",
142: dataResourceId);
143: request.setAttribute("currentEntityName",
144: "SubContentDataResourceId");
145:
146: context2.put("contentIdTo", formInput
147: .get("contentIdTo"));
148: context2.put("mapKey", formInput.get("mapKey"));
149:
150: //Debug.logVerbose("in createLayoutImage, context2:" + context2, module);
151: Map result2 = dispatcher.runSync("deactivateAssocs",
152: context2);
153: }
154:
155: GenericValue dataResource = delegator.findByPrimaryKey(
156: "DataResource", UtilMisc.toMap("dataResourceId",
157: dataResourceId));
158: //Debug.logVerbose("in createLayoutImage, dataResource:" + dataResource, module);
159: // Use objectInfo field to store the name of the file, since there is no
160: // place in ImageDataResource for it.
161: if (dataResource != null) {
162: dataResource.set("objectInfo", imageFileName);
163: dataResource.store();
164: }
165:
166: // See if this needs to be a create or an update procedure
167: GenericValue imageDataResource = delegator
168: .findByPrimaryKey("ImageDataResource", UtilMisc
169: .toMap("dataResourceId", dataResourceId));
170: //Debug.logVerbose("in createLayoutImage, imageDataResource(0):" + imageDataResource, module);
171: if (imageDataResource == null) {
172: imageDataResource = delegator.makeValue(
173: "ImageDataResource", UtilMisc.toMap(
174: "dataResourceId", dataResourceId));
175: imageDataResource.set("imageData", byteWrap.getBytes());
176: imageDataResource.create();
177: } else {
178: imageDataResource.set("imageData", byteWrap.getBytes());
179: imageDataResource.store();
180: }
181: } catch (GenericEntityException e3) {
182: request.setAttribute("_ERROR_MESSAGE_", e3.getMessage());
183: return "error";
184: } catch (GenericServiceException e) {
185: request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
186: return "error";
187: }
188: return "success";
189: }
190:
191: public static String updateLayoutImage(HttpServletRequest request,
192: HttpServletResponse response) {
193:
194: try {
195: GenericDelegator delegator = (GenericDelegator) request
196: .getAttribute("delegator");
197: LocalDispatcher dispatcher = (LocalDispatcher) request
198: .getAttribute("dispatcher");
199: HttpSession session = request.getSession();
200: Map uploadResults = LayoutWorker.uploadImageAndParameters(
201: request, "imageData");
202: Map context = (Map) uploadResults.get("formInput");
203: ByteWrapper byteWrap = (ByteWrapper) uploadResults
204: .get("imageData");
205: if (byteWrap == null) {
206: request.setAttribute("_ERROR_MESSAGE_",
207: "Image data is null.");
208: return "error";
209: }
210: String imageFileName = (String) uploadResults
211: .get("imageFileName");
212: Debug.logVerbose("in createLayoutImage(java), context:"
213: + context, "");
214: context.put("userLogin", session.getAttribute("userLogin"));
215: context.put("dataResourceTypeId", "IMAGE_OBJECT");
216: context.put("contentAssocTypeId", "SUB_CONTENT");
217: context.put("contentTypeId", "DOCUMENT");
218: context.put("mimeType", context.get("drMimeType"));
219: context.put("drMimeType", null);
220: context.put("objectInfo", context.get("drobjectInfo"));
221: context.put("drObjectInfo", null);
222: context.put("drDataResourceTypeId", null);
223:
224: String dataResourceId = (String) context
225: .get("drDataResourceId");
226: Debug.logVerbose(
227: "in createLayoutImage(java), dataResourceId:"
228: + dataResourceId, "");
229:
230: GenericValue dataResource = delegator.findByPrimaryKey(
231: "DataResource", UtilMisc.toMap("dataResourceId",
232: dataResourceId));
233: Debug.logVerbose(
234: "in createLayoutImage(java), dataResource:"
235: + dataResource, "");
236: // Use objectInfo field to store the name of the file, since there is no
237: // place in ImageDataResource for it.
238: Debug.logVerbose(
239: "in createLayoutImage(java), imageFileName:"
240: + imageFileName, "");
241: if (dataResource != null) {
242: //dataResource.set("objectInfo", imageFileName);
243: dataResource.setNonPKFields(context);
244: dataResource.store();
245: }
246:
247: // See if this needs to be a create or an update procedure
248: GenericValue imageDataResource = delegator
249: .findByPrimaryKey("ImageDataResource", UtilMisc
250: .toMap("dataResourceId", dataResourceId));
251: if (imageDataResource == null) {
252: imageDataResource = delegator.makeValue(
253: "ImageDataResource", UtilMisc.toMap(
254: "dataResourceId", dataResourceId));
255: imageDataResource.set("imageData", byteWrap.getBytes());
256: imageDataResource.create();
257: } else {
258: imageDataResource.set("imageData", byteWrap.getBytes());
259: imageDataResource.store();
260: }
261: } catch (GenericEntityException e3) {
262: request.setAttribute("_ERROR_MESSAGE_", e3.getMessage());
263: return "error";
264: }
265: return "success";
266: }
267:
268: public static String replaceSubContent(HttpServletRequest request,
269: HttpServletResponse response) {
270:
271: GenericDelegator delegator = (GenericDelegator) request
272: .getAttribute("delegator");
273: LocalDispatcher dispatcher = (LocalDispatcher) request
274: .getAttribute("dispatcher");
275: HttpSession session = request.getSession();
276: Map context = new HashMap();
277: Map paramMap = UtilHttp.getParameterMap(request);
278: Debug.logVerbose("in replaceSubContent, paramMap:" + paramMap,
279: module);
280: String dataResourceId = (String) paramMap.get("dataResourceId");
281: if (UtilValidate.isEmpty(dataResourceId)) {
282: request.setAttribute("_ERROR_MESSAGE_",
283: "DataResourceId is null.");
284: return "error";
285: }
286: String contentIdTo = (String) paramMap.get("contentIdTo");
287: if (UtilValidate.isEmpty(contentIdTo)) {
288: request.setAttribute("_ERROR_MESSAGE_",
289: "contentIdTo is null.");
290: return "error";
291: }
292: String mapKey = (String) paramMap.get("mapKey");
293:
294: context.put("dataResourceId", dataResourceId);
295: String contentId = (String) paramMap.get("contentId");
296: context.put("userLogin", session.getAttribute("userLogin"));
297:
298: /*
299: // If contentId is missing
300: if (UtilValidate.isEmpty(contentId)) {
301: // Look for an existing associated Content
302: try {
303: List lst = delegator.findByAnd(
304: "DataResourceContentView ",
305: UtilMisc.toMap("dataResourceId", dataResourceId));
306: if (lst.size() > 0) {
307: GenericValue dataResourceContentView = (GenericValue)lst.get(0);
308: contentId = (String)dataResourceContentView.get("coContentId");
309: }
310: } catch( GenericEntityException e) {
311: request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
312: return "error";
313: }
314: // Else, create and associate a Content
315: }
316: */
317: if (UtilValidate.isNotEmpty(contentId)) {
318: context.put("contentId", contentId);
319: context.put("contentIdTo", contentIdTo);
320: context.put("mapKey", mapKey);
321: context.put("contentAssocTypeId", "SUB_CONTENT");
322:
323: try {
324: Map result = dispatcher.runSync(
325: "persistContentAndAssoc", context);
326: //Debug.logVerbose("in replaceSubContent, result:" + result, module);
327: request.setAttribute("contentId", contentIdTo);
328: Map context2 = new HashMap();
329: context2.put("activeContentId", contentId);
330: //context2.put("dataResourceId", dataResourceId);
331: context2.put("contentAssocTypeId", "SUB_CONTENT");
332: context2.put("fromDate", result.get("fromDate"));
333:
334: request.setAttribute("drDataResourceId", null);
335: request.setAttribute("currentEntityName",
336: "ContentDataResourceView");
337:
338: context2.put("contentIdTo", contentIdTo);
339: context2.put("mapKey", mapKey);
340:
341: //Debug.logVerbose("in replaceSubContent, context2:" + context2, module);
342: Map result2 = dispatcher.runSync("deactivateAssocs",
343: context2);
344: } catch (GenericServiceException e) {
345: request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
346: return "error";
347: }
348: }
349:
350: return "success";
351: }
352:
353: public static String cloneLayout(HttpServletRequest request,
354: HttpServletResponse response) {
355:
356: GenericDelegator delegator = (GenericDelegator) request
357: .getAttribute("delegator");
358: LocalDispatcher dispatcher = (LocalDispatcher) request
359: .getAttribute("dispatcher");
360: HttpSession session = request.getSession();
361: Map paramMap = UtilHttp.getParameterMap(request);
362: String contentId = (String) paramMap.get("contentId");
363: Debug.logVerbose("in cloneLayout, contentId:" + contentId, "");
364: if (UtilValidate.isEmpty(contentId)) {
365: request.setAttribute("_ERROR_MESSAGE_",
366: "contentId is empty");
367: return "error";
368: }
369: String contentIdTo = (String) paramMap.get("contentIdTo");
370: Debug.logVerbose("in cloneLayout, contentIdTo:" + contentIdTo,
371: "");
372: GenericValue content = null;
373: GenericValue newContent = null;
374: GenericValue userLogin = (GenericValue) request.getSession()
375: .getAttribute("userLogin");
376: String userLoginId = (String) userLogin.get("userLoginId");
377: List entityList = null;
378: String newId = null;
379: String newDataResourceId = null;
380: try {
381: content = delegator.findByPrimaryKey("Content", UtilMisc
382: .toMap("contentId", contentId));
383: Debug.logVerbose("in cloneLayout, content:" + content, "");
384: if (content == null) {
385: request.setAttribute("_ERROR_MESSAGE_",
386: "content is empty");
387: return "error";
388: }
389: newContent = delegator.makeValue("Content", content);
390: Debug.logVerbose(
391: "in cloneLayout, newContent:" + newContent, "");
392: String oldName = (String) content.get("contentName");
393: newId = delegator.getNextSeqId("Content").toString();
394: newContent.set("contentId", newId);
395: String dataResourceId = (String) content
396: .get("dataResourceId");
397: GenericValue dataResource = delegator.findByPrimaryKey(
398: "DataResource", UtilMisc.toMap("dataResourceId",
399: dataResourceId));
400: if (dataResource != null) {
401: GenericValue newDataResource = delegator.makeValue(
402: "DataResource", dataResource);
403: Debug.logVerbose("in cloneLayout, newDataResource:"
404: + newDataResource, "");
405: String dataResourceName = "Copy:"
406: + (String) dataResource.get("dataResourceName");
407: newDataResource.set("dataResourceName",
408: dataResourceName);
409: newDataResourceId = delegator.getNextSeqId(
410: "DataResource").toString();
411: newDataResource
412: .set("dataResourceId", newDataResourceId);
413: newDataResource.set("createdDate", UtilDateTime
414: .nowTimestamp());
415: newDataResource.set("lastModifiedDate", UtilDateTime
416: .nowTimestamp());
417: newDataResource.set("createdByUserLogin", userLoginId);
418: newDataResource.set("lastModifiedByUserLogin",
419: userLoginId);
420: newDataResource.create();
421: }
422: newContent.set("contentName", "Copy - " + oldName);
423: newContent.set("createdDate", UtilDateTime.nowTimestamp());
424: newContent.set("lastModifiedDate", UtilDateTime
425: .nowTimestamp());
426: newContent.set("createdByUserLogin", userLoginId);
427: newContent.set("lastModifiedByUserLogin", userLoginId);
428: newContent.create();
429: Debug.logVerbose(
430: "in cloneLayout, newContent:" + newContent, "");
431:
432: GenericValue newContentAssoc = delegator.makeValue(
433: "ContentAssoc", null);
434: newContentAssoc.set("contentId", newId);
435: newContentAssoc.set("contentIdTo", "TEMPLATE_MASTER");
436: newContentAssoc.set("contentAssocTypeId", "SUB_CONTENT");
437: newContentAssoc
438: .set("fromDate", UtilDateTime.nowTimestamp());
439: newContentAssoc.create();
440: Debug.logVerbose("in cloneLayout, newContentAssoc:"
441: + newContentAssoc, "");
442: } catch (GenericEntityException e) {
443: request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
444: return "error";
445: }
446: Map serviceIn = new HashMap();
447: Map results = null;
448: serviceIn.put("fromDate", UtilDateTime.nowTimestamp());
449: serviceIn.put("contentId", contentId);
450: serviceIn.put("userLogin", session.getAttribute("userLogin"));
451: serviceIn.put("direction", "From");
452: serviceIn.put("thruDate", null);
453: serviceIn.put("assocTypes", UtilMisc.toList("SUB_CONTENT"));
454: try {
455: results = dispatcher.runSync(
456: "getAssocAndContentAndDataResource", serviceIn);
457: entityList = (List) results.get("entityList");
458: if (entityList == null || entityList.size() == 0) {
459: request.setAttribute("_ERROR_MESSAGE_",
460: "No subContent found");
461: }
462: } catch (GenericServiceException e) {
463: request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
464: return "error";
465: }
466:
467: serviceIn = new HashMap();
468: serviceIn.put("userLogin", session.getAttribute("userLogin"));
469:
470: // Can't count on records being unique
471: Map beenThere = new HashMap();
472: for (int i = 0; i < entityList.size(); i++) {
473: GenericValue view = (GenericValue) entityList.get(i);
474: List errorMessages = new ArrayList();
475: Locale loc = (Locale) request.getSession()
476: .getServletContext().getAttribute("locale");
477: if (loc == null)
478: loc = Locale.getDefault();
479: try {
480: SimpleMapProcessor
481: .runSimpleMapProcessor(
482: "org/ofbiz/content/ContentManagementMapProcessors.xml",
483: "contentAssocIn", view, serviceIn,
484: errorMessages, loc);
485: } catch (IllegalArgumentException e) {
486: request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
487: return "error";
488: } catch (MiniLangException e) {
489: request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
490: return "error";
491: }
492: String contentIdFrom = (String) view.get("contentId");
493: String mapKey = (String) view.get("caMapKey");
494: Timestamp fromDate = (Timestamp) view.get("caFromDate");
495: Timestamp thruDate = (Timestamp) view.get("caThruDate");
496: Debug
497: .logVerbose("in cloneLayout, contentIdFrom:"
498: + contentIdFrom + " fromDate:" + fromDate
499: + " thruDate:" + thruDate + " mapKey:"
500: + mapKey, "");
501: if (beenThere.get(contentIdFrom) == null) {
502: serviceIn.put("contentIdFrom", contentIdFrom);
503: serviceIn.put("contentIdTo", newId);
504: serviceIn.put("fromDate", UtilDateTime.nowTimestamp());
505: serviceIn.put("thruDate", null);
506: try {
507: results = dispatcher.runSync(
508: "persistContentAndAssoc", serviceIn);
509: } catch (GenericServiceException e) {
510: request.setAttribute("_ERROR_MESSAGE_", e
511: .getMessage());
512: return "error";
513: }
514: beenThere.put(contentIdFrom, view);
515: }
516:
517: }
518:
519: GenericValue view = delegator.makeValue(
520: "ContentDataResourceView", null);
521: view.set("contentId", newId);
522: view.set("drDataResourceId", newDataResourceId);
523: Debug.logVerbose("in cloneLayout, view:" + view, "");
524: ContentManagementWorker.setCurrentEntityMap(request, view);
525: request.setAttribute("contentId", view.get("contentId"));
526: request.setAttribute("drDataResourceId", view
527: .get("drDataResourceId"));
528: return "success";
529: }
530:
531: public static String createLayoutSubContent(
532: HttpServletRequest request, HttpServletResponse response) {
533:
534: try {
535: LocalDispatcher dispatcher = (LocalDispatcher) request
536: .getAttribute("dispatcher");
537: HttpSession session = request.getSession();
538: Map paramMap = UtilHttp.getParameterMap(request);
539: String contentIdTo = (String) paramMap.get("contentIdTo");
540: String mapKey = (String) paramMap.get("mapKey");
541: if (Debug.verboseOn()) {
542: Debug.logVerbose("in createSubContent, contentIdTo:"
543: + contentIdTo, module);
544: Debug.logVerbose("in createSubContent, mapKey:"
545: + mapKey, module);
546: }
547: Map context = new HashMap();
548: List errorMessages = null;
549: Locale loc = (Locale) request.getSession()
550: .getServletContext().getAttribute("locale");
551: if (loc == null)
552: loc = Locale.getDefault();
553: GenericValue userLogin = (GenericValue) session
554: .getAttribute("userLogin");
555: context.put("userLogin", userLogin);
556:
557: String rootDir = request.getSession().getServletContext()
558: .getRealPath("/");
559: context.put("rootDir", rootDir);
560: try {
561: SimpleMapProcessor
562: .runSimpleMapProcessor(
563: "org/ofbiz/content/ContentManagementMapProcessors.xml",
564: "contentIn", paramMap, context,
565: errorMessages, loc);
566: SimpleMapProcessor
567: .runSimpleMapProcessor(
568: "org/ofbiz/content/ContentManagementMapProcessors.xml",
569: "dataResourceIn", paramMap, context,
570: errorMessages, loc);
571: SimpleMapProcessor
572: .runSimpleMapProcessor(
573: "org/ofbiz/content/ContentManagementMapProcessors.xml",
574: "contentAssocIn", paramMap, context,
575: errorMessages, loc);
576: } catch (MiniLangException e) {
577: request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
578: return "error";
579: }
580:
581: context.put("dataResourceName", context.get("contentName"));
582: String contentPurposeTypeId = (String) paramMap
583: .get("contentPurposeTypeId");
584: if (UtilValidate.isNotEmpty(contentPurposeTypeId))
585: context.put("contentPurposeList", UtilMisc
586: .toList(contentPurposeTypeId));
587: context.put("contentIdTo", paramMap.get("contentIdTo"));
588: context.put("mapKey", paramMap.get("mapKey"));
589: context.put("textData", paramMap.get("textData"));
590: context.put("contentAssocTypeId", "SUB_CONTENT");
591: if (Debug.verboseOn())
592: Debug.logVerbose("in createSubContent, context:"
593: + context, module);
594: Map result = dispatcher.runSync("persistContentAndAssoc",
595: context);
596: boolean isError = ModelService.RESPOND_ERROR.equals(result
597: .get(ModelService.RESPONSE_MESSAGE));
598: if (isError) {
599: request.setAttribute("_ERROR_MESSAGE_", result
600: .get(ModelService.ERROR_MESSAGE));
601: return "error";
602: }
603:
604: if (Debug.verboseOn())
605: Debug.logVerbose("in createLayoutFile, result:"
606: + result, module);
607: String contentId = (String) result.get("contentId");
608: String dataResourceId = (String) result
609: .get("dataResourceId");
610: request.setAttribute("contentId", contentId);
611: request.setAttribute("drDataResourceId", dataResourceId);
612: request.setAttribute("currentEntityName",
613: "SubContentDataResourceId");
614: Map context2 = new HashMap();
615: context2.put("activeContentId", contentId);
616: //context2.put("dataResourceId", dataResourceId);
617: context2.put("contentAssocTypeId", "SUB_CONTENT");
618: context2.put("fromDate", result.get("fromDate"));
619: context2.put("contentIdTo", contentIdTo);
620: context2.put("mapKey", mapKey);
621:
622: //Debug.logVerbose("in replaceSubContent, context2:" + context2, module);
623: Map result2 = dispatcher.runSync("deactivateAssocs",
624: context2);
625: } catch (GenericServiceException e) {
626: request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
627: return "error";
628: }
629: return "success";
630: }
631:
632: public static String updateLayoutSubContent(
633: HttpServletRequest request, HttpServletResponse response) {
634:
635: try {
636: LocalDispatcher dispatcher = (LocalDispatcher) request
637: .getAttribute("dispatcher");
638: HttpSession session = request.getSession();
639: Map paramMap = UtilHttp.getParameterMap(request);
640: String contentIdTo = (String) paramMap.get("contentIdTo");
641: String mapKey = (String) paramMap.get("mapKey");
642: Map context = new HashMap();
643: List errorMessages = null;
644: Locale loc = (Locale) request.getSession()
645: .getServletContext().getAttribute("locale");
646: if (loc == null)
647: loc = Locale.getDefault();
648: context.put("locale", loc);
649: GenericValue userLogin = (GenericValue) session
650: .getAttribute("userLogin");
651: context.put("userLogin", userLogin);
652:
653: String rootDir = request.getSession().getServletContext()
654: .getRealPath("/");
655: context.put("rootDir", rootDir);
656: try {
657: SimpleMapProcessor
658: .runSimpleMapProcessor(
659: "org/ofbiz/content/ContentManagementMapProcessors.xml",
660: "contentIn", paramMap, context,
661: errorMessages, loc);
662: SimpleMapProcessor
663: .runSimpleMapProcessor(
664: "org/ofbiz/content/ContentManagementMapProcessors.xml",
665: "dataResourceIn", paramMap, context,
666: errorMessages, loc);
667: SimpleMapProcessor
668: .runSimpleMapProcessor(
669: "org/ofbiz/content/ContentManagementMapProcessors.xml",
670: "contentAssocIn", paramMap, context,
671: errorMessages, loc);
672: } catch (MiniLangException e) {
673: request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
674: return "error";
675: }
676:
677: context.put("dataResourceName", context.get("contentName"));
678: String contentPurposeTypeId = (String) paramMap
679: .get("contentPurposeTypeId");
680: if (UtilValidate.isNotEmpty(contentPurposeTypeId))
681: context.put("contentPurposeList", UtilMisc
682: .toList(contentPurposeTypeId));
683: context.put("contentIdTo", paramMap.get("contentIdTo"));
684: context.put("textData", paramMap.get("textData"));
685: context.put("contentAssocTypeId", null);
686: Map result = dispatcher.runSync("persistContentAndAssoc",
687: context);
688: boolean isError = ModelService.RESPOND_ERROR.equals(result
689: .get(ModelService.RESPONSE_MESSAGE));
690: if (isError) {
691: request.setAttribute("_ERROR_MESSAGE_", result
692: .get(ModelService.ERROR_MESSAGE));
693: return "error";
694: }
695: String contentId = (String) result.get("contentId");
696: String dataResourceId = (String) result
697: .get("dataResourceId");
698: request.setAttribute("contentId", contentId);
699: request.setAttribute("drDataResourceId", dataResourceId);
700: request.setAttribute("currentEntityName",
701: "SubContentDataResourceId");
702: /*
703: Map context2 = new HashMap();
704: context2.put("activeContentId", contentId);
705: //context2.put("dataResourceId", dataResourceId);
706: context2.put("contentAssocTypeId", "SUB_CONTENT");
707: context2.put("fromDate", result.get("fromDate"));
708: context2.put("contentIdTo", contentIdTo);
709: context2.put("mapKey", mapKey);
710:
711: //Debug.logVerbose("in replaceSubContent, context2:" + context2, module);
712: Map result2 = dispatcher.runSync("deactivateAssocs", context2);
713: */
714: } catch (GenericServiceException e) {
715: request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
716: return "error";
717: }
718: return "success";
719: }
720:
721: public static String copyToClip(HttpServletRequest request,
722: HttpServletResponse response) {
723: GenericDelegator delegator = (GenericDelegator) request
724: .getAttribute("delegator");
725: Map paramMap = UtilHttp.getParameterMap(request);
726: String entityName = (String) paramMap.get("entityName");
727:
728: if (UtilValidate.isEmpty(entityName)) {
729: request.setAttribute("_ERROR_MESSAGE_",
730: "'entityName' is empty.");
731: return "error";
732: }
733: GenericValue v = delegator.makeValue(entityName, null);
734: GenericPK passedPK = v.getPrimaryKey();
735: Collection keyColl = passedPK.getAllKeys();
736: Iterator keyIt = keyColl.iterator();
737: while (keyIt.hasNext()) {
738: String attrName = (String) keyIt.next();
739: String attrVal = (String) request.getAttribute(attrName);
740: if (attrVal == null) {
741: attrVal = (String) paramMap.get(attrName);
742: }
743: Debug.logVerbose("in copyToClip, attrName:" + attrName, "");
744: Debug.logVerbose("in copyToClip, attrVal:" + attrVal, "");
745: if (UtilValidate.isNotEmpty(attrVal)) {
746: passedPK.put(attrName, attrVal);
747: } else {
748: request.setAttribute("_ERROR_MESSAGE_", attrName
749: + " is empty.");
750: return "error";
751: }
752: }
753: ContentManagementWorker.mruAdd(request, passedPK);
754:
755: return "success";
756: }
757: }
|