#!/usr/bin/ksh                                                        
                                                                    
# Name: extractLevelUsingMapFile
# 
# Purpose: To extract a committed Level using the Map File in the server.
#          This will use a File extract for each file involved, and will not
#          use the actual level extract code.
# 
# IMPLEMENTATION NOTES:   
#          This sample needs further improvement for handling input parameters
#          and error messages.
#
# WARNING:   This is AS-IS code.
#
# EDITORIAL Notes:
# 1) The ChangeView will return duplicate fileName/SID combinations   
#    if multiple tracks were specified upon checkin of a file so you   
#    may need to sort the output from Report -view ChangeView before     
#    iusing "awk".  It is possible that the following will work but may
#    not be too eloquent:
#                                                                   
#       Report -view ChangeView -where "fileId=$FILEID and \          
#         versionId=$VERSIONID and release  Name='$RELEASE' " -raw |
#         sed "s/\|/:/g" | sort -u -k4,5 -t: |                 
#         awk -F":" ' {system("/usr/lpp/cmvc/bin/File -extract " $5 \   
#         " -relative /yourAFSDir -release " $1 " -version " $4)} '     
#                                                                   
# 2) For destroyed files, the File -extract will not work since the
#    File entry in the database is destroyed.  Therefore the only   
#    thing you could do is issue a native SCCS command to get the        
#    file from the CMVC server.  This is NOT recommended since you       
#    do not really want your users issuing native SCCS commands from the 
#    CMVC server.  
# 
 
#  The following could be made as input parameters               
export RELEASE=r1
export LEVEL=l1                                                       
                                                                      
export mapsFile=$HOME/maps/$RELEASE/$LEVEL                        
                                                               
while read line                                       
do                                                                   
   FILENAME=`echo $line | cut -d' ' -f1 `    # field 1 is filename     
   VERSIONID=`echo $line | cut -d' ' -f2 `   # field 2 is version id
   FILEID=`echo $line | cut -d' ' -f3 `      # field 3 is file id   
                                                                       
   Report -view ChangeView -where "fileId=$FILEID and \                         
     versionId=$VERSIONID and releaseName='$RELEASE' " -raw |
      awk -F"|" '{system("/usr/lpp/cmvc/bin/File -extract " $5 \      
      " -relative /yourAFSDir -release " $1 " -version " $4)} '       
                                                                  
   if [ $? -ne 0 ]                                             
   then                                               
      echo "This may have failed because it is a destroyed file"     
      echo "Error found in Report -view ChangeView or File -extract"   
      terminate                                                     
   fi                                                               
done < $mapsFile                                                       
 
exit

# end of file
