use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class RedirectServletTest method assertStatus.
private static void assertStatus(final int expectedStatus, final int testStatus) {
final ValueMap valueMap;
if (testStatus == -2) {
valueMap = null;
} else if (testStatus == -1) {
valueMap = new ValueMapDecorator(new HashMap<String, Object>());
} else {
valueMap = new ValueMapDecorator(Collections.singletonMap(RedirectServlet.STATUS_PROP, (Object) testStatus));
}
final int actualStatus = RedirectServlet.getStatus(valueMap);
assertEquals(expectedStatus, actualStatus);
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class SuperimposingManagerImplTest method prepareSuperimposingResource.
private Resource prepareSuperimposingResource(String superimposedPath, String sourcePath, boolean registerParent, boolean overlayable) {
Resource resource = mock(Resource.class);
when(resource.getPath()).thenReturn(superimposedPath);
ValueMap props = new ValueMapDecorator(new HashMap<String, Object>());
props.put(PROP_SUPERIMPOSE_SOURCE_PATH, sourcePath);
props.put(PROP_SUPERIMPOSE_REGISTER_PARENT, registerParent);
props.put(PROP_SUPERIMPOSE_OVERLAYABLE, overlayable);
when(resource.adaptTo(ValueMap.class)).thenReturn(props);
when(resourceResolver.getResource(superimposedPath)).thenReturn(resource);
return resource;
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class FormServlet method doPost.
@Override
protected void doPost(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response) throws ServletException, IOException {
final Map<String, Object> base = new LinkedHashMap<>();
final ValueMapDecorator parameters = new ValueMapDecorator(base);
final Enumeration<String> names = request.getParameterNames();
while (names.hasMoreElements()) {
final String name = names.nextElement();
parameters.put(name, request.getRequestParameter(name));
}
logger.debug("parameters: {}", parameters);
final String formType = request.getParameter("formType");
logger.debug("form type is '{}'", formType);
final Form form = FormFactory.build(formType, parameters);
if (form == null) {
fail(null, 400, request, response);
return;
}
final String resourcePath = request.getRequestPathInfo().getResourcePath();
final ValidationModel validationModel = validationService.getValidationModel(form.getResourceType(), resourcePath, false);
if (validationModel == null) {
logger.error("no validation model found");
fail(form, 500, request, response);
return;
}
final ValidationResult validationResult = validationService.validate(parameters, validationModel);
form.setValidationResult(validationResult);
if (!validationResult.isValid()) {
logger.debug("validation result not valid");
fail(form, 400, request, response);
return;
}
// render form with message template
// TODO
final String template = "/apps/fling/messaging/form/comment.txt";
final Map<String, Object> variables = Collections.singletonMap("form", form);
final String message;
try (final ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(null)) {
final IContext context = new DefaultSlingContext(resourceResolver, Locale.ENGLISH, variables);
logger.debug("rendering message template '{}' with variables: {}", template, variables);
message = templateEngine.process(template, context);
} catch (Exception e) {
// TODO
// TODO
logger.error("sending message failed: {}", e.getMessage(), e);
fail(form, 500, request, response);
return;
}
logger.debug("message: '{}'", message);
try {
final CompletableFuture<Result> future = messageService.send(message, recipient);
future.get(1, TimeUnit.SECONDS);
logger.debug("comment [{}] form sent to {}", message, recipient);
} catch (Exception e) {
logger.error("sending message failed: {}", e.getMessage(), e);
fail(form, 500, request, response);
return;
}
succeed(form, request, response);
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class MergedResourceTest method testResourceTypeByValueMap.
@Test
public void testResourceTypeByValueMap() throws Exception {
final ValueMap vm1 = new ValueMapDecorator(Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object) "vma"));
final MockResource r1 = new MockResource("/a", vm1, null);
final ValueMap vm2 = new ValueMapDecorator(Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object) "vmb"));
final MockResource r2 = new MockResource("/b", vm2, null);
final ValueMap vm3 = new ValueMapDecorator(Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object) "vmc"));
final MockResource r3 = new MockResource("/c", vm3, null);
final List<Resource> resources = new ArrayList<Resource>();
resources.add(r1);
resources.add(r2);
resources.add(r3);
final List<ValueMap> valueMaps = new ArrayList<ValueMap>();
valueMaps.add(vm1);
valueMaps.add(vm2);
valueMaps.add(vm3);
final MergedResource mr = new MergedResource(null, "/a", "a", resources, valueMaps);
assertEquals("vmc", mr.getResourceType());
assertNull(mr.getResourceSuperType());
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class TextValueDataResourceSource method initValueMap.
private void initValueMap() {
valueMap = new ValueMapDecorator(new HashMap<String, Object>());
valueMap.put(PN_VALUE, getValue());
valueMap.put(PN_TEXT, getText());
}
Aggregations