Skip to main content

Trigger the schedule Entry from Java Program

Comments

1 comment

  • Zendesk API User
    Author: der_sk - 6/24/2015 11:28

    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;

           }

    }

    0

Please sign in to leave a comment.