mirror of
				https://github.com/Alfresco/alfresco-community-repo.git
				synced 2025-10-29 15:21:53 +00:00 
			
		
		
		
	125606 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2)
      125515 slanglois: MNT-16155 Update source headers - add new Copyrights for Java and JSP source files + automatic check in the build
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@125788 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
		
	
		
			
				
	
	
		
			207 lines
		
	
	
		
			6.9 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			207 lines
		
	
	
		
			6.9 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| /*
 | |
|  * #%L
 | |
|  * Alfresco Repository
 | |
|  * %%
 | |
|  * Copyright (C) 2005 - 2016 Alfresco Software Limited
 | |
|  * %%
 | |
|  * This file is part of the Alfresco software. 
 | |
|  * If the software was purchased under a paid Alfresco license, the terms of 
 | |
|  * the paid license agreement will prevail.  Otherwise, the software is 
 | |
|  * provided under the following open source license terms:
 | |
|  * 
 | |
|  * Alfresco is free software: you can redistribute it and/or modify
 | |
|  * it under the terms of the GNU Lesser General Public License as published by
 | |
|  * the Free Software Foundation, either version 3 of the License, or
 | |
|  * (at your option) any later version.
 | |
|  * 
 | |
|  * Alfresco 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 Lesser General Public License for more details.
 | |
|  * 
 | |
|  * You should have received a copy of the GNU Lesser General Public License
 | |
|  * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
 | |
|  * #L%
 | |
|  */
 | |
| 
 | |
| package org.alfresco.repo.publishing;
 | |
| 
 | |
| import java.util.Set;
 | |
| 
 | |
| import org.alfresco.repo.policy.BehaviourFilter;
 | |
| import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
 | |
| import org.alfresco.service.cmr.publishing.PublishingEvent;
 | |
| import org.alfresco.service.cmr.publishing.Status;
 | |
| import org.alfresco.service.cmr.publishing.StatusUpdate;
 | |
| import org.alfresco.service.cmr.publishing.channels.Channel;
 | |
| import org.alfresco.service.cmr.publishing.channels.ChannelService;
 | |
| import org.alfresco.service.cmr.repository.NodeRef;
 | |
| import org.alfresco.service.cmr.repository.NodeService;
 | |
| import org.alfresco.service.cmr.urlshortening.UrlShortener;
 | |
| import org.alfresco.service.transaction.TransactionService;
 | |
| import org.alfresco.util.ParameterCheck;
 | |
| import org.apache.commons.logging.Log;
 | |
| import org.apache.commons.logging.LogFactory;
 | |
| 
 | |
| /**
 | |
|  * @author Nick Smith
 | |
|  * @since 4.0
 | |
|  */
 | |
| public class PublishingEventProcessor
 | |
| {
 | |
|     private static final Log log = LogFactory.getLog(PublishingEventProcessor.class);
 | |
|     
 | |
|     private PublishingEventHelper eventHelper;
 | |
|     private ChannelService channelService;
 | |
|     private NodeService nodeService;
 | |
|     private BehaviourFilter behaviourFilter;
 | |
|     private UrlShortener urlShortener;
 | |
|     private TransactionService transactionService;
 | |
|     
 | |
|     public void processEventNode(NodeRef eventNode)
 | |
|     {
 | |
|         ParameterCheck.mandatory("eventNode", eventNode);
 | |
|         try
 | |
|         {
 | |
|             updateEventStatus(eventNode, Status.IN_PROGRESS);
 | |
|             final PublishingEvent event = eventHelper.getPublishingEvent(eventNode);
 | |
|             String channelName = event.getChannelId();
 | |
|             final ChannelImpl channel = (ChannelImpl) channelService.getChannelById(channelName);
 | |
|             if (channel == null)
 | |
|             {
 | |
|                 fail(eventNode, "No channel found");
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
 | |
|                 {
 | |
|                     @Override
 | |
|                     public Void execute() throws Throwable
 | |
|                     {
 | |
|                         try
 | |
|                         {
 | |
|                             behaviourFilter.disableBehaviour();
 | |
|                             channel.publishEvent(event);
 | |
|                             sendStatusUpdate(channel, event.getStatusUpdate());
 | |
|                         }
 | |
|                         finally
 | |
|                         {
 | |
|                             behaviourFilter.enableBehaviour();
 | |
|                         }
 | |
|                         return null;
 | |
|                     }
 | |
|                 }, false, true);
 | |
|                 updateEventStatus(eventNode, Status.COMPLETED);
 | |
|             }
 | |
|         }
 | |
|         catch (Exception e)
 | |
|         {
 | |
|             log.error("Caught exception while processing publishing event " + eventNode, e);
 | |
|             fail(eventNode, e.getMessage());
 | |
|         }
 | |
|      }
 | |
| 
 | |
|     public void sendStatusUpdate(Channel publishChannel, StatusUpdate update)
 | |
|     {
 | |
|         if (update == null)
 | |
|         {
 | |
|             return;
 | |
|         }
 | |
|         String message = update.getMessage();
 | |
|         String nodeUrl = getNodeUrl(publishChannel, update);
 | |
|         Set<String> channels = update.getChannelIds();
 | |
|         for (String channelId : channels)
 | |
|         {
 | |
|             Channel channel = channelService.getChannelById(channelId);
 | |
|             if (channel != null)
 | |
|             {
 | |
|                 channel.sendStatusUpdate(message, nodeUrl);
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @param publishChannel Channel
 | |
|      * @param update StatusUpdate
 | |
|      * @return String
 | |
|      */
 | |
|     private String getNodeUrl(Channel publishChannel, StatusUpdate update)
 | |
|     {
 | |
|         NodeRef node = update.getNodeToLinkTo();
 | |
|         String nodeUrl = null;
 | |
|         if (node!= null)
 | |
|         {
 | |
|             nodeUrl = publishChannel.getUrl(node);
 | |
|             if (nodeUrl != null)
 | |
|             {
 | |
|                 nodeUrl = " " + urlShortener.shortenUrl(nodeUrl);
 | |
|             }
 | |
|         }
 | |
|         return nodeUrl;
 | |
|     }
 | |
| 
 | |
|      public void fail(NodeRef eventNode, String msg)
 | |
|      {
 | |
|          log.error("Failed to process publishing event " + eventNode + ": " + msg);
 | |
|          updateEventStatus(eventNode, Status.FAILED);
 | |
|      }
 | |
| 
 | |
|      private void updateEventStatus(final NodeRef eventNode, final Status status)
 | |
|      {
 | |
|         transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
 | |
|         {
 | |
|             @Override
 | |
|             public Void execute() throws Throwable
 | |
|             {
 | |
|                 nodeService.setProperty(eventNode, PublishingModel.PROP_PUBLISHING_EVENT_STATUS, status.name());
 | |
|                 return null;
 | |
|             }
 | |
|         }, false, true);
 | |
|      }
 | |
| 
 | |
| 
 | |
|     /**
 | |
|      * @param channelService the channelService to set
 | |
|      */
 | |
|     public void setChannelService(ChannelService channelService)
 | |
|     {
 | |
|         this.channelService = channelService;
 | |
|     }
 | |
|  
 | |
|     /**
 | |
|      * @param eventHelper the Publishing Event Helper to set
 | |
|      */
 | |
|     public void setPublishingEventHelper(PublishingEventHelper eventHelper)
 | |
|     {
 | |
|         this.eventHelper = eventHelper;
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @param nodeService the nodeService to set
 | |
|      */
 | |
|     public void setNodeService(NodeService nodeService)
 | |
|     {
 | |
|         this.nodeService = nodeService;
 | |
|     }
 | |
|     
 | |
|     /**
 | |
|      * @param behaviourFilter the behaviourFilter to set
 | |
|      */
 | |
|     public void setBehaviourFilter(BehaviourFilter behaviourFilter)
 | |
|     {
 | |
|         this.behaviourFilter = behaviourFilter;
 | |
|     }
 | |
|     
 | |
|     /**
 | |
|      * @param urlShortener the urlShortener to set
 | |
|      */
 | |
|     public void setUrlShortener(UrlShortener urlShortener)
 | |
|     {
 | |
|         this.urlShortener = urlShortener;
 | |
|     }
 | |
| 
 | |
|     public void setTransactionService(TransactionService transactionService)
 | |
|     {
 | |
|         this.transactionService = transactionService;
 | |
|     }
 | |
| } |