Author: deepak
Date: Sat May 12 09:04:46 2018 New Revision: 1831457 URL: http://svn.apache.org/viewvc?rev=1831457&view=rev Log: Improved: Remove unused code from ContentServices class file (OFBIZ-10397) While working on OFBIZ-10393, found that we have some unused code in ContentServices class file We can remove following method from ContentServices createContentAssoc createContentAssocMethod updateContent updateContentMethod updateContentAssoc updateContentAssocMethod We have already converted some of these services to entity-auto, so all these can be removed directly. Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentServices.java Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentServices.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentServices.java?rev=1831457&r1=1831456&r2=1831457&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentServices.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentServices.java Sat May 12 09:04:46 2018 @@ -225,360 +225,6 @@ public class ContentServices { } /** - * Create a ContentAssoc service. The work is done in a separate method so that complex services that need this functionality do not need to incur the - * reflection performance penalty. - */ - public static Map<String, Object> createContentAssoc(DispatchContext dctx, Map<String, ? extends Object> rcontext) { - Map<String, Object> context = UtilMisc.makeMapWritable(rcontext); - context.put("entityOperation", "_CREATE"); - List<String> targetOperationList = ContentWorker.prepTargetOperationList(context, "_CREATE"); - - List<String> contentPurposeList = ContentWorker.prepContentPurposeList(context); - context.put("targetOperationList", targetOperationList); - context.put("contentPurposeList", contentPurposeList); - context.put("skipPermissionCheck", null); - - Map<String, Object> result = null; - try { - result = createContentAssocMethod(dctx, context); - } catch (GenericServiceException e) { - return ServiceUtil.returnError(e.getMessage()); - } catch (GenericEntityException e2) { - return ServiceUtil.returnError(e2.getMessage()); - } catch (Exception e3) { - return ServiceUtil.returnError(e3.getMessage()); - } - return result; - } - - /** - * Create a ContentAssoc method. The work is done in this separate method so that complex services that need this functionality do not need to incur the - * reflection performance penalty. - */ - public static Map<String, Object> createContentAssocMethod(DispatchContext dctx, Map<String, ? extends Object> rcontext) throws GenericServiceException, GenericEntityException { - Map<String, Object> context = UtilMisc.makeMapWritable(rcontext); - List<String> targetOperationList = ContentWorker.prepTargetOperationList(context, "_CREATE"); - List<String> contentPurposeList = ContentWorker.prepContentPurposeList(context); - context.put("targetOperationList", targetOperationList); - context.put("contentPurposeList", contentPurposeList); - Locale locale = (Locale) context.get("locale"); - - Delegator delegator = dctx.getDelegator(); - LocalDispatcher dispatcher = dctx.getDispatcher(); - Map<String, Object> result = new HashMap<String, Object>(); - - // This section guesses how contentId should be used (From or To) if - // only a contentIdFrom o contentIdTo is passed in - String contentIdFrom = (String) context.get("contentIdFrom"); - String contentIdTo = (String) context.get("contentIdTo"); - String contentId = (String) context.get("contentId"); - int contentIdCount = 0; - if (UtilValidate.isNotEmpty(contentIdFrom)) - contentIdCount++; - if (UtilValidate.isNotEmpty(contentIdTo)) - contentIdCount++; - if (UtilValidate.isNotEmpty(contentId)) - contentIdCount++; - if (contentIdCount < 2) { - Debug.logError("Not 2 out of ContentId/To/From.", "ContentServices"); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentCreateContentAssocMethodError", locale)); - } - - if (UtilValidate.isNotEmpty(contentIdFrom)) { - if (UtilValidate.isEmpty(contentIdTo)) - contentIdTo = contentId; - } - if (UtilValidate.isNotEmpty(contentIdTo)) { - if (UtilValidate.isEmpty(contentIdFrom)) - contentIdFrom = contentId; - } - - GenericValue contentAssoc = delegator.makeValue("ContentAssoc"); - contentAssoc.put("contentId", contentIdFrom); - contentAssoc.put("contentIdTo", contentIdTo); - contentAssoc.put("contentAssocTypeId", context.get("contentAssocTypeId")); - contentAssoc.put("contentAssocPredicateId", context.get("contentAssocPredicateIdFrom")); - contentAssoc.put("dataSourceId", context.get("dataSourceId")); - - Timestamp fromDate = (Timestamp) context.get("fromDate"); - if (fromDate == null) { - contentAssoc.put("fromDate", UtilDateTime.nowTimestamp()); - } else { - contentAssoc.put("fromDate", fromDate); - } - - Timestamp thruDate = (Timestamp) context.get("thruDate"); - if (thruDate == null) { - contentAssoc.put("thruDate", null); - } else { - contentAssoc.put("thruDate", thruDate); - } - - contentAssoc.put("sequenceNum", context.get("sequenceNum")); - contentAssoc.put("mapKey", context.get("mapKey")); - - String upperCoordinateStr = (String) context.get("upperCoordinate"); - if (UtilValidate.isEmpty(upperCoordinateStr)) { - contentAssoc.put("upperCoordinate", null); - } else { - contentAssoc.put("upperCoordinate", upperCoordinateStr); - } - - String leftCoordinateStr = (String) context.get("leftCoordinate"); - if (UtilValidate.isEmpty(leftCoordinateStr)) { - contentAssoc.put("leftCoordinate", null); - } else { - contentAssoc.put("leftCoordinate", leftCoordinateStr); - } - - GenericValue userLogin = (GenericValue) context.get("userLogin"); - String userLoginId = (String) userLogin.get("userLoginId"); - String createdByUserLogin = userLoginId; - String lastModifiedByUserLogin = userLoginId; - - Timestamp createdDate = UtilDateTime.nowTimestamp(); - Timestamp lastModifiedDate = UtilDateTime.nowTimestamp(); - - contentAssoc.put("createdByUserLogin", createdByUserLogin); - contentAssoc.put("lastModifiedByUserLogin", lastModifiedByUserLogin); - contentAssoc.put("createdDate", createdDate); - contentAssoc.put("lastModifiedDate", lastModifiedDate); - - Map<String, Object> serviceInMap = new HashMap<String, Object>(); - String permissionStatus = null; - serviceInMap.put("userLogin", context.get("userLogin")); - serviceInMap.put("targetOperationList", targetOperationList); - serviceInMap.put("contentPurposeList", contentPurposeList); - serviceInMap.put("entityOperation", context.get("entityOperation")); - serviceInMap.put("contentAssocPredicateId", context.get("contentAssocPredicateId")); - serviceInMap.put("contentIdTo", contentIdTo); - serviceInMap.put("contentIdFrom", contentIdFrom); - serviceInMap.put("statusId", context.get("statusId")); - serviceInMap.put("privilegeEnumId", context.get("privilegeEnumId")); - serviceInMap.put("roleTypeList", context.get("roleTypeList")); - serviceInMap.put("displayFailCond", context.get("displayFailCond")); - - Map<String, Object> permResults = null; - permResults = dispatcher.runSync("checkAssocPermission", serviceInMap); - if (ServiceUtil.isError(permResults)) { - return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(permResults)); - } - permissionStatus = (String) permResults.get("permissionStatus"); - - if (permissionStatus != null && "granted".equals(permissionStatus)) { - contentAssoc.create(); - } - - result.put("contentIdTo", contentIdTo); - result.put("contentIdFrom", contentIdFrom); - result.put("fromDate", contentAssoc.get("fromDate")); - result.put("contentAssocTypeId", contentAssoc.get("contentAssocTypeId")); - - return result; - } - - /** - * A service wrapper for the updateContentMethod method. Forces permissions to be checked. - */ - public static Map<String, Object> updateContent(DispatchContext dctx, Map<String, ? extends Object> rcontext) { - Map<String, Object> context = UtilMisc.makeMapWritable(rcontext); - context.put("entityOperation", "_UPDATE"); - List<String> targetOperationList = ContentWorker.prepTargetOperationList(context, "_UPDATE"); - - List<String> contentPurposeList = ContentWorker.prepContentPurposeList(context); - context.put("targetOperationList", targetOperationList); - context.put("contentPurposeList", contentPurposeList); - context.put("skipPermissionCheck", null); - - Map<String, Object> result = updateContentMethod(dctx, context); - return result; - } - - /** - * Update a Content method. The work is done in this separate method so that complex services that need this functionality do not need to incur the - * reflection performance penalty of calling a service. - * DEJ20060610: why is this being done? It's a bad design because the service call overhead is not very big, but not calling through the service engine breaks functionality possibilities like ECAs and such - */ - public static Map<String, Object> updateContentMethod(DispatchContext dctx, Map<String, ? extends Object> rcontext) { - Map<String, Object> context = UtilMisc.makeMapWritable(rcontext); - Delegator delegator = dctx.getDelegator(); - LocalDispatcher dispatcher = dctx.getDispatcher(); - Map<String, Object> result = new HashMap<String, Object>(); - - context.put("entityOperation", "_UPDATE"); - List<String> targetOperationList = ContentWorker.prepTargetOperationList(context, "_UPDATE"); - - List<String> contentPurposeList = ContentWorker.prepContentPurposeList(context); - context.put("targetOperationList", targetOperationList); - context.put("contentPurposeList", contentPurposeList); - - GenericValue content = null; - Locale locale = (Locale) context.get("locale"); - String contentId = (String) context.get("contentId"); - try { - content = EntityQuery.use(delegator).from("Content").where("contentId", contentId).queryOne(); - } catch (GenericEntityException e) { - Debug.logWarning(e, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentNoContentFound", UtilMisc.toMap("contentId", contentId), locale)); - } - context.put("currentContent", content); - - Map<String, Object> permResults = ContentWorker.callContentPermissionCheckResult(delegator, dispatcher, context); - String permissionStatus = (String) permResults.get("permissionStatus"); - if (permissionStatus != null && "granted".equalsIgnoreCase(permissionStatus)) { - GenericValue userLogin = (GenericValue) context.get("userLogin"); - String userLoginId = (String) userLogin.get("userLoginId"); - String lastModifiedByUserLogin = userLoginId; - Timestamp lastModifiedDate = UtilDateTime.nowTimestamp(); - - // update status first to see if allowed - if (UtilValidate.isNotEmpty(context.get("statusId"))) { - Map<String, Object> statusInMap = UtilMisc.<String, Object>toMap("contentId", context.get("contentId"), "statusId", context.get("statusId"), "userLogin", userLogin); - try { - result = dispatcher.runSync("setContentStatus", statusInMap); - if (ServiceUtil.isError(result)) { - return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); - } - } catch (GenericServiceException e) { - Debug.logError(e, "Problem updating content Status", "ContentServices"); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentStatusUpdateError", UtilMisc.toMap("errorString", e), locale)); - } - } - - content.setNonPKFields(context); - content.put("lastModifiedByUserLogin", lastModifiedByUserLogin); - content.put("lastModifiedDate", lastModifiedDate); - try { - content.store(); - } catch (GenericEntityException e) { - return ServiceUtil.returnError(e.getMessage()); - } - } else { - String errorMsg = ContentWorker.prepPermissionErrorMsg(permResults); - return ServiceUtil.returnError(errorMsg); - } - - return result; - } - - /** - * Update a ContentAssoc service. The work is done in a separate method so that complex services that need this functionality do not need to incur the - * reflection performance penalty. - */ - public static Map<String, Object> updateContentAssoc(DispatchContext dctx, Map<String, ? extends Object> rcontext) { - Map<String, Object> context = UtilMisc.makeMapWritable(rcontext); - context.put("entityOperation", "_UPDATE"); - List<String> targetOperationList = ContentWorker.prepTargetOperationList(context, "_UPDATE"); - - List<String> contentPurposeList = ContentWorker.prepContentPurposeList(context); - context.put("targetOperationList", targetOperationList); - context.put("contentPurposeList", contentPurposeList); - context.put("skipPermissionCheck", null); - - Map<String, Object> result = updateContentAssocMethod(dctx, context); - return result; - } - - /** - * Update a ContentAssoc method. The work is done in this separate method so that complex services that need this functionality do not need to incur the - * reflection performance penalty. - */ - public static Map<String, Object> updateContentAssocMethod(DispatchContext dctx, Map<String, ? extends Object> rcontext) { - Map<String, Object> context = UtilMisc.makeMapWritable(rcontext); - Delegator delegator = dctx.getDelegator(); - LocalDispatcher dispatcher = dctx.getDispatcher(); - Locale locale = (Locale) context.get("locale"); - Map<String, Object> result = new HashMap<String, Object>(); - - context.put("entityOperation", "_UPDATE"); - List<String> targetOperationList = ContentWorker.prepTargetOperationList(context, "_UPDATE"); - - List<String> contentPurposeList = ContentWorker.prepContentPurposeList(context); - context.put("targetOperationList", targetOperationList); - context.put("contentPurposeList", contentPurposeList); - - // This section guesses how contentId should be used (From or To) if - // only a contentIdFrom o contentIdTo is passed in - String contentIdFrom = (String) context.get("contentId"); - String contentIdTo = (String) context.get("contentIdTo"); - String contentId = (String) context.get("contentId"); - String contentAssocTypeId = (String) context.get("contentAssocTypeId"); - Timestamp fromDate = (Timestamp) context.get("fromDate"); - - GenericValue contentAssoc = null; - try { - contentAssoc = EntityQuery.use(delegator).from("ContentAssoc").where("contentId", contentId, "contentIdTo", contentIdTo, "contentAssocTypeId", contentAssocTypeId, "fromDate", fromDate).queryOne(); - } catch (GenericEntityException e) { - Debug.logError(e, "Entity Error:" + e.getMessage(), module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentAssocRetrievingError", UtilMisc.toMap("errorString", e.getMessage()), locale)); - } - if (contentAssoc == null) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentAssocUpdateError", locale)); - } - - contentAssoc.put("contentAssocPredicateId", context.get("contentAssocPredicateId")); - contentAssoc.put("dataSourceId", context.get("dataSourceId")); - contentAssoc.set("thruDate", context.get("thruDate")); - contentAssoc.set("sequenceNum", context.get("sequenceNum")); - contentAssoc.put("mapKey", context.get("mapKey")); - - String upperCoordinateStr = (String) context.get("upperCoordinate"); - if (UtilValidate.isEmpty(upperCoordinateStr)) { - contentAssoc.put("upperCoordinate", null); - } else { - contentAssoc.setString("upperCoordinate", upperCoordinateStr); - } - - String leftCoordinateStr = (String) context.get("leftCoordinate"); - if (UtilValidate.isEmpty(leftCoordinateStr)) { - contentAssoc.put("leftCoordinate", null); - } else { - contentAssoc.setString("leftCoordinate", leftCoordinateStr); - } - - GenericValue userLogin = (GenericValue) context.get("userLogin"); - String userLoginId = (String) userLogin.get("userLoginId"); - String lastModifiedByUserLogin = userLoginId; - Timestamp lastModifiedDate = UtilDateTime.nowTimestamp(); - contentAssoc.put("lastModifiedByUserLogin", lastModifiedByUserLogin); - contentAssoc.put("lastModifiedDate", lastModifiedDate); - - String permissionStatus = null; - Map<String, Object> serviceInMap = new HashMap<String, Object>(); - serviceInMap.put("userLogin", context.get("userLogin")); - serviceInMap.put("targetOperationList", targetOperationList); - serviceInMap.put("contentPurposeList", contentPurposeList); - serviceInMap.put("entityOperation", context.get("entityOperation")); - serviceInMap.put("contentIdTo", contentIdTo); - serviceInMap.put("contentIdFrom", contentIdFrom); - - Map<String, Object> permResults = null; - try { - permResults = dispatcher.runSync("checkAssocPermission", serviceInMap); - if (ServiceUtil.isError(permResults)) { - return ServiceUtil.returnError(ServiceUtil.getErrorMessage(permResults)); - } - } catch (GenericServiceException e) { - Debug.logError(e, "Problem checking permissions", "ContentServices"); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPermissionNotGranted", locale)); - } - permissionStatus = (String) permResults.get("permissionStatus"); - - if (permissionStatus != null && "granted".equals(permissionStatus)) { - try { - contentAssoc.store(); - } catch (GenericEntityException e) { - return ServiceUtil.returnError(e.getMessage()); - } - } else { - String errorMsg = ContentWorker.prepPermissionErrorMsg(permResults); - return ServiceUtil.returnError(errorMsg); - } - - return result; - } - - /** * Update a ContentAssoc service. The work is done in a separate method so that complex services that need this functionality do not need to incur the * reflection performance penalty. */ |
Free forum by Nabble | Edit this page |