Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)

82370: Merged WAT2 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud)
      76476: Removing alfresco-events from the core product in favour of an org.alfresco.services component


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@83214 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Erik Winlof
2014-09-04 06:49:17 +00:00
parent 214e1ea9d8
commit 6575029ee5
5 changed files with 49 additions and 249 deletions

View File

@@ -1,88 +0,0 @@
/*
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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/>.
*/
package org.alfresco.repo.events;
import org.alfresco.events.types.BrowserEvent;
import org.alfresco.events.types.Event;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* An abstract implementation of some of the EventPublisher functionality.
*
* @author Gethin James
* @since 5.0
*/
public abstract class AbstractEventPublisher implements EventPublisher
{
@Override
public void publishBrowserEvent(final WebScriptRequest req, final String siteId, final String component, final String action, final String attributes)
{
publishEvent(new EventPreparator(){
@Override
public Event prepareEvent(String user, String networkId, String transactionId)
{
String agent = req.getHeader("user-agent");
return new BrowserEvent(user, networkId, transactionId, siteId, component, action, agent, attributes);
}
});
}
@Override
public void publishEvent(EventPreparator prep)
{
ThreadInfo info = getThreadInfo();
Event event = prep.prepareEvent(info.user, info.network, info.transaction);
publishEvent(event);
}
/**
* Gets userful information from the current thread for use when creating an event
* @return ThreadInfo
*/
protected ThreadInfo getThreadInfo()
{
return new ThreadInfo(
AuthenticationUtil.getFullyAuthenticatedUser(),
AlfrescoTransactionSupport.getTransactionId(),
TenantUtil.getCurrentDomain());
}
/**
* Basic information from a thread
*
*/
public static class ThreadInfo {
public final String user;
public final String transaction;
public final String network;
public ThreadInfo(String user, String transaction, String network)
{
super();
this.user = user;
this.transaction = transaction;
this.network = network;
}
}
}

View File

@@ -1,42 +0,0 @@
/*
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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/>.
*/
package org.alfresco.repo.events;
import org.alfresco.events.types.Event;
/**
* Creates and prepares event information.
*
* The primary reason for this interface is to allow for deferred creation
* of the Event. If a NoOpEventPublisher is being used then the prepareEvent()
* method will never get called.
*
* As of Java 8 a Lambda expression could be used as the implementation of
* this FunctionalInterface
*
* @author Gethin James
* @since 5.0
**/
//@FunctionalInterface
public interface EventPreparator
{
public Event prepareEvent(String user, String networkId, String transactionId);
}

View File

@@ -1,58 +0,0 @@
/*
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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/>.
*/
package org.alfresco.repo.events;
import org.alfresco.events.types.BrowserEvent;
import org.alfresco.events.types.Event;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* EventPublisher can be used to broadcast events.
*
* @author Gethin James
* @since 5.0
*/
public interface EventPublisher
{
//TODO AbstractEventsService should probably implement this interface
/**
* Publish the event
* @param event Event
*/
public void publishEvent(Event event);
/**
* A special type of Event that occurs in a web browser
* @see BrowserEvent
* @param req - WebScriptRequest
* @param siteId - optional site id
* @param component - page eg. "documentdetails"
* @param action - eg. "view"
* @param attributes - optional additional attributes as a json map eg. {"liked":"true"}
*/
public void publishBrowserEvent(WebScriptRequest req, String siteId, String component, String action, String attributes);
/**
* Publish the event using an EventPreparator
* @param prep EventPreparator
*/
public void publishEvent(EventPreparator prep);
}

View File

@@ -1,43 +0,0 @@
/*
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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/>.
*/
package org.alfresco.repo.events;
import org.alfresco.events.types.Event;
/**
* An implementation of EventPublisher that does nothing.
*
* @author Gethin James
* @since 5.0
*/
public class NoOpEventPublisher extends AbstractEventPublisher implements EventPublisher {
@Override
public void publishEvent(Event event)
{
//Do nothing
}
@Override
public void publishEvent(EventPreparator prep)
{
//Do nothing
}
}

View File

@@ -18,34 +18,30 @@
*/ */
package org.alfresco.repo.events; package org.alfresco.repo.events;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.SimpleFormatter;
import org.alfresco.events.types.BrowserEvent;
import org.alfresco.events.types.Event; import org.alfresco.events.types.Event;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean; import org.springframework.extensions.webscripts.WebScriptRequest;
/** /**
* An implementation of EventPublisher that is used for testing * An implementation of EventPublisher that is used for testing
* Uses a java.util.logging.FileHandler for logging Events to a file.
* It also uses the standard log4j logging for Alfresco.
* *
* @author Gethin James * @author Gethin James
* @since 5.0 * @since 5.0
*/ */
public class EventPublisherForTestingOnly extends AbstractEventPublisher implements EventPublisher, InitializingBean public class EventPublisherForTestingOnly implements EventPublisher
{ {
private static final Logger logger = LoggerFactory.getLogger(EventPublisherForTestingOnly.class); private static final Logger logger = LoggerFactory.getLogger(EventPublisherForTestingOnly.class);
Queue<Event> queue = new ConcurrentLinkedQueue<Event>(); Queue<Event> queue = new ConcurrentLinkedQueue<Event>();
FileHandler fileHandler;
@Override @Override
public void publishEvent(Event event) public void publishEvent(Event event)
@@ -63,13 +59,26 @@ public class EventPublisherForTestingOnly extends AbstractEventPublisher impleme
log("Event published: [" + event + "]"); log("Event published: [" + event + "]");
} }
//
// @Override
// public void publishBrowserEvent(final WebScriptRequest req, final String siteId, final String component, final String action, final String attributes)
// {
// publishEvent(new EventPreparator(){
// @Override
// public Event prepareEvent(String user, String networkId, String transactionId)
// {
// String agent = req.getHeader("user-agent");
// return new BrowserEvent(user, networkId, transactionId, siteId, component, action, agent, attributes);
// }
// });
// }
private void log (String logMessage) private void log (String logMessage)
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug(logMessage); logger.debug(logMessage);
} }
fileHandler.publish(new LogRecord(Level.INFO, logMessage));
} }
public Queue<Event> getQueue() public Queue<Event> getQueue()
@@ -90,14 +99,36 @@ public class EventPublisherForTestingOnly extends AbstractEventPublisher impleme
} }
return (List<T>) toReturn; return (List<T>) toReturn;
} }
@Override /**
public void afterPropertiesSet() throws Exception * Gets userful information from the current thread for use when creating an event
* @return ThreadInfo
*/
protected ThreadInfo getThreadInfo()
{ {
File eventLog = new File("alfresco-events.log"); return new ThreadInfo(
fileHandler = new FileHandler(eventLog.getAbsolutePath(), true); AuthenticationUtil.getFullyAuthenticatedUser(),
fileHandler.setLevel(Level.INFO); AlfrescoTransactionSupport.getTransactionId(),
fileHandler.setFormatter(new SimpleFormatter()); TenantUtil.getCurrentDomain());
}
/**
* Basic information from a thread
*
*/
public static class ThreadInfo {
public final String user;
public final String transaction;
public final String network;
public ThreadInfo(String user, String transaction, String network)
{
super();
this.user = user;
this.transaction = transaction;
this.network = network;
}
} }
} }