Skip to content

Commit

Permalink
change API implementation of getObservations to return observation id…
Browse files Browse the repository at this point in the history
…, first target name, and the observation type.
  • Loading branch information
DJWalker42 committed Oct 31, 2024
1 parent da8f10c commit fff099b
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.orph2020.pst.apiimpl.rest;

import jakarta.persistence.Query;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
import org.ivoa.dm.proposal.prop.*;
Expand Down Expand Up @@ -41,19 +42,25 @@ public List<ObjectIdentifier> getObservations(@PathParam("proposalCode") Long pr
@RestQuery ObsType type)
throws WebApplicationException
{
String select = "select o._id,t.sourceName ";
String select = "select o._id,cast(Type(o) as string),t.sourceName ";
String from = "from ObservingProposal p ";
String innerJoin = "inner join p.observations o inner join o.target t ";
String where = "where p._id=" + proposalCode + " ";
String orderBy = "order by t.sourceName";

String typeQuery = type != null ?
"and Type(o)=" + type.name() + " " : "";
"and Type(o) = :typeName" : "";
String srcLike = srcName != null ?
"and t.sourceName like '" + srcName + "' " : "";
"and t.sourceName like :sourceName" : "";

return getObjectIdentifiers(select + from + innerJoin + where +
typeQuery + srcLike + orderBy);
String qlString = select + from + innerJoin + where +
typeQuery + srcLike + orderBy;

Query query = em.createQuery(qlString);
if (type != null) query.setParameter("typeName", type.name());
if (srcName != null) query.setParameter("sourceName", srcName);

return getObjectIdentifiersAlt(query);
}

@GET
Expand Down

0 comments on commit fff099b

Please sign in to comment.