1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.kuali.ole.module.purap.util.cxml;
21
22 import org.kuali.ole.module.purap.PurapConstants;
23 import org.kuali.ole.module.purap.businessobject.B2BInformation;
24 import org.kuali.ole.module.purap.util.PurApDateFormatUtils;
25 import org.kuali.ole.sys.context.SpringContext;
26 import org.kuali.rice.core.api.datetime.DateTimeService;
27 import org.kuali.rice.kim.api.identity.Person;
28
29 import java.text.SimpleDateFormat;
30 import java.util.Date;
31
32 public class PunchOutSetupCxml {
33 private Person user;
34 private B2BInformation b2bInformation;
35
36 public PunchOutSetupCxml(Person u, B2BInformation b) {
37 user = u;
38 b2bInformation = b;
39 }
40
41
42
43
44
45
46 public String getPunchOutSetupRequestMessage() {
47 StringBuffer cxml = new StringBuffer();
48 Date d = SpringContext.getBean(DateTimeService.class).getCurrentDate();
49 SimpleDateFormat date = PurApDateFormatUtils.getSimpleDateFormat(PurapConstants.NamedDateFormats.CXML_SIMPLE_DATE_FORMAT);
50 SimpleDateFormat time = PurApDateFormatUtils.getSimpleDateFormat(PurapConstants.NamedDateFormats.CXML_SIMPLE_TIME_FORMAT);
51
52
53
54
55
56 cxml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
57 cxml.append("<!DOCTYPE cXML SYSTEM \"cXML.dtd\">\n");
58 cxml.append("<cXML payloadID=\"irrelevant\" xml:lang=\"en-US\" timestamp=\"").append(date.format(d)).append("T")
59 .append(time.format(d)).append("-05:00").append("\">\n");
60
61
62
63
64
65 cxml.append(" <Header>\n");
66 cxml.append(" <From>\n");
67 cxml.append(" <Credential domain=\"NetworkId\">\n");
68 cxml.append(" <Identity>").append(b2bInformation.getIdentity()).append("</Identity>\n");
69 cxml.append(" </Credential>\n");
70 cxml.append(" </From>\n");
71 cxml.append(" <To>\n");
72 cxml.append(" <Credential domain=\"DUNS\">\n");
73 cxml.append(" <Identity>").append(b2bInformation.getIdentity()).append("</Identity>\n");
74 cxml.append(" </Credential>\n");
75 cxml.append(" <Credential domain=\"internalsupplierid\">\n");
76 cxml.append(" <Identity>1016</Identity>\n");
77 cxml.append(" </Credential>\n");
78 cxml.append(" </To>\n");
79 cxml.append(" <Sender>\n");
80 cxml.append(" <Credential domain=\"TOPSNetworkUserId\">\n");
81 cxml.append(" <Identity>").append(user.getPrincipalName().toUpperCase()).append("</Identity>\n");
82 cxml.append(" <SharedSecret>").append(b2bInformation.getPassword()).append("</SharedSecret>\n");
83 cxml.append(" </Credential>\n");
84 cxml.append(" <UserAgent>").append(b2bInformation.getUserAgent()).append("</UserAgent>\n");
85 cxml.append(" </Sender>\n");
86 cxml.append(" </Header>\n");
87 cxml.append(" <Request deploymentMode=\"").append(b2bInformation.getEnvironment()).append("\">\n");
88 cxml.append(" <PunchOutSetupRequest operation=\"create\">\n");
89 cxml.append(" <BuyerCookie>").append(user.getPrincipalName().toUpperCase()).append("</BuyerCookie>\n");
90
91
92
93 cxml.append(" <Extrinsic name=\"UniqueName\">").append(user.getPrincipalName().toUpperCase()).append("</Extrinsic>\n");
94 cxml.append(" <Extrinsic name=\"Department\">IU").append(user.getCampusCode()).append(user.getPrimaryDepartmentCode()).append("</Extrinsic>\n");
95 cxml.append(" <Extrinsic name=\"Campus\">").append(user.getCampusCode()).append("</Extrinsic>\n");
96 cxml.append(" <BrowserFormPost>\n");
97 cxml.append(" <URL>").append(b2bInformation.getPunchbackURL()).append("</URL>\n");
98 cxml.append(" </BrowserFormPost>\n");
99 cxml.append(" <Contact role=\"endUser\">\n");
100 cxml.append(" <Name xml:lang=\"en\">").append(user.getName()).append("</Name>\n");
101
102
103 cxml.append(" </Contact>\n");
104 cxml.append(" <SupplierSetup>\n");
105 cxml.append(" <URL>").append(b2bInformation.getPunchoutURL()).append("</URL>\n");
106 cxml.append(" </SupplierSetup>\n");
107 cxml.append(" </PunchOutSetupRequest>\n");
108 cxml.append(" </Request>\n");
109 cxml.append("</cXML>\n");
110
111 return cxml.toString();
112 }
113
114 }
115