Library that allows to automate Liferay data setup. It uses XML configuration input to add the data.
-
Install the
com.ableneo.liferay.db.setup.core-7.4.3125.2.jar
bundle in${liferay.home}/osgi/modules
-
Prepare your own bundle that uses the library as a
provided
/compileOnly
dependency. For example:build.gradledependencies { compileOnly 'com.ableneo.liferay:com.ableneo.liferay.db.setup.core:7.4.3125.2' }
pom.xml<dependency> <groupId>com.ableneo.liferay</groupId> <artifactId>com.ableneo.liferay.db.setup.core</artifactId> <version>7.4.3125.2</version> <scope>provided</scope> </dependency>
-
Prepare xml data configuration. Documentation sits directly in the setup_definition.xsd file.
Example configuration: setup.xml<?xml version="1.0" encoding="UTF-8" ?> <setup xmlns="http://www.ableneo.com/liferay/setup"> <configuration> <!-- uses random administrator account for the setup in the company, run-as-user-email tag allows to specify particular admin account to be used for the setup --> <company> <companyid>20101</companyid> <!-- companywebid can be used alternatively --> </company> </configuration> <sites> <site> <!-- Guest by default --> <vocabulary name="Some categories" uuid="602f55b6-6021-455e-8d6d-696cc25daa91"> <title-translation locale="de_DE" text="Einige Kategorien"/> <category name="Other categories" uuid="867b33df-2465-4a81-9945-88159c604589"> <title-translation locale="de_DE" text="Andere Kategorien"/> <category name="New category" uuid="5fb4308e-bd21-4cf4-bdc5-3557508ffe4a"> <title-translation locale="de_DE" text="Neue Kategorie"/> </category> </category> </vocabulary> </site> </sites> </setup>
-
Load the XML setup file and run
setup
method on it:URL resource = Thread.currentThread().getContextClassLoader().getResource(path); InputStream setupFile = Objects.requireNonNull(resource, "XML Liferay DB setup file not found in classpath.").openStream(); Setup setup = MarshallUtil.unmarshall(setupFile); boolean setupSuccess = LiferaySetup.setup(setup);
Used primarily for integration testing but may be a good start for your application: com.ableneo.liferay.portal.setup.example
Bundling XML descriptors and code that will execute them in bundle separate to the
All data definitions in the setup XML file are applied according to the configuration
header. The header defines:
-
the virtual instance on which the library will modify the data.
-
admin user account to be used for data modification
<?xml version="1.0" encoding="UTF-8"?>
<setup xmlns="http://www.ableneo.com/liferay/setup">
<configuration>
<!-- run as automatically selected admin -->
<company>
<companywebid>liferay.com</companywebid>
</company>
</configuration>
</setup>
<?xml version="1.0" encoding="UTF-8"?>
<setup xmlns="http://www.ableneo.com/liferay/setup">
<configuration>
<run-as-user-email>admin@my.web.com</run-as-user-email>
<company>
<companywebid>liferay.com</companywebid>
</company>
</configuration>
</setup>
Service access policy is a second from four of Liferay’s API security layers. Together with IP Permission Layer, Authentication and verification layer and User permission layer is responsible for securing access to web services provided by portal instance.
If you develop new REST Builder REST/GraphQL endpoint’s it’s a common requirement to setup an access for those API’s for an unauthenticated portal user- Guest which is by default forbidden.
<?xml version="1.0" encoding="UTF-8"?>
<setup xmlns="http://www.ableneo.com/liferay/setup">
<company-settings>
<service-access-policies>
<service-access-policy name="MY_ACCESS_POLICY" enabled="true" unauthenticated="true">
<title locale="sk_SK" text="Moja pristupova politika" />
<allowed-service-signatures> (1)
com.liferay.headless.admin.user.internal.resource.v1_0.SiteResourceImpl#getSite
</allowed-service-signatures>
</service-access-policy>
</service-access-policies>
</company-settings>
</setup>
-
allowed-service-signatures
provides the same functionality as Advanced Mode
<?xml version="1.0" encoding="UTF-8"?>
<setup xmlns="http://www.ableneo.com/liferay/setup">
<company-settings>
<service-access-policies>
<delete-service-access-policy name="WIZARD_GUEST_ACCESS"/>
</service-access-policies>
</company-settings>
</setup>
Resource permissions.
<?xml version="1.0" encoding="UTF-8"?>
<setup xmlns="http://www.ableneo.com/liferay/setup">
<resource-permissions>
<resource resource-id="my.custom.resource.string">
<actionId name="SPECIAL_PERMISSION">
<role name="My Role"/>
<role name="Your Role"/>
</actionId>
</resource>
</resource-permissions>
</setup>
Resource permissions are set per company are verifiable with followin API call.
permissionChecker.hasPermission(
groupId,
"my.custom.resource.string",
companyId,
"SPECIAL_PERMISSION"
);
Portlet permissions.
<?xml version="1.0" encoding="UTF-8"?>
<setup xmlns="http://www.ableneo.com/liferay/setup">
<resource-permissions>
<resource resource-id="myportlet_WAR_portlets">
<actionId name="VIEW">
<role name="User"/>
<role name="Guest"/>
</actionId>
</resource>
</resource-permissions>
</setup>
<?xml version="1.0" encoding="UTF-8"?>
<setup xmlns="http://www.ableneo.com/liferay/setup">
<roles>
<role name="Regular Role"/>
<role name="Site Role" type="site"/>
</roles>
</setup>
Following snippet creates expando attribute canonical-url
with permissions to view by guest user.
<?xml version="1.0" encoding="UTF-8"?>
<setup xmlns="http://www.ableneo.com/liferay/setup">
<custom-fields>
<field name="canonical-url" type="string" class-name="com.liferay.portal.kernel.model.Layout">
<role-permission role-name="Guest" permission="view"/>
</field>
</custom-fields>
</setup>
All content like pages, articles, documents etc. is always created within a specific site. You can create new or refer to existing site.
<?xml version="1.0" encoding="UTF-8"?>
<setup xmlns="http://www.ableneo.com/liferay/setup">
<sites>
<site default="true">
<!-- default company site -->
</site>
<site global="true">
<!-- global company site -->
</site>
<site default="false" site-friendly-url="/admin" name="Admin">
<!-- specific site -->
<name-translation locale="en_US" text="Admin"/>
</site>
</sites>
</setup>
Files new_structure.xml
and new_structure_template.ftl
are deployed as a part of a module that is using the db-setup-core
library and reside in it’s classpath.
<?xml version="1.0" encoding="UTF-8"?>
<setup xmlns="http://www.ableneo.com/liferay/setup">
<sites>
<site site-friendly-url="/admin" name="Admin">
<article-structure key="NEW-STRUCTURE-KEY"
path="new_structure.xml"
name="New Structure"/>
<article-template key="NEW-STRUCTURE-TEMPLATE-KEY"
path="new_structure_template.ftl"
article-structure-key="NEW-STRUCTURE-KEY" name="New Structure Template" cacheable="true"/>
</site>
</sites>
</setup>
File artcle.xml
is deployed as a part of a module that is using the db-setup-core
library and reside in it’s classpath.
<?xml version="1.0" encoding="UTF-8"?>
<setup xmlns="http://www.ableneo.com/liferay/setup">
<sites>
<site global="true">
<article
title="Article Title"
path="article.xml"
article-structure-key="NEW-STRUCTURE-KEY"
article-template-key="NEW-STRUCTURE-TEMPLATE-KEY"
articleId="ARTICLE_ID">
<tag name="product" />
</article>
</site>
</sites>
</setup>
Document’s file itself is determined by file-system-name
attribute which defines resource on classpath.
<?xml version="1.0" encoding="UTF-8"?>
<setup xmlns="http://www.ableneo.com/liferay/setup">
<sites>
<site name="Guest">
<document file-system-name="image.svg"
document-folder-name="/Images"
document-filename="image.svg"
document-title="image.svg"/>
</site>
</sites>
</setup>
The code is compatible with Liferay Portal 7.4.3.125. Other versions that have been or are supported: