#!/bin/bash
# Licensed Materials - Property of IBM
# 5724-I68
#
# (C) Copyright IBM Corp. 2000, 2006
#
# US Government Users Restricted Rights - Use, duplication, or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.


# 
# # Copyright (c) 2000, 2004 IBM Corp. - All Rights Reserved.
# # IBM makes no representations or warranties about the suitability of
# # this program, either express or implied, including but not limited to
# # the implied warranties of merchantability, fitness for a particular
# # purpose, or non-infringement. 
# 
#


. ${TOP}/src/db/schema/util/set_db.sh


${ECHO} ====================================================
${ECHO} Adding other trigo employees
${ECHO} ====================================================

#		        add_other_ccd_users.sql which is situated in the
#		        correspondinge Oracle/DB2 folder in DBSCRIPTS
#		      * Separated the assigning basic role to Trigo users sql
#			into assign_basic_roles.sql which is situated in the
#			COMMON folder in DBSCRIPTS

#${TRIGO_SQLPLUS} ${CONNECTION} <<EOF

#set define '&'

#-- ====================================================================
#-- WARNING: When a new user is added, please make sure to update the encrypted password for the user
#-- by running:       $JAVA_RT com.ibm.ccd.common.security.UpdatePassword userName password
#-- Trigo employees
#-- ====================================================================

#delete from tsec_scu_user where scu_company_id = 1 and scu_user_id > 0;

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'Admin', 'trigopass',
#       'Trigo', 'Root', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'dprophete@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '', -1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'ua', 'ua',
#       'Umair', 'Akeel', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'uakeel@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '', -1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'vb', 'vb',
#       'Vis', 'Bowatte', 1, '(650) 985 7400', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'vbowatte@trigo.com', '', '(650) 330-0997', 0, 'demo@trigo.com', '', '', -1);

#insert into tsec_scu_user values
#      (qsec_scu_user_id.nextval, 'Y', 'wolf', 'wolf',
#       'Wolfgang', 'Mathurin', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'wmathurin@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '', -1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'trauf', 'baby',
#       'Tariq', 'Rauf', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'tariq@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '', -1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'oa', 'oa',
#       'Omair', 'Ashfaq', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'oashfaq@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '', -1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'saad', 'saad',
#       'Saad', 'Tabani', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'stabani@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '',-1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'abelanger', 'abelanger',
#       'Alexis', 'Belanger', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'abelanger@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '',-1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'pp', 'pp',
#       'Patrice', 'Pominville', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'ppominville@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '',-1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'dp', 'baby',
#       'Didier', 'Prophete', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'dprophete@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '',-1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'at', 'at',
#       'Arvind', 'Thyagarajan', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'athyagarajan@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '',-1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'rm', 'fh',
#       'Reza', 'Mohsin', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'reza@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '',-1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'mi', 'mi',
#       'Mohammad', 'Inamullah', 1, '(650) 330-0980', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'minamullah@trigo.com', '', '(650) 330-0997', 0, 'demo@trigo.com', '', '',-1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'va', 'va',
#       'Vikrant', 'Akavaram', 1, '(650) 330-0980', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'vakavaram@trigo.com', '', '(650) 330-0997', 0, 'demo@trigo.com', '', '',-1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'cp', 'cp',
#       'Chong Pin', 'Lim', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'demo@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '',-1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'anand', 'marina',
#       'Anand', 'Rao', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'arao@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '',-1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'mrahmani', 'marina',
#       'Mark', 'Rahmani', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'mrahmani@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '',-1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'jgreene', 'jgreene',
#       'John', 'Greene', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'jgreene@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '',-1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'qa', 'marina',
#       'QA', 'User', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'qa@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '',-1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'dloflin', 'baby',
#       'Dan', 'Loflin', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'dloflin@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '',-1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'francine', 'riowen',
#       'Francine', 'Abgrall', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'fabgrall@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '',-1);

#insert into tsec_scu_user values
#       (qsec_scu_user_id.nextval, 'Y', 'pg', 'pg',
#       'Paul', 'Giannini', 1, '(650) 827-0500', 'Suite 810, 8000 Marina Blvd, Brisbane CA 94005', 'pgiannini@trigo.com', '', '(650) 827-0500', 0, 'demo@trigo.com', '', '',-1);

#define TRIGO_ADMIN_ROLE_ID="(select rol_role_id from tsec_rol_role where rol_company_id = 1 and rol_role_name = 'trigo_admin')";
#define TRIGO_ROLE_ID="(select rol_role_id from tsec_rol_role where rol_company_id = 1 and rol_role_name = 'trigo_basic')";

#-- ====================================================================
#-- Assign basic role to the Trigo users
#-- ====================================================================


#insert into tsec_urm_user_role_map (select 1, scu_user_id, &TRIGO_ADMIN_ROLE_ID, '' from tsec_scu_user where scu_company_id = 1 and scu_username = 'Admin');
#insert into tsec_urm_user_role_map (select 1, scu_user_id, &TRIGO_ROLE_ID, '' from tsec_scu_user where scu_company_id = 1 and scu_username != 'Admin');

#EOF


#====================================================================
# WARNING: When a new user is added, please make sure to update the encrypted password for the user
# by running:       $JAVA_RT com.ibm.ccd.common.security.UpdatePassword userName password
# Trigo employees
#====================================================================

#		      correspondinge Oracle/DB2 folder in DBSCRIPTS

${ECHO} ====================================================
${ECHO} Creating Other Trigo Users
${ECHO} ====================================================

#${TRIGO_SQLPLUS} ${CONNECTION} <<EOF
#${DB_SQLFILE_EXECUTE} $DB_SCRIPTS/add_other_ccd_users.sql
#EOF
. ${DB_DIR}/util/run_db_cmd.sh --file=$DB_SCRIPTS/add_other_ccd_users.sql


# Assign Basic Roles
${ECHO} ====================================================
${ECHO} Preparing SQL to assign Roles to Other Trigo Users
${ECHO} ====================================================

#GET_TRIGO_ADMIN_ROLE_ID=`${TRIGO_SQLPLUS} ${CONNECTION} <<EOF | ${GREP} 'adminroleid-'
#${DB_SQLFILE_EXECUTE} $DB_CMN_SCRIPTS/get_ccd_admin_role_id.sql
#EOF`
GET_TRIGO_ADMIN_ROLE_ID=`. ${DB_DIR}/util/run_db_cmd.sh --file=$DB_SCRIPTS/get_ccd_admin_role_id.sql | ${GREP} 'adminroleid-'`

TRIGO_ADMIN_ROLE_ID_QRY="${GET_TRIGO_ADMIN_ROLE_ID}"

for i in $TRIGO_ADMIN_ROLE_ID_QRY
do
	TRIGO_ADMIN_ROLE_ID=`${ECHO} $i | ${GREP} 'adminroleid-' | cut -f2 -d "-"`
done

#GET_TRIGO_ROLE_ID=`${TRIGO_SQLPLUS} ${CONNECTION} <<EOF | ${GREP} 'roleid-'
#${DB_SQLFILE_EXECUTE} $DB_CMN_SCRIPTS/get_ccd_role_id.sql
#EOF`
GET_CCD_ROLE_ID=`. ${DB_DIR}/util/run_db_cmd.sh --file=$DB_SCRIPTS/get_ccd_role_id.sql | ${GREP} 'roleid-'`

TRIGO_ROLE_ID_QRY="${GET_CCD_ROLE_ID}"

for j in $TRIGO_ROLE_ID_QRY
do
	TRIGO_ROLE_ID=`${ECHO} $j | ${GREP} 'roleid-' | cut -f2 -d "-"`
done

${TOUCH} tempbasicroles.sql

${CAT} $DB_CMN_SCRIPTS/assign_basic_roles.sql | ${SED} "s#%CCD_ADMIN_ROLE_ID%#$TRIGO_ADMIN_ROLE_ID#" | ${SED} "s#%CCD_ROLE_ID%#$TRIGO_ROLE_ID#" > tempbasicroles.sql

${ECHO} ====================================================
${ECHO} Assigning Roles to Other Trigo Users
${ECHO} ====================================================

#${TRIGO_SQLPLUS} ${CONNECTION} <<EOF
#${DB_SQLFILE_EXECUTE} tempbasicroles.sql
#EOF

. ${DB_DIR}/util/run_db_cmd.sh --file=tempbasicroles.sql

${RM} tempbasicroles.sql



${ECHO} ====================================================
${ECHO} Updating encrypted passwords for other users of Trigo
${ECHO} ====================================================
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=Admin -password=trigopass
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=ua -password=ua
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=vb -password=vb
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=wolf -password=wolf
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=trauf -password=trauf
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=oa -password=oa
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=saad -password=saad
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=abelanger -password=abelanger
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=pp -password=pp
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=dp -password=dp
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=at -password=at
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=rm -password=fh
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=mi -password=mi
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=va -password=va
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=cp -password=cp
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=anand -password=marina
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=mrahmani -password=marina
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=jgreene -password=jgreene
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=qa -password=marina
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=dloflin -password=baby
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=francine -password=riowen
$JAVA_RT com.ibm.ccd.common.security.UpdatePassword -cmp_code=trigo -username=pg -password=pg

