Skip to content

Commit

Permalink
Add tobira related endpoints to allow moving series
Browse files Browse the repository at this point in the history
This adds a `post` method to update series page paths in Tobira,
and also expands some data returned by the `getHostPages` method.
  • Loading branch information
owi92 committed Oct 8, 2024
1 parent f26e50e commit 357b1e2
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,83 @@ public Response getSeriesHostPages(@PathParam("seriesId") String seriesId) {
}
}

@POST
@Path("{seriesId}/tobira/path")
@RestQuery(
name = "updateSeriesTobiraPath",
description = "Updates the path of the given series in a connected Tobira instance",
returnDescription = "Returns the new path if it has been updated in Tobira",
pathParameters = { @RestParameter(
name = "seriesId",
isRequired = true,
description = "The series id",
type = STRING) },
restParameters = {
@RestParameter(
name = "pathComponents",
isRequired = true,
description = "List of realms with name and path segment on path to series.",
type = TEXT),
@RestParameter(
name = "currentPath",
isRequired = true,
description = "Path where the series is currently mounted.",
type = STRING),
@RestParameter(
name = "targetPath",
isRequired = true,
description = "Path where the series will be mounted.",
type = STRING) },
responses = {
@RestResponse(
responseCode = SC_OK,
description = "The path of the series has successfully been updated in Tobira."),
@RestResponse(
responseCode = SC_NOT_FOUND,
description = "Tobira doesn't know about the given series"),
@RestResponse(
responseCode = SC_SERVICE_UNAVAILABLE,
description = "Tobira is not configured (correctly)") })
public Response updateSeriesTobiraPath(
@PathParam("seriesId") String seriesId,
@FormParam("pathComponents") String pathComponents,
@FormParam("currentPath") String currentPath,
@FormParam("targetPath") String targetPath
) throws IOException, InterruptedException {
if (currentPath == null || targetPath == null) {
throw new WebApplicationException("one or more `path` parameters are missing", BAD_REQUEST);
}

var tobira = getTobira();
if (!tobira.ready()) {
return Response.status(Status.SERVICE_UNAVAILABLE)
.entity("Tobira is not configured (correctly)")
.build();
}

try {
var paths = (List<JSONObject>) new JSONParser().parse(pathComponents);

var mountParams = new JSONObject();
mountParams.put("seriesId", seriesId);
mountParams.put("targetPath", targetPath);

var unmountParams = new JSONObject();
unmountParams.put("seriesId", seriesId);
unmountParams.put("currentPath", currentPath);

tobira.createRealmLineage(paths);
tobira.addSeriesMountPoint(mountParams);
tobira.removeSeriesMountPoint(unmountParams);

return ok();
} catch (Exception e) {
return Response.status(Status.INTERNAL_SERVER_ERROR)
.entity("Internal server error: " + e.getMessage())
.build();
}
}

@POST
@Path("/{seriesId}/access")
@RestQuery(name = "applyAclToSeries", description = "Immediate application of an ACL to a series", returnDescription = "Status code", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series ID", type = STRING) }, restParameters = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class TobiraService {
Expand Down Expand Up @@ -66,19 +67,26 @@ public JSONObject getHostPages(String seriesId) throws TobiraException {
"query AdminUIHostPages($seriesId: String!) {"
+ " series: seriesByOpencastId(id: $seriesId) {"
+ " hostPages: hostRealms {"
+ " title: name"
+ " path"
+ " ancestors { title: name }"
+ " ... RealmData"
+ " blocks { id }"
+ " ancestors {"
+ " ... RealmData"
+ " }"
+ " }"
+ " }"
+ "}"
+ "fragment RealmData on Realm {"
+ " title: name"
+ " segment: pathSegment"
+ " path"
+ "}",
Map.of("seriesId", seriesId))
.get("series");
}

public JSONObject getEventHostPages(String eventId) throws TobiraException {
return (JSONObject) request(
"query AdminUIHostPages($eventId: String!) {"
"query AdminUIEventHostPages($eventId: String!) {"
+ " event: eventByOpencastId(id: $eventId) {"
+ " ...on AuthorizedEvent {"
+ " hostPages: hostRealms {"
Expand All @@ -89,8 +97,8 @@ public JSONObject getEventHostPages(String eventId) throws TobiraException {
+ " }"
+ " }"
+ "}",
Map.of("eventId", eventId)
).get("event");
Map.of("eventId", eventId))
.get("event");
}

public void mount(Map<String, Object> variables) throws TobiraException {
Expand All @@ -104,6 +112,37 @@ public void mount(Map<String, Object> variables) throws TobiraException {
variables);
}

public Integer createRealmLineage(List<JSONObject> pathComponents) throws TobiraException {
return (Integer) request(
"mutation AdminUICreateRealmLineage($realms: [RealmLineageComponent!]!) {"
+ " createRealmLineage(realms: $realms) { numCreated }"
+ "}",
Map.of("realms", pathComponents))
.get("numCreated");
}

public String addSeriesMountPoint(Map<String, Object> variables) throws TobiraException {
return (String) request(
"mutation AdminUIAddSeriesMountPoint($seriesId: String!, $targetPath: String!) {"
+ " addSeriesMountPoint(seriesOcId: $seriesId, targetPath: $targetPath) {"
+ " id"
+ " }"
+ "}",
variables)
.get("id");
}

public JSONObject removeSeriesMountPoint(Map<String, Object> variables) throws TobiraException {
return (JSONObject) request(
"mutation AdminUIRemoveSeriesMountPoint($seriesId: String!, $currentPath: String!) {"
+ " outcome: removeSeriesMountPoint(seriesOcId: $seriesId, path: $currentPath) {"
+ " __typename"
+ " }"
+ "}",
variables)
.get("outcome");
}

public boolean ready() {
return this.endpoint != null && this.trustedKey != null;
}
Expand Down

0 comments on commit 357b1e2

Please sign in to comment.