Search in sources :

Example 56 with GraphObjectMap

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;
}
Also used : PaymentProvider(org.structr.payment.api.PaymentProvider) PayPalPaymentProvider(org.structr.payment.impl.paypal.PayPalPaymentProvider) StripePaymentProvider(org.structr.payment.impl.stripe.StripePaymentProvider) TestPaymentProvider(org.structr.payment.impl.test.TestPaymentProvider) BeginCheckoutResponse(org.structr.payment.api.BeginCheckoutResponse) FrameworkException(org.structr.common.error.FrameworkException) GraphObjectMap(org.structr.core.GraphObjectMap)

Example 57 with GraphObjectMap

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);
    }
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) GraphObjectMap(org.structr.core.GraphObjectMap) GraphObject(org.structr.core.GraphObject) IOException(java.io.IOException) GraphObject(org.structr.core.GraphObject) File(java.io.File) LinkedList(java.util.LinkedList)

Example 58 with GraphObjectMap

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;
}
Also used : GraphObjectMap(org.structr.core.GraphObjectMap) DOMElement(org.structr.web.entity.dom.DOMElement)

Example 59 with GraphObjectMap

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);
}
Also used : GraphObjectMap(org.structr.core.GraphObjectMap) GraphObject(org.structr.core.GraphObject) JobQueueManager(org.structr.core.scheduler.JobQueueManager) GraphObject(org.structr.core.GraphObject) LinkedList(java.util.LinkedList)

Example 60 with GraphObjectMap

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());
}
Also used : StaticValue(org.structr.core.StaticValue) GraphObject(org.structr.core.GraphObject) Result(org.structr.core.Result) StringWriter(java.io.StringWriter) StreamingJsonWriter(org.structr.rest.serialization.StreamingJsonWriter) GraphObjectMap(org.structr.core.GraphObjectMap) SecurityContext(org.structr.common.SecurityContext) List(java.util.List) Map(java.util.Map) GraphObjectMap(org.structr.core.GraphObjectMap)

Aggregations

GraphObjectMap (org.structr.core.GraphObjectMap)60 LinkedList (java.util.LinkedList)27 GraphObject (org.structr.core.GraphObject)24 Map (java.util.Map)18 FrameworkException (org.structr.common.error.FrameworkException)16 StringProperty (org.structr.core.property.StringProperty)15 GenericProperty (org.structr.core.property.GenericProperty)13 PropertyKey (org.structr.core.property.PropertyKey)12 List (java.util.List)11 Result (org.structr.core.Result)10 SecurityContext (org.structr.common.SecurityContext)8 IntProperty (org.structr.core.property.IntProperty)8 RestMethodResult (org.structr.rest.RestMethodResult)8 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)6 Test (org.junit.Test)6 ConfigurationProvider (org.structr.schema.ConfigurationProvider)6 HashMap (java.util.HashMap)5 LinkedHashSet (java.util.LinkedHashSet)5 Tx (org.structr.core.graph.Tx)5