掲示板

Liferay Service Builder+Document Library+Quartz Scheduler+Apache POI

thumbnail
7年前 に Mohammed Rawoof Shaik によって更新されました。

Liferay Service Builder+Document Library+Quartz Scheduler+Apache POI

Junior Member 投稿: 37 参加年月日: 16/09/25 最新の投稿
Hello LR Community,

Requirement:
I need advice and help on going about how to create a Liferay(LR) module that will create XLS files with information pulled from a DB, and store them to a folder location in Document Library(DL), during scheduled times throughout the week.

Solution:
I solutionized to use LR's Service Builder+DL+Quartz Scheduler+Apache POI. Code below.

Roadblock:
The receive() method requires a RenderRequest object so that the ThemeDisplay and ServiceContext object can be created, which will be used by the DLAppServiceUtil to create the file in DL. How do I go about creating a RenderRequest object?

Code:
@Override
public void receive(Message message) throws MessageListenerException {
_log.debug(">> receive()");

ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
fileUploadByApp("folder-1", themeDisplay, renderRequest);

_log.debug("<< receive()");
}

public void fileUploadByApp(String folderName, ThemeDisplay themeDisplay, RenderRequest renderRequest) {

try {
// Sample file
File file = new File("D:/liferay-portal-6.2-ce-ga6/temp/sample_" + getDateTimeBasedFilename() + ".txt");
Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
writer.write("Something");
writer.close();

long repositoryId = themeDisplay.getScopeGroupId();
String mimeType = MimeTypesUtil.getContentType(file);
String title = file.getName();
String description = "This file is added via programatically";
String changeLog = "hi";
Long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;

Folder folder = DLAppServiceUtil.getFolder(themeDisplay.getScopeGroupId(), parentFolderId, folderName);
ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(),
renderRequest);
InputStream is = new FileInputStream(file);
DLAppServiceUtil.addFileEntry(repositoryId, folder.getFolderId(), file.getName(), mimeType, title,
description, changeLog, is, file.length(), serviceContext);

} catch (Exception e) {
System.out.println("Exception");
e.printStackTrace();
}
}

Project Repo, click here
thumbnail
7年前 に David H Nebinger によって更新されました。

RE: Liferay Service Builder+Document Library+Quartz Scheduler+Apache POI

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
Theme display has no context as a scheduled task, there is no theme, group, page, etc to take advantage of.

A service context can be created at any time. As a scheduled task you'll have to figure out an appropriate user to use. Often times it's easiest to find an admin user as it gets you by any permissions issues.

You don't have to go through some sort of "file upload", there's no user uploading anything. There are other DL apis that you can use to store a file programmatically in the doc lib.
thumbnail
7年前 に Mohammed Rawoof Shaik によって更新されました。

RE: Liferay Service Builder+Document Library+Quartz Scheduler+Apache POI (回答)

Junior Member 投稿: 37 参加年月日: 16/09/25 最新の投稿
Thanks David for the advice. I looked into the DL API and have posted the solution below,
Solution here