Search in sources :

Example 1 with AgentIdFilter

use of com.day.cq.replication.AgentIdFilter in project acs-aem-commons by Adobe-Consulting-Services.

the class ReplicateVersionImpl method replicateResource.

private List<ReplicationResult> replicateResource(ResourceResolver resolver, List<Resource> resources, String[] agents, Date date) {
    List<ReplicationResult> results = new ArrayList<ReplicationResult>();
    ReplicationOptions opts = new ReplicationOptions();
    AgentIdFilter agentFilter = new AgentIdFilter(agents);
    opts.setFilter(agentFilter);
    Session session = resolver.adaptTo(Session.class);
    for (Resource resource : resources) {
        String path = resource.getPath();
        try {
            Version v = getAppropriateVersion(resource, date, session);
            if (v == null) {
                results.add(new ReplicationResult(path, Status.not_replicated));
                continue;
            }
            String versionName = v.getName();
            opts.setRevision(versionName);
            replicator.replicate(session, ReplicationActionType.ACTIVATE, path, opts);
            results.add(new ReplicationResult(path, Status.replicated, versionName));
        } catch (RepositoryException e) {
            results.add(new ReplicationResult(path, Status.error));
            log.error("Exception while replicating version of " + path, e);
        } catch (ReplicationException e) {
            results.add(new ReplicationResult(path, Status.error));
            log.error("Exception while replicating version of " + path, e);
        }
    }
    return results;
}
Also used : ReplicationResult(com.adobe.acs.commons.replication.ReplicationResult) ReplicationOptions(com.day.cq.replication.ReplicationOptions) AgentIdFilter(com.day.cq.replication.AgentIdFilter) Version(javax.jcr.version.Version) ReplicateVersion(com.adobe.acs.commons.replication.ReplicateVersion) ArrayList(java.util.ArrayList) Resource(org.apache.sling.api.resource.Resource) RepositoryException(javax.jcr.RepositoryException) ReplicationException(com.day.cq.replication.ReplicationException) Session(javax.jcr.Session)

Aggregations

ReplicateVersion (com.adobe.acs.commons.replication.ReplicateVersion)1 ReplicationResult (com.adobe.acs.commons.replication.ReplicationResult)1 AgentIdFilter (com.day.cq.replication.AgentIdFilter)1 ReplicationException (com.day.cq.replication.ReplicationException)1 ReplicationOptions (com.day.cq.replication.ReplicationOptions)1 ArrayList (java.util.ArrayList)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 Version (javax.jcr.version.Version)1 Resource (org.apache.sling.api.resource.Resource)1