Ejemplo n.º 1
0
  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);
  }