Library that allows to setup a number of Liferay artifacts in a DB. It uses xml configuration and Liferay APIs to add all configured artifacts. Artifacts in the database are created by Liferay common upgrade process. Each step of the upgrade process consists of one or more xml files, in which you can define artifacts to create or update.
First add this dependency into your OSGi module project's pom.xml
.
<dependency>
<groupId>eu.lundegaard.liferay</groupId>
<artifactId>liferay-db-setup-core</artifactId>
<version>3.1.0</version>
</dependency>
and specify the dependency in your bnd.bnd
file as a resource to include.
Include-Resource: @liferay-db-setup-core-3.1.0.jar
Second create UpgradeStepRegistrator
component to register your upgrade steps, e.g.
@Component(immediate = true, service = UpgradeStepRegistrator.class)
public class MyPortalUpgrade implements UpgradeStepRegistrator {
@Override
public void register(Registry registry) {
String packageName = MyPortalUpgrade.class.getPackage().getName();
registry.register(packageName, "1.0.0", "1.0.1", new GenericUpgradeStep("v1_0_1"));
}
}
You can also call one of the LiferaySetup.setup
methods directly to setup the database.
XML file of an upgrade step has usually this structure:
<?xml version="1.0" encoding="UTF-8" ?>
<setup xmlns="http://www.lundegaard.eu/liferay/setup">
<configuration>
<runasuser>[email protected]</runasuser>
</configuration>
<!-- Artifacts to manage -->
</setup>
runasuser
defines under which user artifacts will be created. Then you can specify as many artifacts to setup as you want.
For instance, this will create Role with Publisher as a name.
<?xml version="1.0" encoding="UTF-8" ?>
<setup xmlns="http://www.lundegaard.eu/liferay/setup">
<configuration>
<runasuser>[email protected]</runasuser>
</configuration>
<roles>
<role name="Publisher"/>
</roles>
</setup>
In Artifacts to manage section you can specify a lot of artifacts.
<roles>
<role name="Publisher"/>
</roles>
This will create expando attribute canonical-url with permissions to view by guest user.
<customFields>
<field name="canonical-url" type="string" className="com.liferay.portal.kernel.model.Layout">
<role-permission role-name="Guest">
<permission-action action-name="VIEW"/>
</role-permission>
</field>
</customFields>
Site element must always have site-friendly-url
filled. Guest site is determined by default
attribute with true
value. Other sites are specified by name
attribute.
<sites>
<site default="true" site-friendly-url="/guest">
</site>
<site name="My web" default="false" >
</site>
</sites>
Document's file itself is determined by file-system-name
attribute which defines resource on classpath.
<document file-system-name="my-project/documents/icons/icon-home.svg"
document-folder-name="/Icons"
document-filename="icon-home.svg"
document-title="icon-home.svg"/>
Article's content is determined by path
attribute which defines resource on classpath. The resource contains article content in the form of XML.
<article title="Footer"
path="my-project/articles/homepage/web_content/footer.xml"
article-structure-key="BASIC-WEB-CONTENT"
article-template-key="BASIC-WEB-CONTENT"
articleId="FOOTER"
article-folder-path="/Footer">
</article>
<article-structure key="BANNER-MAIN"
path="my-project/articles/homepage/structures/banner-main.json"
name="Banner - main"/>
<article-template key="BANNER-MAIN"
path="my-project/articles/homepage/templates/banner-main.ftl"
article-structure-key="BANNER-MAIN" name="Banner - main" cacheable="true"/>
You can create/update/set many other artifacts like User, Organization, Page, Portlet placement, Permission, ... See source code.
|| Liferay Portal Version || Version || | 7.3.x | 3.1.x | | 7.2.x | 3.0.x | | older | use original Mimacom library |