-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unit tests, moving queries to an implementation class for JSONB d…
…e/serialization.
- Loading branch information
Showing
16 changed files
with
410 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.commonwl.view.util; | ||
|
||
import com.vladmihalcea.hibernate.type.json.JsonBinaryType; | ||
import org.hibernate.annotations.TypeDef; | ||
import org.hibernate.annotations.TypeDefs; | ||
|
||
import javax.persistence.MappedSuperclass; | ||
|
||
@TypeDefs({ | ||
@TypeDef(name = "json", typeClass = JsonBinaryType.class) | ||
}) | ||
@MappedSuperclass | ||
public class BaseEntity { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 7 additions & 20 deletions
27
src/main/java/org/commonwl/view/workflow/QueuedWorkflowRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,32 @@ | ||
package org.commonwl.view.workflow; | ||
|
||
import org.commonwl.view.git.GitDetails; | ||
import org.springframework.data.mongodb.repository.Query; | ||
import org.springframework.data.repository.PagingAndSortingRepository; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
/** | ||
* Stores workflows in the queue waiting for cwltool | ||
*/ | ||
public interface QueuedWorkflowRepository extends PagingAndSortingRepository<QueuedWorkflow, String> { | ||
|
||
/** | ||
* Finds a queued workflow based on where it was retrieved from | ||
* @param retrievedFrom Details of where the queued workflow is from | ||
* @return The queued workflow | ||
*/ | ||
@Query("{\"tempRepresentation.retrievedFrom\": ?0}") | ||
QueuedWorkflow findByRetrievedFrom(GitDetails retrievedFrom); | ||
|
||
/** | ||
* Deletes a queued workflow based on where it was retrieved from | ||
* @param retrievedFrom Details of where the queued workflow is from | ||
*/ | ||
void deleteByTempRepresentation_RetrievedFrom(GitDetails retrievedFrom); | ||
public interface QueuedWorkflowRepository extends JpaRepository<QueuedWorkflow, String>, QueuedWorkflowRepositoryCustom { | ||
|
||
/** | ||
* Deletes all queued workflows with date retrieved on older or equal to the Date argument passed. | ||
* | ||
* @param retrievedOn Date of when the queued workflow was retrieved | ||
* @return The number of queued workflows deleted | ||
*/ | ||
@Query(value = "delete from queued_workflow q where q.tempRepresentation->>retrieved_on <= ?1", nativeQuery = true) | ||
Long deleteByTempRepresentation_RetrievedOnLessThanEqual(Date retrievedOn); | ||
|
||
|
||
/** | ||
* Finds and returns all queued workflows with date retrieved on older or equal to the Date argument passed. | ||
* | ||
* @param retrievedOn Details of where the queued workflow is from | ||
* @return A list of queued workflows | ||
*/ | ||
@Query(value = "select q.* from queued_workflow q where q.tempRepresentation->>retrieved_on <= ?1", nativeQuery = true) | ||
List<QueuedWorkflow> findByTempRepresentation_RetrievedOnLessThanEqual(Date retrievedOn); | ||
|
||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/org/commonwl/view/workflow/QueuedWorkflowRepositoryCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.commonwl.view.workflow; | ||
|
||
import org.commonwl.view.git.GitDetails; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface QueuedWorkflowRepositoryCustom { | ||
/** | ||
* Finds a queued workflow based on where it was retrieved from. | ||
* | ||
* @param retrievedFrom Details of where the queued workflow is from | ||
* @return The queued workflow | ||
*/ | ||
QueuedWorkflow findByRetrievedFrom(@Param("retrievedFrom") GitDetails retrievedFrom); | ||
|
||
/** | ||
* Deletes a queued workflow based on where it was retrieved from. | ||
* | ||
* @param retrievedFrom Details of where the queued workflow is from | ||
*/ | ||
void deleteByTempRepresentation_RetrievedFrom(GitDetails retrievedFrom); | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/org/commonwl/view/workflow/QueuedWorkflowRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.commonwl.view.workflow; | ||
|
||
import com.vladmihalcea.hibernate.type.json.JsonBinaryType; | ||
import org.commonwl.view.git.GitDetails; | ||
import org.hibernate.query.Query; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
|
||
public class QueuedWorkflowRepositoryImpl implements QueuedWorkflowRepositoryCustom { | ||
|
||
// Tested this query directly, and it works! Problem is elsewhere! | ||
private static final String QUERY_FIND_BY_RETRIEVED_FROM = "SELECT q.* FROM queued_workflow q WHERE q.temp_representation -> 'retrievedFrom' = :retrievedFrom"; | ||
|
||
private static final String QUERY_DELETE_BY_RETRIEVED_FROM = "DELETE FROM queued_workflow q WHERE q.temp_representation -> 'retrievedFrom' = :retrievedFrom"; | ||
|
||
@PersistenceContext | ||
EntityManager entityManager; | ||
|
||
@Override | ||
public QueuedWorkflow findByRetrievedFrom(GitDetails retrievedFrom) { | ||
return (QueuedWorkflow) entityManager | ||
.createNativeQuery(QUERY_FIND_BY_RETRIEVED_FROM, QueuedWorkflow.class) | ||
.unwrap(Query.class) | ||
.setParameter("retrievedFrom", retrievedFrom, JsonBinaryType.INSTANCE) | ||
.getResultList() | ||
.stream() | ||
.findFirst() | ||
.orElse(null) | ||
; | ||
} | ||
|
||
@Override | ||
public void deleteByTempRepresentation_RetrievedFrom(GitDetails retrievedFrom) { | ||
entityManager | ||
.createNativeQuery(QUERY_DELETE_BY_RETRIEVED_FROM, QueuedWorkflow.class) | ||
.unwrap(Query.class) | ||
.setParameter("retrievedFrom", retrievedFrom, JsonBinaryType.INSTANCE) | ||
.executeUpdate() | ||
; | ||
} | ||
|
||
} |
Oops, something went wrong.