Package org.apache.sling.api.resource

Examples of org.apache.sling.api.resource.ModifiableValueMap


                    job.retry();
                    try {
                        final Resource jobResource = topicResource.getResourceResolver().getResource(job.getResourcePath());
                        // sanity check
                        if ( jobResource != null ) {
                            final ModifiableValueMap mvm = jobResource.adaptTo(ModifiableValueMap.class);
                            mvm.remove(Job.PROPERTY_JOB_STARTED_TIME);
                            mvm.put(Job.PROPERTY_JOB_RETRY_COUNT, job.getRetryCount());
                            jobResource.getResourceResolver().commit();
                        }
                    } catch ( final PersistenceException ignore) {
                        logger.error("Unable to update unfinished job " + job, ignore);
                    }
View Full Code Here


                Resource childResource = rr.create(testResource, "child1", new HashMap<String, Object>(){{
                    put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);
                }});
                rr.commit();

                ModifiableValueMap mvm = testResource.adaptTo(ModifiableValueMap.class);
                mvm.put("field1", "1");
                rr.commit();

                // /apps/validation/1/resource/child1 will miss its mandatory "hello" property
                Resource resourceChild = rr.create(testResource, "child1", new HashMap<String, Object>(){{
                    put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);
View Full Code Here

                    final VersioningConfiguration versioningConfiguration)
    throws RepositoryException {
        final String nodeType = getPrimaryType(reqProperties, path);
        if (nodeType != null) {
            final Resource rsrc = resolver.getResource(path);
            final ModifiableValueMap mvm = rsrc.adaptTo(ModifiableValueMap.class);
            if ( mvm != null ) {
                final Node node = rsrc.adaptTo(Node.class);
                final boolean wasVersionable = (node == null ? false : isVersionable(node));

                if ( node != null ) {
                    checkoutIfNecessary(node, changes, versioningConfiguration);
                    node.setPrimaryType(nodeType);
                } else {
                    mvm.put("jcr:primaryType", nodeType);
                }

                if ( node != null ) {
                    // this is a bit of a cheat; there isn't a formal checkout, but assigning
                    // the mix:versionable mixin does an implicit checkout
View Full Code Here

    throws RepositoryException {
        final String[] mixins = getMixinTypes(reqProperties, path);
        if (mixins != null) {

            final Resource rsrc = resolver.getResource(path);
            final ModifiableValueMap mvm = rsrc.adaptTo(ModifiableValueMap.class);
            if ( mvm != null ) {
                final Node node = rsrc.adaptTo(Node.class);

                final Set<String> newMixins = new HashSet<String>();
                newMixins.addAll(Arrays.asList(mixins));

                // clear existing mixins first
                if ( node != null ) {
                    checkoutIfNecessary(node, changes, versioningConfiguration);
                    for (NodeType mixin : node.getMixinNodeTypes()) {
                        String mixinName = mixin.getName();
                        if (!newMixins.remove(mixinName)) {
                            node.removeMixin(mixinName);
                        }
                    }

                    // add new mixins
                    for (String mixin : newMixins) {
                        node.addMixin(mixin);
                        // this is a bit of a cheat; there isn't a formal checkout, but assigning
                        // the mix:versionable mixin does an implicit checkout
                        if (mixin.equals("mix:versionable") &&
                                versioningConfiguration.isCheckinOnNewVersionableNode()) {
                            changes.add(Modification.onCheckout(path));
                        }
                    }
                } else {
                    mvm.put("jcr:mixinTypes", mixins);
                }

            }
        }
    }
View Full Code Here

            sb.append(ResourceHelper.filterName(info.getName()));
            final String path = sb.toString();

            final Resource eventResource = resolver.getResource(path);
            if ( eventResource != null ) {
                final ModifiableValueMap mvm = eventResource.adaptTo(ModifiableValueMap.class);
                if ( flag ) {
                    mvm.put(ResourceHelper.PROPERTY_SCHEDULE_SUSPENDED, Boolean.TRUE);
                } else {
                    mvm.remove(ResourceHelper.PROPERTY_SCHEDULE_SUSPENDED);
                }
                resolver.commit();
            }
        } catch (final PersistenceException pe) {
            // we ignore the exception if removing fails
View Full Code Here

    public boolean reschedule() {
        final ResourceResolver resolver = this.configuration.createResourceResolver();
        try {
            final Resource jobResource = resolver.getResource(job.getResourcePath());
            if ( jobResource != null ) {
                final ModifiableValueMap mvm = jobResource.adaptTo(ModifiableValueMap.class);
                mvm.put(Job.PROPERTY_JOB_RETRY_COUNT, job.getProperty(Job.PROPERTY_JOB_RETRY_COUNT));
                if ( job.getProperty(Job.PROPERTY_RESULT_MESSAGE) != null ) {
                    mvm.put(Job.PROPERTY_RESULT_MESSAGE, job.getProperty(Job.PROPERTY_RESULT_MESSAGE));
                }
                mvm.remove(Job.PROPERTY_JOB_STARTED_TIME);
                try {
                    resolver.commit();
                    return true;
                } catch ( final PersistenceException pe ) {
                    this.configuration.getMainLogger().debug("Unable to update reschedule properties for job " + job.getId(), pe);
View Full Code Here

        if ( propNames != null ) {
            final ResourceResolver resolver = this.configuration.createResourceResolver();
            try {
                final Resource jobResource = resolver.getResource(job.getResourcePath());
                if ( jobResource != null ) {
                    final ModifiableValueMap mvm = jobResource.adaptTo(ModifiableValueMap.class);
                    for(final String propName : propNames) {
                        final Object val = job.getProperty(propName);
                        if ( val != null ) {
                            if ( val.getClass().isEnum() ) {
                                mvm.put(propName, val.toString());
                            } else {
                                mvm.put(propName, val);
                            }
                        } else {
                            mvm.remove(propName);
                        }
                    }
                    resolver.commit();

                    return true;
View Full Code Here

    }
   
    @Test
    public void testStringToCalendarConversion() throws IOException {
        Resource resource1 = resourceResolver.getResource(testRoot.getPath() + "/node1");
        ModifiableValueMap modProps = resource1.adaptTo(ModifiableValueMap.class);
        modProps.put("dateISO8601String", ISO8601.format(CALENDAR_VALUE));
        resourceResolver.commit();
       
        resource1 = resourceResolver.getResource(testRoot.getPath() + "/node1");
        ValueMap props = ResourceUtil.getValueMap(resource1);
        assertEquals(CALENDAR_VALUE.getTime(), props.get("calendarProp", Calendar.class).getTime());
View Full Code Here

                                for (Status status : statuses) {
                                    tweetsList.add(processTweet(status));
                                }

                                if (tweetsList.size() > 0) {
                                    ModifiableValueMap map = twitterResource.adaptTo(ModifiableValueMap.class);
                                    map.put("tweets", tweetsList.toArray(new String[tweetsList.size()]));
                                    twitterResource.getResourceResolver().commit();

                                    handleReplication(pageManager, twitterResource);
                                }
                            }
View Full Code Here

                    // Some other resource
                    resource = resourceResolver.getResource(path);
                    log.trace("Candidate Resource for setting replicateBy is [ {} ]", resource.getPath());
                }

                final ModifiableValueMap mvm = resource.adaptTo(ModifiableValueMap.class);

                if (StringUtils.isNotBlank(mvm.get(ReplicationStatus.NODE_PROPERTY_LAST_REPLICATED_BY,
                        String.class))) {
                    mvm.put(ReplicationStatus.NODE_PROPERTY_LAST_REPLICATED_BY, replicatedBy);
                    resourceResolver.commit();
                    log.trace("Set replicateBy to [ {} ] on resource  [ {} ]", replicatedBy, resource.getPath());
                } else {
                    log.trace("Skipping; Resource does not have replicateBy property set  [ {} ]",
                            resource.getPath());
View Full Code Here

TOP

Related Classes of org.apache.sling.api.resource.ModifiableValueMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.