Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shipped with SenzingAPI 1.1.0 #4

Merged
merged 1 commit into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
[markdownlint](https://dlaa.me/markdownlint/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- Thing 5
- Thing 4

## [1.0.1] - yyyy-mm-dd

### Added to 1.0.1

- Thing 3

### Fixed in 1.0.1

- Thing 2

## [1.0.0] - yyyy-mm-dd
## [1.0.0] - 2018-09-18

### Added to 1.0.0

- Thing 2
- Thing 1
- Shipped with SenzingAPI 1.1.0
117 changes: 117 additions & 0 deletions G2ConfigTables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#--python imports
import optparse
import sys
import os
import json

#--optional imports
try: import pyodbc
except: pass
try: import sqlite3
except: pass

#--project classes
import G2Exception
from G2ConfigModule import G2ConfigModule

#======================
class G2ConfigTables:
#======================


#----------------------------------------
def __init__(self, configFile,g2iniPath):
self.configFileName = configFile
self.g2iniPath = g2iniPath
self.success = True


#----------------------------------------
#-- g2 specific calls
#----------------------------------------

#----------------------------------------
def loadConfig(self, tableName):
cfgDict = {}
with open(self.configFileName) as data_file:
cfgDataRoot = json.load(data_file, encoding="utf-8")
configNode = cfgDataRoot['G2_CONFIG']
tableNode = configNode[tableName.upper()]
for rowNode in tableNode:
cfgNodeEntry = {}
if tableName.upper() == 'CFG_DSRC':
cfgNodeEntry['ID'] = rowNode['DSRC_ID'];
cfgNodeEntry['DSRC_CODE'] = rowNode['DSRC_CODE'];
cfgDict[cfgNodeEntry['ID']] = cfgNodeEntry
elif tableName.upper() == 'CFG_ETYPE':
cfgNodeEntry['ID'] = rowNode['ETYPE_ID'];
cfgNodeEntry['ETYPE_CODE'] = rowNode['ETYPE_CODE'];
cfgDict[cfgNodeEntry['ID']] = cfgNodeEntry
elif tableName.upper() == 'CFG_FTYPE':
cfgNodeEntry['ID'] = rowNode['FTYPE_ID'];
cfgNodeEntry['FTYPE_CODE'] = rowNode['FTYPE_CODE'];
cfgNodeEntry['DERIVED'] = rowNode['DERIVED'];
cfgDict[cfgNodeEntry['ID']] = cfgNodeEntry
elif tableName.upper() == 'CFG_ERRULE':
cfgNodeEntry['ID'] = rowNode['ERRULE_ID'];
cfgNodeEntry['ERRULE_CODE'] = rowNode['ERRULE_CODE'];
cfgNodeEntry['REF_SCORE'] = rowNode['REF_SCORE'];
cfgNodeEntry['RTYPE_ID'] = rowNode['RTYPE_ID'];
cfgDict[cfgNodeEntry['ID']] = cfgNodeEntry
elif tableName.upper() == 'CFG_ATTR':
cfgNodeEntry['ATTR_ID'] = rowNode['ATTR_ID'];
cfgNodeEntry['ATTR_CODE'] = rowNode['ATTR_CODE'];
cfgNodeEntry['ATTR_CLASS'] = rowNode['ATTR_CLASS'];
cfgNodeEntry['FTYPE_CODE'] = rowNode['FTYPE_CODE'];
cfgNodeEntry['FELEM_CODE'] = rowNode['FELEM_CODE'];
cfgNodeEntry['FELEM_REQ'] = rowNode['FELEM_REQ'];
cfgDict[cfgNodeEntry['ATTR_CODE']] = cfgNodeEntry
else:
return None
return cfgDict

#----------------------------------------
def addDataSource(self, dataSource):
''' adds a data source if does not exist '''
returnCode = 0 #--1=inserted, 2=updated
g2_config_module = G2ConfigModule('pyG2AddDataSource', self.g2iniPath, False)
g2_config_module.init()
with open(self.configFileName) as data_file:
cfgDataRoot = data_file.read() #.decode('utf8')
configHandle = g2_config_module.load(cfgDataRoot)
dsrcExists = False
dsrcListDocString = g2_config_module.listDataSources(configHandle)
dsrcListDoc = json.loads(dsrcListDocString)
dsrcListNode = dsrcListDoc['DSRC_CODE']
for dsrcNode in dsrcListNode:
if dsrcNode.upper() == dataSource:
dsrcExists = True
if dsrcExists == False:
g2_config_module.addDataSource(configHandle,dataSource)
newConfig = g2_config_module.save(configHandle)
with open(self.configFileName, 'w') as data_file2:
json.dump(json.loads(newConfig),data_file2, indent=4)
returnCode = 1
g2_config_module.close(configHandle)
g2_config_module.destroy()
del g2_config_module
return returnCode

#----------------------------------------
def addEntityType(self, entityType):
''' adds an entity type if does not exist '''
# For now, we just add a data source, which includes creating the entity type.
return self.addDataSource(entityType)

#----------------------------------------
def verifyEntityTypeExists(self,entityType):
etypeExists = False
with open(self.configFileName) as data_file:
cfgDataRoot = json.load(data_file, encoding="utf-8")
configNode = cfgDataRoot['G2_CONFIG']
tableNode = configNode['CFG_ETYPE']
for rowNode in tableNode:
if rowNode['ETYPE_CODE'] == entityType:
etypeExists = True
return etypeExists