Search in sources :

Example 6 with StringValue

use of org.apache.wicket.util.string.StringValue in project hale by halestudio.

the class EditTemplatePage method addControls.

@Override
protected void addControls() {
    StringValue idParam = getPageParameters().get(0);
    if (!idParam.isNull() && !idParam.isEmpty()) {
        String templateId = idParam.toString();
        OrientGraph graph = DatabaseHelper.getGraph();
        try {
            Template template = null;
            try {
                template = Template.getByTemplateId(graph, templateId);
            } catch (NonUniqueResultException e) {
                log.error("Duplicate template representation: " + templateId, e);
            }
            if (template != null) {
                // get associated user
                Vertex v = template.getV();
                Iterator<Vertex> owners = v.getVertices(Direction.OUT, "owner").iterator();
                if (// user is admin
                UserUtil.isAdmin() || // or user is owner
                (owners.hasNext() && UserUtil.getLogin().equals(new User(owners.next(), graph).getLogin()))) {
                    add(new TemplateForm("edit-form", false, templateId));
                } else {
                    throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_FORBIDDEN);
                }
            } else {
                throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Template not found.");
            }
        } finally {
            graph.shutdown();
        }
    } else
        throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_BAD_REQUEST, "Template identifier must be specified.");
}
Also used : NonUniqueResultException(eu.esdihumboldt.util.blueprints.entities.NonUniqueResultException) Vertex(com.tinkerpop.blueprints.Vertex) User(eu.esdihumboldt.hale.server.model.User) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) TemplateForm(eu.esdihumboldt.hale.server.templates.war.components.TemplateForm) AbortWithHttpErrorCodeException(org.apache.wicket.request.http.flow.AbortWithHttpErrorCodeException) StringValue(org.apache.wicket.util.string.StringValue) Template(eu.esdihumboldt.hale.server.model.Template)

Example 7 with StringValue

use of org.apache.wicket.util.string.StringValue in project hale by halestudio.

the class BasePage method configureTheme.

/**
 * sets the theme for the current user.
 *
 * @param pageParameters current page parameters
 */
private void configureTheme(PageParameters pageParameters) {
    StringValue theme = pageParameters.get("theme");
    if (!theme.isEmpty()) {
        IBootstrapSettings settings = Bootstrap.getSettings(getApplication());
        settings.getActiveThemeProvider().setActiveTheme(theme.toString(""));
    }
}
Also used : IBootstrapSettings(de.agilecoders.wicket.core.settings.IBootstrapSettings) StringValue(org.apache.wicket.util.string.StringValue)

Example 8 with StringValue

use of org.apache.wicket.util.string.StringValue in project the-app by devops-dojo.

the class CartRequestCycleListener method onBeginRequest.

@Override
public void onBeginRequest(RequestCycle cycle) {
    StringValue cartParameterValue = cycle.getRequest().getRequestParameters().getParameterValue(CART_PARAMETER);
    if (!cartParameterValue.isEmpty()) {
        try {
            selectedRedisMicroserviceCart();
            cart.setCartId(cartParameterValue.toString());
            LOGGER.info(String.format("Session '%s' set cart '%s'", ShopSession.get().getId(), cartParameterValue.toString()));
        } catch (Exception e) {
            LOGGER.error("Cart processing failed:", e);
        }
    }
}
Also used : StringValue(org.apache.wicket.util.string.StringValue)

Example 9 with StringValue

use of org.apache.wicket.util.string.StringValue in project wicket by apache.

the class MockHttpServletRequest method buildRequest.

/**
 * Build the request based on the uploaded files and the parameters.
 *
 * @return The request as a string.
 */
private byte[] buildRequest() {
    if (uploadedFiles == null && useMultiPartContentType == false) {
        if (post.getParameterNames().size() == 0) {
            return "".getBytes();
        }
        Url url = new Url();
        for (final String parameterName : post.getParameterNames()) {
            List<StringValue> values = post.getParameterValues(parameterName);
            for (StringValue value : values) {
                url.addQueryParameter(parameterName, value.toString());
            }
        }
        String body = url.toString().substring(1);
        return body.getBytes();
    }
    try {
        // Build up the input stream based on the files and parameters
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        // Add parameters
        for (final String parameterName : post.getParameterNames()) {
            List<StringValue> values = post.getParameterValues(parameterName);
            for (StringValue value : values) {
                newAttachment(out);
                out.write("; name=\"".getBytes());
                out.write(parameterName.getBytes());
                out.write("\"".getBytes());
                out.write(crlf.getBytes());
                out.write(crlf.getBytes());
                out.write(value.toString().getBytes());
                out.write(crlf.getBytes());
            }
        }
        // Add files
        if (uploadedFiles != null) {
            for (Map.Entry<String, List<UploadedFile>> entry : uploadedFiles.entrySet()) {
                String fieldName = entry.getKey();
                List<UploadedFile> files = entry.getValue();
                for (UploadedFile uf : files) {
                    newAttachment(out);
                    out.write("; name=\"".getBytes());
                    out.write(fieldName.getBytes());
                    out.write("\"; filename=\"".getBytes());
                    if (uf.getFile() != null) {
                        out.write(uf.getFile().getName().getBytes());
                    }
                    out.write("\"".getBytes());
                    out.write(crlf.getBytes());
                    out.write("Content-Type: ".getBytes());
                    out.write(uf.getContentType().getBytes());
                    out.write(crlf.getBytes());
                    out.write(crlf.getBytes());
                    if (uf.getFile() != null) {
                        // Load the file and put it into the the inputstream
                        FileInputStream fis = new FileInputStream(uf.getFile());
                        try {
                            IOUtils.copy(fis, out);
                        } finally {
                            fis.close();
                        }
                    }
                    out.write(crlf.getBytes());
                }
            }
        }
        out.write(boundary.getBytes());
        out.write("--".getBytes());
        out.write(crlf.getBytes());
        return out.toByteArray();
    } catch (IOException e) {
        // NOTE: IllegalStateException(Throwable) only exists since Java 1.5
        throw new WicketRuntimeException(e);
    }
}
Also used : WicketRuntimeException(org.apache.wicket.WicketRuntimeException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Url(org.apache.wicket.request.Url) FileInputStream(java.io.FileInputStream) List(java.util.List) ArrayList(java.util.ArrayList) StringValue(org.apache.wicket.util.string.StringValue) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ValueMap(org.apache.wicket.util.value.ValueMap)

Example 10 with StringValue

use of org.apache.wicket.util.string.StringValue in project wicket by apache.

the class ServletWebRequest method generatePostParameters.

protected Map<String, List<StringValue>> generatePostParameters() {
    Map<String, List<StringValue>> postParameters = new HashMap<>();
    IRequestParameters queryParams = getQueryParameters();
    @SuppressWarnings("unchecked") Map<String, String[]> params = getContainerRequest().getParameterMap();
    for (Map.Entry<String, String[]> param : params.entrySet()) {
        final String name = param.getKey();
        final String[] values = param.getValue();
        if (name != null && values != null) {
            // build a mutable list of query params that have the same name as the post param
            List<StringValue> queryValues = queryParams.getParameterValues(name);
            if (queryValues == null) {
                queryValues = Collections.emptyList();
            } else {
                queryValues = new ArrayList<>(queryValues);
            }
            // the list that will contain accepted post param values
            List<StringValue> postValues = new ArrayList<>();
            for (String value : values) {
                StringValue val = StringValue.valueOf(value);
                if (queryValues.contains(val)) {
                    // if a query param with this value exists remove it and continue
                    queryValues.remove(val);
                } else {
                    // there is no query param with this value, assume post
                    postValues.add(val);
                }
            }
            if (!postValues.isEmpty()) {
                postParameters.put(name, postValues);
            }
        }
    }
    return postParameters;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) StringValue(org.apache.wicket.util.string.StringValue) HashMap(java.util.HashMap) Map(java.util.Map) IRequestParameters(org.apache.wicket.request.IRequestParameters)

Aggregations

StringValue (org.apache.wicket.util.string.StringValue)54 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)22 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 Test (org.junit.Test)7 Task (com.evolveum.midpoint.task.api.Task)6 Url (org.apache.wicket.request.Url)5 IOException (java.io.IOException)4 WebSession (org.apache.openmeetings.web.app.WebSession)4 RestartResponseException (org.apache.wicket.RestartResponseException)4 IRequestHandler (org.apache.wicket.request.IRequestHandler)3 AbstractResource (org.apache.wicket.request.resource.AbstractResource)3 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 ObjectViewDto (com.evolveum.midpoint.web.page.admin.dto.ObjectViewDto)2 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)2 Vertex (com.tinkerpop.blueprints.Vertex)2 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)2 Template (eu.esdihumboldt.hale.server.model.Template)2 User (eu.esdihumboldt.hale.server.model.User)2 NonUniqueResultException (eu.esdihumboldt.util.blueprints.entities.NonUniqueResultException)2