Source Code Cross Referenced for ContentManagementServices.java in  » ERP-CRM-Financial » SourceTap-CRM » org » ofbiz » content » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » SourceTap CRM » org.ofbiz.content 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.ofbiz.content;
002:
003:        import java.sql.Timestamp;
004:        import java.util.ArrayList;
005:        import java.util.HashMap;
006:        import java.util.Iterator;
007:        import java.util.List;
008:        import java.util.Map;
009:        import java.util.Locale;
010:        import java.io.IOException;
011:        import javax.servlet.http.HttpSession;
012:        import javax.servlet.http.HttpServletRequest;
013:
014:        import org.ofbiz.base.util.Debug;
015:        import org.ofbiz.base.util.UtilDateTime;
016:        import org.ofbiz.base.util.UtilMisc;
017:        import org.ofbiz.base.util.UtilProperties;
018:        import org.ofbiz.base.util.UtilValidate;
019:        import org.ofbiz.entity.GenericDelegator;
020:        import org.ofbiz.entity.GenericEntityException;
021:        import org.ofbiz.entity.GenericValue;
022:        import org.ofbiz.entity.GenericPK;
023:        import org.ofbiz.entity.condition.EntityCondition;
024:        import org.ofbiz.entity.condition.EntityConditionList;
025:        import org.ofbiz.entity.condition.EntityExpr;
026:        import org.ofbiz.entity.condition.EntityOperator;
027:        import org.ofbiz.entity.util.ByteWrapper;
028:        import org.ofbiz.security.Security;
029:        import org.ofbiz.service.DispatchContext;
030:        import org.ofbiz.service.ServiceUtil;
031:        import org.ofbiz.service.GenericServiceException;
032:        import org.ofbiz.service.LocalDispatcher;
033:        import org.ofbiz.service.ModelService;
034:        import org.ofbiz.content.ContentManagementWorker;
035:        import org.ofbiz.content.content.ContentServices;
036:        import org.ofbiz.content.data.DataServices;
037:        import org.ofbiz.content.content.ContentWorker;
038:
039:        /**
040:         * ContentManagementServices Class
041:         *
042:         * @author     <a href="mailto:byersa@automationgroups.com">Al Byers</a>
043:         * @version    $Revision: 1.7 $
044:         * @since      3.0
045:         *
046:         * 
047:         */
048:        public class ContentManagementServices {
049:
050:            public static final String module = ContentManagementServices.class
051:                    .getName();
052:
053:            /**
054:             * getSubContent
055:             * Finds the related subContent given the template Content and the mapKey.
056:             * This service calls a same-named method in ContentWorker to do the work.
057:             */
058:            public static Map getSubContent(DispatchContext dctx, Map context) {
059:
060:                Map results = new HashMap();
061:                Security security = dctx.getSecurity();
062:                GenericDelegator delegator = dctx.getDelegator();
063:                LocalDispatcher dispatcher = dctx.getDispatcher();
064:                String contentId = (String) context.get("contentId");
065:                String subContentId = (String) context.get("subContentId");
066:                String mapKey = (String) context.get("mapKey");
067:                GenericValue userLogin = (GenericValue) context
068:                        .get("userLogin");
069:                Timestamp fromDate = (Timestamp) context.get("fromDate");
070:                List assocTypes = (List) context.get("assocTypes");
071:                GenericValue content = null;
072:                GenericValue view = null;
073:
074:                //Debug.logVerbose("in getSubContent(svc), contentId:" + contentId, "");
075:                //Debug.logVerbose("in getSubContent(svc), subContentId:" + subContentId, "");
076:                //Debug.logVerbose("in getSubContent(svc), mapKey:" + mapKey, "");
077:                try {
078:                    view = ContentWorker.getSubContent(delegator, contentId,
079:                            mapKey, subContentId, userLogin, assocTypes,
080:                            fromDate);
081:                    content = ContentWorker.getContentFromView(view);
082:                } catch (IOException e) {
083:                    return ServiceUtil.returnError(e.getMessage());
084:                }
085:                results.put("view", view);
086:                results.put("content", content);
087:
088:                return results;
089:
090:            }
091:
092:            /**
093:             * addMostRecent
094:             * A service for adding the most recently used of an entity class to the cache.
095:             * Entities make it to the most recently used list primarily by being selected for editing,
096:             * either by being created or being selected from a list.
097:             */
098:            public static Map addMostRecent(DispatchContext dctx, Map context) {
099:
100:                Map results = new HashMap();
101:                Security security = dctx.getSecurity();
102:                GenericDelegator delegator = dctx.getDelegator();
103:                LocalDispatcher dispatcher = dctx.getDispatcher();
104:                HttpServletRequest request = (HttpServletRequest) context
105:                        .get("request");
106:                Debug.logVerbose("in addMostRecentEntity(svc2), request:"
107:                        + request, "");
108:                String suffix = (String) context.get("suffix");
109:                GenericValue val = (GenericValue) context.get("pk");
110:                GenericPK pk = val.getPrimaryKey();
111:                HttpSession session = (HttpSession) context.get("session");
112:
113:                ContentManagementWorker.mruAdd(session, pk, suffix);
114:                return results;
115:
116:            }
117:
118:            /**
119:             * persistContentAndAssoc
120:             * A combination method that will create or update all or one of the following
121:             * a Content entity, a ContentAssoc related to the Content and 
122:             * the ElectronicText that may be associated with the Content.
123:             * The keys for determining if each entity is created is the presence
124:             * of the contentTypeId, contentAssocTypeId and dataResourceTypeId.
125:             */
126:            public static Map persistContentAndAssoc(DispatchContext dctx,
127:                    Map context) throws GenericServiceException {
128:
129:                //Debug.logVerbose("CREATING CONTENTANDASSOC:" + context, null);
130:                HashMap result = new HashMap();
131:                Security security = dctx.getSecurity();
132:                GenericDelegator delegator = dctx.getDelegator();
133:                LocalDispatcher dispatcher = dctx.getDispatcher();
134:                Map permContext = new HashMap();
135:
136:                GenericValue content = delegator.makeValue("Content", null);
137:                content.setPKFields(context);
138:                content.setNonPKFields(context);
139:                String contentId = (String) content.get("contentId");
140:                String contentTypeId = (String) content.get("contentTypeId");
141:                String origDataResourceId = (String) content
142:                        .get("dataResourceId");
143:
144:                GenericValue dataResource = delegator.makeValue("DataResource",
145:                        null);
146:                dataResource.setPKFields(context);
147:                dataResource.setNonPKFields(context);
148:                String dataResourceId = (String) dataResource
149:                        .get("dataResourceId");
150:                String dataResourceTypeId = (String) dataResource
151:                        .get("dataResourceTypeId");
152:
153:                GenericValue electronicText = delegator.makeValue(
154:                        "ElectronicText", null);
155:                electronicText.setPKFields(context);
156:                electronicText.setNonPKFields(context);
157:                String textData = (String) electronicText.get("textData");
158:
159:                ByteWrapper byteWrapper = (ByteWrapper) context
160:                        .get("imageData");
161:
162:                // get user info for multiple use
163:                GenericValue userLogin = (GenericValue) context
164:                        .get("userLogin");
165:                String userLoginId = (String) userLogin.get("userLoginId");
166:                String createdByUserLogin = userLoginId;
167:                String lastModifiedByUserLogin = userLoginId;
168:                Timestamp createdDate = UtilDateTime.nowTimestamp();
169:                Timestamp lastModifiedDate = UtilDateTime.nowTimestamp();
170:
171:                // Do update and create permission checks on DataResource if warranted.
172:                boolean updatePermOK = false;
173:                boolean createPermOK = false;
174:                if (UtilValidate.isNotEmpty(dataResourceTypeId)
175:                        || UtilValidate.isNotEmpty(textData)) {
176:                    List targetOperations = new ArrayList();
177:                    if (UtilValidate.isNotEmpty(dataResourceId)) {
178:                        permContext.put("entityOperation", "_UPDATE");
179:                        targetOperations.add("UPDATE_CONTENT");
180:                        updatePermOK = true;
181:                    } else {
182:                        permContext.put("entityOperation", "_CREATE");
183:                        targetOperations.add("CREATE_CONTENT");
184:                        createPermOK = true;
185:                    }
186:                    permContext.put("targetOperationList", targetOperations);
187:                    permContext.put("contentPurposeList", context
188:                            .get("contentPurposeList"));
189:                    permContext.put("userLogin", userLogin);
190:                    String permissionStatus = ContentWorker
191:                            .callContentPermissionCheck(delegator, dispatcher,
192:                                    permContext);
193:
194:                    Debug.logVerbose("permissionStatus(update):"
195:                            + permissionStatus, null);
196:                    if (permissionStatus == null
197:                            || !permissionStatus.equals("granted")) {
198:                        return ServiceUtil
199:                                .returnError("Permission not granted");
200:                    }
201:                    context.put("skipPermissionCheck", "granted");
202:                }
203:
204:                boolean dataResourceExists = true;
205:                if (UtilValidate.isNotEmpty(dataResourceTypeId)) {
206:                    if (UtilValidate.isEmpty(dataResourceId)) {
207:                        dataResourceExists = false;
208:                        Map this Result = DataServices.createDataResourceMethod(
209:                                dctx, context);
210:                        dataResourceId = (String) this Result
211:                                .get("dataResourceId");
212:                        dataResource = (GenericValue) this Result
213:                                .get("dataResource");
214:                        if (dataResourceTypeId.indexOf("_FILE") >= 0) {
215:                            dataResource = (GenericValue) this Result
216:                                    .get("dataResource");
217:                            context.put("dataResource", dataResource);
218:                            try {
219:                                this Result = DataServices.createFileMethod(
220:                                        dctx, context);
221:                            } catch (GenericServiceException e) {
222:                                Debug.logVerbose("in persistContentAndAssoc. "
223:                                        + e.getMessage(), "");
224:                                return ServiceUtil.returnError(e.getMessage());
225:                            }
226:                        } else if (dataResourceTypeId.equals("IMAGE_OBJECT")) {
227:                            if (byteWrapper != null) {
228:                                context.put("dataResourceId", dataResourceId);
229:                                this Result = DataServices.createImageMethod(
230:                                        dctx, context);
231:                            } else {
232:                                return ServiceUtil
233:                                        .returnError("'byteWrapper' empty when trying to create database image.");
234:                            }
235:                        } else {
236:                            if (UtilValidate.isNotEmpty(textData)) {
237:                                context.put("dataResourceId", dataResourceId);
238:                                this Result = DataServices
239:                                        .createElectronicTextMethod(dctx,
240:                                                context);
241:                            } else {
242:                                return ServiceUtil
243:                                        .returnError("'textData' empty when trying to create database text.");
244:                            }
245:                        }
246:                        //Debug.logVerbose("dataResourceId(create):" + dataResourceId, null);
247:                    } else {
248:                        Map this Result = DataServices.updateDataResourceMethod(
249:                                dctx, context);
250:                        if (dataResourceTypeId.indexOf("_FILE") >= 0) {
251:                            dataResource = (GenericValue) this Result
252:                                    .get("dataResource");
253:                            context.put("dataResource", dataResource);
254:                            try {
255:                                this Result = DataServices.updateFileMethod(
256:                                        dctx, context);
257:                            } catch (GenericServiceException e) {
258:                                return ServiceUtil.returnError(e.getMessage());
259:                            }
260:                        } else if (dataResourceTypeId.equals("IMAGE_OBJECT")) {
261:                            this Result = DataServices.updateImageMethod(dctx,
262:                                    context);
263:                        } else {
264:                            this Result = DataServices
265:                                    .updateElectronicTextMethod(dctx, context);
266:                        }
267:                    }
268:                    result.put("dataResourceId", dataResourceId);
269:                    context.put("dataResourceId", dataResourceId);
270:                }
271:
272:                // Do update and create permission checks on Content if warranted.
273:                if (UtilValidate.isNotEmpty(contentTypeId)) {
274:                    String permissionStatus = "granted";
275:                    List targetOperations = new ArrayList();
276:                    permContext.put("targetOperationList", targetOperations);
277:                    permContext.put("contentPurposeList", context
278:                            .get("contentPurposeList"));
279:                    permContext.put("userLogin", userLogin);
280:                    if (UtilValidate.isNotEmpty(dataResourceId)) {
281:                        permContext.put("entityOperation", "_UPDATE");
282:                        targetOperations.add("UPDATE_CONTENT");
283:                        if (!updatePermOK) {
284:                            permissionStatus = ContentWorker
285:                                    .callContentPermissionCheck(delegator,
286:                                            dispatcher, permContext);
287:                            updatePermOK = true;
288:                        }
289:                    } else {
290:                        permContext.put("entityOperation", "_CREATE");
291:                        targetOperations.add("CREATE_CONTENT");
292:                        if (!createPermOK) {
293:                            permissionStatus = ContentWorker
294:                                    .callContentPermissionCheck(delegator,
295:                                            dispatcher, permContext);
296:                            createPermOK = true;
297:                        }
298:                    }
299:
300:                    Debug.logVerbose("permissionStatus(update):"
301:                            + permissionStatus, null);
302:                    if (permissionStatus == null
303:                            || !permissionStatus.equals("granted")) {
304:                        return ServiceUtil
305:                                .returnError("Permission not granted");
306:                    }
307:                    context.put("skipPermissionCheck", "granted");
308:                }
309:
310:                boolean contentExists = true;
311:                if (UtilValidate.isNotEmpty(contentTypeId)) {
312:                    if (UtilValidate.isEmpty(contentId))
313:                        contentExists = false;
314:                    else {
315:                        try {
316:                            GenericValue val = delegator.findByPrimaryKey(
317:                                    "Content", UtilMisc.toMap("contentId",
318:                                            contentId));
319:                            if (val == null)
320:                                contentExists = false;
321:                        } catch (GenericEntityException e) {
322:                            return ServiceUtil.returnError(e.getMessage());
323:                        }
324:                    }
325:                    if (contentExists) {
326:                        Map this Result = ContentServices.updateContentMethod(
327:                                dctx, context);
328:                    } else {
329:                        Map this Result = ContentServices.createContentMethod(
330:                                dctx, context);
331:                        contentId = (String) this Result.get("contentId");
332:                    }
333:                    result.put("contentId", contentId);
334:                    context.put("contentId", contentId);
335:
336:                    List contentPurposeList = (List) context
337:                            .get("contentPurposeList");
338:                    // Add ContentPurposes if this is a create operation
339:                    if (contentId != null && !contentExists) {
340:                        try {
341:                            if (contentPurposeList != null) {
342:                                for (int i = 0; i < contentPurposeList.size(); i++) {
343:                                    String contentPurposeTypeId = (String) contentPurposeList
344:                                            .get(i);
345:                                    GenericValue contentPurpose = delegator
346:                                            .makeValue(
347:                                                    "ContentPurpose",
348:                                                    UtilMisc
349:                                                            .toMap(
350:                                                                    "contentId",
351:                                                                    contentId,
352:                                                                    "contentPurposeTypeId",
353:                                                                    contentPurposeTypeId));
354:                                    contentPurpose.create();
355:                                }
356:                            }
357:                        } catch (GenericEntityException e) {
358:                            return ServiceUtil.returnError(e.getMessage());
359:                        }
360:                    }
361:
362:                }
363:
364:                // If parentContentIdTo or parentContentIdFrom exists, create association with newly created content
365:                String contentAssocTypeId = (String) context
366:                        .get("contentAssocTypeId");
367:                Debug.logVerbose("CREATING contentASSOC contentAssocTypeId:"
368:                        + contentAssocTypeId, null);
369:                if (contentAssocTypeId != null
370:                        && contentAssocTypeId.length() > 0) {
371:                    Debug.logVerbose(
372:                            "CREATING contentASSOC context:" + context, null);
373:                    Map this Result = null;
374:                    try {
375:                        this Result = ContentServices.createContentAssocMethod(
376:                                dctx, context);
377:                    } catch (GenericEntityException e) {
378:                        throw new GenericServiceException(e.getMessage());
379:                    } catch (Exception e2) {
380:                        throw new GenericServiceException(e2.getMessage());
381:                    }
382:                    result.put("contentIdTo", this Result.get("contentIdTo"));
383:                    result
384:                            .put("contentIdFrom", this Result
385:                                    .get("contentIdFrom"));
386:                    result.put("contentAssocTypeId", this Result
387:                            .get("contentAssocTypeId"));
388:                    result.put("fromDate", this Result.get("fromDate"));
389:                }
390:                //Debug.logVerbose("return from CREATING CONTENTASSOC result:" +  result, null);
391:                context.remove("skipPermissionCheck");
392:                context.remove("contentId");
393:                context.remove("dataResourceId");
394:                context.remove("dataResource");
395:                return result;
396:            }
397:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.