Attached Files | image (3).png [^] (523,112 bytes) 2019-03-12 17:01
diff40364_dlc.diff [^] (13,921 bytes) 2019-07-30 16:50 [Show Content] [Hide Content]diff -r a30e174ee937 src-db/database/sourcedata/AD_PREFERENCE.xml
--- a/src-db/database/sourcedata/AD_PREFERENCE.xml Tue Jul 30 11:11:30 2019 +0200
+++ b/src-db/database/sourcedata/AD_PREFERENCE.xml Tue Jul 30 11:14:47 2019 +0200
@@ -110,4 +110,16 @@
<!--E649BD54D578432CB28EA882B2482499--> <AD_MODULE_ID><![CDATA[E09B68E8080847CF99A3AA62238C7079]]></AD_MODULE_ID>
<!--E649BD54D578432CB28EA882B2482499--></AD_PREFERENCE>
+<!--EAA7DD0594A442ADB966250FB5716357--><AD_PREFERENCE>
+<!--EAA7DD0594A442ADB966250FB5716357--> <AD_PREFERENCE_ID><![CDATA[EAA7DD0594A442ADB966250FB5716357]]></AD_PREFERENCE_ID>
+<!--EAA7DD0594A442ADB966250FB5716357--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--EAA7DD0594A442ADB966250FB5716357--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--EAA7DD0594A442ADB966250FB5716357--> <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--EAA7DD0594A442ADB966250FB5716357--> <VALUE><![CDATA[300]]></VALUE>
+<!--EAA7DD0594A442ADB966250FB5716357--> <PROPERTY><![CDATA[OBAWO_FE_LimitToIgnoreAttValues]]></PROPERTY>
+<!--EAA7DD0594A442ADB966250FB5716357--> <ISPROPERTYLIST><![CDATA[Y]]></ISPROPERTYLIST>
+<!--EAA7DD0594A442ADB966250FB5716357--> <AD_MODULE_ID><![CDATA[E09B68E8080847CF99A3AA62238C7079]]></AD_MODULE_ID>
+<!--EAA7DD0594A442ADB966250FB5716357--> <EM_OPXUTIL_IS_HOST><![CDATA[N]]></EM_OPXUTIL_IS_HOST>
+<!--EAA7DD0594A442ADB966250FB5716357--></AD_PREFERENCE>
+
</data>
diff -r a30e174ee937 src-db/database/sourcedata/AD_REF_LIST.xml
--- a/src-db/database/sourcedata/AD_REF_LIST.xml Tue Jul 30 11:11:30 2019 +0200
+++ b/src-db/database/sourcedata/AD_REF_LIST.xml Tue Jul 30 11:14:47 2019 +0200
@@ -264,6 +264,18 @@
<!--73785C2843C341AB879F47DC3A3AAE24--> <AD_MODULE_ID><![CDATA[E09B68E8080847CF99A3AA62238C7079]]></AD_MODULE_ID>
<!--73785C2843C341AB879F47DC3A3AAE24--></AD_REF_LIST>
+<!--777CB065D7AB41B4915FA1C2900F83A5--><AD_REF_LIST>
+<!--777CB065D7AB41B4915FA1C2900F83A5--> <AD_REF_LIST_ID><![CDATA[777CB065D7AB41B4915FA1C2900F83A5]]></AD_REF_LIST_ID>
+<!--777CB065D7AB41B4915FA1C2900F83A5--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--777CB065D7AB41B4915FA1C2900F83A5--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--777CB065D7AB41B4915FA1C2900F83A5--> <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--777CB065D7AB41B4915FA1C2900F83A5--> <VALUE><![CDATA[OBAWO_FE_LimitToIgnoreAttValues]]></VALUE>
+<!--777CB065D7AB41B4915FA1C2900F83A5--> <NAME><![CDATA[Limit to ignore att values]]></NAME>
+<!--777CB065D7AB41B4915FA1C2900F83A5--> <DESCRIPTION><![CDATA[When the number of values allowed for an attribute is higher than the number defined for this preference, then values are not loaded in AWO FE]]></DESCRIPTION>
+<!--777CB065D7AB41B4915FA1C2900F83A5--> <AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID>
+<!--777CB065D7AB41B4915FA1C2900F83A5--> <AD_MODULE_ID><![CDATA[E09B68E8080847CF99A3AA62238C7079]]></AD_MODULE_ID>
+<!--777CB065D7AB41B4915FA1C2900F83A5--></AD_REF_LIST>
+
<!--7A85B02AF9F644FDB40ECE0345FE7796--><AD_REF_LIST>
<!--7A85B02AF9F644FDB40ECE0345FE7796--> <AD_REF_LIST_ID><![CDATA[7A85B02AF9F644FDB40ECE0345FE7796]]></AD_REF_LIST_ID>
<!--7A85B02AF9F644FDB40ECE0345FE7796--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff -r a30e174ee937 src/org/openbravo/warehouse/advancedwarehouseoperations/mobile/master/Attribute.java
--- a/src/org/openbravo/warehouse/advancedwarehouseoperations/mobile/master/Attribute.java Tue Jul 30 11:11:30 2019 +0200
+++ b/src/org/openbravo/warehouse/advancedwarehouseoperations/mobile/master/Attribute.java Tue Jul 30 11:14:47 2019 +0200
@@ -1,6 +1,6 @@
/*
************************************************************************************
- * Copyright (C) 2016-2018 Openbravo S.L.U.
+ * Copyright (C) 2016-2019 Openbravo S.L.U.
* Licensed under the Openbravo Commercial License version 1.0
* You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
* or in the legal folder of this module distribution.
@@ -9,9 +9,11 @@
package org.openbravo.warehouse.advancedwarehouseoperations.mobile.master;
+import java.io.IOException;
+import java.io.Writer;
import java.util.Date;
import java.util.HashMap;
-import java.util.List;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -23,19 +25,53 @@
import org.codehaus.jettison.json.JSONObject;
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
-import org.hibernate.criterion.Restrictions;
import org.hibernate.query.Query;
import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBCriteria;
import org.openbravo.dal.service.OBDal;
+import org.openbravo.erpCommon.businessUtility.Preferences;
+import org.openbravo.erpCommon.utility.PropertyException;
+import org.openbravo.mobile.core.process.JSONRowConverter;
import org.openbravo.model.common.plm.AttributeValue;
import org.openbravo.service.json.JsonConstants;
import org.openbravo.warehouse.advancedwarehouseoperations.mobile.utils.OBAWOJSONProcessSimple;
public class Attribute extends OBAWOJSONProcessSimple {
- public static final Logger log = Logger.getLogger(Attribute.class);
+ public static final Logger attLog = Logger.getLogger(Attribute.class);
+ public Map<String, JSONArray> cacheAttsValues;
+ public long maxNumberOfAttValuesToLoad = 300;
+ @Override
+ public void exec(Writer w, JSONObject jsonsent) throws IOException, ServletException {
+ checkTimeout();
+ JSONObject execResultJson;
+ try {
+ execResultJson = exec(jsonsent);
+ JSONObject contextInfo = getContextInformation();
+ if (contextInfo != null) {
+ execResultJson.put("contextInfo", contextInfo);
+ }
+ String responseStr = execResultJson.toString();
+ w.write(responseStr.substring(1, responseStr.length() - 1));
+ } catch (JSONException e) {
+ JSONRowConverter.addJSONExceptionFields(w, e);
+ }
+ }
+
+ @Override
public JSONObject exec(JSONObject jsonsent) throws JSONException, ServletException {
+ this.cacheAttsValues = new LinkedHashMap<String, JSONArray>();
+ try {
+ OBContext.setAdminMode(false);
+ Long maxNumberOfAttValuesToLoadFromPref = Long.parseLong(Preferences.getPreferenceValue(
+ "OBAWO_FE_LimitToIgnoreAttValues", true, OBContext.getOBContext().getCurrentClient(),
+ OBContext.getOBContext().getCurrentOrganization(), OBContext.getOBContext().getUser(),
+ OBContext.getOBContext().getRole(), null));
+ maxNumberOfAttValuesToLoad = maxNumberOfAttValuesToLoadFromPref.longValue();
+ } catch (PropertyException e) {
+ attLog.error("Error getting preference OBAWO_FE_LimitToIgnoreAttValues " + e.getMessage(), e);
+ } finally {
+ OBContext.restorePreviousMode();
+ }
JSONObject jsonResult = new JSONObject();
JSONArray jsonData = new JSONArray();
Long lastUpdated = jsonsent.has("lastUpdated")
@@ -137,17 +173,17 @@
}
JSONObject jsObj = this.readHeaderAttributes(attributeSetData.getBoolean(1),
attributeSetData.getBoolean(2), attributeSetData.getBoolean(3), guranteeDays);
- jsObj.put(attributeSetData.getString(5), this.readAttribute(
- attributeSetData.getString(5), attributeSetData.getString(6),
- attributeSetData.getBoolean(7), attributeSetData.getBoolean(8),
- attributeSetData.getLong(9), attributeSetData.getBoolean(10)));
+ jsObj.put(attributeSetData.getString(5),
+ this.readAttribute(attributeSetData.getString(5), attributeSetData.getString(6),
+ attributeSetData.getBoolean(7), attributeSetData.getBoolean(8),
+ attributeSetData.getLong(9), attributeSetData.getBoolean(10)));
attSetMap.put(curAttSetId, jsObj);
} else {
JSONObject curJsObj = attSetMap.get(curAttSetId);
- curJsObj.put(attributeSetData.getString(5), this.readAttribute(
- attributeSetData.getString(5), attributeSetData.getString(6),
- attributeSetData.getBoolean(7), attributeSetData.getBoolean(8),
- attributeSetData.getLong(9), attributeSetData.getBoolean(10)));
+ curJsObj.put(attributeSetData.getString(5),
+ this.readAttribute(attributeSetData.getString(5), attributeSetData.getString(6),
+ attributeSetData.getBoolean(7), attributeSetData.getBoolean(8),
+ attributeSetData.getLong(9), attributeSetData.getBoolean(10)));
}
}
while (simpleAttributeSetData.next()) {
@@ -176,8 +212,8 @@
jsonResult.put("endRow", (jsonData.length() - 1));
jsonResult.put(JsonConstants.RESPONSE_STATUS, JsonConstants.RPCREQUEST_STATUS_SUCCESS);
} catch (Exception e) {
- throw new JSONException("An error happened while retrieving Attribute set Information: "
- + e.getMessage());
+ throw new JSONException(
+ "An error happened while retrieving Attribute set Information: " + e.getMessage());
} finally {
OBContext.restorePreviousMode();
}
@@ -187,6 +223,7 @@
private JSONObject readAttribute(String id, String name, Boolean mandatory, Boolean list,
Long seqNo, Boolean updatable) throws JSONException {
JSONObject custAttJsonObj = new JSONObject();
+ ScrollableResults attValuesScrollableResults;
custAttJsonObj.put("id", id);
custAttJsonObj.put("mandatory", mandatory);
custAttJsonObj.put("list", list);
@@ -194,18 +231,60 @@
custAttJsonObj.put("seqNo", seqNo + 40);
custAttJsonObj.put("updatable", updatable);
if (list) {
- OBCriteria<AttributeValue> attValueCrit = OBDal.getInstance().createCriteria(
- AttributeValue.class);
- attValueCrit.add(Restrictions.eq(AttributeValue.PROPERTY_ATTRIBUTE + ".id", id));
- attValueCrit.addOrderBy(AttributeValue.PROPERTY_SEARCHKEY, true);
- List<AttributeValue> lstAttValues = attValueCrit.list();
JSONArray arrValues = new JSONArray();
- for (AttributeValue attValueObj : lstAttValues) {
- JSONObject valueJsObj = new JSONObject();
- valueJsObj.put("id", attValueObj.getId());
- valueJsObj.put("value", attValueObj.getSearchKey());
- valueJsObj.put("name", attValueObj.getName());
- arrValues.put(valueJsObj);
+ if (this.cacheAttsValues.containsKey(id)) {
+ arrValues = this.cacheAttsValues.get(id);
+ } else {
+ StringBuilder countAttValuesHqlQuerySelectString = new StringBuilder();
+ countAttValuesHqlQuerySelectString.append("select count(attvl.id) ");
+ StringBuilder attValuesHqlQuerySelectString = new StringBuilder();
+ attValuesHqlQuerySelectString.append("select attvl.id, attvl.searchKey, attvl.name ");
+ StringBuilder attValuesHqlQueryWhereString = new StringBuilder();
+ StringBuilder attValuesHqlQueryOrderByString = new StringBuilder();
+ attValuesHqlQueryWhereString.append("from " + AttributeValue.ENTITY_NAME + " attvl ");
+ attValuesHqlQueryWhereString.append("where attvl.attribute.id = :attid AND ");
+ attValuesHqlQueryWhereString.append("attvl.client.id = :clientid ");
+ attValuesHqlQueryOrderByString.append("order by attvl.searchKey ASC");
+ // Execute att values COUNT query
+ StringBuilder countAttValuesHqlQueryString = new StringBuilder();
+ countAttValuesHqlQueryString.append(countAttValuesHqlQuerySelectString);
+ countAttValuesHqlQueryString.append(attValuesHqlQueryWhereString);
+ Query<Long> countAttValuesQuery = OBDal.getInstance().getSession()
+ .createQuery(countAttValuesHqlQueryString.toString(), Long.class);
+ countAttValuesQuery.setParameter("attid", id);
+ countAttValuesQuery.setParameter("clientid",
+ OBContext.getOBContext().getCurrentClient().getId());
+ Long numberOfAttValuesForAtt = countAttValuesQuery.uniqueResult();
+ if (numberOfAttValuesForAtt.longValue() <= maxNumberOfAttValuesToLoad) {
+ // Execute att values GET query
+ StringBuilder attValuesHqlQueryString = new StringBuilder();
+ attValuesHqlQueryString.append(attValuesHqlQuerySelectString);
+ attValuesHqlQueryString.append(attValuesHqlQueryWhereString);
+ attValuesHqlQueryString.append(attValuesHqlQueryOrderByString);
+ Query<Object[]> attValuesQuery = OBDal.getInstance().getSession()
+ .createQuery(attValuesHqlQueryString.toString(), Object[].class);
+ attValuesQuery.setParameter("attid", id);
+ attValuesQuery.setParameter("clientid",
+ OBContext.getOBContext().getCurrentClient().getId());
+ attValuesQuery.setFetchSize((int) maxNumberOfAttValuesToLoad);
+ attValuesScrollableResults = attValuesQuery.scroll(ScrollMode.FORWARD_ONLY);
+ while (attValuesScrollableResults.next()) {
+ JSONObject valueJsObj = new JSONObject();
+ valueJsObj.put("id", (String) attValuesScrollableResults.get()[0]);
+ valueJsObj.put("value", (String) attValuesScrollableResults.get()[1]);
+ valueJsObj.put("name", (String) attValuesScrollableResults.get()[2]);
+ arrValues.put(valueJsObj);
+ // Clear the session after each loop to improve performance in inner flushes
+ OBDal.getInstance().getSession().clear();
+ }
+ } else {
+ // If number of values is greater than preference, then not execute query and log
+ attLog.info("Attribute " + name + " has " + numberOfAttValuesForAtt
+ + " values, more than " + maxNumberOfAttValuesToLoad
+ + " (from preference -OBAWO_FE_LimitToIgnoreAttValues-). They will not be loaded in AWO FE.");
+ }
+ // Save in cache
+ this.cacheAttsValues.put(id, arrValues);
}
custAttJsonObj.put("listValues", arrValues);
}
|