use of org.onosproject.ui.UiExtensionService in project onos by opennetworkinglab.
the class MainIndexResource method getMainIndex.
@GET
@Produces(MediaType.TEXT_HTML)
@Path("/index.html")
public Response getMainIndex() throws IOException {
ClassLoader classLoader = getClass().getClassLoader();
UiExtensionService service;
UiTokenService tokens;
try {
service = get(UiExtensionService.class);
tokens = get(UiTokenService.class);
} catch (ServiceNotFoundException e) {
return Response.ok(classLoader.getResourceAsStream(NOT_READY)).build();
}
InputStream indexTemplate = classLoader.getResourceAsStream(INDEX);
String index = new String(toByteArray(indexTemplate));
int p0s = split(index, 0, INJECT_USER_START) - INJECT_USER_START.length();
int p0e = split(index, p0s, INJECT_USER_END);
int p1s = split(index, p0e, INJECT_JS_START) - INJECT_JS_START.length();
int p1e = split(index, p1s, INJECT_JS_END);
int p2s = split(index, p1e, INJECT_CSS_START) - INJECT_CSS_START.length();
int p2e = split(index, p2s, INJECT_CSS_END);
int p3s = split(index, p2e, null);
// FIXME: use global opaque auth token to allow secure failover
// for now, just use the user principal name...
String userName = ctx.getUserPrincipal().getName();
// get a session token to use for UI-web-socket authentication
UiSessionToken token = tokens.issueToken(userName);
String auth = "var onosUser='" + userName + "',\n" + " onosAuth='" + token + "';\n";
StreamEnumeration streams = new StreamEnumeration(of(stream(index, 0, p0s), new ByteArrayInputStream(SCRIPT_START), stream(auth, 0, auth.length()), userPreferences(userName), userConsoleLog(userName), new ByteArrayInputStream(SCRIPT_END), stream(index, p0e, p1s), includeJs(service), stream(index, p1e, p2s), includeCss(service), stream(index, p2e, p3s)));
return Response.ok(new SequenceInputStream(streams)).build();
}
use of org.onosproject.ui.UiExtensionService in project onos by opennetworkinglab.
the class MainModuleResource method getMainModule.
@GET
@Produces(SCRIPT)
public Response getMainModule() throws IOException {
UiExtensionService service = get(UiExtensionService.class);
InputStream jsTemplate = getClass().getClassLoader().getResourceAsStream(MAIN_JS);
String js = new String(toByteArray(jsTemplate));
int p1s = split(js, 0, INJECT_VIEW_IDS_START) - INJECT_VIEW_IDS_START.length();
int p1e = split(js, 0, INJECT_VIEW_IDS_END);
int p2s = split(js, p1e, null);
StreamEnumeration streams = new StreamEnumeration(of(stream(js, 0, p1s), includeViewIds(service), stream(js, p1e, p2s)));
return Response.ok(new SequenceInputStream(streams)).build();
}
use of org.onosproject.ui.UiExtensionService in project onos by opennetworkinglab.
the class MapSelectorMessageHandler method mapsJson.
private ObjectNode mapsJson() {
ObjectNode payload = objectNode();
ArrayNode order = arrayNode();
ObjectNode maps = objectNode();
payload.set(ORDER, order);
payload.set(MAPS, maps);
UiExtensionService service = get(UiExtensionService.class);
service.getExtensions().forEach(ext -> {
UiTopoMapFactory mapFactory = ext.topoMapFactory();
if (mapFactory != null) {
List<UiTopoMap> topoMaps = mapFactory.geoMaps();
topoMaps.forEach(m -> {
maps.set(m.id(), objectNode().put(MAP_ID, m.id()).put(DESCRIPTION, m.description()).put(FILE_PATH, m.filePath()).put(SCALE, m.scale()));
order.add(m.id());
});
}
});
return payload;
}
use of org.onosproject.ui.UiExtensionService in project onos by opennetworkinglab.
the class MainIndexResource method getMainIndex.
@GET
@Produces(MediaType.TEXT_HTML)
@Path("/index.html")
public Response getMainIndex() throws IOException {
ClassLoader classLoader = getClass().getClassLoader();
UiExtensionService service;
UiTokenService tokens;
try {
service = get(UiExtensionService.class);
tokens = get(UiTokenService.class);
} catch (ServiceNotFoundException e) {
return Response.ok(classLoader.getResourceAsStream(NOT_READY)).build();
}
InputStream indexTemplate = classLoader.getResourceAsStream(INDEX);
String index = new String(toByteArray(indexTemplate));
int p0s = split(index, 0, INJECT_USER_START) - INJECT_USER_START.length();
int p0e = split(index, p0s, INJECT_USER_END);
int p3s = split(index, p0e, null);
// FIXME: use global opaque auth token to allow secure failover
// for now, just use the user principal name...
String userName = ctx.getUserPrincipal().getName();
// get a session token to use for UI-web-socket authentication
UiSessionToken token = tokens.issueToken(userName);
String auth = "var onosUser='" + userName + "',\n" + " onosAuth='" + token + "';\n";
StreamEnumeration streams = new StreamEnumeration(of(stream(index, 0, p0s), new ByteArrayInputStream(SCRIPT_START), stream(auth, 0, auth.length()), userPreferences(userName), userConsoleLog(userName), new ByteArrayInputStream(SCRIPT_END), stream(index, p0e, p3s)));
return Response.ok(new SequenceInputStream(streams)).build();
}
use of org.onosproject.ui.UiExtensionService in project onos by opennetworkinglab.
the class NavResource method getNavigation.
@GET
@Path("uiextensions")
@Produces(MediaType.APPLICATION_JSON)
public Response getNavigation() throws JsonProcessingException {
UiExtensionService service = get(UiExtensionService.class);
UiViewSerializer serializer = new UiViewSerializer(UiView.class);
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule("UiViewSerializer");
module.addSerializer(serializer);
mapper.registerModule(module);
StringBuilder sb = new StringBuilder("[");
boolean first = true;
for (UiExtension uiExt : service.getExtensions()) {
for (UiView view : uiExt.views()) {
if (first) {
first = false;
} else {
sb.append(",");
}
sb.append(mapper.writeValueAsString(view));
}
}
sb.append("]");
return ok(sb.toString()).build();
}
Aggregations