-- WAP creation data model 
-- written by Andrew Grumet (aegrumet@arsdigita.com).
-- ported to acs40 by Shan Shan Huang (shuang@arsdigita.com)

-- We will store data about known WAP user agents, to hand off
-- incoming requests to the right place.
--
-- This is free software distributed under the terms of the GNU Public
-- License.  Full text of the license is available from the GNU Project:
-- http://www.fsf.org/copyleft/gpl.html

begin
  acs_object_type.create_type (
    supertype		=> 'acs_object',
    object_type 	=> 'wap_user_agent',
    pretty_name 	=> 'WAP User Agent',
    pretty_plural	=> 'WAP User Agents',
    table_name		=> 'wap_user_agents',
    id_column		=> 'user_agent_id'
  );
end;
/
show error;

declare 
  atrr_id acs_attributes.attribute_id%TYPE;
begin
  atrr_id := acs_attribute.create_attribute (
    object_type		=> 'wap_user_agent',
    attribute_name	=> 'NAME',
    pretty_name		=> 'Name',
    pretty_plural	=> 'Names',
    datatype		=> 'string'
  );

  atrr_id := acs_attribute.create_attribute (
    object_type		=> 'wap_user_agent',
    attribute_name	=> 'CREATION_COMMENT',
    pretty_name		=> 'Comment',
    pretty_plural	=> 'Comments',
    datatype		=> 'string'
  );

  atrr_id := acs_attribute.create_attribute (
    object_type		=> 'wap_user_agent',
    attribute_name	=> 'ACTIVE_P',
    pretty_name		=> 'Active Status',
    pretty_plural	=> 'Active Status',
    datatype		=> 'string'
  );
end;
/
show error;

create table wap_user_agents (
	user_agent_id		integer references acs_objects(object_id) primary key,
	name			varchar(200)
				  constraint wap_user_agent_name_nn not null,
	creation_comment        varchar(4000),
        active_p		char(1) 
				constraint wap_user_agt_act_p_chk check(active_p in('t', 'f'))
);

-- package for wap_user_agents
create or replace package wap_user_agent 
as
  function new (
    v_user_agent_id	in wap_user_agents.user_agent_id%TYPE default null,
    v_name		in wap_user_agents.name%TYPE,
    v_creation_comment	in wap_user_agents.creation_comment%TYPE,
    v_active_p		in wap_user_agents.creation_comment%TYPE default 't',
    v_creation_user	in acs_objects.creation_user%TYPE,
    v_creation_ip	in acs_objects.creation_ip%TYPE
  ) return wap_user_agents.user_agent_id%TYPE;

  procedure delete (
    v_user_agent_id	in wap_user_agents.user_agent_id%TYPE
  );

  procedure toggle_active_p (
    v_user_agent_id	in wap_user_agents.user_agent_id%TYPE
  );

  procedure modify (
    v_user_agent_id	in wap_user_agents.user_agent_id%TYPE,
    v_name		in wap_user_agents.name%TYPE,
    v_creation_comment	in wap_user_agents.creation_comment%TYPE,
    v_active_p		in wap_user_agents.active_p%TYPE
  );

end wap_user_agent;
/
show error;

-- package body for wap_user_agent
create or replace package body wap_user_agent
as
  function new (
    v_user_agent_id	in wap_user_agents.user_agent_id%TYPE default null,
    v_name		in wap_user_agents.name%TYPE,
    v_creation_comment	in wap_user_agents.creation_comment%TYPE,
    v_active_p		in wap_user_agents.creation_comment%TYPE default 't',
    v_creation_user	in acs_objects.creation_user%TYPE,
    v_creation_ip	in acs_objects.creation_ip%TYPE
  ) return wap_user_agents.user_agent_id%TYPE
  as 
    new_id	integer;
  begin
    new_id := acs_object.new (
      object_id		=> v_user_agent_id,
      object_type	=> 'wap_user_agent',
      creation_date	=> sysdate,
      creation_user	=> v_creation_user,
      creation_ip	=> v_creation_ip,
      context_id	=> null
    );

    insert into wap_user_agents
      (user_agent_id, name, creation_comment, active_p)
    values
      (new_id, v_name, v_creation_comment, v_active_p);

    return new_id; 	
  end new;

  procedure delete (
    v_user_agent_id	in wap_user_agents.user_agent_id%TYPE
  ) 
  is
  begin
    delete from wap_user_agents where user_agent_id = v_user_agent_id;

    acs_object.delete(v_user_agent_id);
  end delete;

  procedure toggle_active_p (
    v_user_agent_id	in wap_user_agents.user_agent_id%TYPE
  )
  is
    v_active_p	varchar2(1);
  begin
    select active_p into v_active_p
    from wap_user_agents where user_agent_id = v_user_agent_id;

    update wap_user_agents 
    set active_p = decode(v_active_p, 't', 'f', 't')
    where user_agent_id = v_user_agent_id ;

  end toggle_active_p;

  procedure modify (
    v_user_agent_id	in wap_user_agents.user_agent_id%TYPE,
    v_name		in wap_user_agents.name%TYPE,
    v_creation_comment	in wap_user_agents.creation_comment%TYPE,
    v_active_p		in wap_user_agents.active_p%TYPE
  )
  is
  begin
    update wap_user_agents
      set name = v_name,
          creation_comment = v_creation_comment,
 	  active_p = v_active_p
    where user_agent_id = v_user_agent_id;
  end modify;

end wap_user_agent;
/
show error;

-- A bunch of user-agent data

declare
  v_user_agent_id	integer;
begin
  v_user_agent_id := wap_user_agent.new(null, 'ALAV UP/4.0.7', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Alcatel-BE3/1.0 UP/4.0.6c', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'AUR PALM WAPPER', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Device V1.12', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'EricssonR320/R1A', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'fetchpage.cgi/0.53', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Java1.1.8', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'm-crawler/1.0 WAP', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Materna-WAPPreview/1.1.3', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'MC218 2.0 WAP1.1', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Mitsu/1.1.A', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'MOT-CB/0.0.19 UP/4.0.5j', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'MOT-CB/0.0.21 UP/4.0.5m', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Nokia-WAP-Toolkit/1.2', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Nokia-WAP-Toolkit/1.3beta', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Nokia7110/1.0', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Nokia7110/1.0 ()', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Nokia7110/1.0 (04.67)', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Nokia7110/1.0 (04.69)', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Nokia7110/1.0 (04.70)', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Nokia7110/1.0 (04.71)', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Nokia7110/1.0 (04.73)', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Nokia7110/1.0 (04.74)', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Nokia7110/1.0 (04.76)', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Nokia7110/1.0 (04.77)', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Nokia7110/1.0 (04.80)', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Nokia7110/1.0 (30.05)', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'PLM''s WapBrowser', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'QWAPPER/1.0', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'R380 2.0 WAP1.1', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'SIE-IC35/1.0', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'SIE-P35/1.0 UP/4.1.2a', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'UP.Browser/3.01-IG01', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'UP.Browser/3.01-QC31', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'UP.Browser/3.02-MC01', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'UP.Browser/3.02-SY01', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'UP.Browser/3.1-UPG1', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'UP.Browser/4.1.2a-XXXX', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'UPG1 UP/4.0.7', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Wapalizer/1.0', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Wapalizer/1.1', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'WapIDE-SDK/2.0; (R320s (Arial))', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'WAPJAG Virtual WAP', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'WAPman Version 1.1', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'WAPman Version 1.1 beta:Build W2000020401', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Waptor 1.0', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'WapView 0.00', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'WapView 0.20371', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'WapView 0.28', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'WapView 0.37', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'WapView 0.46', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'WapView 0.47', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'WinWAP 2.2 WML 1.1', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'wmlb', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'YourWap/0.91', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'YourWap/1.16', null, 't');
  v_user_agent_id := wap_user_agent.new(null, 'Zetor', null, 't');
end;






 