use of org.structr.core.GraphObjectMap in project structr by structr.
the class PaymentNode method beginCheckout.
public static GraphObject beginCheckout(final PaymentNode thisNode, final String providerName, final String successUrl, final String cancelUrl) throws FrameworkException {
final PaymentProvider provider = PaymentNode.getPaymentProvider(providerName);
if (provider != null) {
final BeginCheckoutResponse response = provider.beginCheckout(thisNode, successUrl, cancelUrl);
if (CheckoutState.Success.equals(response.getCheckoutState())) {
final GraphObjectMap data = new GraphObjectMap();
data.put(StructrApp.key(PaymentNode.class, "token"), response.getToken());
return data;
} else {
throwErrors("Unable to begin checkout.", response);
}
} else {
throw new FrameworkException(422, "Payment provider " + providerName + " not found.");
}
return null;
}
use of org.structr.core.GraphObjectMap in project structr by structr.
the class LayoutsCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final Map<String, Object> data = webSocketData.getNodeData();
final String mode = (String) data.get("mode");
final String name = (String) data.get("name");
if (mode != null) {
final List<GraphObject> result = new LinkedList<>();
switch(mode) {
case "list":
final List<String> layouts = LayoutsCommand.listLayouts();
if (layouts != null) {
final GraphObjectMap layoutContainer = new GraphObjectMap();
layoutContainer.put(layoutsProperty, layouts);
result.add(layoutContainer);
webSocketData.setResult(result);
webSocketData.setRawResultCount(1);
getWebSocket().send(webSocketData, true);
}
break;
case "get":
try {
final String content = new String(Files.readAllBytes(locateFile(name).toPath()));
getWebSocket().send(MessageBuilder.finished().callback(callback).data("schemaLayout", content).build(), true);
} catch (IOException | FrameworkException ex) {
logger.error("", ex);
}
break;
case "add":
final String positions = (String) data.get("schemaLayout");
try {
final File layoutFile = locateFile(name);
if (layoutFile.exists()) {
getWebSocket().send(MessageBuilder.status().code(422).message("Layout already exists!").build(), true);
} else {
createLayout(name, positions);
}
getWebSocket().send(MessageBuilder.finished().callback(callback).build(), true);
} catch (FrameworkException ex) {
logger.error("", ex);
}
break;
case "delete":
try {
deleteLayout(name);
getWebSocket().send(MessageBuilder.finished().callback(callback).build(), true);
} catch (FrameworkException ex) {
logger.error("", ex);
}
break;
default:
getWebSocket().send(MessageBuilder.status().code(422).message("Mode must be one of list, get, add or delete.").build(), true);
}
} else {
getWebSocket().send(MessageBuilder.status().code(422).message("Mode must be one of list, get, add or delete.").build(), true);
}
}
use of org.structr.core.GraphObjectMap in project structr by structr.
the class ListActiveElementsCommand method extractActiveElement.
private GraphObject extractActiveElement(final DOMNode node, final Set<String> dataKeys, final String parentId, final ActiveElementState state, final int depth) {
final PropertyKey<String> actionKey = StructrApp.key(DOMElement.class, "data-structr-action");
final PropertyKey<String> hrefKey = StructrApp.key(Link.class, "_html_href");
final PropertyKey<String> contentKey = StructrApp.key(Content.class, "content");
final GraphObjectMap activeElement = new GraphObjectMap();
activeElement.put(GraphObject.id, node.getUuid());
activeElement.put(GraphObject.type, node.getType());
activeElement.put(StructrApp.key(DOMElement.class, "dataKey"), StringUtils.join(dataKeys, ","));
activeElement.put(contentKey, node.getProperty(contentKey));
switch(state) {
case Button:
activeElement.put(actionProperty, node.getProperty(actionKey));
break;
case Link:
activeElement.put(actionProperty, node.getProperty(hrefKey));
break;
case Query:
extractQueries(activeElement, node);
break;
}
activeElement.put(stateProperty, state.name());
activeElement.put(recursionDepthProperty, depth);
activeElement.put(parentIdProperty, parentId);
return activeElement;
}
use of org.structr.core.GraphObjectMap in project structr by structr.
the class FileImportCommand method processMessage.
// ~--- methods --------------------------------------------------------
@Override
public void processMessage(WebSocketMessage webSocketData) throws FrameworkException {
// final SecurityContext securityContext = getWebSocket().getSecurityContext();
final Map<String, Object> properties = webSocketData.getNodeData();
// default: list start | pause | resume | cancel | abort
final String mode = (String) properties.get("mode");
final Long jobId = (Long) properties.get("jobId");
final JobQueueManager mgr = JobQueueManager.getInstance();
final List<GraphObject> result = new LinkedList<>();
switch(mode) {
case "start":
mgr.startJob(jobId);
break;
case "pause":
mgr.pauseRunningJob(jobId);
break;
case "resume":
mgr.resumePausedJob(jobId);
break;
case "abort":
mgr.abortActiveJob(jobId);
break;
case "cancel":
mgr.cancelQueuedJob(jobId);
break;
case "list":
default:
final GraphObjectMap importsContainer = new GraphObjectMap();
importsContainer.put(importJobsProperty, mgr.listJobs());
result.add(importsContainer);
}
webSocketData.setResult(result);
webSocketData.setRawResultCount(1);
getWebSocket().send(webSocketData, true);
}
use of org.structr.core.GraphObjectMap in project structr by structr.
the class ToJsonFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) {
if (sources != null && sources.length >= 1 && sources.length <= 3) {
try {
final SecurityContext securityContext = ctx.getSecurityContext();
final Value<String> view = new StaticValue<>("public");
if (sources.length > 1) {
view.set(securityContext, sources[1].toString());
}
int outputDepth = 3;
if (sources.length > 2 && sources[2] instanceof Number) {
outputDepth = ((Number) sources[2]).intValue();
}
final StreamingJsonWriter jsonStreamer = new StreamingJsonWriter(view, true, outputDepth);
final StringWriter writer = new StringWriter();
if (sources[0] instanceof GraphObject) {
jsonStreamer.streamSingle(securityContext, writer, (GraphObject) sources[0]);
} else if (sources[0] instanceof List) {
final List list = (List) sources[0];
jsonStreamer.stream(securityContext, writer, new Result(list, list.size(), true, false), null);
} else if (sources[0] instanceof Map) {
final GraphObjectMap map = new GraphObjectMap();
this.recursivelyConvertMapToGraphObjectMap(map, (Map) sources[0], outputDepth);
jsonStreamer.stream(securityContext, writer, new Result(map, false), null);
}
return writer.getBuffer().toString();
} catch (Throwable t) {
logException(caller, t, sources);
}
return "";
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
}
return usage(ctx.isJavaScriptContext());
}
Aggregations