DBA Data[Home] [Help]

PACKAGE BODY: APPS.PER_IMAGE_UPLOAD_PKG

Source


1 package body PER_IMAGE_UPLOAD_PKG as
2 /* $Header: peimgupl.pkb 120.2.12020000.2 2012/11/22 11:21:32 avarri ship $ */
3 
4 
5 g_image_is_blob boolean := null;
6 
7 function image_is_blob return boolean  is
8 l_data_type varchar2(100);
9 l_username  varchar2(100);
10 begin
11 
12   if g_image_is_blob is null
13   then
14 
15 
16     -- There may be fnd/ad utility routines for one or
17     -- both of these cursors. To check - and ideally
18     -- replace.
19 
20     select u.oracle_username
21     into   l_username
22     from   fnd_oracle_userid         u,
23            fnd_product_installations p
24     where  p.application_id = 800
25     and    u.oracle_id      = p.oracle_id;
26     --
27    select col.data_type
28     into   l_data_type
29     from   user_synonyms syn, dba_tab_columns col
30     where  syn.table_owner    = l_username
31     and    syn.synonym_name   = 'PER_IMAGES'
32     and    col.owner          = syn.table_owner
33     and    col.table_name     = syn.table_name
34     and    col.column_name    = 'IMAGE' ;
35     --
36     g_image_is_blob := ( l_data_type = 'BLOB' );
37 
38    end if;
39 
40    return (g_image_is_blob);
41 
42 end image_is_blob;
43 
44 -- procedure generic_error - copied from code in:
45 -- $FND_TOP/patch/115/sql/AFCINFOB.pls
46 --
47 
48 procedure generic_error(routine in varchar2,
49                         errcode in number,
50                         errmsg in varchar2) is
51 l_msg varchar2(2000);
52 begin
53     fnd_message.set_name('FND', 'SQL_PLSQL_ERROR');
54     fnd_message.set_token('ROUTINE', routine);
55     fnd_message.set_token('ERRNO', errcode);
56     fnd_message.set_token('REASON', errmsg);
57     fnd_message.raise_error;
58 end;
59 
60 --
61 -- Transfer_pvt
62 --
63 -- java wrapper for java upload code
64 --
65 
66 function Transfer_pvt (file_id       in number,
67                        image_id      in number,
68                        connectString in varchar2,
69                        un            in varchar2,
70                        pw            in varchar2,
71                        msg           in out nocopy varchar2) return number
72    as language java
73    name 'oracle.apps.per.util.ImageUtils.lob_to_img(long,
74                                                     long,
75                                                     java.lang.String,
76                                                     java.lang.String,
77                                                     java.lang.String,
78                                                     java.lang.String[])
79    return int' ;
80 
81 --
82 -- Transfer
83 -- Only the file_id,image_id parameters are relevant if the
84 -- PER_IMAGES.IMAGE is a BLOB rather than a LONG RAW
85 function Transfer (file_id       in number,
86                    image_id      in number,
87                    connectString in varchar2,
88                    un            in varchar2,
89                    pw            in varchar2,
90                    msg           in out nocopy varchar2) return int is
91 
92 l_retval number;
93 --
94 begin
95 --
96 
97   if  ( image_is_blob )
98   then
99 
100     execute immediate
101         'UPDATE PER_IMAGES
102          SET IMAGE = (SELECT FILE_DATA
103                       FROM   FND_LOBS
104                       WHERE  FILE_ID = :1)
105          WHERE IMAGE_ID = :2 '
106     using file_id , image_id ;
107 
108      if ( sql%rowcount = 1 ) then
109         l_retval := 1 ;
110      else
111         l_retval := 0 ;
112      end if;
113 
114   else
115 
116     -- call java code
117     l_retval := Transfer_pvt (file_id,
118                               image_id,
119                               connectString,
120                               un,
121                               pw,
122                               msg);
123   end if;
124 
125   return (l_retval);
126 
127   exception
128     when others then
129     --
130     -- DK
131     -- The message text for a javavm error contains the main
132     -- details - there is usually a generic error code like
133     -- ORA-29532, ORA-29540. We raise -20001 to ensure that
134     -- the message text is displayed in forms. For some reason
135     -- that message text would not otherwise be displayed.
136     -- This is probably a bug in AOL's message handler
137     --
138     -- sqlcode is not being passed to avoid the error number appearing
139     -- twice
140     --
141     generic_error(routine => 'PER_IMAGE_UPLOAD_PKG',
142                   errcode =>  null,
143                   errmsg  =>  sqlerrm);
144 
145 
146 --
147 end Transfer;
148 --
149 
150 --
151 -- LOAD
152 --
153 procedure Load( doc       in varchar2,
154                 access_id in number ) is
155 
156 file_id number ;
157 
158 begin
159 
160 file_id :=  fnd_gfm.confirm_upload(
161               access_id    => access_id,
162               file_name    => doc,
163               program_name => 'PERWSIMG');
164 
165 htp.htmlopen;
166 htp.p('Loaded: '||doc||' File ID: '||file_id);
167 htp.htmlclose;
168 
169 exception
170   when others then
171     htp.htmlopen;
172     htp.p('error in load');
173     htp.htmlclose;
174     raise;
175 end Load;
176 
177 --
178 -- LAUNCH
179 --
180 procedure Launch is
181 
182 form_action varchar2(2000);
183 access_id   number := fnd_gfm.authorize(NULL);
184 user_id     number := fnd_profile.value('USER_ID');
185 
186 begin
187 
188 form_action := fnd_gfm.construct_upload_url(fnd_web_config.gfm_agent,
189                                            'per_image_upload_pkg.Load',
190                                             access_id);
191 
192 htp.htmlOpen;
193 
194 htp.p('<form action='||form_action||
195         ' method=post enctype="multipart/form-data">');
196 
197 
198 htp.p('<input type="File" name="doc"></input>');
199 
200 htp.p('<input type="Hidden" name="access_id" value='||access_id||'>'||
201       '</input>');
202 
203 htp.p('<input type="Hidden" name="user_id" value='||user_id||'>'||
204       '</input>');
205 
206 htp.p('<input type="Submit" value="Submit"></input>');
207 
208 htp.p('</form>');
209 
210 htp.htmlClose;
211 
212 end Launch;
213 
214 end PER_IMAGE_UPLOAD_PKG;