#liferayobject
Explore tagged Tumblr posts
Text
Deactivating and activating custom modules for a particular site in Liferay 7.4 (Part 2)
In previous part, we have created a panel module now we will create a service builder to store the values given from the user and to pass it to theme. Then we will create a theme to get this data and deactivate it from the site.
Creating a service builder (IntelliJ)
To store the state of the portlet on a particular side and to send this information in theme we need a service builder.
To create a service builder this are the following steps:
Go to File -> New -> Module
2. Update the service.xml file
<?xml version="1.0"?> <!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 7.4.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_7_4_0.dtd"> <service-builder dependency-injector="ds" package-path="moduleblacklistservice"> <namespace>ModuleBlaclist</namespace> <!--<entity data-source="sampleDataSource" local-service="true" name="Foo" remote-service="false" session-factory="sampleSessionFactory" table="foo" tx-manager="sampleTransactionManager uuid="true"">--> <entity local-service="true" name="Portlet" remote-service="true" uuid="true"> <!-- PK fields --> <column name="id" primary="true" type="long" /> <!-- Group instance --> <column name="groupId" type="long" /> <!-- Audit fields --> <column name="companyId" type="long" /> <column name="userId" type="long" /> <column name="userName" type="String" /> <column name="createDate" type="Date" /> <column name="modifiedDate" type="Date" /> <!-- Other fields --> <column name="portletId" type="String" /> <column name="active" type="boolean" /> <!-- Finder methods --> <finder name="portletId" return-type="Collection"> <finder-column name="portletId" /> </finder> <finder name="groupId" return-type="Collection"> <finder-column name="groupId" /> </finder> <finder name="group_portlet" return-type="Collection"> <finder-column name="groupId" /> <finder-column name="portletId" /> </finder> </entity> </service-builder>
3. Update the local service implantation class
package moduleblacklistservice.service.impl; import com.liferay.portal.aop.AopService; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.model.User; import com.liferay.portal.kernel.service.ServiceContext; import com.liferay.portal.kernel.util.OrderByComparator; import moduleblacklistservice.model.Portlet; import moduleblacklistservice.service.base.PortletLocalServiceBaseImpl; import org.osgi.service.component.annotations.Component; import java.util.Date; import java.util.List; @Component( property = "model.class.name=moduleblacklistservice.model.Portlet", service = AopService.class ) public class PortletLocalServiceImpl extends PortletLocalServiceBaseImpl { public Portlet addPortlet( long userId, long groupId,String portletId,Boolean active, ServiceContext serviceContext) throws PortalException { User user = userLocalService.getUserById(userId); Date now = new Date(); long id = counterLocalService.increment(); Portlet portlet = portletPersistence.create(id); portlet.setPortletId(portletId); portlet.setActive(active); portlet.setCompanyId(user.getCompanyId()); portlet.setGroupId(groupId); portlet.setCreateDate(serviceContext.getCreateDate(now)); portlet.setModifiedDate(serviceContext.getModifiedDate(now)); portlet.setUserId(userId); portlet.setUserName(user.getScreenName()); portlet.setUuid(serviceContext.getUuid()); portlet.setExpandoBridgeAttributes(serviceContext); portletPersistence.update(portlet); return portlet; } public List<Portlet> getPortletByPortletId(String portletId) { return portletPersistence.findByportletId(portletId); } public List<Portlet> getPortletByGroupId(long groupId) { return portletPersistence.findBygroupId(groupId); } public List<Portlet> getPortlet(long groupId,String portletId) { return portletPersistence.findBygroup_portlet(groupId,portletId); } public List<Portlet> getPortlets(int start, int end) { return portletPersistence.findAll(start, end); } public List<Portlet> getPortlets(int start, int end, OrderByComparator<Portlet> obc) { return portletPersistence.findAll(start, end,obc); } public int getPortletsCount() { return portletPersistence.countAll(); } public List<Portlet> getPortlets() { return portletPersistence.findAll(); } }
After this you would be able to disable a portlet on a particular site. To disable:
Go to the ModuleBlackListConfiguration tab
2.Then go to action and uncheck the active status.
3.This will deactivate the module from the site.
We will only be able to deactivate MVC modules which are present in widget panel.
Conclusion
Using this you would be able to disable modules on a particular site without affecting the rest of the site.
Originally published by: Deactivating and activating custom modules for a particular site in Liferay 7.4 (Part 2)
0 notes
Text
Deactivating and activating custom modules for a particular site in Liferay 7.4 (Part 1)
In Liferay 7.4 we can deactivate or activate a module for Liferay portal. This can be done using the components and app manager section from the control panel.
But Liferay doesn’t provide any feature to activate or deactivate a module for a particular site. As it can be a necessary thing when we have multiple sites and want to limit modules for that. To achieve this in Liferay we must create a panel module, service builder and theme. In the following part we will create a panel module to list all custom modules and to give user the access to disable a module on a particular site. In second part we will create a service builder and theme.
Creating a panel module (IntelliJ)
To show and let users perform action we need a module to display portlets and take user action.
To create a panel module this are the following steps:
Go to File -> New -> Module
Select Liferay Modules
3.Give the name to the module and choose the project type panel app.
4.This will create a panel module.
5.After this to see all modules in view we need to add a render method that will give the list of all custom modules present on the portal.
The portlet will look like this:
As we don’t have service builder and theme, we won’t be able to perform the active and deactivating functionality. Conclusion
We have created a module to list all the custom modules and let the users have access to activate and deactivate modules for a particular site. In part 2 we will create a service builder and theme.
Originally published by: https://www.inexture.com/deactivating-and-activating-liferay-objects/
0 notes