예제 #1
0
  protected void addBlogsEntry(long groupId, String assetTagName) throws Exception {

    ServiceContext serviceContext = ServiceTestUtil.getServiceContext(groupId);

    serviceContext.setAssetTagNames(new String[] {assetTagName});

    BlogsTestUtil.addEntry(
        TestPropsValues.getUserId(), ServiceTestUtil.randomString(), true, serviceContext);
  }
예제 #2
0
  /**
   * 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;
  }
  @Test
  public void testAsstTags() throws Exception {
    long folderId = parentFolder.getFolderId();
    String name = "TestTags.txt";
    String description = StringPool.BLANK;
    String changeLog = StringPool.BLANK;
    byte[] bytes = CONTENT.getBytes();

    ServiceContext serviceContext = new ServiceContext();

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

    String[] assetTagNames = new String[] {"hello", "world"};

    serviceContext.setAssetTagNames(assetTagNames);

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

    AssetEntry assetEntry =
        AssetEntryLocalServiceUtil.fetchEntry(
            DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId());

    AssertUtils.assertEqualsSorted(assetTagNames, assetEntry.getTagNames());

    Thread.sleep(1000 * TestPropsValues.JUNIT_DELAY_FACTOR);

    _fileEntry = fileEntry;

    search(_fileEntry, false, "hello", true);
    search(_fileEntry, false, "world", true);
    search(_fileEntry, false, "liferay", false);

    assetTagNames = new String[] {"hello", "world", "liferay"};

    serviceContext.setAssetTagNames(assetTagNames);

    fileEntry =
        DLAppServiceUtil.updateFileEntry(
            fileEntry.getFileEntryId(),
            name,
            ContentTypes.TEXT_PLAIN,
            name,
            description,
            changeLog,
            false,
            bytes,
            serviceContext);

    assetEntry =
        AssetEntryLocalServiceUtil.fetchEntry(
            DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId());

    AssertUtils.assertEqualsSorted(assetTagNames, assetEntry.getTagNames());

    Thread.sleep(1000 * TestPropsValues.JUNIT_DELAY_FACTOR);

    _fileEntry = fileEntry;

    search(_fileEntry, false, "hello", true);
    search(_fileEntry, false, "world", true);
    search(_fileEntry, false, "liferay", true);

    DLAppServiceUtil.deleteFileEntry(_fileEntry.getFileEntryId());

    _fileEntry = null;
  }
  protected ServiceContext createServiceContext(
      Element element, String path, ClassedModel classedModel, String namespace) {

    Class<?> clazz = classedModel.getModelClass();
    long classPK = getClassPK(classedModel);

    ServiceContext serviceContext = new ServiceContext();

    // Theme display

    serviceContext.setCompanyId(getCompanyId());
    serviceContext.setScopeGroupId(getScopeGroupId());

    // Dates

    if (classedModel instanceof AuditedModel) {
      AuditedModel auditedModel = (AuditedModel) classedModel;

      serviceContext.setCreateDate(auditedModel.getCreateDate());
      serviceContext.setModifiedDate(auditedModel.getModifiedDate());
    }

    // Permissions

    if (!MapUtil.getBoolean(_parameterMap, PortletDataHandlerKeys.PERMISSIONS)) {

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

    // Asset

    boolean portletMetadataAll =
        getBooleanParameter(namespace, PortletDataHandlerKeys.PORTLET_METADATA_ALL);

    if (isResourceMain(classedModel)) {
      if (portletMetadataAll || getBooleanParameter(namespace, "categories")) {

        long[] assetCategoryIds = getAssetCategoryIds(clazz, classPK);

        serviceContext.setAssetCategoryIds(assetCategoryIds);
      }

      if (portletMetadataAll || getBooleanParameter(namespace, "tags")) {
        String[] assetTagNames = getAssetTagNames(clazz, classPK);

        serviceContext.setAssetTagNames(assetTagNames);
      }
    }

    // Expando

    String expandoPath = null;

    if (element != null) {
      expandoPath = element.attributeValue("expando-path");
    } else {
      expandoPath = getExpandoPath(path);
    }

    if (Validator.isNotNull(expandoPath)) {
      try {
        Map<String, Serializable> expandoBridgeAttributes =
            (Map<String, Serializable>) getZipEntryAsObject(expandoPath);

        serviceContext.setExpandoBridgeAttributes(expandoBridgeAttributes);
      } catch (Exception e) {
        if (_log.isDebugEnabled()) {
          _log.debug(e, e);
        }
      }
    }

    return serviceContext;
  }
  protected void importPage(
      long userId,
      String author,
      WikiNode node,
      String title,
      String content,
      String summary,
      Map<String, String> usersMap,
      boolean strictImportMode)
      throws PortalException {

    try {
      long authorUserId = getUserId(userId, node, author, usersMap);
      String parentTitle = readParentTitle(content);
      String redirectTitle = readRedirectTitle(content);

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddGroupPermissions(true);
      serviceContext.setAddGuestPermissions(true);
      serviceContext.setAssetTagNames(readAssetTagNames(userId, node, content));

      if (Validator.isNull(redirectTitle)) {
        _translator.setStrictImportMode(strictImportMode);

        content = _translator.translate(content);
      } else {
        content = StringPool.DOUBLE_OPEN_BRACKET + redirectTitle + StringPool.DOUBLE_CLOSE_BRACKET;
      }

      WikiPage page = null;

      try {
        page = WikiPageLocalServiceUtil.getPage(node.getNodeId(), title);
      } catch (NoSuchPageException nspe) {
        page =
            WikiPageLocalServiceUtil.addPage(
                authorUserId,
                node.getNodeId(),
                title,
                WikiPageConstants.NEW,
                null,
                true,
                serviceContext);
      }

      WikiPageLocalServiceUtil.updatePage(
          authorUserId,
          node.getNodeId(),
          title,
          page.getVersion(),
          content,
          summary,
          true,
          "creole",
          parentTitle,
          redirectTitle,
          serviceContext);
    } catch (Exception e) {
      throw new PortalException("Error importing page " + title, e);
    }
  }
예제 #6
0
  public void merge(ServiceContext serviceContext) {
    setAddGroupPermissions(serviceContext.isAddGroupPermissions());
    setAddGuestPermissions(serviceContext.isAddGuestPermissions());

    if (serviceContext.getAssetCategoryIds() != null) {
      setAssetCategoryIds(serviceContext.getAssetCategoryIds());
    }

    if (serviceContext.getAssetLinkEntryIds() != null) {
      setAssetLinkEntryIds(serviceContext.getAssetLinkEntryIds());
    }

    if (serviceContext.getAssetTagNames() != null) {
      setAssetTagNames(serviceContext.getAssetTagNames());
    }

    if (serviceContext.getAttributes() != null) {
      setAttributes(serviceContext.getAttributes());
    }

    if (Validator.isNotNull(serviceContext.getCommand())) {
      setCommand(serviceContext.getCommand());
    }

    if (serviceContext.getCompanyId() > 0) {
      setCompanyId(serviceContext.getCompanyId());
    }

    if (serviceContext.getCreateDate() != null) {
      setCreateDate(serviceContext.getCreateDate());
    }

    if (Validator.isNotNull(serviceContext.getCurrentURL())) {
      setCurrentURL(serviceContext.getCurrentURL());
    }

    if (serviceContext.getExpandoBridgeAttributes() != null) {
      setExpandoBridgeAttributes(serviceContext.getExpandoBridgeAttributes());
    }

    if (serviceContext.getGroupPermissions() != null) {
      setGroupPermissions(serviceContext.getGroupPermissions());
    }

    if (serviceContext.getGuestPermissions() != null) {
      setGuestPermissions(serviceContext.getGuestPermissions());
    }

    if (serviceContext.getHeaders() != null) {
      setHeaders(serviceContext.getHeaders());
    }

    setFailOnPortalException(serviceContext.isFailOnPortalException());
    setLanguageId(serviceContext.getLanguageId());

    if (Validator.isNotNull(serviceContext.getLayoutFullURL())) {
      setLayoutFullURL(serviceContext.getLayoutFullURL());
    }

    if (Validator.isNotNull(serviceContext.getLayoutURL())) {
      setLayoutURL(serviceContext.getLayoutURL());
    }

    if (serviceContext.getModifiedDate() != null) {
      setModifiedDate(serviceContext.getModifiedDate());
    }

    if (Validator.isNotNull(serviceContext.getPathMain())) {
      setPathMain(serviceContext.getPathMain());
    }

    if (serviceContext.getPlid() > 0) {
      setPlid(serviceContext.getPlid());
    }

    if (Validator.isNotNull(serviceContext.getPortalURL())) {
      setPortalURL(serviceContext.getPortalURL());
    }

    if (serviceContext.getPortletPreferencesIds() != null) {
      setPortletPreferencesIds(serviceContext.getPortletPreferencesIds());
    }

    if (Validator.isNotNull(serviceContext.getRemoteAddr())) {
      setRemoteAddr(serviceContext.getRemoteAddr());
    }

    if (Validator.isNotNull(serviceContext.getRemoteHost())) {
      setRemoteHost(serviceContext.getRemoteHost());
    }

    if (serviceContext.getScopeGroupId() > 0) {
      setScopeGroupId(serviceContext.getScopeGroupId());
    }

    setSignedIn(serviceContext.isSignedIn());

    if (Validator.isNotNull(serviceContext.getUserDisplayURL())) {
      setUserDisplayURL(serviceContext.getUserDisplayURL());
    }

    if (serviceContext.getUserId() > 0) {
      setUserId(serviceContext.getUserId());
    }

    if (Validator.isNotNull(serviceContext.getUuid())) {
      setUuid(serviceContext.getUuid());
    }

    if (serviceContext.getWorkflowAction() > 0) {
      setWorkflowAction(serviceContext.getWorkflowAction());
    }
  }
예제 #7
0
  public void updateMeetupsEntry(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    ServiceContext serviceContext = ServiceContextFactory.getInstance(uploadRequest);
    ThemeDisplay themeDisplay = (ThemeDisplay) uploadRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    // get selected tags
    String[] assetTagNames = null;

    String assetTagCSV = ParamUtil.getString(uploadRequest, "assetTagNames");

    assetTagNames = assetTagCSV != null ? assetTagCSV.split(",") : null;

    // set asset tag names in service context
    serviceContext.setAssetTagNames(
        (null != assetTagCSV && !assetTagCSV.equals("")) ? assetTagNames : null);

    if (!permissionChecker.isCompanyAdmin()) {
      return;
    }

    long meetupsEntryId = ParamUtil.getLong(uploadRequest, "meetupsEntryId");

    String title = ParamUtil.getString(uploadRequest, "title");
    String description = ParamUtil.getString(uploadRequest, "description");

    int startDateMonth = ParamUtil.getInteger(uploadRequest, "startDateMonth");
    int startDateDay = ParamUtil.getInteger(uploadRequest, "startDateDay");
    int startDateYear = ParamUtil.getInteger(uploadRequest, "startDateYear");
    int startDateHour = ParamUtil.getInteger(uploadRequest, "startDateHour");
    int startDateMinute = ParamUtil.getInteger(uploadRequest, "startDateMinute");
    int startDateAmPm = ParamUtil.getInteger(uploadRequest, "startDateAmPm");

    if (startDateAmPm == Calendar.PM) {
      startDateHour += 12;
    }

    int endDateMonth = ParamUtil.getInteger(uploadRequest, "endDateMonth");
    int endDateDay = ParamUtil.getInteger(uploadRequest, "endDateDay");
    int endDateYear = ParamUtil.getInteger(uploadRequest, "endDateYear");
    int endDateHour = ParamUtil.getInteger(uploadRequest, "endDateHour");
    int endDateMinute = ParamUtil.getInteger(uploadRequest, "endDateMinute");
    int endDateAmPm = ParamUtil.getInteger(uploadRequest, "endDateAmPm");

    if (endDateAmPm == Calendar.PM) {
      endDateHour += 12;
    }

    int totalAttendees = ParamUtil.getInteger(uploadRequest, "totalAttendees");
    int maxAttendees = ParamUtil.getInteger(uploadRequest, "maxAttendees");
    double price = ParamUtil.getDouble(uploadRequest, "price");

    File file = uploadRequest.getFile("fileName");
    byte[] bytes = FileUtil.getBytes(file);

    if (meetupsEntryId <= 0) {
      // Add Meetups Entry
      MeetupsEntryLocalServiceUtil.addMeetupsEntry(
          themeDisplay.getUserId(),
          title,
          description,
          startDateMonth,
          startDateDay,
          startDateYear,
          startDateHour,
          startDateMinute,
          endDateMonth,
          endDateDay,
          endDateYear,
          endDateHour,
          endDateMinute,
          totalAttendees,
          maxAttendees,
          price,
          bytes,
          serviceContext);

    } else {
      MeetupsEntryLocalServiceUtil.updateMeetupsEntry(
          themeDisplay.getUserId(),
          meetupsEntryId,
          title,
          description,
          startDateMonth,
          startDateDay,
          startDateYear,
          startDateHour,
          startDateMinute,
          endDateMonth,
          endDateDay,
          endDateYear,
          endDateHour,
          endDateMinute,
          totalAttendees,
          maxAttendees,
          price,
          bytes,
          serviceContext);
    }
  }
예제 #8
0
  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();
      }
    }
  }