Attribut-Änderungs-Skripte#

Attribut-Änderungs-Skripte ändern den Wert eines Attributes basierend auf einem Event, in der Regel einer Änderung eines anderen Attributs. Diese Skripte sind also Event Handler.

Änderung einer Auswahl#

Ändert den Listenwert eines abhängigen Listenattributs, ausgelöst durch ein anderes Listenattribut.

package script.attributeChange
import com.aurel.track.beans.TWorkItemBean;
import com.aurel.track.fieldType.constants.SystemFields
import com.aurel.track.fieldType.runtime.base.WorkItemContext
import com.aurel.track.item.attributeDependency.AttributeDependencyTO
import com.aurel.track.item.attributeDependency.ChangeListValueDependency
import com.aurel.track.item.attributeDependency.RemoveListEntryDependency
import com.aurel.track.item.attributeDependency.RequiredDependency
import com.aurel.track.report.execute.WorkItemBeanComparator
import com.aurel.track.util.event.IEventHandler;

/**
 * Changes the list value of a dependent list attribute, triggered by another list attribute 
 */
public class ChangeListValueByListValue implements IEventHandler {
	
	//the fieldIDs can be looked up in the database directly or 
	//using FieldBL.loadByName() (the latter is less efficient)
	private static Integer targetProjectID = 1304;
	private static Integer triggerAttribut = 1476;
	private static Integer dependentAttribut = SystemFields.PRIORITY;
	
	/**
	 * Applies the dependency between the two lists
	 * The IDs can be looked up in the database directly or 
	 * using OptionBL.loadByLabel(...) (the latter is less efficient)
	 */
	def public Map<String, Object> handleEvent(Map<String, Object> inputBinding) {
		WorkItemContext workItemContext = (WorkItemContext)inputBinding.get("workItemContext")
		TWorkItemBean workItemBean = workItemContext.getWorkItemBean()
		Object[] classification = workItemBean.getAttribute(triggerAttribut)
		Integer dependentValue = null
		Integer value = null
		if (classification!=null) {
			value = (Integer)classification[0]
		}
		if (value!=null) {
			switch (value) {
				case 6474:
				case 6475:
				case 6476:
					dependentValue = 1
					break;
				case 6469:
				case 6470:
				case 6471:
				case 6472:
				case 6473:
					dependentValue = 2
					break;
				case 6465:
				case 6466:
				case 6467:
				case 6468:
					dependentValue = 3
					break;
			}
		}
		if (dependentValue!=null) {
			ChangeListValueDependency.changeListEntry(workItemContext, dependentAttribut, dependentValue)
		}
		return inputBinding
	}
	
	/**
	 * Defines a dependency between two lists 
	 * @param inputBinding
	 * @return
	 */
	List<AttributeDependencyTO> getDependencies(Map<String, Object> inputBinding) {
		List<AttributeDependencyTO> dependencies = null
		//uncomment this to activate this attribute change script
		/*WorkItemContext workItemContext = (WorkItemContext)inputBinding.get("workItemContext")
		TWorkItemBean workItemBean = workItemContext.getWorkItemBean()
		Integer projectID = workItemBean.getProjectID()
		if (projectID!=null && projectID.intValue()==targetProjectID) {
			dependencies = new ArrayList<>()
			ChangeListValueDependency.configureAttributeAsConditionallyChangeListValue(
				workItemContext, dependentAttribut, triggerAttribut, dependencies)
		}*/
		return dependencies;
	}
}

Änderung eines Datums#

package script.attributeChange
import com.aurel.track.beans.TWorkItemBean;
import com.aurel.track.fieldType.constants.SystemFields
import com.aurel.track.fieldType.runtime.base.IFieldTypeRT
import com.aurel.track.fieldType.runtime.base.WorkItemContext
import com.aurel.track.fieldType.types.FieldTypeManager
import com.aurel.track.item.attributeDependency.AttributeDependencyTO
import com.aurel.track.item.attributeDependency.ChangeListValueDependency
import com.aurel.track.item.attributeDependency.RemoveListEntryDependency
import com.aurel.track.item.attributeDependency.RequiredDependency
import com.aurel.track.report.execute.WorkItemBeanComparator
import com.aurel.track.util.event.IEventHandler;

/**
 * Changes the value of a dependent date attribute, triggered by a list attribute 
 */
public class ChangeValueByListValue implements IEventHandler {
	//the fieldIDs can be looked up in the database directly or
	//using FieldBL.loadByName() (the latter is less efficient)
	private static Integer triggerAttribut = 1030;
	private static Integer dependentAttribut = 1101;
	//the dependency is valid only in this project
	private static Integer targetProjectID = 1080;
	
	/**
	 * This method is being called as soon as triggerAttribut has been changed (ajax call).
	 * It changes the value of dependentAttribut 
	 */
	def public Map<String, Object> handleEvent(Map<String, Object> inputBinding) {
		WorkItemContext workItemContext = (WorkItemContext)inputBinding.get("workItemContext")
		TWorkItemBean workItemBean = workItemContext.getWorkItemBean()
		workItemBean.setAttribute(dependentAttribut, new Date());
		return inputBinding
	}

	/**
	 * Defines the dependency of dependentAttribut from triggerAttribut if the item is in the targetProjectID or
	 * targetProjectID is null
	 * @param inputBinding
	 * @return
	 */
	List<AttributeDependencyTO> getDependencies(Map<String, Object> inputBinding) {
		List<AttributeDependencyTO> dependencies = null
		//uncomment this to activate this attribute change script
		/*WorkItemContext workItemContext = (WorkItemContext)inputBinding.get("workItemContext")
		TWorkItemBean workItemBean = workItemContext.getWorkItemBean()
		Integer projectID = workItemBean.getProjectID()
		if (targetProjectID==null || projectID.intValue()==targetProjectID) {
			dependencies = new ArrayList<>()
			ChangeListValueDependency.configureAttributeAsConditionallyChangeListValue(
				workItemContext, dependentAttribut, triggerAttribut, dependencies)
		}*/
		return dependencies;
	}
}

Freigabe Manager-Änderung nach Zustand#

Ermöglicht die Änderung des Managers und erzwingt das Attribut „Build“ in bestimmten Zuständen.

package script.attributeChange
import com.aurel.track.admin.customize.scripting.BINDING_PARAMS
import com.aurel.track.beans.TWorkItemBean
import com.aurel.track.fieldType.constants.SystemFields
import com.aurel.track.fieldType.runtime.base.WorkItemContext
import com.aurel.track.item.attributeDependency.AttributeDependencyTO
import com.aurel.track.item.attributeDependency.ReadOnlyDependency
import com.aurel.track.item.attributeDependency.RequiredDependency
import com.aurel.track.util.event.IEventHandler

/**
 * Enables changing the manager and enforces the build attribute as required in certain statuses
 */
public class EnableManagerOnStatus implements IEventHandler {

	/**
	 * Applies the constrains configured through an ajax request called on each status change
	 */
	def public Map<String, Object> handleEvent(Map<String, Object> inputBinding) {
		WorkItemContext workItemContext = (WorkItemContext)inputBinding.get(BINDING_PARAMS.WORKITEM_CONTEXT)
		TWorkItemBean workItemBean = workItemContext.getWorkItemBean()
		Integer statusID = workItemBean.getStateID()
		ReadOnlyDependency.configureAttributeAsReadOnly(workItemContext, SystemFields.MANAGER, statusID.intValue()!=1, true)
		RequiredDependency.configureAttributeAsRequired(workItemContext, SystemFields.BUILD, statusID.intValue()!=1)
		return inputBinding
	}

	/**
	 * Defines two attributes depending on a third attribute
	 * The manager attribute will be set as read only if the status is not 1
	 * The build attribute will be set as required if the status is not 1
	 * @param inputBinding
	 * @return
	 */
	List<AttributeDependencyTO> getDependencies(Map<String, Object> inputBinding) {
		List<AttributeDependencyTO> dependencies = new ArrayList<>();
		//uncomment this to activate this attribute change script
		/*WorkItemContext workItemContext = (WorkItemContext)inputBinding.get(BINDING_PARAMS.WORKITEM_CONTEXT)
		TWorkItemBean workItemBean = workItemContext.getWorkItemBean()
		Integer statusID = workItemBean.getStateID()
		ReadOnlyDependency.configureAttributeAsConditionallyReadOnly(workItemContext, SystemFields.MANAGER, SystemFields.STATE, dependencies);
		ReadOnlyDependency.configureAttributeAsReadOnly(workItemContext, SystemFields.MANAGER, statusID.intValue()!=1, true)
		RequiredDependency.configureAttributeAsConditionallyRequired(workItemContext, SystemFields.BUILD, SystemFields.STATE, dependencies);
		RequiredDependency.configureAttributeAsRequired(workItemContext, SystemFields.BUILD, statusID.intValue()!=1)*/
		return dependencies
	}
}

Kommentar erzwingen#

Erzwinge die Eingabe eines Kommentars je nach Zustand.

package script.attributeChange
import com.aurel.track.admin.customize.scripting.BINDING_PARAMS
import com.aurel.track.beans.TWorkItemBean;
import com.aurel.track.fieldType.constants.SystemFields
import com.aurel.track.fieldType.runtime.base.WorkItemContext
import com.aurel.track.item.attributeDependency.AttributeDependencyTO
import com.aurel.track.item.attributeDependency.RequiredDependency
import com.aurel.track.util.event.IEventHandler;


/**
 * Enforces the comment as required for status changes
 */
public class RequireCommentOnStatus implements IEventHandler {

	/**
	 * Enforce the Comment as required if status changed to a certain value
	 */
	def public Map<String, Object> handleEvent(Map<String, Object> inputBinding) {
		WorkItemContext workItemContext = (WorkItemContext)inputBinding.get(BINDING_PARAMS.WORKITEM_CONTEXT)
		TWorkItemBean workItemBean = workItemContext.getWorkItemBean()
		Integer statusID = workItemBean.getStateID()
		RequiredDependency.configureAttributeAsRequired(workItemContext, SystemFields.COMMENT, statusID.intValue()==1075)
		return inputBinding
	}

	/**
	 * The Comment attribute will depend on status change
	 * @param inputBinding
	 * @return
	 */
	List<AttributeDependencyTO> getDependencies(Map<String, Object> inputBinding) {
		WorkItemContext workItemContext = (WorkItemContext)inputBinding.get(BINDING_PARAMS.WORKITEM_CONTEXT)
		List<AttributeDependencyTO> dependencies = new ArrayList<>();
		//uncomment this to activate this attribute change script
		//RequiredDependency.configureAttributeAsConditionallyRequired(workItemContext, SystemFields.COMMENT, SystemFields.STATE, dependencies);
		return dependencies;
	}
}

Durchschnittliche Bearbeitungszeit vorschlagen#

Schlägt eine Bearbeitungszeit vor, die auf der durchschnittlichen Bearbeitungszeit nach Verantwortlichem und Vorgangstyp basiert.

package script.attributeChange
import com.aurel.track.admin.customize.lists.systemOption.ItemTypeBL
import com.aurel.track.admin.customize.lists.systemOption.ItemTypeFlag
import com.aurel.track.admin.customize.scripting.BINDING_PARAMS
import com.aurel.track.admin.customize.treeConfig.field.FieldBL
import com.aurel.track.admin.customize.treeConfig.field.GeneralSettingsBL
import com.aurel.track.beans.TFieldBean
import com.aurel.track.beans.TWorkItemBean
import com.aurel.track.fieldType.constants.SystemFields
import com.aurel.track.fieldType.runtime.base.WorkItemContext
import com.aurel.track.fieldType.runtime.custom.calculated.throughput.AverageThrouhputBL
import com.aurel.track.fieldType.runtime.custom.calculated.throughput.CalendarWorkingHoursUtil
import com.aurel.track.fieldType.runtime.custom.calculated.throughput.IntervalUtil
import com.aurel.track.fieldType.runtime.custom.calculated.throughput.WorkingHourSection
import com.aurel.track.fieldType.types.system.text.SystemDuration.DurationParametersCode
import com.aurel.track.item.attributeDependency.AttributeDependencyTO
import com.aurel.track.resourceCalendar.itemDuration.ItemThoughputDurationBL

/**
 * Suggests a processing time based on average processing time by responsible and item type
 * @author tamasruff
 *
 */
public class SetAverageProcessingTime {
	private static String processingTimeAttributeName = "ProcessingTime"
	private static String throughputAttributeName = "Throughput"
	private static int daysBefore = 30
	
	/**
	 * Sets a the value of processingTimeAttributeName attribute to the average throughput time based on responsible and item type
	 * @param inputBinding
	 * @return
	 */
	public Map<String, Object> handleEvent(Map<String, Object> inputBinding) {
		TFieldBean averageProcessingTimeFieldBean = FieldBL.loadByName(processingTimeAttributeName)
		TFieldBean throughputFieldBean = FieldBL.loadByName(throughputAttributeName)
		if (averageProcessingTimeFieldBean!=null && throughputFieldBean!=null) {
			Integer throughputFieldID = throughputFieldBean.getObjectID()
			Integer averageProcessingTimeFieldID = averageProcessingTimeFieldBean.getObjectID()
			WorkItemContext workItemContext = (WorkItemContext)inputBinding.get(BINDING_PARAMS.WORKITEM_CONTEXT);
			TWorkItemBean workItemBean = inputBinding.get(BINDING_PARAMS.ITEM)
			Date datedFrom = IntervalUtil.getEarliestDate(daysBefore, null);
			double workHours = 8.0
			List<Integer> itemFilterFieldIDs = Arrays.asList(SystemFields.RESPONSIBLE, SystemFields.ISSUETYPE)
			Long averageDurationInMinutes = AverageThrouhputBL.getAverageThrougputMinutes(workItemBean, itemFilterFieldIDs, throughputFieldID, datedFrom)
			Double averageDurationInDays = CalendarWorkingHoursUtil.getDurationInDays(averageDurationInMinutes, workHours)
			if (averageDurationInDays==null) {
				averageDurationInDays = 1;
			}
			workItemBean.setAttribute(averageProcessingTimeFieldID, averageDurationInDays.intValue())
		}
		return inputBinding
	}

	/**
	 * Gets the dependencies for computing the default processing time attribute for task type items
	 * @param inputBinding
	 * @return
	 */
	List<AttributeDependencyTO> getDependencies(Map<String, Object> inputBinding) {
		List<AttributeDependencyTO> dependencies = new ArrayList<>()
		//uncomment this to activate this attribute change script
		/*WorkItemContext workItemContext = (WorkItemContext)inputBinding.get(BINDING_PARAMS.WORKITEM_CONTEXT)
		TWorkItemBean workItemBean = (TWorkItemBean)inputBinding.get(BINDING_PARAMS.ITEM)
		if (ItemTypeBL.isOfFlag(workItemBean.getListTypeID(), ItemTypeFlag.TASK.getFlag())) {
			TFieldBean averageProcessingTimeField = FieldBL.loadByName(processingTimeAttributeName)
			if (averageProcessingTimeField!=null) {
				Integer fieldID = averageProcessingTimeField.getObjectID()
				AttributeDependencyTO responsibleDependency = new AttributeDependencyTO(fieldID, SystemFields.RESPONSIBLE, true, false)
				dependencies.add(responsibleDependency);
				AttributeDependencyTO itemTypeDependency = new AttributeDependencyTO(fieldID, SystemFields.ISSUETYPE, true, false)
				dependencies.add(itemTypeDependency);
			}
		}*/
		return dependencies;
	}

}