svn commit: r1818388 - in /ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data: DataEvents.java DataResourceWorker.java DataServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1818388 - in /ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data: DataEvents.java DataResourceWorker.java DataServices.java

mbrohl
Author: mbrohl
Date: Sat Dec 16 11:58:56 2017
New Revision: 1818388

URL: http://svn.apache.org/viewvc?rev=1818388&view=rev
Log:
Improved: General refactoring and code improvements, package
org.apache.ofbiz.content.data.
(OFBIZ-10077)

Thanks Julian Leichert for reporting and providing the patches.

Modified:
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataEvents.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataServices.java

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataEvents.java?rev=1818388&r1=1818387&r2=1818388&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataEvents.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataEvents.java Sat Dec 16 11:58:56 2017
@@ -185,11 +185,7 @@ public class DataEvents {
         Map<String, Object> resourceData;
         try {
             resourceData = DataResourceWorker.getDataResourceStream(dataResource, https, webSiteId, locale, contextRoot, false);
-        } catch (IOException e) {
-            Debug.logError(e, "Error getting DataResource stream", module);
-            request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
-            return "error";
-        } catch (GeneralException e) {
+        } catch (IOException | GeneralException e) {
             Debug.logError(e, "Error getting DataResource stream", module);
             request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
             return "error";
@@ -287,17 +283,7 @@ public class DataEvents {
             Map<String, Object> resourceData = DataResourceWorker.getDataResourceStream(dataResource, "", application.getInitParameter("webSiteId"), UtilHttp.getLocale(request), application.getRealPath("/"), false);
             os.write(IOUtils.toByteArray((ByteArrayInputStream)resourceData.get("stream")));
             os.flush();
-        } catch (GenericEntityException e) {
-            String errMsg = "Error downloading digital product content: " + e.toString();
-            Debug.logError(e, errMsg, module);
-            request.setAttribute("_ERROR_MESSAGE_", errMsg);
-            return "error";
-        } catch (GeneralException e) {
-            String errMsg = "Error downloading digital product content: " + e.toString();
-            Debug.logError(e, errMsg, module);
-            request.setAttribute("_ERROR_MESSAGE_", errMsg);
-            return "error";
-        } catch (IOException e) {
+        } catch (GeneralException | IOException e) {
             String errMsg = "Error downloading digital product content: " + e.toString();
             Debug.logError(e, errMsg, module);
             request.setAttribute("_ERROR_MESSAGE_", errMsg);

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java?rev=1818388&r1=1818387&r2=1818388&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java Sat Dec 16 11:58:56 2017
@@ -129,16 +129,17 @@ public class DataResourceWorker  impleme
                 .where("parentCategoryId", parentCategoryId)
                 .cache().queryList();
         categoryNode.put("count", Integer.valueOf(categoryValues.size()));
-        List<Map<String, Object>> subCategoryIds = new LinkedList<Map<String,Object>>();
+        List<Map<String, Object>> subCategoryIds = new LinkedList<>();
         for (GenericValue category : categoryValues) {
             String id = (String) category.get("dataCategoryId");
             String categoryName = (String) category.get("categoryName");
-            Map<String, Object> newNode = new HashMap<String, Object>();
+            Map<String, Object> newNode = new HashMap<>();
             newNode.put("id", id);
             newNode.put("name", categoryName);
             errorMsg = getDataCategoryMap(delegator, depth + 1, newNode, categoryTypeIds, getAll);
-            if (errorMsg != null)
+            if (errorMsg != null) {
                 break;
+            }
             subCategoryIds.add(newNode);
         }
 
@@ -163,8 +164,9 @@ public class DataResourceWorker  impleme
     public static void getDataCategoryAncestry(Delegator delegator, String dataCategoryId, List<String> categoryTypeIds) throws GenericEntityException {
         categoryTypeIds.add(dataCategoryId);
         GenericValue dataCategoryValue = EntityQuery.use(delegator).from("DataCategory").where("dataCategoryId", dataCategoryId).queryOne();
-        if (dataCategoryValue == null)
+        if (dataCategoryValue == null) {
             return;
+        }
         String parentCategoryId = (String) dataCategoryValue.get("parentCategoryId");
         if (parentCategoryId != null) {
             getDataCategoryAncestry(delegator, parentCategoryId, categoryTypeIds);
@@ -179,9 +181,10 @@ public class DataResourceWorker  impleme
         String id = (String) nd.get("id");
         String nm = (String) nd.get("name");
         StringBuilder spcBuilder = new StringBuilder();
-        for (int i = 0; i < depth; i++)
+        for (int i = 0; i < depth; i++) {
             spcBuilder.append("&nbsp;&nbsp;");
-        Map<String, Object> map = new HashMap<String, Object>();
+        }
+        Map<String, Object> map = new HashMap<>();
         spcBuilder.append(nm);
         map.put("dataCategoryId", id);
         map.put("categoryName", spcBuilder.toString());
@@ -222,7 +225,7 @@ public class DataResourceWorker  impleme
         FileItem fi = null;
         FileItem imageFi = null;
         String imageFileName = null;
-        Map<String, Object> passedParams = new HashMap<String, Object>();
+        Map<String, Object> passedParams = new HashMap<>();
         HttpSession session = request.getSession();
         GenericValue userLogin = (GenericValue)session.getAttribute("userLogin");
         passedParams.put("userLogin", userLogin);
@@ -239,7 +242,9 @@ public class DataResourceWorker  impleme
                 passedParams.put(fieldName, imageBytes);
                 imageFileName = imageFi.getName();
                 passedParams.put("drObjectInfo", imageFileName);
-                if (Debug.infoOn()) Debug.logInfo("[UploadContentAndImage]imageData: " + imageBytes.length, module);
+                if (Debug.infoOn()) {
+                    Debug.logInfo("[UploadContentAndImage]imageData: " + imageBytes.length, module);
+                }
             }
         }
 
@@ -266,19 +271,22 @@ public class DataResourceWorker  impleme
 
     public static String getMimeTypeFromImageFileName(String imageFileName) {
         String mimeType = null;
-        if (UtilValidate.isEmpty(imageFileName))
-           return mimeType;
+        if (UtilValidate.isEmpty(imageFileName)) {
+            return mimeType;
+        }
 
         int pos = imageFileName.lastIndexOf('.');
-        if (pos < 0)
-           return mimeType;
+        if (pos < 0) {
+            return mimeType;
+        }
 
         String suffix = imageFileName.substring(pos + 1);
         String suffixLC = suffix.toLowerCase(Locale.getDefault());
-        if ("jpg".equals(suffixLC))
+        if ("jpg".equals(suffixLC)) {
             mimeType = "image/jpeg";
-        else
+        } else {
             mimeType = "image/" + suffixLC;
+        }
 
         return mimeType;
     }
@@ -297,14 +305,16 @@ public class DataResourceWorker  impleme
      */
     public static Map<String, Object> callDataResourcePermissionCheckResult(Delegator delegator, LocalDispatcher dispatcher, Map<String, Object> context) {
 
-        Map<String, Object> permResults = new HashMap<String, Object>();
+        Map<String, Object> permResults = new HashMap<>();
         String skipPermissionCheck = (String) context.get("skipPermissionCheck");
-            if (Debug.infoOn()) Debug.logInfo("in callDataResourcePermissionCheckResult, skipPermissionCheck:" + skipPermissionCheck,"");
+            if (Debug.infoOn()) {
+                Debug.logInfo("in callDataResourcePermissionCheckResult, skipPermissionCheck:" + skipPermissionCheck,"");
+            }
 
-        if (UtilValidate.isEmpty(skipPermissionCheck)
+        if (UtilValidate.isEmpty(skipPermissionCheck)
                 || (!"true".equalsIgnoreCase(skipPermissionCheck) && !"granted".equalsIgnoreCase(skipPermissionCheck))) {
             GenericValue userLogin = (GenericValue) context.get("userLogin");
-            Map<String, Object> serviceInMap = new HashMap<String, Object>();
+            Map<String, Object> serviceInMap = new HashMap<>();
             serviceInMap.put("userLogin", userLogin);
             serviceInMap.put("targetOperationList", context.get("targetOperationList"));
             serviceInMap.put("contentPurposeList", context.get("contentPurposeList"));
@@ -316,8 +326,9 @@ public class DataResourceWorker  impleme
             if (UtilValidate.isNotEmpty(ownerContentId)) {
                 try {
                     GenericValue content = EntityQuery.use(delegator).from("Content").where("contentId", ownerContentId).queryOne();
-                    if (content != null)
+                    if (content != null) {
                         serviceInMap.put("currentContent", content);
+                    }
                 } catch (GenericEntityException e) {
                     Debug.logError(e, "e.getMessage()", "ContentServices");
                 }
@@ -340,8 +351,9 @@ public class DataResourceWorker  impleme
 
         byte[] b = null;
         GenericValue dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", dataResourceId).cache().queryOne();
-        if (dataResource == null)
+        if (dataResource == null) {
             return b;
+        }
 
         b = acquireImage(delegator, dataResource);
         return b;
@@ -397,7 +409,7 @@ public class DataResourceWorker  impleme
     }
 
     public static String buildRequestPrefix(Delegator delegator, Locale locale, String webSiteId, String https) {
-        Map<String, Object> prefixValues = new HashMap<String, Object>();
+        Map<String, Object> prefixValues = new HashMap<>();
         String prefix;
 
         NotificationServices.setBaseUrl(delegator, webSiteId, prefixValues);
@@ -461,8 +473,9 @@ public class DataResourceWorker  impleme
     public static String getDataResourceMimeType(Delegator delegator, String dataResourceId, GenericValue view) throws GenericEntityException {
 
         String mimeType = null;
-        if (view != null)
+        if (view != null) {
             mimeType = view.getString("drMimeTypeId");
+        }
         if (UtilValidate.isEmpty(mimeType) && UtilValidate.isNotEmpty(dataResourceId)) {
                 GenericValue dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", dataResourceId).cache().queryOne();
                 mimeType = dataResource.getString("mimeTypeId");
@@ -514,6 +527,7 @@ public class DataResourceWorker  impleme
 
         // descending comparator
         Comparator<Object> desc = new Comparator<Object>() {
+            @Override
             public int compare(Object o1, Object o2) {
                 if (((Long) o1).longValue() > ((Long) o2).longValue()) {
                     return -1;
@@ -527,7 +541,7 @@ public class DataResourceWorker  impleme
         // check for the latest subdirectory
         String parentDir = ofbizHome + initialPath;
         File parent = FileUtil.getFile(parentDir);
-        TreeMap<Long, File> dirMap = new TreeMap<Long, File>(desc);
+        TreeMap<Long, File> dirMap = new TreeMap<>(desc);
         if (parent.exists()) {
             File[] subs = parent.listFiles();
             if (subs != null) {
@@ -563,16 +577,15 @@ public class DataResourceWorker  impleme
             latestDir = makeNewDirectory(parent);
         }
         String name = "";
-        if (latestDir != null)
+        if (latestDir != null) {
             name = latestDir.getName();
+        }
 
         Debug.logInfo("Directory Name : " + name, module);
         if (absolute) {
             return latestDir.getAbsolutePath().replace('\\', '/');
-        } else {
-            return initialPath + "/" + name;
-
         }
+        return initialPath + "/" + name;
     }
 
     private static File makeNewDirectory(File parent) {
@@ -630,7 +643,7 @@ public class DataResourceWorker  impleme
             throw new GeneralException("Cannot lookup data resource with for a null dataResourceId");
         }
         if (templateContext == null) {
-            templateContext = new HashMap<String, Object>();
+            templateContext = new HashMap<>();
         }
         if (UtilValidate.isEmpty(targetMimeTypeId)) {
             targetMimeTypeId = "text/html";
@@ -708,7 +721,7 @@ public class DataResourceWorker  impleme
                 File targetFileLocation = new File(System.getProperty("ofbiz.home")+"/runtime/tempfiles/docbook.css");
                 // This is related with the other FIXME above: we need to correctly propagate the theme.
                 String defaultVisualThemeId = EntityUtilProperties.getPropertyValue("general", "VISUAL_THEME", delegator);
-                visualTheme = ThemeFactory.getVisualThemeFromId(defaultVisualThemeId);  
+                visualTheme = ThemeFactory.getVisualThemeFromId(defaultVisualThemeId);
                 modelTheme = visualTheme.getModelTheme();
                 String docbookStylesheet = modelTheme.getProperty("VT_DOCBOOKSTYLESHEET").toString();
                 File sourceFileLocation = new File(System.getProperty("ofbiz.home") + "/themes" + docbookStylesheet.substring(1, docbookStylesheet.length() - 1));
@@ -732,7 +745,7 @@ public class DataResourceWorker  impleme
                     // prepare the map for preRenderedContent
                     String textData = (String) context.get("textData");
                     if (UtilValidate.isNotEmpty(textData)) {
-                        Map<String, Object> prc = new HashMap<String, Object>();
+                        Map<String, Object> prc = new HashMap<>();
                         String mapKey = (String) context.get("mapKey");
                         if (mapKey != null) {
                             prc.put(mapKey, mapKey);
@@ -821,7 +834,7 @@ public class DataResourceWorker  impleme
             Delegator delegator, Appendable out, boolean cache) throws IOException, GeneralException {
         Map<String, Object> context = UtilGenerics.checkMap(templateContext.get("context"));
         if (context == null) {
-            context = new HashMap<String, Object>();
+            context = new HashMap<>();
         }
         String webSiteId = (String) templateContext.get("webSiteId");
         if (UtilValidate.isEmpty(webSiteId)) {
@@ -932,7 +945,7 @@ public class DataResourceWorker  impleme
 
             if (mimeTypeTemplate != null && mimeTypeTemplate.get("templateLocation") != null) {
                 // prepare the context
-                Map<String, Object> mimeContext = new HashMap<String, Object>();
+                Map<String, Object> mimeContext = new HashMap<>();
                 mimeContext.putAll(context);
                 mimeContext.put("dataResource", dataResource);
                 mimeContext.put("textData", textData);
@@ -991,7 +1004,9 @@ public class DataResourceWorker  impleme
             try {
                 in = new InputStreamReader(new FileInputStream(file), UtilIO.getUtf8());
                 String enc = in.getEncoding();
-                if (Debug.infoOn()) Debug.logInfo("in serveImage, encoding:" + enc, module);
+                if (Debug.infoOn()) {
+                    Debug.logInfo("in serveImage, encoding:" + enc, module);
+                }
 
             } catch (FileNotFoundException e) {
                 Debug.logError(e, " in renderDataResourceAsHtml(CONTEXT_FILE), in FNFexception:", module);
@@ -1049,7 +1064,8 @@ public class DataResourceWorker  impleme
             return UtilMisc.toMap("stream", new ByteArrayInputStream(bytes), "length", Long.valueOf(bytes.length));
 
         // object (binary) data
-        } else if (dataResourceTypeId.endsWith("_OBJECT")) {
+        }
+        if (dataResourceTypeId.endsWith("_OBJECT")) {
             byte[] bytes = new byte[0];
             GenericValue valObj;
 
@@ -1085,9 +1101,8 @@ public class DataResourceWorker  impleme
             if (UtilValidate.isNotEmpty(objectInfo)) {
                 File file = DataResourceWorker.getContentFile(dataResourceTypeId, objectInfo, contextRoot);
                 return UtilMisc.toMap("stream", new ByteArrayInputStream(FileUtils.readFileToByteArray(file)), "length", Long.valueOf(file.length()));
-            } else {
-                throw new GeneralException("No objectInfo found for FILE type [" + dataResourceTypeId + "]; cannot stream");
             }
+            throw new GeneralException("No objectInfo found for FILE type [" + dataResourceTypeId + "]; cannot stream");
 
         // URL resource data
         } else if ("URL_RESOURCE".equals(dataResourceTypeId)) {
@@ -1105,9 +1120,8 @@ public class DataResourceWorker  impleme
 
                 URLConnection con = url.openConnection();
                 return UtilMisc.toMap("stream", con.getInputStream(), "length", Long.valueOf(con.getContentLength()));
-            } else {
-                throw new GeneralException("No objectInfo found for URL_RESOURCE type; cannot stream");
             }
+            throw new GeneralException("No objectInfo found for URL_RESOURCE type; cannot stream");
         }
 
         // unsupported type
@@ -1115,13 +1129,14 @@ public class DataResourceWorker  impleme
     }
 
     public static ByteBuffer getContentAsByteBuffer(Delegator delegator, String dataResourceId, String https, String webSiteId, Locale locale, String rootDir) throws IOException, GeneralException {
-        GenericValue dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", dataResourceId).queryOne();
+        GenericValue dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", dataResourceId).queryOne();
         Map<String, Object> resourceData = DataResourceWorker.getDataResourceStream(dataResource, https, webSiteId, locale, rootDir, false);
         ByteArrayInputStream stream = (ByteArrayInputStream) resourceData.get("stream");
         ByteBuffer byteBuffer = ByteBuffer.wrap(IOUtils.toByteArray(stream));
         return byteBuffer;
     }
 
+    @Override
     public String renderDataResourceAsTextExt(Delegator delegator, String dataResourceId, Map<String, Object> templateContext,
             Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException {
         return renderDataResourceAsText(null, delegator, dataResourceId, templateContext, locale, targetMimeTypeId, cache);

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataServices.java?rev=1818388&r1=1818387&r2=1818388&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/data/DataServices.java Sat Dec 16 11:58:56 2017
@@ -77,7 +77,7 @@ public class DataServices {
      */
     public static Map<String, Object> createDataResourceAndText(DispatchContext dctx, Map<String, ? extends Object> rcontext) {
         Map<String, Object> context = UtilMisc.makeMapWritable(rcontext);
-        Map<String, Object> result = new HashMap<String, Object>();
+        Map<String, Object> result = new HashMap<>();
 
         Map<String, Object> thisResult = createDataResourceMethod(dctx, context);
         if (thisResult.get(ModelService.RESPONSE_MESSAGE) != null) {
@@ -108,7 +108,7 @@ public class DataServices {
 
     public static Map<String, Object> createDataResourceMethod(DispatchContext dctx, Map<String, ? extends Object> rcontext) {
         Map<String, Object> context = UtilMisc.makeMapWritable(rcontext);
-        Map<String, Object> result = new HashMap<String, Object>();
+        Map<String, Object> result = new HashMap<>();
         Delegator delegator = dctx.getDelegator();
         GenericValue userLogin = (GenericValue) context.get("userLogin");
         String userLoginId = (String) userLogin.get("userLoginId");
@@ -126,7 +126,7 @@ public class DataServices {
         String dataResourceId = (String) context.get("dataResourceId");
         if (UtilValidate.isEmpty(dataResourceId)) {
             dataResourceId = delegator.getNextSeqId("DataResource");
-        }  
+        }
         if (Debug.infoOn()) {
             Debug.logInfo("in createDataResourceMethod, dataResourceId:" + dataResourceId, module);
         }
@@ -152,8 +152,6 @@ public class DataServices {
             dataResource.create();
         } catch (GenericEntityException e) {
             return ServiceUtil.returnError(e.getMessage());
-        } catch (Exception e2) {
-            return ServiceUtil.returnError(e2.getMessage());
         }
         result.put("dataResourceId", dataResourceId);
         result.put("dataResource", dataResource);
@@ -169,7 +167,7 @@ public class DataServices {
     }
 
     public static Map<String, Object> createElectronicTextMethod(DispatchContext dctx, Map<String, ? extends Object> context) {
-        Map<String, Object> result = new HashMap<String, Object>();
+        Map<String, Object> result = new HashMap<>();
         Delegator delegator = dctx.getDelegator();
         String dataResourceId = (String) context.get("dataResourceId");
         String textData = (String) context.get("textData");
@@ -301,7 +299,7 @@ public class DataServices {
     }
 
     public static Map<String, Object> updateDataResourceMethod(DispatchContext dctx, Map<String, ? extends Object> context) {
-        Map<String, Object> result = new HashMap<String, Object>();
+        Map<String, Object> result = new HashMap<>();
         Delegator delegator = dctx.getDelegator();
         GenericValue dataResource = null;
         Locale locale = (Locale) context.get("locale");
@@ -350,7 +348,7 @@ public class DataServices {
      * @return update the ElectronicText
      */
     public static Map<String, Object> updateElectronicTextMethod(DispatchContext dctx, Map<String, ? extends Object> context) {
-        Map<String, Object> result = new HashMap<String, Object>();
+        Map<String, Object> result = new HashMap<>();
         Delegator delegator = dctx.getDelegator();
         GenericValue electronicText = null;
         Locale locale = (Locale) context.get("locale");
@@ -399,7 +397,7 @@ public class DataServices {
     }
 
     public static Map<String, Object> updateFileMethod(DispatchContext dctx, Map<String, ? extends Object> context) throws GenericServiceException {
-        Map<String, Object> result = new HashMap<String, Object>();
+        Map<String, Object> result = new HashMap<>();
         Locale locale = (Locale) context.get("locale");
         String dataResourceTypeId = (String) context.get("dataResourceTypeId");
         String objectInfo = (String) context.get("objectInfo");
@@ -469,7 +467,7 @@ public class DataServices {
     }
 
     public static Map<String, Object> renderDataResourceAsText(DispatchContext dctx, Map<String, ? extends Object> context) throws GeneralException, IOException {
-        Map<String, Object> results = new HashMap<String, Object>();
+        Map<String, Object> results = new HashMap<>();
         //LocalDispatcher dispatcher = dctx.getDispatcher();
         Writer out = (Writer) context.get("outWriter");
         Map<String, Object> templateContext = UtilGenerics.checkMap(context.get("templateContext"));
@@ -486,7 +484,7 @@ public class DataServices {
         Locale locale = (Locale) context.get("locale");
 
         if (templateContext == null) {
-            templateContext = new HashMap<String, Object>();
+            templateContext = new HashMap<>();
         }
 
         Writer outWriter = new StringWriter();
@@ -510,7 +508,7 @@ public class DataServices {
     }
 
     public static Map<String, Object> updateImageMethod(DispatchContext dctx, Map<String, ? extends Object> context) {
-        Map<String, Object> result = new HashMap<String, Object>();
+        Map<String, Object> result = new HashMap<>();
         Delegator delegator = dctx.getDelegator();
         //Locale locale = (Locale) context.get("locale");
         String dataResourceId = (String) context.get("dataResourceId");
@@ -525,10 +523,9 @@ public class DataServices {
                 }
                 if (imageDataResource == null) {
                     return createImageMethod(dctx, context);
-                } else {
-                    imageDataResource.setBytes("imageData", imageBytes);
-                    imageDataResource.store();
                 }
+                imageDataResource.setBytes("imageData", imageBytes);
+                imageDataResource.store();
             } catch (GenericEntityException e) {
                 return ServiceUtil.returnError(e.getMessage());
             }
@@ -545,7 +542,7 @@ public class DataServices {
     }
 
     public static Map<String, Object> createImageMethod(DispatchContext dctx, Map<String, ? extends Object> context) {
-        Map<String, Object> result = new HashMap<String, Object>();
+        Map<String, Object> result = new HashMap<>();
         Delegator delegator = dctx.getDelegator();
         String dataResourceId = (String) context.get("dataResourceId");
         ByteBuffer byteBuffer = (ByteBuffer)context.get("imageData");
@@ -580,7 +577,7 @@ public class DataServices {
     }
 
     public static Map<String, Object> createBinaryFileMethod(DispatchContext dctx, Map<String, ? extends Object> context) throws GenericServiceException {
-        Map<String, Object> result = new HashMap<String, Object>();
+        Map<String, Object> result = new HashMap<>();
         GenericValue dataResource = (GenericValue) context.get("dataResource");
         String dataResourceTypeId = (String) dataResource.get("dataResourceTypeId");
         String objectInfo = (String) dataResource.get("objectInfo");
@@ -594,12 +591,9 @@ public class DataServices {
         }
         try {
             file = DataResourceWorker.getContentFile(dataResourceTypeId, objectInfo, rootDir);
-        } catch (FileNotFoundException e) {
+        } catch (FileNotFoundException | GeneralException e) {
             Debug.logWarning(e, module);
             throw new GenericServiceException(e.getMessage());
-        } catch (GeneralException e2) {
-            Debug.logWarning(e2, module);
-            throw new GenericServiceException(e2.getMessage());
         }
         if (Debug.infoOn()) {
             Debug.logInfo("in createBinaryFileMethod, file:" + file, module);
@@ -636,7 +630,7 @@ public class DataServices {
     }
 
     public static Map<String, Object> updateBinaryFileMethod(DispatchContext dctx, Map<String, ? extends Object> context) throws GenericServiceException {
-        Map<String, Object> result = new HashMap<String, Object>();
+        Map<String, Object> result = new HashMap<>();
         GenericValue dataResource = (GenericValue) context.get("dataResource");
         String dataResourceTypeId = (String) dataResource.get("dataResourceTypeId");
         String objectInfo = (String) dataResource.get("objectInfo");