use of com.bluenimble.platform.ValueHolder in project serverless by bluenimble.
the class ApiImpl method describe.
@Override
public JsonObject describe(final DescribeOption... options) {
if (options == null || options.length == 0) {
return JsonObject.Blank;
}
final Map<DescribeOption.Option, DescribeOption> opts = DescribeUtils.toMap(options);
JsonObject describe = new JsonObject();
if (opts.containsKey(DescribeOption.Option.info)) {
describe.set(Api.Spec.Namespace, getNamespace());
describe.set(Api.Spec.Name, getName());
describe.set(Api.Spec.Description, getDescription());
describe.set(Api.Spec.Status, status().name());
if (failure != null) {
describe.set(Describe.Failure, failure);
}
describe.set(Api.Spec.Release, getRelease());
}
if (getSecurity() != null && opts.containsKey(DescribeOption.Option.security)) {
describe.set(Api.Spec.Security.class.getSimpleName().toLowerCase(), getSecurity().duplicate());
}
if (getTracking() != null && opts.containsKey(DescribeOption.Option.tracking)) {
describe.set(Api.Spec.Tracking.class.getSimpleName().toLowerCase(), getTracking().duplicate());
}
if (getFeatures() != null && opts.containsKey(DescribeOption.Option.features)) {
describe.set(Api.Spec.Features, getFeatures().duplicate());
}
if (getCustom() != null && opts.containsKey(DescribeOption.Option.custom)) {
describe.set(Api.Spec.Custom, getCustom().duplicate());
}
if (servicesManager.isEmpty(null)) {
return describe;
}
final JsonObject failedServices = new JsonObject();
describe.set(Describe.FailedServices, failedServices);
JsonArray aServices = new JsonArray();
describe.set(Describe.Services, aServices);
final JsonArray fServices = aServices;
final ValueHolder<Integer> apiMarkers = new ValueHolder<Integer>(0);
servicesManager.list(new Selector() {
@Override
public boolean select(ApiService service) {
if (opts.containsKey(DescribeOption.Option.services)) {
DescribeOption opt = opts.get(DescribeOption.Option.services);
JsonObject jService = service.toJson();
JsonObject sDesc = jService;
if (!opt.isVerbose()) {
sDesc = new JsonObject();
sDesc.set(ApiService.Spec.Name, jService.get(ApiService.Spec.Name));
sDesc.set(ApiService.Spec.Endpoint, jService.get(ApiService.Spec.Endpoint));
sDesc.set(ApiService.Spec.Verb, jService.get(ApiService.Spec.Verb));
sDesc.set(ApiService.Spec.Status, jService.get(ApiService.Spec.Status));
sDesc.set(ApiService.Spec.Security.class.getSimpleName().toLowerCase(), service.getSecurity());
JsonArray aMarkers = Json.getArray(jService, Api.Spec.Markers);
int markers = aMarkers != null ? aMarkers.size() : 0;
apiMarkers.set(apiMarkers.get() + markers);
if (markers > 0) {
sDesc.set(Api.Spec.Markers, markers);
}
}
fServices.add(sDesc);
}
if (ApiStatus.Failed.equals(service.status())) {
failedServices.put(service.getVerb().name() + Lang.SPACE + Json.getString(service.toJson(), ApiService.Spec.Endpoint), service.getFailure());
}
return false;
}
});
describe.set(Api.Spec.Markers, apiMarkers.get());
if (fServices.isEmpty()) {
describe.remove(Describe.Services);
}
if (failedServices.isEmpty()) {
describe.remove(Describe.FailedServices);
}
return describe;
}
use of com.bluenimble.platform.ValueHolder in project serverless by bluenimble.
the class FileSystemFolder method list.
@Override
public void list(Visitor visitor, Filter filter) throws StorageException {
if (visitor == null) {
return;
}
final ValueHolder<FileSystemStorageObject> vh = new ValueHolder<FileSystemStorageObject>();
vh.set(new FileSystemStorageObject());
DirectoryStream<Path> stream = null;
try {
stream = Files.newDirectoryStream(source.toPath(), new DirectoryStream.Filter<Path>() {
public boolean accept(Path path) throws IOException {
vh.get().setSource(path.toFile());
return filter == null ? true : filter.accept(vh.get());
}
});
if (stream == null) {
return;
}
for (Path path : stream) {
vh.get().setSource(path.toFile());
if (vh.get().isFolder()) {
try {
vh.set(vh.get().toFolder());
} catch (StorageException e) {
throw new IOException(e.getMessage(), e);
}
}
visitor.visit(vh.get());
}
} catch (IOException e) {
throw new StorageException(e.getMessage(), e);
} finally {
try {
if (stream != null)
stream.close();
} catch (IOException ex) {
}
}
}
use of com.bluenimble.platform.ValueHolder in project serverless by bluenimble.
the class ApiImpl method lockup.
protected ApiService lockup(final ApiVerb verb, String[] endpoint) {
if (servicesManager.isEmpty(verb)) {
return null;
}
String path = Lang.SLASH;
if (endpoint != null && endpoint.length > 0) {
path += Lang.join(endpoint, Lang.SLASH);
}
ApiService service = servicesManager.get(verb, path);
if (service != null) {
return service;
}
final String wildcard = path;
final ValueHolder<ApiService> holder = new ValueHolder<ApiService>();
servicesManager.list(new Selector() {
@Override
public boolean select(ApiService service) {
WildcardMatcher matcher = new WildcardMatcher(WildcardCompiler.compile(service.getEndpoint()), wildcard);
if (matcher.find() && service.getVerb().equals(verb)) {
holder.set(service);
return true;
}
return false;
}
});
return holder.get();
}
Aggregations