我们希望实现一个流程,只要修改了该对象,就会创建页面或资产的版本。有没有办法在CQ5 ootb中设置它,还是需要自定义事件处理程序?
答案 0 :(得分:3)
您将会发生许多版本,因为每次在上下文中或通过对话框更改组件时都会抛出修改事件。修改时的推出也是一样的,给作者带来了很大的负担。
我也会考虑它将耗尽的磁盘空间。
您可以设置在修改时触发的工作流,然后使用CreateVersioningProcess步骤获取版本快照。
或者,如果您想根据时间或其他指标连接修改,那么我将采用自定义事件处理程序。
答案 1 :(得分:0)
我是AEM的新手,但在过去的25年里,我一直在IT行业工作。我的建议是在AEM中实现JCRlistener并在不同的系统(DBMS)上保留此信息(即,使用/不使用过滤修改节点)。
我能够非常轻松地将侦听器实现为OSGI包(尽管我遇到了bind和unbind方法的一些问题)。请在下面找到完整的(不包括持久性)和工作Java类:
package com.dlwconsulting.mywebsite;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.observation.Event;
import javax.jcr.observation.EventIterator;
import javax.jcr.observation.EventListener;
import javax.jcr.observation.ObservationManager;
import org.apache.felix.scr.annotations.*;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.api.SlingConstants;
import org.osgi.service.event.EventAdmin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Dictionary;
@Component(immediate=true, metatype=false, description = "Wim's JCRListener")
@Service
public class JCRListenerImplementator implements EventListener{
private static final Logger LOGGER = LoggerFactory.getLogger(JCRListenerImplementator.class);
private Session session;
private ObservationManager observationManager;
private static final String NODE_TREE = "/content/geometrixx-outdoors";
@Reference
private SlingRepository slingRepository;
// @Reference(policy = ReferencePolicy.STATIC, cardinality = ReferenceCardinality.MANDATORY_UNARY)
// private SlingRepository slingRepository;
/* public void bindEventAdmin (EventAdmin eventAdmin) {
this.eventAdmin = eventAdmin;
}
public void unbindEventAdmin() {
this.eventAdmin = null;
} */
public void bindSlingRepository (SlingRepository slingRepository) {
this.slingRepository = slingRepository;
}
public void unbindSlingRepository(SlingRepository slingRepository) {
this.slingRepository = null;
}
@Activate
public void start() {
LOGGER.info(">>>Delaware: started JCRListenerImplementator.activate()");
try {
LOGGER.info(">>>Delaware: Inside Try!");
session = slingRepository.loginAdministrative(null);
if (slingRepository.getDescriptor(SlingRepository.OPTION_OBSERVATION_SUPPORTED).equals("true")) {
observationManager = session.getWorkspace().getObservationManager();
// final String[] types = {"nt:unstructured","sling:OrderedFolder"};
// final String path = "/content/customer";
observationManager.addEventListener(this, Event.NODE_ADDED, NODE_TREE, true, null, null, false);
observationManager.addEventListener(this, Event.PROPERTY_CHANGED, NODE_TREE, true, null, null, false);
LOGGER.info(">>>Delaware : EventListeners added");
}
else {
LOGGER.info(">>>Delaware : No OBSERVATION SUPPORTED");
}
} catch (RepositoryException e) {
LOGGER.info("Exception in JCRListenerImplementator.activate()");
// throw new RepositoryException (e);
}
}
@Deactivate
public void stop() {
LOGGER.info(">>>Delaware: started JCRListenerImplementator.deactivate()");
try {
if(observationManager != null) {
observationManager.removeEventListener(this);
}
if (session != null) {
session.logout();
session = null;
}
} catch (RepositoryException e) {
LOGGER.info("Exception in JCRListenerImplementator.activate()");
// throw new RepositoryException (e);
}
}
// @Reference
// private EventAdmin eventAdmin;
/** The job topic for my events. */
public static final String JOB_TOPIC = "com/sling/eventing/WimsTopic";
// @Override
public void onEvent(EventIterator events) {
LOGGER.info(">>>Delaware: started JCRListenerImplementator.onEvent()");
while(events.hasNext()){
Event e = events.nextEvent();
try {
LOGGER.info(">>>Delaware: Event " + e.getPath() + " has occurred!");
LOGGER.info(">>>Delaware: >>>Event Identifier = " + e.getIdentifier());
LOGGER.info(">>>Delaware: >>>Event UserData = " + e.getUserData());
LOGGER.info(">>>Delaware: >>>Event date = " + e.getDate());
LOGGER.info(">>>Delaware: >>>Event type = " + e.getType());
Map<String, Object> m = e.getInfo();
for (Map.Entry<String, Object> entry : m.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
LOGGER.info(">>>Delaware: >>>Event Info Key = " + key);
LOGGER.info(">>>Delaware: >>>Event Info Value = " + value);
}
final Dictionary<String,Object> properties = new Hashtable();
properties.put("name", "my name");
properties.put("description", "my description");
properties.put("path", e.getPath());
} catch (RepositoryException e1) {
LOGGER.info("Exception in JCRListenerImplementator.onEvent()");
}
} // end while
} // end method
}