Author: mthl
Date: Thu Jun 27 19:38:44 2019
New Revision: 1862249
URL: http://svn.apache.org/viewvc?rev=1862249&view=rev
Log:
Improved: Remove dead code
(OFBIZ-10966)
Modified:
ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityJsonReader.java
ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonEvents.java
ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonHelper.java
Modified:
ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityJsonReader.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityJsonReader.java?rev=1862249&r1=1862248&r2=1862249&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityJsonReader.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityJsonReader.java
Thu Jun 27 19:38:44 2019
@@ -13,7 +13,6 @@ import java.util.Map;
import org.apache.ofbiz.base.lang.JSON;
import org.apache.ofbiz.base.util.Base64;
import org.apache.ofbiz.base.util.Debug;
-import org.apache.ofbiz.base.util.UtilMisc;
import org.apache.ofbiz.base.util.UtilValidate;
import org.apache.ofbiz.entity.Delegator;
import org.apache.ofbiz.entity.GenericEntityException;
@@ -41,9 +40,7 @@ public class EntityJsonReader {
private long numberSkipped = 0;
private int valuesPerWrite = 100;
- private int valuesPerMessage = 1000;
private int transactionTimeout = 7200;
- private boolean useTryInsertMethod = false;
private boolean maintainTxStamps = false;
private boolean createDummyFks = false;
private boolean checkDataOnly = false;
@@ -55,9 +52,6 @@ public class EntityJsonReader {
private List<GenericValue> valuesToDelete = new
ArrayList<>(valuesPerWrite);
private List<GenericValue> valuesToUpdate = new
ArrayList<>(valuesPerWrite);
- /**TODO need to evaluate how placeholders are going to be used in json
data*/
- private Map<String, Object> placeholderValues = null; //contains map of
values for corresponding placeholders (eg. ${key}) in the entity xml data file.
-
protected EntityJsonReader() {
}
@@ -75,7 +69,6 @@ public class EntityJsonReader {
}
public void setUseTryInsertMethod(boolean value) {
- this.useTryInsertMethod = value;
}
public void setTransactionTimeout(int transactionTimeout) throws
GenericTransactionException {
@@ -103,7 +96,7 @@ public class EntityJsonReader {
}
public void setPlaceholderValues(Map<String, Object> placeholderValues) {
- this.placeholderValues = placeholderValues;
+ /**TODO need to evaluate how placeholders are going to be used in json
data*/
}
public List<Object> getMessageList() {
@@ -120,7 +113,7 @@ public class EntityJsonReader {
this.ecaHandler = this.delegator.getEntityEcaHandler();
}
- this.delegator.setEntityEcaHandler((EntityEcaHandler) null);
+ this.delegator.setEntityEcaHandler(null);
} else if (this.ecaHandler != null) {
this.delegator.setEntityEcaHandler(this.ecaHandler);
}
@@ -156,13 +149,11 @@ public class EntityJsonReader {
private long convertJsonAndWriteValues(String jsonString) throws
IOException {
this.numberRead = 0L;
- String _prefix = "";
JSONArray jsonArray = new JSONArray(jsonString);
int length = jsonArray.length();
for (int jsonIndex = 0; jsonIndex < length; ++jsonIndex) {
JSONObject jsonObject = jsonArray.getJSONObject(jsonIndex);
- Map<String, Map<String, Object>> flatJson = new HashMap<String,
Map<String, Object>>();
Iterator iterator = jsonObject.keySet().iterator();
while (iterator.hasNext()) {
@@ -235,52 +226,6 @@ public class EntityJsonReader {
return mapObj;
}
- private long create(JSONObject jsonObject) throws IOException {
- Iterator iterator = jsonObject.keySet().iterator();
- while (iterator.hasNext()) {
- String key = iterator.next().toString();
- Object value = jsonObject.get(key);
- if (UtilValidate.isNotEmpty(value)) {
- List<Map<String, Object>> genericMapList =
iterateJsonEntityData(value);
- for (Map<String, Object> keyValPair : genericMapList) {
- try {
- ModelEntity modelEntity =
this.delegator.getModelEntity(key);
- GenericValue currentValue = delegator.makeValue(key,
keyValPair);
- if (this.maintainTxStamps) {
- currentValue.setIsFromEntitySync(true);
- }
- GenericHelper helper =
delegator.getEntityHelper(currentValue.getEntityName());
- if (UtilValidate.isNotEmpty(currentValue)) {
- boolean exist = true;
- if (currentValue.containsPrimaryKey()) {
- try {
-
helper.findByPrimaryKey(currentValue.getPrimaryKey());
- } catch (GenericEntityNotFoundException e) {
- exist = false;
- }
- }
- if (!exist) {
- if (this.useTryInsertMethod &&
!this.checkDataOnly) {
- currentValue.create();
- } else {
- this.valuesToCreate.add(currentValue);
- }
- this.numberCreated++;
- }//if pk exist ignore it.
- }
- } catch (Exception e) {
- if (continueOnFail) {
- Debug.logError(e, module);
- } else {
- throw new IOException(e);
- }
- }
- }
- }
- }
- return this.numberCreated;
- }
-
private long createUpdate(JSONObject jsonObject) throws IOException {
Iterator iterator = jsonObject.keySet().iterator();
while (iterator.hasNext()) {
@@ -366,158 +311,6 @@ public class EntityJsonReader {
return this.numberUpdated;
}
- private long createReplace(JSONObject jsonObject) throws IOException {
- Iterator iterator = jsonObject.keySet().iterator();
- while (iterator.hasNext()) {
- String key = iterator.next().toString();
- Object value = jsonObject.get(key);
- if (UtilValidate.isNotEmpty(value)) {
- List<Map<String, Object>> genericMapList =
iterateJsonEntityData(value);
- for (Map<String, Object> keyValPair : genericMapList) {
- try {
- GenericValue currentValue =
this.delegator.makeValue(key);
- if (this.maintainTxStamps) {
- currentValue.setIsFromEntitySync(true);
- }
- ModelEntity modelEntity =
currentValue.getModelEntity();
- List<String> pkFields = modelEntity.getPkFieldNames();
- if (currentValue != null) {
- for (String pkField : pkFields) {
- ModelField modelField =
modelEntity.getField(pkField);
- Object pkFieldValue = keyValPair.get(pkField);
- String type = modelField.getType();
- if (type != null && "blob".equals(type)) {
- byte[] binData =
Base64.base64Decode((pkFieldValue.toString()).getBytes());
- currentValue.setBytes(pkField, binData);
- } else {
- currentValue.setString(pkField,
pkFieldValue.toString());
- }
- }
-
- GenericHelper helper =
delegator.getEntityHelper(currentValue.getEntityName());
-
- boolean exist = true;
- if (currentValue.containsPrimaryKey()) {
- try {
-
helper.findByPrimaryKey(currentValue.getPrimaryKey());
- } catch (GenericEntityNotFoundException e) {
- exist = false;
- }
- } else {
- if (modelEntity.getPksSize() == 1) {
- ModelField modelField =
currentValue.getModelEntity().getOnlyPk();
- String newSeq =
delegator.getNextSeqId(currentValue.getEntityName());
-
currentValue.setString(modelField.getName(), newSeq);
- } else {
- throw new IOException("Cannot store value
with incomplete primary key with more than 1 primary key field: " +
currentValue);
- }
- }
-
- ModelEntity currentEntity =
currentValue.getModelEntity();
- List<String> absentFields =
currentEntity.getNoPkFieldNames();
-
absentFields.removeAll(currentEntity.getAutomaticFieldNames());
-
- for (Map.Entry<String, Object> entry :
keyValPair.entrySet()) {
- String currentFieldName = entry.getKey();
- Object currentFieldValue = entry.getValue();
- if (UtilValidate.isNotEmpty(currentFieldName)
&& !pkFields.contains(currentFieldName)) {
- if (modelEntity.isField(currentFieldName))
{
- if
(UtilValidate.isNotEmpty(currentFieldValue)) {
- ModelField modelField =
modelEntity.getField(currentFieldName);
- String type = modelField.getType();
- if (type != null &&
"blob".equals(type)) {
- byte[] binData =
Base64.base64Decode(((String) currentFieldValue).getBytes());
-
currentValue.setBytes(currentFieldName, binData);
- } else {
-
currentValue.setString(currentFieldName, currentFieldValue.toString());
- }
-
absentFields.remove(currentFieldName);
- }
- } else {
- Debug.logWarning("Ignoring invalid
field name [" + currentFieldName + "] found for the entity: "
- + currentValue.getEntityName()
+ " with value=" + currentFieldValue.toString(), module);
- }
- }
- }
- if (absentFields != null) {
- for (String fieldName : absentFields) {
- currentValue.set(fieldName, null);
- }
- }
- if (exist) {
- this.valuesToUpdate.add(currentValue);
- } else {
- // Not sure about this!
- //if (this.useTryInsertMethod &&
!this.checkDataOnly) {
- // currentValue.create();
- //} else {
- this.valuesToCreate.add(currentValue);
- //}
- }
- if (this.maintainTxStamps) {
- currentValue.setIsFromEntitySync(true);
- }
- this.numberReplaced++;
- }
- } catch (Exception e) {
- if (continueOnFail) {
- Debug.logError(e, module);
- } else {
- throw new IOException(e);
- }
- }
- }
- }
- }
- return this.numberReplaced;
- }
-
- private long delete(JSONObject jsonObject) throws IOException {
- Iterator iterator = jsonObject.keySet().iterator();
- while (iterator.hasNext()) {
- String key = iterator.next().toString();
- Object value = jsonObject.get(key);
- if (UtilValidate.isNotEmpty(value)) {
- List<Map<String, Object>> genericMapList =
iterateJsonEntityData(value);
- for (Map<String, Object> keyValPair : genericMapList) {
- try {
- ModelEntity modelEntity =
this.delegator.getModelEntity(key);
- GenericValue currentValue = delegator.makeValue(key,
keyValPair);
- if (this.maintainTxStamps) {
- currentValue.setIsFromEntitySync(true);
- }
- GenericHelper helper = delegator.getEntityHelper(key);
- if (currentValue != null) {
- boolean exist = true;
- if (currentValue.containsPrimaryKey()) {
- try {
-
helper.findByPrimaryKey(currentValue.getPrimaryKey());
- } catch (GenericEntityNotFoundException e) {
- exist = false;
- }
- }
- if (exist) {
- if (this.useTryInsertMethod &&
!this.checkDataOnly) {
- currentValue.remove();
- } else {
- this.valuesToDelete.add(currentValue);
- }
- this.numberDeleted++;
- }//if pk exist ignore it.
- }
- } catch (Exception e) {
- if (continueOnFail) {
- Debug.logError(e, module);
- } else {
- throw new IOException(e);
- }
- }
- }
- }
- }
- return this.numberDeleted;
- }
-
private long action(Object jsonData, String actionName) throws IOException
{
java.lang.reflect.Method method;
try {
Modified:
ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonEvents.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonEvents.java?rev=1862249&r1=1862248&r2=1862249&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonEvents.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonEvents.java
Thu Jun 27 19:38:44 2019
@@ -20,17 +20,14 @@ package org.apache.ofbiz.webtools;
import java.io.IOException;
import java.io.PrintWriter;
-import java.util.Collection;
import java.util.Iterator;
import java.util.TreeSet;
-import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.ofbiz.base.util.Debug;
-import org.apache.ofbiz.base.util.GeneralException;
import org.apache.ofbiz.entity.Delegator;
import org.apache.ofbiz.entity.GenericEntityException;
import org.apache.ofbiz.entity.GenericValue;
@@ -48,9 +45,7 @@ public class EntityJsonEvents {
public static String downloadJsonData(HttpServletRequest request,
HttpServletResponse response) {
HttpSession session = request.getSession();
- ServletContext application = session.getServletContext();
Delegator delegator = (Delegator) request.getAttribute("delegator");
- GenericValue userLogin = (GenericValue)
session.getAttribute("userLogin");
Security security = (Security) request.getAttribute("security");
boolean isFirst = true;
if (security.hasPermission("ENTITY_MAINT", session)) {
@@ -62,12 +57,6 @@ public class EntityJsonEvents {
if (passedEntityNames != null) {
ModelReader reader = delegator.getModelReader();
- Collection ec = reader.getEntityNames();
- TreeSet entityNames = new TreeSet(ec);
-
- long numberWritten = 0;
- byte[] outputByte = new byte[4096];
-
response.setContentType("text/plain;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment;
filename=DownloadEntityData.json");
@@ -103,9 +92,8 @@ public class EntityJsonEvents {
textBuilder.append("\n\t");
textBuilder.append("[");
int numberOfValues = 0;
- while ((value = (GenericValue) values.next())
!= null) {
+ while ((value = values.next()) != null) {
EntityJsonHelper.writeJsonText(textBuilder, value);
- numberWritten++;
numberOfValues++;
if (numberOfValues <
values.getResultsSizeAfterPartialList()) {
textBuilder.append(",");
@@ -156,11 +144,6 @@ public class EntityJsonEvents {
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
- } catch (GeneralException e) {
- String errMsg = "Error downloading json data: " + e.toString();
- Debug.logError(e, errMsg, module);
- request.setAttribute("_ERROR_MESSAGE_", errMsg);
- return "error";
} catch (IOException e) {
String errMsg = "Error downloading json data : " +
e.toString();
Debug.logError(e, errMsg, module);
Modified:
ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonHelper.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonHelper.java?rev=1862249&r1=1862248&r2=1862249&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonHelper.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonHelper.java
Thu Jun 27 19:38:44 2019
@@ -22,12 +22,10 @@ import org.apache.ofbiz.base.util.Base64
import org.apache.ofbiz.base.util.Debug;
import org.apache.ofbiz.base.util.UtilIO;
import org.apache.ofbiz.base.util.UtilValidate;
-import org.apache.ofbiz.entity.GenericEntity;
import org.apache.ofbiz.entity.GenericValue;
import org.apache.ofbiz.entity.model.ModelField;
import java.io.PrintWriter;
-import java.text.StringCharacterIterator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;