@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 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; }
protected void populateElementLayoutMetadata(Element layoutElement, Layout layout) throws Exception { LayoutStagingHandler layoutStagingHandler = LayoutStagingUtil.getLayoutStagingHandler(layout); if (layoutStagingHandler != null) { LayoutRevision layoutRevision = layoutStagingHandler.getLayoutRevision(); if (layoutRevision != null) { layoutElement.addAttribute( "layout-revision-id", String.valueOf(layoutRevision.getLayoutRevisionId())); layoutElement.addAttribute( "layout-branch-id", String.valueOf(layoutRevision.getLayoutBranchId())); LayoutBranch layoutBranch = layoutRevision.getLayoutBranch(); layoutElement.addAttribute("layout-branch-name", String.valueOf(layoutBranch.getName())); } } layoutElement.addAttribute("layout-uuid", layout.getUuid()); layoutElement.addAttribute("layout-id", String.valueOf(layout.getLayoutId())); layoutElement.addAttribute("layout-priority", String.valueOf(layout.getPriority())); String layoutPrototypeUuid = layout.getLayoutPrototypeUuid(); if (Validator.isNotNull(layoutPrototypeUuid)) { LayoutPrototype layoutPrototype = _layoutPrototypeLocalService.getLayoutPrototypeByUuidAndCompanyId( layoutPrototypeUuid, layout.getCompanyId()); layoutElement.addAttribute("layout-prototype-uuid", layoutPrototypeUuid); layoutElement.addAttribute( "layout-prototype-name", layoutPrototype.getName(LocaleUtil.getDefault())); } }
@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; }
@Override public String getDescriptiveName(Locale locale) throws PortalException { Group curGroup = this; String name = getName(locale); if (Validator.isNull(name)) { Locale siteDefaultLocale = PortalUtil.getSiteDefaultLocale(getGroupId()); name = getName(siteDefaultLocale); } if (isCompany() && !isCompanyStagingGroup()) { name = LanguageUtil.get(locale, "global"); } else if (isControlPanel()) { name = LanguageUtil.get(locale, "control-panel"); } else if (isGuest()) { Company company = CompanyLocalServiceUtil.getCompany(getCompanyId()); Account account = company.getAccount(); name = account.getName(); } else if (isLayout()) { Layout layout = LayoutLocalServiceUtil.getLayout(getClassPK()); name = layout.getName(locale); } else if (isLayoutPrototype()) { LayoutPrototype layoutPrototype = LayoutPrototypeLocalServiceUtil.getLayoutPrototype(getClassPK()); name = layoutPrototype.getName(locale); } else if (isLayoutSetPrototype()) { LayoutSetPrototype layoutSetPrototype = LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(getClassPK()); name = layoutSetPrototype.getName(locale); } else if (isOrganization()) { long organizationId = getOrganizationId(); Organization organization = OrganizationLocalServiceUtil.getOrganization(organizationId); name = organization.getName(); curGroup = organization.getGroup(); } else if (isUser()) { long userId = getClassPK(); User user = UserLocalServiceUtil.getUser(userId); name = user.getFullName(); } else if (isUserGroup()) { long userGroupId = getClassPK(); UserGroup userGroup = UserGroupLocalServiceUtil.getUserGroup(userGroupId); name = userGroup.getName(); } else if (isUserPersonalSite()) { name = LanguageUtil.get(locale, "user-personal-site"); } if (curGroup.isStaged() && !curGroup.isStagedRemotely() && curGroup.isStagingGroup()) { Group liveGroup = getLiveGroup(); name = liveGroup.getDescriptiveName(locale); } return name; }