View Javadoc
1   /*
2    * Copyright 2005-2009 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  /*
17   * Created on Mar 10, 2005
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       * Get cxml punch out request xml
43       *
44       * @return xml for punch out request
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          // doing as two parts b/c they want a T instead of space
53          // between them, and SimpleDateFormat doesn't allow putting the
54          // constant "T" in the string
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          // note that timezone is hard coded b/c this is the format
62          // they wanted, but SimpleDateFormat returns -0500, so rather than
63          // parse it just hard-coded
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          //cxml.append(" <Extrinsic
91          // name=\"UserEmail\">jdoe@TOPS.com</Extrinsic>\n"); // we can't reliably
92          // get the e-mail address, so we're leaving it out
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         //cxml.append(" <Email>jdoe@TOPS.com</Email>\n"); // again, we can't
102         // reliably get this, so we're leaving it out
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