public List<KBArticle> getKBArticleAndAllDescendants(
      long resourcePrimKey, int status, OrderByComparator orderByComparator)
      throws SystemException {

    List<KBArticle> kbArticles = getKBArticles(new long[] {resourcePrimKey}, status, null);

    kbArticles = ListUtil.copy(kbArticles);

    Long[][] params = new Long[][] {new Long[] {resourcePrimKey}};

    while ((params = KnowledgeBaseUtil.getParams(params[0])) != null) {
      List<KBArticle> curKBArticles = null;

      if (status == WorkflowConstants.STATUS_ANY) {
        curKBArticles = kbArticlePersistence.findByP_L(ArrayUtil.toArray(params[1]), true);
      } else if (status == WorkflowConstants.STATUS_APPROVED) {
        curKBArticles = kbArticlePersistence.findByP_M(ArrayUtil.toArray(params[1]), true);
      } else {
        curKBArticles = kbArticlePersistence.findByP_S(ArrayUtil.toArray(params[1]), status);
      }

      kbArticles.addAll(curKBArticles);

      long[] resourcePrimKeys =
          StringUtil.split(ListUtil.toString(curKBArticles, "resourcePrimKey"), 0L);

      params[0] = ArrayUtil.append(params[0], ArrayUtil.toArray(resourcePrimKeys));
    }

    if (orderByComparator != null) {
      kbArticles = ListUtil.sort(kbArticles, orderByComparator);
    }

    return new UnmodifiableList<KBArticle>(kbArticles);
  }
  public List<KBArticle> getKBArticles(
      long[] resourcePrimKeys, int status, OrderByComparator orderByComparator)
      throws SystemException {

    List<KBArticle> kbArticles = new ArrayList<KBArticle>();

    Long[][] params = new Long[][] {ArrayUtil.toArray(resourcePrimKeys)};

    while ((params = KnowledgeBaseUtil.getParams(params[0])) != null) {
      List<KBArticle> curKBArticles = null;

      if (status == WorkflowConstants.STATUS_ANY) {
        curKBArticles = kbArticlePersistence.findByR_L(ArrayUtil.toArray(params[1]), true);
      } else if (status == WorkflowConstants.STATUS_APPROVED) {
        curKBArticles = kbArticlePersistence.findByR_M(ArrayUtil.toArray(params[1]), true);
      } else {
        curKBArticles = kbArticlePersistence.findByR_S(ArrayUtil.toArray(params[1]), status);
      }

      kbArticles.addAll(curKBArticles);
    }

    if (orderByComparator != null) {
      kbArticles = ListUtil.sort(kbArticles, orderByComparator);
    } else {
      kbArticles = KnowledgeBaseUtil.sort(resourcePrimKeys, kbArticles);
    }

    return new UnmodifiableList<KBArticle>(kbArticles);
  }
  @Override
  public Long[] getClassTypeIds(
      PortletPreferences portletPreferences, String className, Long[] availableClassTypeIds) {

    boolean anyAssetType =
        GetterUtil.getBoolean(
            portletPreferences.getValue("anyClassType" + className, Boolean.TRUE.toString()));

    if (anyAssetType) {
      return availableClassTypeIds;
    }

    long defaultClassTypeId =
        GetterUtil.getLong(portletPreferences.getValue("anyClassType" + className, null));

    if (defaultClassTypeId > 0) {
      return new Long[] {defaultClassTypeId};
    }

    Long[] classTypeIds =
        ArrayUtil.toArray(
            StringUtil.split(portletPreferences.getValue("classTypeIds" + className, null), 0L));

    if (classTypeIds != null) {
      return classTypeIds;
    } else {
      return availableClassTypeIds;
    }
  }
  protected long[] getLayoutIds(long groupId, boolean privateLayout, String layoutIdsJSON)
      throws Exception {

    if (Validator.isNull(layoutIdsJSON)) {
      return new long[0];
    }

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

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray(layoutIdsJSON);

    for (int i = 0; i < jsonArray.length(); ++i) {
      JSONObject jsonObject = jsonArray.getJSONObject(i);

      long layoutId = jsonObject.getLong("layoutId");

      if (layoutId > 0) {
        layoutIds.add(layoutId);
      }

      if (jsonObject.getBoolean("includeChildren")) {
        addLayoutIds(layoutIds, groupId, privateLayout, layoutId);
      }
    }

    return ArrayUtil.toArray(layoutIds.toArray(new Long[layoutIds.size()]));
  }
Пример #5
0
  public void synchronizePage(long folderId, int pageNumber, int messagesPerPage)
      throws PortalException {

    long[] remoteMessageIds = _imapAccessor.getMessageUIDs(folderId, pageNumber, messagesPerPage);

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

    for (int i = 0; i < remoteMessageIds.length; i++) {
      long remoteMessageId = remoteMessageIds[i];

      try {
        MessageLocalServiceUtil.getMessage(folderId, remoteMessageId);
      } catch (NoSuchMessageException nsme) {
        missingRemoteMessageIdsList.add(remoteMessageId);
      }
    }

    if (!missingRemoteMessageIdsList.isEmpty()) {
      long[] missingRemoteMessageIds =
          ArrayUtil.toArray(
              missingRemoteMessageIdsList.toArray(new Long[missingRemoteMessageIdsList.size()]));

      _imapAccessor.storeEnvelopes(folderId, missingRemoteMessageIds);
    }
  }
Пример #6
0
  @Override
  public void addNumber(String name, long[] values) {
    if (values == null) {
      return;
    }

    createNumberField(name, ArrayUtil.toArray(values));
  }
  @Override
  public long[] getCategoryIds(long groupId, long categoryId) {
    List<Long> categoryIds = new ArrayList<>();

    categoryIds.add(categoryId);

    getSubcategoryIds(categoryIds, groupId, categoryId);

    return ArrayUtil.toArray(categoryIds.toArray(new Long[categoryIds.size()]));
  }
  protected long[] filterRemoveUserIds(long groupId, long[] userIds) throws Exception {

    Set<Long> filteredUserIds = new HashSet<>(userIds.length);

    for (long userId : userIds) {
      if (_userLocalService.hasGroupUser(groupId, userId)) {
        filteredUserIds.add(userId);
      }
    }

    return ArrayUtil.toArray(filteredUserIds.toArray(new Long[filteredUserIds.size()]));
  }
Пример #9
0
  protected void readAssetLinks(PortletDataContext portletDataContext) throws Exception {

    String xml =
        portletDataContext.getZipEntryAsString(
            portletDataContext.getSourceRootPath() + "/links.xml");

    if (xml == null) {
      return;
    }

    Document document = SAXReaderUtil.read(xml);

    Element rootElement = document.getRootElement();

    List<Element> assetLinkElements = rootElement.elements("asset-link");

    for (Element assetLinkElement : assetLinkElements) {
      String sourceUuid = GetterUtil.getString(assetLinkElement.attributeValue("source-uuid"));
      String[] assetEntryUuidArray =
          StringUtil.split(GetterUtil.getString(assetLinkElement.attributeValue("target-uuids")));
      int assetLinkType = GetterUtil.getInteger(assetLinkElement.attributeValue("type"));

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

      for (String assetEntryUuid : assetEntryUuidArray) {
        try {
          AssetEntry assetEntry =
              AssetEntryLocalServiceUtil.getEntry(
                  portletDataContext.getScopeGroupId(), assetEntryUuid);

          assetEntryIds.add(assetEntry.getEntryId());
        } catch (NoSuchEntryException nsee) {
        }
      }

      if (assetEntryIds.isEmpty()) {
        continue;
      }

      long[] assetEntryIdsArray =
          ArrayUtil.toArray(assetEntryIds.toArray(new Long[assetEntryIds.size()]));

      try {
        AssetEntry assetEntry =
            AssetEntryLocalServiceUtil.getEntry(portletDataContext.getScopeGroupId(), sourceUuid);

        AssetLinkLocalServiceUtil.updateLinks(
            assetEntry.getUserId(), assetEntry.getEntryId(), assetEntryIdsArray, assetLinkType);
      } catch (NoSuchEntryException nsee) {
      }
    }
  }
Пример #10
0
  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()]));
  }
Пример #11
0
  private long[] _flattenTagIds(long[][] tagIdsArray) {
    List<Long> tagIdsList = new ArrayList<>();

    for (int i = 0; i < tagIdsArray.length; i++) {
      long[] tagIds = tagIdsArray[i];

      for (int j = 0; j < tagIds.length; j++) {
        long tagId = tagIds[j];

        tagIdsList.add(tagId);
      }
    }

    return ArrayUtil.toArray(tagIdsList.toArray(new Long[tagIdsList.size()]));
  }
    @Override
    public Void call() {
      Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);

      long[] userIds = ArrayUtil.toArray(_userIds.toArray(new Long[0]));

      try {
        indexer.reindex(userIds);
      } catch (SearchException se) {
        if (_log.isWarnEnabled()) {
          _log.warn(se, se);
        }
      }

      return null;
    }
Пример #13
0
  @Override
  public long[] getTagIds(long[] groupIds, String name) throws PortalException, SystemException {

    List<Long> tagIds = new ArrayList<Long>(groupIds.length);

    for (long groupId : groupIds) {
      try {
        AssetTag tag = getTag(groupId, name);

        tagIds.add(tag.getTagId());
      } catch (NoSuchTagException nste) {
      }
    }

    return ArrayUtil.toArray(tagIds.toArray(new Long[tagIds.size()]));
  }
Пример #14
0
  public static long[] filterCategoryIds(PermissionChecker permissionChecker, long[] categoryIds)
      throws PortalException {

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

    for (long categoryId : categoryIds) {
      AssetCategory category = AssetCategoryLocalServiceUtil.fetchCategory(categoryId);

      if ((category != null)
          && AssetCategoryPermission.contains(permissionChecker, categoryId, ActionKeys.VIEW)) {

        viewableCategoryIds.add(categoryId);
      }
    }

    return ArrayUtil.toArray(viewableCategoryIds.toArray(new Long[viewableCategoryIds.size()]));
  }
Пример #15
0
  private long[] _getCompanyIdsBySQL() throws SQLException {
    List<Long> companyIds = new ArrayList<>();

    String currentShardName = ShardUtil.setTargetSource(PropsValues.SHARD_DEFAULT_NAME);

    if (Validator.isNotNull(currentShardName)) {
      ShardUtil.pushCompanyService(PropsValues.SHARD_DEFAULT_NAME);
    }

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      ps = con.prepareStatement(_GET_COMPANY_IDS);

      if (Validator.isNotNull(currentShardName)) {
        ps.setString(1, currentShardName);
      } else {
        ps.setString(1, PropsValues.SHARD_DEFAULT_NAME);
      }

      rs = ps.executeQuery();

      while (rs.next()) {
        long companyId = rs.getLong("companyId");

        companyIds.add(companyId);
      }
    } finally {
      if (Validator.isNotNull(currentShardName)) {
        ShardUtil.popCompanyService();

        ShardUtil.setTargetSource(currentShardName);
      }

      DataAccess.cleanUp(con, ps, rs);
    }

    return ArrayUtil.toArray(companyIds.toArray(new Long[companyIds.size()]));
  }
  public long[] getCompanyIds() {
    Set<Long> companyIds = _serverStatistics.getCompanyIds();

    return ArrayUtil.toArray(companyIds.toArray(new Long[companyIds.size()]));
  }
  protected RenderedImage convert(RenderedImage renderedImage) throws Exception {

    int height = renderedImage.getHeight();
    int width = renderedImage.getWidth();

    SampleModel sampleModel = renderedImage.getSampleModel();
    ColorModel colorModel = renderedImage.getColorModel();

    Raster raster = renderedImage.getData();

    DataBuffer dataBuffer = raster.getDataBuffer();

    if (colorModel instanceof IndexColorModel) {
      IndexColorModel indexColorModel = (IndexColorModel) colorModel;

      int mapSize = indexColorModel.getMapSize();

      byte[][] data = new byte[4][mapSize];

      indexColorModel.getReds(data[0]);
      indexColorModel.getGreens(data[1]);
      indexColorModel.getBlues(data[2]);
      indexColorModel.getAlphas(data[3]);

      LookupTableJAI lookupTableJAI = new LookupTableJAI(data);

      renderedImage = LookupDescriptor.create(renderedImage, lookupTableJAI, null);
    } else if (sampleModel.getNumBands() == 2) {
      List<Byte> bytesList = new ArrayList<Byte>(height * width * _NUM_OF_BANDS);

      List<Byte> tempBytesList = new ArrayList<Byte>(_NUM_OF_BANDS);

      for (int i = 0; i < dataBuffer.getSize(); i++) {
        int mod = (i + 1) % 2;

        int elemPos = i;

        if (mod == 0) {
          tempBytesList.add((byte) dataBuffer.getElem(elemPos - 1));
          tempBytesList.add((byte) dataBuffer.getElem(elemPos - 1));
        }

        tempBytesList.add((byte) dataBuffer.getElem(elemPos));

        if (mod == 0) {
          Collections.reverse(tempBytesList);

          bytesList.addAll(tempBytesList);

          tempBytesList.clear();
        }
      }

      byte[] data = ArrayUtil.toArray(bytesList.toArray(new Byte[bytesList.size()]));

      DataBuffer newDataBuffer = new DataBufferByte(data, data.length);

      renderedImage = createRenderedImage(renderedImage, height, width, newDataBuffer);
    } else if (colorModel.getTransparency() != Transparency.TRANSLUCENT) {
      List<Byte> bytesList = new ArrayList<Byte>(height * width * _NUM_OF_BANDS);

      List<Byte> tempBytesList = new ArrayList<Byte>(_NUM_OF_BANDS);

      for (int i = 0; i < dataBuffer.getSize(); i++) {
        int mod = (i + 1) % 3;

        int elemPos = i;

        tempBytesList.add((byte) dataBuffer.getElem(elemPos));

        if (mod == 0) {
          tempBytesList.add((byte) 255);

          Collections.reverse(tempBytesList);

          bytesList.addAll(tempBytesList);

          tempBytesList.clear();
        }
      }

      byte[] data = ArrayUtil.toArray(bytesList.toArray(new Byte[bytesList.size()]));

      DataBuffer newDataBuffer = new DataBufferByte(data, data.length);

      renderedImage = createRenderedImage(renderedImage, height, width, newDataBuffer);
    }

    return renderedImage;
  }
  public int getFoldersAndArticlesCount(long groupId, List<Long> folderIds) throws SystemException {

    return journalArticlePersistence.filterCountByG_F(
        groupId, ArrayUtil.toArray(folderIds.toArray(new Long[folderIds.size()])));
  }