protected static void processJobDescription()

in framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/ManifoldCF.java [4499:4761]


  protected static void processJobDescription(org.apache.manifoldcf.crawler.jobs.JobDescription jobDescription, ConfigurationNode jobNode)
    throws ManifoldCFException
  {
    // Walk through the node's children
    Map<String,PipelineStage> pipelineStages = new HashMap<String,PipelineStage>();
    for (int i = 0; i < jobNode.getChildCount(); i++)
    {
      ConfigurationNode child = jobNode.findChild(i);
      String childType = child.getType();
      if (childType.equals(JOBNODE_ID))
      {
        if (child.getValue() == null)
          throw new ManifoldCFException("Job id node requires a value");
        jobDescription.setID(new Long(child.getValue()));
      }
      else if (childType.equals(JOBNODE_DESCRIPTION))
      {
        jobDescription.setDescription(child.getValue());
      }
      else if (childType.equals(JOBNODE_CONNECTIONNAME))
      {
        jobDescription.setConnectionName(child.getValue());
      }
      else if (childType.equals(JOBNODE_PIPELINESTAGE))
      {
        String stageID = null;
        String stagePrerequisite = null;
        String stageIsOutput = null;
        String stageConnectionName = null;
        String stageDescription = null;
        ConfigurationNode stageSpecification = null;
        for (int q = 0; q < child.getChildCount(); q++)
        {
          ConfigurationNode cn = child.findChild(q);
          if (cn.getType().equals(JOBNODE_STAGEID))
            stageID = cn.getValue();
          else if (cn.getType().equals(JOBNODE_STAGEPREREQUISITE))
            stagePrerequisite = cn.getValue();
          else if (cn.getType().equals(JOBNODE_STAGEISOUTPUT))
            stageIsOutput = cn.getValue();
          else if (cn.getType().equals(JOBNODE_STAGECONNECTIONNAME))
            stageConnectionName = cn.getValue();
          else if (cn.getType().equals(JOBNODE_STAGEDESCRIPTION))
            stageDescription = cn.getValue();
          else if (cn.getType().equals(JOBNODE_STAGESPECIFICATION))
          {
            stageSpecification = cn;
          }
          else
            throw new ManifoldCFException("Found an unexpected node type: '"+cn.getType()+"'");
        }
        if (stageID == null)
          throw new ManifoldCFException("Missing required field: '"+JOBNODE_STAGEID+"'");
        if (stageIsOutput == null)
          throw new ManifoldCFException("Missing required field: '"+JOBNODE_STAGEISOUTPUT+"'");
        if (stageConnectionName == null)
          throw new ManifoldCFException("Missing required field: '"+JOBNODE_STAGECONNECTIONNAME+"'");
        pipelineStages.put(stageID,new PipelineStage(stagePrerequisite,stageIsOutput.equals("true"),
          stageConnectionName,stageDescription,stageSpecification));
      }
      else if (childType.equals(JOBNODE_NOTIFICATIONSTAGE))
      {
        String stageConnectionName = null;
        String stageDescription = null;
        ConfigurationNode stageSpecification = null;
        for (int q = 0; q < child.getChildCount(); q++)
        {
          ConfigurationNode cn = child.findChild(q);
          if (cn.getType().equals(JOBNODE_STAGECONNECTIONNAME))
            stageConnectionName = cn.getValue();
          else if (cn.getType().equals(JOBNODE_STAGEDESCRIPTION))
            stageDescription = cn.getValue();
          else if (cn.getType().equals(JOBNODE_STAGESPECIFICATION))
          {
            stageSpecification = cn;
          }
          else
            throw new ManifoldCFException("Found an unexpected node type: '"+cn.getType()+"'");
        }
        if (stageConnectionName == null)
          throw new ManifoldCFException("Missing required field: '"+JOBNODE_STAGECONNECTIONNAME+"'");
        Specification os = jobDescription.addNotification(stageConnectionName,stageDescription);
        os.clearChildren();
        if (stageSpecification != null)
        {
          for (int j = 0; j < stageSpecification.getChildCount(); j++)
          {
            ConfigurationNode cn = stageSpecification.findChild(j);
            os.addChild(os.getChildCount(),new SpecificationNode(cn));
          }
        }

      }
      else if (childType.equals(JOBNODE_DOCUMENTSPECIFICATION))
      {
        // Get the job's document specification, clear out the children, and copy new ones from the child.
        Specification ds = jobDescription.getSpecification();
        ds.clearChildren();
        for (int j = 0; j < child.getChildCount(); j++)
        {
          ConfigurationNode cn = child.findChild(j);
          ds.addChild(ds.getChildCount(),new SpecificationNode(cn));
        }
      }
      else if (childType.equals(JOBNODE_STARTMODE))
      {
        jobDescription.setStartMethod(mapToStartMode(child.getValue()));
      }
      else if (childType.equals(JOBNODE_RUNMODE))
      {
        jobDescription.setType(mapToRunMode(child.getValue()));
      }
      else if (childType.equals(JOBNODE_HOPCOUNTMODE))
      {
        jobDescription.setHopcountMode(mapToHopcountMode(child.getValue()));
      }
      else if (childType.equals(JOBNODE_PRIORITY))
      {
        try
        {
          jobDescription.setPriority(Integer.parseInt(child.getValue()));
        }
        catch (NumberFormatException e)
        {
          throw new ManifoldCFException(e.getMessage(),e);
        }
      }
      else if (childType.equals(JOBNODE_RECRAWLINTERVAL))
      {
        jobDescription.setInterval(interpretInterval(child.getValue()));
      }
      else if (childType.equals(JOBNODE_MAXRECRAWLINTERVAL))
      {
        jobDescription.setMaxInterval(interpretInterval(child.getValue()));
      }
      else if (childType.equals(JOBNODE_EXPIRATIONINTERVAL))
      {
        jobDescription.setExpiration(interpretInterval(child.getValue()));
      }
      else if (childType.equals(JOBNODE_RESEEDINTERVAL))
      {
        jobDescription.setReseedInterval(interpretInterval(child.getValue()));
      }
      else if (childType.equals(JOBNODE_HOPCOUNT))
      {
        // Read the hopcount values
        String linkType = null;
        String hopCount = null;
        
        int q = 0;
        while (q < child.getChildCount())
        {
          ConfigurationNode cn = child.findChild(q++);
          if (cn.getType().equals(JOBNODE_LINKTYPE))
            linkType = cn.getValue();
          else if (cn.getType().equals(JOBNODE_COUNT))
            hopCount = cn.getValue();
          else
            throw new ManifoldCFException("Found an unexpected node type: '"+cn.getType()+"'");
        }
        if (linkType == null)
          throw new ManifoldCFException("Missing required field: '"+JOBNODE_LINKTYPE+"'");
        if (hopCount == null)
          throw new ManifoldCFException("Missing required field: '"+JOBNODE_COUNT+"'");
        jobDescription.addHopCountFilter(linkType,new Long(hopCount));
      }
      else if (childType.equals(JOBNODE_SCHEDULE))
      {
        // Create a schedule record.
        String timezone = null;
        Long duration = null;
        boolean requestMinimum = false;
        EnumeratedValues dayOfWeek = null;
        EnumeratedValues monthOfYear = null;
        EnumeratedValues dayOfMonth = null;
        EnumeratedValues year = null;
        EnumeratedValues hourOfDay = null;
        EnumeratedValues minutesOfHour = null;
            
        // Now, walk through children of the schedule node.
        int q = 0;
        while (q < child.getChildCount())
        {
          ConfigurationNode scheduleField = child.findChild(q++);
          String fieldType = scheduleField.getType();
          if (fieldType.equals(JOBNODE_REQUESTMINIMUM))
          {
            requestMinimum = scheduleField.getValue().equals("true");
          }
          else if (fieldType.equals(JOBNODE_TIMEZONE))
          {
            timezone = scheduleField.getValue();
          }
          else if (fieldType.equals(JOBNODE_DURATION))
          {
            duration = new Long(scheduleField.getValue());
          }
          else if (fieldType.equals(JOBNODE_DAYOFWEEK))
          {
            dayOfWeek = processEnumeratedValues(scheduleField);
          }
          else if (fieldType.equals(JOBNODE_MONTHOFYEAR))
          {
            monthOfYear = processEnumeratedValues(scheduleField);
          }
          else if (fieldType.equals(JOBNODE_YEAR))
          {
            year = processEnumeratedValues(scheduleField);
          }
          else if (fieldType.equals(JOBNODE_DAYOFMONTH))
          {
            dayOfMonth = processEnumeratedValues(scheduleField);
          }
          else if (fieldType.equals(JOBNODE_HOUROFDAY))
          {
            hourOfDay = processEnumeratedValues(scheduleField);
          }
          else if (fieldType.equals(JOBNODE_MINUTESOFHOUR))
          {
            minutesOfHour = processEnumeratedValues(scheduleField);
          }
          else
            throw new ManifoldCFException("Unrecognized field in schedule record: '"+fieldType+"'");
        }
        ScheduleRecord sr = new ScheduleRecord(dayOfWeek,monthOfYear,dayOfMonth,year,hourOfDay,minutesOfHour,timezone,duration,requestMinimum);
        // Add the schedule record to the job.
        jobDescription.addScheduleRecord(sr);
      }
      else
        throw new ManifoldCFException("Unrecognized job field: '"+childType+"'");
    }
    
    // Do pipeline stages.  These must be ordered so that the prerequisites are always done first.
    List<String> orderedStageNames = new ArrayList<String>();
    Set<String> keysSeen = new HashSet<String>();
    for (String stageName : pipelineStages.keySet())
    {
      PipelineStage ps = pipelineStages.get(stageName);
      if (keysSeen.contains(stageName))
        continue;
      // Look at the prerequisite; insert them beforehand if they aren't already there
      addStage(stageName,orderedStageNames,keysSeen,pipelineStages);
    }
    
    // Now, add stages to job in  order, and map to ordinals
    int k = 0;
    for (String stageName : orderedStageNames)
    {
      PipelineStage ps = pipelineStages.get(stageName);
      ps.ordinal = k++;
      int prerequisite = (ps.prerequisite == null)?-1:pipelineStages.get(ps.prerequisite).ordinal;
      Specification os = jobDescription.addPipelineStage(prerequisite,ps.isOutput,ps.connectionName,ps.description);
      os.clearChildren();
      if (ps.specification != null)
      {
        for (int j = 0; j < ps.specification.getChildCount(); j++)
        {
          ConfigurationNode cn = ps.specification.findChild(j);
          os.addChild(os.getChildCount(),new SpecificationNode(cn));
        }
      }
    }
  }