示例#1
0
  public long[] getClassTypeIds() {
    if (_classTypeIds == null) {
      _classTypeIds = GetterUtil.getLongValues(_portletPreferences.getValues("classTypeIds", null));
    }

    return _classTypeIds;
  }
示例#2
0
  public static List<Calendar> getSelectedCalendars(long userId)
      throws PortalException, SystemException {

    ArrayList<Calendar> calendars = new ArrayList<Calendar>();

    String otherCalendarPreferences = "calendar-portlet-other-calendars";

    if (_calendarVersion == 0) {
      Portlet calendarPortlet = PortletLocalServiceUtil.getPortletById(PortletKeys.CALENDAR);

      String calendarVersionStr = calendarPortlet.getPluginPackage().getVersion();

      Version calendarVersion = Version.getInstance(calendarVersionStr);

      _calendarVersion = GetterUtil.getInteger(calendarVersion.getBuildNumber(), 1);
    }

    if (_calendarVersion < 10) {
      otherCalendarPreferences = "otherCalendars";
    }

    long[] calendarIds =
        GetterUtil.getLongValues(
            StringUtil.split(
                PortletPreferencesFactoryUtil.getPortalPreferences(userId, true)
                    .getValue(SessionClicks.class.getName(), otherCalendarPreferences)));

    for (long calendarId : calendarIds) {
      calendars.add(CalendarServiceUtil.getCalendar(calendarId));
    }

    return calendars;
  }
  @Override
  public long[] getClassNameIds(
      PortletPreferences portletPreferences, long[] availableClassNameIds) {

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

    if (anyAssetType) {
      return availableClassNameIds;
    }

    long defaultClassNameId = GetterUtil.getLong(portletPreferences.getValue("anyAssetType", null));

    if (defaultClassNameId > 0) {
      return new long[] {defaultClassNameId};
    }

    long[] classNameIds =
        GetterUtil.getLongValues(portletPreferences.getValues("classNameIds", null));

    if (classNameIds != null) {
      return classNameIds;
    } else {
      return availableClassNameIds;
    }
  }
  @Override
  public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws PortalException {

    ExportImportConfiguration exportImportConfiguration =
        getExportImportConfiguration(backgroundTask);

    Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap();

    long userId = MapUtil.getLong(settingsMap, "userId");
    long groupId = MapUtil.getLong(settingsMap, "sourceGroupId");
    boolean privateLayout = MapUtil.getBoolean(settingsMap, "privateLayout");
    long[] layoutIds = GetterUtil.getLongValues(settingsMap.get("layoutIds"));
    Map<String, String[]> parameterMap = (Map<String, String[]>) settingsMap.get("parameterMap");
    DateRange dateRange =
        ExportImportDateUtil.getDateRange(
            exportImportConfiguration, ExportImportDateUtil.RANGE_ALL);

    StringBundler sb = new StringBundler(4);

    sb.append(
        StringUtil.replace(
            exportImportConfiguration.getName(), StringPool.SPACE, StringPool.UNDERLINE));
    sb.append(StringPool.DASH);
    sb.append(Time.getShortTimestamp());
    sb.append(".lar");

    File larFile =
        LayoutLocalServiceUtil.exportLayoutsAsFile(
            groupId,
            privateLayout,
            layoutIds,
            parameterMap,
            dateRange.getStartDate(),
            dateRange.getEndDate());

    BackgroundTaskLocalServiceUtil.addBackgroundTaskAttachment(
        userId, backgroundTask.getBackgroundTaskId(), sb.toString(), larFile);

    boolean updateLastPublishDate =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE);

    if (updateLastPublishDate) {
      ExportImportDateUtil.updateLastPublishDate(
          groupId, privateLayout, dateRange, dateRange.getEndDate());
    }

    return BackgroundTaskResult.SUCCESS;
  }
  @Override
  protected void doReceive(Message message, MessageStatus messageStatus) throws PortalException {

    long exportImportConfigurationId = GetterUtil.getLong(message.getPayload());

    ExportImportConfiguration exportImportConfiguration =
        _exportImportConfigurationLocalService.fetchExportImportConfiguration(
            exportImportConfigurationId);

    if (exportImportConfiguration == null) {
      if (_log.isWarnEnabled()) {
        _log.warn(
            "Unable to find export import configuration with ID " + exportImportConfigurationId);
      }

      return;
    }

    messageStatus.setPayload(exportImportConfiguration);

    Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap();

    long userId = MapUtil.getLong(settingsMap, "userId");
    long sourceGroupId = MapUtil.getLong(settingsMap, "sourceGroupId");
    long targetGroupId = MapUtil.getLong(settingsMap, "targetGroupId");
    boolean privateLayout = MapUtil.getBoolean(settingsMap, "privateLayout");
    long[] layoutIds = GetterUtil.getLongValues(settingsMap.get("layoutIds"));
    Map<String, String[]> parameterMap = (Map<String, String[]>) settingsMap.get("parameterMap");

    initThreadLocals(userId, parameterMap);

    try {
      StagingUtil.publishLayouts(
          userId,
          sourceGroupId,
          targetGroupId,
          privateLayout,
          layoutIds,
          exportImportConfiguration.getName(),
          parameterMap);
    } finally {
      resetThreadLocals();
    }
  }
  @Override
  public File export(ExportImportConfiguration exportImportConfiguration) throws Exception {

    PortletDataContext portletDataContext = null;

    try {
      ExportImportThreadLocal.setLayoutExportInProcess(true);

      Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap();

      long[] layoutIds = GetterUtil.getLongValues(settingsMap.get("layoutIds"));

      portletDataContext = getPortletDataContext(exportImportConfiguration);

      _exportImportLifecycleManager.fireExportImportLifecycleEvent(
          EVENT_LAYOUT_EXPORT_STARTED,
          getProcessFlag(),
          PortletDataContextFactoryUtil.clonePortletDataContext(portletDataContext));

      File file = doExport(portletDataContext, layoutIds);

      ExportImportThreadLocal.setLayoutExportInProcess(false);

      _exportImportLifecycleManager.fireExportImportLifecycleEvent(
          EVENT_LAYOUT_EXPORT_SUCCEEDED,
          getProcessFlag(),
          PortletDataContextFactoryUtil.clonePortletDataContext(portletDataContext));

      return file;
    } catch (Throwable t) {
      ExportImportThreadLocal.setLayoutExportInProcess(false);

      _exportImportLifecycleManager.fireExportImportLifecycleEvent(
          EVENT_LAYOUT_EXPORT_FAILED,
          getProcessFlag(),
          PortletDataContextFactoryUtil.clonePortletDataContext(portletDataContext),
          t);

      throw t;
    }
  }
  public static Serializable getAttributeFromStringArray(int type, String[] attribute) {

    if (ArrayUtil.isEmpty(attribute)) {
      return null;
    }

    if (type == ExpandoColumnConstants.BOOLEAN) {
      return GetterUtil.getBoolean(attribute[0]);
    } else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
      return GetterUtil.getBooleanValues(attribute);
    } else if (type == ExpandoColumnConstants.DATE) {
      return GetterUtil.getDate(attribute[0], _getDateFormat());
    } else if (type == ExpandoColumnConstants.DATE_ARRAY) {
      return GetterUtil.getDateValues(attribute, _getDateFormat());
    } else if (type == ExpandoColumnConstants.DOUBLE) {
      return GetterUtil.getDouble(attribute[0]);
    } else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
      return GetterUtil.getDoubleValues(attribute);
    } else if (type == ExpandoColumnConstants.FLOAT) {
      return GetterUtil.getFloat(attribute[0]);
    } else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
      return GetterUtil.getFloatValues(attribute);
    } else if (type == ExpandoColumnConstants.INTEGER) {
      return GetterUtil.getInteger(attribute[0]);
    } else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
      return GetterUtil.getIntegerValues(attribute);
    } else if (type == ExpandoColumnConstants.LONG) {
      return GetterUtil.getLong(attribute[0]);
    } else if (type == ExpandoColumnConstants.LONG_ARRAY) {
      return GetterUtil.getLongValues(attribute);
    } else if (type == ExpandoColumnConstants.SHORT) {
      return GetterUtil.getShort(attribute[0]);
    } else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
      return GetterUtil.getShortValues(attribute);
    } else if (type == ExpandoColumnConstants.STRING) {
      return attribute[0];
    } else {
      return attribute;
    }
  }
示例#8
0
  protected List<AssetEntry> getAssetEntries(
      PortletRequest portletRequest, PortletPreferences preferences) throws Exception {

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

    AssetEntryQuery assetEntryQuery =
        AssetPublisherUtil.getAssetEntryQuery(
            preferences, new long[] {themeDisplay.getScopeGroupId()});

    boolean anyAssetType = GetterUtil.getBoolean(preferences.getValue("anyAssetType", null), true);

    if (!anyAssetType) {
      long[] availableClassNameIds = AssetRendererFactoryRegistryUtil.getClassNameIds();

      long[] classNameIds = AssetPublisherUtil.getClassNameIds(preferences, availableClassNameIds);

      assetEntryQuery.setClassNameIds(classNameIds);
    }

    long[] classTypeIds = GetterUtil.getLongValues(preferences.getValues("classTypeIds", null));

    assetEntryQuery.setClassTypeIds(classTypeIds);

    boolean enablePermissions =
        GetterUtil.getBoolean(preferences.getValue("enablePermissions", null));

    assetEntryQuery.setEnablePermissions(enablePermissions);

    int rssDelta = GetterUtil.getInteger(preferences.getValue("rssDelta", "20"));

    assetEntryQuery.setEnd(rssDelta);

    boolean excludeZeroViewCount =
        GetterUtil.getBoolean(preferences.getValue("excludeZeroViewCount", null));

    assetEntryQuery.setExcludeZeroViewCount(excludeZeroViewCount);

    long[] groupIds =
        AssetPublisherUtil.getGroupIds(
            preferences, themeDisplay.getScopeGroupId(), themeDisplay.getLayout());

    assetEntryQuery.setGroupIds(groupIds);

    boolean showOnlyLayoutAssets =
        GetterUtil.getBoolean(preferences.getValue("showOnlyLayoutAssets", null));

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

    String orderByColumn1 =
        GetterUtil.getString(preferences.getValue("orderByColumn1", "modifiedDate"));

    assetEntryQuery.setOrderByCol1(orderByColumn1);

    String orderByColumn2 = GetterUtil.getString(preferences.getValue("orderByColumn2", "title"));

    assetEntryQuery.setOrderByCol2(orderByColumn2);

    String orderByType1 = GetterUtil.getString(preferences.getValue("orderByType1", "DESC"));

    assetEntryQuery.setOrderByType1(orderByType1);

    String orderByType2 = GetterUtil.getString(preferences.getValue("orderByType2", "ASC"));

    assetEntryQuery.setOrderByType2(orderByType2);

    assetEntryQuery.setStart(0);

    return AssetEntryServiceUtil.getEntries(assetEntryQuery);
  }
  public static long[] getLongValues(
      ServiceContext serviceContext, String param, long[] defaultValue) {

    return GetterUtil.getLongValues(serviceContext.getAttribute(param), defaultValue);
  }
  public static long[] getLongValues(
      PortletRequest portletRequest, String param, long[] defaultValue) {

    return GetterUtil.getLongValues(getParameterValues(portletRequest, param), defaultValue);
  }
  public static long[] getLongValues(
      HttpServletRequest request, String param, long[] defaultValue) {

    return GetterUtil.getLongValues(getParameterValues(request, param), defaultValue);
  }
  private void _checkAssetEntries(com.liferay.portal.model.PortletPreferences portletPreferences)
      throws PortalException, SystemException {

    Layout layout = LayoutLocalServiceUtil.getLayout(portletPreferences.getPlid());

    PortletPreferences preferences =
        PortletPreferencesFactoryUtil.fromXML(
            layout.getCompanyId(),
            portletPreferences.getOwnerId(),
            portletPreferences.getOwnerType(),
            portletPreferences.getPlid(),
            portletPreferences.getPortletId(),
            portletPreferences.getPreferences());

    if (!getEmailAssetEntryAddedEnabled(preferences)) {
      return;
    }

    List<AssetEntry> assetEntries =
        getAssetEntries(
            preferences,
            layout,
            layout.getGroupId(),
            PropsValues.ASSET_PUBLISHER_DYNAMIC_SUBSCRIPTION_LIMIT,
            false);

    if (assetEntries.isEmpty()) {
      return;
    }

    long[] notifiedAssetEntryIds =
        GetterUtil.getLongValues(preferences.getValues("notifiedAssetEntryIds", null));

    List<AssetEntry> newAssetEntries = new ArrayList<AssetEntry>();

    for (int i = 0; i < assetEntries.size(); i++) {
      AssetEntry assetEntry = assetEntries.get(i);

      if (!ArrayUtil.contains(notifiedAssetEntryIds, assetEntry.getEntryId())) {

        newAssetEntries.add(assetEntry);
      }
    }

    notifySubscribers(
        preferences,
        portletPreferences.getPlid(),
        portletPreferences.getPortletId(),
        newAssetEntries);

    try {
      preferences.setValues(
          "notifiedAssetEntryIds",
          StringUtil.split(ListUtil.toString(assetEntries, AssetEntry.ENTRY_ID_ACCESSOR)));

      preferences.store();
    } catch (IOException ioe) {
      throw new SystemException(ioe);
    } catch (PortletException pe) {
      throw new SystemException(pe);
    }
  }
  @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;
  }
  @Override
  public List<AssetEntry> getAssetEntries(
      PortletPreferences preferences,
      Layout layout,
      long scopeGroupId,
      int max,
      boolean checkPermission)
      throws PortalException, SystemException {

    AssetEntryQuery assetEntryQuery = getAssetEntryQuery(preferences, new long[] {scopeGroupId});

    boolean anyAssetType = GetterUtil.getBoolean(preferences.getValue("anyAssetType", null), true);

    if (!anyAssetType) {
      long[] availableClassNameIds =
          AssetRendererFactoryRegistryUtil.getClassNameIds(layout.getCompanyId());

      long[] classNameIds = getClassNameIds(preferences, availableClassNameIds);

      assetEntryQuery.setClassNameIds(classNameIds);
    }

    long[] classTypeIds = GetterUtil.getLongValues(preferences.getValues("classTypeIds", null));

    assetEntryQuery.setClassTypeIds(classTypeIds);

    boolean enablePermissions =
        GetterUtil.getBoolean(preferences.getValue("enablePermissions", null));

    assetEntryQuery.setEnablePermissions(enablePermissions);

    assetEntryQuery.setEnd(max);

    boolean excludeZeroViewCount =
        GetterUtil.getBoolean(preferences.getValue("excludeZeroViewCount", null));

    assetEntryQuery.setExcludeZeroViewCount(excludeZeroViewCount);

    long[] groupIds = getGroupIds(preferences, scopeGroupId, layout);

    assetEntryQuery.setGroupIds(groupIds);

    boolean showOnlyLayoutAssets =
        GetterUtil.getBoolean(preferences.getValue("showOnlyLayoutAssets", null));

    if (showOnlyLayoutAssets) {
      assetEntryQuery.setLayout(layout);
    }

    String orderByColumn1 =
        GetterUtil.getString(preferences.getValue("orderByColumn1", "modifiedDate"));

    assetEntryQuery.setOrderByCol1(orderByColumn1);

    String orderByColumn2 = GetterUtil.getString(preferences.getValue("orderByColumn2", "title"));

    assetEntryQuery.setOrderByCol2(orderByColumn2);

    String orderByType1 = GetterUtil.getString(preferences.getValue("orderByType1", "DESC"));

    assetEntryQuery.setOrderByType1(orderByType1);

    String orderByType2 = GetterUtil.getString(preferences.getValue("orderByType2", "ASC"));

    assetEntryQuery.setOrderByType2(orderByType2);

    assetEntryQuery.setStart(0);

    if (checkPermission) {
      return AssetEntryServiceUtil.getEntries(assetEntryQuery);
    } else {
      return AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
    }
  }