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
<!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>
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();
}
}
Creating a theme
To generate a theme, you can follow the steps given in link.
After this you would be able to disable a portlet on a particular site. To disable:
- Go to the ModuleBlackListConfiguration tab
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)
Comments
Post a Comment