コード例 #1
0
 @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);
   }
 }
 @Override
 protected List<Predicate> getPredicates(ProposalBudgetForm model) {
   String budgetCategoryTypeCode =
       model.getAddProjectBudgetLineItemHelper().getBudgetCategoryTypeCode();
   List<Predicate> predicates = new ArrayList<>();
   if (StringUtils.isNotEmpty(budgetCategoryTypeCode)) {
     predicates.add(PredicateFactory.equal(BUDGET_CATEGORY_TYPE_CODE, budgetCategoryTypeCode));
   } else {
     predicates.add(
         PredicateFactory.notEqual(
             BUDGET_CATEGORY_TYPE_CODE, getPersonnelBudgetCategoryTypeCode()));
   }
   return predicates;
 }
コード例 #3
0
  protected PropAwardPersonRoleServiceImpl getPropAwardPersonRoleService() {
    final PropAwardPersonRoleServiceImpl roleService = new PropAwardPersonRoleServiceImpl();
    final DataObjectService dataObjectService = context.mock(DataObjectService.class);
    final ParameterService parameterService = context.mock(ParameterService.class);
    final SponsorHierarchyService hierarchyService = context.mock(SponsorHierarchyService.class);

    context.checking(
        new Expectations() {
          {
            one(parameterService)
                .getParameterValueAsBoolean(
                    Constants.MODULE_NAMESPACE_PROPOSAL_DEVELOPMENT,
                    Constants.PARAMETER_COMPONENT_DOCUMENT,
                    PropAwardPersonRoleServiceImpl.ALL_SPONSOR_HIERARCHY_NIH_MULTI_PI);
            will(returnValue(true));
            one(dataObjectService)
                .findMatching(
                    PropAwardPersonRole.class,
                    QueryByCriteria.Builder.forAttribute(
                            "sponsorHierarchyName",
                            PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY)
                        .build());
            will(returnValue(roleListBuilder.build()));
          }
        });

    final QueryByCriteria.Builder criteriaCoInvestigator1 =
        QueryByCriteria.Builder.create()
            .setPredicates(
                PredicateFactory.equal("code", ContactRole.COI_CODE),
                PredicateFactory.equal(
                    "sponsorHierarchyName",
                    PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY));
    final PropAwardPersonRole roleCoInvestigator1 =
        createTestRole(
            3L, ContactRole.COI_CODE, PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY);
    context.checking(
        new Expectations() {
          {
            one(parameterService)
                .getParameterValueAsBoolean(
                    Constants.MODULE_NAMESPACE_PROPOSAL_DEVELOPMENT,
                    Constants.PARAMETER_COMPONENT_DOCUMENT,
                    PropAwardPersonRoleServiceImpl.ALL_SPONSOR_HIERARCHY_NIH_MULTI_PI);
            will(returnValue(true));
            one(dataObjectService)
                .findUnique(PropAwardPersonRole.class, criteriaCoInvestigator1.build());
            will(returnValue(roleCoInvestigator1));
          }
        });

    final QueryByCriteria.Builder criteriaCoInvestigator2 =
        QueryByCriteria.Builder.create()
            .setPredicates(
                PredicateFactory.equal("code", ContactRole.COI_CODE),
                PredicateFactory.equal(
                    "sponsorHierarchyName",
                    PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY));
    final PropAwardPersonRole roleCoInvestigator2 =
        createTestRole(
            3L, ContactRole.COI_CODE, PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY);
    context.checking(
        new Expectations() {
          {
            one(parameterService)
                .getParameterValueAsBoolean(
                    Constants.MODULE_NAMESPACE_PROPOSAL_DEVELOPMENT,
                    Constants.PARAMETER_COMPONENT_DOCUMENT,
                    PropAwardPersonRoleServiceImpl.ALL_SPONSOR_HIERARCHY_NIH_MULTI_PI);
            will(returnValue(true));
            one(dataObjectService)
                .findUnique(PropAwardPersonRole.class, criteriaCoInvestigator2.build());
            will(returnValue(roleCoInvestigator2));
          }
        });

    final QueryByCriteria.Builder criteriaKeyPerson1 =
        QueryByCriteria.Builder.create()
            .setPredicates(
                PredicateFactory.equal("code", ContactRole.KEY_PERSON_CODE),
                PredicateFactory.equal(
                    "sponsorHierarchyName",
                    PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY));
    final PropAwardPersonRole roleKeyPerson1 =
        createTestRole(
            3L,
            ContactRole.KEY_PERSON_CODE,
            PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY);
    context.checking(
        new Expectations() {
          {
            one(parameterService)
                .getParameterValueAsBoolean(
                    Constants.MODULE_NAMESPACE_PROPOSAL_DEVELOPMENT,
                    Constants.PARAMETER_COMPONENT_DOCUMENT,
                    PropAwardPersonRoleServiceImpl.ALL_SPONSOR_HIERARCHY_NIH_MULTI_PI);
            will(returnValue(true));
            one(dataObjectService)
                .findUnique(PropAwardPersonRole.class, criteriaKeyPerson1.build());
            will(returnValue(roleKeyPerson1));
          }
        });

    final QueryByCriteria.Builder criteriaKeyPerson2 =
        QueryByCriteria.Builder.create()
            .setPredicates(
                PredicateFactory.equal("code", ContactRole.KEY_PERSON_CODE),
                PredicateFactory.equal(
                    "sponsorHierarchyName",
                    PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY));
    final PropAwardPersonRole roleKeyPerson2 =
        createTestRole(
            3L,
            ContactRole.KEY_PERSON_CODE,
            PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY);
    context.checking(
        new Expectations() {
          {
            one(parameterService)
                .getParameterValueAsBoolean(
                    Constants.MODULE_NAMESPACE_PROPOSAL_DEVELOPMENT,
                    Constants.PARAMETER_COMPONENT_DOCUMENT,
                    PropAwardPersonRoleServiceImpl.ALL_SPONSOR_HIERARCHY_NIH_MULTI_PI);
            will(returnValue(true));
            one(dataObjectService)
                .findUnique(PropAwardPersonRole.class, criteriaKeyPerson2.build());
            will(returnValue(roleKeyPerson2));
          }
        });

    final QueryByCriteria.Builder criteriaKeyPerson3 =
        QueryByCriteria.Builder.create()
            .setPredicates(
                PredicateFactory.equal("code", ContactRole.KEY_PERSON_CODE),
                PredicateFactory.equal(
                    "sponsorHierarchyName",
                    PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY));
    final PropAwardPersonRole roleKeyPerson3 =
        createTestRole(
            3L,
            ContactRole.KEY_PERSON_CODE,
            PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY);
    context.checking(
        new Expectations() {
          {
            one(parameterService)
                .getParameterValueAsBoolean(
                    Constants.MODULE_NAMESPACE_PROPOSAL_DEVELOPMENT,
                    Constants.PARAMETER_COMPONENT_DOCUMENT,
                    PropAwardPersonRoleServiceImpl.ALL_SPONSOR_HIERARCHY_NIH_MULTI_PI);
            will(returnValue(true));
            one(dataObjectService)
                .findUnique(PropAwardPersonRole.class, criteriaKeyPerson3.build());
            will(returnValue(roleKeyPerson3));
          }
        });

    final QueryByCriteria.Builder criteriaKeyPerson4 =
        QueryByCriteria.Builder.create()
            .setPredicates(
                PredicateFactory.equal("code", ContactRole.KEY_PERSON_CODE),
                PredicateFactory.equal(
                    "sponsorHierarchyName",
                    PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY));
    final PropAwardPersonRole roleKeyPerson4 =
        createTestRole(
            3L,
            ContactRole.KEY_PERSON_CODE,
            PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY);
    context.checking(
        new Expectations() {
          {
            one(parameterService)
                .getParameterValueAsBoolean(
                    Constants.MODULE_NAMESPACE_PROPOSAL_DEVELOPMENT,
                    Constants.PARAMETER_COMPONENT_DOCUMENT,
                    PropAwardPersonRoleServiceImpl.ALL_SPONSOR_HIERARCHY_NIH_MULTI_PI);
            will(returnValue(true));
            one(dataObjectService)
                .findUnique(PropAwardPersonRole.class, criteriaKeyPerson4.build());
            will(returnValue(roleKeyPerson4));
          }
        });

    final QueryByCriteria.Builder criteriaKeyPerson5 =
        QueryByCriteria.Builder.create()
            .setPredicates(
                PredicateFactory.equal("code", ContactRole.KEY_PERSON_CODE),
                PredicateFactory.equal(
                    "sponsorHierarchyName",
                    PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY));
    final PropAwardPersonRole roleKeyPerson5 =
        createTestRole(
            3L,
            ContactRole.KEY_PERSON_CODE,
            PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY);
    context.checking(
        new Expectations() {
          {
            one(parameterService)
                .getParameterValueAsBoolean(
                    Constants.MODULE_NAMESPACE_PROPOSAL_DEVELOPMENT,
                    Constants.PARAMETER_COMPONENT_DOCUMENT,
                    PropAwardPersonRoleServiceImpl.ALL_SPONSOR_HIERARCHY_NIH_MULTI_PI);
            will(returnValue(true));
            one(dataObjectService)
                .findUnique(PropAwardPersonRole.class, criteriaKeyPerson5.build());
            will(returnValue(roleKeyPerson5));
          }
        });

    final QueryByCriteria.Builder criteriaPrincipalInvestigator1 =
        QueryByCriteria.Builder.create()
            .setPredicates(
                PredicateFactory.equal("code", ContactRole.PI_CODE),
                PredicateFactory.equal(
                    "sponsorHierarchyName",
                    PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY));
    final PropAwardPersonRole rolePrincipalInvestigator1 =
        createTestRole(
            3L, ContactRole.PI_CODE, PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY);
    context.checking(
        new Expectations() {
          {
            one(parameterService)
                .getParameterValueAsBoolean(
                    Constants.MODULE_NAMESPACE_PROPOSAL_DEVELOPMENT,
                    Constants.PARAMETER_COMPONENT_DOCUMENT,
                    PropAwardPersonRoleServiceImpl.ALL_SPONSOR_HIERARCHY_NIH_MULTI_PI);
            will(returnValue(true));
            one(dataObjectService)
                .findUnique(PropAwardPersonRole.class, criteriaPrincipalInvestigator1.build());
            will(returnValue(rolePrincipalInvestigator1));
          }
        });

    final QueryByCriteria.Builder criteriaPrincipalInvestigator2 =
        QueryByCriteria.Builder.create()
            .setPredicates(
                PredicateFactory.equal("code", ContactRole.PI_CODE),
                PredicateFactory.equal(
                    "sponsorHierarchyName",
                    PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY));
    final PropAwardPersonRole rolePrincipalInvestigator2 =
        createTestRole(
            3L, ContactRole.PI_CODE, PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY);
    context.checking(
        new Expectations() {
          {
            one(parameterService)
                .getParameterValueAsBoolean(
                    Constants.MODULE_NAMESPACE_PROPOSAL_DEVELOPMENT,
                    Constants.PARAMETER_COMPONENT_DOCUMENT,
                    PropAwardPersonRoleServiceImpl.ALL_SPONSOR_HIERARCHY_NIH_MULTI_PI);
            will(returnValue(true));
            one(dataObjectService)
                .findUnique(PropAwardPersonRole.class, criteriaPrincipalInvestigator2.build());
            will(returnValue(rolePrincipalInvestigator2));
          }
        });

    final QueryByCriteria.Builder criteriaPrincipalInvestigator3 =
        QueryByCriteria.Builder.create()
            .setPredicates(
                PredicateFactory.equal("code", ContactRole.PI_CODE),
                PredicateFactory.equal(
                    "sponsorHierarchyName",
                    PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY));
    final PropAwardPersonRole rolePrincipalInvestigator3 =
        createTestRole(
            3L, ContactRole.PI_CODE, PropAwardPersonRoleServiceImpl.NIH_MULTIPLE_PI_HIERARCHY);
    context.checking(
        new Expectations() {
          {
            one(parameterService)
                .getParameterValueAsBoolean(
                    Constants.MODULE_NAMESPACE_PROPOSAL_DEVELOPMENT,
                    Constants.PARAMETER_COMPONENT_DOCUMENT,
                    PropAwardPersonRoleServiceImpl.ALL_SPONSOR_HIERARCHY_NIH_MULTI_PI);
            will(returnValue(true));
            one(dataObjectService)
                .findUnique(PropAwardPersonRole.class, criteriaPrincipalInvestigator3.build());
            will(returnValue(rolePrincipalInvestigator3));
          }
        });

    roleService.setDataObjectService(dataObjectService);
    roleService.setSponsorHierarchyService(hierarchyService);
    roleService.setParameterService(parameterService);
    return roleService;
  }