/*
 * cilla - Blog Management System
 *
 * Copyright (C) 2014 Richard "Shred" Körber
 *   http://cilla.shredzone.org
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.shredzone.cilla.plugin.tumblr;

import javax.annotation.Resource;

import org.shredzone.cilla.core.event.EventType;
import org.shredzone.cilla.core.event.annotation.EventListener;
import org.shredzone.cilla.core.event.annotation.OnEvent;
import org.shredzone.cilla.core.model.Page;
import org.springframework.stereotype.Component;

/**
 * Handles page events for creating, updating and deleting Tumblr things.
 *
 * @author Richard "Shred" Körber
 */
@Component
@EventListener
public class TumblrEventListener {

    private @Resource TumblrPublicationService tumblrPublicationService;

    /**
     * Publish a Page to Tumblr.
     *
     * @param page {@link Page} that has been published
     */
    @OnEvent(EventType.PAGE_PUBLISH)
    public void onPagePublish(Page page) {
        if (!tumblrPublicationService.isRegistered(page)) {
            tumblrPublicationService.publish(page);
        }
    }

    /**
     * Update a Page at Tumblr.
     *
     * @param page {@link Page} that was updated
     */
    @OnEvent(EventType.PAGE_UPDATE)
    public void onPageUpdate(Page page) {
        if (page.isPublishedState() && page.getPublication() != null) {
            if (tumblrPublicationService.isRegistered(page)) {
                tumblrPublicationService.update(page);
            } else {
                tumblrPublicationService.publish(page);
            }
        }
    }

    /**
     * Remove a Page at Tumblr.
     *
     * @param page {@link Page} that has been unpublished or deleted
     */
    @OnEvent({ EventType.PAGE_UNPUBLISH, EventType.PAGE_DELETE })
    public void onPageUnpublish(Page page) {
        if (tumblrPublicationService.isRegistered(page)) {
            tumblrPublicationService.remove(page);
        }
    }

}

@@ -1580,16 +1580,37 @@
     if (
+page.isPromoted() && 
 !tumblrP
@@ -1976,36 +1976,55 @@
 ) %7B%0A            
-if (
+boolean isRegistered = 
 tumblrPublicatio
@@ -2042,32 +2042,84 @@
 Registered(page)
+;%0A            if (page.isPromoted() && !isRegistered
 ) %7B%0A            
@@ -2147,22 +2147,23 @@
 Service.
-update
+publish
 (page);%0A
@@ -2180,16 +2180,55 @@
   %7D else
+ if (page.isPromoted() && isRegistered)
  %7B%0A     
@@ -2255,39 +2255,154 @@
 licationService.
-publish
+update(page);%0A            %7D else if (!page.isPromoted() && isRegistered) %7B%0A                tumblrPublicationService.remove
 (page);%0A        

Use promote flag for promoting in Tumblr