protected String[] readAssetTagNames(long userId, WikiNode node, String content)
      throws PortalException {

    Matcher matcher = _categoriesPattern.matcher(content);

    List<String> assetTagNames = new ArrayList<String>();

    while (matcher.find()) {
      String categoryName = matcher.group(1);

      categoryName = normalize(categoryName, 75);

      AssetTag assetTag = null;

      try {
        assetTag = AssetTagLocalServiceUtil.getTag(node.getGroupId(), categoryName);
      } catch (NoSuchTagException nste) {
        ServiceContext serviceContext = new ServiceContext();

        serviceContext.setAddGroupPermissions(true);
        serviceContext.setAddGuestPermissions(true);
        serviceContext.setScopeGroupId(node.getGroupId());

        assetTag = AssetTagLocalServiceUtil.addTag(userId, categoryName, null, serviceContext);
      }

      assetTagNames.add(assetTag.getName());
    }

    if (content.contains(_WORK_IN_PROGRESS)) {
      assetTagNames.add(_WORK_IN_PROGRESS_TAG);
    }

    return assetTagNames.toArray(new String[assetTagNames.size()]);
  }
  @Override
  protected void doImportStagedModel(PortletDataContext portletDataContext, AssetTag assetTag)
      throws Exception {

    long userId = portletDataContext.getUserId(assetTag.getUserUuid());

    ServiceContext serviceContext = createServiceContext(portletDataContext, assetTag);

    AssetTag existingAssetTag =
        fetchStagedModelByUuidAndGroupId(assetTag.getUuid(), portletDataContext.getScopeGroupId());

    AssetTag importedAssetTag = null;

    if (existingAssetTag == null) {
      serviceContext.setUuid(assetTag.getUuid());

      importedAssetTag =
          AssetTagLocalServiceUtil.addTag(
              userId, portletDataContext.getScopeGroupId(), assetTag.getName(), serviceContext);
    } else {
      importedAssetTag =
          AssetTagLocalServiceUtil.updateTag(
              userId, existingAssetTag.getTagId(), assetTag.getName(), serviceContext);
    }

    portletDataContext.importClassedModel(assetTag, importedAssetTag);
  }
  protected void processSpecialPages(
      long userId, WikiNode node, Element rootElement, List<String> specialNamespaces)
      throws PortalException {

    ProgressTracker progressTracker = ProgressTrackerThreadLocal.getProgressTracker();

    List<Element> pageElements = rootElement.elements("page");

    for (int i = 0; i < pageElements.size(); i++) {
      Element pageElement = pageElements.get(i);

      String title = pageElement.elementText("title");

      if (!title.startsWith("Category:")) {
        if (isSpecialMediaWikiPage(title, specialNamespaces)) {
          rootElement.remove(pageElement);
        }

        continue;
      }

      String categoryName = title.substring("Category:".length());

      categoryName = normalize(categoryName, 75);

      Element revisionElement = pageElement.element("revision");

      String description = revisionElement.elementText("text");

      description = normalizeDescription(description);

      try {
        AssetTag assetTag = null;

        try {
          assetTag = AssetTagLocalServiceUtil.getTag(node.getCompanyId(), categoryName);
        } catch (NoSuchTagException nste) {
          ServiceContext serviceContext = new ServiceContext();

          serviceContext.setAddGroupPermissions(true);
          serviceContext.setAddGuestPermissions(true);
          serviceContext.setScopeGroupId(node.getGroupId());

          assetTag = AssetTagLocalServiceUtil.addTag(userId, categoryName, null, serviceContext);
        }

        if (Validator.isNotNull(description)) {
          AssetTagPropertyLocalServiceUtil.addTagProperty(
              userId, assetTag.getTagId(), "description", description);
        }
      } catch (SystemException se) {
        _log.error(se, se);
      }

      if ((i % 5) == 0) {
        progressTracker.setPercent((i * 10) / pageElements.size());
      }
    }
  }
  protected void checkPopulatedServiceContext(
      ServiceContext serviceContext, WikiPage page, boolean hasExpandoValues) throws Exception {

    long[] assetCategoryIds =
        AssetCategoryLocalServiceUtil.getCategoryIds(
            WikiPage.class.getName(), page.getResourcePrimKey());

    Assert.assertArrayEquals(serviceContext.getAssetCategoryIds(), assetCategoryIds);

    AssetEntry assetEntry =
        AssetEntryLocalServiceUtil.getEntry(WikiPage.class.getName(), page.getResourcePrimKey());

    List<AssetLink> assetLinks = AssetLinkLocalServiceUtil.getLinks(assetEntry.getEntryId());

    long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR);

    Assert.assertArrayEquals(serviceContext.getAssetLinkEntryIds(), assetLinkEntryIds);

    String[] assetTagNames =
        AssetTagLocalServiceUtil.getTagNames(WikiPage.class.getName(), page.getResourcePrimKey());

    Assert.assertArrayEquals(serviceContext.getAssetTagNames(), assetTagNames);

    if (hasExpandoValues) {
      ExpandoBridge expandoBridge = page.getExpandoBridge();

      AssertUtils.assertEquals(
          expandoBridge.getAttributes(), serviceContext.getExpandoBridgeAttributes());
    }
  }
Example #5
0
  public void addAssetTags(Class<?> clazz, long classPK) throws SystemException {

    String[] tagNames = AssetTagLocalServiceUtil.getTagNames(clazz.getName(), classPK);

    if (tagNames.length == 0) {
      return;
    }

    _assetTagNamesMap.put(getPrimaryKeyString(clazz, classPK), tagNames);
  }
  protected void updateQueryLogic(ActionRequest actionRequest, PortletPreferences preferences)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long userId = themeDisplay.getUserId();
    long groupId = themeDisplay.getScopeGroupId();

    int[] queryRulesIndexes =
        StringUtil.split(ParamUtil.getString(actionRequest, "queryLogicIndexes"), 0);

    int i = 0;

    for (int queryRulesIndex : queryRulesIndexes) {
      boolean contains = ParamUtil.getBoolean(actionRequest, "queryContains" + queryRulesIndex);
      boolean andOperator =
          ParamUtil.getBoolean(actionRequest, "queryAndOperator" + queryRulesIndex);
      String name = ParamUtil.getString(actionRequest, "queryName" + queryRulesIndex);

      String[] values = null;

      if (name.equals("assetTags")) {
        values =
            StringUtil.split(ParamUtil.getString(actionRequest, "queryTagNames" + queryRulesIndex));

        AssetTagLocalServiceUtil.checkTags(userId, groupId, values);
      } else {
        values =
            StringUtil.split(
                ParamUtil.getString(actionRequest, "queryCategoryIds" + queryRulesIndex));
      }

      preferences.setValue("queryContains" + i, String.valueOf(contains));
      preferences.setValue("queryAndOperator" + i, String.valueOf(andOperator));
      preferences.setValue("queryName" + i, name);
      preferences.setValues("queryValues" + i, values);

      i++;
    }

    // Clear previous preferences that are now blank

    String[] values = preferences.getValues("queryValues" + i, new String[0]);

    while (values.length > 0) {
      preferences.setValue("queryContains" + i, StringPool.BLANK);
      preferences.setValue("queryAndOperator" + i, StringPool.BLANK);
      preferences.setValue("queryName" + i, StringPool.BLANK);
      preferences.setValues("queryValues" + i, new String[0]);

      i++;

      values = preferences.getValues("queryValues" + i, new String[0]);
    }
  }
  @Override
  public AssetTag fetchStagedModelByUuidAndGroupId(String uuid, long groupId) {

    AssetTag assetTag = AssetTagLocalServiceUtil.fetchTag(groupId, uuid);

    if (assetTag == null) {
      return null;
    }

    return assetTag;
  }
  public static boolean addBreadcrumbEntry(PortletRequest request, Entry entry, String currentURL)
      throws SystemException {

    HttpServletRequest servletRequest = PortalUtil.getHttpServletRequest(request);

    PortalUtil.addPortletBreadcrumbEntry(servletRequest, entry.getName(), currentURL);

    PortalUtil.setPageSubtitle(entry.getName(), servletRequest);
    PortalUtil.setPageDescription(entry.getName(), servletRequest);

    List<AssetTag> assetTags =
        AssetTagLocalServiceUtil.getTags(Guestbook.class.getName(), entry.getGuestbookId());
    PortalUtil.setPageKeywords(ListUtil.toString(assetTags, "name"), servletRequest);

    return true;
  }
Example #9
0
  public static String getAssetKeywords(String className, long classPK) {
    List<AssetTag> tags = AssetTagLocalServiceUtil.getTags(className, classPK);
    List<AssetCategory> categories =
        AssetCategoryLocalServiceUtil.getCategories(className, classPK);

    StringBuffer sb = new StringBuffer();

    sb.append(ListUtil.toString(tags, AssetTag.NAME_ACCESSOR));

    if (!tags.isEmpty()) {
      sb.append(StringPool.COMMA);
    }

    sb.append(ListUtil.toString(categories, AssetCategory.NAME_ACCESSOR));

    return sb.toString();
  }
  @Override
  protected Document doGetDocument(Object obj) throws Exception {
    DLFileEntry dlFileEntry = (DLFileEntry) obj;

    FileModel fileModel = new FileModel();

    long[] assetCategoryIds =
        AssetCategoryLocalServiceUtil.getCategoryIds(
            DLFileEntry.class.getName(), dlFileEntry.getFileEntryId());

    fileModel.setAssetCategoryIds(assetCategoryIds);

    String[] assetCategoryNames =
        AssetCategoryLocalServiceUtil.getCategoryNames(
            DLFileEntry.class.getName(), dlFileEntry.getFileEntryId());

    fileModel.setAssetCategoryNames(assetCategoryNames);

    String[] assetTagNames =
        AssetTagLocalServiceUtil.getTagNames(
            DLFileEntry.class.getName(), dlFileEntry.getFileEntryId());

    fileModel.setAssetTagNames(assetTagNames);

    fileModel.setCompanyId(dlFileEntry.getCompanyId());
    fileModel.setCreateDate(dlFileEntry.getCreateDate());
    fileModel.setFileEntryId(dlFileEntry.getFileEntryId());
    fileModel.setFileName(dlFileEntry.getName());
    fileModel.setGroupId(dlFileEntry.getGroupId());
    fileModel.setModifiedDate(dlFileEntry.getModifiedDate());
    fileModel.setPortletId(PORTLET_ID);
    fileModel.setProperties(dlFileEntry.getLuceneProperties());
    fileModel.setRepositoryId(dlFileEntry.getDataRepositoryId());
    fileModel.setUserId(dlFileEntry.getUserId());
    fileModel.setUserName(dlFileEntry.getUserName());
    fileModel.setUserUuid(dlFileEntry.getUserUuid());

    Indexer indexer = IndexerRegistryUtil.getIndexer(FileModel.class);

    return indexer.getDocument(fileModel);
  }
  public static long[] getAssetTagIds(long[] groupIds, KBArticle kbArticle) throws PortalException {

    List<AssetTag> assetTags =
        AssetTagServiceUtil.getTags(KBArticle.class.getName(), kbArticle.getClassPK());

    long[] tagIds =
        AssetTagLocalServiceUtil.getTagIds(
            groupIds, StringUtil.split(ListUtil.toString(assetTags, "name")));

    Set<Long> filteredTagIds = new LinkedHashSet<>();

    for (long tagId : tagIds) {
      try {
        AssetTagServiceUtil.getTag(tagId);
      } catch (PrincipalException pe) {
        continue;
      }

      filteredTagIds.add(tagId);
    }

    return StringUtil.split(StringUtil.merge(filteredTagIds), 0L);
  }
  @Override
  public List<AssetTag> fetchStagedModelsByUuidAndCompanyId(String uuid, long companyId) {

    return AssetTagLocalServiceUtil.getAssetTagsByUuidAndCompanyId(uuid, companyId);
  }
  @Override
  public void deleteStagedModel(AssetTag stagedAssetTag) throws PortalException {

    AssetTagLocalServiceUtil.deleteTag(stagedAssetTag);
  }
  public AssetEntryQuery getAssetEntryQuery() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    long[] groupIds = getGroupIds();

    if (!ArrayUtil.contains(groupIds, themeDisplay.getScopeGroupId())) {
      groupIds = ArrayUtil.append(groupIds, themeDisplay.getScopeGroupId());
    }

    AssetEntryQuery assetEntryQuery =
        AssetPublisherUtil.getAssetEntryQuery(_portletPreferences, groupIds);

    long[] classNameIds = getClassNameIds();
    long[] classTypeIds = getClassTypeIds();

    if (isSubtypeFieldsFilterEnabled()
        && (classNameIds.length == 1)
        && (classTypeIds.length == 1)
        && Validator.isNotNull(getDDMStructureFieldName())
        && Validator.isNotNull(getDDMStructureFieldValue())) {

      AssetRendererFactory assetRendererFactory =
          AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
              PortalUtil.getClassName(classNameIds[0]));

      Tuple classTypeFieldName =
          assetRendererFactory.getClassTypeFieldName(
              classTypeIds[0], getDDMStructureFieldName(), themeDisplay.getLocale());

      long ddmStructureId = GetterUtil.getLong(classTypeFieldName.getObject(3));

      assetEntryQuery.setAttribute(
          "ddmStructureFieldName",
          DDMIndexerUtil.encodeName(
              ddmStructureId, getDDMStructureFieldName(), themeDisplay.getLocale()));
      assetEntryQuery.setAttribute("ddmStructureFieldValue", getDDMStructureFieldValue());
    }

    AssetPublisherUtil.processAssetEntryQuery(
        themeDisplay.getUser(), _portletPreferences, assetEntryQuery);

    assetEntryQuery.setAllCategoryIds(getAllAssetCategoryIds());

    if (hasLayoutGroup(groupIds)) {
      assetEntryQuery.setAllTagIds(
          AssetTagLocalServiceUtil.getTagIds(groupIds, getAllAssetTagNames()));
    } else {
      assetEntryQuery.setAllTagIds(
          AssetTagLocalServiceUtil.getTagIds(getGroupIds(), getAllAssetTagNames()));
    }

    assetEntryQuery.setClassTypeIds(classTypeIds);
    assetEntryQuery.setEnablePermissions(isEnablePermissions());
    assetEntryQuery.setExcludeZeroViewCount(isExcludeZeroViewCount());

    String portletName = getPortletName();

    if (!portletName.equals(PortletKeys.RELATED_ASSETS)) {
      assetEntryQuery.setGroupIds(getGroupIds());
    }

    if (isShowOnlyLayoutAssets()) {
      assetEntryQuery.setLayout(themeDisplay.getLayout());
    }

    if (portletName.equals(PortletKeys.RELATED_ASSETS)) {
      AssetEntry layoutAssetEntry = (AssetEntry) _request.getAttribute(WebKeys.LAYOUT_ASSET_ENTRY);

      if (layoutAssetEntry != null) {
        assetEntryQuery.setLinkedAssetEntryId(layoutAssetEntry.getEntryId());
      }
    }

    assetEntryQuery.setPaginationType(getPaginationType());
    assetEntryQuery.setOrderByCol1(getOrderByColumn1());
    assetEntryQuery.setOrderByCol2(getOrderByColumn2());
    assetEntryQuery.setOrderByType1(getOrderByType1());
    assetEntryQuery.setOrderByType2(getOrderByType2());

    return assetEntryQuery;
  }
Example #15
0
  @RequestMapping
  public String ver(
      RenderRequest request,
      RenderResponse response,
      @RequestParam(required = false) Integer dias,
      Model model) {
    log.debug("Viendo el versiculo");
    TimeZone tz = null;
    DateTimeZone zone = null;
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    try {
      tz = themeDisplay.getTimeZone();
      zone = DateTimeZone.forID(tz.getID());
    } catch (IllegalArgumentException e) {
      zone = DateTimeZone.forID(ZonaHorariaUtil.getConvertedId(tz.getID()));
    }
    try {
      long scopeGroupId = themeDisplay.getScopeGroupId();

      AssetEntryQuery assetEntryQuery = new AssetEntryQuery();

      DateTime hoy =
          (DateTime)
              request.getPortletSession().getAttribute("hoy", PortletSession.APPLICATION_SCOPE);
      if (hoy == null) {
        hoy = new DateTime(zone);
        log.debug("Subiendo atributo hoy({}) a la sesion", hoy);
        request.getPortletSession().setAttribute("hoy", hoy, PortletSession.APPLICATION_SCOPE);
      }

      // Busca el contenido del dia
      String[] tags = TagsUtil.getTags(new String[4], hoy);
      tags[3] = "versiculo";

      long[] assetTagIds = AssetTagLocalServiceUtil.getTagIds(scopeGroupId, tags);

      assetEntryQuery.setAllTagIds(assetTagIds);

      List<AssetEntry> results = AssetEntryServiceUtil.getEntries(assetEntryQuery);

      log.debug("Buscando el versiculo de la semana {}", hoy);
      for (AssetEntry asset : results) {
        if (asset.getClassName().equals(JournalArticle.class.getName())) {
          JournalArticle ja = JournalArticleLocalServiceUtil.getLatestArticle(asset.getClassPK());
          String contenido =
              JournalArticleLocalServiceUtil.getArticleContent(
                  ja.getGroupId(),
                  ja.getArticleId(),
                  "view",
                  "" + themeDisplay.getLocale(),
                  themeDisplay);
          model.addAttribute("contenido", contenido);
        }
      }

    } catch (Exception e) {
      log.error("No se pudo cargar el contenido", e);
      throw new RuntimeException("No se pudo cargar el contenido", e);
    }

    return "versiculo/ver";
  }
  protected void addAssetTag(long groupId, String name, String[] properties) throws Exception {

    ServiceContext serviceContext = ServiceTestUtil.getServiceContext(groupId);

    AssetTagLocalServiceUtil.addTag(TestPropsValues.getUserId(), name, properties, serviceContext);
  }
  public int putResource(WebDAVRequest webDavRequest) throws WebDAVException {
    File file = null;

    try {
      HttpServletRequest request = webDavRequest.getHttpServletRequest();

      String[] pathArray = webDavRequest.getPathArray();

      long companyId = webDavRequest.getCompanyId();
      long groupId = webDavRequest.getGroupId();
      long parentFolderId = getParentFolderId(companyId, pathArray);
      String name = WebDAVUtil.getResourceName(pathArray);
      String description = StringPool.BLANK;

      file = FileUtil.createTempFile(FileUtil.getExtension(name));

      FileUtil.write(file, request.getInputStream());

      String contentType = MimeTypesUtil.getContentType(name);

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddCommunityPermissions(isAddCommunityPermissions(groupId));
      serviceContext.setAddGuestPermissions(true);

      try {
        IGImage image =
            IGImageServiceUtil.getImageByFolderIdAndNameWithExtension(
                groupId, parentFolderId, name);

        long imageId = image.getImageId();

        description = image.getDescription();

        String[] assetTagNames =
            AssetTagLocalServiceUtil.getTagNames(IGImage.class.getName(), imageId);

        serviceContext.setAssetTagNames(assetTagNames);

        IGImageServiceUtil.updateImage(
            imageId, groupId, parentFolderId, name, description, file, contentType, serviceContext);
      } catch (NoSuchImageException nsie) {
        IGImageServiceUtil.addImage(
            groupId, parentFolderId, name, description, file, contentType, serviceContext);
      }

      return HttpServletResponse.SC_CREATED;
    } catch (PrincipalException pe) {
      return HttpServletResponse.SC_FORBIDDEN;
    } catch (PortalException pe) {
      if (_log.isWarnEnabled()) {
        _log.warn(pe, pe);
      }

      return HttpServletResponse.SC_CONFLICT;
    } catch (Exception e) {
      throw new WebDAVException(e);
    } finally {
      if (file != null) {
        file.delete();
      }
    }
  }
 @Override
 public String[] getAssetTagNames() throws SystemException {
   return AssetTagLocalServiceUtil.getTagNames(MBMessage.class.getName(), getMessageId());
 }
  @Override
  public AssetEntryQuery getAssetEntryQuery(
      PortletPreferences portletPreferences, long[] scopeGroupIds)
      throws PortalException, SystemException {

    AssetEntryQuery assetEntryQuery = new AssetEntryQuery();

    long[] allAssetCategoryIds = new long[0];
    long[] anyAssetCategoryIds = new long[0];
    long[] notAllAssetCategoryIds = new long[0];
    long[] notAnyAssetCategoryIds = new long[0];

    String[] allAssetTagNames = new String[0];
    String[] anyAssetTagNames = new String[0];
    String[] notAllAssetTagNames = new String[0];
    String[] notAnyAssetTagNames = new String[0];

    for (int i = 0; true; i++) {
      String[] queryValues = portletPreferences.getValues("queryValues" + i, null);

      if ((queryValues == null) || (queryValues.length == 0)) {
        break;
      }

      boolean queryContains =
          GetterUtil.getBoolean(portletPreferences.getValue("queryContains" + i, StringPool.BLANK));
      boolean queryAndOperator =
          GetterUtil.getBoolean(
              portletPreferences.getValue("queryAndOperator" + i, StringPool.BLANK));
      String queryName = portletPreferences.getValue("queryName" + i, StringPool.BLANK);

      if (Validator.equals(queryName, "assetCategories")) {
        long[] assetCategoryIds = GetterUtil.getLongValues(queryValues);

        if (queryContains && queryAndOperator) {
          allAssetCategoryIds = assetCategoryIds;
        } else if (queryContains && !queryAndOperator) {
          anyAssetCategoryIds = assetCategoryIds;
        } else if (!queryContains && queryAndOperator) {
          notAllAssetCategoryIds = assetCategoryIds;
        } else {
          notAnyAssetCategoryIds = assetCategoryIds;
        }
      } else {
        if (queryContains && queryAndOperator) {
          allAssetTagNames = queryValues;
        } else if (queryContains && !queryAndOperator) {
          anyAssetTagNames = queryValues;
        } else if (!queryContains && queryAndOperator) {
          notAllAssetTagNames = queryValues;
        } else {
          notAnyAssetTagNames = queryValues;
        }
      }
    }

    assetEntryQuery.setAllCategoryIds(allAssetCategoryIds);

    for (String assetTagName : allAssetTagNames) {
      long[] allAssetTagIds = AssetTagLocalServiceUtil.getTagIds(scopeGroupIds, assetTagName);

      assetEntryQuery.addAllTagIdsArray(allAssetTagIds);
    }

    assetEntryQuery.setAnyCategoryIds(anyAssetCategoryIds);

    long[] anyAssetTagIds = AssetTagLocalServiceUtil.getTagIds(scopeGroupIds, anyAssetTagNames);

    assetEntryQuery.setAnyTagIds(anyAssetTagIds);

    assetEntryQuery.setNotAllCategoryIds(notAllAssetCategoryIds);

    for (String assetTagName : notAllAssetTagNames) {
      long[] notAllAssetTagIds = AssetTagLocalServiceUtil.getTagIds(scopeGroupIds, assetTagName);

      assetEntryQuery.addNotAllTagIdsArray(notAllAssetTagIds);
    }

    assetEntryQuery.setNotAnyCategoryIds(notAnyAssetCategoryIds);

    long[] notAnyAssetTagIds =
        AssetTagLocalServiceUtil.getTagIds(scopeGroupIds, notAnyAssetTagNames);

    assetEntryQuery.setNotAnyTagIds(notAnyAssetTagIds);

    return assetEntryQuery;
  }