Foren
upload csv files to document and media during a scheduler
Alex Man, geändert vor 7 Jahren.
upload csv files to document and media during a scheduler
Junior Member Beiträge: 70 Beitrittsdatum: 08.02.16 Neueste Beiträge
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
can anyone please help me on this
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
Nidhish Krishnan, geändert vor 7 Jahren.
RE: upload csv files to document and media during a scheduler
New Member Beiträge: 2 Beitrittsdatum: 02.01.15 Neueste Beiträge
Try using ServiceContextThreadLocal for getting ServiceContext in your service impl like as shown below
ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
Miroslav Ligas, geändert vor 7 Jahren.
RE: upload csv files to document and media during a scheduler
New Member Beiträge: 17 Beitrittsdatum: 23.02.12 Neueste Beiträge
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.
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.
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.
Alex Man, geändert vor 7 Jahren.
RE: upload csv files to document and media during a scheduler
Junior Member Beiträge: 70 Beitrittsdatum: 08.02.16 Neueste BeiträgeMiroslav 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
David H Nebinger, geändert vor 7 Jahren.
RE: upload csv files to document and media during a scheduler
Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
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.
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.
Alex Man, geändert vor 7 Jahren.
RE: upload csv files to document and media during a scheduler
Junior Member Beiträge: 70 Beitrittsdatum: 08.02.16 Neueste BeiträgeDavid 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