use of org.apache.sling.api.resource.ModifiableValueMap in project sling by apache.
the class RatingsServiceImpl method setRating.
/**
* @see org.apache.sling.sample.slingshot.ratings.RatingsService#setRating(org.apache.sling.api.resource.Resource, java.lang.String, int)
*/
@Override
public void setRating(final Resource resource, final String userId, final double rating) throws PersistenceException {
final String ratingsPath = getRatingsResourcePath(resource);
final Map<String, Object> props = new HashMap<String, Object>();
props.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, RESOURCETYPE_RATINGS);
final Resource ratingsResource = ResourceUtil.getOrCreateResource(resource.getResourceResolver(), ratingsPath, props, null, true);
final Resource ratingRsrc = resource.getResourceResolver().getResource(ratingsResource, userId);
if (ratingRsrc == null) {
props.clear();
props.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, RatingsUtil.RESOURCETYPE_RATING);
props.put(RatingsUtil.PROPERTY_RATING, String.valueOf(rating));
resource.getResourceResolver().create(ratingsResource, userId, props);
} else {
final ModifiableValueMap mvm = ratingRsrc.adaptTo(ModifiableValueMap.class);
mvm.put(RatingsUtil.PROPERTY_RATING, String.valueOf(rating));
}
resource.getResourceResolver().commit();
}
use of org.apache.sling.api.resource.ModifiableValueMap in project sling by apache.
the class StreamedChunk method processChunks.
/**
* process all chunks formed so far to create the final body.
* @param contentResource
* @param changes
* @throws PersistenceException
*/
private void processChunks(Resource contentResource, List<Modification> changes) throws PersistenceException {
if (completed) {
// have to commit before processing chunks.
contentResource.getResourceResolver().commit();
ModifiableValueMap vm = contentResource.adaptTo(ModifiableValueMap.class);
vm.put("jcr:data", getChunksInputStream(contentResource));
// might have to commit before removing chunk data, depending on if the InputStream still works.
removeChunkData(contentResource, vm);
}
}
use of org.apache.sling.api.resource.ModifiableValueMap in project sling by apache.
the class ValueMapTest method testModifiableValueMap.
@Test
public void testModifiableValueMap() throws IOException {
Resource resource1 = resourceResolver.getResource(testRoot.getPath() + "/node1");
ValueMap map = resource1.adaptTo(ModifiableValueMap.class);
assertTrue(map instanceof ValueMap && map instanceof ModifiableValueMap);
assertEquals("value1", map.get("prop1"));
map.put("prop1", "value2");
}
use of org.apache.sling.api.resource.ModifiableValueMap in project sling by apache.
the class ValueMapTest method testMap.
@SuppressWarnings("unchecked")
@Test
public void testMap() throws IOException {
Resource resource1 = resourceResolver.getResource(testRoot.getPath() + "/node1");
Map<String, Object> map = resource1.adaptTo(Map.class);
assertTrue(map instanceof ValueMap && !(map instanceof ModifiableValueMap));
assertEquals("value1", map.get("prop1"));
}
use of org.apache.sling.api.resource.ModifiableValueMap in project sling by apache.
the class ValueMapTest method testValueMap.
@Test
public void testValueMap() throws IOException {
Resource resource1 = resourceResolver.getResource(testRoot.getPath() + "/node1");
ValueMap map = resource1.adaptTo(ValueMap.class);
assertTrue(map instanceof ValueMap && !(map instanceof ModifiableValueMap));
assertEquals("value1", map.get("prop1"));
}
Aggregations