@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());
  }
  @Override
  @SystemEvent(action = SystemEventConstants.ACTION_SKIP, type = SystemEventConstants.TYPE_DELETE)
  public LayoutPrototype deleteLayoutPrototype(LayoutPrototype layoutPrototype)
      throws PortalException, SystemException {

    // Group

    if (layoutPersistence.countByLayoutPrototypeUuid(layoutPrototype.getUuid()) > 0) {

      throw new RequiredLayoutPrototypeException();
    }

    Group group = layoutPrototype.getGroup();

    groupLocalService.deleteGroup(group);

    // Resources

    resourceLocalService.deleteResource(
        layoutPrototype.getCompanyId(),
        LayoutPrototype.class.getName(),
        ResourceConstants.SCOPE_INDIVIDUAL,
        layoutPrototype.getLayoutPrototypeId());

    // Layout Prototype

    layoutPrototypePersistence.remove(layoutPrototype);

    // Permission cache

    PermissionCacheUtil.clearCache();

    return layoutPrototype;
  }
  @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;
  }