Skip to content

Library that allows to setup a number of Liferay Portal artifacts in the DB. It uses xml configuration and Liferay APIs to add all configured artifacts.

License

Notifications You must be signed in to change notification settings

lundegaard/liferay-db-setup-core

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Artifact Javadocs

Liferay Portal DB Setup core

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.

What's new in 4.0.0?
Upgrade to work with Liferay API version 7.4.
Addition of possibility to setup artifacts for not default company.
Addition of Tags.

⚠️ BREAKING CHANGES ⚠️

In version 4.0.0 definition of configuration element was made, that is not backwards compatible with lower versions. See XML File Content to see how it was changed.

Usage

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>4.0.0</version>
</dependency>

and specify the dependency in your bnd.bnd file as a resource to include.

Include-Resource: @liferay-db-setup-core-4.0.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 content

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="test@liferay.com"/>
        <company companyId="2050040"/>
    </configuration>

    <!-- Artifacts to manage --> 
</setup>

runasuser defines under which user artifacts should be created. Then you can specify as many artifacts to setup as you want.

NEW:
company defines in which company should the setups be done. It is optional element.
Company is set using defined attributes

  • companyMx
  • companyWebId
  • logoId
  • virtualHost

To make sure that the company is set correctly make sure you use only one of those attributes. Combination of those attributes could lead to undesired behavior.


Example of whole XML file

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="test@liferay.com"/>
    </configuration>
 
    <roles>
        <role name="Publisher"/>
    </roles>
</setup>

Features

In Artifacts to manage section you can specify a lot of artifacts.

Roles

Code below creates Role named "Content Admin" that can VIEW com.liferay.layout.page.template.model.LayoutPageTemplateEntry

<roles>
    <role name="Content admin">
        <define-permissions>
            <define-permission define-permission-name="com.liferay.layout.page.template.model.LayoutPageTemplateEntry">
                <permission-action action-name="VIEW"/>
            </define-permission>
        </define-permissions>
    </role>
</roles>

Expando attribute

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

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 Folder

Create Document folder named "/Icons" if it does not exist.

<document-folder create-if-not-exists="true" folder-name="/Icons" />

Document

Create Document. 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 Folder

Code below creates folder for articles.

<article-folder folder-path="/links" description="Folder for links"/>

Articles

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

<article-structure key="BANNER-MAIN"
                   path="my-project/articles/homepage/structures/banner-main.json"
                   name="Banner - main"/>

Article Template

<article-template key="BANNER-MAIN"
                  path="my-project/articles/homepage/templates/banner-main.ftl"
                  article-structure-key="BANNER-MAIN" name="Banner - main" cacheable="true"/>

Fragment Collection and Fragments

Fragment collections and fragments can be created, updated or deleted. This action is determined via setup-action attributes.
Fragment content can be set by path attribute or by inner tag <![CDATA[]]>.

 <fragment-collection name="FragmentCollection" setup-action="update">
        <fragment name="test-fragment" entryKey="test-fragmentKey">
            <html path="my-project/content/fragments/test-fragment/content.html" />
            <css>
            <![CDATA[
            .fragment-text-red{
            	color:red !important;
            }
            ]]>
            </css>
            <js></js>
            <configuration path="my-project/content/fragments/test-fragment/config.json" />
        </fragment>
    </fragment-collection>

Organizations

Create Organization named setup-organization

<organizations>
   <organization name="setup-organization">
   </organization>
</organizations>

User Groups

Create user group.

<userGroups>
   <userGroup name="setup-group" description="This is setup group.">
       <role name="Content administrator">
       </role>
   </userGroup>
</userGroups>

User

Create User.

 <users>
    <user screenName="SetupUserOne" emailAddress="test@test.com" password="test" firstName="FirstName" lastName="LastName">
        <role name="Client administrator">
        </role>
    </user>
</users>

Vocabulary and Categories

Creates Vocabulary and Categories within.

<vocabulary name="setup-vocabulary">
    <category name="setup-category" description="This is created vocabulary.">
        <title-translation locale="en_US" title-text="Vocabulary"/>
        <title-translation locale="cs_CZ" title-text="Slovník"/>
    </category>
</vocabulary>

Tags

Create tags.

<tags>
    <tag name="news-article"/>
    <tag name="faq-questions"/>
</tags>

Pages

Setup Public and Private Pages.

<public-pages>
    <page friendlyURL="/setup-page" name="Setup Page">
        <custom-field-setting key="IS_SUPERB_PAGE" value="true"/>
        <page friendlyURL="/child-page" name="Child Page">
            <title-translation locale="en_US" title-text="Child Page"/>
            <title-translation locale="cs_CZ" title-text="Podstránka"/>
        </page>
    </page>
</public-pages>
<private-pages>
    <page friendlyURL="/setup-private" name="Private Page">
    </page>
</private-pages>

Others

You can create/update/set many other artifacts like Portlet placement, Permission, ... See source code.

Compatibility

Liferay Portal Version Version
7.4.x 4.x.x
7.3.x 3.1.x
7.2.x 3.0.x
older use original Mimacom library

Note: New changes introduced in version 4.0.0 may not be backwards compatible. Such as Tags and Company.
See the source if you are not sure about some features.

About

Library that allows to setup a number of Liferay Portal artifacts in the DB. It uses xml configuration and Liferay APIs to add all configured artifacts.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 99.0%
  • Other 1.0%