Search in sources :

Example 36 with StringValue

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

the class GroupResource method newResourceResponse.

@Override
protected ResourceResponse newResourceResponse(final Attributes attributes) {
    LOG.debug("Search all available groups");
    ResourceResponse response = new ResourceResponse();
    response.setContentType(MediaType.APPLICATION_JSON);
    try {
        HttpServletRequest request = (HttpServletRequest) attributes.getRequest().getContainerRequest();
        if (!xsrfCheck(request)) {
            LOG.error("XSRF TOKEN does not match");
            response.setError(Response.Status.BAD_REQUEST.getStatusCode(), "XSRF TOKEN does not match");
            return response;
        }
        String realm = URLDecoder.decode(attributes.getParameters().get("realm").toString(SyncopeConstants.ROOT_REALM), "UTF-8");
        StringValue term = attributes.getParameters().get("term");
        final GroupResponse groupResponse = new GroupResponse();
        final int totGroups = SyncopeEnduserSession.get().getService(SyncopeService.class).numbers().getTotalGroups();
        final List<GroupTO> groupTOs = SyncopeEnduserSession.get().getService(SyncopeService.class).searchAssignableGroups(realm, term.isNull() || term.isEmpty() ? null : URLDecoder.decode(term.toString(), "UTF-8"), 1, 30).getResult();
        groupResponse.setTotGroups(totGroups);
        groupResponse.setGroupTOs(groupTOs.stream().collect(Collectors.toMap(GroupTO::getKey, GroupTO::getName)));
        response.setTextEncoding(StandardCharsets.UTF_8.name());
        response.setWriteCallback(new AbstractResource.WriteCallback() {

            @Override
            public void writeData(final Attributes attributes) throws IOException {
                attributes.getResponse().write(MAPPER.writeValueAsString(groupResponse));
            }
        });
        response.setStatusCode(Response.Status.OK.getStatusCode());
    } catch (Exception e) {
        LOG.error("Error retrieving available groups", e);
        response.setError(Response.Status.BAD_REQUEST.getStatusCode(), new StringBuilder().append("ErrorMessage{{ ").append(e.getMessage()).append(" }}").toString());
    }
    return response;
}
Also used : AbstractResource(org.apache.wicket.request.resource.AbstractResource) IOException(java.io.IOException) IOException(java.io.IOException) GroupTO(org.apache.syncope.common.lib.to.GroupTO) HttpServletRequest(javax.servlet.http.HttpServletRequest) StringValue(org.apache.wicket.util.string.StringValue)

Example 37 with StringValue

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

the class FormTester method addFormComponentValue.

/**
 * Adds an additional <code>FormComponent</code>'s value into request parameter -- this method
 * retains existing parameters but removes any duplicate parameters.
 *
 * @param formComponent
 *            a <code>FormComponent</code>
 * @param value
 *            a value to add
 * @return This
 */
private FormTester addFormComponentValue(FormComponent<?> formComponent, String value) {
    if (parameterExist(formComponent)) {
        List<StringValue> values = tester.getRequest().getPostParameters().getParameterValues(formComponent.getInputName());
        // remove duplicated
        HashSet<String> all = new HashSet<String>();
        for (StringValue val : values) {
            all.add(val.toString());
        }
        all.add(value);
        values = new ArrayList<StringValue>();
        for (String val : all) {
            values.add(StringValue.valueOf(val));
        }
        tester.getRequest().getPostParameters().setParameterValues(formComponent.getInputName(), values);
    } else {
        setFormComponentValue(formComponent, value);
    }
    return this;
}
Also used : StringValue(org.apache.wicket.util.string.StringValue) HashSet(java.util.HashSet)

Example 38 with StringValue

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

the class QueryStringWithVersionResourceCachingStrategy method undecorateUrl.

@Override
public void undecorateUrl(ResourceUrl url) {
    final INamedParameters parameters = url.getParameters();
    if (parameters != null) {
        // store the version in the request cycle
        StringValue versionValue = parameters.get(versionParameter);
        RequestCycle requestCycle = RequestCycle.get();
        if (versionValue.isEmpty() == false && requestCycle != null) {
            requestCycle.setMetaData(URL_VERSION, versionValue.toString());
        }
        // undecorate
        parameters.remove(versionParameter);
    }
}
Also used : INamedParameters(org.apache.wicket.request.mapper.parameter.INamedParameters) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) StringValue(org.apache.wicket.util.string.StringValue)

Example 39 with StringValue

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

the class ResourceMapperTest method validPathWithParams.

/**
 * testValidPathWithParams()
 */
@Test
public void validPathWithParams() {
    Request request = createRequest("test/resource/1/fred");
    IRequestHandler requestHandler = mapper.mapRequest(request);
    assertNotNull(requestHandler);
    assertEquals(ResourceReferenceRequestHandler.class, requestHandler.getClass());
    assertEquals(request.getUrl(), mapper.mapHandler(requestHandler));
    tester.processRequest(requestHandler);
    PageParameters params = resource.pageParameters;
    assertNotNull(params);
    assertEquals(0, params.getAllNamed().size());
    assertEquals(2, params.getIndexedCount());
    StringValue paramId = params.get(0);
    assertNotNull(paramId);
    assertEquals(1, paramId.toInt());
    StringValue paramName = params.get(1);
    assertNotNull(paramName);
    assertEquals("fred", paramName.toString());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) StringValue(org.apache.wicket.util.string.StringValue) Test(org.junit.Test)

Example 40 with StringValue

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

the class ResourceMapperTest method validPathWithParamsAndQueryPath.

/**
 * testValidPathWithParamsAndQueryPath()
 */
@Test
public void validPathWithParamsAndQueryPath() {
    Request request = createRequest("test/resource/1/fred?foo=bar&foo=baz&value=12");
    IRequestHandler requestHandler = mapper.mapRequest(request);
    assertNotNull(requestHandler);
    assertEquals(ResourceReferenceRequestHandler.class, requestHandler.getClass());
    assertEquals(request.getUrl(), mapper.mapHandler(requestHandler));
    tester.processRequest(requestHandler);
    PageParameters params = resource.pageParameters;
    assertNotNull(params);
    assertEquals(3, params.getAllNamed().size());
    assertEquals(2, params.getIndexedCount());
    StringValue paramId = params.get(0);
    assertNotNull(paramId);
    assertEquals(1, paramId.toInt());
    StringValue paramName = params.get(1);
    assertNotNull(paramName);
    assertEquals("fred", paramName.toString());
    List<StringValue> foo = params.getValues("foo");
    assertNotNull(foo.size() == 2);
    assertEquals("bar", foo.get(0).toString(""));
    assertEquals("baz", foo.get(1).toString(""));
    StringValue paramValue = params.get("value");
    assertEquals(12, paramValue.toInt());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) StringValue(org.apache.wicket.util.string.StringValue) Test(org.junit.Test)

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