diff --git a/pic-sure-api-data/src/main/java/edu/harvard/dbmi/avillach/data/repository/QueryRepository.java b/pic-sure-api-data/src/main/java/edu/harvard/dbmi/avillach/data/repository/QueryRepository.java index 5eab08bf..aaf2340f 100644 --- a/pic-sure-api-data/src/main/java/edu/harvard/dbmi/avillach/data/repository/QueryRepository.java +++ b/pic-sure-api-data/src/main/java/edu/harvard/dbmi/avillach/data/repository/QueryRepository.java @@ -3,7 +3,7 @@ import edu.harvard.dbmi.avillach.data.entity.Query; import javax.enterprise.context.ApplicationScoped; -import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.PersistenceException; import javax.transaction.Transactional; import java.util.UUID; @@ -15,11 +15,13 @@ protected QueryRepository() { super(Query.class); } - public UUID getQueryUUIDFromCommonAreaUUID(UUID caID) { + public Query getQueryUUIDFromCommonAreaUUID(UUID caID) { String caIDRegex = "%" + caID + "%"; - String query = "SELECT uuid FROM query WHERE CONVERT(metadata using utf8) LIKE ?;"; - // em().getCriteriaBuilder().like(em()) - em().createQuery(query).setParameter(0, caIDRegex).getSingleResult(); - return null; + String query = "SELECT * FROM query WHERE CONVERT(metadata USING utf8) LIKE ?"; + try { + return (Query) em().createNativeQuery(query, Query.class).setParameter(1, caIDRegex).getSingleResult(); + } catch (PersistenceException ignored) { + return null; + } } } diff --git a/pic-sure-api-war/src/main/java/edu/harvard/dbmi/avillach/service/PicsureQueryService.java b/pic-sure-api-war/src/main/java/edu/harvard/dbmi/avillach/service/PicsureQueryService.java index 767dae5f..136e547d 100644 --- a/pic-sure-api-war/src/main/java/edu/harvard/dbmi/avillach/service/PicsureQueryService.java +++ b/pic-sure-api-war/src/main/java/edu/harvard/dbmi/avillach/service/PicsureQueryService.java @@ -246,6 +246,7 @@ public QueryStatus queryCommonAreaMetaData(UUID commonAreaQueryId, HttpHeaders h */ public QueryStatus queryMetadata(UUID queryId, HttpHeaders headers) { Query query = queryRepo.getById(queryId); + query = query == null ? queryRepo.getQueryUUIDFromCommonAreaUUID(queryId) : query; if (query == null) { throw new ProtocolException(ProtocolException.QUERY_NOT_FOUND + queryId.toString()); }