Packaging Document Structures and templates in Liferay plugin wars - liferay

Is there a way to include Liferay document or web-content structures and templates in portlet plugin war files and have them become available to users like the standard ones are?
The use-case would be that you are writing a portlet that takes advantage of a custom Document Library structure that you are providing. But you don't want to distribute this structure as a separate thing with its own installation procedure (such as providing a LAR just for the structure), you just want your plugin to make the custom structure available whenever it is installed.

You can achieve your goal by adding a portal.properties file to the WEB-INF/classes directory of your portlet. This file should contain the following line:
application.startup.events=com.yourcompany.whatever.YourCustomStartupAction
This custom startup action should be a class that extends from com.liferay.portal.kernel.events.SimpleAction. In it you will be able to leverage all the Liferay service utils to do things in Liferay at the moment your portlet is started. The class you need to use to work with the Liferay document library specifically is DLAppLocalServiceUtil. This util class has all the necessary methods to work with files/folders in the document library.
For web content related stuff, such as structures, templates and articles, just use JournalStructureLocalServiceUtil, JournalTemplateLocalServiceUtil and JournalArticleLocalServiceUtil.

I hope i got your question right ;)
You could create the folder Structure via the DLFolderService when the portlet is deployed.
To run a method when the Server starts you will have to use the CustomAction i think, check it out : here

Related

How can I create Liferay web content structure's outside of Liferay configuration?

I'm very new to Liferay theme development and i'm trying to find the most optimal workflow for development.
So I've been experimenting with creating Web Content Templates and Web Content Structures within Liferay CMS configuration.
What I would ideally like to do is create my view "Web Content Structure" outside of Liferay configuration and instead have it as a view/template inside my theme files so that I can have my code peer reviewed and version controlled in Bitbucket.
Is this possible?
Alternatively is there a way to output the values of a given web content instance within my theme?
I'm building a theme for Liferay 7 by the way.
Thanks in advance
Richard
You can copy and paste the structure when you create them form the LFR editors into your source code repository.
Also if you know how to define the JSON you can do it straight in the file. The free market templates are even easier to edit in file format. When you're done, you need to go and upload the artefacts to the portal via the editor/file upload option.
You can't stick it into the theme because that approach would not allow you to do updates.
You can search for a community plugin or write your own one that would do structure/template updates during deploy.

Automatic way of export / import pages from liferay

I have created portlets for liferay and prepare couple of pages. Now I want to create installation script, which create pages definition in customer liferay server. I know that pages export/import is possible using LAR file, but this could be done only manualy, or using remote publishing which i am not able to do.
I was searching on net and found ddm tool. Which should be able to do that. Unfortunately i'm not able to get it work as it export only web content, blogs, wikis, etc, but not pages with portlets. It is probably because one of the condition is "Every Template must be assigned to a Structure. Don't create any templates on the Liferay server which does not have a structure connected to it.
". But how can I assign page to structure ? Cant find anything.
Or is there any other option for automatic page creation, which could be used ?
In case you created a custom theme, you can easily use the "resources importer" to create an entire site via the "sitemap.json" file (define pages: choose layout, assign portlets to the columns, ...). You can also export existing content as xml from the current instance and import them via the theme. Same thing for web content structures and templates.
for more details: https://dev.liferay.com/develop/tutorials/-/knowledge_base/6-1/importing-resources-with-your-themes
Unfortunately theme is produced by another supplier, so this solution isn't suitable for me.
at the end i find working solution which consist of following steps:
create plugin hook
in hook setup upgrade process
in the upgrade process create pages with appropriate layout, friendlyUrl, etc. All these is possible to do using liferay api
Don't have enough reputation, so at least two links
https://www.liferay.com/de/web/james.falkner/blog/-/blogs/7cogs-is-dead-long-live-7cogs-
https://github.com/azzazzel/liferay-official-plugins/tree/master/hooks/sevencogs-hook/docroot/WEB-INF/src/com/liferay/sevencogs/hook/upgrade

Liferay create site / page programmatically

I have been using Liferay for work for 2 weeks. I noticed that it's a bit difficult to find good documentation and tutorials.
Until now I created pages from the web portal. After I create them, I drag and drop portlets. I don't really like this approach, I would prefer to use a coding approach. Is there a way to create a website or page programmatically by defining a project as I do to create portlets?
Moreover, I am using Liferay with WebLogic 10.3.6. I want to know where liferay puts pages I created via web-portal on the file system. I suppose that a file, or something similar, is created when I declare a new site on the Liferay web-portal.
Thank you all,
Marco
Yes Liferay has it's Database, all data of any Liferay object is stored in the database and / or on the file system depending on your configuration.
However, one of the functionality of Liferay is to let you create pages / sites through the UI. As documented in the Java Portal Specification and Liferay Server Documents your approach to create pages in an alternative way is possible but it is part of Liferay's Portal Services. You can use Liferay's Service (HTTP REST) API to call the related service. To access those APIs you need to configure your Liferay Server.
In case you want to do programmatically you still need to configure, enable and call those external HTTP services from your code. You should not create Liferay Objects from your own code hosted as an extension inside your Liferay Instance as that will result inconsistency in your Liferay Database / filesystem. (As in case of page creation Liferay creates a set of other related objects in it's database / filesystem.)
In your liferay bundle you will find two plugins of interest.
First is resources-importer-web for which description says
The Resources Importer app allows front-end developers to package web
content, portlet configurations, and layouts together in a theme
without saving it as a compiled .LAR file thereby allowing for greater
flexibility in its usage between Liferay Portal versions.This app will automatically create associated content when other
plugins are deployed that are configured to make use of the Resource
Importer app.This app installs as a Liferay service.
Second is welcome-theme which declares resources to be created by resources-importer-web. This on should be example how to create your own. Take a look at
welcome-theme\WEB-INF\src\resources-importer\*
welcome-theme\WEB-INF\liferay-plugin-package.properties
This feature is described at importing-resources-with-themes
As mentioned by gabor_the_kid, Liferay stores all objects in its tables. For example, User related objects would be in user table. Liferay exposed services or API's to change the default/to add new behaviors by program but not easier than achieving it through UI. Also maintenance should be considered for going program way of creating pages or layouts etc.
You can describe your changes using xml and use the Liferay Portal DB Setup core to create the changes in DB.
The library defines the list of available xml configurations.

Two portlets with same database

I am developing Liferay portal and I have one portlet which handles the administrator side of the portal and one the client side. The thing is that the clients cannot see the administrator page (including the portlet). Also I have created custom DataBase for the portal (I included my own tables in the Liferay database using Service Builder). Now I want to use the same database so I can take info from it using the client portlet.
Any ideas?
I am using Liferay 6.1 with Tomcat and Liferay SDK plugin for Eclipse.
You can copy the [portlet name]-service.jar from Web-Inf/lib, and paste it to any other portlet's lib folder. Even better if you can do this with maven and add this jar as a dependency. This way you can have access to the Util Classes that your service provides, to any other Portlet
All portlets in a plugin project share the service builder service made by that plugin (because they end up in one war file and thus share runtime context). So you could just put both your portlets in the same plugin and they can both access that plugin's service builder services/tables. I think you will find this is a commonly used approach. The permission and visibility issues you mention are not impacted by this organization.
Doing it this way keeps the deployment simple -- just deploy the plugin's war, done.
If there are reasons beyond your control that require the portlets to be in separate plugins, then it becomes harder -- yannicuLar's approach is one way.
If you have two portlets sharing same tables/entities , you can copy the service.jar to
tomcat-7.0.27\lib\ext a common location where these two portlets can access this .jar at runtime.

Utilize Organization selection in custom portlet

I want to use Liferay's Organization select/search feature such as when adding a new user through the Control Panel (under Users and Organizations).
Does anyone know where that code lives? Trying to get a grasp on navigating their source code but can't find it.
Thanks
All the liferay OOTB portlets' JSPs lie in the folder portal-web/docroot/html/portlet.
And all the implementation classes (service implementation) reside in the portal-impl/src/com/liferay/portlet for respective portlets.
So keeping this convention in mind, the JSPs for the Users & Organization would reside in portal-web/docroot/html/portlet/users_admin since you can't see any folder with the name users or organizations or users_organization, so your best bet is to look inside the users_admin folder, also because this folder has user & organization folder which include specific JSPs for Users and Organizations.
In this folder you would find different *search.jsp & *search_results.jsp which would be what you might be looking for.
I would suggest always start looking from the view.jsp for a particular portlet since this is the first landing page when we add the portlet to the page or click on any Control Panel portlets the first time. Most probably this view.jsp would include all the other JSPs which you might want to customize or take an idea from.
Most of the time the JSPs lead you to the implementation classes, we can't use liferay's implementation classes (since they live in portal-impl.jar and using this jar in plugin-portlets is prohibited) but we can use the different *Util.java classes which are exposed for our use like the UserLocalServiceUtil, OrganizationLocalServiceUtil, OrganizationServiceUtil etc.
Hope this gives a clue to finding out Liferay implementations.

Resources