protected PeopleFlowBo getPeopleFlowBoByName(String namespaceCode, String name) {
    if (StringUtils.isBlank(namespaceCode)) {
      throw new RiceIllegalArgumentException("namespaceCode was a null or blank value");
    }
    if (StringUtils.isBlank(name)) {
      throw new RiceIllegalArgumentException("name was a null or blank value");
    }

    QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
    criteria.setPredicates(
        equal(KewImplConstants.PropertyConstants.NAMESPACE_CODE, namespaceCode),
        equal(KewImplConstants.PropertyConstants.NAME, name));
    Collection<PeopleFlowBo> peopleFlows =
        dataObjectService.findMatching(PeopleFlowBo.class, criteria.build()).getResults();

    if (CollectionUtils.isEmpty(peopleFlows)) {
      return null;
    } else if (peopleFlows.size() > 1) {
      throw new RiceIllegalStateException(
          "Found more than one PeopleFlow with the given namespace code '"
              + namespaceCode
              + "' and name '"
              + name
              + "'");
    }
    return peopleFlows.iterator().next();
  }
 @Override
 public List<StateInfo> performSearch(
     LookupForm lookupForm, Map<String, String> searchCriteria, boolean bounded) {
   QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
   List<Predicate> pList = new ArrayList<Predicate>();
   // Code Changed for JIRA-8997 - SONAR Critical issues - Performance - Inefficient use of keySet
   // iterator instead of entrySet iterator
   for (Map.Entry<String, String> entry : searchCriteria.entrySet()) {
     String fieldName = entry.getKey();
     String value = entry.getValue();
     if (value != null && !value.isEmpty()) {
       if (fieldName.equals("maxResultsToReturn")) {
         qBuilder.setMaxResults(Integer.parseInt(value));
         continue;
       }
       pList.add(PredicateFactory.equal(fieldName, value));
     }
   }
   if (!pList.isEmpty()) {
     qBuilder.setPredicates(PredicateFactory.and(pList.toArray(new Predicate[pList.size()])));
   }
   try {
     return this.getStateService().searchForStates(qBuilder.build(), getContextInfo());
   } catch (Exception ex) {
     throw new RuntimeException(ex);
   }
 }
  protected void populateRoutingExceptionResponsibility(DocumentConfigurationViewForm form) {
    DocumentType docType = form.getDocumentType();
    List<ResponsibilityForDisplay> responsibilities = new ArrayList<ResponsibilityForDisplay>();
    while (docType != null) {
      QueryByCriteria.Builder builder = QueryByCriteria.Builder.create();
      Predicate p =
          and(
              equal("template.namespaceCode", KRADConstants.KUALI_RICE_WORKFLOW_NAMESPACE),
              equal(
                  "template.name", KewApiConstants.EXCEPTION_ROUTING_RESPONSIBILITY_TEMPLATE_NAME),
              equal("active", "Y"),
              equal("attributes[documentTypeName]", docType.getName()));
      builder.setPredicates(p);
      List<Responsibility> resps =
          getResponsibilityService().findResponsibilities(builder.build()).getResults();

      for (Responsibility r : resps) {
        if (responsibilities.isEmpty()) {
          responsibilities.add(new ResponsibilityForDisplay(r, false));
        } else {
          responsibilities.add(new ResponsibilityForDisplay(r, true));
        }
      }
      docType = docType.getParentDocType();
    }
    form.setExceptionResponsibilities(responsibilities);
    for (ResponsibilityForDisplay responsibility : responsibilities) {
      List<String> roleIds =
          getResponsibilityService().getRoleIdsForResponsibility(responsibility.getResp().getId());
      if (!roleIds.isEmpty()) {
        form.getResponsibilityRoles()
            .put(responsibility.getResponsibilityId(), getRoleService().getRoles(roleIds));
      }
    }
  }
  protected static List<String> getOptionKeys(
      CourseOfferingCreateWrapper createWrapper, CourseOfferingInfo existingCO) {

    List<String> optionKeys =
        getDefaultOptionKeysService().getDefaultOptionKeysForCopySingleCourseOffering();

    if (createWrapper.isExcludeInstructorInformation()) {
      optionKeys.add(CourseOfferingSetServiceConstants.NO_INSTRUCTORS_OPTION_KEY);
    }

    if (createWrapper.isExcludeSchedulingInformation()) {
      optionKeys.add(CourseOfferingSetServiceConstants.NO_SCHEDULE_OPTION_KEY);
    }

    if (createWrapper.isExcludeCancelledActivityOfferings()) {
      optionKeys.add(CourseOfferingSetServiceConstants.IGNORE_CANCELLED_AO_OPTION_KEY);
    }

    ContextInfo contextInfo = ContextUtils.createDefaultContextInfo();

    try {
      // if source term differs from target term determine if add suffix or not
      if (StringUtils.equals(existingCO.getTermId(), createWrapper.getTerm().getId())) {
        optionKeys.add(CourseOfferingServiceConstants.APPEND_COURSE_OFFERING_IN_SUFFIX_OPTION_KEY);
      } else {
        QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
        qbcBuilder.setPredicates(
            PredicateFactory.and(
                PredicateFactory.like(
                    "courseOfferingCode", existingCO.getCourseOfferingCode() + "%"),
                PredicateFactory.equalIgnoreCase("atpId", createWrapper.getTerm().getId())));
        QueryByCriteria criteria = qbcBuilder.build();
        List<String> courseOfferingIds =
            CourseOfferingManagementUtil.getCourseOfferingService()
                .searchForCourseOfferingIds(criteria, contextInfo);

        if (courseOfferingIds.size() > 0) {
          optionKeys.add(
              CourseOfferingServiceConstants.APPEND_COURSE_OFFERING_IN_SUFFIX_OPTION_KEY);
        }
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    //  According to Jira 4353 copy the title from CO instead of CLU. So set the property not to
    // copy from CLU
    optionKeys.add(CourseOfferingSetServiceConstants.NOT_COURSE_TITLE_OPTION_KEY);
    return optionKeys;
  }
 protected QueryByCriteria setUpEntityLookupCriteria(String principalId) {
   PersonServiceImpl personServiceImpl =
       (PersonServiceImpl)
           KIMServiceLocatorInternal.getService(KimApiServiceLocator.KIM_PERSON_SERVICE);
   Map<String, String> criteria = new HashMap<String, String>(1);
   criteria.put(KIMPropertyConstants.Person.PRINCIPAL_ID, principalId);
   Map<String, String> entityCriteria =
       personServiceImpl.convertPersonPropertiesToEntityProperties(criteria);
   entityCriteria.put("entityTypeContactInfos.entityTypeCode", "PERSON");
   QueryByCriteria.Builder query = QueryByCriteria.Builder.create();
   List<Predicate> predicates = new ArrayList<Predicate>();
   for (String key : entityCriteria.keySet()) {
     predicates.add(like(key, entityCriteria.get(key)));
   }
   if (!predicates.isEmpty()) {
     query.setPredicates(and(predicates.toArray(new Predicate[predicates.size()])));
   }
   return query.build();
 }
  @SuppressWarnings("unchecked")
  public void populateRoutingResponsibilities(DocumentConfigurationViewForm form) {
    // pull all the responsibilities
    // merge the data and attach to route levels
    // pull the route levels and store on form
    // List<RouteNode> routeNodes = getRouteNodeService().getFlattenedNodes(form.getDocumentType(),
    // true);
    Map<String, List<Role>> respToRoleMap = new HashMap<String, List<Role>>();
    List<ProcessDefinitionBo> processes =
        (List<ProcessDefinitionBo>) form.getDocumentType().getProcesses();
    if (!(processes.isEmpty())) {
      RouteNode rootNode = processes.get(0).getInitialRouteNode();
      LinkedHashMap<String, RouteNode> routeNodeMap = new LinkedHashMap<String, RouteNode>();
      flattenRouteNodes(rootNode, routeNodeMap);

      form.setRouteNodes(new ArrayList<RouteNode>(routeNodeMap.values()));
      // pull all the responsibilities and store into a map for use by the JSP

      // FILTER TO THE "Review" template only
      // pull responsibility roles
      DocumentType docType = form.getDocumentType();
      Set<Responsibility> responsibilities = new HashSet<Responsibility>();
      Map<String, List<ResponsibilityForDisplay>> nodeToRespMap =
          new LinkedHashMap<String, List<ResponsibilityForDisplay>>();
      while (docType != null) {
        QueryByCriteria.Builder builder = QueryByCriteria.Builder.create();
        Predicate p =
            and(
                equal("template.namespaceCode", KRADConstants.KUALI_RICE_WORKFLOW_NAMESPACE),
                equal("template.name", KewApiConstants.DEFAULT_RESPONSIBILITY_TEMPLATE_NAME),
                equal("active", "Y"),
                equal("attributes[documentTypeName]", docType.getName()));
        builder.setPredicates(p);
        List<Responsibility> resps =
            getResponsibilityService().findResponsibilities(builder.build()).getResults();

        for (Responsibility r : resps) {
          String routeNodeName =
              r.getAttributes().get(KimConstants.AttributeConstants.ROUTE_NODE_NAME);
          if (StringUtils.isNotBlank(routeNodeName)) {
            if (!nodeToRespMap.containsKey(routeNodeName)) {
              nodeToRespMap.put(routeNodeName, new ArrayList<ResponsibilityForDisplay>());
              nodeToRespMap.get(routeNodeName).add(new ResponsibilityForDisplay(r, false));
            } else {
              // check if the responsibility in the existing list is for the current document
              // if so, OK to add.  Otherwise, a lower level document has overridden this
              // responsibility (since we are walking up the hierarchy
              if (nodeToRespMap
                  .get(routeNodeName)
                  .get(0)
                  .getDetails()
                  .get(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME)
                  .equals(docType.getName())) {
                nodeToRespMap.get(routeNodeName).add(new ResponsibilityForDisplay(r, false));
              } else { // doc type name did not match, mark as overridden
                nodeToRespMap.get(routeNodeName).add(new ResponsibilityForDisplay(r, true));
              }
            }
            responsibilities.add(r);
          }
        }
        docType = docType.getParentDocType();
      }
      form.setResponsibilityMap(nodeToRespMap);

      for (Responsibility responsibility : responsibilities) {
        List<String> roleIds =
            getResponsibilityService().getRoleIdsForResponsibility(responsibility.getId());
        if (!roleIds.isEmpty()) {
          respToRoleMap.put(responsibility.getId(), getRoleService().getRoles(roleIds));
        }
      }
    }
    form.setResponsibilityRoles(respToRoleMap);
  }