(*
 * $Id$
 *
 * JSDAI(TM), a way to implement STEP, ISO 10303
 * Copyright (C) 1997-2008, LKSoftWare GmbH, Germany
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License
 * version 3 as published by the Free Software Foundation (AGPL v3).
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * JSDAI is a registered trademark of LKSoftWare GmbH, Germany
 * This software is also available under commercial licenses.
 * See also http://www.jsdai.net/
 *)

(*schema_mapping approval(Approval_arm, Approval_mim);*)

uof_mapping Approval(Approval);

entity_mapping approval_armx(approval_armx, approval);
(*
attribute_mapping status(status, approval_status.name, Approval_status);

				  approval.status ->
					approval_status
					approval_status.name
				
end_attribute_mapping;
*)
attribute_mapping purpose(purpose, approval.level);

end_attribute_mapping;

attribute_mapping planned_date(planned_date, $PATH, date_and_time);
approval <-
				  approval_date_time.dated_approval
					approval_date_time
					{approval_date_time.role ->
					object_role
					object_role.name='planned'}
					approval_date_time.date_time ->
					date_time_select
					{(date_time_select = date_and_time)
					(date_time_select = date)}
				
end_attribute_mapping;

attribute_mapping planned_date(planned_date, $PATH, Calendar_date);
approval <-
				  approval_date_time.dated_approval
					approval_date_time
					{approval_date_time.role ->
					object_role
					object_role.name='planned'}
					approval_date_time.date_time ->
					date_time_select
					{(date_time_select = date_and_time)
					(date_time_select = date
					date => calendar_date)}
				
end_attribute_mapping;

attribute_mapping actual_date(actual_date, $PATH, date_and_time);
approval <-
				  approval_date_time.dated_approval
					approval_date_time
					{approval_date_time.role ->
					object_role
					object_role.name='actual'}
					approval_date_time.date_time ->
					date_time_select
					{(date_time_select = date_and_time)
					(date_time_select = date)}
				
end_attribute_mapping;

attribute_mapping actual_date(actual_date, $PATH, Calendar_date);
approval <-
				  approval_date_time.dated_approval
					approval_date_time
					{approval_date_time.role ->
					object_role
					object_role.name='actual'}
					approval_date_time.date_time ->
					date_time_select
					{(date_time_select = date_and_time)
					(date_time_select = date
					date => calendar_date)}
				
end_attribute_mapping;

end_entity_mapping;

entity_mapping approval_assignment_armx(approval_assignment_armx, applied_approval_assignment);

mapping_constraints;

			applied_approval_assignment <= approval_assignment
			
end_mapping_constraints;

attribute_mapping assigned_approval(assigned_approval, $PATH, Approval);

			approval_assignment.assigned_approval -> approval
			
end_attribute_mapping;

attribute_mapping items(items, $PATH, approval_item);

			applied_approval_assignment.items[i] -> approval_item
			
end_attribute_mapping;

attribute_mapping role(role, object_role.name);

			applied_approval_assignment <= approval_assignment
			approval_assignment = role_select
			role_select <- role_association.item_with_role
			role_association.role -> object_role
			object_role.name
		  
end_attribute_mapping;

end_entity_mapping;
(* It is taken from AIM
entity_mapping Approval_relationship(Approval_relationship, approval_relationship);

attribute_mapping relation_type(relation_type, approval_relationship.name);

end_attribute_mapping;

attribute_mapping description(description, approval_relationship.description);

end_attribute_mapping;

attribute_mapping relating_approval(relating_approval, $PATH, Approval);

				approval_relationship.relating_approval -> approval
				
end_attribute_mapping;

attribute_mapping related_approval(related_approval, $PATH, Approval);

				approval_relationship.related_approval -> approval
				
end_attribute_mapping;

end_entity_mapping;
*)
(* Entity with the same name is taken from AIM
entity_mapping Approval_status(Approval_status, approval_status);

attribute_mapping status_name(status_name, approval_status.name);

end_attribute_mapping;

end_entity_mapping;
*)
entity_mapping Approving_person_organization(Approving_person_organization, approval_person_organization);

attribute_mapping person_organization(person_organization, $PATH, Organization);

			approval_person_organization 
			approval_person_organization.person_organization -> person_organization_select
			person_organization_select = organization

			  
end_attribute_mapping;

attribute_mapping person_organization(person_organization, $PATH, person_and_organization);

			approval_person_organization 
			approval_person_organization.person_organization -> person_organization_select
			person_organization_select = person_and_organization					
			  
end_attribute_mapping;

attribute_mapping approval_date(approval_date, $PATH, Calendar_date);

(date_item = approval_person_organization
date_item <- applied_date_assignment.items[i]
applied_date_assignment <= date_assignment
{date_assignment.role -> date_role
date_role.name = 'sign off'}
{date_assignment.assigned_date -> date
date => calendar_date})
				
end_attribute_mapping;

attribute_mapping approval_date(approval_date, $PATH, date_and_time);

			(date_and_time_item = approval_person_organization
date_and_time_item <-
applied_date_and_time_assignment.items[i]
applied_date_and_time_assignment <=
date_and_time_assignment
{date_and_time_assignment.role ->
date_time_role
date_time_role.name = 'sign off'})
				
end_attribute_mapping;

attribute_mapping authorized_approval(authorized_approval, $PATH, Approval);

				approval_person_organization.authorized_approval -> approval 
				
end_attribute_mapping;

attribute_mapping role(role, approval_role.role);

	approval_person_organization.role -> approval_role
	approval_role.role
	
end_attribute_mapping;

end_entity_mapping;
end_uof_mapping;

(*end_schema_mapping;*)
