@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) {
      }
    }
  }
  /**
   * 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;
  }
  @Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    LayoutSet newLayoutSet = addLayoutSet();

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

    Assert.assertEquals(existingLayoutSet, newLayoutSet);
  }
  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>");
    }
  }
  @Test
  public void testCreate() throws Exception {
    long pk = RandomTestUtil.nextLong();

    LayoutSet layoutSet = _persistence.create(pk);

    Assert.assertNotNull(layoutSet);

    Assert.assertEquals(layoutSet.getPrimaryKey(), pk);
  }
  @Test
  public void testRemove() throws Exception {
    LayoutSet newLayoutSet = addLayoutSet();

    _persistence.remove(newLayoutSet);

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

    Assert.assertNull(existingLayoutSet);
  }
  /**
   * 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())
        });
  }
 /**
  * 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);
     }
   }
 }
  @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()));
  }
  @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;
  }
  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());
  }
  @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]));
  }
  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;
  }
Beispiel #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;
  }
  /**
   * 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();
  }
  @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;
  }
  public void buildDocument(Element element, LayoutSet layoutSet, ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

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

    addUsers(element, suppliedGroup, themeDisplay);
  }
  @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);
  }
  @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()));
  }
  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;
  }
  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;
  }
  @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;
    }
  }
  @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;
  }
  @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);
  }
  @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);
  }
  @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;
    }
  }
  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;
  }
  @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()));
  }