コード例 #1
0
  @Override
  protected void doUpgrade() throws Exception {
    List<User> users = UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS);

    for (User user : users) {
      try {
        if (user.isDefaultUser()) {
          continue;
        }

        Group group = user.getGroup();

        LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(group.getGroupId(), false);

        String themeId = layoutSet.getThemeId();

        if (!themeId.equals("so_WAR_sotheme")) {
          return;
        }

        Role role =
            RoleLocalServiceUtil.getRole(user.getCompanyId(), RoleConstants.SOCIAL_OFFICE_USER);

        UserLocalServiceUtil.addRoleUsers(role.getRoleId(), new long[] {user.getUserId()});

        updateUserGroup(group);
        updateSocialRelations(user);
      } catch (Exception e) {
      }
    }
  }
コード例 #2
0
  /**
   * Creates a new layout set with the primary key. Does not add the layout set to the database.
   *
   * @param layoutSetId the primary key for the new layout set
   * @return the new layout set
   */
  public LayoutSet create(long layoutSetId) {
    LayoutSet layoutSet = new LayoutSetImpl();

    layoutSet.setNew(true);
    layoutSet.setPrimaryKey(layoutSetId);

    return layoutSet;
  }
コード例 #3
0
  @Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    LayoutSet newLayoutSet = addLayoutSet();

    LayoutSet existingLayoutSet = _persistence.fetchByPrimaryKey(newLayoutSet.getPrimaryKey());

    Assert.assertEquals(existingLayoutSet, newLayoutSet);
  }
コード例 #4
0
  private void _buildParentGroupsBreadcrumb(
      LayoutSet layoutSet, PortletURL portletURL, ThemeDisplay themeDisplay, StringBundler sb)
      throws Exception {
    Group group = layoutSet.getGroup();

    if (group.isOrganization()) {
      Organization organization =
          OrganizationLocalServiceUtil.getOrganization(group.getOrganizationId());

      Organization parentOrganization = organization.getParentOrganization();

      if (parentOrganization != null) {
        Group parentGroup = parentOrganization.getGroup();

        LayoutSet parentLayoutSet =
            LayoutSetLocalServiceUtil.getLayoutSet(
                parentGroup.getGroupId(), layoutSet.isPrivateLayout());

        _buildParentGroupsBreadcrumb(parentLayoutSet, portletURL, themeDisplay, sb);
      }
    } else if (group.isUser()) {
      User groupUser = UserLocalServiceUtil.getUser(group.getClassPK());

      List<Organization> organizations =
          OrganizationLocalServiceUtil.getUserOrganizations(groupUser.getUserId(), true);

      if (!organizations.isEmpty()) {
        Organization organization = organizations.get(0);

        Group parentGroup = organization.getGroup();

        LayoutSet parentLayoutSet =
            LayoutSetLocalServiceUtil.getLayoutSet(
                parentGroup.getGroupId(), layoutSet.isPrivateLayout());

        _buildParentGroupsBreadcrumb(parentLayoutSet, portletURL, themeDisplay, sb);
      }
    }

    int layoutsPageCount = 0;

    if (layoutSet.isPrivateLayout()) {
      layoutsPageCount = group.getPrivateLayoutsPageCount();
    } else {
      layoutsPageCount = group.getPublicLayoutsPageCount();
    }

    if ((layoutsPageCount > 0) && !group.getName().equals(GroupConstants.GUEST)) {
      String layoutSetFriendlyURL = PortalUtil.getLayoutSetFriendlyURL(layoutSet, themeDisplay);

      sb.append("<li><span><a href=\"");
      sb.append(layoutSetFriendlyURL);
      sb.append("\">");
      sb.append(HtmlUtil.escape(group.getDescriptiveName()));
      sb.append("</a></span></li>");
    }
  }
コード例 #5
0
  @Test
  public void testCreate() throws Exception {
    long pk = RandomTestUtil.nextLong();

    LayoutSet layoutSet = _persistence.create(pk);

    Assert.assertNotNull(layoutSet);

    Assert.assertEquals(layoutSet.getPrimaryKey(), pk);
  }
コード例 #6
0
  @Test
  public void testRemove() throws Exception {
    LayoutSet newLayoutSet = addLayoutSet();

    _persistence.remove(newLayoutSet);

    LayoutSet existingLayoutSet = _persistence.fetchByPrimaryKey(newLayoutSet.getPrimaryKey());

    Assert.assertNull(existingLayoutSet);
  }
コード例 #7
0
  /**
   * Clears the cache for the layout set.
   *
   * <p>The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link
   * com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
   */
  @Override
  public void clearCache(LayoutSet layoutSet) {
    EntityCacheUtil.removeResult(
        LayoutSetModelImpl.ENTITY_CACHE_ENABLED, LayoutSetImpl.class, layoutSet.getPrimaryKey());

    FinderCacheUtil.removeResult(
        FINDER_PATH_FETCH_BY_G_P,
        new Object[] {
          Long.valueOf(layoutSet.getGroupId()), Boolean.valueOf(layoutSet.getPrivateLayout())
        });
  }
コード例 #8
0
 /**
  * Caches the layout sets in the entity cache if it is enabled.
  *
  * @param layoutSets the layout sets
  */
 public void cacheResult(List<LayoutSet> layoutSets) {
   for (LayoutSet layoutSet : layoutSets) {
     if (EntityCacheUtil.getResult(
             LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
             LayoutSetImpl.class,
             layoutSet.getPrimaryKey(),
             this)
         == null) {
       cacheResult(layoutSet);
     }
   }
 }
コード例 #9
0
  @Test
  public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
    LayoutSet newLayoutSet = addLayoutSet();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newLayoutSet.getPrimaryKey());

    Map<Serializable, LayoutSet> layoutSets = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, layoutSets.size());
    Assert.assertEquals(newLayoutSet, layoutSets.get(newLayoutSet.getPrimaryKey()));
  }
コード例 #10
0
  @Override
  public LayoutSet updateImpl(com.liferay.portal.model.LayoutSet layoutSet, boolean merge)
      throws SystemException {
    layoutSet = toUnwrappedModel(layoutSet);

    boolean isNew = layoutSet.isNew();

    LayoutSetModelImpl layoutSetModelImpl = (LayoutSetModelImpl) layoutSet;

    Session session = null;

    try {
      session = openSession();

      BatchSessionUtil.update(session, layoutSet, merge);

      layoutSet.setNew(false);
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);
    }

    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);

    EntityCacheUtil.putResult(
        LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
        LayoutSetImpl.class,
        layoutSet.getPrimaryKey(),
        layoutSet);

    if (!isNew
        && ((layoutSet.getGroupId() != layoutSetModelImpl.getOriginalGroupId())
            || (layoutSet.getPrivateLayout() != layoutSetModelImpl.getOriginalPrivateLayout()))) {
      FinderCacheUtil.removeResult(
          FINDER_PATH_FETCH_BY_G_P,
          new Object[] {
            Long.valueOf(layoutSetModelImpl.getOriginalGroupId()),
            Boolean.valueOf(layoutSetModelImpl.getOriginalPrivateLayout())
          });
    }

    if (isNew
        || ((layoutSet.getGroupId() != layoutSetModelImpl.getOriginalGroupId())
            || (layoutSet.getPrivateLayout() != layoutSetModelImpl.getOriginalPrivateLayout()))) {
      FinderCacheUtil.putResult(
          FINDER_PATH_FETCH_BY_G_P,
          new Object[] {
            Long.valueOf(layoutSet.getGroupId()), Boolean.valueOf(layoutSet.getPrivateLayout())
          },
          layoutSet);
    }

    return layoutSet;
  }
コード例 #11
0
  public static void updateLastPublishDate(LayoutSet layoutSet, long lastPublishDate)
      throws Exception {

    UnicodeProperties settingsProperties = layoutSet.getSettingsProperties();

    if (lastPublishDate <= 0) {
      settingsProperties.remove("last-publish-date");
    } else {
      settingsProperties.setProperty("last-publish-date", String.valueOf(lastPublishDate));
    }

    LayoutSetLocalServiceUtil.updateSettings(
        layoutSet.getGroupId(), layoutSet.isPrivateLayout(), settingsProperties.toString());
  }
コード例 #12
0
  @Test
  public void testResetOriginalValues() throws Exception {
    LayoutSet newLayoutSet = addLayoutSet();

    _persistence.clearCache();

    LayoutSet existingLayoutSet = _persistence.findByPrimaryKey(newLayoutSet.getPrimaryKey());

    Assert.assertEquals(
        existingLayoutSet.getGroupId(),
        ReflectionTestUtil.invoke(existingLayoutSet, "getOriginalGroupId", new Class<?>[0]));
    Assert.assertEquals(
        existingLayoutSet.getPrivateLayout(),
        ReflectionTestUtil.invoke(existingLayoutSet, "getOriginalPrivateLayout", new Class<?>[0]));
  }
コード例 #13
0
  protected boolean isLayoutSetPrototype() {
    try {
      Layout layout = getLayout();

      LayoutSet layoutSet = layout.getLayoutSet();

      Group group = layoutSet.getGroup();

      return group.isLayoutSetPrototype();
    } catch (Exception e) {
      _log.error(e, e);
    }

    return false;
  }
コード例 #14
0
  protected List<Layout> addUserGroupLayouts(
      Group group, LayoutSet layoutSet, List<Layout> layouts, long parentLayoutId)
      throws Exception {

    layouts = ListUtil.copy(layouts);

    List<UserGroup> userUserGroups =
        UserGroupLocalServiceUtil.getUserUserGroups(group.getClassPK());

    for (UserGroup userGroup : userUserGroups) {
      Group userGroupGroup = userGroup.getGroup();

      List<Layout> userGroupLayouts =
          LayoutLocalServiceUtil.getLayouts(
              userGroupGroup.getGroupId(), layoutSet.isPrivateLayout(), parentLayoutId);

      for (Layout userGroupLayout : userGroupLayouts) {
        Layout virtualLayout = new VirtualLayout(userGroupLayout, group);

        layouts.add(virtualLayout);
      }
    }

    return layouts;
  }
コード例 #15
0
  /**
   * Caches the layout set in the entity cache if it is enabled.
   *
   * @param layoutSet the layout set
   */
  public void cacheResult(LayoutSet layoutSet) {
    EntityCacheUtil.putResult(
        LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
        LayoutSetImpl.class,
        layoutSet.getPrimaryKey(),
        layoutSet);

    FinderCacheUtil.putResult(
        FINDER_PATH_FETCH_BY_G_P,
        new Object[] {
          Long.valueOf(layoutSet.getGroupId()), Boolean.valueOf(layoutSet.getPrivateLayout())
        },
        layoutSet);

    layoutSet.resetOriginalValues();
  }
コード例 #16
0
  @Override
  protected LayoutSet removeImpl(LayoutSet layoutSet) throws SystemException {
    layoutSet = toUnwrappedModel(layoutSet);

    Session session = null;

    try {
      session = openSession();

      BatchSessionUtil.delete(session, layoutSet);
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);
    }

    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);

    LayoutSetModelImpl layoutSetModelImpl = (LayoutSetModelImpl) layoutSet;

    FinderCacheUtil.removeResult(
        FINDER_PATH_FETCH_BY_G_P,
        new Object[] {
          Long.valueOf(layoutSetModelImpl.getGroupId()),
          Boolean.valueOf(layoutSetModelImpl.getPrivateLayout())
        });

    EntityCacheUtil.removeResult(
        LayoutSetModelImpl.ENTITY_CACHE_ENABLED, LayoutSetImpl.class, layoutSet.getPrimaryKey());

    return layoutSet;
  }
コード例 #17
0
  public void buildDocument(Element element, LayoutSet layoutSet, ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    Group suppliedGroup = GroupLocalServiceUtil.getGroup(layoutSet.getGroupId());

    addUsers(element, suppliedGroup, themeDisplay);
  }
コード例 #18
0
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    LayoutSet newLayoutSet = addLayoutSet();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(LayoutSet.class, _dynamicQueryClassLoader);

    dynamicQuery.add(RestrictionsFactoryUtil.eq("layoutSetId", newLayoutSet.getLayoutSetId()));

    List<LayoutSet> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    LayoutSet existingLayoutSet = result.get(0);

    Assert.assertEquals(existingLayoutSet, newLayoutSet);
  }
コード例 #19
0
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
      throws Exception {
    LayoutSet newLayoutSet = addLayoutSet();

    long pk = RandomTestUtil.nextLong();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newLayoutSet.getPrimaryKey());
    primaryKeys.add(pk);

    Map<Serializable, LayoutSet> layoutSets = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, layoutSets.size());
    Assert.assertEquals(newLayoutSet, layoutSets.get(newLayoutSet.getPrimaryKey()));
  }
コード例 #20
0
  public String getThemeSetting(String key, String device) {
    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();

    String value =
        typeSettingsProperties.getProperty(ThemeSettingImpl.namespaceProperty(device, key));

    if (value != null) {
      return value;
    }

    try {
      LayoutSet layoutSet = getLayoutSet();

      value = layoutSet.getThemeSetting(key, device);
    } catch (Exception e) {
    }

    return value;
  }
コード例 #21
0
  public int compareTo(LayoutSet layoutSet) {
    long primaryKey = layoutSet.getPrimaryKey();

    if (getPrimaryKey() < primaryKey) {
      return -1;
    } else if (getPrimaryKey() > primaryKey) {
      return 1;
    } else {
      return 0;
    }
  }
  protected long getGroupId(String className, long classPK) throws SystemException {

    long groupId = 0;

    if (className.equals(Layout.class.getName())) {
      Layout layout = layoutPersistence.fetchByPrimaryKey(classPK);

      if (layout != null) {
        groupId = layout.getGroupId();
      }
    } else if (className.equals(LayoutSet.class.getName())) {
      LayoutSet layoutSet = layoutSetPersistence.fetchByPrimaryKey(classPK);

      if (layoutSet != null) {
        groupId = layoutSet.getGroupId();
      }
    }

    return groupId;
  }
コード例 #23
0
  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }

    if (!(obj instanceof LayoutSet)) {
      return false;
    }

    LayoutSet layoutSet = (LayoutSet) obj;

    long primaryKey = layoutSet.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
コード例 #24
0
  @Override
  public String getDefaultThemeSetting(String key, String device, boolean inheritLookAndFeel) {

    if (!inheritLookAndFeel) {
      try {
        Theme theme = getTheme(device);

        return theme.getSetting(key);
      } catch (Exception e) {
      }
    }

    try {
      LayoutSet layoutSet = getLayoutSet();

      return layoutSet.getThemeSetting(key, device);
    } catch (Exception e) {
    }

    return StringPool.BLANK;
  }
コード例 #25
0
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    LayoutSet newLayoutSet = addLayoutSet();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(LayoutSet.class, _dynamicQueryClassLoader);

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("layoutSetId"));

    Object newLayoutSetId = newLayoutSet.getLayoutSetId();

    dynamicQuery.add(RestrictionsFactoryUtil.in("layoutSetId", new Object[] {newLayoutSetId}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingLayoutSetId = result.get(0);

    Assert.assertEquals(existingLayoutSetId, newLayoutSetId);
  }
コード例 #26
0
  @Override
  public String getPortalURL(long groupId) throws PortalException, SystemException {

    String portalURL = PortalUtil.getPortalURL(getVirtualHostname(), Http.HTTP_PORT, false);

    if (groupId <= 0) {
      return portalURL;
    }

    Group group = GroupLocalServiceUtil.getGroup(groupId);

    if (group.hasPublicLayouts()) {
      LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, false);

      if (Validator.isNotNull(layoutSet.getVirtualHostname())) {
        portalURL = PortalUtil.getPortalURL(layoutSet.getVirtualHostname(), Http.HTTP_PORT, false);
      }
    } else if (group.hasPrivateLayouts()) {
      LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, true);

      if (Validator.isNotNull(layoutSet.getVirtualHostname())) {
        portalURL = PortalUtil.getPortalURL(layoutSet.getVirtualHostname(), Http.HTTP_PORT, false);
      }
    }

    return portalURL;
  }
  protected void updateLayoutSetPrototype(long groupId, boolean privateLayout)
      throws PortalException {

    // Layout

    LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, privateLayout);

    LayoutSetPrototype layoutSetPrototype =
        LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(
            layoutSet.getLayoutSetPrototypeId());

    Group layoutSetPrototypeGroup = layoutSetPrototype.getGroup();

    List<Layout> layoutSetPrototypeLayouts =
        LayoutLocalServiceUtil.getLayouts(layoutSetPrototypeGroup.getGroupId(), true);

    String[] layoutSetPrototypeLayoutUuids = new String[layoutSetPrototypeLayouts.size()];

    for (int i = 0; i < layoutSetPrototypeLayouts.size(); i++) {
      Layout layout = layoutSetPrototypeLayouts.get(i);

      layoutSetPrototypeLayoutUuids[i] = layout.getUuid();
    }

    List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(groupId, privateLayout);

    for (Layout layout : layouts) {
      if (ArrayUtil.contains(
          layoutSetPrototypeLayoutUuids, layout.getSourcePrototypeLayoutUuid())) {

        layout.setLayoutPrototypeUuid(StringPool.BLANK);
        layout.setLayoutPrototypeLinkEnabled(false);
        layout.setSourcePrototypeLayoutUuid(StringPool.BLANK);

        LayoutLocalServiceUtil.updateLayout(layout);
      }
    }

    // Layout set

    UnicodeProperties settingsProperties = layoutSet.getSettingsProperties();

    settingsProperties.remove("last-merge-time");

    layoutSet.setSettingsProperties(settingsProperties);

    layoutSet.setLayoutSetPrototypeUuid(StringPool.BLANK);
    layoutSet.setLayoutSetPrototypeLinkEnabled(false);

    LayoutSetLocalServiceUtil.updateLayoutSet(layoutSet);

    LayoutSetLocalServiceUtil.updateLookAndFeel(
        layoutSet.getGroupId(), null, null, StringPool.BLANK, false);
  }
コード例 #28
0
  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }

    LayoutSet layoutSet = null;

    try {
      layoutSet = (LayoutSet) obj;
    } catch (ClassCastException cce) {
      return false;
    }

    long primaryKey = layoutSet.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
コード例 #29
0
  public static Layout getSourcePrototypeLayout(Layout layout) {
    if (Validator.isNull(layout.getUuid())) {
      return null;
    }

    try {
      Group group = null;

      if (Validator.isNotNull(layout.getLayoutPrototypeUuid())) {
        LayoutPrototype layoutPrototype =
            LayoutPrototypeLocalServiceUtil.getLayoutPrototypeByUuid(
                layout.getLayoutPrototypeUuid());

        group = layoutPrototype.getGroup();
      } else {
        LayoutSet layoutSet = layout.getLayoutSet();

        if (Validator.isNull(layoutSet.getLayoutSetPrototypeUuid())) {
          return null;
        }

        LayoutSetPrototype layoutSetPrototype =
            LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototypeByUuid(
                layoutSet.getLayoutSetPrototypeUuid());

        group = layoutSetPrototype.getGroup();
      }

      return LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
          layout.getSourcePrototypeLayoutUuid(), group.getGroupId());
    } catch (Exception e) {
      _log.error(e, e);
    }

    return null;
  }
コード例 #30
0
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
      throws Exception {
    LayoutSet newLayoutSet1 = addLayoutSet();
    LayoutSet newLayoutSet2 = addLayoutSet();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newLayoutSet1.getPrimaryKey());
    primaryKeys.add(newLayoutSet2.getPrimaryKey());

    Map<Serializable, LayoutSet> layoutSets = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(2, layoutSets.size());
    Assert.assertEquals(newLayoutSet1, layoutSets.get(newLayoutSet1.getPrimaryKey()));
    Assert.assertEquals(newLayoutSet2, layoutSets.get(newLayoutSet2.getPrimaryKey()));
  }