DBA Data[Home] [Help]

PACKAGE BODY: APPS.CAC_SYNC_COMMON

Source


1 PACKAGE BODY cac_sync_common AS
2 /* $Header: cacstcob.pls 120.7 2006/02/12 23:57:41 deeprao noship $ */
3 /*=======================================================================+
4  |  Copyright (c) 2002 Oracle Corporation Redwood Shores, California, USA|
5  |                            All rights reserved.                       |
6  +=======================================================================+
7  | FILENAME                                                              |
8  |   jtavscb.pls                                                         |
9  |                                                                       |
10  | DESCRIPTION                                                           |
11  |   - This package is implemented for the commonly used procedure or    |
12  |        function.                                                      |
13  |                                                                       |
14  | NOTES                                                                 |
15  |                                                                       |
16  | Date          Developer        Change                                 |
17  | ------        ---------------  -------------------------------------- |
18  | 01-Feb-2002   rdespoto         Modified                               |
19  | 12-Feb-2002   cjang            Added get_userid,get_resourceid,       |
20  |                                   get_timezoneid,get_messages         |
21  | 27-Feb-2002   hbouten          Added get_territory_code               |
22  +======================================================================*/
23    FUNCTION get_seqid
24    RETURN NUMBER
25    IS
26       l_seqnum  NUMBER := 0;
27    BEGIN
28       SELECT jta_sync_contact_mapping_s.nextval
29         INTO l_seqnum
30         FROM DUAL;
31 
32       RETURN l_seqnum;
33    END get_seqid;
34 
35    FUNCTION is_success (
36       p_return_status IN VARCHAR2
37       )
38       RETURN BOOLEAN
39    IS
40    BEGIN
41       IF (p_return_status = fnd_api.g_ret_sts_success)
42       THEN
43          RETURN TRUE;
44       ELSE
45          RETURN FALSE;
46       END IF;
47    END;
48 
49    PROCEDURE put_messages_to_result (
50       p_task_rec     IN OUT NOCOPY cac_sync_task.task_rec,
51       p_status       IN     NUMBER,
52       p_user_message IN     VARCHAR2,
53       p_token_name   IN     VARCHAR2 default null,
54       p_token_value  IN     VARCHAR2 default null
55    )
56    IS
57       no_of_messages NUMBER;
58       l_msg_data VARCHAR2(2000);
59    BEGIN
60    --   p_task_rec.resultusermessage := p_user_message;
61      fnd_message.set_name('JTF', p_user_message);
62      --check if token name and value exists...limitation is that it takes one token(name,value)
63      --at a time
64      if ((p_token_name is not null) and (p_token_value is not null)) then
65      fnd_message.set_token(p_token_name,p_token_value);
66      end if;
67 
68      fnd_msg_pub.add;
69 
70      IF fnd_msg_pub.count_msg > 0
71      THEN
72        FOR j IN 1 .. fnd_msg_pub.count_msg
73        LOOP
74          l_msg_data := fnd_msg_pub.get (p_msg_index => j, p_encoded => 'F');
75          p_task_rec.resultusermessage := p_task_rec.resultusermessage ||
76                                             fnd_global.local_chr (10)||l_msg_data;
77        END LOOP;
78      END IF;
79 
80      p_task_rec.resultusermessage := substr(p_task_rec.resultusermessage,1,2000);
81      p_task_rec.resultid := p_status;
82 
83      if (p_status <> cac_sync_task_common.g_sync_success) then
84      p_task_rec.resultsystemmessage := cac_sync_common.sync_failure;
85      else
86      p_task_rec.resultsystemmessage := cac_sync_common.sync_success;
87      end if;
88 
89 
90    END;
91 
92 
93 
94 /* commented for bug # 5031090
95    PROCEDURE put_messages_to_result (
96       p_contact_rec  IN OUT NOCOPY jta_sync_contact.contact_rec,
97       p_status       IN     NUMBER
98    )
99    IS
100    BEGIN
101       p_contact_rec.resultid   := p_status;
102       p_contact_rec.syncAnchor := SYSDATE;
103       p_contact_rec.resultusermessage := jta_sync_contact_common.GET_MSG();
104 
105    IF (p_status = 0) THEN
106       p_contact_rec.resultsystemmessage := sync_success;
107    ELSE
108       p_contact_rec.resultsystemmessage := sync_failure;
109    END IF;
110 
111    END put_messages_to_result; */
112 
113    PROCEDURE apps_login (
114       p_user_id IN NUMBER
115    )
116    IS
117    BEGIN
118       fnd_global.apps_initialize (user_id => p_user_id
119                                 , resp_id => fnd_global.resp_id --21787
120                                 , resp_appl_id => fnd_global.resp_appl_id --690
121                                 , security_group_id => fnd_global.security_group_id --0
122       );
123    END;
124 
125 
126    PROCEDURE get_userid (p_user_name  IN VARCHAR2
127                         ,x_user_id   OUT NOCOPY NUMBER)
128    IS
129        CURSOR c_user IS
130        SELECT user_id
131          FROM fnd_user
132         WHERE user_name = p_user_name;
133    BEGIN
134        OPEN c_user;
135        FETCH c_user INTO x_user_id;
136        IF c_user%NOTFOUND THEN
137            x_user_id := 0;
138        END IF;
139        CLOSE c_user;
140    END get_userid;
141 
142    PROCEDURE get_resourceid (p_user_id      IN NUMBER
143                             ,x_resource_id OUT NOCOPY NUMBER)
144    IS
145        CURSOR c_resource IS
146        SELECT resource_id
147          FROM jtf_rs_resource_extns
148         WHERE user_id = p_user_id;
149    BEGIN
150        OPEN c_resource;
151        FETCH c_resource INTO x_resource_id;
152        IF c_resource%NOTFOUND THEN
153            x_resource_id := 0;
154        END IF;
155        CLOSE c_resource;
156    END get_resourceid;
157 
158    PROCEDURE get_timezoneid (p_timezone_name  IN VARCHAR2
159                             ,x_timezone_id   OUT NOCOPY NUMBER)
160    IS
161        CURSOR c_timezone IS
162        SELECT timezone_id
163          FROM HZ_TIMEZONES
164         WHERE global_timezone_name = p_timezone_name;
165    BEGIN
166        OPEN c_timezone;
167        FETCH c_timezone INTO x_timezone_id;
168        IF c_timezone%NOTFOUND THEN
169            x_timezone_id := 0;
170        END IF;
171        CLOSE c_timezone;
172    END get_timezoneid;
173 
174    FUNCTION get_messages
175    RETURN VARCHAR2
176    IS
177        l_msg_count NUMBER;
178        l_msg_data  VARCHAR2(5000);
179    BEGIN
180        l_msg_count := fnd_msg_pub.count_msg;
181 
182        FOR i IN 1..l_msg_count LOOP
183            l_msg_data := substr(l_msg_data||fnd_msg_pub.get( i , 'F' ),1,5000);
184        END LOOP;
185 
186        RETURN l_msg_data;
187    END get_messages;
188 
189    --------------------------------------------------------------------------
190    --  API name    : get_territory_code
191    --  Type        : Private
192    --  Function    : Tries to convert a country into a CRM territory_code
193    --  Notes:
194    --------------------------------------------------------------------------
195    FUNCTION get_territory_code
196    ( p_country IN     VARCHAR2
197    )RETURN VARCHAR2
198    IS
199      CURSOR c_territory
200      (b_country IN VARCHAR2
201      )IS SELECT territory_code code
202          FROM fnd_territories_tl -- using TL since a match in any language will do
203          WHERE UPPER(b_country) = UPPER(territory_short_name)
204          OR    UPPER(b_country) = UPPER(description)
205          OR    UPPER(b_country) = UPPER(territory_code);
206 
207      l_territory_code VARCHAR2(2);
208 
209    BEGIN
210     OPEN c_territory(p_country);
211 
212     FETCH c_territory INTO l_territory_code;
213 
214     CLOSE c_territory;
215 
216     RETURN NVL(l_territory_code,p_country);
217 
218    END get_territory_code;
219 
220 
221 
222  PROCEDURE put_message_to_excl_record (
223       p_exclusion_rec     IN OUT NOCOPY  cac_sync_task.exclusion_rec,
224       p_status       IN     NUMBER,
225       p_user_message IN     VARCHAR2,
226       p_token_name   IN     VARCHAR2 default null,
227       p_token_value  IN     VARCHAR2 default null
228    )
229    IS
230       no_of_messages NUMBER;
231       l_msg_data VARCHAR2(2000);
232    BEGIN
233 
234      fnd_message.set_name('JTF', p_user_message);
235      --check if token name and value exists...limitation is that it takes one token(name,value)
236      --at a time
237      if ((p_token_name is not null) and (p_token_value is not null)) then
238      fnd_message.set_token(p_token_name,p_token_value);
239      end if;
240 
241      fnd_msg_pub.add;
242 
243      IF fnd_msg_pub.count_msg > 0
244      THEN
245        FOR j IN 1 .. fnd_msg_pub.count_msg
246        LOOP
247          l_msg_data := fnd_msg_pub.get (p_msg_index => j, p_encoded => 'F');
248        p_exclusion_rec.resultusermessage := p_exclusion_rec.resultusermessage ||
249                                           fnd_global.local_chr (10)||l_msg_data;
250        END LOOP;
251      END IF;
252 
253     p_exclusion_rec.resultusermessage := substr(p_exclusion_rec.resultusermessage,1,2000);
254     p_exclusion_rec.resultid := p_status;
255     p_exclusion_rec.resultsystemmessage := cac_sync_common.sync_failure;
256 
257    if( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
258     FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,'cac_sync_common.put_messages_to_excl_record', ' p_exclusion_rec.resultusermessage for task '|| p_exclusion_rec.subject|| ' is '||p_exclusion_rec.resultusermessage);
259     FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,'cac_sync_common.put_messages_to_excl_record', ' p_exclusion_rec.p_task_rec.resultid for task '|| p_exclusion_rec.subject|| ' is '||p_exclusion_rec.resultid);
260     FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,'cac_sync_common.put_messages_to_excl_record', ' p_exclusion_rec.resultsystemmessage '|| p_exclusion_rec.subject|| ' is '||p_exclusion_rec.resultsystemmessage);
261 
262     end if;
263 
264 
265    END;
266 
267 
268 END;