@Override
  public List<AssetVocabulary> deleteVocabularies(
      long[] vocabularyIds, ServiceContext serviceContext) throws PortalException {

    List<AssetVocabulary> failedVocabularies = new ArrayList<>();

    for (long vocabularyId : vocabularyIds) {
      try {
        AssetVocabularyPermission.check(getPermissionChecker(), vocabularyId, ActionKeys.DELETE);

        assetVocabularyLocalService.deleteVocabulary(vocabularyId);
      } catch (PortalException pe) {
        if (serviceContext == null) {
          return null;
        }

        if (serviceContext.isFailOnPortalException()) {
          throw pe;
        }

        AssetVocabulary vocabulary = assetVocabularyPersistence.fetchByPrimaryKey(vocabularyId);

        if (vocabulary == null) {
          vocabulary = assetVocabularyPersistence.create(vocabularyId);
        }

        failedVocabularies.add(vocabulary);
      }
    }

    return failedVocabularies;
  }
  @Override
  public AssetVocabulary getVocabulary(long vocabularyId) throws PortalException {

    AssetVocabularyPermission.check(getPermissionChecker(), vocabularyId, ActionKeys.VIEW);

    return assetVocabularyLocalService.getVocabulary(vocabularyId);
  }
  public static long[] filterVocabularyIds(
      PermissionChecker permissionChecker, long[] vocabularyIds) throws PortalException {

    List<Long> viewableVocabularyIds = new ArrayList<>();

    for (long vocabularyId : vocabularyIds) {
      if (AssetVocabularyPermission.contains(permissionChecker, vocabularyId, ActionKeys.VIEW)) {

        viewableVocabularyIds.add(vocabularyId);
      }
    }

    return ArrayUtil.toArray(viewableVocabularyIds.toArray(new Long[viewableVocabularyIds.size()]));
  }
  @Override
  public AssetVocabulary updateVocabulary(
      long vocabularyId,
      String title,
      Map<Locale, String> titleMap,
      Map<Locale, String> descriptionMap,
      String settings,
      ServiceContext serviceContext)
      throws PortalException {

    AssetVocabularyPermission.check(getPermissionChecker(), vocabularyId, ActionKeys.UPDATE);

    return assetVocabularyLocalService.updateVocabulary(
        vocabularyId, title, titleMap, descriptionMap, settings, serviceContext);
  }
  /** @deprecated As of 7.0.0, with no direct replacement */
  @Deprecated
  protected List<AssetVocabulary> filterVocabularies(List<AssetVocabulary> vocabularies)
      throws PortalException {

    PermissionChecker permissionChecker = getPermissionChecker();

    vocabularies = ListUtil.copy(vocabularies);

    Iterator<AssetVocabulary> itr = vocabularies.iterator();

    while (itr.hasNext()) {
      AssetVocabulary vocabulary = itr.next();

      if (!AssetVocabularyPermission.contains(permissionChecker, vocabulary, ActionKeys.VIEW)) {

        itr.remove();
      }
    }

    return vocabularies;
  }
  @Override
  public void deleteVocabulary(long vocabularyId) throws PortalException {
    AssetVocabularyPermission.check(getPermissionChecker(), vocabularyId, ActionKeys.DELETE);

    assetVocabularyLocalService.deleteVocabulary(vocabularyId);
  }