package io.digdag.core.session;

import java.util.List;
import java.time.Instant;
import com.google.common.base.Optional;
import io.digdag.core.repository.ResourceConflictException;
import io.digdag.core.repository.ResourceNotFoundException;

public interface SessionStore
        extends SessionTransaction
{
    List<StoredSessionWithLastAttempt> getSessions(int pageSize, Optional<Long> lastId);

    StoredSessionWithLastAttempt getSessionById(long sessionId)
        throws ResourceNotFoundException;

    List<StoredSessionWithLastAttempt> getSessionsOfProject(int projectId, int pageSize, Optional<Long> lastId);

    List<StoredSessionWithLastAttempt> getSessionsOfWorkflowByName(int projectId, String workflowName, int pageSize, Optional<Long> lastId);

    List<StoredSessionAttemptWithSession> getAttempts(boolean withRetriedAttempts, int pageSize, Optional<Long> lastId);

    List<StoredSessionAttemptWithSession> getAttemptsOfProject(boolean withRetriedAttempts, int projectId, int pageSize, Optional<Long> lastId);

    List<StoredSessionAttemptWithSession> getAttemptsOfWorkflow(boolean withRetriedAttempts, int projectId, String workflowName, int pageSize, Optional<Long> lastId);

    List<StoredSessionAttemptWithSession> getActiveAttemptsOfWorkflow(int projectId, String workflowName, int pageSize, Optional<Long> lastId);

    List<StoredSessionAttempt> getAttemptsOfSession(long sessionId, int pageSize, Optional<Long> lastId);

    StoredSessionAttemptWithSession getAttemptById(long attemptId)
        throws ResourceNotFoundException;

    StoredSessionAttemptWithSession getLastAttemptByName(int projectId, String workflowName, Instant instant)
        throws ResourceNotFoundException;

    StoredSessionAttemptWithSession getAttemptByName(int projectId, String workflowName, Instant instant, String retryAttemptName)
        throws ResourceNotFoundException;

    List<StoredSessionAttemptWithSession> getOtherAttempts(long attemptId)
        throws ResourceNotFoundException;

    List<ArchivedTask> getTasksOfAttempt(long attemptId);

    interface SessionTransactionAction <T>
    {
        T call(SessionTransaction transaction)
            throws Exception;
    }

    <T> T sessionTransaction(SessionTransactionAction<T> func)
            throws Exception;
}

@@ -160,16 +160,16 @@
 urce
-Conflict
+NotFound
 Exce
@@ -196,49 +196,31 @@
 dag.
-core.repository.ResourceNotFoundException
+spi.ac.AccessController
 ;%0A%0Ap
@@ -363,32 +363,70 @@
 nal%3CLong%3E lastId
+, AccessController.ListFilter acFilter
 );%0A%0A    StoredSe
@@ -622,32 +622,70 @@
 nal%3CLong%3E lastId
+, AccessController.ListFilter acFilter
 );%0A%0A    List%3CSto
@@ -802,32 +802,70 @@
 nal%3CLong%3E lastId
+, AccessController.ListFilter acFilter
 );%0A%0A    List%3CSto
@@ -962,32 +962,70 @@
 nal%3CLong%3E lastId
+, AccessController.ListFilter acFilter
 );%0A%0A    List%3CSto
@@ -1146,32 +1146,70 @@
 nal%3CLong%3E lastId
+, AccessController.ListFilter acFilter
 );%0A%0A    List%3CSto
@@ -1352,32 +1352,70 @@
 nal%3CLong%3E lastId
+, AccessController.ListFilter acFilter
 );%0A%0A    List%3CSto

Update digdag-core's SessionStore