DBA Data[Home] [Help]

PACKAGE BODY: APPS.AMW_ATTACHMENT_PVT

Source


1 PACKAGE BODY AMW_Attachment_PVT as
2 /* $Header: amwvatcb.pls 120.0 2005/05/31 18:34:48 appldev noship $ */
3 -- ===============================================================
4 -- Start of Comments
5 -- Package name
6 --          AMW_Attachment_PVT
7 -- Purpose
8 --
9 -- History
10 --
11 -- NOTE
12 --
13 -- End of Comments
14 -- ===============================================================
15 
16 
17 G_PKG_NAME CONSTANT VARCHAR2(30):= 'AMW_Attachment_PVT';
18 G_FILE_NAME CONSTANT VARCHAR2(12) := 'AMWvatcb.pls';
19 
20 AMW_DEBUG_HIGH_ON boolean   := FND_MSG_PUB.CHECK_MSG_LEVEL(FND_MSG_PUB.G_MSG_LVL_DEBUG_HIGH);
21 AMW_DEBUG_LOW_ON boolean    := FND_MSG_PUB.CHECK_MSG_LEVEL(FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW);
22 AMW_DEBUG_MEDIUM_ON boolean := FND_MSG_PUB.CHECK_MSG_LEVEL(FND_MSG_PUB.G_MSG_LVL_DEBUG_MEDIUM);
23 
24 -- Hint: Primary key needs to be returned.
25 PROCEDURE Create_Fnd_Attachment(
26     p_api_version_number         IN   NUMBER,
27     p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE,
28     p_commit                     IN   VARCHAR2     := FND_API.G_FALSE,
29     p_validation_level           IN   NUMBER       := FND_API.G_VALID_LEVEL_FULL,
30 
31     x_return_status              OUT NOCOPY VARCHAR2,
32     x_msg_count                  OUT NOCOPY NUMBER,
33     x_msg_data                   OUT NOCOPY VARCHAR2,
34 
35     p_Fnd_Attachment_rec         IN   fnd_attachment_rec_type,
36     x_document_id                OUT NOCOPY NUMBER,
37     x_attached_document_id       OUT NOCOPY NUMBER
38      )
39 
40  IS
41 L_API_NAME                  CONSTANT VARCHAR2(30) := 'Create_Fnd_Attachment';
42 L_API_VERSION_NUMBER        CONSTANT NUMBER   := 1.0;
43    l_return_status_full     VARCHAR2(1);
44    l_document_ID            NUMBER;
45    l_media_ID            NUMBER;
46    l_attached_document_ID   NUMBER;
47    l_dummy       NUMBER;
48    l_seq_num     NUMBER := 10;
49    l_row_id     VARCHAR2(255);
50    l_Fnd_Attachment_rec fnd_attachment_rec_type;
51    l_create_Attached_Doc boolean := true;
52 
53    CURSOR c_attached_doc_id IS
54       SELECT FND_ATTACHED_DOCUMENTS_S.nextval
55       FROM dual;
56 
57    CURSOR c_attached_doc_id_exists (l_id IN NUMBER) IS
58       SELECT 1
59       FROM FND_ATTACHED_DOCUMENTS
60       WHERE document_id = l_id;
61 
62 BEGIN
63       -- Standard Start of API savepoint
64       SAVEPOINT CREATE_Fnd_Attachment_PVT;
65 
66       -- Standard call to check for call compatibility.
67       IF NOT FND_API.Compatible_API_Call ( l_api_version_number,
68                                            p_api_version_number,
69                                            l_api_name,
70                                            G_PKG_NAME)
71       THEN
72           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
73       END IF;
74 
75       -- Initialize message list if p_init_msg_list is set to TRUE.
76       IF FND_API.to_Boolean( p_init_msg_list )
77       THEN
78          FND_MSG_PUB.initialize;
79       END IF;
80 
81       -- Debug Message
82       IF (AMW_DEBUG_HIGH_ON) THEN
83             AMW_UTILITY_PVT.debug_message('Private API: ' || l_api_name || 'start');
84       END IF;
85 
86 
87       -- Initialize API return status to SUCCESS
88       x_return_status := FND_API.G_RET_STS_SUCCESS;
89 
90    -- Local variable initialization
91 
92       -- =========================================================================
93       -- Validate Environment
94       -- =========================================================================
95 
96       IF FND_GLOBAL.User_Id IS NULL
97       THEN
98  AMW_Utility_PVT.Error_Message(p_message_name => 'USER_PROFILE_MISSING');
99           RAISE FND_API.G_EXC_ERROR;
100       END IF;
101 
102       -- Debug Message
103       IF (AMW_DEBUG_HIGH_ON) THEN
104             AMW_UTILITY_PVT.debug_message( 'Private API: Calling table handler fnd_documents_pkg.insert_row');
105       END IF;
106 
107      l_media_id := p_Fnd_Attachment_rec.media_id;
108 
109       -- Invoke table handler
110       fnd_documents_pkg.insert_row(
111 	 X_rowid => l_row_id,
112 	 X_document_id => x_document_id,
113 	 X_creation_date => sysdate,
114 	 X_created_by => FND_GLOBAL.USER_ID,
115 	 X_last_update_date => sysdate,
116 	 X_last_updated_by => FND_GLOBAL.USER_ID,
117 	 X_last_update_login => FND_GLOBAL.CONC_LOGIN_ID,
118 	 X_datatype_id => p_Fnd_Attachment_rec.datatype_id,
119 	 X_category_id => p_Fnd_Attachment_rec.category_id,
120 	 X_security_type => p_Fnd_Attachment_rec.security_type,
121 	 X_publish_flag => p_Fnd_Attachment_rec.publish_flag,
122 	 X_usage_type => p_Fnd_Attachment_rec.usage_type,
123 	 X_language => p_Fnd_Attachment_rec.language,
124 	 X_description =>p_Fnd_Attachment_rec.description,
125 	 X_file_name => p_Fnd_Attachment_rec.file_name,
126 	 X_media_id => l_media_id
127 	 );
128       if (p_Fnd_Attachment_rec.datatype_id = 1) then
129 
130 	 /* Verify if the media_id is not null */
131 	 if (p_Fnd_Attachment_rec.media_id is null) then
132 	     /* It means that a new text needs to be created, otherwise not */
133 	     /* Populate Short Text */
134 	     insert into
135 	     fnd_documents_short_text
136 	     (media_id,
137 	      short_text
138 	     )
139 	     values
140 	     (l_media_id,
141 	      p_Fnd_Attachment_rec.short_text
142 	     );
143           else
144 	     /*
145 		Update fnd_documents_tl because FND_API inserts newly generated
146 		media_id into that table.
147              */
148 	      update fnd_documents_tl
149 	      set media_id = p_Fnd_Attachment_rec.media_id
150 	      where document_id = x_document_id;
151 
152           end if;
153 
154       elsif (p_Fnd_Attachment_rec.datatype_id = 6) then /* File */
155 	 /* For File we have already generated a file id - the fnd_documents_pkg.insert_row
156 	    table handler has generated a fnd_lobs_s.nextval but that's not what shoule be the
157 	    reference to the FND_LOBS table - because the upload program has already generated a
158 	    sequence */
159          /**
160 	 update fnd_documents_tl
161 	 set media_id = p_Fnd_Attachment_rec.media_id
162 	 where document_id = l_document_id;
163 	 **/
164 	 null;
165       end if;
166 
167       if (p_Fnd_Attachment_rec.attachment_type is not null) then
168 
169 	 if ((p_Fnd_Attachment_rec.attachment_type = 'WEB_TEXT') OR
170 	    (p_Fnd_Attachment_rec.attachment_type = 'WEB_IMAGE')) then
171 
172 	    l_create_Attached_Doc := false;
173 
174          end if;
175 
176       end if;
177 
178       if (l_create_Attached_Doc) then
179 
180             /*
181 	      IF p_Fnd_Attachment_rec.attached_DOCUMENT_ID IS NULL THEN
182             */
183             LOOP
184                 l_dummy := NULL;
185                 OPEN c_attached_doc_id;
186                 FETCH c_attached_doc_id INTO l_attached_document_ID;
187                 CLOSE c_attached_doc_id;
188 
189                 OPEN c_attached_doc_id_exists(l_attached_document_ID);
190                 FETCH c_attached_doc_id_exists INTO l_dummy;
191                 CLOSE c_attached_doc_id_exists;
192                 EXIT WHEN l_dummy IS NULL;
193             END LOOP;
194 
195             l_Fnd_Attachment_rec.attached_document_id := l_attached_document_id;
196             x_attached_document_id := l_attached_document_id;
197 
198 
199 	   /* Populate FND Attachments */
200 	   fnd_attached_documents_pkg.Insert_Row
201 	   (  x_rowid => l_row_id,
202 	      X_attached_document_id => l_attached_document_ID,
203 	      X_document_id => x_document_ID,
204 	      X_creation_date => sysdate,
205 	      X_created_by => FND_GLOBAL.USER_ID,
206 	      X_last_update_date => sysdate,
207 	      X_last_updated_by => FND_GLOBAL.USER_ID,
208 	      X_last_update_login => FND_GLOBAL.CONC_LOGIN_ID,
209 	      X_seq_num => l_seq_num,
210 	      X_entity_name => p_Fnd_Attachment_rec.entity_name,
211 	      x_column1 => null,
212 	      X_pk1_value => p_Fnd_Attachment_rec.pk1_value,
213 	      X_pk2_value => null,
214 	      X_pk3_value => null,
215 	      X_pk4_value => null,
216 	      X_pk5_value => null,
217 	      X_automatically_added_flag => p_Fnd_Attachment_rec.automatically_added_flag,
218 	      X_datatype_id => null,
219 	      X_category_id => null,
220 	      X_security_type => null,
221 	      X_publish_flag => null,
222 	      X_usage_type => p_Fnd_Attachment_rec.usage_type,
223 	      X_language => null,
224 	      X_media_id => l_media_id,
225 	      X_doc_attribute_Category => null,
226 	      X_doc_attribute1 => null,
227 	      X_doc_attribute2 => null,
228 	      X_doc_attribute3 => null,
229 	      X_doc_attribute4 => null,
230 	      X_doc_attribute5 => null,
231 	      X_doc_attribute6 => null,
232 	      X_doc_attribute7 => null,
233 	      X_doc_attribute8 => null,
234 	      X_doc_attribute9 => null,
235 	      X_doc_attribute10 => null,
236 	      X_doc_attribute11 => null,
237 	      X_doc_attribute12 => null,
238 	      X_doc_attribute13 => null,
239 	      X_doc_attribute14 => null,
240 	      X_doc_attribute15 => null
241 	   );
242       end if;
243 
244 
245       -- Standard check for p_commit
246       IF FND_API.to_Boolean( p_commit )
247       THEN
248          COMMIT WORK;
249       END IF;
250 
251 
252       -- Debug Message
253       IF (AMW_DEBUG_HIGH_ON) THEN
254             AMW_UTILITY_PVT.debug_message('Private API: ' || l_api_name || 'end');
255       END IF;
256 
257       -- Standard call to get message count and if count is 1, get message info.
258       FND_MSG_PUB.Count_And_Get
259         (p_count          =>   x_msg_count,
260          p_data           =>   x_msg_data
261       );
262 
263 
264 EXCEPTION
265 
266    WHEN AMW_Utility_PVT.resource_locked THEN
267      x_return_status := FND_API.g_ret_sts_error;
268      AMW_Utility_PVT.Error_Message(p_message_name => 'AMW_API_RESOURCE_LOCKED');
269 
270    WHEN FND_API.G_EXC_ERROR THEN
271      ROLLBACK TO CREATE_Fnd_Attachment_PVT;
272      x_return_status := FND_API.G_RET_STS_ERROR;
273      -- Standard call to get message count and if count=1, get the message
274      FND_MSG_PUB.Count_And_Get (
275             p_encoded => FND_API.G_FALSE,
276             p_count   => x_msg_count,
277             p_data    => x_msg_data
278      );
279 
280    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
281      ROLLBACK TO CREATE_Fnd_Attachment_PVT;
282      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
283      -- Standard call to get message count and if count=1, get the message
284      FND_MSG_PUB.Count_And_Get (
285             p_encoded => FND_API.G_FALSE,
286             p_count => x_msg_count,
287             p_data  => x_msg_data
288      );
289 
290    WHEN OTHERS THEN
291      ROLLBACK TO CREATE_Fnd_Attachment_PVT;
292      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
293      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
294      THEN
295         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
296      END IF;
297      -- Standard call to get message count and if count=1, get the message
298      FND_MSG_PUB.Count_And_Get (
299             p_encoded => FND_API.G_FALSE,
300             p_count => x_msg_count,
301             p_data  => x_msg_data
302      );
303 End Create_Fnd_Attachment;
304 END AMW_Attachment_PVT;