Changeset 802


Ignore:
Timestamp:
05/13/11 18:58:07 (8 years ago)
Author:
philsmart
Message:
 
Location:
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor
Files:
1 added
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/attribute/filtering/AttrributeFilterEngine.java

    r790 r802  
    2020 
    2121import java.util.ArrayList; 
     22import java.util.HashSet; 
     23import java.util.Iterator; 
    2224import java.util.List; 
    2325 
     
    5153                log.debug("Applying attribute filter policy {} to event set", attributeFilterPolicy.getPolicyName()); 
    5254                List<Event> filteredEntries = clone(events); 
    53                 for (Event entry : filteredEntries) { 
     55                for (Event event : filteredEntries) { 
    5456                        for (AttributeRule attributeRule : attributeFilterPolicy.getAttributeRules()) { 
    55                                 filterAttributes(entry, attributeRule, metadata); 
     57                                filterAttributes(event, attributeRule, metadata); 
     58 
    5659                        } 
    5760                } 
    58  
    5961                return filteredEntries; 
    6062        } 
     
    8991        } 
    9092 
     93 
    9194} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/AttributeAssociationDefinition.java

    r756 r802  
    3434 * 
    3535 */ 
    36 public class AttributeAssociationDefinition { 
     36public abstract class AttributeAssociationDefinition { 
    3737 
    3838    /** Class logger. */ 
     
    4242    private String definiationName; 
    4343 
    44     /** The name of the field the subject's principal should be extracted from*/ 
    45     private String subjectPrincipalField; 
    46  
    47     private List<AttributeLookup> lookupAttributes; 
    48  
    4944    /** Whether to apply the attribute association*/ 
    5045    private boolean enabled; 
    5146 
    5247    /** The class type that these attribute definitions are attached to*/ 
    53     private Class<?> classToAdd; 
     48    protected Class<?> classToAdd; 
    5449 
    5550    /** The class type that this attribute association is applicable for */ 
    56     private String associateWithClass; 
     51    protected String associateWithClass; 
    5752 
    58     /** The data connector used to acquire the attributes*/ 
    59     private DataConnector dataConnector; 
     53    public abstract boolean associate(Event event); 
    6054 
    61     /** The ldap search filter template*/ 
    62     private String searchFilterTemplate; 
     55    public abstract void initialise(); 
    6356 
    64     /** 
    65      * @return 
    66      */ 
    67     public String[] getSourceAttributesAsArray() { 
    68         String[] sourceAttributes = new String[lookupAttributes.size()]; 
    69         int i=0; 
    70         for (AttributeLookup lookupAttribute : lookupAttributes){ 
    71             sourceAttributes[i++] = lookupAttribute.getSourceAttributeName(); 
    72         } 
    73         return sourceAttributes; 
    74     } 
    75  
    76     public void initialise(){ 
    77         dataConnector.initialise(); 
    78  
    79     } 
    80  
    81  
    82     /** 
    83      * @param attributeSourceName 
    84      * @return 
    85      */ 
    86     public String getInternalAttributeName(String attributeSourceName) throws AttributeAssociationException{ 
    87         for (AttributeLookup lookupAttribute : lookupAttributes){ 
    88                if (lookupAttribute.getSourceAttributeName().equals(attributeSourceName)) 
    89                    return lookupAttribute.getInternalAttributeName(); 
    90         } 
    91         throw new AttributeAssociationException("Source attribute "+attributeSourceName+" was not found in the attribute association mappings"); 
    92     } 
    93  
    94  
    95     private void populate(Map<String,String> attributes, Event event) throws InstantiationException, IllegalAccessException{ 
    96  
    97         Object classToPopulate = getClassToAdd().newInstance(); 
    98  
    99         for (Map.Entry<String,String> entry : attributes.entrySet()){ 
    100             String attributeSourceName = entry.getKey(); 
    101             String attributeValue = entry.getValue(); 
    102             log.trace("source [{}], value [{}]",attributeSourceName,attributeValue); 
    103             try{ 
    104                 String internalFieldName = getInternalAttributeName(attributeSourceName); 
    105                 ReflectionHelper.setValueOnObject(internalFieldName, attributeValue, classToPopulate); 
    106             } 
    107             catch(AttributeAssociationException e){ 
    108                 log.warn("Error trying to populate internal model. {}",e.getMessage()); 
    109             } 
    110         } 
    111  
    112         //now attach the object where appropriate on the current <code>Event</code> object 
    113         ReflectionHelper.attachObjectTo(classToPopulate,event); 
    114  
    115        // log.debug("{}",event); 
    116     } 
    117  
    118     /** 
    119      * @param event 
    120      */ 
    121     public boolean associate(Event event) { 
    122        // log.debug("{},v {}",event.getClass().getCanonicalName(),associateWithClass.getClass().getCanonicalName()); 
    123         if (!event.getClass().getCanonicalName().equals(associateWithClass)){ 
    124             return false; 
    125         } 
    126  
    127         Object principalObject = ReflectionHelper.getValueFromObject(getSubjectPrincipalField(), event); 
    128         String principal = null; 
    129         if (principalObject instanceof String){ 
    130             principal = (String)principalObject; 
    131         } 
    132         if (principal!=null){ 
    133             try { 
    134                  dataConnector.setReturnAttributes(getSourceAttributesAsArray()); 
    135                  dataConnector.setSearchFilterTemplate(searchFilterTemplate); 
    136                  Map<String, String> attributes = dataConnector.lookup(principal); 
    137                  populate(attributes,event); 
    138  
    139                  return true; 
    140             } catch (AttributeAssociationException e) { 
    141                 log.error("Association error for principal [{}], {}",principal,e.getMessage()); 
    142             } catch (InstantiationException e) { 
    143                 log.warn("Could not populate event [{}], {}",event,e.getMessage()); 
    144             } catch (IllegalAccessException e) { 
    145                 log.warn("Could not populate event [{}], {}",event,e.getMessage()); 
    146             } 
    147         } 
    148         return false; 
    149  
    150     } 
    151  
    152  
    153  
    154     /** 
    155      * @param subjectPrincipalField the subjectPrincipalField to set 
    156      */ 
    157     public void setSubjectPrincipalField(String subjectPrincipalField) { 
    158         this.subjectPrincipalField = subjectPrincipalField; 
    159     } 
    160  
    161     /** 
    162      * @return the subjectPrincipalField 
    163      */ 
    164     public String getSubjectPrincipalField() { 
    165         return subjectPrincipalField; 
    166     } 
    167  
    168     /** 
    169      * @param lookupAttributes the lookupAttributes to set 
    170      */ 
    171     public void setLookupAttributes(List<AttributeLookup> lookupAttributes) { 
    172         this.lookupAttributes = lookupAttributes; 
    173     } 
    174  
    175     /** 
    176      * @return the lookupAttributes 
    177      */ 
    178     public List<AttributeLookup> getLookupAttributes() { 
    179         return lookupAttributes; 
    180     } 
    18157 
    18258    /** 
     
    19571        return enabled; 
    19672    } 
    197  
    198  
    199  
    200     /** 
    201      * @param dataConnector the dataConnector to set 
    202      */ 
    203     public void setDataConnector(DataConnector dataConnector) { 
    204         this.dataConnector = dataConnector; 
    205     } 
    206  
    207  
    208  
    209     /** 
    210      * @return the dataConnector 
    211      */ 
    212     public DataConnector getDataConnector() { 
    213         return dataConnector; 
    214     } 
    215  
    216  
    217  
    218     /** 
    219      * @param searchFilterTemplate the searchFilterTemplate to set 
    220      */ 
    221     public void setSearchFilterTemplate(String searchFilterTemplate) { 
    222         this.searchFilterTemplate = searchFilterTemplate; 
    223     } 
    224  
    225  
    226  
    227     /** 
    228      * @return the searchFilterTemplate 
    229      */ 
    230     public String getSearchFilterTemplate() { 
    231         return searchFilterTemplate; 
    232     } 
    233  
    23473 
    23574 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/AttributeAssociationEngine.java

    r713 r802  
    5454     */ 
    5555    public void associateAttributes(List<Event> events) throws AttributeAssociationException{ 
    56  
    5756        for (AttributeAssociationDefinition attributeAssociationDefinition: attributeAssociationDefinitions){ 
    5857            log.info("Attribute Association Definition [{}], is enabled [{}]",attributeAssociationDefinition.getDefiniationName(), attributeAssociationDefinition.isEnabled()); 
     
    8079                    new Object[]{attributeAssociationDefinition.getDefiniationName(),attached,noPrincipal}); 
    8180        } 
     81 
    8282    } 
    8383 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/PrincipalAttributeAssociationDefinition.java

    r796 r802  
    2626 
    2727import uk.ac.cardiff.model.event.Event; 
     28import uk.ac.cardiff.model.resource.ResourceMetadata; 
    2829import uk.ac.cardiff.raptor.event.expansion.connector.AttributeAssociationException; 
    2930import uk.ac.cardiff.raptor.event.expansion.connector.DataConnector; 
    3031import uk.ac.cardiff.raptor.runtimeutils.ReflectionHelper; 
     32import uk.ac.cardiff.raptor.store.dao.RaptorDataConnection; 
    3133 
    3234/** 
     
    3436 * 
    3537 */ 
    36 public class AttributeAssociationDefinition { 
     38public class PrincipalAttributeAssociationDefinition extends AttributeAssociationDefinition{ 
    3739 
    3840    /** Class logger. */ 
    39     private final Logger log = LoggerFactory.getLogger(AttributeAssociationDefinition.class); 
    40  
    41     /** Human readable name for this definition*/ 
    42     private String definiationName; 
     41    private final Logger log = LoggerFactory.getLogger(ResourceCategoryAttributeAssociationDefinition.class); 
    4342 
    4443    /** The name of the field the subject's principal should be extracted from*/ 
     
    4645 
    4746    private List<AttributeLookup> lookupAttributes; 
    48  
    49     /** Whether to apply the attribute association*/ 
    50     private boolean enabled; 
    51  
    52     /** The class type that these attribute definitions are attached to*/ 
    53     private Class<?> classToAdd; 
    54  
    55     /** The class type that this attribute association is applicable for */ 
    56     private String associateWithClass; 
    5747 
    5848    /** The data connector used to acquire the attributes*/ 
     
    180170    } 
    181171 
    182     /** 
    183      * @param enabled the enabled to set 
    184      */ 
    185     public void setEnabled(boolean enabled) { 
    186         this.enabled = enabled; 
    187     } 
    188  
    189  
    190  
    191     /** 
    192      * @return the enabled 
    193      */ 
    194     public boolean isEnabled() { 
    195         return enabled; 
    196     } 
    197  
    198  
    199172 
    200173    /** 
     
    232205    } 
    233206 
    234  
    235  
    236     /** 
    237      * @param definiationName the definiationName to set 
    238      */ 
    239     public void setDefiniationName(String definiationName) { 
    240         this.definiationName = definiationName; 
    241     } 
    242  
    243  
    244  
    245     /** 
    246      * @return the definiationName 
    247      */ 
    248     public String getDefiniationName() { 
    249         return definiationName; 
    250     } 
    251  
    252207    /** 
    253208     * @param classToAdd the classToAdd to set 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/remoting/client/EventReleaseEngine.java

    r796 r802  
    2121import java.util.ArrayList; 
    2222import java.util.Date; 
     23import java.util.HashSet; 
     24import java.util.Iterator; 
    2325import java.util.List; 
    2426 
     
    3537import uk.ac.cardiff.model.ServiceMetadata; 
    3638import uk.ac.cardiff.model.event.Event; 
     39import uk.ac.cardiff.model.event.auxiliary.EventMetadata; 
    3740import uk.ac.cardiff.model.wsmodel.EventPushMessage; 
    3841 
     
    7174                        if (shouldRelease) { 
    7275                                List<Event> filteredEntries = filterAttributes(serviceMetadata, endpoint, applicableEvents); 
     76                                appendMetadata(filteredEntries,serviceMetadata); 
    7377                                EventPushMessage pushMessage = constructEventPush(serviceMetadata, filteredEntries); 
    7478                                log.debug("Pushing {} entries to the Endpoint [{}]", filteredEntries.size(),endpoint.getServiceEndpoint()); 
     
    8084                                        releaseCount++; 
    8185                                        /* Saves the state of the event before modification e.g. <code>applicableEvents</code> 
    82                                          * not <code>applicableEvents</code> */ 
     86                                         * not <code>filteredEntries</code> */ 
    8387                                        endpoint.releasePerformed(applicableEvents); 
    8488                                        log.debug("Endpoint [{}] has been sent events up to and including {}",endpoint.getServiceEndpoint(), 
     
    97101        } 
    98102 
     103 
    99104        /** 
    100105     * Method that returns those events that are supported by the <code>endpoint</code parameter. 
     
    105110     */ 
    106111    private List<Event> eventTypeFilter(Endpoint endpoint, List<Event> events) { 
     112        if (endpoint.getSupportedEvents()==null){ 
     113            log.info("There are 0 events to send to the endpoint [{}] after event type filtering. Has the endpoint been set" + 
     114                        " with the correct supported event types?",endpoint.getServiceEndpoint()); 
     115            return new ArrayList<Event>(); 
     116        } 
     117 
    107118        ArrayList<Event> applicableEvents = new ArrayList<Event>(); 
    108  
    109         return events; 
     119        for (Event event : events){ 
     120            boolean supported = false; 
     121            for (Class<?> supportedClass : endpoint.getSupportedEvents()){ 
     122                if (event.getClass()==supportedClass){ 
     123                    supported = true; 
     124                } 
     125            } 
     126            if (supported){ 
     127                applicableEvents.add(event); 
     128            } 
     129 
     130        } 
     131        log.info("There are {} events to send to the endpoint [{}] after event type filtering",applicableEvents.size(),endpoint.getServiceEndpoint()); 
     132        return applicableEvents; 
    110133    } 
    111134 
    112135 
     136    private void appendMetadata(List<Event> events, ServiceMetadata metadata){ 
     137        for (Event event : events){ 
     138            EventMetadata eventMetadata = new EventMetadata(); 
     139            eventMetadata.setEntityId(metadata.getEntityId()); 
     140            eventMetadata.setServiceName(metadata.getServiceName()); 
     141            eventMetadata.setOrganisationName(metadata.getOrganisationName()); 
     142            event.setEventMetadata(eventMetadata); 
     143        } 
     144    } 
    113145 
    114146    /** 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/StorageEngine.java

    r775 r802  
    2929 
    3030import uk.ac.cardiff.model.event.Event; 
     31import uk.ac.cardiff.model.resource.ResourceMetadata; 
    3132import uk.ac.cardiff.raptor.event.expansion.AttributeAssociationEngine; 
    3233 
     
    106107    } 
    107108 
     109 
    108110    /** 
    109111     * 
     
    152154 
    153155 
     156 
     157 
     158 
     159 
    154160} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/PersistantEntryHandler.java

    r796 r802  
    129129 
    130130                Set<Event> persist = new HashSet<Event>(); 
    131  
    132131                for (Event event : persistQueue) { 
    133132                        String query ="select count(*) from "+event.getClass().getSimpleName()+" where eventTime = ? and eventId =?"; 
    134133                        Object[] parameters= new Object[]{event.getEventTime().toDate(),event.getEventId()}; 
    135                         int numberOfDuplicates = ((Integer) dataConnection.runQueryUnique(query, parameters)).intValue(); 
    136 //                      int numberOfDuplicates = ((Integer) dataConnection.runQueryUnique("select count(*) from " + event.getClass().getSimpleName() 
    137 //                                     + " where eventTime = '" + event.getEventTime().toDate() + "' and hashCode ='" + hashcode + "'", null)).intValue(); 
    138  
    139                         if (numberOfDuplicates == 0){ 
    140                             //log.debug("dups [{}], params {} ",numberOfDuplicates, "select count(*) from " + event.getClass().getSimpleName() 
    141                             //        + " where eventTime = '" + event.getEventTime().toDate() + "' and hashCode ='" + hashcode + "'"); 
    142                             //Date local = new Date(event.getEventTime().getMillis()); 
    143                            // DateTime newTime = new DateTime(local); 
    144                            // log.debug("Before: {} [{}] Local:{} [{}], back {} [{}]",new Object[] 
    145                             //        {event.getEventTime(),event.getEventTime().getMillis(), local, local.getTime(), newTime, newTime.getMillis()}); 
     134                        int storedDuplicates = ((Integer) dataConnection.runQueryUnique(query, parameters)).intValue(); 
     135 
     136                        if (storedDuplicates == 0){ 
    146137                            persist.add(event); 
    147138                        } 
     
    150141                        } 
    151142                } 
    152                 log.debug("After both internal (from the list of events send) and external (from the store) duplicate checking" + 
    153                                 "there are {} events left to persit",persist.size()); 
    154143                try{ 
    155144                    dataConnection.saveAll(persist); 
     
    163152 
    164153        public boolean addEntry(Event event) { 
    165                  
     154 
    166155                String query ="select count(*) from "+event.getClass().getSimpleName()+" where eventTime = ? and eventId =?"; 
    167156                Object[] parameters= new Object[]{event.getEventTime().toDate(),event.getEventId()}; 
Note: See TracChangeset for help on using the changeset viewer.