Openbravo Issue Tracking System - POS2
View Issue Details
0055215POS2POSpublic2024-04-17 11:082024-05-10 08:53
malsasua 
sreehari 
highmajorsometimes
closedunable to reproduce 
5
 
24Q2 
marvintm
No
0055215: Keymap goes to EWI if the product doesn't exist in obpos2_keymap_product and the JSON doesn't include the product property
The error shown is:

org.openbravo.base.exception.OBException: org.openbravo.pos2.OBPOS2KeymapProduct product is a mandatory field to create a new org.openbravo.pos2.OBPOS2KeymapProduct from Web Pos
    at org.openbravo.pos2.KeymapLoader.checkMandatoryFields(KeymapLoader.java:340)
    at org.openbravo.pos2.KeymapLoader.createEntity(KeymapLoader.java:253)
    at org.openbravo.pos2.KeymapLoader.processEntity(KeymapLoader.java:293)
    at org.openbravo.pos2.KeymapLoader.processEntity(KeymapLoader.java:329)
    at org.openbravo.pos2.KeymapLoader.saveRecord(KeymapLoader.java:111)
    at org.openbravo.mobile.core.process.DataSynchronizationProcess.saveRecord(DataSynchronizationProcess.java:214)
No reproduced
Analyzing Terminal Log (attached),they launched Clicked on 'Save' - (obpos2KeymapEditorSaveButton) 5 times and it failed the two last ones (20:02:44 and 20:03:38)
No tags attached.
csv TerminalLogCDSKeymap.csv (430,441) 2024-04-17 11:08
https://issues.openbravo.com/file_download.php?file_id=19651&type=bug
diff keymapLogs-Patch.diff (2,589) 2024-05-09 13:54
https://issues.openbravo.com/file_download.php?file_id=19758&type=bug
Issue History
2024-04-17 11:08malsasuaNew Issue
2024-04-17 11:08malsasuaAssigned To => Retail
2024-04-17 11:08malsasuaFile Added: TerminalLogCDSKeymap.csv
2024-04-17 11:08malsasuaTriggers an Emergency Pack => No
2024-04-17 11:09malsasuaNote Added: 0163316
2024-04-17 11:09ngarciaIssue Monitored: ngarcia
2024-04-17 11:10ngarciaNote Edited: 0163316bug_revision_view_page.php?bugnote_id=0163316#r27828
2024-04-23 09:18guilleaerStatusnew => acknowledged
2024-04-29 09:38sreehariAssigned ToRetail => sreehari
2024-04-29 09:38sreehariStatusacknowledged => scheduled
2024-05-07 16:17lorenzofidalgoTarget Version => 24Q2
2024-05-09 13:53sreehariNote Added: 0164412
2024-05-09 13:54sreehariFile Added: keymapLogs-Patch.diff
2024-05-10 08:53marvintmReview Assigned To => marvintm
2024-05-10 08:53marvintmNote Added: 0164422
2024-05-10 08:53marvintmStatusscheduled => closed
2024-05-10 08:53marvintmResolutionopen => unable to reproduce

Notes
(0163316)
malsasua   
2024-04-17 11:09   
(edited on: 2024-04-17 11:10)
The error shown is raised in the following code (modules/org.openbravo.pos2/src/org/openbravo/pos2/KeymapLoader.java):
  private void checkMandatoryFields(String fields[], JSONObject json, String objectIdentifier)
      throws JSONException {
    for (String field : fields) {
      if (!json.has(field) || "null".equals(json.getString(field))) {
        String errorMessage = objectIdentifier + " " + field
            + " is a mandatory field to create a new " + objectIdentifier + " from Web Pos";
        log.error(errorMessage);
        throw new OBException(errorMessage);
      }
    }
  }
 
It is launched in the createEntity function that is only launched from the processEntity function when the obpos2_keymap_product doesn't exist.
  private void processEntity(Class<? extends BaseOBObject> type, JSONArray jsonEntities,
      String[] mandatoryFields, Map<String, String> uniqueProperties) throws JSONException {
    JSONArray filteredEntities = filterNotDeletedObjects(jsonEntities);
    deleteObjectsIfRequired(type, jsonEntities);
    for (int i = 0; i < filteredEntities.length(); i++) {
      JSONObject jsonEntityObject = filteredEntities.getJSONObject(i);
      BaseOBObject entityInstance = getEntityInstance(type, jsonEntityObject.optString("id", null));
      if (entityInstance == null) {
        BaseOBObject equivalentInstance = getEquivalentInstance(type, jsonEntityObject,
            uniqueProperties);
        if (equivalentInstance == null) {
          createEntity(type, jsonEntityObject, mandatoryFields);
        } else {
          updateEntity(type, equivalentInstance, jsonEntityObject);
        }
      } else {
        updateEntity(type, entityInstance, jsonEntityObject);
      }
    }
  }
 
This is why all the Keymaps are not failing.
 
In this case, when the entity doesn't exist, it looks for the following mandatory fields:
if (json.has("keymapProducts")) {
   processEntity(OBPOS2KeymapProduct.class, json.getJSONArray("keymapProducts"),
      KEYMAP_PRODUCT_MANDATORY_FIELDS);
}
      
public static final String[] KEYMAP_PRODUCT_MANDATORY_FIELDS = { "id", "organization", "name",
      "status", "product" };
 
It is looking for the product property and it doesn't exist.
 
We checked if any of the records in keymapProducts property didn't exist in the backoffice and we found one:
{
  "id": "...",
  "image": null,
  "organization": "0",
  "priority": 0,
  "useProductImg": true,
  "keymapCategoryId": "...",
  "productId": "...",
  "name": "...",
  "status": "A",
  "startingDate": null,
  "endingDate": null,
  "isButtonMandatory": false,
  "active": true
}
 
Although we added the "product" property to that section, it failed with a NPE in the following piece of code (modules/org.openbravo.pos2/src/org/openbravo/pos2/event/OBPOS2KeymapCategoryIsExtensibleEventHandler.java):
 
OBPOS2KeymapProduct keymapProduct = (OBPOS2KeymapProduct) event.getTargetInstance();
OBPOS2KeymapCategory keymapCategory = keymapProduct.getOBPOS2KeymapCategory();
Boolean canCreateProduct = keymapCategory.isStoresAllowedToAddNewProducts();
 
It is because the keymapCategory is null.

(0164412)
sreehari   
2024-05-09 13:53   
The issue is unable to reproduce, as per my analysis there are several calls to processEntity method which handles the createEntity methods based on certain cases.

we have mandatory defined for each of the keymap subrecords as follows:

{
  "keymapCategoryProductPositions": [
    "id",
    "organization",
    "productID",
    "layoutPositionColumn",
    "layoutPositionRow",
    "layoutColumnSpan",
    "layoutRowSpan",
    "screenResolutionID"
  ],
  "keymapCategoryProductAppearances": [
    "id",
    "organization",
    "productID"
  ],
  "keymapCategoryPositions": [
    "id",
    "organization",
    "categoryID",
    "positionX",
    "positionY",
    "layoutRowSpan",
    "layoutColumnSpan",
    "screenResolutionID"
  ],
  "keymapCategoryAppearances": [
    "id",
    "organization",
    "categoryID"
  ],
  "keymapCategoryLayouts": [
    "id",
    "organization",
    "keymapVersionID",
    "screenResolutionID",
    "cATLayoutCols",
    "cATLayoutRows"
  ],
  "keymapProductLayouts": [
    "id",
    "organization",
    "categoryID",
    "prodLayoutRows",
    "prodLayoutCols",
    "screenResolutionID"
  ],
  "keymapCategories": [
    "id",
    "organization",
    "name",
    "status",
    "searchKey"
  ],
  "keymapProducts": [
    "id",
    "organization",
    "name",
    "status",
    "product"
  ],
  "keymapCategoryProductCategories": [
    "id",
    "organization",
    "categoryID",
    "productCategory"
  ]
}

So attaching a patch which logs the all the details of the keymap when createEntity method is invoked, also everytime a save is triggered the keymapdata from frontend is logged.
(0164422)
marvintm   
2024-05-10 08:53   
We haven't been able to reproduce the problem. We have attached a diff with additional log, this can be deployed on the customer environment, and if the problem happens again the issue can be reopened with the additional information.