kavin
I'm new here

Trigger the schedule Entry from Java Program

Jump to solution

Hello All!

I need to excute the First Spirit Schedule entry from java program.

Is it possible to trigger the schedule entry from java program?

Thank you!

1 Solution

Accepted Solutions
der_sk
I'm new here

Yes, it is possible - but only, if you have ACCESS_API licensed. You can check this in the server-monitoring.

Here a simple (unpretty) code-example:

import java.io.IOException;

import java.util.List;

import de.espirit.firstspirit.access.AdminService;

import de.espirit.firstspirit.access.Connection;

import de.espirit.firstspirit.access.ConnectionManager;

import de.espirit.firstspirit.access.project.Project;

import de.espirit.firstspirit.access.schedule.ScheduleEntry;

import de.espirit.firstspirit.access.schedule.ScheduleEntryControl;

import de.espirit.firstspirit.access.schedule.ScheduleEntryRunningException;

import de.espirit.firstspirit.access.schedule.ScheduleStorage;

import de.espirit.firstspirit.common.MaximumNumberOfSessionsExceededException;

import de.espirit.firstspirit.server.authentication.AuthenticationException;

public class StartTaskOnFSServer {

       private static String PROJECTADMIN_PASSWORD = "Admin";

       private static String TASKNAME = "MyTaskName";

       private static String SERVER_HOST = "localhost";

       private static int SERVER_PORT = 4288;

       private static String PROJECTADMIN_USER = "Admin";

       private static long PROJECT_ID = 6483L;

       private static int SERVER_PROTOCOL = ConnectionManager.SOCKET_MODE; // or ConnectionManager.HTTP_MODE

       public static void main(String[] args) {

Connection connection = ConnectionManager.getConnection(StartTaskOnFSServer.SERVER_HOST,

StartTaskOnFSServer.SERVER_PORT, StartTaskOnFSServer.SERVER_PROTOCOL,

StartTaskOnFSServer.PROJECTADMIN_USER, StartTaskOnFSServer.PROJECTADMIN_PASSWORD);

try {

connection.connect();

Project project = connection.getProjectById(StartTaskOnFSServer.PROJECT_ID);

ScheduleEntry entry = getScheduleEntryByName(connection, project, StartTaskOnFSServer.TASKNAME);

if (entry != null) {

ScheduleEntryControl control = entry.execute();

}

} catch (MaximumNumberOfSessionsExceededException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} catch (AuthenticationException e) {

e.printStackTrace();

} catch (ScheduleEntryRunningException e) {

e.printStackTrace();

} finally {

try {

connection.disconnect();

} catch (Exception e) {

}

try {

connection.close();

} catch (Exception e) {

}

}

       }

       private static ScheduleEntry getScheduleEntryByName(Connection connection, Project project, String scheduleEntryName) {

AdminService adminService = connection.getService(AdminService.class);

ScheduleStorage scheduleStorage = adminService.getScheduleStorage();

List<ScheduleEntry> scheduleEntries = scheduleStorage.getScheduleEntries(project);

for (ScheduleEntry scheduleEntry : scheduleEntries) {

if (scheduleEntryName.equals(scheduleEntry.getName())) {

return scheduleEntry;

}

}

return null;

       }

}

View solution in original post

3 Replies
der_sk
I'm new here

Yes, it is possible - but only, if you have ACCESS_API licensed. You can check this in the server-monitoring.

Here a simple (unpretty) code-example:

import java.io.IOException;

import java.util.List;

import de.espirit.firstspirit.access.AdminService;

import de.espirit.firstspirit.access.Connection;

import de.espirit.firstspirit.access.ConnectionManager;

import de.espirit.firstspirit.access.project.Project;

import de.espirit.firstspirit.access.schedule.ScheduleEntry;

import de.espirit.firstspirit.access.schedule.ScheduleEntryControl;

import de.espirit.firstspirit.access.schedule.ScheduleEntryRunningException;

import de.espirit.firstspirit.access.schedule.ScheduleStorage;

import de.espirit.firstspirit.common.MaximumNumberOfSessionsExceededException;

import de.espirit.firstspirit.server.authentication.AuthenticationException;

public class StartTaskOnFSServer {

       private static String PROJECTADMIN_PASSWORD = "Admin";

       private static String TASKNAME = "MyTaskName";

       private static String SERVER_HOST = "localhost";

       private static int SERVER_PORT = 4288;

       private static String PROJECTADMIN_USER = "Admin";

       private static long PROJECT_ID = 6483L;

       private static int SERVER_PROTOCOL = ConnectionManager.SOCKET_MODE; // or ConnectionManager.HTTP_MODE

       public static void main(String[] args) {

Connection connection = ConnectionManager.getConnection(StartTaskOnFSServer.SERVER_HOST,

StartTaskOnFSServer.SERVER_PORT, StartTaskOnFSServer.SERVER_PROTOCOL,

StartTaskOnFSServer.PROJECTADMIN_USER, StartTaskOnFSServer.PROJECTADMIN_PASSWORD);

try {

connection.connect();

Project project = connection.getProjectById(StartTaskOnFSServer.PROJECT_ID);

ScheduleEntry entry = getScheduleEntryByName(connection, project, StartTaskOnFSServer.TASKNAME);

if (entry != null) {

ScheduleEntryControl control = entry.execute();

}

} catch (MaximumNumberOfSessionsExceededException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} catch (AuthenticationException e) {

e.printStackTrace();

} catch (ScheduleEntryRunningException e) {

e.printStackTrace();

} finally {

try {

connection.disconnect();

} catch (Exception e) {

}

try {

connection.close();

} catch (Exception e) {

}

}

       }

       private static ScheduleEntry getScheduleEntryByName(Connection connection, Project project, String scheduleEntryName) {

AdminService adminService = connection.getService(AdminService.class);

ScheduleStorage scheduleStorage = adminService.getScheduleStorage();

List<ScheduleEntry> scheduleEntries = scheduleStorage.getScheduleEntries(project);

for (ScheduleEntry scheduleEntry : scheduleEntries) {

if (scheduleEntryName.equals(scheduleEntry.getName())) {

return scheduleEntry;

}

}

return null;

       }

}

Thank you Sascha Korver.

Before executing the schedule entry i have to set the start nodes in genration task.

i tried the below code to get the Generation task.

But i am not able to find any method to set the startnods.

can you help me?

            List<ScheduleTask> tasks=scheduleEntry.getTasks();

               for(ScheduleTask task:tasks)

               {

                   if(task instanceof GenerateTask)

                   {

                       GenerateTask generateTask=(GenerateTask)task;

                   }

               }


0 Kudos

final List<IDProvider> startNodes = generateTask.getStartNodes();

startNodes.clear();

startNodes.add(someIdProvider); //Only Media- or SiteStore