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;
}
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;
}
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);
}
}
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());
}
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());
}
Aggregations