掲示板

upload csv files to document and media during a scheduler

7年前 に Alex Man によって更新されました。

upload csv files to document and media during a scheduler

Junior Member 投稿: 70 参加年月日: 16/02/08 最新の投稿
I have a cron job scheduler which run every 2 hours. During the scheduling i need to create csv files based on some incoming values, the csv files created are to be uploaded into the document and media. Here the challenge which I am facing is that for the method addFileEntry it requires ServiceContext object to be passed as a parameter.

But in the above scenario how can I get the ServiceContext object in service builder.

My Scenario seems a valid one I think

my code is as given below

bytes = getCSVOutputStream(headers, details).toByteArray();
ServiceContext serviceContext = new ServiceContext();  
String title = "Csv_"+new Date().getTime()+".csv";
String mimeType = "text/csv";
DLAppServiceUtil.addFileEntry(repositoryId, folderId, title, mimeType, title, title, StringPool.BLANK, bytes, serviceContext);


can anyone please help me on this
7年前 に Nidhish Krishnan によって更新されました。

RE: upload csv files to document and media during a scheduler

New Member 投稿: 2 参加年月日: 15/01/02 最新の投稿
Try using ServiceContextThreadLocal for getting ServiceContext in your service impl like as shown below

ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
thumbnail
7年前 に Miroslav Ligas によって更新されました。

RE: upload csv files to document and media during a scheduler

New Member 投稿: 17 参加年月日: 12/02/23 最新の投稿
Hi
Nidhish suggestion is a possibility but if you don't like the object returned you can create a new service context manually and configure it as you require. usually it sufficient to create the object and it's good to set the basic permissions.


ServiceContext serviceContext = new ServiceContext();
        serviceContext.setAddGroupPermissions(true);
        serviceContext.setAddGuestPermissions(false);


Especially in the scheduled task you might not get anything from the thread local as there have not been an user interaction in the thread.
7年前 に Alex Man によって更新されました。

RE: upload csv files to document and media during a scheduler

Junior Member 投稿: 70 参加年月日: 16/02/08 最新の投稿
Miroslav Ligas:
Hi
Nidhish suggestion is a possibility but if you don't like the object returned you can create a new service context manually and configure it as you require. usually it sufficient to create the object and it's good to set the basic permissions.


ServiceContext serviceContext = new ServiceContext();
        serviceContext.setAddGroupPermissions(true);
        serviceContext.setAddGuestPermissions(false);


Especially in the scheduled task you might not get anything from the thread local as there have not been an user interaction in the thread.


When when I tried with your code I got

PermissionChecker not initialized PortalException
thumbnail
7年前 に David H Nebinger によって更新されました。

RE: upload csv files to document and media during a scheduler

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
You may have to take things a step farther and initialize more stuff including the principal thread local, etc.

When I need to do this kind of thing I'll look up an administrator user and set things up as that user.

I don't like to "hard code" for a specific admin user unless, of course, I have created a specific admin user for this task.
7年前 に Alex Man によって更新されました。

RE: upload csv files to document and media during a scheduler

Junior Member 投稿: 70 参加年月日: 16/02/08 最新の投稿
David H Nebinger:
You may have to take things a step farther and initialize more stuff including the principal thread local, etc.

When I need to do this kind of thing I'll look up an administrator user and set things up as that user.

I don't like to "hard code" for a specific admin user unless, of course, I have created a specific admin user for this task.


Did'nt get much...it would be greatful if you can you please explain with an example