use of com.bluenimble.platform.api.ApiServiceExecutionException in project serverless by bluenimble.
the class GetEntrySpi method execute.
@Override
public ApiOutput execute(Api api, final ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
String provider = (String) request.get(CommonSpec.Provider);
String key = (String) request.get(Spec.Key);
ApiSpace space;
try {
space = MgmUtils.space(consumer, api);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.FORBIDDEN);
}
Cache cache = space.feature(Cache.class, provider, request);
return new JsonApiOutput((JsonObject) new JsonObject().set(Spec.Key, key).set(Output.Value, cache.get(key, false)));
}
use of com.bluenimble.platform.api.ApiServiceExecutionException in project serverless by bluenimble.
the class BulkRecordsSpi method execute.
@Override
public ApiOutput execute(Api api, final ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
String provider = (String) request.get(CommonSpec.Provider);
final JsonObject payload = (JsonObject) request.get(ApiRequest.Payload);
ApiSpace space;
try {
space = MgmUtils.space(consumer, api);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.FORBIDDEN);
}
try {
return new JsonApiOutput(space.feature(Database.class, provider, request).bulk(payload));
} catch (DatabaseException e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
}
use of com.bluenimble.platform.api.ApiServiceExecutionException in project serverless by bluenimble.
the class DeleteRecordSpi method execute.
@Override
public ApiOutput execute(Api api, final ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
String provider = (String) request.get(CommonSpec.Provider);
String sEntity = (String) request.get(CommonSpec.Entity);
String record = (String) request.get(Spec.Record);
ApiSpace space;
try {
space = MgmUtils.space(consumer, api);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.FORBIDDEN);
}
try {
Database db = space.feature(Database.class, provider, request);
DatabaseObject oRecord = db.get(sEntity, record);
if (oRecord == null) {
return new JsonApiOutput((JsonObject) new JsonObject().set(CommonOutput.Deleted, false));
}
oRecord.delete();
} catch (DatabaseException e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
return new JsonApiOutput((JsonObject) new JsonObject().set(CommonOutput.Deleted, true));
}
use of com.bluenimble.platform.api.ApiServiceExecutionException in project serverless by bluenimble.
the class DropEntitySpi method execute.
@Override
public ApiOutput execute(Api api, final ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
String provider = (String) request.get(CommonSpec.Provider);
String sEntity = (String) request.get(CommonSpec.Entity);
ApiSpace space;
try {
space = MgmUtils.space(consumer, api);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.FORBIDDEN);
}
try {
Database db = space.feature(Database.class, provider, request);
db.drop(sEntity);
} catch (DatabaseException e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
} catch (Exception e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.NOT_FOUND);
}
return new JsonApiOutput((JsonObject) new JsonObject().set(CommonOutput.Dropped, true));
}
use of com.bluenimble.platform.api.ApiServiceExecutionException in project serverless by bluenimble.
the class ChangeServiceStatusSpi method execute.
@Override
public ApiOutput execute(Api api, ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
String apiNs = (String) request.get(CommonSpec.Api);
String sAction = (String) request.getResource()[request.getResource().length - 2];
Action action = null;
try {
action = Action.valueOf(sAction);
} catch (Exception ex) {
// ignore
}
if (action == null) {
throw new ApiServiceExecutionException("unknown change-status action " + sAction).status(ApiResponse.BAD_REQUEST);
}
JsonObject payload = (JsonObject) request.get(ApiRequest.Payload);
String sVerb = Json.getString(payload, ApiService.Spec.Verb).toUpperCase();
String endpoint = Json.getString(payload, ApiService.Spec.Endpoint);
ApiVerb verb = null;
try {
verb = ApiVerb.valueOf(sVerb);
} catch (Exception ex) {
// ignore
}
if (verb == null) {
throw new ApiServiceExecutionException("unknown service verb " + sVerb).status(ApiResponse.BAD_REQUEST);
}
Api targetApi = null;
try {
targetApi = MgmUtils.api(consumer, api, apiNs);
switch(action) {
case start:
targetApi.getServicesManager().start(verb, endpoint);
break;
case stop:
targetApi.getServicesManager().stop(verb, endpoint);
break;
case pause:
targetApi.getServicesManager().get(verb, endpoint).pause();
break;
case resume:
targetApi.getServicesManager().get(verb, endpoint).resume();
break;
default:
break;
}
} catch (Exception ex) {
throw new ApiServiceExecutionException(ex.getMessage(), ex);
}
return new JsonApiOutput((JsonObject) new JsonObject().set(Api.Spec.Status, targetApi.getServicesManager().get(verb, endpoint).status().name()));
}
Aggregations