?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE Accounting and Validation: Family Interfaces' ??
MODULE avm$family_interfaces;

{ PURPOSE:
{
{   This module contains the external interfaces used to create and change a
{ family, and to get the set name for a family.
{
{  DESIGN:
{
{   The interfaces in this module validate the caller before performing the
{ requested functions.

?? PUSH (LISTEXT := ON) ??
?? NEWTITLE := 'Declarations', EJECT ??
*copyc ave$family_errors
*copyc fst$path
*copyc jmc$system_family
?? POP ??
?? OLDTITLE ??
?? NEWTITLE := 'XREF Procedures', EJECT ??
*copyc amp$return
*copyc avp$change_acct_proj_value
*copyc avp$change_capability_value
*copyc avp$change_login_password_value
*copyc avp$close_validation_file
*copyc avp$create_$system_user
*copyc avp$create_account_member_rec
*copyc avp$create_account_record
*copyc avp$create_project_record
*copyc avp$create_user_record
*copyc avp$end_subutility_session
*copyc avp$open_validation_file
*copyc avp$system_administrator
*copyc fsp$build_file_ref_from_elems
*copyc osp$append_status_parameter
*copyc osp$generate_log_message
*copyc osp$get_set_name
*copyc osp$set_status_abnormal
*copyc pfp$change_family_name
*copyc pfp$define_master_catalog
?? OLDTITLE ??
?? NEWTITLE := 'Static Variables', EJECT ??
*copyc stv$system_set_name
?? OLDTITLE ??
?? NEWTITLE := 'avp$change_family_interface', EJECT ??
*copyc avh$change_family_interface
  PROCEDURE [XDCL, #GATE] avp$change_family_interface
    (    family_name: ost$family_name;
         new_family_name: ost$family_name;
     VAR status: ost$status);

    VAR
      set_name: stt$set_name,
      system_administrator: boolean;

    status.normal := TRUE;

    IF NOT avp$system_administrator() THEN
      osp$set_status_abnormal ('AV', ave$insufficient_authority, '', status);
      RETURN;
    IFEND;

    osp$get_set_name (family_name, set_name, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    pfp$change_family_name (set_name, family_name, new_family_name, status);

  PROCEND avp$change_family_interface;
?? OLDTITLE ??
?? NEWTITLE := 'avp$create_family_interface', EJECT ??
*copyc avh$create_family_interface
  PROCEDURE [XDCL, #GATE] avp$create_family_interface
    (    family_name: ost$family_name;
         family_administrator: ost$user_name;
         account_name: avt$account_name;
         project_name: avt$project_name;
         password: ost$name;
         permanent_file_set: stt$set_name;
     VAR status: ost$status);

    VAR
      capability: boolean,
      charge_id: pft$charge_id,
      command_table_size: integer,
      file_information: avt$template_file_information,
      local_status: ost$status,
      login_password: avt$login_password,
      path: ^array [1 .. * ] of pft$name,
      set_name: stt$set_name,
      record_id: ost$name,
      system_administrator: boolean,
      validation_file_path: fst$path;

    status.normal := TRUE;

    IF NOT avp$system_administrator() THEN
      osp$set_status_abnormal ('AV', ave$insufficient_authority, '', status);
      RETURN;
    IFEND;

{ If the set name specifed is a null name then use the system default set name.

    set_name := permanent_file_set;
    IF set_name = osc$null_name THEN
      set_name := stv$system_set_name;
    IFEND;

{ Define the master catalog for the $SYSTEM user for this family so
{ the validation file may be placed on it.

    charge_id.account := osc$null_name;
    charge_id.project := osc$null_name;
    pfp$define_master_catalog (set_name, family_name, jmc$system_user, charge_id, status);
    IF NOT status.normal THEN
      IF status.condition = pfe$duplicate_master_catalog THEN
        osp$set_status_abnormal ('AV', ave$catalog_already_exists, jmc$system_user, local_status);
        osp$append_status_parameter (osc$status_parameter_delimiter, family_name, local_status);
        osp$generate_log_message ($pmt$ascii_logset [pmc$system_log, pmc$job_log], local_status,
              {ignore} status);
        status.normal := TRUE;
      ELSE
        RETURN;
      IFEND;
    IFEND;

{ Build the path to the validation file for this family.

    PUSH path: [1 .. 3];
    path^ [1] := family_name;
    path^ [2] := jmc$system_user;
    path^ [3] := avc$validation_file_name;
    fsp$build_file_ref_from_elems (path, validation_file_path, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

{ Create the validation file.

    avp$open_validation_file (validation_file_path, NIL, NIL, TRUE, file_information, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

  /validation_file_open/
    BEGIN

{ Add the validations for the $SYSTEM user to the validation file.

      avp$create_$system_user (family_name, file_information, status);
      IF NOT status.normal THEN
        IF status.condition = ave$user_already_exists THEN
          osp$set_status_abnormal ('AV', ave$user_validation_info_exists, jmc$system_user, local_status);
          osp$append_status_parameter (osc$status_parameter_delimiter, family_name, local_status);
          osp$generate_log_message ($pmt$ascii_logset [pmc$system_log, pmc$job_log], local_status,
                {ignore} status);
          osp$set_status_abnormal ('PF', pfe$family_already_exists, family_name, status);
        IFEND;
        EXIT /validation_file_open/;
      IFEND;

{ Add the validations for the specified family administrator to the validation file.

      avp$create_user_record (family_administrator, record_id, command_table_size, file_information, status);
      IF NOT status.normal THEN
        IF status.condition = ave$master_catalog_exists THEN
          osp$set_status_abnormal ('AV', ave$catalog_already_exists, family_administrator, local_status);
          osp$append_status_parameter (osc$status_parameter_delimiter, family_name, local_status);
          osp$generate_log_message ($pmt$ascii_logset [pmc$system_log, pmc$job_log], local_status,
                {ignore} status);
          status.normal := TRUE;
        ELSEIF status.condition = ave$user_already_exists THEN
          osp$set_status_abnormal ('AV', ave$user_validation_info_exists, family_administrator,
                local_status);
          osp$append_status_parameter (osc$status_parameter_delimiter, family_name, local_status);
          osp$generate_log_message ($pmt$ascii_logset [pmc$system_log, pmc$job_log], local_status,
                {ignore} status);
          status.normal := TRUE;
          EXIT /validation_file_open/;
        ELSE
          EXIT /validation_file_open/;
        IFEND;
      IFEND;

{ Assign the specifed validations to the specified family administrator.

      login_password.encrypted := FALSE;
      login_password.value := password;
      avp$change_login_password_value (avc$login_password, NIL, ^login_password, NIL, NIL, NIL, NIL, NIL, NIL,
            NIL, record_id, { update_batch_job_passwords = } FALSE, file_information, {ignore} status);
      login_password.value := osc$null_name;

      capability := TRUE;
      avp$change_capability_value (avc$family_administration, ^capability, record_id, file_information,
            {ignore} status);

      avp$change_acct_proj_value (avc$default_account_project, ^account_name, ^project_name, record_id,
            file_information, {ignore} status);

      avp$end_subutility_session (record_id, TRUE, file_information, {ignore} status);
      status.normal := TRUE;

{ Create the account validation record.

      avp$create_account_record (account_name, record_id, command_table_size, file_information, status);
      IF status.normal THEN
        avp$end_subutility_session (record_id, TRUE, file_information, {ignore} status);
      IFEND;
      status.normal := TRUE;

{ Create the project validation record.

      avp$create_project_record (account_name, project_name, record_id, command_table_size, file_information,
            status);
      IF status.normal THEN
        avp$end_subutility_session (record_id, TRUE, file_information, {ignore} status);
      IFEND;
      status.normal := TRUE;

{ Create the account member validation record for the family administrator.

      avp$create_account_member_rec (account_name, family_administrator, record_id, command_table_size,
            file_information, status);
      IF status.normal THEN
        avp$end_subutility_session (record_id, TRUE, file_information, {ignore} status);
      IFEND;
      status.normal := TRUE;
    END /validation_file_open/;

    IF status.normal THEN
      avp$close_validation_file (file_information, status);
    ELSE
      avp$close_validation_file (file_information, local_status);
    IFEND;
    amp$return (validation_file_path, local_status);

  PROCEND avp$create_family_interface;
?? OLDTITLE ??
?? NEWTITLE := '  avp$get_set_name', EJECT ??
*copyc avh$get_set_name
  PROCEDURE [XDCL, #GATE] avp$get_set_name
    (    family: ost$family_name;
     VAR set_name: stt$set_name;
     VAR status: ost$status);

    status.normal := TRUE;

    osp$get_set_name (family, set_name, status);

  PROCEND avp$get_set_name;
?? OLDTITLE ??
MODEND avm$family_interfaces;

