Search in sources :

Example 21 with ScriptValue

use of com.enonic.xp.script.ScriptValue in project xp by enonic.

the class ModifyProfileHandler method newProfileEditor.

private void newProfileEditor(final EditableUser edit) {
    final PropertyTree profile = edit.source.getProfile();
    final PropertyTreeMapper mapper = createPropertyTreeMapper(profile, true);
    final ScriptValue scriptValue = this.editor.call(mapper);
    updateUser(edit, scriptValue);
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) PropertyTree(com.enonic.xp.data.PropertyTree) PropertyTreeMapper(com.enonic.xp.lib.common.PropertyTreeMapper)

Example 22 with ScriptValue

use of com.enonic.xp.script.ScriptValue in project xp by enonic.

the class ModifyNodeHandler method execute.

@Override
public Object execute() {
    final Node node = getExistingNode();
    final ScriptValue updatedNodeScriptValue = applyEditor(node);
    final BinaryAttachments binaryAttachments = getBinaryAttachments(updatedNodeScriptValue);
    final UpdateNodeParams updateNodeParams = UpdateNodeParams.create().id(node.id()).editor(createEditor(updatedNodeScriptValue)).setBinaryAttachments(binaryAttachments).build();
    final Node updatedNode = this.nodeService.update(updateNodeParams);
    return new NodeMapper(updatedNode, false);
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) BinaryAttachments(com.enonic.xp.node.BinaryAttachments) Node(com.enonic.xp.node.Node) EditableNode(com.enonic.xp.node.EditableNode) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) NodeMapper(com.enonic.xp.lib.node.mapper.NodeMapper)

Example 23 with ScriptValue

use of com.enonic.xp.script.ScriptValue in project xp by enonic.

the class ErrorHandlerScriptImpl method doExecute.

private PortalResponse doExecute(final PortalError portalError, final String handlerMethod) {
    Tracer.withCurrent(this::addTraceInfo);
    final PortalErrorMapper portalErrorMapper = new PortalErrorMapper(portalError);
    final ScriptValue result = this.scriptExports.executeMethod(handlerMethod, portalErrorMapper);
    if ((result == null) || !result.isObject()) {
        return null;
    } else {
        return new PortalResponseSerializer(result, portalError.getStatus()).defaultPostProcess(false).applyFilters(false).serialize();
    }
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) PortalResponseSerializer(com.enonic.xp.portal.impl.controller.PortalResponseSerializer) PortalErrorMapper(com.enonic.xp.portal.impl.mapper.PortalErrorMapper)

Example 24 with ScriptValue

use of com.enonic.xp.script.ScriptValue in project xp by enonic.

the class ScriptValueTranslatorTest method getCreateNodeHandlerParams.

private ScriptValueTranslatorResult getCreateNodeHandlerParams(final String name) {
    final ScriptExports exports = runScript("/com/enonic/xp/lib/value/script-values.js");
    final ScriptValue value = exports.executeMethod(name);
    return new ScriptValueTranslator().create(value);
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) ScriptExports(com.enonic.xp.script.ScriptExports)

Example 25 with ScriptValue

use of com.enonic.xp.script.ScriptValue in project xp by enonic.

the class ControllerScriptImpl method doExecute.

private PortalResponse doExecute(final PortalRequest portalRequest) {
    Tracer.withCurrent(this::addTraceInfo);
    final HttpMethod method = portalRequest.getMethod();
    final boolean isHead = method == HttpMethod.HEAD;
    String runMethod = isHead ? "get" : method.toString().toLowerCase();
    final boolean exists = this.scriptExports.hasMethod(runMethod);
    if (!exists) {
        if (this.scriptExports.hasMethod(ALL_SCRIPT_METHOD_NAME)) {
            runMethod = ALL_SCRIPT_METHOD_NAME;
        } else {
            return new PortalResponseSerializer(null, HttpStatus.METHOD_NOT_ALLOWED).serialize();
        }
    }
    final PortalRequestMapper requestMapper = new PortalRequestMapper(portalRequest);
    final ScriptValue result = this.scriptExports.executeMethod(runMethod, requestMapper);
    return new PortalResponseSerializer(result).serialize();
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) PortalRequestMapper(com.enonic.xp.portal.impl.mapper.PortalRequestMapper) HttpMethod(com.enonic.xp.web.HttpMethod)

Aggregations

ScriptValue (com.enonic.xp.script.ScriptValue)40 Test (org.junit.jupiter.api.Test)20 PortalRequest (com.enonic.xp.portal.PortalRequest)7 PortalResponseSerializer (com.enonic.xp.portal.impl.controller.PortalResponseSerializer)5 PortalRequestMapper (com.enonic.xp.portal.impl.mapper.PortalRequestMapper)5 JSObject (jdk.nashorn.api.scripting.JSObject)4 PortalResponseMapper (com.enonic.xp.portal.impl.mapper.PortalResponseMapper)3 ScriptExports (com.enonic.xp.script.ScriptExports)3 PropertyTree (com.enonic.xp.data.PropertyTree)2 ResourceProblemException (com.enonic.xp.resource.ResourceProblemException)2 WebException (com.enonic.xp.web.WebException)2 ByteSource (com.google.common.io.ByteSource)2 Map (java.util.Map)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 Content (com.enonic.xp.content.Content)1 ContentId (com.enonic.xp.content.ContentId)1 ContentQuery (com.enonic.xp.content.ContentQuery)1 Contents (com.enonic.xp.content.Contents)1 FindContentIdsByQueryResult (com.enonic.xp.content.FindContentIdsByQueryResult)1 GetContentByIdsParams (com.enonic.xp.content.GetContentByIdsParams)1