blob: 031acf15f2a53eecc421635c1418c0cc740dc5f3 [file] [log] [blame]
Pavlin Radoslavov13669052014-05-13 10:33:39 -07001package net.onrc.onos.core.intent.runtime.web;
2
Ray Milkey3aeda4f2014-05-21 14:38:58 -07003import net.onrc.onos.api.rest.RestError;
4import net.onrc.onos.api.rest.RestErrorCodes;
Pavlin Radoslavov13669052014-05-13 10:33:39 -07005import net.onrc.onos.core.intent.Intent;
6import net.onrc.onos.core.intent.IntentMap;
7import net.onrc.onos.core.intent.runtime.IPathCalcRuntimeService;
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -07008
Ray Milkey3aeda4f2014-05-21 14:38:58 -07009import org.restlet.data.Status;
10import org.restlet.representation.Representation;
Pavlin Radoslavov13669052014-05-13 10:33:39 -070011import org.restlet.resource.Get;
12import org.restlet.resource.ServerResource;
Pavlin Radoslavov13669052014-05-13 10:33:39 -070013
14/**
15 * A class to access a single low-level intent.
16 */
17public class IntentLowObjectResource extends ServerResource {
Pavlin Radoslavov13669052014-05-13 10:33:39 -070018 // TODO need to assign proper application id.
19 private static final String APPLN_ID = "1";
20
21 /**
22 * Gets a single low-level intent.
23 *
Ray Milkey3aeda4f2014-05-21 14:38:58 -070024 * @return a Representation of the single low-level intent if found,
25 * otherwise a Representation of a RestError object describing the problem.
Pavlin Radoslavov13669052014-05-13 10:33:39 -070026 */
27 @Get("json")
Ray Milkey3aeda4f2014-05-21 14:38:58 -070028 public Representation retrieve() {
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070029 IPathCalcRuntimeService pathRuntime =
30 (IPathCalcRuntimeService) getContext().getAttributes()
31 .get(IPathCalcRuntimeService.class.getCanonicalName());
Ray Milkey3aeda4f2014-05-21 14:38:58 -070032
33 Representation result;
Pavlin Radoslavov13669052014-05-13 10:33:39 -070034
35 String intentId = (String) getRequestAttributes().get("intent-id");
Pavlin Radoslavov13669052014-05-13 10:33:39 -070036
37 //
38 // Get a single low-level Intent: use the Intent ID to find it
39 //
40 IntentMap intentMap = pathRuntime.getPathIntents();
41 String applnIntentId = APPLN_ID + ":" + intentId;
42 Intent intent = intentMap.getIntent(applnIntentId);
43 if (intent != null) {
Ray Milkey3aeda4f2014-05-21 14:38:58 -070044 result = toRepresentation(intent, null);
45 } else {
46 setStatus(Status.CLIENT_ERROR_NOT_FOUND);
47 final RestError notFound =
48 RestError.createRestError(RestErrorCodes.RestErrorCode.INTENT_NOT_FOUND,
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070049 applnIntentId);
Ray Milkey3aeda4f2014-05-21 14:38:58 -070050 result = toRepresentation(notFound, null);
Pavlin Radoslavov13669052014-05-13 10:33:39 -070051 }
52
Ray Milkey3aeda4f2014-05-21 14:38:58 -070053 return result;
Pavlin Radoslavov13669052014-05-13 10:33:39 -070054 }
55}