コード例 #1
0
  protected LayoutPrototype addLayoutPrototype() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    LayoutPrototype layoutPrototype = _persistence.create(pk);

    layoutPrototype.setMvccVersion(ServiceTestUtil.nextLong());

    layoutPrototype.setUuid(ServiceTestUtil.randomString());

    layoutPrototype.setCompanyId(ServiceTestUtil.nextLong());

    layoutPrototype.setUserId(ServiceTestUtil.nextLong());

    layoutPrototype.setUserName(ServiceTestUtil.randomString());

    layoutPrototype.setCreateDate(ServiceTestUtil.nextDate());

    layoutPrototype.setModifiedDate(ServiceTestUtil.nextDate());

    layoutPrototype.setName(ServiceTestUtil.randomString());

    layoutPrototype.setDescription(ServiceTestUtil.randomString());

    layoutPrototype.setSettings(ServiceTestUtil.randomString());

    layoutPrototype.setActive(ServiceTestUtil.randomBoolean());

    _persistence.update(layoutPrototype);

    return layoutPrototype;
  }
コード例 #2
0
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    LayoutPrototype newLayoutPrototype = _persistence.create(pk);

    newLayoutPrototype.setMvccVersion(ServiceTestUtil.nextLong());

    newLayoutPrototype.setUuid(ServiceTestUtil.randomString());

    newLayoutPrototype.setCompanyId(ServiceTestUtil.nextLong());

    newLayoutPrototype.setUserId(ServiceTestUtil.nextLong());

    newLayoutPrototype.setUserName(ServiceTestUtil.randomString());

    newLayoutPrototype.setCreateDate(ServiceTestUtil.nextDate());

    newLayoutPrototype.setModifiedDate(ServiceTestUtil.nextDate());

    newLayoutPrototype.setName(ServiceTestUtil.randomString());

    newLayoutPrototype.setDescription(ServiceTestUtil.randomString());

    newLayoutPrototype.setSettings(ServiceTestUtil.randomString());

    newLayoutPrototype.setActive(ServiceTestUtil.randomBoolean());

    _persistence.update(newLayoutPrototype);

    LayoutPrototype existingLayoutPrototype =
        _persistence.findByPrimaryKey(newLayoutPrototype.getPrimaryKey());

    Assert.assertEquals(
        existingLayoutPrototype.getMvccVersion(), newLayoutPrototype.getMvccVersion());
    Assert.assertEquals(existingLayoutPrototype.getUuid(), newLayoutPrototype.getUuid());
    Assert.assertEquals(
        existingLayoutPrototype.getLayoutPrototypeId(), newLayoutPrototype.getLayoutPrototypeId());
    Assert.assertEquals(existingLayoutPrototype.getCompanyId(), newLayoutPrototype.getCompanyId());
    Assert.assertEquals(existingLayoutPrototype.getUserId(), newLayoutPrototype.getUserId());
    Assert.assertEquals(existingLayoutPrototype.getUserName(), newLayoutPrototype.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingLayoutPrototype.getCreateDate()),
        Time.getShortTimestamp(newLayoutPrototype.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingLayoutPrototype.getModifiedDate()),
        Time.getShortTimestamp(newLayoutPrototype.getModifiedDate()));
    Assert.assertEquals(existingLayoutPrototype.getName(), newLayoutPrototype.getName());
    Assert.assertEquals(
        existingLayoutPrototype.getDescription(), newLayoutPrototype.getDescription());
    Assert.assertEquals(existingLayoutPrototype.getSettings(), newLayoutPrototype.getSettings());
    Assert.assertEquals(existingLayoutPrototype.getActive(), newLayoutPrototype.getActive());
  }
コード例 #3
0
  @Override
  public LayoutPrototype updateLayoutPrototype(
      long layoutPrototypeId,
      Map<Locale, String> nameMap,
      String description,
      boolean active,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Layout prototype

    LayoutPrototype layoutPrototype =
        layoutPrototypePersistence.findByPrimaryKey(layoutPrototypeId);

    layoutPrototype.setModifiedDate(serviceContext.getModifiedDate(new Date()));
    layoutPrototype.setNameMap(nameMap);
    layoutPrototype.setDescription(description);
    layoutPrototype.setActive(active);

    layoutPrototypePersistence.update(layoutPrototype);

    // Group

    Group group =
        groupLocalService.getLayoutPrototypeGroup(
            layoutPrototype.getCompanyId(), layoutPrototypeId);

    group.setName(layoutPrototype.getName(LocaleUtil.getDefault()));

    groupPersistence.update(group);

    // Layout

    Layout layout = layoutPrototype.getLayout();

    layout.setModifiedDate(layoutPrototype.getModifiedDate());
    layout.setNameMap(nameMap);

    layoutPersistence.update(layout);

    return layoutPrototype;
  }
コード例 #4
0
  @Override
  public LayoutPrototype addLayoutPrototype(
      long userId,
      long companyId,
      Map<Locale, String> nameMap,
      String description,
      boolean active,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Layout prototype

    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();

    long layoutPrototypeId = counterLocalService.increment();

    LayoutPrototype layoutPrototype = layoutPrototypePersistence.create(layoutPrototypeId);

    layoutPrototype.setUuid(serviceContext.getUuid());
    layoutPrototype.setCompanyId(companyId);
    layoutPrototype.setUserId(userId);
    layoutPrototype.setUserName(user.getFullName());
    layoutPrototype.setCreateDate(serviceContext.getCreateDate(now));
    layoutPrototype.setModifiedDate(serviceContext.getModifiedDate(now));
    layoutPrototype.setNameMap(nameMap);
    layoutPrototype.setDescription(description);
    layoutPrototype.setActive(active);

    layoutPrototypePersistence.update(layoutPrototype);

    // Resources

    if (userId > 0) {
      resourceLocalService.addResources(
          companyId,
          0,
          userId,
          LayoutPrototype.class.getName(),
          layoutPrototype.getLayoutPrototypeId(),
          false,
          false,
          false);
    }

    // Group

    String friendlyURL = "/template-" + layoutPrototype.getLayoutPrototypeId();

    Group group =
        groupLocalService.addGroup(
            userId,
            GroupConstants.DEFAULT_PARENT_GROUP_ID,
            LayoutPrototype.class.getName(),
            layoutPrototype.getLayoutPrototypeId(),
            GroupConstants.DEFAULT_LIVE_GROUP_ID,
            layoutPrototype.getName(LocaleUtil.getDefault()),
            null,
            0,
            true,
            GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION,
            friendlyURL,
            false,
            true,
            null);

    if (GetterUtil.getBoolean(serviceContext.getAttribute("addDefaultLayout"), true)) {

      layoutLocalService.addLayout(
          userId,
          group.getGroupId(),
          true,
          LayoutConstants.DEFAULT_PARENT_LAYOUT_ID,
          layoutPrototype.getName(LocaleUtil.getDefault()),
          null,
          null,
          LayoutConstants.TYPE_PORTLET,
          false,
          "/layout",
          serviceContext);
    }

    return layoutPrototype;
  }