Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-18822

Impossible to rebuild category tree programmatically

    Details

    • Type: Bug
    • Status: Closed
    • Resolution: Duplicate
    • Affects Version/s: 6.0.11 EE
    • Fix Version/s: --Sprint 12/11, 6.1.0 CE RC1
    • Component/s: Asset Framework, Categories
    • Labels:
      None
    • Environment:
      mysql Ver 14.14 Distrib 5.1.49, for debian-linux-gnu (i686) using readline 6.1

      Description

      Reference to tickets:
      #18433
      #16008
      Marked as "Cannot Reproduce" and closed. Here is a code sample to reproduce both of them.

      • Sample 1: created categories where leftCategoryId and rightCategoryId are OK. Allthough, groupId is 0. Thus, a search for categories within this group returns nothing.
      • Sample 2: associates these categories to a group (the global one). groupId is OK, but leftCategoryId and rightCategoryId are wrong. When moving them manually in the BackOffice, it restores the right leftCategoryId and rightCategoryId.

      After sample java codes are the MySQL outputs.

      Sample1.java
      ServiceContext serviceContext = new ServiceContext();
      serviceContext.setAddCommunityPermissions(true);
      serviceContext.setAddGuestPermissions(true);
      
      Map<Locale, String> titleMap = new HashMap<Locale, String>();
      titleMap.put(LocaleUtil.getDefault(), "vocabularyNameTest1");
      Map<Locale, String> titleMapParent = new HashMap<Locale, String>();
      titleMapParent.put(LocaleUtil.getDefault(), "categoryParentNameTest1");
      Map<Locale, String> titleMap1 = new HashMap<Locale, String>();
      titleMap1.put(LocaleUtil.getDefault(), "category1NameTest1");
      Map<Locale, String> titleMap2 = new HashMap<Locale, String>();
      titleMap2.put(LocaleUtil.getDefault(), "category2NameTest1");
      
      AssetVocabulary assetVocabulary = AssetVocabularyLocalServiceUtil
      .addVocabulary(getDefaultUserId(),
      		"TEST1", titleMap, null,
      		null, serviceContext);
      
      AssetCategory assetCategoryParent = AssetCategoryLocalServiceUtil
      		.addCategory(getDefaultUserId(), 0, titleMapParent,
      				assetVocabulary.getVocabularyId(), null, serviceContext);
      
      AssetCategory assetCategoryChild1 = AssetCategoryLocalServiceUtil
      .addCategory(getDefaultUserId(), assetCategoryParent.getCategoryId(), titleMap1,
      		assetVocabulary.getVocabularyId(), null, serviceContext);
      
      AssetCategory assetCategoryChild2 = AssetCategoryLocalServiceUtil
      .addCategory(getDefaultUserId(), assetCategoryParent.getCategoryId(), titleMap2,
      		assetVocabulary.getVocabularyId(), null, serviceContext);
      
      Sample2.java
      ServiceContext serviceContext = new ServiceContext();
      serviceContext.setAddCommunityPermissions(true);
      serviceContext.setAddGuestPermissions(true);
      
      Map<Locale, String> titleMap = new HashMap<Locale, String>();
      titleMap.put(LocaleUtil.getDefault(), "vocabularyNameTest1");
      Map<Locale, String> titleMapParent = new HashMap<Locale, String>();
      titleMapParent.put(LocaleUtil.getDefault(), "categoryParentNameTest1");
      Map<Locale, String> titleMap1 = new HashMap<Locale, String>();
      titleMap1.put(LocaleUtil.getDefault(), "category1NameTest1");
      Map<Locale, String> titleMap2 = new HashMap<Locale, String>();
      titleMap2.put(LocaleUtil.getDefault(), "category2NameTest1");
      
      AssetVocabulary assetVocabulary = AssetVocabularyLocalServiceUtil
      .addVocabulary(getDefaultUserId(),
      		"TEST1", titleMap, null,
      		null, serviceContext);
      assetVocabulary.setGroupId(getGlobalGroupId());
      AssetVocabularyLocalServiceUtil.updateAssetVocabulary(assetVocabulary);
      
      AssetCategory assetCategoryParent = AssetCategoryLocalServiceUtil
      		.addCategory(getDefaultUserId(), 0, titleMapParent,
      				assetVocabulary.getVocabularyId(), null, serviceContext);
      assetCategoryParent.setGroupId(getGlobalGroupId());
      AssetCategoryLocalServiceUtil.updateAssetCategory(assetCategoryParent);
      
      AssetCategory assetCategoryChild1 = AssetCategoryLocalServiceUtil
      .addCategory(getDefaultUserId(), assetCategoryParent.getCategoryId(), titleMap1,
      		assetVocabulary.getVocabularyId(), null, serviceContext);
      assetCategoryChild1.setGroupId(getGlobalGroupId());
      AssetCategoryLocalServiceUtil.updateAssetCategory(assetCategoryChild1);
      
      AssetCategory assetCategoryChild2 = AssetCategoryLocalServiceUtil
      .addCategory(getDefaultUserId(), assetCategoryParent.getCategoryId(), titleMap2,
      		assetVocabulary.getVocabularyId(), null, serviceContext);
      assetCategoryChild2.setGroupId(getGlobalGroupId());
      AssetCategoryLocalServiceUtil.updateAssetCategory(assetCategoryChild2);
      
      • Before code execution
        mysql> SELECT categoryId, name, parentCategoryId, leftCategoryId, rightCategoryId FROM AssetCategory;
        Empty set (0.00 sec)
        
      • After Sample1.java
        mysql> SELECT categoryId, name, groupId, parentCategoryId, leftCategoryId, rightCategoryId FROM AssetCategory;
        +------------+-------------------------+---------+------------------+----------------+-----------------+
        | categoryId | name                    | groupId | parentCategoryId | leftCategoryId | rightCategoryId |
        +------------+-------------------------+---------+------------------+----------------+-----------------+
        |      10341 | categoryParentNameTest1 |       0 |                0 |              2 |               7 |
        |      10342 | category1NameTest1      |       0 |            10341 |              3 |               4 |
        |      10343 | category2NameTest1      |       0 |            10341 |              5 |               6 |
        +------------+-------------------------+---------+------------------+----------------+-----------------+
        3 rows in set (0.00 sec)
        
      • After Sample2.java (database was reseted after Sample1)
        mysql> SELECT categoryId, name, groupId, parentCategoryId, leftCategoryId, rightCategoryId FROM AssetCategory;
        +------------+-------------------------+---------+------------------+----------------+-----------------+
        | categoryId | name                    | groupId | parentCategoryId | leftCategoryId | rightCategoryId |
        +------------+-------------------------+---------+------------------+----------------+-----------------+
        |      10345 | categoryParentNameTest1 |   10165 |                0 |              2 |               3 |
        |      10346 | category1NameTest1      |   10165 |            10345 |              3 |               4 |
        |      10347 | category2NameTest1      |   10165 |            10345 |              3 |               4 |
        +------------+-------------------------+---------+------------------+----------------+-----------------+
        3 rows in set (0.00 sec)
        
      • After moving manually one category in BackOffice, and putting it back to its place
        mysql> SELECT categoryId, name, groupId, parentCategoryId, leftCategoryId, rightCategoryId FROM AssetCategory;
        +------------+-------------------------+---------+------------------+----------------+-----------------+
        | categoryId | name                    | groupId | parentCategoryId | leftCategoryId | rightCategoryId |
        +------------+-------------------------+---------+------------------+----------------+-----------------+
        |      10345 | categoryParentNameTest1 |   10165 |                0 |              2 |               3 |
        |      10346 | category1NameTest1      |   10165 |            10345 |              3 |               4 |
        |      10347 | category2NameTest1      |   10165 |            10345 |              5 |               6 |
        +------------+-------------------------+---------+------------------+----------------+-----------------+
        3 rows in set (0.00 sec)
        

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ryan.wan Ryan Wan
              Reporter:
              frinux frinux (Inactive)
              Participants of an Issue:
              Recent user:
              Marta Elicegui
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                10 years, 18 weeks, 5 days ago

                  Packages

                  Version Package
                  --Sprint 12/11
                  6.1.0 CE RC1