Class ChangeStatusEventHandler

java.lang.Object
wt.services.ServiceEventListenerAdapter
wt.change2.listeners.ChangeStatusEventHandler
All Implemented Interfaces:
KeyedEventListener
Direct Known Subclasses:
PendingChangeEventHandler, ResultingChangeEventHandler

public abstract class ChangeStatusEventHandler extends ServiceEventListenerAdapter
This class is responsible for implementing the common functionality for processing the events that could change the status indicator of changeables. Changeables currently have three status indicators: Pending Change, Hanging Change and Variance Exists.

ChangeStatusEventHandler is the abstract class that implements the common functionality for handling events. This class name will be the key for the service look up. For each change status indicator, (for say pending change), an abstract event handler (PendingChangeEventHandler) will be written that will extend ChangeStatusEventHandler. The abstract event handler (PendingChangeEventHandler) will implement the business logic for the corresponding change indicator (pending change). The requestor for the service look up will be the 'abstract event handler' (PendingChangeEventHandler)

The implementing event handler (DefaultPendingChangeEventHandler) extends from the abstract event handler for the change status indicator.

For example, the following is the registration for the default implementation:

 <Service context="default" name="wt.change2.listeners.ChangeStatusEventHandler">
    <Option serviceClass="wt.change2.listeners.DefaultPendingChangeEventHandler"
              selector="null"
              requestor="wt.change2.listeners.PendingChangeEventHandler"
              cardinality="duplicate"/>
 </Service>
 
 
The naming convention followed for the method name that handles the event is ChangeStatusEventHandler.HANDLE_EVENT_METHOD_PREFIX + the event key. For e.g. the method handling the UPDATE event would be ChangeStatusEventHandler.HANDLE_EVENT_METHOD_PREFIX + UPDATE. In case of a need to handle a new event for a change Indicator, the below steps need to be followed:

    1. Register events to be handled by the handler in the property returned by getEventRegisterProperty method in wt.properties.
    2. Write a custom handler that extends the abstract event handler for change indicator(PendingChangeEventHandler) or the implementation class
       (DefaultPendingChangeEventHandler).The custom event handler needs to implement the  ChangeStatusEventHandler.HANDLE_EVENT_METHOD_PREFIX + EVENTKEY
       method where EVENTKEY is the event that needs to be handled.
    3. Register the custom handler in the service.properties.
    3. getGeneratedEventKeys method need to overridden, if the event to be handled is not in the list of events, that the default implementation handles.
 
Supported API: true Extended API: true
  • Constructor Details

    • ChangeStatusEventHandler

      public ChangeStatusEventHandler(String serviceId)
      Constructs event handler with specified service id.

      Supported API: true
      Parameters:
      serviceId -
  • Method Details

    • notifyVetoableMultiObjectEvent

      public void notifyVetoableMultiObjectEvent(Object event) throws WTException, WTPropertyVetoException
      This method handles the event that can change the value of change status indicator. Given an event, it constructs the method name and invokes it on the event targets. The convention used for the method name that handles the event is ChangeStatusEventHandler.HANDLE_EVENT_METHOD_PREFIX + the event key. For e.g. the method handling the INSERT event would be ChangeStatusEventHandler.HANDLE_EVENT_METHOD_PREFIX + INSERT. The notifyVetoableMultiObjectEvent method must be overridden by the implementation class and it will call its super class as required by the Windchill event handling infrastructure.

      For example:
       
       @Override
       public void notifyVetoableMultiObjectEvent(Object event) throws Exception {
           super.notifyVetoableMultiObjectEvent(event);
       }
       
       


      Supported API: true
      Specified by:
      notifyVetoableMultiObjectEvent in interface KeyedEventListener
      Overrides:
      notifyVetoableMultiObjectEvent in class ServiceEventListenerAdapter
      Parameters:
      event -
      Throws:
      WTException
      WTPropertyVetoException
    • calculate

      protected abstract HashMap<Long,Boolean> calculate(Collection<Long> changeables, ChangeItem changeItem) throws WTException
      This method calculates the change status indicator for a collection of changeables. The implementation class for the change status indicator should implement the business logic to calculate the value of the indicator (true/false) for the given changeables. The change item may be specified if it is required for the calculation. For some calculations, the change item might be needed to exclude changeables due to the change item. Only calculates for Changeable2.HAS_PENDING_CHANGE.

      Supported API: true
      Parameters:
      changeables - - the list containing object identifiers of changeables for which the calculation needs to be performed
      changeItem - - the change item that has to be excluded/included in the calculation.
      Returns:
      map where the keys are the object identifiers and the value indicates if the change status is on or off. The map key size should be equal to the size of the changeable collection.
      Throws:
      WTException
    • getChangeablesToSetIndicator

      public abstract StatementSpec getChangeablesToSetIndicator() throws WTException, WTPropertyVetoException
      This method returns the query spec that would get the branch identifiers of changeables that the change status indicator is NOT set in the database and the change status indicator should be updated to a true value. Only sets the Changeable2.HAS_PENDING_CHANGE attributes.

      Supported API: true
      Returns:
      StatementSpec - the defined statement spec for retrieve the changeable branch ids.
      Throws:
      WTException
      WTPropertyVetoException
    • getChangeablesToSetIndicator

      public abstract StatementSpec getChangeablesToSetIndicator(WTCollection changeItems) throws WTException, WTPropertyVetoException
      This method returns the query spec that would get the branch identifiers of changeables that the change status indicator is NOT set in the database and the change status indicator should be updated to a true value. Only sets the Changeable2.HAS_PENDING_CHANGE attributes. It will only consider setting the indicator for the specified change items passed into the API in the WTCollection.

      Supported API: true
      Parameters:
      WTCollection - - the collection of change items to consider for the indicator update
      Returns:
      StatementSpec - the defined statement spec for retrieve the changeable branch ids.
      Throws:
      WTException
      WTPropertyVetoException
    • getChangeablesToResetIndicator

      public abstract QuerySpec getChangeablesToResetIndicator() throws WTException, WTPropertyVetoException
      This method returns the query spec that would get the branch identifiers of changeables for which the change status indicator is set in the database and the change status indicator should be updated to false. Only resets the Changeable2.HAS_PENDING_CHANGE attributes.

      Supported API: true
      Returns:
      query spec - the defined query for retrieve the changeable branch ids.
      Throws:
      WTException
      WTPropertyVetoException
    • getChangeablesToResetIndicator

      public abstract StatementSpec getChangeablesToResetIndicator(WTCollection changeItems) throws WTException, WTPropertyVetoException
      This method returns the query spec that would get the branch identifiers of changeables for which the change status indicator is set in the database and the change status indicator should be updated to false. Only resets the Changeable2.HAS_PENDING_CHANGE attributes. It will only consider doing the reset for the specified change items passed into the API in the WTCollection.

      Supported API: true
      Parameters:
      changeItems - - the set of changeItems to consider for the reset
      Returns:
      query spec - the defined query for retrieve the changeable branch ids.
      Throws:
      WTException
      WTPropertyVetoException
    • updateChangeStatus

      public void updateChangeStatus(HashSet<Long> changeables, String changeStatusIndicator, boolean changeStatus) throws WTException, WTPropertyVetoException
      Helper method that sets the change indicator value on the specified changeables.

      for e.g. if changeStatusAttribute is Changeable2.HAS_PENDING_CHANGE and changeStatus is true, it will update the hasPendingChange for the given changeables to true.

      Supported API: true
      Parameters:
      changeables - - the list of changeables that need to be updated
      changeStatusIndicator - - the indicator to be updated (eg. Changeable2.HAS_PENDING_CHANGE)
      changeStatus - - the new value for the indicator
      Throws:
      WTException
      WTPropertyVetoException
    • updateChangeStatus

      public int updateChangeStatus(StatementSpec spec, Class<?> changeableClass, String changeStatusIndicator, boolean changeStatus) throws WTException
      Helper method that sets the change indicator value on the specified query.

      for e.g. if changeStatusAttribute is Changeable2.HAS_PENDING_CHANGE and changeStatus is true, it will update the hasPendingChange for the given query to true.

      Supported API: true
      Parameters:
      StatementSpec - - the query which returns the list of changeable branch identifiers that need to be updated
      changeableClass -
      changeStatusIndicator - - the indicator to be updated (eg. Changeable2.HAS_PENDING_CHANGE)
      changeStatus - - the new value for the indicator
      Throws:
      WTException
    • getChangeables

      protected QueryResult getChangeables(ChangeItem changeItem, List<String> attributes) throws WTException
      Helper method to return the attributes of the changeables associated to the change item. The attributes needed to be returned by the query should be specified in the attributes list. If the attributes are null or empty it would return only the object identifier of the changeables.

      Supported API: true
      Parameters:
      changeItem -
      attributes - - list of the attribute names of changeables to be returned [query name for the attribute]
      Returns:
      query result that contains the value for attributes of the changeables
      Throws:
      WTException
    • getChangeables

      protected QueryResult getChangeables(ChangeItem changeItem, Class<?> linkClass, List<String> attributes) throws WTException
      Helper method to return the attributes of the changeables associated to the change item. The attributes needed to be returned by the query should be specified in the attributes list. If the attributes are null or empty it would return only the object identifier of the changeables.

      Supported API: true
      Parameters:
      changeItem -
      linkClass -
      attributes - - list of the attribute names of changeables to be returned [query name for the attribute]
      Returns:
      query result that contains the value for attributes of the changeables
      Throws:
      WTException
    • setChangeableQueryClass

      public void setChangeableQueryClass(Class clazz)
      Set method for changeableQueryClass
      Supported API: true
      Parameters:
      clazz -
    • getChangeableQueryClass

      public Class getChangeableQueryClass()
      Get method for changeableQueryClass
      Supported API: true
      Returns:
      changeableQueryClass
    • buildCompoundQuerySpec

      public CompoundQuerySpec buildCompoundQuerySpec(QuerySpec querySpec1, QuerySpec querySpec2) throws WTPropertyVetoException
      Will return a compound query spec that unions 2 queries. The two queries should return the same number and type of attributes.

      Supported API: true
      Parameters:
      querySpec1 -
      querySpec2 -
      Returns:
      a compound query spec that unions of the 2 queries
      Throws:
      WTPropertyVetoException
    • buildCompoundQuerySpec2

      public StatementSpec buildCompoundQuerySpec2(QuerySpec querySpec1, QuerySpec querySpec2) throws WTPropertyVetoException
      Will return a compound query spec that unions 2 queries. The two queries should return the same number and type of attributes if they are not null.

      Supported API: true
      Parameters:
      querySpec1 -
      querySpec2 -
      Returns:
      a compound query spec that unions of the 2 queries
      Throws:
      WTPropertyVetoException
    • appendLatestChangeCondition

      protected void appendLatestChangeCondition(QuerySpec querySpec, Class<?> changeItemClass, int changeIdx) throws WTException
      Appends the condition to the query spec to apply for latest changes only. The following condition phrase will be appended to the specified query spec, where A0 is the changeIdx (the table index for the change Item):
      
       A0.latest = 1
       

      Supported API: true
      Parameters:
      querySpec - - Query Spec to which the condition need to be appended
      changeItemClass - - class name for the Change Item table
      changeIdx - - table index for the change item
      Throws:
      WTException
    • appendByChangeItem

      protected void appendByChangeItem(QuerySpec querySpec, Class<?> changeItemClass, ChangeItem changeItem, int changeIdx, boolean notInclude) throws WTException
      Appends the condition to the query spec to filter by the change Item. The following condition phrase will be appended to the specified query spec, where A0 is the changeIdx (the table index for the change Item):
      
       A0.branchiditerationinfo = 12675
       
      where 12675 is the branch identifiers of change item.

      Supported API: true
      Parameters:
      querySpec - - Query Spec to which the condition need to be appended
      changeItemClass - - class name for the Change Item table
      changeItem -
      changeIdx - - table index for the change item
      notInclude - - if true, would not include the rows of the given changeItem, if notInclude is false, it will only include the rows for the given change item.
      Throws:
      WTException
    • appendByChangeables

      protected void appendByChangeables(QuerySpec qs, Class<?> linkClass, Collection<Long> changeables) throws WTException
      Appends the condition to the query spec to filter by the given changeables as Role A of the link. The following condition phrase will be appended to the specified query spec, where A0 is the changeIdx (the table index for the change Item):
      
       A0.ida3a5 in (12787, 12986)
       
      where 12787, 12986 are object identifiers of changeables.

      Supported API: true
      Parameters:
      qs - - query spec to which the condition needs to be appended
      linkClass - - class name of the binary link that's being queried for and the Changeable2 is the role A
      changeables - - list of changeables that are role A objects.
      Throws:
      WTException
    • buildJoinQuerySpec

      protected QuerySpec buildJoinQuerySpec(Class<?> linkClass, Class<?> changeClass, String changeRole) throws WTException
      Creates a query spec that joins the link class and target class specified by the role of the link. The usage for this would be some thing like below:
      
       QuerySpec querySpec = buildJoinQuerySpec(IncludedIn2.class, ChangeOrder2.class, IncludedIn2.CHANGE_ORDER2_ROLE);
       


      Supported API: true Creates the QuerySpec for .
      Parameters:
      linkClass - - The class of the link table
      changeClass - - The class of the change table
      changeRole - - role between the link class and change class
      Returns:
      Throws:
      WTException
    • getGeneratedEventKeys

      protected List<String> getGeneratedEventKeys() throws WTException
      Returns generated event keys for all the events that need to be listened for. The getEventRegisterProperty method gets the property that need to be registered for a change indicator.In the default implementation, it generates the keys for the following events:
         1. PersistenceManagerEvent.INSERT
         2. PersistenceManagerEvent.REMOVE
         3. LifeCycleServiceEvent.STATE_CHANGE
         4. LifeCycleServiceEvent.REASSIGN
         5. VersionControlServiceEvent.NEW_VERSION
       
      In case, the custom event handler needs to register for more event types, the handler would override this method and add the event keys that of interest. Make sure that the method calls super of the method so that it adds all the events that is supported by the default implementation.The implementation in the custom hander would be like below, if UPDATE event on a persistent object need to be also listened for :
      
           List eventKeys = super();
           eventKeys.add(PersistenceManagerEvent.generateEventKey(PersistenceManagerEvent.UPDATE));
       

      Supported API: true
      Returns:
      Throws:
      IOException
      WTException