Changeset 598 for raptor-client


Ignore:
Timestamp:
03/26/11 18:01:37 (9 years ago)
Author:
philsmart
Message:
 
Location:
raptor-client/trunk
Files:
10 added
8 deleted
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • raptor-client/trunk/pom.xml

    r595 r598  
    3737            <version>1.6.1</version> 
    3838        </dependency> 
     39         
     40        <!-- Deep clone library --> 
     41                <dependency> 
     42                        <groupId>clonable</groupId> 
     43                        <artifactId>cloning</artifactId> 
     44                        <version>1.7</version> 
     45                </dependency> 
    3946 
    4047        <dependency> 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/AtrributeFilterEngine.java

    r595 r598  
    1919package uk.ac.cardiff.raptor.attribute.filtering; 
    2020 
     21import java.util.ArrayList; 
    2122import java.util.LinkedHashSet; 
    2223import java.util.List; 
     
    2627import org.slf4j.LoggerFactory; 
    2728 
     29import com.rits.cloning.Cloner; 
     30 
    2831import uk.ac.cardiff.model.Event; 
     32import uk.ac.cardiff.raptor.runtimeutils.ReflectionHelper; 
    2933 
    3034/** 
    3135 * @author philsmart 
    32  * 
     36 *  
    3337 */ 
    3438public class AtrributeFilterEngine { 
    3539 
    36     /* class logger. */ 
    37     private final Logger log = LoggerFactory.getLogger(AtrributeFilterEngine.class); 
     40        /* class logger. */ 
     41        private final Logger log = LoggerFactory.getLogger(AtrributeFilterEngine.class); 
    3842 
     43        /** 
     44         * Only runs against the deny rules, and only denies basic:ANY attributes, 
     45         * does not deny individual values. 
     46         *  
     47         * @param attributeFilterPolicy 
     48         * @param entries 
     49         * @return 
     50         */ 
     51        public List<Event> filter(AttributeFilterPolicy attributeFilterPolicy, List<Event> events) { 
     52                log.debug("Applying attribute filter policy {} to event set", attributeFilterPolicy.getPolicyName()); 
     53                List<Event> filteredEntries = clone(events); 
    3954 
    40     /** 
    41      * Only runs against the deny rules, and only denies basic:ANY attributes, does not 
    42      * deny individual values. 
    43      * 
    44      * @param attributeFilterPolicy 
    45      * @param entries 
    46      * @return 
    47      */ 
    48     public static List<Event> filter(AttributeFilterPolicy attributeFilterPolicy, List<Event> events){ 
    49         log.debug("Applying attribute filter policy {} to entry set",attributeFilterPolicy.getPolicyName()); 
    50         Set<Event> filteredEntries = clone(events); 
     55                for (Event entry : filteredEntries) { 
     56                        for (AttributeRule attributeRule : attributeFilterPolicy.getAttributeRules()) { 
     57                                filterAttributes(entry, attributeRule); 
     58                        } 
     59                } 
    5160 
    52         for (Event entry: filteredEntries){ 
    53             for (AttributeRule attributeRule : attributeFilterPolicy.getAttributeRules()){ 
    54                 filterAttributes(entry, attributeRule); 
    55             } 
     61                return filteredEntries; 
    5662        } 
    5763 
     64        /** 
     65         * Only process deny rules on the level of basic:ANY attributes. Hence will 
     66         * not deny individual values 
     67         *  
     68         * @param entry 
     69         * @param attributeRule 
     70         */ 
     71        private void filterAttributes(Event entry, AttributeRule attributeRule) { 
     72                String attributeID = attributeRule.getAttributeID(); 
     73                if (classHasAttribute(entry, attributeID)) { 
     74                        if (attributeRule.getDenyValueRule().isEnabled()) { 
     75                                nullAttribute(entry, attributeID); 
     76                        } 
     77                } else { 
    5878 
    59         return filteredEntries; 
    60     } 
    61  
    62     /** 
    63      * Only process deny rules on the level of basic:ANY attributes. Hence will not deny individual values 
    64      * @param entry 
    65      * @param attributeRule 
    66      */ 
    67     private static void filterAttributes(Event entry, AttributeRule attributeRule){ 
    68         String attributeID = attributeRule.getAttributeID(); 
    69         if (classHasAttribute(entry, attributeID)){ 
    70             if (attributeRule.getDenyValueRule().isEnabled()){ 
    71                 nullAttribute(entry, attributeID); 
    72             } 
    73         } 
    74         else{ 
     79                } 
    7580 
    7681        } 
    7782 
    78     } 
     83        private static void nullAttribute(Event event, String attributeID) { 
     84                ReflectionHelper.nullAttribute(event, attributeID); 
     85        } 
    7986 
    80     private static void nullAttribute(Event event, String attributeID){ 
    81         ReflectionHelper.nullAttribute(event, attributeID); 
    82     } 
     87        private static boolean classHasAttribute(Event entry, String attributeID) { 
     88                return ReflectionHelper.classHasAttribute(entry, attributeID); 
     89        } 
    8390 
    84     private static boolean classHasAttribute(Event entry, String attributeID){ 
    85         return ReflectionHelper.classHasAttribute(entry, attributeID); 
    86     } 
    87  
    88     private static Set<Event> clone(List<Event> events){ 
    89         Set<Event> clonedSet = new LinkedHashSet<Event>(); 
    90         Cloner cloner = new Cloner(); 
    91         for (Event entry: events){ 
    92             Event newEntry = cloner.deepClone(entry); 
    93             clonedSet.add(newEntry); 
     91        private static List<Event> clone(List<Event> events) { 
     92                List<Event> clonedSet = new ArrayList<Event>(); 
     93                Cloner cloner = new Cloner(); 
     94                for (Event entry : events) { 
     95                        Event newEntry = cloner.deepClone(entry); 
     96                        clonedSet.add(newEntry); 
     97                } 
     98                return clonedSet; 
    9499        } 
    95         return clonedSet; 
    96     } 
    97  
    98  
    99100 
    100101} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/registry/EventReleaseEngine.java

    r595 r598  
    2424import java.util.Set; 
    2525 
    26 import uk.ac.cardiff.raptor.raptorica.dao.external.AuthenticationInput; 
    27 import uk.ac.cardiff.raptor.raptorica.engine.sei.ServiceEndpointInterface; 
    28 import uk.ac.cardiff.raptor.raptorica.model.UAEntry; 
     26import uk.ac.cardiff.raptor.attribute.filtering.AtrributeFilterEngine; 
     27import uk.ac.cardiff.raptor.remoting.client.sei.ServiceEndpointInterface; 
    2928 
    3029import org.slf4j.Logger; 
     
    3332import uk.ac.cardiff.model.ClientMetadata; 
    3433import uk.ac.cardiff.model.Event; 
    35 import uk.ac.cardiff.model.ICAMetadata; 
    3634import uk.ac.cardiff.model.wsmodel.EventPushMessage; 
    37 import uk.ac.cardiff.model.wsmodel.ICAEntryPush; 
    38  
    3935 
    4036/** 
    4137 * @author philsmart 
    42  * 
     38 *  
    4339 */ 
    4440public class EventReleaseEngine { 
    4541 
    46     /** Class logger */ 
    47     private final Logger log = LoggerFactory.getLogger(EventReleaseEngine.class); 
     42        private AtrributeFilterEngine attributeFilterEngine; 
     43        private ServiceEndpointInterface serviceEndpointInterface; 
    4844 
    49     /** 
    50      * Performs the release of all events to all applicable endpoints defined in the endpoint registry. Endpoints are applicable 
    51      * to be sent to if they meet the push policy defined on them. Event attributes are also filtered according to the 
    52      * attribute filter policy defined per endpoint. 
    53      * @param authenticationModules 
    54      */ 
    55     public boolean release(EndpointRegistry endpointRegistry, List<Event> events, ClientMetadata clientMetadata) { 
    56         boolean releasedtoAll = true; 
    57         int releaseCount=0; 
    58         for (Endpoint endpoint : endpointRegistry.getEndpoints()){ 
    59             boolean shouldRelease = (endpoint.getPushPolicy().getPushOnOrAfterNoEntries() <= events.size()); 
    60             log.debug("Endpoint {}, should release {}",endpoint.getServiceEndpoint(),shouldRelease); 
    61             List<Event> filteredEntries = filterAttributes(endpoint, events); 
    62             EventPushMessage pushMessage = constructEventPush(clientMetadata, filteredEntries); 
    63             if (shouldRelease) { 
    64                 log.debug("Pushing {} entries to the Endpoint [{}]",filteredEntries.size(),endpoint.getServiceEndpoint()); 
    65                 boolean releaseSuccess = ServiceEndpointInterface.sendAuthentications(pushMessage, endpoint.getServiceEndpoint()); 
    66                 log.debug("Release to [{}] succeeded {}",endpoint.getServiceEndpoint(),releaseSuccess); 
    67                 if (releaseSuccess==false)  releasedtoAll =false; 
    68                 else releaseCount++; 
    69             } 
    70             else{ 
    71                 releasedtoAll=false; 
    72             } 
     45        /** Class logger */ 
     46        private final Logger log = LoggerFactory.getLogger(EventReleaseEngine.class); 
     47 
     48        /** 
     49         * Performs the release of all events to all applicable endpoints defined in 
     50         * the endpoint registry. Endpoints are applicable to be sent to if they 
     51         * meet the push policy defined on them. Event attributes are also filtered 
     52         * according to the attribute filter policy defined per endpoint. 
     53         *  
     54         * @param authenticationModules 
     55         */ 
     56        public boolean release(EndpointRegistry endpointRegistry, List<Event> events, ClientMetadata clientMetadata) { 
     57                boolean releasedtoAll = true; 
     58                int releaseCount = 0; 
     59                for (Endpoint endpoint : endpointRegistry.getEndpoints()) { 
     60                        boolean shouldRelease = (endpoint.getPushPolicy().getPushOnOrAfterNoEntries() <= events.size()); 
     61                        log.debug("Endpoint {}, should release {}", endpoint.getServiceEndpoint(), shouldRelease); 
     62                        List<Event> filteredEntries = filterAttributes(endpoint, events); 
     63                        EventPushMessage pushMessage = constructEventPush(clientMetadata, filteredEntries); 
     64                        if (shouldRelease) { 
     65                                log.debug("Pushing {} entries to the Endpoint [{}]", filteredEntries.size(),endpoint.getServiceEndpoint()); 
     66                                boolean releaseSuccess = serviceEndpointInterface.sendEvents(pushMessage,endpoint.getServiceEndpoint()); 
     67                                log.debug("Release to [{}] succeeded {}", endpoint.getServiceEndpoint(), releaseSuccess); 
     68                                if (releaseSuccess == false) 
     69                                        releasedtoAll = false; 
     70                                else 
     71                                        releaseCount++; 
     72                        } else { 
     73                                releasedtoAll = false; 
     74                        } 
     75 
     76                } 
     77                log.info("Released to {} listening Endpoints, out of a total of {}", releaseCount, endpointRegistry 
     78                                .getEndpoints().size()); 
     79 
     80                return releasedtoAll; 
    7381 
    7482        } 
    75         log.info("Released to {} listening Endpoints, out of a total of {}",releaseCount,endpointRegistry.getEndpoints().size()); 
    7683 
    77         return releasedtoAll; 
     84        /** 
     85         * Filters the attributes from each event being pushed to the input 
     86         * endpoint. If no filter policy has been defined, no work is done, and the 
     87         * input allEvents is returned without modification 
     88         *  
     89         * @param endpoint 
     90         * @param allEvents 
     91         * @return 
     92         */ 
     93        private List<Event> filterAttributes(Endpoint endpoint, List<Event> allEvents) { 
     94                if (endpoint.getAttributeFilterPolicy() == null) 
     95                        return allEvents; 
     96                return attributeFilterEngine.filter(endpoint.getAttributeFilterPolicy(), allEvents); 
     97        } 
    7898 
     99        /** 
     100         * Constructs an event push message, which encapsulates the events to send 
     101         *  
     102         * @param clientMetadata 
     103         * @param events 
     104         * @return 
     105         */ 
     106        private EventPushMessage constructEventPush(ClientMetadata clientMetadata, List<Event> events) { 
     107                EventPushMessage pushMessage = new EventPushMessage(); 
     108                pushMessage.setClientMetadata(clientMetadata); 
     109                pushMessage.setEvents(events); 
     110                pushMessage.setTimeOfPush(new Date(System.currentTimeMillis())); 
     111                return pushMessage; 
     112        } 
    79113 
    80     } 
     114        public void setAttributeFilterEngine(AtrributeFilterEngine attributeFilterEngine) { 
     115                this.attributeFilterEngine = attributeFilterEngine; 
     116        } 
    81117 
    82     /** 
    83      * Filters the attributes from each event being pushed to the input endpoint. 
    84      * If no filter policy has been defined, no work is done, and the input allEvents 
    85      * is returned without modification 
    86      * 
    87      * @param endpoint 
    88      * @param allEvents 
    89      * @return 
    90      */ 
    91     private List<Event> filterAttributes(Endpoint endpoint, List<Event> allEvents){ 
    92         if (endpoint.getAttributeFilterPolicy()==null) return allEvents; 
    93         return AtrributeFilterEngine.filter(endpoint.getAttributeFilterPolicy(), allEvents); 
    94     } 
    95  
    96     /** 
    97      * Constructs an event push message, which encapsulates the events to send 
    98      * 
    99      * @param clientMetadata 
    100      * @param events 
    101      * @return 
    102      */ 
    103     private EventPushMessage constructEventPush(ClientMetadata clientMetadata, List<Event> events){ 
    104         EventPushMessage pushMessage = new EventPushMessage(); 
    105         pushMessage.setClientMetadata(clientMetadata); 
    106         pushMessage.setEvents(events); 
    107         pushMessage.setTimeOfPush(new Date(System.currentTimeMillis())); 
    108         return pushMessage; 
    109     } 
     118        public AtrributeFilterEngine getAttributeFilterEngine() { 
     119                return attributeFilterEngine; 
     120        } 
    110121 
    111122} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/EventReleaseClient.java

    r595 r598  
    33 */ 
    44package uk.ac.cardiff.raptor.remoting.client; 
     5 
     6import java.util.List; 
     7 
     8import uk.ac.cardiff.model.ClientMetadata; 
     9import uk.ac.cardiff.model.Event; 
     10import uk.ac.cardiff.raptor.exceptions.ReleaseFailureException; 
    511 
    612/** 
     
    915 * 
    1016 */ 
    11 public interface CxfSoapClient { 
     17public interface EventReleaseClient { 
     18         
     19        public boolean release(List<Event> events, ClientMetadata clientMetadata) throws ReleaseFailureException; 
    1220 
    1321} 
Note: See TracChangeset for help on using the changeset viewer.