Search in sources :

Example 1 with ReplicationStatus

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

the class PageReplicationStatusModel method getReplicationStatus.

public String getReplicationStatus() {
    Session session = resource.getResourceResolver().adaptTo(Session.class);
    String path = resource.getPath();
    if (path.contains(JcrConstants.JCR_CONTENT)) {
        path = StringUtils.substringAfter(path, JcrConstants.JCR_CONTENT) + JcrConstants.JCR_CONTENT;
    } else {
        path += "/" + JcrConstants.JCR_CONTENT;
    }
    log.debug("Getting replication status for {}", path);
    ReplicationStatus status = replicator.getReplicationStatus(session, path);
    Status rStatus = Status.NOT_ACTIVATED;
    if (status != null) {
        if (status.isDeactivated()) {
            rStatus = Status.DEACTIVATED;
        } else if (status.isPending()) {
            rStatus = Status.IN_PROGRESS;
        } else if (status.isActivated()) {
            Calendar lastModified = getLastModified(resource.getResourceResolver(), path);
            if (lastModified != null && status.getLastPublished() != null && lastModified.after(status.getLastPublished())) {
                rStatus = Status.MODIFIED;
            } else {
                rStatus = Status.ACTIVATED;
            }
        }
    }
    log.debug("Retrieved replication status {}", rStatus);
    return rStatus.toString();
}
Also used : ReplicationStatus(com.day.cq.replication.ReplicationStatus) ReplicationStatus(com.day.cq.replication.ReplicationStatus) Calendar(java.util.Calendar) Session(javax.jcr.Session)

Aggregations

ReplicationStatus (com.day.cq.replication.ReplicationStatus)1 Calendar (java.util.Calendar)1 Session (javax.jcr.Session)1