private static void _checkFileEntry(String[] pathArray) throws Exception {
    if (pathArray.length == 1) {
      long dlFileShortcutId = GetterUtil.getLong(pathArray[0]);

      DLFileShortcut dlFileShortcut = DLAppLocalServiceUtil.getFileShortcut(dlFileShortcutId);

      DLAppLocalServiceUtil.getFileEntry(dlFileShortcut.getToFileEntryId());
    } else if (pathArray.length == 2) {

      // Unable to check with UUID because of multiple repositories

    } else if (pathArray.length == 3) {
      long groupId = GetterUtil.getLong(pathArray[0]);
      long folderId = GetterUtil.getLong(pathArray[1]);
      String fileName = pathArray[2];

      try {
        DLAppLocalServiceUtil.getFileEntry(groupId, folderId, fileName);
      } catch (RepositoryException re) {
      }
    } else {
      long groupId = GetterUtil.getLong(pathArray[0]);

      String uuid = pathArray[3];

      try {
        DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
      } catch (RepositoryException re) {
      }
    }
  }
  protected String getBody(String className, long classPK, ServiceContext serviceContext)
      throws Exception {

    StringBundler sb = new StringBundler(11);

    sb.append("<div class=\"activity-body document\">");
    sb.append("<span class=\"document-thumbnail\"><img src=\"");

    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(classPK);

    FileVersion fileVersion = fileEntry.getFileVersion();

    String thumbnailSrc =
        DLUtil.getThumbnailSrc(fileEntry, fileVersion, null, serviceContext.getThemeDisplay());

    sb.append(thumbnailSrc);
    sb.append("\"></span>");
    sb.append("<div class=\"document-container\"><div class=\"title\">");
    sb.append(getPageTitle(className, classPK, serviceContext));
    sb.append("</div><div class=\"version\">");
    sb.append(serviceContext.translate("version-x", fileVersion.getVersion()));
    sb.append("</div><div class=\"document-content\">");

    AssetRenderer assetRenderer = getAssetRenderer(className, classPK);

    sb.append(StringUtil.shorten(assetRenderer.getSummary(serviceContext.getLocale()), 200));

    sb.append("</div></div></div>");

    return sb.toString();
  }
  @Override
  public void deletePortletFileEntry(long groupId, long folderId, String fileName)
      throws PortalException, SystemException {

    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(groupId, folderId, fileName);

    deletePortletFileEntry(fileEntry.getFileEntryId());
  }
  @Override
  public boolean isVisible(long classPK, int status) throws Exception {
    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(classPK);

    FileVersion fileVersion = fileEntry.getFileVersion();

    return isVisible(fileVersion.getStatus(), status);
  }
  @Override
  public void restorePortletFileEntryFromTrash(
      long groupId, long userId, long folderId, String fileName)
      throws PortalException, SystemException {

    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(groupId, folderId, fileName);

    restorePortletFileEntryFromTrash(userId, fileEntry.getFileEntryId());
  }
Example #6
0
  @Override
  public List<Object> getEntries(Hits hits) {
    List<Object> entries = new ArrayList<Object>();

    for (Document document : hits.getDocs()) {
      String entryClassName = GetterUtil.getString(document.get(Field.ENTRY_CLASS_NAME));
      long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      try {
        Object obj = null;

        if (entryClassName.equals(DLFileEntry.class.getName())) {
          obj = DLAppLocalServiceUtil.getFileEntry(entryClassPK);
        } else if (entryClassName.equals(MBMessage.class.getName())) {
          long classPK = GetterUtil.getLong(document.get(Field.CLASS_PK));

          DLAppLocalServiceUtil.getFileEntry(classPK);

          obj = MBMessageLocalServiceUtil.getMessage(entryClassPK);
        }

        entries.add(obj);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(
              "Documents and Media search index is stale and "
                  + "contains entry {className="
                  + entryClassName
                  + ", classPK="
                  + entryClassPK
                  + "}");
        }
      }
    }

    return entries;
  }
  @Override
  public boolean isVisibleRelatedEntry(long classPK, int status) throws Exception {

    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(classPK);

    if (fileEntry instanceof LiferayFileEntry) {
      DLFileEntry dlFileEntry = (DLFileEntry) fileEntry.getModel();

      if (dlFileEntry.isInHiddenFolder()) {
        Indexer indexer = IndexerRegistryUtil.getIndexer(dlFileEntry.getClassName());

        return indexer.isVisible(dlFileEntry.getClassPK(), status);
      }
    }

    return true;
  }
  @Override
  public void addRelatedEntryFields(Document document, Object obj) throws Exception {

    MBMessage message = (MBMessage) obj;

    FileEntry fileEntry = null;

    try {
      fileEntry = DLAppLocalServiceUtil.getFileEntry(message.getClassPK());
    } catch (Exception e) {
      return;
    }

    if (fileEntry instanceof LiferayFileEntry) {
      DLFileEntry dlFileEntry = (DLFileEntry) fileEntry.getModel();

      document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId());
      document.addKeyword(Field.HIDDEN, dlFileEntry.isInHiddenFolder());
      document.addKeyword(
          Field.TREE_PATH, StringUtil.split(dlFileEntry.getTreePath(), CharPool.SLASH));
    }
  }
  @Override
  protected String getLink(SocialActivity activity, ServiceContext serviceContext)
      throws Exception {

    StringBundler sb = new StringBundler(8);

    sb.append(serviceContext.getPortalURL());
    sb.append(serviceContext.getPathMain());
    sb.append("/document_library/get_file?groupId=");

    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(activity.getClassPK());

    sb.append(fileEntry.getRepositoryId());

    sb.append("&folderId=");
    sb.append(fileEntry.getFolderId());
    sb.append("&title=");
    sb.append(HttpUtil.encodeURL(fileEntry.getTitle()));

    String downloadLink = wrapLink(sb.toString(), serviceContext.translate("download"));

    return "<span>" + downloadLink + "</span>";
  }
  @Override
  protected String getTitlePattern(String groupName, SocialActivity activity) throws Exception {

    String titlePattern = StringPool.BLANK;

    if (activity.getType() == SocialActivityKeyConstants.DL_ADD_FILE_ENTRY) {

      titlePattern = "uploaded-a-new-document";
    } else if (activity.getType() == SocialActivityKeyConstants.DL_UPDATE_FILE_ENTRY) {

      titlePattern = "updated-a-document";
    } else {
      return StringPool.BLANK;
    }

    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(activity.getClassPK());

    if (fileEntry.getFolderId() > 0) {
      titlePattern = titlePattern.concat("-in-the-x-folder");
    }

    return titlePattern;
  }
  protected String getFolderLink(long classPK, ServiceContext serviceContext) throws Exception {

    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(classPK);

    if (fileEntry.getFolderId() <= 0) {
      return null;
    }

    StringBundler sb = new StringBundler(6);

    sb.append(serviceContext.getPortalURL());
    sb.append(serviceContext.getPathMain());
    sb.append("/document_library/find_folder?groupId=");
    sb.append(fileEntry.getRepositoryId());
    sb.append("&folderId=");
    sb.append(fileEntry.getFolderId());

    Folder folder = fileEntry.getFolder();

    String folderName = HtmlUtil.escape(folder.getName());

    return wrapLink(sb.toString(), folderName);
  }
  @Override
  public AssetRenderer getAssetRenderer(long classPK, int type)
      throws PortalException, SystemException {

    FileEntry fileEntry = null;
    FileVersion fileVersion = null;

    if (type == TYPE_LATEST) {
      fileVersion = DLAppLocalServiceUtil.getFileVersion(classPK);

      fileEntry = fileVersion.getFileEntry();
    } else {
      fileEntry = DLAppLocalServiceUtil.getFileEntry(classPK);

      fileVersion = fileEntry.getFileVersion();
    }

    DLFileEntryAssetRenderer dlFileEntryAssetRenderer =
        new DLFileEntryAssetRenderer(fileEntry, fileVersion);

    dlFileEntryAssetRenderer.setAssetRendererType(type);

    return dlFileEntryAssetRenderer;
  }
  @Override
  protected long getGroupId(long primaryKey) throws Exception {
    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(primaryKey);

    return fileEntry.getRepositoryId();
  }
  protected Organization updateOrganization(ActionRequest actionRequest) throws Exception {

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

    long organizationId = ParamUtil.getLong(actionRequest, "organizationId");

    long parentOrganizationId =
        ParamUtil.getLong(
            actionRequest,
            "parentOrganizationSearchContainerPrimaryKeys",
            OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID);
    String name = ParamUtil.getString(actionRequest, "name");
    int statusId = ParamUtil.getInteger(actionRequest, "statusId");
    String type = ParamUtil.getString(actionRequest, "type");
    long regionId = ParamUtil.getLong(actionRequest, "regionId");
    long countryId = ParamUtil.getLong(actionRequest, "countryId");
    String comments = ParamUtil.getString(actionRequest, "comments");
    boolean deleteLogo = ParamUtil.getBoolean(actionRequest, "deleteLogo");

    byte[] logoBytes = null;

    long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId");

    if (fileEntryId > 0) {
      FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(fileEntryId);

      logoBytes = FileUtil.getBytes(fileEntry.getContentStream());
    }

    boolean site = ParamUtil.getBoolean(actionRequest, "site");
    List<Address> addresses = UsersAdminUtil.getAddresses(actionRequest);
    List<EmailAddress> emailAddresses = UsersAdminUtil.getEmailAddresses(actionRequest);
    List<OrgLabor> orgLabors = UsersAdminUtil.getOrgLabors(actionRequest);
    List<Phone> phones = UsersAdminUtil.getPhones(actionRequest);
    List<Website> websites = UsersAdminUtil.getWebsites(actionRequest);

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(Organization.class.getName(), actionRequest);

    Organization organization = null;

    if (organizationId <= 0) {

      // Add organization

      organization =
          OrganizationServiceUtil.addOrganization(
              parentOrganizationId,
              name,
              type,
              regionId,
              countryId,
              statusId,
              comments,
              site,
              addresses,
              emailAddresses,
              orgLabors,
              phones,
              websites,
              serviceContext);
    } else {

      // Update organization

      organization =
          OrganizationServiceUtil.updateOrganization(
              organizationId,
              parentOrganizationId,
              name,
              type,
              regionId,
              countryId,
              statusId,
              comments,
              !deleteLogo,
              logoBytes,
              site,
              addresses,
              emailAddresses,
              orgLabors,
              phones,
              websites,
              serviceContext);
    }

    // Layout set prototypes

    long publicLayoutSetPrototypeId =
        ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId");
    long privateLayoutSetPrototypeId =
        ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId");
    boolean publicLayoutSetPrototypeLinkEnabled =
        ParamUtil.getBoolean(
            actionRequest, "publicLayoutSetPrototypeLinkEnabled", (publicLayoutSetPrototypeId > 0));
    boolean privateLayoutSetPrototypeLinkEnabled =
        ParamUtil.getBoolean(
            actionRequest,
            "privateLayoutSetPrototypeLinkEnabled",
            (privateLayoutSetPrototypeId > 0));

    Group organizationGroup = organization.getGroup();

    if (GroupPermissionUtil.contains(
        themeDisplay.getPermissionChecker(), organizationGroup, ActionKeys.UPDATE)) {

      SitesUtil.updateLayoutSetPrototypesLinks(
          organizationGroup,
          publicLayoutSetPrototypeId,
          privateLayoutSetPrototypeId,
          publicLayoutSetPrototypeLinkEnabled,
          privateLayoutSetPrototypeLinkEnabled);
    }

    // Reminder queries

    String reminderQueries = actionRequest.getParameter("reminderQueries");

    PortletPreferences portletPreferences = organization.getPreferences();

    LocalizationUtil.setLocalizedPreferencesValues(
        actionRequest, portletPreferences, "reminderQueries");

    portletPreferences.setValue("reminderQueries", reminderQueries);

    portletPreferences.store();

    return organization;
  }
Example #15
0
  protected static String exportDLFileEntries(
      PortletDataContext portletDataContext,
      Element dlFileEntryTypesElement,
      Element dlFoldersElement,
      Element dlFileEntriesElement,
      Element dlFileRanksElement,
      Element dlRepositoriesElement,
      Element dlRepositoryEntriesElement,
      Element entityElement,
      String content,
      boolean checkDateRange)
      throws Exception {

    Group group = GroupLocalServiceUtil.getGroup(portletDataContext.getGroupId());

    if (group.isStagingGroup()) {
      group = group.getLiveGroup();
    }

    if (group.isStaged()
        && !group.isStagedRemotely()
        && !group.isStagedPortlet(PortletKeys.DOCUMENT_LIBRARY)) {

      return content;
    }

    StringBuilder sb = new StringBuilder(content);

    int beginPos = content.length();
    int currentLocation = -1;

    boolean legacyURL = true;

    while (true) {
      String contextPath = PortalUtil.getPathContext();

      currentLocation =
          content.lastIndexOf(contextPath.concat("/c/document_library/get_file?"), beginPos);

      if (currentLocation == -1) {
        currentLocation =
            content.lastIndexOf(contextPath.concat("/image/image_gallery?"), beginPos);
      }

      if (currentLocation == -1) {
        currentLocation = content.lastIndexOf(contextPath.concat("/documents/"), beginPos);

        legacyURL = false;
      }

      if (currentLocation == -1) {
        return sb.toString();
      }

      beginPos = currentLocation + contextPath.length();

      int endPos1 = content.indexOf(CharPool.APOSTROPHE, beginPos);
      int endPos2 = content.indexOf(CharPool.CLOSE_BRACKET, beginPos);
      int endPos3 = content.indexOf(CharPool.CLOSE_CURLY_BRACE, beginPos);
      int endPos4 = content.indexOf(CharPool.CLOSE_PARENTHESIS, beginPos);
      int endPos5 = content.indexOf(CharPool.LESS_THAN, beginPos);
      int endPos6 = content.indexOf(CharPool.QUESTION, beginPos);
      int endPos7 = content.indexOf(CharPool.QUOTE, beginPos);
      int endPos8 = content.indexOf(CharPool.SPACE, beginPos);

      int endPos = endPos1;

      if ((endPos == -1) || ((endPos2 != -1) && (endPos2 < endPos))) {
        endPos = endPos2;
      }

      if ((endPos == -1) || ((endPos3 != -1) && (endPos3 < endPos))) {
        endPos = endPos3;
      }

      if ((endPos == -1) || ((endPos4 != -1) && (endPos4 < endPos))) {
        endPos = endPos4;
      }

      if ((endPos == -1) || ((endPos5 != -1) && (endPos5 < endPos))) {
        endPos = endPos5;
      }

      if ((endPos == -1) || ((endPos6 != -1) && (endPos6 < endPos) && !legacyURL)) {

        endPos = endPos6;
      }

      if ((endPos == -1) || ((endPos7 != -1) && (endPos7 < endPos))) {
        endPos = endPos7;
      }

      if ((endPos == -1) || ((endPos8 != -1) && (endPos8 < endPos))) {
        endPos = endPos8;
      }

      if ((beginPos == -1) || (endPos == -1)) {
        break;
      }

      try {
        String oldParameters = content.substring(beginPos, endPos);

        while (oldParameters.contains(StringPool.AMPERSAND_ENCODED)) {
          oldParameters = oldParameters.replace(StringPool.AMPERSAND_ENCODED, StringPool.AMPERSAND);
        }

        Map<String, String[]> map = new HashMap<String, String[]>();

        if (oldParameters.startsWith("/documents/")) {
          String[] pathArray = oldParameters.split(StringPool.SLASH);

          map.put("groupId", new String[] {pathArray[2]});

          if (pathArray.length == 4) {
            map.put("uuid", new String[] {pathArray[3]});
          } else if (pathArray.length == 5) {
            map.put("folderId", new String[] {pathArray[3]});

            String title = HttpUtil.decodeURL(pathArray[4]);

            int pos = title.indexOf(StringPool.QUESTION);

            if (pos != -1) {
              title = title.substring(0, pos);
            }

            map.put("title", new String[] {title});
          } else if (pathArray.length > 5) {
            String uuid = pathArray[5];

            int pos = uuid.indexOf(StringPool.QUESTION);

            if (pos != -1) {
              uuid = uuid.substring(0, pos);
            }

            map.put("uuid", new String[] {uuid});
          }
        } else {
          oldParameters = oldParameters.substring(oldParameters.indexOf(CharPool.QUESTION) + 1);

          map = HttpUtil.parameterMapFromString(oldParameters);
        }

        FileEntry fileEntry = null;

        String uuid = MapUtil.getString(map, "uuid");

        if (Validator.isNotNull(uuid)) {
          String groupIdString = MapUtil.getString(map, "groupId");

          long groupId = GetterUtil.getLong(groupIdString);

          if (groupIdString.equals("@group_id@")) {
            groupId = portletDataContext.getScopeGroupId();
          }

          fileEntry = DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
        } else {
          String folderIdString = MapUtil.getString(map, "folderId");

          if (Validator.isNotNull(folderIdString)) {
            long folderId = GetterUtil.getLong(folderIdString);
            String name = MapUtil.getString(map, "name");
            String title = MapUtil.getString(map, "title");

            String groupIdString = MapUtil.getString(map, "groupId");

            long groupId = GetterUtil.getLong(groupIdString);

            if (groupIdString.equals("@group_id@")) {
              groupId = portletDataContext.getScopeGroupId();
            }

            if (Validator.isNotNull(title)) {
              fileEntry = DLAppLocalServiceUtil.getFileEntry(groupId, folderId, title);
            } else {
              DLFileEntry dlFileEntry =
                  DLFileEntryLocalServiceUtil.getFileEntryByName(groupId, folderId, name);

              fileEntry = new LiferayFileEntry(dlFileEntry);
            }
          } else if (map.containsKey("image_id")
              || map.containsKey("img_id")
              || map.containsKey("i_id")) {

            long imageId = MapUtil.getLong(map, "image_id");

            if (imageId <= 0) {
              imageId = MapUtil.getLong(map, "img_id");

              if (imageId <= 0) {
                imageId = MapUtil.getLong(map, "i_id");
              }
            }

            DLFileEntry dlFileEntry =
                DLFileEntryLocalServiceUtil.fetchFileEntryByAnyImageId(imageId);

            if (dlFileEntry != null) {
              fileEntry = new LiferayFileEntry(dlFileEntry);
            }
          }
        }

        if (fileEntry == null) {
          beginPos--;

          continue;
        }

        beginPos = currentLocation;

        DLPortletDataHandler.exportFileEntry(
            portletDataContext,
            dlFileEntryTypesElement,
            dlFoldersElement,
            dlFileEntriesElement,
            dlFileRanksElement,
            dlRepositoriesElement,
            dlRepositoryEntriesElement,
            fileEntry,
            checkDateRange);

        Element dlReferenceElement = entityElement.addElement("dl-reference");

        dlReferenceElement.addAttribute(
            "default-repository", String.valueOf(fileEntry.isDefaultRepository()));

        String path = null;

        if (fileEntry.isDefaultRepository()) {
          path = DLPortletDataHandler.getFileEntryPath(portletDataContext, fileEntry);

        } else {
          path =
              DLPortletDataHandler.getRepositoryEntryPath(
                  portletDataContext, fileEntry.getFileEntryId());
        }

        dlReferenceElement.addAttribute("path", path);

        String dlReference = "[$dl-reference=" + path + "$]";

        sb.replace(beginPos, endPos, dlReference);
      } catch (Exception e) {
        if (_log.isDebugEnabled()) {
          _log.debug(e, e);
        } else if (_log.isWarnEnabled()) {
          _log.warn(e.getMessage());
        }
      }

      beginPos--;
    }

    return sb.toString();
  }
  @Override
  public FileEntry getPortletFileEntry(long fileEntryId) throws PortalException, SystemException {

    return DLAppLocalServiceUtil.getFileEntry(fileEntryId);
  }
  @Override
  public FileEntry getPortletFileEntry(long groupId, long folderId, String fileName)
      throws PortalException, SystemException {

    return DLAppLocalServiceUtil.getFileEntry(groupId, folderId, fileName);
  }