001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 /*
017 * Created on Mar 10, 2005
018 *
019 */
020 package org.kuali.kfs.module.purap.util.cxml;
021
022 import java.text.SimpleDateFormat;
023 import java.util.Date;
024
025 import org.kuali.kfs.module.purap.PurapConstants;
026 import org.kuali.kfs.module.purap.businessobject.B2BInformation;
027 import org.kuali.kfs.module.purap.util.PurApDateFormatUtils;
028 import org.kuali.kfs.sys.context.SpringContext;
029 import org.kuali.rice.kim.bo.Person;
030 import org.kuali.rice.kns.service.DateTimeService;
031
032 public class PunchOutSetupCxml {
033 private Person user;
034 private B2BInformation b2bInformation;
035
036 public PunchOutSetupCxml(Person u,B2BInformation b) {
037 user = u;
038 b2bInformation = b;
039 }
040
041 /**
042 * Get cxml punch out request xml
043 * @return xml for punch out request
044 */
045 public String getPunchOutSetupRequestMessage() {
046 StringBuffer cxml = new StringBuffer();
047 Date d = SpringContext.getBean(DateTimeService.class).getCurrentDate();
048 SimpleDateFormat date = PurApDateFormatUtils.getSimpleDateFormat(PurapConstants.NamedDateFormats.CXML_SIMPLE_DATE_FORMAT);
049 SimpleDateFormat time = PurApDateFormatUtils.getSimpleDateFormat(PurapConstants.NamedDateFormats.CXML_SIMPLE_TIME_FORMAT);
050
051 // doing as two parts b/c they want a T instead of space
052 // between them, and SimpleDateFormat doesn't allow putting the
053 // constant "T" in the string
054
055 cxml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
056 cxml.append("<!DOCTYPE cXML SYSTEM \"cXML.dtd\">\n");
057 cxml.append("<cXML payloadID=\"irrelevant\" xml:lang=\"en-US\" timestamp=\"").append(date.format(d)).append("T")
058 .append(time.format(d)).append("-05:00").append("\">\n");
059
060 // note that timezone is hard coded b/c this is the format
061 // they wanted, but SimpleDateFormat returns -0500, so rather than
062 // parse it just hard-coded
063
064 cxml.append(" <Header>\n");
065 cxml.append(" <From>\n");
066 cxml.append(" <Credential domain=\"NetworkId\">\n");
067 cxml.append(" <Identity>").append(b2bInformation.getIdentity()).append("</Identity>\n");
068 cxml.append(" </Credential>\n");
069 cxml.append(" </From>\n");
070 cxml.append(" <To>\n");
071 cxml.append(" <Credential domain=\"DUNS\">\n");
072 cxml.append(" <Identity>").append(b2bInformation.getIdentity()).append("</Identity>\n");
073 cxml.append(" </Credential>\n");
074 cxml.append(" <Credential domain=\"internalsupplierid\">\n");
075 cxml.append(" <Identity>1016</Identity>\n");
076 cxml.append(" </Credential>\n");
077 cxml.append(" </To>\n");
078 cxml.append(" <Sender>\n");
079 cxml.append(" <Credential domain=\"TOPSNetworkUserId\">\n");
080 cxml.append(" <Identity>").append(user.getPrincipalName().toUpperCase()).append("</Identity>\n");
081 cxml.append(" <SharedSecret>").append(b2bInformation.getPassword()).append("</SharedSecret>\n");
082 cxml.append(" </Credential>\n");
083 cxml.append(" <UserAgent>").append(b2bInformation.getUserAgent()).append("</UserAgent>\n");
084 cxml.append(" </Sender>\n");
085 cxml.append(" </Header>\n");
086 cxml.append(" <Request deploymentMode=\"").append(b2bInformation.getEnvironment()).append("\">\n");
087 cxml.append(" <PunchOutSetupRequest operation=\"create\">\n");
088 cxml.append(" <BuyerCookie>").append(user.getPrincipalName().toUpperCase()).append("</BuyerCookie>\n");
089 //cxml.append(" <Extrinsic
090 // name=\"UserEmail\">jdoe@TOPS.com</Extrinsic>\n"); // we can't reliably
091 // get the e-mail address, so we're leaving it out
092 cxml.append(" <Extrinsic name=\"UniqueName\">").append(user.getPrincipalName().toUpperCase()).append("</Extrinsic>\n");
093 cxml.append(" <Extrinsic name=\"Department\">IU").append(user.getCampusCode()).append(user.getPrimaryDepartmentCode()).append("</Extrinsic>\n");
094 cxml.append(" <Extrinsic name=\"Campus\">").append(user.getCampusCode()).append("</Extrinsic>\n");
095 cxml.append(" <BrowserFormPost>\n");
096 cxml.append(" <URL>").append(b2bInformation.getPunchbackURL()).append("</URL>\n");
097 cxml.append(" </BrowserFormPost>\n");
098 cxml.append(" <Contact role=\"endUser\">\n");
099 cxml.append(" <Name xml:lang=\"en\">").append(user.getName()).append("</Name>\n");
100 //cxml.append(" <Email>jdoe@TOPS.com</Email>\n"); // again, we can't
101 // reliably get this, so we're leaving it out
102 cxml.append(" </Contact>\n");
103 cxml.append(" <SupplierSetup>\n");
104 cxml.append(" <URL>").append(b2bInformation.getPunchoutURL()).append("</URL>\n");
105 cxml.append(" </SupplierSetup>\n");
106 cxml.append(" </PunchOutSetupRequest>\n");
107 cxml.append(" </Request>\n");
108 cxml.append("</cXML>\n");
109
110 return cxml.toString();
111 }
112
113 }
114