public AssetCategoryPropertyActionableDynamicQuery() throws SystemException {
    setBaseLocalService(AssetCategoryPropertyLocalServiceUtil.getService());
    setClass(AssetCategoryProperty.class);

    setClassLoader(PortalClassLoaderUtil.getClassLoader());

    setPrimaryKeyPropertyName("categoryPropertyId");
  }
  protected void exportAssetCategory(
      PortletDataContext portletDataContext,
      Element assetVocabulariesElement,
      Element assetCategoriesElement,
      AssetCategory assetCategory)
      throws Exception {

    exportAssetVocabulary(
        portletDataContext, assetVocabulariesElement, assetCategory.getVocabularyId());

    if (assetCategory.getParentCategoryId() != AssetCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {

      exportAssetCategory(
          portletDataContext,
          assetVocabulariesElement,
          assetCategoriesElement,
          assetCategory.getParentCategoryId());
    }

    String path = getAssetCategoryPath(portletDataContext, assetCategory.getCategoryId());

    if (!portletDataContext.isPathNotProcessed(path)) {
      return;
    }

    Element assetCategoryElement = assetCategoriesElement.addElement("category");

    assetCategoryElement.addAttribute("path", path);

    assetCategory.setUserUuid(assetCategory.getUserUuid());

    portletDataContext.addZipEntry(path, assetCategory);

    List<AssetCategoryProperty> assetCategoryProperties =
        AssetCategoryPropertyLocalServiceUtil.getCategoryProperties(assetCategory.getCategoryId());

    for (AssetCategoryProperty assetCategoryProperty : assetCategoryProperties) {

      Element propertyElement = assetCategoryElement.addElement("property");

      propertyElement.addAttribute("userUuid", assetCategoryProperty.getUserUuid());
      propertyElement.addAttribute("key", assetCategoryProperty.getKey());
      propertyElement.addAttribute("value", assetCategoryProperty.getValue());
    }

    portletDataContext.addPermissions(AssetCategory.class, assetCategory.getCategoryId());
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, AssetCategory category)
      throws Exception {

    if (category.getParentCategoryId() != AssetCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {

      AssetCategory parentCategory =
          AssetCategoryLocalServiceUtil.fetchAssetCategory(category.getParentCategoryId());

      StagedModelDataHandlerUtil.exportReferenceStagedModel(
          portletDataContext, category, parentCategory, PortletDataContext.REFERENCE_TYPE_PARENT);
    } else {
      AssetVocabulary vocabulary =
          AssetVocabularyLocalServiceUtil.fetchAssetVocabulary(category.getVocabularyId());

      StagedModelDataHandlerUtil.exportReferenceStagedModel(
          portletDataContext, category, vocabulary, PortletDataContext.REFERENCE_TYPE_PARENT);
    }

    Element categoryElement = portletDataContext.getExportDataElement(category);

    category.setUserUuid(category.getUserUuid());

    List<AssetCategoryProperty> categoryProperties =
        AssetCategoryPropertyLocalServiceUtil.getCategoryProperties(category.getCategoryId());

    for (AssetCategoryProperty categoryProperty : categoryProperties) {
      Element propertyElement = categoryElement.addElement("property");

      propertyElement.addAttribute("userUuid", categoryProperty.getUserUuid());
      propertyElement.addAttribute("key", categoryProperty.getKey());
      propertyElement.addAttribute("value", categoryProperty.getValue());
    }

    String categoryPath = ExportImportPathUtil.getModelPath(category);

    categoryElement.addAttribute("path", categoryPath);

    portletDataContext.addPermissions(AssetCategory.class, category.getCategoryId());

    portletDataContext.addZipEntry(categoryPath, category);
  }
  public static String substituteCategoryPropertyVariables(
      long groupId, long categoryId, String s) {

    String result = s;

    AssetCategory category = null;

    if (categoryId > 0) {
      category = AssetCategoryLocalServiceUtil.fetchCategory(categoryId);
    }

    if (category != null) {
      List<AssetCategoryProperty> categoryProperties =
          AssetCategoryPropertyLocalServiceUtil.getCategoryProperties(categoryId);

      for (AssetCategoryProperty categoryProperty : categoryProperties) {
        result =
            StringUtil.replace(
                result, "[$" + categoryProperty.getKey() + "$]", categoryProperty.getValue());
      }
    }

    return StringUtil.stripBetween(result, "[$", "$]");
  }
  public void loadCategoriesFromCsv(ActionRequest actionRequest, ActionResponse actionResponse)
      throws IOException, PortletException, PortalException, SystemException {

    LOGGER.info("Begin  AssetCategoriesImporter");
    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);
    ThemeDisplay themeDisplay =
        (ThemeDisplay) uploadPortletRequest.getAttribute(WebKeys.THEME_DISPLAY);
    Map<String, FileItem[]> multipartParameterMap = uploadPortletRequest.getMultipartParameterMap();

    File file = null;
    BufferedReader bufferedReader = null;
    AssetVocabulary assetVocabulary = null;
    long userId = themeDisplay.getUserId();
    long groupId = themeDisplay.getScopeGroupId();

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(AssetCategory.class.getName(), uploadPortletRequest);

    // create vocabulary
    try {

      assetVocabulary =
          AssetVocabularyLocalServiceUtil.addVocabulary(
              userId,
              "Announcements",
              ServiceContextFactory.getInstance(
                  AssetVocabulary.class.getName(), uploadPortletRequest));
    } catch (DuplicateVocabularyException dve) {
      try {
        assetVocabulary =
            AssetVocabularyLocalServiceUtil.getGroupVocabulary(groupId, "Announcements");
      } catch (PortalException e) {
        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug(e);
        }
        LOGGER.error(e.getMessage());
      } catch (SystemException e) {
        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug(e);
        }
        LOGGER.error(e.getMessage());
      }
    }

    if (multipartParameterMap.keySet().contains("fileCategory")
        && Validator.isNotNull(assetVocabulary)) {
      try {
        file = uploadPortletRequest.getFile("fileCategory");
        bufferedReader = new BufferedReader(new FileReader(file.getAbsolutePath()));
        String line = StringPool.BLANK;
        long vocabularyId = assetVocabulary.getVocabularyId();

        String parentCategoryName = StringPool.BLANK;
        AssetCategory parentCategory = null;

        while ((line = bufferedReader.readLine()) != null) {

          // use comma as separator
          String[] categories = line.split(StringPool.SEMICOLON);

          if (categories.length == 4) {
            String parentCategoryCode = categories[0];

            if (Validator.isNull(parentCategory) || !parentCategoryName.equals(categories[1])) {
              parentCategoryName = categories[1];
              try {
                parentCategory =
                    AssetCategoryLocalServiceUtil.addCategory(
                        userId, parentCategoryName, vocabularyId, serviceContext);
                AssetCategoryPropertyLocalServiceUtil.addCategoryProperty(
                    userId, parentCategory.getCategoryId(), "Code", parentCategoryCode);
              } catch (Exception e) {
                if (LOGGER.isDebugEnabled()) {
                  LOGGER.debug(e);
                }
                LOGGER.error(e.getMessage());
              }
            }

            Map<Locale, String> titles = new HashMap<Locale, String>();
            Map<Locale, String> descriptionMap = new HashMap<Locale, String>();

            titles.put(LocaleUtil.fromLanguageId("fr_FR"), categories[3]);
            titles.put(LocaleUtil.fromLanguageId("en_US"), categories[3]);

            try {
              AssetCategory child =
                  AssetCategoryLocalServiceUtil.addCategory(
                      userId,
                      parentCategory.getCategoryId(),
                      titles,
                      descriptionMap,
                      vocabularyId,
                      null,
                      serviceContext);
              AssetCategoryPropertyLocalServiceUtil.addCategoryProperty(
                  userId, child.getCategoryId(), "Code", categories[2]);
            } catch (Exception e) {
              if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(e);
              }
              LOGGER.error(e.getMessage());
            }
          }
        }
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      } finally {
        if (bufferedReader != null) {
          try {
            bufferedReader.close();
          } catch (IOException e) {
            if (LOGGER.isDebugEnabled()) {
              LOGGER.debug(e);
            }
            LOGGER.error(e.getMessage());
          }
        }
      }
    }
    LOGGER.info("End  AssetCategoriesImporter");
  }