Skip to content

Commit

Permalink
DIS-214 Link Patron Types with Account Profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mdnoble73 committed Jan 10, 2025
1 parent 8defd9d commit 46d1994
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
Binary file modified code/polaris_export/polaris_export.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class PolarisExportMain {
private static String serverName;

private static IlsExtractLogEntry logEntry;
private static long accountProfileId;
private static String webServiceUrl;
private static String clientId;
private static String clientSecret;
Expand Down Expand Up @@ -159,6 +160,7 @@ public static void main(String[] args) {
domain = accountProfileRS.getString("domain");
staffUsername = accountProfileRS.getString( "staffUsername");
staffPassword = accountProfileRS.getString( "staffPassword");
profileToLoad = accountProfileRS.getString("recordSource");
}
accountProfileRS.close();

Expand Down Expand Up @@ -425,8 +427,8 @@ private static void updateSublocationInfo(Connection dbConn) {
private static void updateBranchInfo(Connection dbConn) {
try{
PreparedStatement existingAspenLocationStmt = dbConn.prepareStatement("SELECT libraryId, locationId, isMainBranch from location where code = ?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
PreparedStatement existingAspenLibraryStmt = dbConn.prepareStatement("SELECT libraryId from library where ilsCode = ?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
PreparedStatement addAspenLibraryStmt = dbConn.prepareStatement("INSERT INTO library (subdomain, displayName, ilsCode, browseCategoryGroupId, groupedWorkDisplaySettingId) VALUES (?, ?, ?, 1, 1)", Statement.RETURN_GENERATED_KEYS);
PreparedStatement existingAspenLibraryStmt = dbConn.prepareStatement("SELECT libraryId from library where ilsCode = ? and accountProfileId = ?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
PreparedStatement addAspenLibraryStmt = dbConn.prepareStatement("INSERT INTO library (accountProfileId, subdomain, displayName, ilsCode, browseCategoryGroupId, groupedWorkDisplaySettingId) VALUES (?, ?, ?, ?, 1, 1)", Statement.RETURN_GENERATED_KEYS);
PreparedStatement addAspenLocationStmt = dbConn.prepareStatement("INSERT INTO location (libraryId, displayName, code, browseCategoryGroupId, groupedWorkDisplaySettingId) VALUES (?, ?, ?, -1, -1)", Statement.RETURN_GENERATED_KEYS);
PreparedStatement addAspenLocationRecordsOwnedStmt = dbConn.prepareStatement("INSERT INTO location_records_to_include (locationId, indexingProfileId, location, subLocation, markRecordsAsOwned) VALUES (?, ?, ?, '', 1)");
PreparedStatement addAspenLocationRecordsToIncludeStmt = dbConn.prepareStatement("INSERT INTO location_records_to_include (locationId, indexingProfileId, location, subLocation, weight) VALUES (?, ?, '.*', '', 1)");
Expand Down Expand Up @@ -454,12 +456,14 @@ private static void updateBranchInfo(Connection dbConn) {
int organizationCodeId = organizationInfo.getInt("OrganizationCodeID");
if (organizationCodeId == 2) {
existingAspenLibraryStmt.setLong(1, ilsId);
existingAspenLibraryStmt.setLong(2, accountProfileId);
ResultSet existingLibraryRS = existingAspenLibraryStmt.executeQuery();
long libraryId = 0;
if (!existingLibraryRS.next()) {
addAspenLibraryStmt.setString(1, abbreviation);
addAspenLibraryStmt.setString(2, libraryDisplayName);
addAspenLibraryStmt.setLong(3, ilsId);
addAspenLibraryStmt.setLong(1, accountProfileId);
addAspenLibraryStmt.setString(2, abbreviation);
addAspenLibraryStmt.setString(3, libraryDisplayName);
addAspenLibraryStmt.setLong(4, ilsId);
addAspenLibraryStmt.executeUpdate();
ResultSet addAspenLibraryRS = addAspenLibraryStmt.getGeneratedKeys();
if (addAspenLibraryRS.next()){
Expand Down Expand Up @@ -535,15 +539,16 @@ private static void updateBranchInfo(Connection dbConn) {

private static void updatePatronCodes(Connection dbConn){
try{
PreparedStatement existingPTypeStmt = dbConn.prepareStatement("SELECT * from ptype");
PreparedStatement existingPTypeStmt = dbConn.prepareStatement("SELECT * from ptype where accountProfileId = ?");
existingPTypeStmt.setLong(1, accountProfileId);
ResultSet existingPTypesRS = existingPTypeStmt.executeQuery();
HashSet<Long> existingPTypes = new HashSet<>();
while (existingPTypesRS.next()){
existingPTypes.add(existingPTypesRS.getLong("pType"));
}
existingPTypesRS.close();
existingPTypeStmt.close();
PreparedStatement addPTypeStmt = dbConn.prepareStatement("INSERT INTO ptype (pType, description) VALUES (?, ?)");
PreparedStatement addPTypeStmt = dbConn.prepareStatement("INSERT INTO ptype (accountProfileId, pType, description) VALUES (?, ?, ?)");
//Get a list of all libraries
String getPatronCodesUrl = "/PAPIService/REST/public/v1/1033/100/1/patroncodes";
WebServiceResponse patronCodesResponse = callPolarisAPI(getPatronCodesUrl, null, "GET", "application/json", null);
Expand All @@ -554,8 +559,9 @@ private static void updatePatronCodes(Connection dbConn){
JSONObject curPatronType = patronCodeRows.getJSONObject(i);
long patronCodeId = curPatronType.getLong("PatronCodeID");
if (!existingPTypes.contains(patronCodeId)){
addPTypeStmt.setLong(1, patronCodeId);
addPTypeStmt.setString(2, curPatronType.getString("Description"));
addPTypeStmt.setLong(1, accountProfileId);
addPTypeStmt.setLong(2, patronCodeId);
addPTypeStmt.setString(3, curPatronType.getString("Description"));
addPTypeStmt.executeUpdate();
}
}
Expand Down Expand Up @@ -762,6 +768,7 @@ private static boolean loadAccountProfile(Connection dbConn) {
}
clientId = accountProfileRS.getString("oAuthClientId");
clientSecret = accountProfileRS.getString("oAuthClientSecret");
accountProfileId = accountProfileRS.getLong("id");
} else {
logger.error("Could not find an account profile for Polaris stopping");
System.exit(1);
Expand Down
15 changes: 15 additions & 0 deletions code/web/sys/Account/PType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class PType extends DataObject {
public $__table = 'ptype'; // table name
public $id;
public $pType; //varchar(45)
public $accountProfileId;
public $description;
public $maxHolds; //int(11)
public $assignedRoleId;
Expand Down Expand Up @@ -53,6 +54,12 @@ static function getObjectStructure($context = ''): array {
while ($twoFactorAuthSetting->fetch()) {
$twoFactorAuthSettings[$twoFactorAuthSetting->id] = $twoFactorAuthSetting->name;
}
require_once ROOT_DIR . '/sys/Account/AccountProfile.php';
$accountProfile = new AccountProfile();
$accountProfile->whereAdd("name <> 'admin'");
$accountProfile->orderBy('name');
$accountProfileOptions = $accountProfile->fetchAll('id', 'name');

$structure = [
'id' => [
'property' => 'id',
Expand All @@ -61,6 +68,14 @@ static function getObjectStructure($context = ''): array {
'description' => 'The unique id of the p-type within the database',
'hideInLists' => false,
],
'accountProfileId' => [
'property' => 'accountProfileId',
'type' => 'enum',
'values' => $accountProfileOptions,
'label' => 'Account Profile Id',
'description' => 'Account Profile to apply to this interface',
'permissions' => ['Administer Account Profiles'],
],
'pType' => [
'property' => 'pType',
'type' => 'text',
Expand Down
12 changes: 11 additions & 1 deletion code/web/sys/DBMaintenance/version_updates/25.02.00.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ function getUpdates25_02_00(): array {
], //name*/

//mark - Grove

'ptype_account_profile' => [
'title' => 'Patron Type - Add Account Profile',
'description' => 'Add Information about which account profile a patron type belongs to',
'continueOnError' => true,
'sql' => [
'ALTER TABLE ptype ADD COLUMN accountProfileId INT',
"UPDATE ptype set accountProfileId = (SELECT MIN(id) from account_profiles where ils <> 'na' and name <> 'admin')",
"ALTER TABLE ptype DROP INDEX ptype",
"ALTER TABLE ptype ADD UNIQUE INDEX ptype_profile(ptype, accountProfileId)",
]
], //ptype_account_profile

//katherine

Expand Down

0 comments on commit 46d1994

Please sign in to comment.