use of com.manydesigns.portofino.dispatcher.Resource in project Portofino by ManyDesigns.
the class DocumentedApiRoot method afterScan.
@Override
public void afterScan(OpenApiReader reader, OpenAPI openAPI) {
final SubResourceReader subResourceReader = getSubResourceReader(openAPI);
try {
// TODO actions should be put in a special "inspection mode" to avoid checks (e.g. not-in-use-case),
// hitting the DB or services, etc.
Resource root = rootFactory.createRoot();
root.setResourceContext(getResourceContext());
initRoot(root);
if (openAPI.getPaths() == null) {
openAPI.setPaths(new Paths());
}
new DepthFirstVisitor(node -> {
try {
OpenAPI subApi = subResourceReader.readSubResource(node);
openAPI.getPaths().putAll(subApi.getPaths());
// TODO merge components too
} catch (Exception e) {
logger.error("Could not read node at " + node.getLocation(), e);
}
}).visit(root);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
use of com.manydesigns.portofino.dispatcher.Resource in project Portofino by ManyDesigns.
the class ActionsAction method getResource.
@Path("action")
public Resource getResource() {
String actionPath = StringUtils.join(parameters, "/");
Resource resource = getResource(actionPath);
if (resource == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
return resource;
}
use of com.manydesigns.portofino.dispatcher.Resource in project Portofino by ManyDesigns.
the class ActionsAction method getResourceAction.
protected AbstractResourceAction getResourceAction() {
String actionPath = StringUtils.join(parameters, "/");
Resource resource = getResource(actionPath);
if (resource instanceof AbstractResourceAction) {
return ((AbstractResourceAction) resource);
} else {
logger.error("Not a ResourceAction: " + resource);
throw new WebApplicationException();
}
}
use of com.manydesigns.portofino.dispatcher.Resource in project Portofino by ManyDesigns.
the class ActionsAction method getResource.
public Resource getResource(String actionPath) {
Resource resource = getRoot();
if (actionPath.isEmpty()) {
return resource;
}
String[] pathSegments = actionPath.split("/");
for (String segment : pathSegments) {
if (resource instanceof WithParameters) {
WithParameters withParameters = (WithParameters) resource;
if (withParameters.getParameters().size() < withParameters.getMinParameters()) {
withParameters.consumeParameter(segment);
continue;
}
}
Object subResource = null;
try {
subResource = resource.getSubResource(segment);
} catch (Exception e) {
logger.debug("Could not load resource", e);
}
if (subResource instanceof Resource) {
resource = (Resource) subResource;
} else if (resource instanceof WithParameters) {
WithParameters withParameters = (WithParameters) resource;
if (withParameters.getParameters().size() < withParameters.getMaxParameters()) {
withParameters.consumeParameter(segment);
} else {
return null;
}
} else {
return null;
}
}
return resource;
}
use of com.manydesigns.portofino.dispatcher.Resource in project Portofino by ManyDesigns.
the class ApplicationRoot method start.
@Path("")
public Object start() throws Exception {
Resource root = rootFactory.createRoot();
resourceContext.initResource(root);
return root.init();
}
Aggregations