Skip to content

Commit

Permalink
Updated RoutingResources to utilize Legacy DB DAI retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
zack-rma committed Dec 10, 2024
1 parent ede5be4 commit 711cca0
Showing 1 changed file with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

package org.opendcs.odcsapi.res;

import java.sql.SQLException;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -37,12 +36,12 @@
import javax.ws.rs.core.Response;

import decodes.db.DatabaseException;
import decodes.db.DatabaseIO;
import decodes.db.RoutingSpec;
import decodes.db.RoutingSpecList;
import decodes.db.ScheduleEntry;
import decodes.polling.DacqEvent;
import decodes.sql.DbKey;
import decodes.sql.RoutingSpecListIO;
import decodes.tsdb.DbIoException;
import opendcs.dai.DacqEventDAI;
import opendcs.dai.ScheduleEntryDAI;
Expand All @@ -60,7 +59,6 @@ public class RoutingResources extends OpenDcsResource
{
@Context private HttpServletRequest request;
@Context private HttpHeaders httpHeaders;
private static final String NO_SCHEDULE_ENTRY_DAI = "No ScheduleEntryDAI available";

@GET
@Path("routingrefs")
Expand All @@ -70,13 +68,13 @@ public Response getRoutingRefs() throws DbException
{
try
{
RoutingSpecListIO rsl = new RoutingSpecListIO(null, null, null, null);
DatabaseIO dbio = getLegacyDatabase();
RoutingSpecList rsList = new RoutingSpecList();
rsl.read(rsList);
dbio.readRoutingSpecList(rsList);
return Response.status(HttpServletResponse.SC_OK)
.entity(map(rsList)).build();
}
catch(SQLException | DatabaseException e)
catch(DatabaseException e)
{
throw new DbException("Unable to retrieve routing reference list", e);
}
Expand Down Expand Up @@ -108,10 +106,10 @@ public Response getRouting(@QueryParam("routingid") Long routingId)

try
{
RoutingSpecListIO rsl = new RoutingSpecListIO(null, null, null, null);
DatabaseIO dbio = getLegacyDatabase();
RoutingSpec spec = new RoutingSpec();
spec.setId(DbKey.createDbKey(routingId));
rsl.readRoutingSpec(spec);
dbio.readRoutingSpec(spec);
return Response.status(HttpServletResponse.SC_OK)
.entity(map(spec)).build();
}
Expand Down Expand Up @@ -142,13 +140,12 @@ static ApiRouting map(RoutingSpec spec) {
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({AuthorizationCheck.ODCS_API_ADMIN, AuthorizationCheck.ODCS_API_USER})
public Response postRouting(ApiRouting routing)
throws DbException, SQLException
throws DbException
{
try
{
RoutingSpecListIO rsl = new RoutingSpecListIO(null, null, null, null);
RoutingSpec mappedRouting = map(routing);
rsl.write(mappedRouting);
DatabaseIO dbio = getLegacyDatabase();
dbio.writeRoutingSpec(map(routing));
return Response.status(HttpServletResponse.SC_OK).build();
}
catch(DatabaseException e)
Expand Down Expand Up @@ -186,14 +183,14 @@ static RoutingSpec map(ApiRouting routing) throws DbException
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response deleteRouting(@QueryParam("routingid") Long routingId)
throws DbException, SQLException
throws DbException
{
try
{
RoutingSpecListIO rsl = new RoutingSpecListIO(null, null, null, null);
DatabaseIO dbio = getLegacyDatabase();
RoutingSpec spec = new RoutingSpec();
spec.setId(DbKey.createDbKey(routingId));
rsl.delete(spec);
dbio.deleteRoutingSpec(spec);
return Response.status(HttpServletResponse.SC_OK)
.entity("RoutingSpec with ID " + routingId + " deleted").build();
}
Expand All @@ -210,8 +207,8 @@ public Response deleteRouting(@QueryParam("routingid") Long routingId)
public Response getScheduleRefs()
throws DbException
{
try (ScheduleEntryDAI dai = createDb().getDao(ScheduleEntryDAI.class)
.orElseThrow(() -> new DbException(NO_SCHEDULE_ENTRY_DAI)))

try (ScheduleEntryDAI dai = getLegacyDatabase().makeScheduleEntryDAO())
{
List<ScheduleEntry> entries = dai.listScheduleEntries(null);
return Response.status(HttpServletResponse.SC_OK)
Expand Down Expand Up @@ -244,17 +241,26 @@ static List<ApiScheduleEntryRef> map(List<ScheduleEntry> entries)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({AuthorizationCheck.ODCS_API_GUEST})
public Response getSchedule(@QueryParam("scheduleid") Long scheduleId)
throws WebAppException, DbException, SQLException
throws WebAppException, DbException
{
if (scheduleId == null)
throw new WebAppException(ErrorCodes.MISSING_ID,
"Missing required scheduleid parameter.");

// try (DbInterface dbi = new DbInterface();
// ApiRoutingDAO dao = new ApiRoutingDAO(dbi))
try (ScheduleEntryDAI dai = getLegacyDatabase().makeScheduleEntryDAO())
{
ScheduleEntry entry = new ScheduleEntry(DbKey.createDbKey(scheduleId));

// try (DbInterface dbi = new DbInterface();
// ApiRoutingDAO dao = new ApiRoutingDAO(dbi))
// {
// return ApiHttpUtil.createResponse(dao.getSchedule(scheduleId));
// }
}
// catch(DbIoException e)
// {
// return ApiHttpUtil.createResponse(dao.getSchedule(scheduleId));
// throw new DbException("Unable to retrieve schedule entry by ID", e);
// }

return Response.status(HttpServletResponse.SC_NOT_IMPLEMENTED).build();
}

Expand All @@ -266,8 +272,7 @@ public Response getSchedule(@QueryParam("scheduleid") Long scheduleId)
public Response postSchedule(ApiScheduleEntry schedule)
throws DbException
{
try (ScheduleEntryDAI dai = createDb().getDao(ScheduleEntryDAI.class)
.orElseThrow(() -> new DbException(NO_SCHEDULE_ENTRY_DAI)))
try (ScheduleEntryDAI dai = getLegacyDatabase().makeScheduleEntryDAO())
{
ScheduleEntry entry = map(schedule);
dai.writeScheduleEntry(entry);
Expand Down Expand Up @@ -310,14 +315,12 @@ static ScheduleEntry map(ApiScheduleEntry schedule) throws DbException
public Response deleteSchedule(@QueryParam("scheduleid") Long scheduleId)
throws DbException
{
// Use username and password to attempt to connect to the database
try (ScheduleEntryDAI dai = createDb().getDao(ScheduleEntryDAI.class)
.orElseThrow(() -> new DbException(NO_SCHEDULE_ENTRY_DAI)))
try (ScheduleEntryDAI dai = getLegacyDatabase().makeScheduleEntryDAO())
{
ScheduleEntry entry = new ScheduleEntry(DbKey.createDbKey(scheduleId));
dai.deleteScheduleEntry(entry);
return Response.status(HttpServletResponse.SC_OK)
.entity("schedulec with ID " + scheduleId + " deleted").build();
.entity("Schedule entry with ID " + scheduleId + " deleted").build();
}
catch (DbIoException e)
{
Expand All @@ -331,7 +334,7 @@ public Response deleteSchedule(@QueryParam("scheduleid") Long scheduleId)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({AuthorizationCheck.ODCS_API_GUEST})
public Response getRoutingStats()
throws WebAppException, DbException
throws DbException
{
// try (DbInterface dbi = new DbInterface();
// ApiRoutingDAO dao = new ApiRoutingDAO(dbi))
Expand Down Expand Up @@ -374,8 +377,7 @@ public Response getDacqEvents(@QueryParam("appid") Long appId, @QueryParam("rout
// return ApiHttpUtil.createResponse(dao.getDacqEvents(appId, routingExecId, platformId, backlog, session));
// }

try (DacqEventDAI dai = createDb().getDao(DacqEventDAI.class)
.orElseThrow(() -> new DbException("No DacqEventDAI available")))
try (DacqEventDAI dai = getLegacyTimeseriesDB().makeDacqEventDAO())
{
ArrayList<DacqEvent> platformEvents = new ArrayList<>();
if (platformId != null) {
Expand Down

0 comments on commit 711cca0

Please sign in to comment.