Personnalisation avancée > Business Logic Customization > Windchill ProjectLink Customization > Configuring Automatic Deadline Calculation > Construct a Deadline Algorithm for Individual Activities
  
Construct a Deadline Algorithm for Individual Activities
Perform the following steps to create a custom algorithm for individual activity (“leaf activity”) deadline calculation.
Before you begin:
You will need the internal name of the activity subtype created in Set the Deadline Mode.
Review the registered event listeners: Registered Event Listeners for Deadline and Status Calculation
Review supported APIs: Supported APIs for Activity Calculation
Review custom handler guidelines: Custom Handler Guidelines for Status and Deadline Calculation
Step 1: Author a Handler Class
The EPPDeadlineHandler interface allows you to provide a custom calculation algorithm:
EPPDeadlineHandler.java
calculateDeadline(<Collection of leaf activity objects>, event);
You can extend this interface and override certain APIs in order to utilize your custom algorithm. For example, the following sample code would calculate the deadline based on the start date of the activity:

package com.ptc.projectmanagement.plan.EPPDeadlineHandler;
public class CustomDeadlineImplementation implements EPPDeadlineHandler {
@Override
public void calculateDeadline(ArrayList<PlanActivity> activitiesCollection, Object event)
throws WTException, WTPropertyVetoException {

try{
WTCollection leafAct = new WTArrayList();
WTCollection leafActivities = new WTArrayList(activitiesCollection);
leafActivities = CollectionsHelper.manager.refresh(leafActivities);

for (Object activity: leafActivities){
if(activity instanceof PlanActivity){
PlanActivity pActivity = (PlanActivity)activity;
Timestamp tmStart = pActivity.getStartDate();
pActivity.setDeadline(addDays(10, tmStart));
}
leafAct.add(pActivity);
}

PersistenceHelper.manager.save(leafAct);
//After saving the activities, the EPP_CUSTOM_DEADLINE_CHANGE event must be thrown
//so that the subsequent health status recalculations and notification emails are triggered.

PlanHelper.service.dispatchMultiEvent(ProjectManagementEvent.EPP_CUSTOM_DEADLINE_CHANGE,leafAct);

} catch(Exception ae){
ae.printStackTrace();
}
}
}
Step 2: Configure the Handler Class
Once the custom algorithm for deadline calculation is authored, you must to add it to projectmanagement.service.properties.xconf.
1. Copy the internal name of the activity subtype created in Set the Deadline Mode.
2. Navigate to the following location:
${WT_HOME}/Windchill/codebase/com/ptc/projectmanagement/projectmanagement.service.properties.xconf
3. Edit the following entry to include the internal name of the activity subtype and your handler class name:
<Service context="default" name="com.ptc.projectmanagement.plan.EPPDeadlineHandler">
<Option cardinality="singleton" requestor= "null"
selector = "<internal type name>"
serviceClass="<fully qualified handler class name>"/>
</Service>
For example, given the sample handler class above and an internal name of “org.rnd.Custom_Engineering_Activity”:
<Service context="default" name="com.ptc.projectmanagement.plan.EPPDeadlineHandler">
<Option cardinality="singleton" requestor= "null"
selector = "org.rnd.Custom_Engineering_Activity"
serviceClass="com.ptc.projectmanagement.plan.CustomDeadlineImplementation"/>
</Service>
4. Run the following command from a Windchill shell:
xconfmanager -p
* 
The PlanActivity type has following an out-of-the-box handler defined. This handler has no effect:
<Service context="default" name="com.ptc.projectmanagement.plan.EPPDeadlineHandler">
<Option cardinality="singleton" requestor= "null"
selector = "com.ptc.projectmanagement.plan.PlanActivity"
serviceClass="com.ptc.projectmanagement.plan.PlanActivityDeadlineHandler"/>
</Service>