diff --git a/src/main/java/com/gw/database/EnvironmentRepository.java b/src/main/java/com/gw/database/EnvironmentRepository.java index f57401392..8ff1e34ae 100644 --- a/src/main/java/com/gw/database/EnvironmentRepository.java +++ b/src/main/java/com/gw/database/EnvironmentRepository.java @@ -7,22 +7,41 @@ import com.gw.jpa.Environment; -public interface EnvironmentRepository extends CrudRepository{ - -// new StringBuffer("select * from environment where host = '").append(hostid) -// .append("' and bin = '").append(bin).append("' and pyenv = '") -// .append(env).append("' and basedir = '").append(basedir).append("';"); - @Query(value = "select * from environment where hostid = ?1 and bin = ?2 and pyenv = ?3 and basedir = ?4 ", - nativeQuery = true) - Collection findEnvByID_BIN_ENV_BaseDir(String hostid, String bin, String pyenv, String basedir); - - @Query(value = "select * from environment where hostid = ?1 and bin = ?2", - nativeQuery = true) - Collection findEnvByID_BIN(String hostid, String bin); - - - @Query(value = "select * from environment where hostid = ?1 ", - nativeQuery = true) - Collection findEnvByHost(String hostid); - +/** + * The EnvironmentRepository interface provides methods for querying environment configurations from a database. + * It extends the CrudRepository interface to handle database operations for the Environment entity. + */ +public interface EnvironmentRepository extends CrudRepository { + + /** + * Find environment configurations based on the provided host ID, binary path, Python environment, and base directory. + * + * @param hostid The ID of the host. + * @param bin The binary path. + * @param pyenv The Python environment. + * @param basedir The base directory. + * @return A collection of environment configurations matching the specified criteria. + */ + @Query(value = "select * from environment where hostid = ?1 and bin = ?2 and pyenv = ?3 and basedir = ?4", nativeQuery = true) + Collection findEnvByID_BIN_ENV_BaseDir(String hostid, String bin, String pyenv, String basedir); + + /** + * Find environment configurations based on the provided host ID and binary path. + * + * @param hostid The ID of the host. + * @param bin The binary path. + * @return A collection of environment configurations matching the specified host and binary path. + */ + @Query(value = "select * from environment where hostid = ?1 and bin = ?2", nativeQuery = true) + Collection findEnvByID_BIN(String hostid, String bin); + + /** + * Find environment configurations based on the provided host ID. + * + * @param hostid The ID of the host. + * @return A collection of environment configurations associated with the specified host. + */ + @Query(value = "select * from environment where hostid = ?1", nativeQuery = true) + Collection findEnvByHost(String hostid); } + diff --git a/src/main/java/com/gw/database/HistoryRepository.java b/src/main/java/com/gw/database/HistoryRepository.java index 41e0087e2..69e53701a 100644 --- a/src/main/java/com/gw/database/HistoryRepository.java +++ b/src/main/java/com/gw/database/HistoryRepository.java @@ -8,68 +8,129 @@ import com.gw.jpa.History; -public interface HistoryRepository extends JpaRepository{ - - @Query(value="select * from history where host_id = ?1 ORDER BY history_begin_time DESC limit ?2", - nativeQuery = true) - Collection findRecentHistory(String hostid, int limit); - - @Query(value="select * from history where indicator='Running' ORDER BY history_begin_time DESC;", - nativeQuery = true) - List findAllRunningResource(); - - @Query(value="select * from history, workflow where history.history_process = workflow.id and history.indicator = 'Running' ORDER BY history_begin_time DESC;", - nativeQuery = true) - List findRunningWorkflow(); - - @Query(value="select * from history, workflow where history.history_process = workflow.id and history.indicator = 'Failed' ORDER BY history_begin_time DESC;", - nativeQuery = true) - List findFailedWorkflow(); - - @Query(value="select * from history, workflow where history.history_process = workflow.id and history.indicator = 'Done' ORDER BY history_begin_time DESC;", - nativeQuery = true) - List findSuccessWorkflow(); - - @Query(value="select * from history, gwprocess where history.history_process = gwprocess.id and history.indicator = 'Running' ORDER BY history_begin_time DESC;", - nativeQuery = true) - List findRunningProcess(); - - @Query(value="select * from history, gwprocess where history.history_process = gwprocess.id and history.indicator = 'Failed' ORDER BY history_begin_time DESC;", - nativeQuery = true) - List findFailedProcess(); - - @Query(value="select * from history, gwprocess where history.history_process = gwprocess.id and history.indicator = 'Done' ORDER BY history_begin_time DESC;", - nativeQuery = true) - List findSuccessProcess(); - - @Query(value="select * from history where history.history_process = ?1 ORDER BY history_begin_time DESC;", - nativeQuery = true) - List findByProcessId(String pid); - - @Query(value="select * from history where history.history_process = ?1 and history.indicator != 'Skipped' ORDER BY history_begin_time DESC;", - nativeQuery = true) - List findByProcessIdIgnoreUnknown(String pid); - - @Query(value="select * from history where history.history_process = ?1 ORDER BY history_begin_time DESC;", - nativeQuery = true) - List findByWorkflowId(String wid); - - - @Query(value="select * from history, workflow where workflow.id = history.history_process ORDER BY history_begin_time DESC limit ?1", - nativeQuery = true) - List findRecentWorkflow(int limit); - - - @Query(value="select * from history, gwprocess where gwprocess.id = history.history_process ORDER BY history_begin_time DESC limit ?1", - nativeQuery = true) - List findRecentProcess(int limit); - - @Query(value="select * from history, gwprocess where history.history_id = ?1 and history.history_process=gwprocess.id", - nativeQuery = true) - List findOneHistoryofProcess(String history_id); - - - - - +/** + * The HistoryRepository interface provides methods for querying historical execution data (history) from a database. + * It extends the JpaRepository interface to handle database operations. + */ +public interface HistoryRepository extends JpaRepository { + + /** + * Find recent history records for a specific host, limited by the specified count. + * + * @param hostid The ID of the host. + * @param limit The maximum number of history records to retrieve. + * @return A collection of recent history records for the host. + */ + @Query(value = "select * from history where host_id = ?1 ORDER BY history_begin_time DESC limit ?2", nativeQuery = true) + Collection findRecentHistory(String hostid, int limit); + + /** + * Find all running history records. + * + * @return A list of all running history records. + */ + @Query(value = "select * from history where indicator='Running' ORDER BY history_begin_time DESC;", nativeQuery = true) + List findAllRunningResource(); + + /** + * Find all running workflows. + * + * @return A list of all running workflow records with additional information. + */ + @Query(value = "select * from history, workflow where history.history_process = workflow.id and history.indicator = 'Running' ORDER BY history_begin_time DESC;", nativeQuery = true) + List findRunningWorkflow(); + + /** + * Find all failed workflows. + * + * @return A list of all failed workflow records with additional information. + */ + @Query(value = "select * from history, workflow where history.history_process = workflow.id and history.indicator = 'Failed' ORDER BY history_begin_time DESC;", nativeQuery = true) + List findFailedWorkflow(); + + /** + * Find all successfully completed workflows. + * + * @return A list of all successful workflow records with additional information. + */ + @Query(value = "select * from history, workflow where history.history_process = workflow.id and history.indicator = 'Done' ORDER BY history_begin_time DESC;", nativeQuery = true) + List findSuccessWorkflow(); + + /** + * Find all running processes. + * + * @return A list of all running process records with additional information. + */ + @Query(value = "select * from history, gwprocess where history.history_process = gwprocess.id and history.indicator = 'Running' ORDER BY history_begin_time DESC;", nativeQuery = true) + List findRunningProcess(); + + /** + * Find all failed processes. + * + * @return A list of all failed process records with additional information. + */ + @Query(value = "select * from history, gwprocess where history.history_process = gwprocess.id and history.indicator = 'Failed' ORDER BY history_begin_time DESC;", nativeQuery = true) + List findFailedProcess(); + + /** + * Find all successfully completed processes. + * + * @return A list of all successful process records with additional information. + */ + @Query(value = "select * from history, gwprocess where history.history_process = gwprocess.id and history.indicator = 'Done' ORDER BY history_begin_time DESC;", nativeQuery = true) + List findSuccessProcess(); + + /** + * Find history records by process ID. + * + * @param pid The ID of the process. + * @return A list of history records associated with the specified process ID. + */ + @Query(value = "select * from history where history.history_process = ?1 ORDER BY history_begin_time DESC;", nativeQuery = true) + List findByProcessId(String pid); + + /** + * Find history records by process ID, excluding 'Skipped' indicator. + * + * @param pid The ID of the process. + * @return A list of history records associated with the specified process ID, excluding 'Skipped' records. + */ + @Query(value = "select * from history where history.history_process = ?1 and history.indicator != 'Skipped' ORDER BY history_begin_time DESC;", nativeQuery = true) + List findByProcessIdIgnoreUnknown(String pid); + + /** + * Find history records by workflow ID. + * + * @param wid The ID of the workflow. + * @return A list of history records associated with the specified workflow ID. + */ + @Query(value = "select * from history where history.history_process = ?1 ORDER BY history_begin_time DESC;", nativeQuery = true) + List findByWorkflowId(String wid); + + /** + * Find recent workflow records, limited by the specified count. + * + * @param limit The maximum number of recent workflow records to retrieve. + * @return A list of recent workflow records with additional information. + */ + @Query(value = "select * from history, workflow where workflow.id = history.history_process ORDER BY history_begin_time DESC limit ?1", nativeQuery = true) + List findRecentWorkflow(int limit); + + /** + * Find recent process records, limited by the specified count. + * + * @param limit The maximum number of recent process records to retrieve. + * @return A list of recent process records with additional information. + */ + @Query(value = "select * from history, gwprocess where gwprocess.id = history.history_process ORDER BY history_begin_time DESC limit ?1", nativeQuery = true) + List findRecentProcess(int limit); + + /** + * Find a history record associated with a specific history ID. + * + * @param history_id The ID of the history record. + * @return A list containing a history record and additional information about the associated process. + */ + @Query(value = "select * from history, gwprocess where history.history_id = ?1 and history.history_process=gwprocess.id", nativeQuery = true) + List findOneHistoryofProcess(String history_id); } diff --git a/src/main/java/com/gw/database/HostRepository.java b/src/main/java/com/gw/database/HostRepository.java index 1650b1f96..8442b15f0 100644 --- a/src/main/java/com/gw/database/HostRepository.java +++ b/src/main/java/com/gw/database/HostRepository.java @@ -9,46 +9,97 @@ import com.gw.jpa.Host; -public interface HostRepository extends CrudRepository{ - - @Query(value="select * from host where owner = ?1 ", - nativeQuery = true) - Collection findByOwner(String owner); - - @Query(value="select * from HOST where name like CONCAT('%',:keyword,'%')", - nativeQuery = true) - Collection findHostsByNameAlike(@Param("keyword") String keyword); - - @Query(value="select * from HOST where type = 'ssh'", - nativeQuery = true) - Collection findSSHHosts(); - - @Query(value="select * from HOST where owner = ?1 ", - nativeQuery = true) - Collection findAllPublicAndPrivateByOwner(String owner); - - @Query(value="select * from HOST where owner = ?1 and confidential = 'TRUE'", - nativeQuery = true) - Collection findPrivateByOwner(String owner); - - @Query(value="select * from HOST where confidential = 'FALSE' ", - nativeQuery = true) - Collection findAllPublicHosts(); - - @Query(value="select * from HOST where type = 'jupyter'", - nativeQuery = true) - Collection findJupyterNotebookHosts(); - - @Query(value="select * from HOST where type = 'jupyterhub'", - nativeQuery = true) - Collection findJupyterHubHosts(); - - @Query(value="select * from HOST where type = 'jupyterlab'", - nativeQuery = true) - Collection findJupyterLabHosts(); - - @Query(value="select * from HOST where type = 'gee'", - nativeQuery = true) - Collection findGEEHosts(); +/** + * The HostRepository interface provides methods for querying host-related information from the database. + * It extends the CrudRepository interface to handle basic CRUD operations. + */ +public interface HostRepository extends CrudRepository { + /** + * Find hosts by owner. + * + * @param owner The owner's name. + * @return A collection of hosts owned by the specified owner. + */ + @Query(value = "select * from host where owner = ?1 ", nativeQuery = true) + Collection findByOwner(String owner); + // Collection findByOwner(String owner); + + /** + * Find hosts by name containing the specified keyword. + * + * @param keyword The keyword to search for in host names. + * @return A collection of hosts with names containing the keyword. + */ + @Query(value = "select * from HOST where name like CONCAT('%',:keyword,'%')", nativeQuery = true) + Collection findHostsByNameAlike(@Param("keyword") String keyword); + // Collection findByNameContaining(String keyword); + + /** + * Find SSH hosts. + * + * @return A collection of SSH hosts. + */ + @Query(value = "select * from HOST where type = 'ssh'", nativeQuery = true) + Collection findSSHHosts(); + + /** + * Find all public and private hosts of an owner. + * + * @param owner The owner's name. + * @return A collection of all public and private hosts owned by the specified owner. + */ + @Query(value = "select * from HOST where owner = ?1 ", nativeQuery = true) + Collection findAllPublicAndPrivateByOwner(String owner); + + /** + * Find private hosts of an owner. + * + * @param owner The owner's name. + * @return A collection of private hosts owned by the specified owner. + */ + @Query(value = "select * from HOST where owner = ?1 and confidential = 'TRUE'", nativeQuery = true) + Collection findPrivateByOwner(String owner); + // Collection findByOwnerAndConfidential(String owner, boolean confidential); + + /** + * Find all public hosts. + * + * @return A collection of all public hosts. + */ + @Query(value = "select * from HOST where confidential = 'FALSE'", nativeQuery = true) + Collection findAllPublicHosts(); + + /** + * Find hosts of type 'jupyter'. + * + * @return A collection of hosts of type 'jupyter'. + */ + @Query(value = "select * from HOST where type = 'jupyter'", nativeQuery = true) + Collection findJupyterNotebookHosts(); + + /** + * Find hosts of type 'jupyterhub'. + * + * @return A collection of hosts of type 'jupyterhub'. + */ + @Query(value = "select * from HOST where type = 'jupyterhub'", nativeQuery = true) + Collection findJupyterHubHosts(); + + /** + * Find hosts of type 'jupyterlab'. + * + * @return A collection of hosts of type 'jupyterlab'. + */ + @Query(value = "select * from HOST where type = 'jupyterlab'", nativeQuery = true) + Collection findJupyterLabHosts(); + + /** + * Find hosts of type 'gee'. + * + * @return A collection of hosts of type 'gee'. + */ + @Query(value = "select * from HOST where type = 'gee'", nativeQuery = true) + Collection findGEEHosts(); } + diff --git a/src/main/java/com/gw/database/ProcessRepository.java b/src/main/java/com/gw/database/ProcessRepository.java index 610bd0a6d..f1ac73b53 100644 --- a/src/main/java/com/gw/database/ProcessRepository.java +++ b/src/main/java/com/gw/database/ProcessRepository.java @@ -9,36 +9,68 @@ import com.gw.jpa.GWProcess; import com.gw.jpa.Host; -public interface ProcessRepository extends CrudRepository{ - - @Query(value = "select * from GWProcess where name like CONCAT('%',:keyword,'%')", - nativeQuery = true) - Collection findProcessesByNameAlike(@Param("keyword") String keyword); - - @Query(value="select * from gwprocess where lang = 'python'", - nativeQuery = true) - Collection findPythonProcess(); - - @Query(value="select * from gwprocess where owner = ?1 and confidential = 'TRUE'", - nativeQuery = true) - Collection findAllPrivateByOwner(String owner); - - @Query(value="select * from gwprocess where confidential = 'FALSE'", - nativeQuery = true) - Collection findAllPublic(); - - @Query(value="select * from gwprocess where lang = 'shell'", - nativeQuery = true) - Collection findShellProcess(); - - @Query(value="select * from gwprocess where lang = 'builtin'", - nativeQuery = true) - Collection findBuiltinProcess(); - - @Query(value="select * from gwprocess where lang = 'jupyter'", - nativeQuery = true) - Collection findNotebookProcess(); - - - +/** + * The ProcessRepository interface provides methods for querying process information from a database. + * It extends the CrudRepository interface to handle database operations for the GWProcess entity. + */ +public interface ProcessRepository extends CrudRepository { + + /** + * Find processes whose names are similar to the provided keyword. + * + * @param keyword The keyword to search for in process names. + * @return A collection of processes with names similar to the provided keyword. + */ + @Query(value = "select * from GWProcess where name like CONCAT('%',:keyword,'%')", nativeQuery = true) + Collection findProcessesByNameAlike(@Param("keyword") String keyword); + + /** + * Find processes written in the Python language. + * + * @return A collection of processes implemented in the Python language. + */ + @Query(value = "select * from gwprocess where lang = 'python'", nativeQuery = true) + Collection findPythonProcess(); + + /** + * Find processes owned by the specified user and marked as confidential. + * + * @param owner The owner's username. + * @return A collection of private processes owned by the specified user. + */ + @Query(value = "select * from gwprocess where owner = ?1 and confidential = 'TRUE'", nativeQuery = true) + Collection findAllPrivateByOwner(String owner); + + /** + * Find processes that are marked as public (not confidential). + * + * @return A collection of public processes. + */ + @Query(value = "select * from gwprocess where confidential = 'FALSE'", nativeQuery = true) + Collection findAllPublic(); + + /** + * Find processes written in the Shell language. + * + * @return A collection of processes implemented in the Shell language. + */ + @Query(value = "select * from gwprocess where lang = 'shell'", nativeQuery = true) + Collection findShellProcess(); + + /** + * Find processes written in a built-in language or system. + * + * @return A collection of processes implemented using a built-in language or system. + */ + @Query(value = "select * from gwprocess where lang = 'builtin'", nativeQuery = true) + Collection findBuiltinProcess(); + + /** + * Find processes implemented as Jupyter notebooks. + * + * @return A collection of processes represented as Jupyter notebooks. + */ + @Query(value = "select * from gwprocess where lang = 'jupyter'", nativeQuery = true) + Collection findNotebookProcess(); } + diff --git a/src/main/java/com/gw/database/WorkflowRepository.java b/src/main/java/com/gw/database/WorkflowRepository.java index 52e521659..0885760f5 100644 --- a/src/main/java/com/gw/database/WorkflowRepository.java +++ b/src/main/java/com/gw/database/WorkflowRepository.java @@ -9,17 +9,36 @@ import com.gw.jpa.GWProcess; import com.gw.jpa.Workflow; -public interface WorkflowRepository extends CrudRepository{ - - @Query(value="select * from workflow where name like CONCAT('%',:keyword,'%')", - nativeQuery=true) - Collection findProcessesByNameAlike(@Param("keyword") String keyword); - - @Query(value="select * from workflow where owner = ?1 and confidential = 'TRUE'", - nativeQuery=true) - Collection findAllPrivateByOwner(String owner); - - @Query(value="select * from workflow where confidential = 'FALSE'", - nativeQuery=true) - Collection findAllPublic(); +/** + * The WorkflowRepository interface provides methods for querying workflow information from a database. + * It extends the CrudRepository interface to handle database operations for the Workflow entity. + */ +public interface WorkflowRepository extends CrudRepository { + + /** + * Find workflows whose names are similar to the provided keyword. + * + * @param keyword The keyword to search for in workflow names. + * @return A collection of workflows with names similar to the provided keyword. + */ + @Query(value = "select * from workflow where name like CONCAT('%',:keyword,'%')", nativeQuery = true) + Collection findProcessesByNameAlike(@Param("keyword") String keyword); + + /** + * Find workflows owned by the specified user and marked as confidential. + * + * @param owner The owner's username. + * @return A collection of private workflows owned by the specified user. + */ + @Query(value = "select * from workflow where owner = ?1 and confidential = 'TRUE'", nativeQuery = true) + Collection findAllPrivateByOwner(String owner); + + /** + * Find workflows that are marked as public (not confidential). + * + * @return A collection of public workflows. + */ + @Query(value = "select * from workflow where confidential = 'FALSE'", nativeQuery = true) + Collection findAllPublic(); } +