Example #1
0
  /**
   * Returns an instance of the bean with the given id that has been configured in the test
   * dictionary
   *
   * @param id - id of the bean definition
   * @return Object instance of the given bean class, or null if not found or dictionary is not
   *     loaded
   */
  protected Object getTestDictionaryObject(String id) {
    if (dd != null) {
      return dd.getDictionaryBean(id);
    }

    return null;
  }
 /**
  * Returns all of the inactivation blocks registered for a particular business object
  *
  * @see
  *     org.kuali.rice.krad.service.DataDictionaryService#getAllInactivationBlockingDefinitions(java.lang.Class)
  */
 public Set<InactivationBlockingMetadata> getAllInactivationBlockingDefinitions(
     Class inactivationBlockedBusinessObjectClass) {
   Set<InactivationBlockingMetadata> blockingClasses =
       dataDictionary.getAllInactivationBlockingMetadatas(inactivationBlockedBusinessObjectClass);
   if (blockingClasses == null) {
     return Collections.emptySet();
   }
   return blockingClasses;
 }
Example #3
0
  @Override
  protected void setUpInternal() throws Exception {
    super.setUpInternal();

    List<Class> classes =
        TestUtilities.getHierarchyClassesToHandle(
            getClass(), new Class[] {TestDictionaryConfig.class}, new HashSet<String>());

    // if annotation is present then initialize test data dictionary (setup once per suite)
    if (!classes.isEmpty()) {
      ConfigurableApplicationContext context =
          new ClassPathXmlApplicationContext("TestDataDictionary.xml");
      dd = (DataDictionary) context.getBean("testDataDictionary");

      // add any additional dictionary files required by the test
      for (Class c : classes) {
        if (c.isAnnotationPresent(TestDictionaryConfig.class)) {
          TestDictionaryConfig testDictionaryConfig =
              (TestDictionaryConfig) c.getAnnotation(TestDictionaryConfig.class);

          String namespaceCode = testDictionaryConfig.namespaceCode();
          String dictionaryFileString = testDictionaryConfig.dataDictionaryFiles();

          String[] dictionaryFiles = StringUtils.split(dictionaryFileString, ",");
          for (String dictionaryFile : dictionaryFiles) {
            LOG.info("Adding test data dictionary file: " + dictionaryFile);

            dd.addConfigFileLocation(namespaceCode, dictionaryFile);
          }
        }
      }

      dd.parseDataDictionaryConfigurationFiles(false);
      dd.validateDD(
          false); // Validation performs some necessary post-processing of the beans - we need to
                  // run this each time we add new files
      dd.performBeanOverrides();
    }
  }
 /**
  * @see org.kuali.rice.krad.service.DataDictionaryService#addDataDictionaryLocations(
  *     java.lang.String, java.util.List<java.lang.String>)
  */
 public void addDataDictionaryLocations(String namespaceCode, List<String> locations)
     throws IOException {
   for (String location : locations) {
     dataDictionary.addConfigFileLocation(namespaceCode, location);
   }
 }
 /**
  * @see
  *     org.kuali.rice.krad.service.DataDictionaryService#getViewIdByTypeIndex(org.kuali.rice.krad.uif.UifConstants.ViewType,
  *     java.util.Map<java.lang.String,java.lang.String>)
  */
 public String getViewIdByTypeIndex(ViewType viewTypeName, Map<String, String> indexKey) {
   return dataDictionary.getViewIdByTypeIndex(viewTypeName, indexKey);
 }
 /**
  * @see
  *     org.kuali.rice.krad.service.DataDictionaryService#containsDictionaryObject(java.lang.String)
  */
 public boolean containsDictionaryObject(String id) {
   return dataDictionary.containsDictionaryObject(id);
 }
 /**
  * @see org.kuali.rice.krad.service.DataDictionaryService#getDictionaryObject(java.lang.String)
  */
 public Object getDictionaryObject(String id) {
   return dataDictionary.getDictionaryObject(id);
 }
 /** @see org.kuali.rice.krad.service.DataDictionaryService#getViewById(java.lang.String) */
 public View getViewById(String viewId) {
   return dataDictionary.getViewById(viewId);
 }
Example #9
0
  /**
   * This method does validation on the quickfinderParameterString and
   * quickfinderParameterStringBuilderClass members
   *
   * @param rootBusinessObjectClass
   * @param boMetadataService
   */
  private void validateQuickfinderParameters(
      Class rootBusinessObjectClass, BusinessObjectMetaDataService boMetadataService) {
    if (quickfinderParameterStringBuilderClass != null && quickfinderParameterString != null) {
      throw new AttributeValidationException(
          "Both quickfinderParameterString and quickfinderParameterStringBuilderClass can not be specified on attribute "
              + getAttributeName()
              + " in rootBusinessObjectClass "
              + rootBusinessObjectClass.getName());
    }

    // String used for building exception messages
    String quickfinderParameterStringSource = "quickfinderParameterString";

    if (quickfinderParameterStringBuilderClass != null) {
      try {
        quickfinderParameterStringSource =
            "quickfinderParameterStringBuilderClass "
                + quickfinderParameterStringBuilderClass.getCanonicalName();
        quickfinderParameterString =
            quickfinderParameterStringBuilderClass.newInstance().getValue();
      } catch (InstantiationException e) {
        throw new ClassValidationException(
            "unable to create new instance of "
                + quickfinderParameterStringSource
                + " while validating rootBusinessObjectClass '"
                + rootBusinessObjectClass.getName()
                + "'",
            e);
      } catch (IllegalAccessException e) {
        throw new ClassValidationException(
            "unable to create new instance of "
                + quickfinderParameterStringSource
                + " while validating rootBusinessObjectClass '"
                + rootBusinessObjectClass.getName()
                + "'",
            e);
      }
    }

    if (!StringUtils.isEmpty(quickfinderParameterString)) {
      // quickfinderParameterString will look something like "campusTypeCode=P,active=Y"
      for (String quickfinderParam :
          quickfinderParameterString.split(",")) { // this is guaranteed to return at least one
        if (quickfinderParam.contains("=")) {
          String propertyName = quickfinderParam.split("=")[0];
          RelationshipDefinition relationship =
              boMetadataService.getBusinessObjectRelationshipDefinition(
                  rootBusinessObjectClass, attributeName);
          Class targetClass = relationship.getTargetClass();

          // This is insufficient to ensure the property is valid for a lookup default, but it's
          // better than nothing.
          if (!DataDictionary.isPropertyOf(targetClass, propertyName)) {
            throw new ClassValidationException(
                "malformed parameter string  '"
                    + quickfinderParameterString
                    + "' from "
                    + quickfinderParameterStringSource
                    + ", '"
                    + propertyName
                    + "' is not a property of "
                    + targetClass
                    + "' for rootBusinessObjectClass '"
                    + rootBusinessObjectClass.getName()
                    + "'");
          }

        } else {
          throw new ClassValidationException(
              "malformed parameter string '"
                  + quickfinderParameterString
                  + "' from "
                  + quickfinderParameterStringSource
                  + " for rootBusinessObjectClass '"
                  + rootBusinessObjectClass.getName()
                  + "'");
        }
      }
    }
  }
Example #10
0
  /**
   * Directly validate simple fields.
   *
   * @see
   *     org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class,
   *     java.lang.Object)
   */
  public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
    BusinessObjectMetaDataService boMetadataService =
        KNSServiceLocator.getBusinessObjectMetaDataService();

    if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getAttributeName())) {
      throw new AttributeValidationException(
          "unable to find attribute '"
              + attributeName
              + "' in rootBusinessObjectClass '"
              + rootBusinessObjectClass.getName()
              + "' ("
              + ""
              + ")");
    }

    if (StringUtils.isNotBlank(getAlternateDisplayAttributeName())) {
      if (!DataDictionary.isPropertyOf(
          rootBusinessObjectClass, getAlternateDisplayAttributeName())) {
        throw new AttributeValidationException(
            "unable to find attribute named '"
                + getName()
                + "' in rootBusinessObjectClass '"
                + rootBusinessObjectClass.getName()
                + "' ("
                + ""
                + ")");
      }
    }

    if (StringUtils.isNotBlank(getAdditionalDisplayAttributeName())) {
      if (!DataDictionary.isPropertyOf(
          rootBusinessObjectClass, getAdditionalDisplayAttributeName())) {
        throw new AttributeValidationException(
            "unable to find attribute named '"
                + getName()
                + "' in rootBusinessObjectClass '"
                + rootBusinessObjectClass.getName()
                + "' ("
                + ""
                + ")");
      }
    }

    if (defaultValueFinderClass != null && defaultValue != null) {
      throw new AttributeValidationException(
          "Both defaultValue and defaultValueFinderClass can not be specified on attribute "
              + getAttributeName()
              + " in rootBusinessObjectClass "
              + rootBusinessObjectClass.getName());
    }

    validateQuickfinderParameters(rootBusinessObjectClass, boMetadataService);

    if (forceInquiry == true && noInquiry == true) {
      throw new AttributeValidationException(
          "Both forceInquiry and noInquiry can not be set to true on attribute "
              + getAttributeName()
              + " in rootBusinessObjectClass "
              + rootBusinessObjectClass.getName());
    }
    if (forceLookup == true && noLookup == true) {
      throw new AttributeValidationException(
          "Both forceLookup and noLookup can not be set to true on attribute "
              + getAttributeName()
              + " in rootBusinessObjectClass "
              + rootBusinessObjectClass.getName());
    }
  }