use of org.structr.common.SecurityContext in project structr by structr.
the class JavaParserModule method indexSourceTree.
/**
* Create an index containing all compilation units of Java files from
* the source tree under the given root folder.
*
* @param rootFolder
*/
public void indexSourceTree(final Folder rootFolder) {
logger.info("Starting indexing of source tree " + rootFolder.getPath());
final SecurityContext securityContext = rootFolder.getSecurityContext();
app = StructrApp.getInstance(securityContext);
structrTypeSolver.parseRoot(rootFolder);
final CombinedTypeSolver typeSolver = new CombinedTypeSolver();
typeSolver.add(new ReflectionTypeSolver());
typeSolver.add(structrTypeSolver);
facade = JavaParserFacade.get(typeSolver);
logger.info("Done with indexing of source tree " + rootFolder.getPath());
}
use of org.structr.common.SecurityContext in project structr by structr.
the class JavaParserModule method parseSourceTree.
/**
* Parse the source tree under the given root folder.
*
* @param rootFolder
*/
public void parseSourceTree(final Folder rootFolder) {
logger.info("Starting parsing of source tree " + rootFolder.getPath());
final SecurityContext securityContext = rootFolder.getSecurityContext();
app = StructrApp.getInstance(securityContext);
final CombinedTypeSolver typeSolver = new CombinedTypeSolver();
typeSolver.add(new ReflectionTypeSolver());
typeSolver.add(structrTypeSolver);
facade = JavaParserFacade.get(typeSolver);
parseFolder(rootFolder, 0, null);
logger.info("Done with parsing of source tree " + rootFolder.getPath());
}
use of org.structr.common.SecurityContext in project structr by structr.
the class ParseSourceTreeFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
try {
if (!(arrayHasLengthAndAllElementsNotNull(sources, 1) && sources[0] instanceof String)) {
return null;
}
final SecurityContext securityContext = ctx.getSecurityContext();
final App app = StructrApp.getInstance(securityContext);
new JavaParserModule().parseSourceTree(app.nodeQuery(Folder.class).and(StructrApp.key(Folder.class, "path"), (String) sources[0]).getFirst());
} catch (final IllegalArgumentException e) {
logParameterError(caller, sources, ctx.isJavaScriptContext());
return usage(ctx.isJavaScriptContext());
}
return "";
}
use of org.structr.common.SecurityContext in project structr by structr.
the class VideoFile method getMetadata.
static RestMethodResult getMetadata(final VideoFile thisVideo) throws FrameworkException {
final SecurityContext securityContext = thisVideo.getSecurityContext();
final Map<String, String> metadata = AVConv.newInstance(securityContext, thisVideo).getMetadata();
final RestMethodResult result = new RestMethodResult(200);
final GraphObjectMap map = new GraphObjectMap();
for (final Entry<String, String> entry : metadata.entrySet()) {
map.setProperty(new StringProperty(entry.getKey()), entry.getValue());
}
result.addContent(map);
return result;
}
use of org.structr.common.SecurityContext in project structr by structr.
the class GraphQLServlet method handleGraphQLRequest.
// ----- private methods -----
private void handleGraphQLRequest(final HttpServletRequest request, final HttpServletResponse response, final String query) throws IOException, FrameworkException {
final SecurityContext securityContext;
final Authenticator authenticator;
try {
// isolate request authentication in a transaction
try (final Tx tx = StructrApp.getInstance().tx()) {
authenticator = config.getAuthenticator();
securityContext = authenticator.initializeAndExamineRequest(request, response);
tx.success();
}
final App app = StructrApp.getInstance(securityContext);
if (securityContext != null) {
// isolate write output
try (final Tx tx = app.tx()) {
final Document doc = GraphQLRequest.parse(new Parser(), query);
if (doc != null) {
final List<ValidationError> errors = new Validator().validateDocument(SchemaService.getGraphQLSchema(), doc);
if (errors.isEmpty()) {
// no validation errors in query, do request
final GraphQLWriter graphQLWriter = new GraphQLWriter(true);
// no trailing semicolon so we dont trip MimeTypes.getContentTypeWithoutCharset
response.setContentType("application/json; charset=utf-8");
final Writer writer = response.getWriter();
graphQLWriter.stream(securityContext, writer, new GraphQLRequest(securityContext, doc, query));
// useful newline
writer.append("\n");
} else {
final Map<String, Object> map = new LinkedHashMap<>();
final Writer writer = response.getWriter();
final Gson gson = getGson();
map.put("errors", errors);
gson.toJson(map, writer);
// useful newline
writer.append("\n");
// send 422 status
response.setStatus(422);
}
}
tx.success();
}
}
} catch (FrameworkException frameworkException) {
// set status & write JSON output
response.setStatus(frameworkException.getStatus());
getGson().toJson(frameworkException, response.getWriter());
response.getWriter().println();
} catch (IllegalStateException | IllegalArgumentException iex) {
final Map<String, Object> map = new LinkedHashMap<>();
map.put("code", 422);
map.put("message", iex.getMessage());
// set status & write JSON output
response.setStatus(422);
getGson().toJson(map, response.getWriter());
response.getWriter().println();
} catch (UnsupportedOperationException uoe) {
logger.warn("POST not supported");
int code = HttpServletResponse.SC_BAD_REQUEST;
response.setStatus(code);
response.getWriter().append(RestMethodResult.jsonError(code, "POST not supported: " + uoe.getMessage()));
} catch (Throwable t) {
logger.warn("Exception in POST", t);
int code = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
response.setStatus(code);
response.getWriter().append(RestMethodResult.jsonError(code, "JsonSyntaxException in POST: " + t.getMessage()));
} finally {
try {
// response.getWriter().flush();
response.getWriter().close();
} catch (Throwable t) {
logger.warn("Unable to flush and close response: {}", t.getMessage());
}
}
}
Aggregations