3.10 Enabling a Task for the Object View

The Object view provides tools so users can manage by first selecting one or more objects, then selecting the task to perform. When you select objects in the Object view, iManager provides a way to view the list of available tasks for that object.To do this, tasks must be able to accept object names programmatically, rather than through the UI; inform the iManager framework on which object types it can work; and specify whether they can accept more than one object at a time.

To configure your tasks to work properly with the Object view requires the following:

3.10.1 Register a Task to Work with Specific Object Types

To specify the object types on which your task can operate, add the names of the object classes to the task registration file using the <object-type-name> element, as shown in the following example:

 <task>
    <id>base.ClearIntruderLockout</id>
    <version>2.0.0.0</version>
    <required-version>2.7.0</required-version>
    <type>snapinTask</type>
    <class-name>java:com.novell.emframe.base.ClearLockoutTask</class-name>
    <merge-template>base.ClrLock</merge-template>
    <error-template>dev.GenFatal</error-template>
    <description>This task clears the intruder lockout flag</description>
    <resource-properties-file>BaseResources</resource-properties-file>
    <display-name-key>ClearLockoutTaskDisplayName</display-name-key>
    <object-type-name>User</object-type-name>
    <rights-assignment>
       <attribute-name>Locked By Intruder</attribute-name>
       <privilege>Supervisor</privilege>
    </rights-assignment>
    <rights-assignment>
       <attribute-name>Login Intruder Attempts</attribute-name>
       <privilege>Supervisor</privilege>
    </rights-assignment>
    <role-assignment>Help Desk Management</role-assignment>
    <gadget-assignable>false</gadget-assignable>
    <frame-type>Full</frame-type>
 </task>
 

In this example, the <object-type-name>User</object-type-name> line enables the task for User objects. All eDirectory classes and auxiliary classes are valid values. The special types, [root], [containers], and [leafs] are also valid types. Specifying [root] enables a task to operate on the root of the tree, specifying [containers] enables a task to operate on all container-type objects, and specifying [leafs] enables a task to operate on all leaf-type objects.

If your task operates on multiple object types, use mulitple <object-type-name> elements in the task registration file. For example:

 <task>
   . . .
   <object-type-name>User</object-type-name>
   <object-type-name>Group</object-type-name>
   . . .
 </task>
 

If your task can modify multiple objects at the same time, specify that the task is enabled for multiple-object operations (moo) using the <url-param> element. For example:

 <task>
    . . .
    <url-param>
       <param-key>mooEnabled</param-key>
       <param-value>true</param-value>
    </url-param>
    . . .
 </task>
 

3.10.2 Retrieve Objects from iManager

In the Object view, users can select one or more objects. The selected objects are passed to the task as a packed string in the targetNames parameter.

Single Object Selection

If your task works on only a single object, use the com.novell.emframe.dev.eMFrameUtils.getSingleTarget method to get the name of the selected object from iManager. If the object was not selected in the Object view, getSingleTarget returns an empty string.

Typically the first screen of a task allows the user to specify the object on which the task should operate. If the object name is the only information collected on the first screen, you should skip the first screen, as shown in the following example:

 public boolean execute(TaskContext context, Properties resultStrings)
 {
   this.context=context;
   this.resultStrings=resultStrings;
   req=context.getHttpServletRequest();
 
   String nextState=req.getParameter(eMFrameConsts.NEXTSTATE);
   String targetName = eMFrameUtils.getSingleTarget(req);
   if(targetName.length() > 0)
   {
     nextState = "doClearLockout";
   }
 
   if(nextState.equalsIgnoreCase(eMFrameConsts.INITIALSTATE))
   {
     return showInitialForm();
   }
   else if(nextState.equalsIgnoreCase("doClearLockout"))
   {
     if(targetName.length() == 0)
     {
       targetName = req.getParameter("single");
     }
     if (doClearLockout(targetName))
 
   {
 
      setUIPage("dev/GenConf.jsp");
 
      return true;
 
   }
 
   else
 
   {
 
      setUIPage("dev/GenFatal.jsp");
 
      return true;
 
      }
 
 throw new RuntimeException("Task received invalid nextState:"+nextState);
 }
 
 
 

In this example, the value returned by getSingleTarget (targetName) is used to determine whether the object has already been selected by testing whether the length of the name is greater than zero. If so, the nextState is set to “doClearLockout,” which clears the lockout for the specified object without stopping at the first screen, where the object is specified. Because the object was selected in the Object view, the first screen is unnecessary. If the Object view was not used (targetName.length() == 0), the task displays the first screen, and the getParameter method returns the object selected.

If the first screen collects information in addition to the object name, you should display the first screen, but populate the object name field with the name of the object selected in the Object view. For a task that operates on a single object at a time, you can accomplish this by calling the getSingleTarget method within the JSP:

 <INPUT type=text name="single"
 value="<%= eMFrameUtils.toTag(eMFrameUtils.getSingleTarget(request)) %>" />
 

Multiple Object Selection

If your task operates on multiple objects, use the TargetObjects class to enumerate the selected objects, as shown in the following example:

 String targetNames = req.getParameter("targetNames");
 TargetObjects targetObjects = new TargetObjects(targetNames, context);
 
 if(targetObjects.isMultiple())
 {
   ObjectEntryEnumeration enum = targetObjects.getObjectEntryEnumeration();
   // do work with multiple objects
 }
 else
 {
   ObjectEntry oe = targetObjects.getObjectEntry();
   // do work for single object
 }