CQ5 modify event fired on page delete - aem

I'm trying to use CQ5 workflow to control my resources (page in particular).
I want to start different scripts on different events (Add/Delete/Modify). I have registered a launcher on each event.
When I delete a page anyway both the delete and modify events get fired and so both the script run. I can't understand how to exclude the modify event on delete.
Thanks for any advice

When deleting a page, a version of the page is created before it is actually deleted. Which means it would actually fire a PageModification Event with ModificationType as VERSION_CREATED.
You can verify the same using the following Sample EventHandler which would just log the PageModifications.
#Component
#Service
#Property(name="event.topics", value=PageEvent.EVENT_TOPIC)
public class MyPageEventHandler implements EventHandler {
private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
#Override
public void handleEvent(Event event) {
PageEvent pgEvent = PageEvent.fromEvent(event);
Iterator<PageModification> modifications = pgEvent.getModifications();
while(modifications.hasNext()) {
log.info("Page Modifications are {}", modifications.next().getType());
}
}
}

Related

Quartz: Show list of completed task

I don't know if this is the best place to ask, but is it possible to query Quartz completed jobs ?
I can't find a solution, I already visited quartz website and googled it.
If you are looking for information on historical run like start, end time (duration), params with which it was invoked you need to create your own table to persist those information.
The way i have done this in the past is
Created a new JOB_LOG table
Created a Custom Quartz Job Listener by extending JobListenerSupport http://www.quartz-scheduler.org/api/2.1.7/org/quartz/listeners/JobListenerSupport.html
Depending on your requirement add your persistence logic to
#Override
public void jobToBeExecuted(JobExecutionContext context) {
//insert here
}
#Override
public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {
//insert here
}

How to distinguish whether a page is published first time or multiple times in publish environment of Adobe CQ5

I need to display labels "New" and "Updated" besides the links displayed on a page on my website.
For this I applied a logic of checking number of versions. If number of versions are more than 2 I displayed "updated" else i displayed "New". I am able to achieve it in the Author environment.
But in Publish environment, number of versions created for a page, even though the page is modified and republished, are one only. So how can i identify that whether the page is published first time or it has been published multiple times.
One suggestion to this is to implement you own servlet/listener that listens to the replication events. Look at the EventHandler and JobProcessor interfaces. This servlet could then for example set a property value on the component instance so that the component could be displayed different the first time. It could just be a small counter variable that keeps track of how many times the actualy thing has been published or some more fancy logic there :)
//imports
#Service...
#Component...
#Property(name = "event.topics", value = ReplicationAction.EVENT_TOPIC)
public class MyCustomEventHandler implements EventHandler, JobProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(MyCustomEventHandler.class);
#Override
public void handleEvent(Event event) {
LOGGER.info("Handling an event of some kind !!");
process (event);
}
#Override
public boolean process(Event event) {
LOGGER.info("Processing an event !!");
ReplicationAction action = ReplicationAction.fromEvent(event);
if (action.getType().equals(ReplicationActionType.ACTIVATE)) {
LOGGER.info("Processing an activation job, this is just what we are looking for !!!!!");
//Logic for fetching/setting the properties you want from the component you want
//goes here. Here you can make use of the action.getPath(); to get hold of the containing page
//and then later on any specific components...
}
return true;
}
}
To see my original answer head over to: http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.html/forum__kbyb-i_need_to_displayla.html

Handle Window close event

I'm trying to handle the event when the close button of a Window is clicked:
// View Code
#Override
public void attachWindowListener(WindowListener listener) {
window.addWindowListener(listener);
}
// Presenter code
view.attachWindowListener(new WindowListener(){
public void windowHide(WindowEvent we) {
GWT.log("Window Event - Processing fields");
processFields();
}
});
However, the windowHide function seems to be not executed since I can't see the log I placed there.
How to properly handle that event?
How about
Window.addCloseHandler(
new CloseHandler<Window>()
{
public void onClose( CloseEvent<Window> windowCloseEvent )
{
// Do your worst here
}
} );
I usually put this in onModuleLoad() in my EntryPoint class.
Cheers,
Based on the information provided I would guess that either a.) the events you think are firing do not fire for the Window component (even if it seems like they should) or b.) the events are firing but in a different order than you expect.
For example, it's possible that a BrowserEvent or some other event is firing first as the window is being closed and the Window object's WindowEvent never fires. According to the API docs for GXT 2.x, the WindowEvent will fire on hide and deactivate but it does not specify that it fires on close. The GXT 3.0.x API doc is less clear on this point but I would assume the same behavior. Unfortunately Sencha does not provide good documentation on what events fire for a given component and in what order.
With that said, I have had some luck working through similar issues to this by using a debug class which outputs all the events on a component to which it is attached. This may shed some light on which events are firing and their order of execution, and you may find an optimal event to which you can attach your processFields() method.
For a good example of a debugger class, see this answer from a related post: https://stackoverflow.com/a/2891746/460638. It also includes an example of how to attach the debugger to your component.
API Doc for Window, GXT 2.x: http://dev.sencha.com/deploy/gxt-2.2.5/docs/api/com/extjs/gxt/ui/client/widget/Window.html
API Doc for Window, GXT 3.0.x: http://dev.sencha.com/deploy/gxt-3.0.0/javadoc/gxt/com/sencha/gxt/widget/core/client/Window.html
This worked:
window.addListener(Events.Hide, new Listener<ComponentEvent>() {
#Override
public void handleEvent(ComponentEvent be) {
// Do stuff
}
});

UiHandler doesn't work with SuggestBox SuggestionEvent

I am using a SuggestBox and trying to capture the SuggestionEvent that is fired when the user selects a Suggestion. I can do this with normal event handlers easily enough:
itemInputBox.addEventHandler(new SuggestionHandler() {
#Override
public void onSuggestionSelect(SuggestionEvent event) {
Window.alert(event.getSelectedSuggestion().getReplacementString());
}
});
That works fine, event fires with the correct replacement string. However, I like to use UiHandler whenever possible due to how much cleaner the code is. So I've tried the following:
#UiHandler("itemInputBox")
void onSuggestionSelect(SuggestionEvent event) {
Window.alert(event.getSelectedSuggestion().getReplacementString());
}
But this results in the following errors:
[WARN] [jsonp] - Method 'getAssociatedType()' could not be found in the event 'SuggestionEvent'.
[ERROR] [jsonp] - Parameter 'SuggestionEvent' is not an event (subclass of GwtEvent).
I have a different UiHandler working correctly on the same SuggestBox so I am kind of confused where I'm going wrong:
#UiHandler("itemInputBox")
void onKeyUp(KeyUpEvent event) {
Window.alert("Key up event firing.");
}
I don't understand why one UiHandler fires correctly, while the other results in a error.
SuggestionEvent does not extend GwtEvent instead it extends java.util.EventObject.
This is why it will not work with UiBinder. I will bring this up on the GWT contributer list to see if there is a specific reason for this. Right now I am just guessing that it was forgotten when moving to the new event system.

GWT How discard changes on a Editor

I there a way of Editor discards changes made on its properties? This on client side. No persitence.
I have:
public class ClaseEditor extends PopupPanel implements Editor<ClaseProxy> {
#UiField ValidatedTextBox tema;
#UiField ValidatedTextBox catedratico;
}
I use this editor on a ListEditor as u know there are a list of editors in your
ListEditor<ClaseProxy, ClaseEditor>
If user create one, its okay, then if user edit it. i have a save or cancel options, i save ok, just hide the editor and changes made are ok.
But in user clicks Cancel and if there was some changes on the properties the editor flush(lazely) that changes to the proxy.
Yes i can store the start value on a string then restore with setValue() on the texboxes. But there is some other way (Editor API) that prevents this?
Thank you
If you are using a SimpleBeanEditorDriver, you can do a new call on the edit method, without calling flush first.
The SimpleBeanEditorDriver class reads from the bean into the editors on edit, and from the editors into the bean on flush.
If you don't want to revert all the editors, but only one of them, remember to call flush on every accepted editor change, in order to be able to restore to the last flush point. Note that a flush call is local and doesn't necessarily have to correspond to a call to the persisting layer.
Example code
private Bean currentObject;
/**
* Start editing the given object.
*/
public void edit(Bean object) {
this.currentObject = object;
this.driver.edit(object);
}
/**
* Call this every time an editor is in a consistent state.
* (e.g. onBlur event if validation succeeds)
*/
private void save() {
this.driver.flush(); // saves editors' state into currentObject
}
/**
* Call this to cancel changes on all editing editors.
* (e.g. onBlur event if validation fails)
*/
private void revert() {
this.driver.edit(currentObject); // reloads currentObject into editors
}
/**
* Stores all pending changes to the server.
* Remember to validate all editors.
*/
public void commit() {
Bean object = this.driver.flush();
Server.persist(object);
}
Yes. On the cancel button, do a fire() without building any request. What the editor does never effects the original proxy, it is immutable. The flush only gives you a copy (unless you are using the RequestFactoryEditorDriver then it returns the context you sent into it with the driver.edit(proxy,ctx) . The fire() without a request clears the edit proxy copy if the user wants to edit again it won't get an error that it is already being editted.