deleting web content programmatically in liferay 6.0 - liferay

I am new to liferay. I am developing delete scheduler, which has to delete documents programatically based on some condition. using DLfileLocalServiceUtil.deleteFileEntry(id) I can delete it, but it is deleting only entry in DlfileEntry table not the actual file stored in file system in server in data folder.

DLfileLocalServiceUtil is used for managing Documents. You need to use 'JournalArticle*Util' APIs to deal with Web Contents. There are multiple Util classes for different purpose. You'll perhaps need JournalArticleLocalServiceUtil.deleteJournalArticle() methods for deleting the web contents.

Related

Best design approach for storing documents

We have a sharepoint website and as part of functional process across the website where there are lot of documents been uploaded. Currently they are been stored into database which results in very bulky table in terms of size. My initial approach was to utilize sharepoint to store the documents into file library. Does anybody think database is the wiser options and why or any other approach which is performant and better to store confidential files?
Using a database for storing documents is not a recommended approach, not only it will have large size but will be hard when it comes to maintenance and performance.
If you have a SharePoint server, why not go with a library or multiple libraries to store documents. You will get the below advantages when using SharePoint.
1.Permission management : you can set up access to documents and choose who access what.
2.Search : if there is a search service running you can search through your libraries.
3.OWA : office web apps can be used to open documents on the browser.
4.Audits : You can enable audit logs to see who does what.
Remember, SharePoint is a CMS and there are other options like MMS etc, but it stores the documents in a database too, its designed well so you dont have to worry much about it. If you go with your custom solution you will have to do a lot of custom development and testing.
I never recommend saving files in the database. The easiest approach is to store them on the server in a directory and only save the file names in the database. This makes it easy to show them via a URL in a browser as well. Create a table with a column for the OriginalFileName and one for the ActualFileName. When i save a file to the server after its uploaded i usually change the name so you never have complications with duplicate file names. I use a GUID as the actual file name when its saved and save the original file name in the database along with the actual so you can get both back.

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.

Where does Liferay save its data?

Let's say I'm adding data to different portlets inside of the Liferay Portal. Where is all these data saved to?
Most of the out of the box portlets that Liferay ships with like Blogs, Forums, Wiki, Web content gets stored in Liferay database. You can see the tables and the actual data properly if you have a production ready database configured with Liferay like MySQL or Oracle.
Liferay by default ships with Hypersonic database for quick demo purpose. It save all the information in a file. All the hypersonic related files are saved in "data\hsql" folder inside wherever you have extracted Liferay. You can view the tables using DbVisualizer if you want to see hypersonic db data.
You can also create your custom portlets. Where the data of these has to be stored is completely upto you. You can save the data in the Liferay's database if you want but that is not mandatory. It's upto you where you want to persist data for the custom portlets

import Web Content into Liferay Database

I want to keep web content in liferay database. Currently the JPGs are in another filesystem on another server, which I want to move to liferay database. Is there a way to bulk import these JPGs/web content to liferay db? One option I'm thinking is having a daily scheduled job to import new files from the filesystem. Curious to hear if anyone else has done it and how?
I found that there is a thing called as Database Hook. But as far as I understand, this lets you save to db only those files which you upload through the Image Gallery in Liferay. Which is a bit different from having to import files from another filesystem programmatically.
When you go to Liferay's Document Library (or image gallery in 6.0) you'll find a link "Access from Desktop" in every folder. This can be used to connect via WebDAV, so you can connect to Liferay's Document Library as if it was a Network share. Then just copy through batch files or explorer (drag&drop) and they'll end up in the doclib. Works in both directions.
For Liferay 6.1 you can also consider Liferay Sync, a Dropbox-like client that just synchronizes the document library with a folder on a local (remote from the server) system.
And the most complex variant (just to be complete here) is to use Liferay's API to insert documents programmatically. The advandage here is that you can also use it to tag and categorize the content during your import process, but it definitely is more work than just dragging and dropping files.

SharePoint - Obtaining all files from a web

I have a requirement wherein I have to obtain all the files of a web recursively (i.e. traversing through the folders and sub folders) and display them for the user through SP Object Model.
This has to be security trimmed, in the sense, if the user doesn't have sufficient privileges to view or open the file, then that file shouldn't be taken into account. Is it possible to obtain all the files without looping through each and every document library, folders and sub folders?
Also, I don't want the default document libraries like web part gallery, master page gallery,etc to be listed out. Any insights on how to achieve this?
The Content Query Web Part can get you most of the way there. Out-of-the-box you could set this up to show all files (based on a content type or content type category) from a site collection. You could even filter to remove system files although that might be a little tricky to get the filters right.
If that doesn't get you far enough, then you could write a web part that extends the Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart class. You could override the Filters (by setting the FilterField1, FilterType1, FilterOperator1, FilterValue1, etc).
The security trimming should happen for you by the default behavior of the ContentQueryWebPart. The Web Part and Master Page galleries will get filtered out based on your content type settings so you shouldn't have to worry about those.

Resources