Skip to content

Commit

Permalink
[ALS-5827] Enable search by CA id
Browse files Browse the repository at this point in the history
- If a uuid does not match a query, instead search for common area UUID
- If we have a collision, I'm buying a lottery ticket
  • Loading branch information
Luke Sikina authored and Luke-Sikina committed Feb 9, 2024
1 parent b67777d commit e710221
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,25 @@
import edu.harvard.dbmi.avillach.data.entity.Query;

import javax.enterprise.context.ApplicationScoped;
import javax.persistence.PersistenceException;
import javax.transaction.Transactional;
import java.util.UUID;

@Transactional
@ApplicationScoped
public class QueryRepository extends BaseRepository<Query, UUID>{
public class QueryRepository extends BaseRepository<Query, UUID> {

protected QueryRepository() {super(Query.class);}
protected QueryRepository() {
super(Query.class);
}

public Query getQueryUUIDFromCommonAreaUUID(UUID caID) {
String caIDRegex = "%commonAreaUUID\":\"" + caID + "\"%";
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public Response querySync(QueryRequest queryRequest, HttpHeaders headers) {
*/
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());
}
Expand Down

0 comments on commit e710221

Please sign in to comment.