def getSchemaInfo(self, databaseName, dataTyping="ANY"): """Convenience method to return essential schema details for the input repository content type. Args: databaseName (str): schema name (e.g. pdbx, bird, chem_comp, ...) dataTyping (str, optional): Application name for the target schema (e.g. ANY, SQL, ...) Returns: tuple: SchemaDefAccess(object), target database name, target collection name list, primary index attribute list """ sd = None dbName = None collectionNameList = [] docIndexD = {} try: mU = MarshalUtil(workPath=self.__workPath) schemaLocator = self.__getSchemaDefLocator(databaseName, dataTyping=dataTyping) if self.__rebuildFlag: filePath = os.path.join( self.__schemaCachePath, self.__fileU.getFileName(schemaLocator)) self.makeSchemaDef(databaseName, dataTyping=dataTyping, saveSchema=True) else: filePath = self.__reload(schemaLocator, self.__schemaCachePath, useCache=self.__useCache) if not filePath: logger.error("Unable to recover schema %s (%s)", databaseName, dataTyping) logger.debug("ContentType %r dataTyping %r schemaLocator %r", databaseName, dataTyping, schemaLocator) schemaDef = mU.doImport(filePath, fmt="json") if schemaDef: logger.debug( "Using cached schema definition for %s application %s", databaseName, dataTyping) sd = SchemaDefAccess(schemaDef) if sd: dbName = sd.getDatabaseName() collectionInfoList = sd.getCollectionInfo() logger.debug("Schema %s database name %s collections %r", databaseName, dbName, collectionInfoList) for cd in collectionInfoList: collectionName = cd["NAME"] collectionNameList.append(collectionName) docIndexD[collectionName] = sd.getDocumentIndices( collectionName) except Exception as e: logger.exception("Retreiving schema %s for %s failing with %s", databaseName, dataTyping, str(e)) return sd, dbName, collectionNameList, docIndexD
def __testAccessors(self, schemaDef): """ Verify data and accessor mapping - """ sd = SchemaDefAccess(schemaDef) logger.debug("Schema name %s", sd.getName()) logger.debug("Schema name %s", sd.getAppName()) logger.debug("Database name %s", sd.getDatabaseName()) logger.debug("Versioned database name %s", sd.getVersionedDatabaseName()) logger.debug("Collection info %r", sd.getCollectionInfo()) for dS in sd.getDataSelectorNames(): logger.debug("Selector %s %r", dS, sd.getDataSelectors(dS)) collectionInfoL = sd.getCollectionInfo() for dD in collectionInfoL: collectionName = dD["NAME"] logger.debug("Collection excluded %r", sd.getCollectionExcluded(collectionName)) logger.debug("Collection included %r", sd.getCollectionSelected(collectionName)) logger.debug("Collection document key attribute names %r", sd.getDocumentKeyAttributeNames(collectionName)) schemaIdList = sd.getSchemaIdList() for schemaId in schemaIdList: # aIdL = sd.getAttributeIdList(schemaId) tObj = sd.getSchemaObject(schemaId) attributeIdList = tObj.getAttributeIdList() self.assertEqual(len(aIdL), len(attributeIdList)) attributeNameList = tObj.getAttributeNameList() logger.debug("Ordered attribute Id list %s", str(attributeIdList)) logger.debug("Ordered attribute name list %s", str(attributeNameList)) # mAL = tObj.getMapAttributeNameList() logger.debug("Ordered mapped attribute name list %s", str(mAL)) mAL = tObj.getMapAttributeIdList() logger.debug("Ordered mapped attribute id list %s", str(mAL)) cL = tObj.getMapInstanceCategoryList() logger.debug("Mapped category list %s", str(cL)) for cV in cL: aL = tObj.getMapInstanceAttributeList(cV) logger.debug("Mapped attribute list in %s : %s", cV, str(aL)) return True