protected FileEntry updateFileEntry(
      long fileEntryId, String sourceFileName, String title, boolean majorVersion)
      throws Exception {

    String description = StringPool.BLANK;
    String changeLog = StringPool.BLANK;

    byte[] bytes = null;

    if (Validator.isNotNull(sourceFileName)) {
      bytes = CONTENT.getBytes();
    }

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    return DLAppServiceUtil.updateFileEntry(
        fileEntryId,
        sourceFileName,
        ContentTypes.TEXT_PLAIN,
        title,
        description,
        changeLog,
        majorVersion,
        bytes,
        serviceContext);
  }
  protected FileEntry addFileEntry(
      long folderId, String sourceFileName, String title, byte[] bytes, int workflowAction)
      throws Exception {

    String description = StringPool.BLANK;
    String changeLog = StringPool.BLANK;

    if ((bytes == null) && Validator.isNotNull(sourceFileName)) {
      bytes = CONTENT.getBytes();
    }

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setWorkflowAction(workflowAction);

    return DLAppServiceUtil.addFileEntry(
        TestPropsValues.getGroupId(),
        folderId,
        sourceFileName,
        ContentTypes.TEXT_PLAIN,
        title,
        description,
        changeLog,
        bytes,
        serviceContext);
  }
  @Before
  public void setUp() throws Exception {
    _group = ServiceTestUtil.addGroup();

    String name = "Test Folder";
    String description = "This is a test folder.";

    ServiceContext serviceContext = new ServiceContext();

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

    try {
      DLAppServiceHttp.deleteFolder(
          TestPropsValues.getHttpPrincipal(),
          _group.getGroupId(),
          DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
          name);
    } catch (Exception e) {
    }

    _folder =
        DLAppServiceHttp.addFolder(
            TestPropsValues.getHttpPrincipal(),
            _group.getGroupId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            name,
            description,
            serviceContext);
  }
  @Override
  public Folder addAttachmentsFolder() throws PortalException, SystemException {

    if (_attachmentsFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

      return PortletFileRepositoryUtil.getPortletFolder(_attachmentsFolderId);
    }

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    Repository repository =
        PortletFileRepositoryUtil.addPortletRepository(
            getGroupId(), PortletKeys.MESSAGE_BOARDS, serviceContext);

    MBThread thread = getThread();

    Folder threadFolder = thread.addAttachmentsFolder();

    Folder folder =
        PortletFileRepositoryUtil.addPortletFolder(
            getUserId(),
            repository.getRepositoryId(),
            threadFolder.getFolderId(),
            String.valueOf(getMessageId()),
            serviceContext);

    _attachmentsFolderId = folder.getFolderId();

    return folder;
  }
  @Override
  public long getAttachmentsFolderId() {
    if (_attachmentsFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

      return _attachmentsFolderId;
    }

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    Repository repository =
        PortletFileRepositoryUtil.fetchPortletRepository(getGroupId(), PortletKeys.BACKGROUND_TASK);

    if (repository == null) {
      return DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
    }

    try {
      Folder folder =
          PortletFileRepositoryUtil.getPortletFolder(
              repository.getRepositoryId(),
              DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
              String.valueOf(getBackgroundTaskId()));

      _attachmentsFolderId = folder.getFolderId();
    } catch (Exception e) {
    }

    return _attachmentsFolderId;
  }
  protected void addFileEntry(boolean rootFolder) throws PortalException, SystemException {

    long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;

    if (!rootFolder) {
      folderId = _folder.getFolderId();
    }

    String fileName = "Title.txt";
    String description = StringPool.BLANK;
    String changeLog = StringPool.BLANK;

    String content = "Content: Enterprise. Open Source. For Life.";

    byte[] bytes = content.getBytes();

    ServiceContext serviceContext = new ServiceContext();

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

    _fileEntry =
        DLAppServiceUtil.addFileEntry(
            _groupId, folderId, fileName, description, changeLog, bytes, serviceContext);
  }
  protected void importAssetVocabulary(
      PortletDataContext portletDataContext,
      Map<Long, Long> assetVocabularyPKs,
      Element assetVocabularyElement,
      AssetVocabulary assetVocabulary)
      throws Exception {

    long userId = portletDataContext.getUserId(assetVocabulary.getUserUuid());
    long groupId = portletDataContext.getScopeGroupId();

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setCreateDate(assetVocabulary.getCreateDate());
    serviceContext.setModifiedDate(assetVocabulary.getModifiedDate());
    serviceContext.setScopeGroupId(portletDataContext.getScopeGroupId());

    AssetVocabulary importedAssetVocabulary = null;

    AssetVocabulary existingAssetVocabulary =
        AssetVocabularyUtil.fetchByG_N(groupId, assetVocabulary.getName());

    if (existingAssetVocabulary == null) {
      Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(portletDataContext.getCompanyId());

      existingAssetVocabulary =
          AssetVocabularyUtil.fetchByG_N(companyGroup.getGroupId(), assetVocabulary.getName());
    }

    if (existingAssetVocabulary == null) {
      serviceContext.setUuid(assetVocabulary.getUuid());

      importedAssetVocabulary =
          AssetVocabularyLocalServiceUtil.addVocabulary(
              userId,
              assetVocabulary.getTitle(),
              getAssetVocabularyTitleMap(assetVocabulary),
              assetVocabulary.getDescriptionMap(),
              assetVocabulary.getSettings(),
              serviceContext);
    } else {
      importedAssetVocabulary =
          AssetVocabularyLocalServiceUtil.updateVocabulary(
              existingAssetVocabulary.getVocabularyId(),
              assetVocabulary.getTitle(),
              getAssetVocabularyTitleMap(assetVocabulary),
              assetVocabulary.getDescriptionMap(),
              assetVocabulary.getSettings(),
              serviceContext);
    }

    assetVocabularyPKs.put(
        assetVocabulary.getVocabularyId(), importedAssetVocabulary.getVocabularyId());

    portletDataContext.importPermissions(
        AssetVocabulary.class,
        assetVocabulary.getVocabularyId(),
        importedAssetVocabulary.getVocabularyId());
  }
  @Override
  public Folder addAttachmentsFolder() throws PortalException {
    if (_attachmentsFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

      return PortletFileRepositoryUtil.getPortletFolder(_attachmentsFolderId);
    }

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    Repository repository =
        PortletFileRepositoryUtil.addPortletRepository(
            getGroupId(), PortletKeys.BACKGROUND_TASK, serviceContext);

    Folder folder =
        PortletFileRepositoryUtil.addPortletFolder(
            getUserId(),
            repository.getRepositoryId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            String.valueOf(getBackgroundTaskId()),
            serviceContext);

    _attachmentsFolderId = folder.getFolderId();

    return folder;
  }
  protected String fileUpload(
      CommandArgument commandArgument, String fileName, File file, String extension) {

    try {
      Group group = commandArgument.getCurrentGroup();

      Folder folder = _getFolder(group.getGroupId(), commandArgument.getCurrentFolder());

      long folderId = folder.getFolderId();
      String title = fileName;
      String description = StringPool.BLANK;
      String changeLog = StringPool.BLANK;

      ServiceContext serviceContext = new ServiceContext();

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

      DLAppServiceUtil.addFileEntry(
          group.getGroupId(), folderId, title, description, changeLog, file, serviceContext);
    } catch (Exception e) {
      throw new FCKException(e);
    }

    return "0";
  }
  public static Folder getGadgetEditorRootFolder(long repositoryId) throws Exception {

    Folder folder = null;

    try {
      folder =
          DLAppServiceUtil.getFolder(
              repositoryId,
              DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
              _GADGET_EDITOR_ROOT_FOLDER_NAME);
    } catch (Exception e) {
    }

    if (folder == null) {
      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddGroupPermissions(true);
      serviceContext.setAddGuestPermissions(true);
      serviceContext.setScopeGroupId(repositoryId);

      folder =
          DLAppServiceUtil.addFolder(
              repositoryId,
              DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
              _GADGET_EDITOR_ROOT_FOLDER_NAME,
              StringPool.BLANK,
              serviceContext);
    }

    return folder;
  }
  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()]);
  }
  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 testUserPermissions(
      boolean addBaseModelPermission, boolean addParentBaseModelPermission) throws Exception {

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId());

    searchContext.setKeywords(getSearchKeywords());

    int initialBaseModelsSearchCount =
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext);

    serviceContext.setAddGroupPermissions(addParentBaseModelPermission);
    serviceContext.setAddGuestPermissions(addParentBaseModelPermission);

    BaseModel<?> parentBaseModel = getParentBaseModel(group, serviceContext);

    serviceContext.setAddGroupPermissions(addBaseModelPermission);
    serviceContext.setAddGuestPermissions(addBaseModelPermission);

    baseModel = addBaseModel(parentBaseModel, true, getSearchKeywords(), serviceContext);

    User user = UserTestUtil.addUser(null, 0);

    PermissionChecker originalPermissionChecker = PermissionThreadLocal.getPermissionChecker();

    try {
      PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user);

      PermissionThreadLocal.setPermissionChecker(permissionChecker);

      searchContext.setUserId(user.getUserId());

      int baseModelsCount = initialBaseModelsSearchCount;

      if (addBaseModelPermission && !isCheckBaseModelPermission()) {
        baseModelsCount++;
      }

      Assert.assertEquals(
          baseModelsCount,
          searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
    } finally {
      PermissionThreadLocal.setPermissionChecker(originalPermissionChecker);
    }
  }
  protected ServiceContext getServiceContext() {
    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    return serviceContext;
  }
  public int copyCollectionResource(
      WebDAVRequest webDavRequest,
      Resource resource,
      String destination,
      boolean overwrite,
      long depth)
      throws WebDAVException {

    try {
      String[] destinationArray = WebDAVUtil.getPathArray(destination, true);

      long companyId = webDavRequest.getCompanyId();

      long parentFolderId = IGFolderConstants.DEFAULT_PARENT_FOLDER_ID;

      try {
        parentFolderId = getParentFolderId(companyId, destinationArray);
      } catch (NoSuchFolderException nsfe) {
        return HttpServletResponse.SC_CONFLICT;
      }

      IGFolder folder = (IGFolder) resource.getModel();

      long groupId = WebDAVUtil.getGroupId(companyId, destination);
      String name = WebDAVUtil.getResourceName(destinationArray);
      String description = folder.getDescription();

      int status = HttpServletResponse.SC_CREATED;

      if (overwrite) {
        if (deleteResource(groupId, parentFolderId, name)) {
          status = HttpServletResponse.SC_NO_CONTENT;
        }
      }

      ServiceContext serviceContext = new ServiceContext();

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

      if (depth == 0) {
        IGFolderServiceUtil.addFolder(parentFolderId, name, description, serviceContext);
      } else {
        IGFolderServiceUtil.copyFolder(
            folder.getFolderId(), parentFolderId, name, description, serviceContext);
      }

      return status;
    } catch (DuplicateFolderNameException dfne) {
      return HttpServletResponse.SC_PRECONDITION_FAILED;
    } catch (PrincipalException pe) {
      return HttpServletResponse.SC_FORBIDDEN;
    } catch (Exception e) {
      throw new WebDAVException(e);
    }
  }
  protected DLFileShortcut addDLFileShortcut(FileEntry fileEntry, long folderId) throws Exception {

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    return DLAppServiceUtil.addFileShortcut(
        TestPropsValues.getGroupId(), folderId, fileEntry.getFileEntryId(), serviceContext);
  }
Exemple #17
0
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
    String fileLogoParam = "file";
    File file = uploadRequest.getFile(fileLogoParam);
    ServiceContext sc;

    try {

      sc = ServiceContextFactory.getInstance(this.getClass().getName(), actionRequest);
      // Make sure the uploaded images can be view by any one;
      sc.setAddCommunityPermissions(true);
      sc.setAddGuestPermissions(true);

      IGFolder folder = Functions.getIGFolder(sc);
      // String fileName = uploadRequest.getFileName(fileLogoParam);
      String contentType = uploadRequest.getContentType(fileLogoParam);

      IGImage image =
          IGImageLocalServiceUtil.addImage(
              sc.getUserId(),
              folder.getFolderId(),
              file.getName() + (new Time()).toString(),
              file.getName(),
              file,
              contentType,
              sc);

      HttpServletRequest servletRequest = PortalUtil.getHttpServletRequest(actionRequest);
      String res =
          image.getImageId()
              + "|"
              + ProGateUtil.getImageURL(image.getSmallImageId(), servletRequest)
              + "|"
              + ProGateUtil.getImageURL(image.getLargeImageId(), servletRequest);
      ProGateUtil.servletPrint(actionResponse, res);

    } catch (PortalException e) {
      // TODO Auto-generated catch block

      e.printStackTrace();
    } catch (SystemException se) {

      se.printStackTrace();
    } catch (NullPointerException e2) {

      e2.printStackTrace();
    }
  }
  @Override
  public FileEntry addPortletFileEntry(
      long groupId,
      long userId,
      String className,
      long classPK,
      String portletId,
      long folderId,
      File file,
      String fileName,
      String mimeType,
      boolean indexingEnabled)
      throws PortalException, SystemException {

    if (Validator.isNull(fileName)) {
      return null;
    }

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    Repository repository = addPortletRepository(groupId, portletId, serviceContext);

    serviceContext.setAttribute("className", className);
    serviceContext.setAttribute("classPK", String.valueOf(classPK));
    serviceContext.setIndexingEnabled(indexingEnabled);

    if (Validator.isNull(mimeType) || mimeType.equals(ContentTypes.APPLICATION_OCTET_STREAM)) {

      mimeType = MimeTypesUtil.getContentType(file, fileName);
    }

    boolean dlAppHelperEnabled = DLAppHelperThreadLocal.isEnabled();

    try {
      DLAppHelperThreadLocal.setEnabled(false);

      return DLAppLocalServiceUtil.addFileEntry(
          userId,
          repository.getRepositoryId(),
          folderId,
          fileName,
          mimeType,
          fileName,
          StringPool.BLANK,
          StringPool.BLANK,
          file,
          serviceContext);
    } finally {
      DLAppHelperThreadLocal.setEnabled(dlAppHelperEnabled);
    }
  }
  protected DLFileRank addDLFileRank(long fileEntryId) throws Exception {
    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    return DLAppLocalServiceUtil.addFileRank(
        TestPropsValues.getGroupId(),
        TestPropsValues.getCompanyId(),
        TestPropsValues.getUserId(),
        fileEntryId,
        serviceContext);
  }
  protected ServiceContext createServiceContext(
      PortletDataContext portletDataContext, AssetTag assetTag) {

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setCreateDate(assetTag.getCreateDate());
    serviceContext.setModifiedDate(assetTag.getModifiedDate());
    serviceContext.setScopeGroupId(portletDataContext.getScopeGroupId());

    return serviceContext;
  }
Exemple #21
0
  public static WikiNode getFirstVisibleNode(PortletRequest portletRequest)
      throws PortalException, SystemException {

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

    WikiNode node = null;

    int nodesCount = WikiNodeLocalServiceUtil.getNodesCount(themeDisplay.getScopeGroupId());

    if (nodesCount == 0) {
      Layout layout = themeDisplay.getLayout();

      ServiceContext serviceContext =
          ServiceContextFactory.getInstance(WikiNode.class.getName(), portletRequest);

      serviceContext.setAddCommunityPermissions(true);

      if (layout.isPublicLayout()) {
        serviceContext.setAddGuestPermissions(true);
      } else {
        serviceContext.setAddGuestPermissions(false);
      }

      node = WikiNodeLocalServiceUtil.addDefaultNode(themeDisplay.getUserId(), serviceContext);
    } else {
      node = WikiUtil.getFirstNode(portletRequest);

      if (node == null) {
        throw new PrincipalException();
      }

      return node;
    }

    portletRequest.setAttribute(WebKeys.WIKI_NODE, node);

    return node;
  }
  @Test
  public void testAddFileEntryWithInvalidMimeType() throws Exception {
    long folderId = parentFolder.getFolderId();
    String description = StringPool.BLANK;
    String changeLog = StringPool.BLANK;

    ServiceContext serviceContext = new ServiceContext();

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

    try {
      String name = "InvalidMime.txt";
      byte[] bytes = CONTENT.getBytes();

      FileEntry fileEntry =
          DLAppServiceUtil.addFileEntry(
              group.getGroupId(),
              folderId,
              name,
              ContentTypes.APPLICATION_OCTET_STREAM,
              name,
              description,
              changeLog,
              bytes,
              serviceContext);

      Assert.assertEquals(ContentTypes.TEXT_PLAIN, fileEntry.getMimeType());

      name = "InvalidMime";

      fileEntry =
          DLAppServiceUtil.updateFileEntry(
              fileEntry.getFileEntryId(),
              name,
              null,
              name,
              description,
              changeLog,
              true,
              bytes,
              serviceContext);

      Assert.assertEquals(ContentTypes.TEXT_PLAIN, fileEntry.getMimeType());
    } catch (Exception e) {
      Assert.fail("Unable to add file with invalid mime type " + StackTraceUtil.getStackTrace(e));
    }
  }
Exemple #23
0
  public static int addResource(WebDAVRequest webDavRequest, long classNameId) throws Exception {

    String[] pathArray = webDavRequest.getPathArray();

    if (pathArray.length != 4) {
      return HttpServletResponse.SC_FORBIDDEN;
    }

    String type = pathArray[2];
    String typeId = pathArray[3];

    if (type.equals(TYPE_STRUCTURES)) {
      HttpServletRequest request = webDavRequest.getHttpServletRequest();

      String xsd = StringUtil.read(request.getInputStream());

      String defaultLocale = LocalizationUtil.getDefaultLocale(xsd);

      Map<Locale, String> nameMap = new HashMap<Locale, String>();

      nameMap.put(LocaleUtil.fromLanguageId(defaultLocale), typeId);

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddGroupPermissions(true);
      serviceContext.setAddGuestPermissions(true);

      DDMStructureLocalServiceUtil.addStructure(
          webDavRequest.getUserId(),
          webDavRequest.getGroupId(),
          classNameId,
          nameMap,
          null,
          xsd,
          serviceContext);

      return HttpServletResponse.SC_CREATED;
    } else if (type.equals(TYPE_TEMPLATES)) {

      // DDM templates can not be added via WebDAV because there is no way
      // to know the associated class name or class PK

      return HttpServletResponse.SC_FORBIDDEN;
    }

    return HttpServletResponse.SC_FORBIDDEN;
  }
  /**
   * Returns a new service context object identical to this service context object.
   *
   * @return a new service context object
   */
  @Override
  public Object clone() {
    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(isAddGroupPermissions());
    serviceContext.setAddGuestPermissions(isAddGuestPermissions());
    serviceContext.setAssetCategoryIds(getAssetCategoryIds());
    serviceContext.setAssetEntryVisible(isAssetEntryVisible());
    serviceContext.setAssetLinkEntryIds(getAssetLinkEntryIds());
    serviceContext.setAssetTagNames(getAssetTagNames());
    serviceContext.setAttributes(getAttributes());
    serviceContext.setCommand(getCommand());
    serviceContext.setCompanyId(getCompanyId());
    serviceContext.setCreateDate(getCreateDate());
    serviceContext.setCurrentURL(getCurrentURL());
    serviceContext.setExpandoBridgeAttributes(getExpandoBridgeAttributes());
    serviceContext.setFailOnPortalException(isFailOnPortalException());
    serviceContext.setGroupPermissions(getGroupPermissions());
    serviceContext.setGuestPermissions(getGuestPermissions());
    serviceContext.setHeaders(getHeaders());
    serviceContext.setIndexingEnabled(isIndexingEnabled());
    serviceContext.setLanguageId(getLanguageId());
    serviceContext.setLayoutFullURL(getLayoutFullURL());
    serviceContext.setLayoutURL(getLayoutURL());
    serviceContext.setModifiedDate(getModifiedDate());
    serviceContext.setPathFriendlyURLPrivateGroup(getPathFriendlyURLPrivateGroup());
    serviceContext.setPathFriendlyURLPrivateUser(getPathFriendlyURLPrivateUser());
    serviceContext.setPathFriendlyURLPublic(getPathFriendlyURLPublic());
    serviceContext.setPathMain(getPathMain());
    serviceContext.setPlid(getPlid());
    serviceContext.setPortalURL(getPortalURL());
    serviceContext.setPortletPreferencesIds(getPortletPreferencesIds());
    serviceContext.setRemoteAddr(getRemoteAddr());
    serviceContext.setRemoteHost(getRemoteHost());
    serviceContext.setRequest(getRequest());
    serviceContext.setScopeGroupId(getScopeGroupId());
    serviceContext.setSignedIn(isSignedIn());
    serviceContext.setUserDisplayURL(getUserDisplayURL());
    serviceContext.setUserId(getUserId());
    serviceContext.setUuid(getUuid());
    serviceContext.setWorkflowAction(getWorkflowAction());

    return serviceContext;
  }
Exemple #25
0
  /**
   * Returns the tags matching the group and names, creating new tags with the names if the group
   * doesn't already have them.
   *
   * <p>For each name, if a tag with that name doesn't already exist for the group, this method
   * creates a new tag with that name for the group. If a tag with that name already exists in the
   * company group, this method copies that company group's tag's properties to the group's new tag.
   *
   * @param userId the primary key of the user
   * @param group ID the primary key of the tag's group
   * @param names the tag names
   * @return the tags matching the group and names and new tags matching the names that don't
   *     already exist for the group
   * @throws PortalException if a matching group could not be found, if the tag's key or value were
   *     invalid, or if a portal exception occurred
   * @throws SystemException if a system exception occurred
   */
  @Override
  public List<AssetTag> checkTags(long userId, Group group, String[] names)
      throws PortalException, SystemException {

    List<AssetTag> tags = new ArrayList<AssetTag>();

    for (String name : names) {
      AssetTag tag = null;

      try {
        tag = getTag(group.getGroupId(), name);
      } catch (NoSuchTagException nste1) {
        ServiceContext serviceContext = new ServiceContext();

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

        tag = addTag(userId, name, PropsValues.ASSET_TAG_PROPERTIES_DEFAULT, serviceContext);

        Group companyGroup = groupLocalService.getCompanyGroup(group.getCompanyId());

        try {
          AssetTag companyGroupTag = getTag(companyGroup.getGroupId(), name);

          List<AssetTagProperty> tagProperties =
              assetTagPropertyLocalService.getTagProperties(companyGroupTag.getTagId());

          for (AssetTagProperty tagProperty : tagProperties) {
            assetTagPropertyLocalService.addTagProperty(
                userId, tag.getTagId(), tagProperty.getKey(), tagProperty.getValue());
          }
        } catch (NoSuchTagException nste2) {
        }
      }

      if (tag != null) {
        tags.add(tag);
      }
    }

    return tags;
  }
  protected Folder addFolder(long parentFolderId, String name, boolean deleteExisting)
      throws Exception {

    String description = StringPool.BLANK;

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    if (deleteExisting) {
      try {
        DLAppServiceUtil.deleteFolder(TestPropsValues.getGroupId(), parentFolderId, name);
      } catch (NoSuchFolderException nsfe) {
      }
    }

    return DLAppServiceUtil.addFolder(
        TestPropsValues.getGroupId(), parentFolderId, name, description, serviceContext);
  }
  public Status makeCollection(WebDAVRequest webDavRequest) throws WebDAVException {

    try {
      HttpServletRequest request = webDavRequest.getHttpServletRequest();

      if (request.getContentLength() > 0) {
        return new Status(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
      }

      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;

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddCommunityPermissions(isAddCommunityPermissions(groupId));
      serviceContext.setAddGuestPermissions(true);
      serviceContext.setPlid(getPlid(webDavRequest.getGroupId()));
      serviceContext.setScopeGroupId(webDavRequest.getGroupId());

      IGFolderServiceUtil.addFolder(parentFolderId, name, description, serviceContext);

      String location = StringUtil.merge(pathArray, StringPool.SLASH);

      return new Status(location, HttpServletResponse.SC_CREATED);
    } catch (DuplicateFolderNameException dfne) {
      return new Status(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
    } catch (NoSuchFolderException nsfe) {
      return new Status(HttpServletResponse.SC_CONFLICT);
    } catch (PrincipalException pe) {
      return new Status(HttpServletResponse.SC_FORBIDDEN);
    } catch (Exception e) {
      throw new WebDAVException(e);
    }
  }
  @Override
  public long getAttachmentsFolderId() throws PortalException, SystemException {

    if (_attachmentsFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

      return _attachmentsFolderId;
    }

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    Repository repository =
        PortletFileRepositoryUtil.fetchPortletRepository(getGroupId(), PortletKeys.MESSAGE_BOARDS);

    long threadAttachmetsFolderId = getThreadAttachmentsFolderId();

    if ((repository == null)
        || (threadAttachmetsFolderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {

      return DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
    }

    try {
      Folder folder =
          PortletFileRepositoryUtil.getPortletFolder(
              getUserId(),
              repository.getRepositoryId(),
              threadAttachmetsFolderId,
              String.valueOf(getMessageId()),
              serviceContext);

      _attachmentsFolderId = folder.getFolderId();
    } catch (Exception e) {
    }

    return _attachmentsFolderId;
  }
Exemple #29
0
  protected FileEntry addFileEntry(String title) throws Exception {
    long folderId = _folder.getFolderId();
    String description = StringPool.BLANK;
    String changeLog = StringPool.BLANK;
    byte[] bytes = _CONTENT.getBytes();

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    return DLAppServiceHttp.addFileEntry(
        TestPropsValues.getHttpPrincipal(),
        TestPropsValues.getGroupId(),
        folderId,
        title,
        ContentTypes.TEXT_PLAIN,
        title,
        description,
        changeLog,
        bytes,
        serviceContext);
  }
  protected void moveFrontPage(long userId, WikiNode node, Map<String, String[]> options) {

    String frontPageTitle = MapUtil.getString(options, WikiImporterKeys.OPTIONS_FRONT_PAGE);

    if (Validator.isNotNull(frontPageTitle)) {
      frontPageTitle = normalizeTitle(frontPageTitle);

      try {
        if (WikiPageLocalServiceUtil.getPagesCount(node.getNodeId(), frontPageTitle, true) > 0) {

          ServiceContext serviceContext = new ServiceContext();

          serviceContext.setAddGroupPermissions(true);
          serviceContext.setAddGuestPermissions(true);

          WikiPageLocalServiceUtil.movePage(
              userId,
              node.getNodeId(),
              frontPageTitle,
              WikiPageConstants.FRONT_PAGE,
              false,
              serviceContext);
        }
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          StringBundler sb = new StringBundler(4);

          sb.append("Could not move ");
          sb.append(WikiPageConstants.FRONT_PAGE);
          sb.append(" to the title provided: ");
          sb.append(frontPageTitle);

          _log.warn(sb.toString(), e);
        }
      }
    }
  }