智慧水务管理系统 - 精河县供水工程综合管理平台

getMetadataClassProperty.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import defined from "../Core/defined.js";
  2. /**
  3. * Return the `MetadataClassProperty` from the given schema that
  4. * matches the given description.
  5. *
  6. * If the given schema is `undefined`, then `undefined` is returned.
  7. * If the given `schemaId` is defined but does not match the ID
  8. * of the given schema, then `undefined` is returned.
  9. * If the given schema does not have a class with the given name,
  10. * or the class does not have a property with the given name,
  11. * then `undefined` is returned.
  12. *
  13. * Otherwise, the `MetadataClassProperty` is returned.
  14. *
  15. * @param {object} schema The schema object
  16. * @param {string|undefined} schemaId The ID of the metadata schema
  17. * @param {string} className The name of the metadata class
  18. * @param {string} propertyName The name of the metadata property
  19. * @returns {MetadataClassProperty|undefined}
  20. * @private
  21. */
  22. function getMetadataClassProperty(schema, schemaId, className, propertyName) {
  23. if (!defined(schema)) {
  24. return undefined;
  25. }
  26. if (defined(schemaId) && schema.id !== schemaId) {
  27. return undefined;
  28. }
  29. const classes = schema.classes || {};
  30. const metadataClass = classes[className];
  31. if (!defined(metadataClass)) {
  32. return undefined;
  33. }
  34. const properties = metadataClass.properties || {};
  35. const metadataProperty = properties[propertyName];
  36. if (!defined(metadataProperty)) {
  37. return undefined;
  38. }
  39. return metadataProperty;
  40. }
  41. export default getMetadataClassProperty;