<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
	version="1.0">
	<description>User</description>

	<!--  User, role, permission mappings -->

	<mapped-superclass class="gov.va.med.fw.model.UserPrincipalImpl"
		access="FIELD">
		<attributes>
			<basic name="givenName">
				<column name="FIRST_NAME" />
			</basic>
			<basic name="middleName">
				<column name="MIDDLE_NAME" />
			</basic>
			<basic name="familyName">
				<column name="LAST_NAME" />
			</basic>
			<basic name="telephoneNumber">
				<column name="telephone_number" />
			</basic>
			<basic name="email">
				<column name="email" />
			</basic>
			<embedded name="userCredentials" />
			<transient name="authorities" />
			<transient name="ldapRoles" />
			<transient name="userDn" />
			<transient name="title" />
			<transient name="department" />
			<transient name="description" />
			<transient name="office" />
			<transient name="currentTimeZone" />
		</attributes>
	</mapped-superclass>
	
	<entity class="gov.va.med.ccht.model.SimpleUser" access="FIELD" name="SimpleUser">
		<table schema="HT" name="APP_USER" />

		<attribute-override name="id">
			<column name="APP_USER_ID" nullable="false" updatable="false" />
		</attribute-override>
		<attributes>
			<basic name="inactiveDate">
				<column name="INACTIVE_DATE" />
			</basic>		
			<many-to-one name="visn" target-entity="gov.va.med.ccht.model.inventory.SimpleVisn">
				<join-column name="VISN_ID" />
			</many-to-one>
			<many-to-one name="facility" target-entity="gov.va.med.ccht.model.inventory.SimpleFacility">
				<join-column name="PRI_FACILITIES_ID" />
			</many-to-one>
			<many-to-one name="secondaryFacility" target-entity="gov.va.med.ccht.model.inventory.SimpleFacility">
				<join-column name="SEC_FACILITIES_ID" />
			</many-to-one>	
			<many-to-one name="vendor"
				target-entity="gov.va.med.ccht.model.inventory.Vendor">
				<join-column name="VENDOR_ID" />
			</many-to-one>							
		</attributes>
	</entity>

	<entity class="gov.va.med.ccht.model.User" access="FIELD" name="User">
		<table schema="HT" name="APP_USER" />

		<attribute-override name="id">
			<column name="APP_USER_ID" nullable="false" updatable="false"/>
		</attribute-override>
		<attributes>
			<basic name="accountExpireDate">
				<column name="ACCOUNT_EXPIRE_DATE" />
			</basic>
			<basic name="accountLockDate">
				<column name="ACCOUNT_LOCK_DATE" />
			</basic>
			<basic name="inactiveDate">
				<column name="INACTIVE_DATE" />
			</basic>
			<basic name="lastLoginDate">
				<column name="LAST_LOGIN_DATE" />
			</basic>
			<basic name="loginFailedDate">
				<column name="LOGIN_FAILED_DATE" />
			</basic>
			<basic name="loginFailedCount">
				<column name="LOGIN_FAILED_COUNT" />
			</basic>
			<many-to-one name="inactiveReason"
				target-entity="gov.va.med.ccht.model.terminology.InactiveReason">
				<join-column name="ACCOUNT_INACTIVE_REASON_ID" />
			</many-to-one>
			<many-to-one name="registrationDeniedReason"
				target-entity="gov.va.med.ccht.model.terminology.RegistrationDeniedReason">
				<join-column name="REG_DENIED_REASON_ID" />
			</many-to-one>				
			<many-to-one name="registrationReason"
				target-entity="gov.va.med.ccht.model.terminology.RegistrationReason">
				<join-column name="HT_JOB_DESCRIPTION_ID" />
			</many-to-one>				
			<many-to-one name="registrationStatus"
				target-entity="gov.va.med.ccht.model.terminology.RegistrationStatus">
				<join-column name="REGISTRATION_STATUS_ID" />
			</many-to-one>
			<many-to-one name="visn" target-entity="gov.va.med.ccht.model.inventory.SimpleVisn">
				<join-column name="VISN_ID" />
			</many-to-one>
			<many-to-one name="facility" target-entity="gov.va.med.ccht.model.inventory.SimpleFacility">
				<join-column name="PRI_FACILITIES_ID" />
			</many-to-one>
			<many-to-one name="secondaryFacility" target-entity="gov.va.med.ccht.model.inventory.SimpleFacility">
				<join-column name="SEC_FACILITIES_ID" />
			</many-to-one>	
			<many-to-one name="vendor"
				target-entity="gov.va.med.ccht.model.inventory.Vendor">
				<join-column name="VENDOR_ID" />
			</many-to-one>								
			<one-to-many name="internalRoles" target-entity="gov.va.med.ccht.model.UserRole"
				mapped-by="user" fetch="EAGER">
				<cascade>
					<cascade-all />
				</cascade>
			</one-to-many>
			<one-to-many name="internalUserGroups" target-entity="gov.va.med.ccht.model.AppUserGroup"
				mapped-by="user" fetch="EAGER">
				<cascade>
					<cascade-all />
				</cascade>
			</one-to-many>
			<one-to-many name="internalPreferences" target-entity="gov.va.med.ccht.model.UserPreference"
				mapped-by="user" fetch="EAGER">
				<cascade>
					<cascade-all />
				</cascade>
			</one-to-many>			
		</attributes>
	</entity>

	<entity class="gov.va.med.ccht.model.UserRole" access="FIELD"
		name="UserRole">
		<table schema="HT" name="USER_ROLE" />
		<attribute-override name="id">
			<column name="USER_ROLE_ID" />
		</attribute-override>
		<attributes>
			<many-to-one name="user" target-entity="gov.va.med.ccht.model.User">
				<join-column name="APP_USER_ID" />
			</many-to-one>
			<many-to-one name="role" target-entity="gov.va.med.fw.security.Role">
				<join-column name="ROLE_ID" />
			</many-to-one>
		</attributes>
	</entity>

	<entity class="gov.va.med.ccht.model.AppUserGroup" access="FIELD"
		name="AppUserGroup">
		<table schema="HT" name="USER_GROUP" />
		<attribute-override name="id">
			<column name="USER_GROUP_ID" />
		</attribute-override>
		<attributes>
			<many-to-one name="user" target-entity="gov.va.med.ccht.model.User">
				<join-column name="APP_USER_ID" />
			</many-to-one>
			<many-to-one name="userGroup"
				target-entity="gov.va.med.ccht.model.terminology.UserGroup">
				<join-column name="HT_USER_GROUP_ID" />
			</many-to-one>
		</attributes>
	</entity>

	<entity class="gov.va.med.ccht.model.UserPreference" access="FIELD"
		name="UserPreference">
		<table schema="HT" name="USER_PREFERENCE" />
		<attribute-override name="id">
			<column name="USER_PREFERENCE_ID" />
		</attribute-override>
		<attributes>
			<basic name="name">
				<column name="NAME" />
			</basic>
			<basic name="value">
				<column name="PREF_VALUE" />
			</basic>
			<many-to-one name="user" target-entity="gov.va.med.ccht.model.User">
				<join-column name="APP_USER_ID" />
			</many-to-one>
		</attributes>
	</entity>
	
	<entity class="gov.va.med.fw.security.Role" access="FIELD" name="Role">
		<table schema="HT" name="ROLE" />
		<attribute-override name="id">
			<column name="ROLE_ID" />
		</attribute-override>
		<attributes>
			<basic name="name">
				<column name="ROLE_NAME" />
			</basic>
			<basic name="description">
				<column name="DESCRIPTION" />
			</basic>
			<one-to-many name="internalPermissions" target-entity="gov.va.med.fw.security.RolePermission"
				mapped-by="role" fetch="EAGER">
				<cascade>
					<cascade-all />
				</cascade>
			</one-to-many>
			<!--  not mapped for now -->
			<transient name="inactive" />
			<transient name="inactiveDate" />
			<transient name="application" />
		</attributes>
	</entity>

	<entity class="gov.va.med.fw.security.SimpleRole" access="FIELD"
		name="SimpleRole">
		<table schema="HT" name="ROLE" />
		<attribute-override name="id">
			<column name="ROLE_ID" />
		</attribute-override>
		<attributes>
			<basic name="name">
				<column name="ROLE_NAME" />				
			</basic>
			<basic name="description">
				<column name="DESCRIPTION" />				
			</basic>			
		</attributes>
	</entity>

	<entity class="gov.va.med.fw.security.RolePermission" access="FIELD"
		name="RolePermission">
		<table schema="HT" name="ROLE_PERMISSION" />
		<attribute-override name="id">
			<column name="ROLE_PERMISSION_ID" />
		</attribute-override>
		<attributes>
			<many-to-one name="role" target-entity="gov.va.med.fw.security.Role">
				<join-column name="ROLE_ID" />
			</many-to-one>
			<many-to-one name="permission" target-entity="gov.va.med.fw.security.Permission">
				<join-column name="PERMISSION_ID" />
			</many-to-one>
			<transient name="inactive" />
		</attributes>
	</entity>
	<entity class="gov.va.med.ccht.model.terminology.FederalHoliday"
		access="FIELD" name="FederalHoliday">
		<table schema="HT" name="HT_FEDERAL_HOLIDAYS" />
		<attribute-override name="id">
			<column name="ID" />
		</attribute-override>
		<attributes>
			<basic name="activeDate">
				<column name="ACTIVE_DATE" />
			</basic>
			<basic name="inactiveDate">
				<column name="INACTIVE_DATE" />
			</basic>
			<basic name="date">
				<column name="HOLIDAY_DATE" />
			</basic>
			<basic name="description">
				<column name="DESCRIPTION" />
			</basic>
			<!--  not mapped for now -->
			<transient name="version" />
		</attributes>
	</entity>

	<entity class="gov.va.med.fw.security.Permission" access="FIELD"
		name="Permission">
		<table schema="HT" name="PERMISSION" />
		<attribute-override name="id">
			<column name="PERMISSION_ID" />
		</attribute-override>
		<attributes>
			<basic name="name">
				<column name="PERMISSION_NAME" />
			</basic>
			<basic name="description">
				<column name="DESCRIPTION" />
			</basic>
			<transient name="description" />
			<transient name="application" />
		</attributes>
	</entity>

	<embeddable class="gov.va.med.fw.security.UserCredentials">
		<attributes>
			<basic name="userID">
				<column name="USER_NAME" />
			</basic>
			<transient name="password" />
			<transient name="logicalID" />
			<transient name="securityCode" />
			<transient name="anonymous" />
			<transient name="verified" />
		</attributes>
	</embeddable>
</entity-mappings>