0001: /*
0002: * Copyright 2007 The Kuali Foundation.
0003: *
0004: * Licensed under the Educational Community License, Version 1.0 (the "License");
0005: * you may not use this file except in compliance with the License.
0006: * You may obtain a copy of the License at
0007: *
0008: * http://www.opensource.org/licenses/ecl1.php
0009: *
0010: * Unless required by applicable law or agreed to in writing, software
0011: * distributed under the License is distributed on an "AS IS" BASIS,
0012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013: * See the License for the specific language governing permissions and
0014: * limitations under the License.
0015: */
0016:
0017: package org.kuali.module.kra.routingform.xml;
0018:
0019: import java.text.DateFormat;
0020: import java.text.SimpleDateFormat;
0021: import java.util.Calendar;
0022: import java.util.Date;
0023: import java.util.GregorianCalendar;
0024: import java.util.Iterator;
0025: import java.util.List;
0026:
0027: import org.apache.commons.lang.ObjectUtils;
0028: import org.apache.commons.lang.StringUtils;
0029: import org.kuali.core.bo.Note;
0030: import org.kuali.core.bo.user.UniversalUser;
0031: import org.kuali.core.exceptions.UserNotFoundException;
0032: import org.kuali.core.service.UniversalUserService;
0033: import org.kuali.kfs.context.SpringContext;
0034: import org.kuali.kfs.service.ParameterService;
0035: import org.kuali.module.chart.bo.ChartUser;
0036: import org.kuali.module.chart.service.ChartUserService;
0037: import org.kuali.module.kra.KraConstants;
0038: import org.kuali.module.kra.routingform.bo.RoutingFormAgency;
0039: import org.kuali.module.kra.routingform.bo.RoutingFormBudget;
0040: import org.kuali.module.kra.routingform.bo.RoutingFormInstitutionCostShare;
0041: import org.kuali.module.kra.routingform.bo.RoutingFormKeyword;
0042: import org.kuali.module.kra.routingform.bo.RoutingFormOrganization;
0043: import org.kuali.module.kra.routingform.bo.RoutingFormOrganizationCreditPercent;
0044: import org.kuali.module.kra.routingform.bo.RoutingFormOtherCostShare;
0045: import org.kuali.module.kra.routingform.bo.RoutingFormPersonnel;
0046: import org.kuali.module.kra.routingform.bo.RoutingFormProjectType;
0047: import org.kuali.module.kra.routingform.bo.RoutingFormPurpose;
0048: import org.kuali.module.kra.routingform.bo.RoutingFormQuestion;
0049: import org.kuali.module.kra.routingform.bo.RoutingFormResearchRisk;
0050: import org.kuali.module.kra.routingform.bo.RoutingFormResearchRiskStudy;
0051: import org.kuali.module.kra.routingform.bo.RoutingFormSubcontractor;
0052: import org.kuali.module.kra.routingform.document.RoutingFormDocument;
0053: import org.kuali.module.kra.routingform.lookup.keyvalues.RoutingFormApprovalStatusValuesFinder;
0054: import org.kuali.module.kra.routingform.lookup.keyvalues.RoutingFormStudyReviewCodeValuesFinder;
0055: import org.kuali.module.kra.routingform.service.RoutingFormMainPageService;
0056: import org.w3c.dom.Document;
0057: import org.w3c.dom.Element;
0058:
0059: import edu.iu.uis.eden.EdenConstants;
0060: import edu.iu.uis.eden.clientapp.WorkflowInfo;
0061: import edu.iu.uis.eden.clientapp.vo.ActionRequestVO;
0062: import edu.iu.uis.eden.clientapp.vo.ActionTakenVO;
0063: import edu.iu.uis.eden.clientapp.vo.DocumentDetailVO;
0064: import edu.iu.uis.eden.clientapp.vo.ReportCriteriaVO;
0065: import edu.iu.uis.eden.clientapp.vo.UserVO;
0066: import edu.iu.uis.eden.exception.WorkflowException;
0067:
0068: /**
0069: * This class creates an XML representation of a RoutingForm's data.
0070: */
0071: public class RoutingFormXml {
0072:
0073: private static final String TO_BE_NAMED = "To Be Named";
0074:
0075: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
0076: .getLogger(RoutingFormXml.class);
0077:
0078: /**
0079: * Driving method for this class. Functions as a hub calling helper methods.
0080: *
0081: * @param routingFormroutingFormDocumentDoc data representation of a routingForm
0082: * @param xmlDoc target xml representation for the routingForm. This field will be side effected.
0083: * @param imagesUrl location of the images the stylesheets use
0084: * @throws Exception
0085: */
0086: public static void makeXml(RoutingFormDocument routingFormDocument,
0087: Document xmlDoc, String imagesUrl) throws Exception {
0088: // Start of XML elements
0089: Element proposalElement = xmlDoc.createElement("PROPOSAL");
0090: xmlDoc.appendChild(proposalElement);
0091:
0092: Element routingFormElement = xmlDoc
0093: .createElement("ROUTING_FORM");
0094: proposalElement.appendChild(routingFormElement);
0095:
0096: routingFormElement.setAttribute("TRACKING_NUMBER",
0097: routingFormDocument.getDocumentNumber());
0098: routingFormElement.setAttribute("PROPOSAL_NUMBER",
0099: ObjectUtils
0100: .toString(routingFormDocument
0101: .getContractGrantProposal()
0102: .getProposalNumber()));
0103: routingFormElement.setAttribute("LINKED_BUDGET_NUMBER",
0104: routingFormDocument.getRoutingFormBudgetNumber());
0105:
0106: // Code to get the current date/time
0107: Calendar calendar = new GregorianCalendar();
0108: Date date = calendar.getTime();
0109: DateFormat localFormat = DateFormat.getDateTimeInstance();
0110:
0111: routingFormElement.setAttribute("XML_CREATE_DATE_TIME",
0112: localFormat.format(date));
0113: routingFormElement.setAttribute("IMAGES_URL", imagesUrl);
0114:
0115: routingFormElement.appendChild(createAgencyElement(
0116: routingFormDocument.getRoutingFormAgency(),
0117: routingFormDocument.getRoutingFormAnnouncementNumber(),
0118: xmlDoc));
0119: routingFormElement.appendChild(createPrinciplesElement(
0120: routingFormDocument, xmlDoc));
0121: routingFormElement.appendChild(createPurposeElement(
0122: routingFormDocument, xmlDoc));
0123: routingFormElement.appendChild(createProjectInformationElement(
0124: routingFormDocument, xmlDoc));
0125: routingFormElement.appendChild(createAmountsDatesElement(
0126: routingFormDocument.getRoutingFormBudget(), xmlDoc));
0127: routingFormElement.appendChild(createTypeElement(
0128: routingFormDocument, xmlDoc));
0129: routingFormElement.appendChild(createResearchRiskElement(
0130: routingFormDocument, xmlDoc));
0131: routingFormElement.appendChild(createProjectDetailElement(
0132: routingFormDocument, xmlDoc));
0133: routingFormElement.appendChild(createApprovalsElement(
0134: routingFormDocument, xmlDoc));
0135: routingFormElement.appendChild(createKeywordsElement(
0136: routingFormDocument.getRoutingFormKeywords(), xmlDoc));
0137: // createSubmissionTypesElement would go here but is skipped because it's not needed at this time.
0138: routingFormElement.appendChild(createCommentsElement(
0139: routingFormDocument, xmlDoc));
0140: }
0141:
0142: /**
0143: * Creates AGENCY node.
0144: *
0145: * @param routingFormAgency
0146: * @param routingFormAnnouncementNumber
0147: * @param xmlDoc
0148: * @return resulting node
0149: */
0150: private static Element createAgencyElement(
0151: RoutingFormAgency routingFormAgency,
0152: String routingFormAnnouncementNumber, Document xmlDoc) {
0153: Element agencyElement = xmlDoc.createElement("AGENCY");
0154:
0155: DateFormat dateFormatter = new SimpleDateFormat(
0156: KraConstants.SHORT_TIMESTAMP_FORMAT);
0157:
0158: if (routingFormAgency.getAgency() != null) {
0159: Element agencyDataElement = xmlDoc
0160: .createElement("AGENCY_DATA");
0161: agencyDataElement.setAttribute("AGENCY_NUMBER",
0162: routingFormAgency.getAgencyNumber());
0163: agencyDataElement.setAttribute("AGENCY_TYPE_CODE",
0164: routingFormAgency.getAgency().getAgencyTypeCode());
0165: agencyDataElement.setAttribute(
0166: "PROGRAM_ANNOUNCEMENT_NUMBER",
0167: routingFormAnnouncementNumber);
0168:
0169: Element agencyFullNameElement = xmlDoc
0170: .createElement("AGENCY_FULL_NAME");
0171: agencyFullNameElement.appendChild(xmlDoc
0172: .createTextNode(ObjectUtils
0173: .toString(routingFormAgency.getAgency()
0174: .getFullName())));
0175: agencyDataElement.appendChild(agencyFullNameElement);
0176:
0177: agencyElement.appendChild(agencyDataElement);
0178: }
0179:
0180: Element agencyDueDateElement = xmlDoc.createElement("DUE_DATE");
0181: agencyDueDateElement.setAttribute("DUE_DATE_TYPE",
0182: routingFormAgency.getDueDateType() == null ? ""
0183: : routingFormAgency.getDueDateType()
0184: .getDueDateDescription());
0185: agencyDueDateElement.setAttribute("DUE_DATE", routingFormAgency
0186: .getRoutingFormDueDate() == null ? "" : dateFormatter
0187: .format(routingFormAgency.getRoutingFormDueDate()));
0188: // following field is dropped in KRA but per request preserved for Indiana University ERA implementation.
0189: agencyDueDateElement.setAttribute("DUE_TIME", routingFormAgency
0190: .getRoutingFormDueTime());
0191: agencyElement.appendChild(agencyDueDateElement);
0192:
0193: Element agencyDeliveryElement = xmlDoc
0194: .createElement("AGENCY_DELIVERY");
0195: agencyDeliveryElement.setAttribute("COPIES", routingFormAgency
0196: .getRoutingFormRequiredCopyText());
0197:
0198: Element agencyDeliveryInstructionsElement = xmlDoc
0199: .createElement("DELIVERY_INSTRUCTIONS");
0200: agencyDeliveryInstructionsElement.appendChild(xmlDoc
0201: .createTextNode(ObjectUtils.toString(routingFormAgency
0202: .getAgencyAddressDescription())));
0203: agencyDeliveryElement
0204: .appendChild(agencyDeliveryInstructionsElement);
0205:
0206: Element agencyAdditionalDeliveryInstructionsElement = xmlDoc
0207: .createElement("ADDITIONAL_DELIVERY_INSTRUCTIONS");
0208: agencyAdditionalDeliveryInstructionsElement.setAttribute(
0209: "DISK_INCLUDED_IND", formatBoolean(routingFormAgency
0210: .getAgencyDiskAccompanyIndicator()));
0211: agencyAdditionalDeliveryInstructionsElement.setAttribute(
0212: "ELECTRONIC_SUBMISSIONS_IND",
0213: formatBoolean(routingFormAgency
0214: .getAgencyElectronicSubmissionIndicator()));
0215: agencyAdditionalDeliveryInstructionsElement.appendChild(xmlDoc
0216: .createTextNode(ObjectUtils.toString(routingFormAgency
0217: .getAgencyShippingInstructionsDescription())));
0218: agencyDeliveryElement
0219: .appendChild(agencyAdditionalDeliveryInstructionsElement);
0220:
0221: agencyElement.appendChild(agencyDeliveryElement);
0222:
0223: return agencyElement;
0224: }
0225:
0226: /**
0227: * Creates PRINCIPLES node.
0228: *
0229: * @param routingFormDocument
0230: * @param xmlDoc
0231: * @return resulting node
0232: */
0233: private static Element createPrinciplesElement(
0234: RoutingFormDocument routingFormDocument, Document xmlDoc) {
0235: Element principlesElement = xmlDoc.createElement("PRINCIPLES");
0236:
0237: final String PERSON_ROLE_CODE_COPD = SpringContext.getBean(
0238: ParameterService.class).getParameterValue(
0239: RoutingFormDocument.class,
0240: KraConstants.PERSON_ROLE_CODE_CO_PROJECT_DIRECTOR);
0241:
0242: RoutingFormMainPageService routingFormMainPageService = SpringContext
0243: .getBean(RoutingFormMainPageService.class);
0244: List<RoutingFormPersonnel> routingFormPersonnel = routingFormDocument
0245: .getRoutingFormPersonnel();
0246: RoutingFormPersonnel projectDirector = routingFormMainPageService
0247: .getProjectDirector(routingFormPersonnel);
0248:
0249: principlesElement.setAttribute("CO-PD_IND",
0250: formatBoolean(routingFormMainPageService
0251: .checkCoPdExistance(routingFormPersonnel)));
0252:
0253: Element projectDirectorElement = xmlDoc
0254: .createElement("PROJECT_DIRECTOR");
0255: if (projectDirector != null) {
0256: if (projectDirector.isPersonToBeNamedIndicator()) {
0257: projectDirectorElement.setAttribute("FIRST_NAME",
0258: TO_BE_NAMED);
0259: projectDirectorElement.setAttribute("PERCENT_CREDIT",
0260: ObjectUtils.toString(projectDirector
0261: .getPersonCreditPercent()));
0262: } else {
0263: projectDirectorElement.setAttribute("FIRST_NAME",
0264: ObjectUtils.toString(projectDirector.getUser()
0265: .getPersonFirstName()));
0266: projectDirectorElement.setAttribute("LAST_NAME",
0267: ObjectUtils.toString(projectDirector.getUser()
0268: .getPersonLastName()));
0269: projectDirectorElement.setAttribute("PERCENT_CREDIT",
0270: ObjectUtils.toString(projectDirector
0271: .getPersonCreditPercent()));
0272:
0273: Element homeOrgElement = xmlDoc
0274: .createElement("HOME_ORG");
0275: String chart = "";
0276: String org = "";
0277: if (projectDirector.getUser().getModuleUser(
0278: ChartUser.MODULE_ID) != null) {
0279: chart = ((ChartUser) projectDirector.getUser()
0280: .getModuleUser(ChartUser.MODULE_ID))
0281: .getChartOfAccountsCode();
0282: org = ((ChartUser) projectDirector.getUser()
0283: .getModuleUser(ChartUser.MODULE_ID))
0284: .getOrganizationCode();
0285: } else {
0286: chart = SpringContext.getBean(
0287: ChartUserService.class)
0288: .getDefaultChartCode(
0289: projectDirector.getUser());
0290: org = SpringContext.getBean(ChartUserService.class)
0291: .getDefaultOrganizationCode(
0292: projectDirector.getUser());
0293: }
0294:
0295: homeOrgElement.setAttribute("HOME_CHART", ObjectUtils
0296: .toString(chart));
0297: homeOrgElement.setAttribute("HOME_ORG", ObjectUtils
0298: .toString(org));
0299: projectDirectorElement.appendChild(homeOrgElement);
0300: }
0301:
0302: Element pdCampusAddressElement = xmlDoc
0303: .createElement("PD_CAMPUS_ADDRESS");
0304: pdCampusAddressElement.appendChild(xmlDoc
0305: .createTextNode(ObjectUtils
0306: .toString(projectDirector
0307: .getPersonLine1Address())));
0308: projectDirectorElement.appendChild(pdCampusAddressElement);
0309:
0310: Element pdPhoneElement = xmlDoc.createElement("PD_PHONE");
0311: pdPhoneElement.appendChild(xmlDoc
0312: .createTextNode(ObjectUtils
0313: .toString(projectDirector
0314: .getPersonPhoneNumber())));
0315: projectDirectorElement.appendChild(pdPhoneElement);
0316:
0317: Element pdEmailElement = xmlDoc.createElement("PD_EMAIL");
0318: pdEmailElement.appendChild(xmlDoc
0319: .createTextNode(ObjectUtils
0320: .toString(projectDirector
0321: .getPersonEmailAddress())));
0322: projectDirectorElement.appendChild(pdEmailElement);
0323:
0324: Element submittingOrgElement = xmlDoc
0325: .createElement("SUBMITTING_ORG");
0326: submittingOrgElement.setAttribute("SUBMITTING_CHART",
0327: ObjectUtils.toString(projectDirector
0328: .getChartOfAccountsCode()));
0329: submittingOrgElement.setAttribute("SUBMITTING_ORG",
0330: ObjectUtils.toString(projectDirector
0331: .getOrganizationCode()));
0332: submittingOrgElement
0333: .appendChild(xmlDoc.createTextNode(projectDirector
0334: .getOrganization() == null ? ""
0335: : projectDirector.getOrganization()
0336: .getOrganizationName()));
0337: projectDirectorElement.appendChild(submittingOrgElement);
0338: }
0339: principlesElement.appendChild(projectDirectorElement);
0340:
0341: Element coPdsElement = xmlDoc
0342: .createElement("CO-PROJECT_DIRECTORS");
0343: for (RoutingFormPersonnel person : routingFormDocument
0344: .getRoutingFormPersonnel()) {
0345: if (PERSON_ROLE_CODE_COPD
0346: .equals(person.getPersonRoleCode())) {
0347: Element coPdElement = xmlDoc
0348: .createElement("CO-PROJECT_DIRECTOR");
0349:
0350: if (person.isPersonToBeNamedIndicator()) {
0351: coPdElement.setAttribute("FIRST_NAME", TO_BE_NAMED);
0352: } else {
0353: coPdElement.setAttribute("FIRST_NAME", ObjectUtils
0354: .toString(person.getUser()
0355: .getPersonFirstName()));
0356: coPdElement.setAttribute("LAST_NAME", ObjectUtils
0357: .toString(person.getUser()
0358: .getPersonLastName()));
0359: }
0360:
0361: coPdElement.setAttribute("CHART", ObjectUtils
0362: .toString(person.getChartOfAccountsCode()));
0363: coPdElement.setAttribute("ORG", ObjectUtils
0364: .toString(person.getOrganizationCode()));
0365: coPdElement.setAttribute("PERCENT_CREDIT", ObjectUtils
0366: .toString(person.getPersonCreditPercent()));
0367:
0368: coPdsElement.appendChild(coPdElement);
0369: }
0370: }
0371: principlesElement.appendChild(coPdsElement);
0372:
0373: RoutingFormPersonnel contactPerson = routingFormMainPageService
0374: .getContactPerson(routingFormPersonnel);
0375:
0376: Element contactPersonElement = xmlDoc
0377: .createElement("CONTACT_PERSON");
0378: if (contactPerson != null) {
0379: if (contactPerson.isPersonToBeNamedIndicator()) {
0380: contactPersonElement.setAttribute("FIRST_NAME",
0381: TO_BE_NAMED);
0382: } else {
0383: contactPersonElement.setAttribute("FIRST_NAME",
0384: ObjectUtils.toString(contactPerson.getUser()
0385: .getPersonFirstName()));
0386: contactPersonElement.setAttribute("LAST_NAME",
0387: ObjectUtils.toString(contactPerson.getUser()
0388: .getPersonLastName()));
0389: }
0390: contactPersonElement.setAttribute("EMAIL", ObjectUtils
0391: .toString(contactPerson.getPersonEmailAddress()));
0392: contactPersonElement.setAttribute("PHONE_NUMBER",
0393: ObjectUtils.toString(contactPerson
0394: .getPersonPhoneNumber()));
0395: contactPersonElement.setAttribute("FAX_NUMBER", ObjectUtils
0396: .toString(contactPerson.getPersonFaxNumber()));
0397: }
0398: principlesElement.appendChild(contactPersonElement);
0399:
0400: Element fellowDescriptionElement = xmlDoc
0401: .createElement("FELLOW");
0402: fellowDescriptionElement.appendChild(xmlDoc
0403: .createTextNode(ObjectUtils
0404: .toString(routingFormDocument
0405: .getRoutingFormFellowFullName())));
0406: principlesElement.appendChild(fellowDescriptionElement);
0407:
0408: return principlesElement;
0409: }
0410:
0411: /**
0412: * Creates PURPOSE node.
0413: *
0414: * @param routingFormDocument
0415: * @param xmlDoc
0416: * @return resulting node
0417: */
0418: private static Element createPurposeElement(
0419: RoutingFormDocument routingFormDocument, Document xmlDoc) {
0420: Element purposesElement = xmlDoc.createElement("PURPOSES");
0421:
0422: for (RoutingFormPurpose routingFormPurpose : routingFormDocument
0423: .getRoutingFormPurposes()) {
0424: Element purposeElement = xmlDoc.createElement("PURPOSE");
0425:
0426: purposeElement
0427: .setAttribute(
0428: "SELECTED",
0429: formatBoolean(routingFormPurpose
0430: .getPurposeCode()
0431: .equals(
0432: routingFormDocument
0433: .getRoutingFormPurposeCode())));
0434: purposeElement.setAttribute("CODE", ObjectUtils
0435: .toString(routingFormPurpose.getPurposeCode()));
0436: purposeElement.appendChild(xmlDoc
0437: .createTextNode(ObjectUtils
0438: .toString(routingFormPurpose.getPurpose()
0439: .getPurposeDescription())));
0440:
0441: purposesElement.appendChild(purposeElement);
0442: }
0443:
0444: Element purposeDescriptionElement = xmlDoc
0445: .createElement("PURPOSE_OTHER_DESCRIPTION");
0446: purposeDescriptionElement
0447: .appendChild(xmlDoc
0448: .createTextNode(ObjectUtils
0449: .toString(routingFormDocument
0450: .getRoutingFormOtherPurposeDescription())));
0451: purposesElement.appendChild(purposeDescriptionElement);
0452:
0453: // Research Type dropdown omitted since it was not present in ERA.
0454:
0455: return purposesElement;
0456: }
0457:
0458: /**
0459: * Creates PROJECT_INFORMATION node.
0460: *
0461: * @param routingFormDocument
0462: * @param xmlDoc
0463: * @return resulting node
0464: */
0465: private static Element createProjectInformationElement(
0466: RoutingFormDocument routingFormDocument, Document xmlDoc) {
0467: Element projectInformationElement = xmlDoc
0468: .createElement("PROJECT_INFORMATION");
0469:
0470: projectInformationElement
0471: .setAttribute(
0472: "CFDA_TXT",
0473: routingFormDocument
0474: .getRoutingFormCatalogOfFederalDomesticAssistanceNumber());
0475:
0476: Element projectTitleElement = xmlDoc
0477: .createElement("PROJECT_TITLE");
0478: projectTitleElement.appendChild(xmlDoc
0479: .createTextNode(ObjectUtils
0480: .toString(routingFormDocument
0481: .getRoutingFormProjectTitle())));
0482: projectInformationElement.appendChild(projectTitleElement);
0483:
0484: Element layDescription = xmlDoc
0485: .createElement("LAY_DESCRIPTION");
0486: layDescription.appendChild(xmlDoc.createTextNode(ObjectUtils
0487: .toString(routingFormDocument
0488: .getRoutingFormLayDescription())));
0489: projectInformationElement.appendChild(layDescription);
0490:
0491: Element abstractDescription = xmlDoc.createElement("ABSTRACT");
0492: abstractDescription.appendChild(xmlDoc
0493: .createTextNode(ObjectUtils
0494: .toString(routingFormDocument
0495: .getProjectAbstract())));
0496: projectInformationElement.appendChild(abstractDescription);
0497:
0498: return projectInformationElement;
0499: }
0500:
0501: /**
0502: * Creates AMOUNTS_DATES node. Only puts current period into XML per functional specification.
0503: *
0504: * @param routingFormDocument
0505: * @param xmlDoc
0506: * @return resulting node
0507: */
0508: private static Element createAmountsDatesElement(
0509: RoutingFormBudget routingFormBudget, Document xmlDoc) {
0510: Element amountsDatesElement = xmlDoc
0511: .createElement("AMOUNTS_DATES");
0512:
0513: DateFormat dateFormatter = new SimpleDateFormat(
0514: KraConstants.SHORT_TIMESTAMP_FORMAT);
0515:
0516: Element directCostsDescription = xmlDoc
0517: .createElement("DIRECT_COSTS");
0518: directCostsDescription.appendChild(xmlDoc
0519: .createTextNode(ObjectUtils.toString(routingFormBudget
0520: .getRoutingFormBudgetDirectAmount())));
0521: amountsDatesElement.appendChild(directCostsDescription);
0522:
0523: Element indirectCostsDescription = xmlDoc
0524: .createElement("INDIRECT_COSTS");
0525: indirectCostsDescription.appendChild(xmlDoc
0526: .createTextNode(ObjectUtils.toString(routingFormBudget
0527: .getRoutingFormBudgetIndirectCostAmount())));
0528: amountsDatesElement.appendChild(indirectCostsDescription);
0529:
0530: Element totalCostsDescription = xmlDoc
0531: .createElement("TOTAL_COSTS");
0532: totalCostsDescription.appendChild(xmlDoc
0533: .createTextNode(ObjectUtils.toString(routingFormBudget
0534: .getTotalCostsCurrentPeriod())));
0535: amountsDatesElement.appendChild(totalCostsDescription);
0536:
0537: Element startDateDescription = xmlDoc
0538: .createElement("START_DATE");
0539: if (routingFormBudget.getRoutingFormBudgetStartDate() != null) {
0540: startDateDescription.appendChild(xmlDoc
0541: .createTextNode(dateFormatter
0542: .format(routingFormBudget
0543: .getRoutingFormBudgetStartDate())));
0544: }
0545: amountsDatesElement.appendChild(startDateDescription);
0546:
0547: Element endDateDescription = xmlDoc.createElement("STOP_DATE");
0548: if (routingFormBudget.getRoutingFormBudgetEndDate() != null) {
0549: endDateDescription.appendChild(xmlDoc
0550: .createTextNode(dateFormatter
0551: .format(routingFormBudget
0552: .getRoutingFormBudgetEndDate())));
0553: }
0554: amountsDatesElement.appendChild(endDateDescription);
0555:
0556: return amountsDatesElement;
0557: }
0558:
0559: /**
0560: * Creates TYPES node.
0561: *
0562: * @param routingFormDocument
0563: * @param xmlDoc
0564: * @return resulting node
0565: */
0566: private static Element createTypeElement(
0567: RoutingFormDocument routingFormDocument, Document xmlDoc) {
0568: Element typesElement = xmlDoc.createElement("TYPES");
0569:
0570: for (RoutingFormProjectType routingFormProjectType : routingFormDocument
0571: .getRoutingFormProjectTypes()) {
0572: Element typeElement = xmlDoc.createElement("TYPE");
0573:
0574: typeElement.setAttribute("CODE", routingFormProjectType
0575: .getProjectTypeCode());
0576: typeElement.setAttribute("SELECTED",
0577: formatBoolean(routingFormProjectType
0578: .isProjectTypeSelectedIndicator()));
0579: typeElement.appendChild(xmlDoc.createTextNode(ObjectUtils
0580: .toString(routingFormProjectType.getProjectType()
0581: .getProjectTypeDescription())));
0582:
0583: typesElement.appendChild(typeElement);
0584: }
0585:
0586: Element typeOtherTextDescription = xmlDoc
0587: .createElement("TYPE_OTHER_DESCRIPTION");
0588: typeOtherTextDescription.appendChild(xmlDoc
0589: .createTextNode(ObjectUtils
0590: .toString(routingFormDocument
0591: .getProjectTypeOtherDescription())));
0592: typesElement.appendChild(typeOtherTextDescription);
0593:
0594: Element priorGrantDescription = xmlDoc
0595: .createElement("PRIOR_GRANT");
0596: priorGrantDescription.appendChild(xmlDoc
0597: .createTextNode(ObjectUtils
0598: .toString(routingFormDocument
0599: .getRoutingFormPriorGrantNumber())));
0600: typesElement.appendChild(priorGrantDescription);
0601:
0602: Element currentGrantDescription = xmlDoc
0603: .createElement("CURRENT_GRANT");
0604: currentGrantDescription
0605: .appendChild(xmlDoc
0606: .createTextNode(ObjectUtils
0607: .toString(routingFormDocument
0608: .getGrantNumber())));
0609: typesElement.appendChild(currentGrantDescription);
0610:
0611: Element institutionAccountDescription = xmlDoc
0612: .createElement("INSTITUTION_ACCOUNT");
0613: institutionAccountDescription.appendChild(xmlDoc
0614: .createTextNode(ObjectUtils
0615: .toString(routingFormDocument
0616: .getInstitutionAccountNumber())));
0617: typesElement.appendChild(institutionAccountDescription);
0618:
0619: Element currentProposalDescription = xmlDoc
0620: .createElement("CURRENT_PROPOSAL");
0621: currentProposalDescription.appendChild(xmlDoc
0622: .createTextNode(ObjectUtils
0623: .toString(routingFormDocument
0624: .getContractGrantProposal()
0625: .getProposalNumber())));
0626: typesElement.appendChild(currentProposalDescription);
0627:
0628: return typesElement;
0629: }
0630:
0631: /**
0632: * Creates RESEARCH_RISK node.
0633: *
0634: * @param routingFormDocument
0635: * @param xmlDoc
0636: * @return resulting node
0637: */
0638: private static Element createResearchRiskElement(
0639: RoutingFormDocument routingFormDocument, Document xmlDoc) {
0640: Element researchRisksElement = xmlDoc
0641: .createElement("RESEARCH_RISKS");
0642:
0643: boolean anyStudySelected = false;
0644: DateFormat dateFormatter = new SimpleDateFormat(
0645: KraConstants.SHORT_TIMESTAMP_FORMAT);
0646: RoutingFormApprovalStatusValuesFinder routingFormApprovalStatusValuesFinder = new RoutingFormApprovalStatusValuesFinder();
0647: RoutingFormStudyReviewCodeValuesFinder routingFormStudyReviewCodeValuesFinder = new RoutingFormStudyReviewCodeValuesFinder();
0648:
0649: for (RoutingFormResearchRisk routingFormResearchRisk : routingFormDocument
0650: .getRoutingFormResearchRisks()) {
0651: if (KraConstants.RESEARCH_RISK_TYPE_DESCRIPTION
0652: .equals(routingFormResearchRisk
0653: .getResearchRiskType()
0654: .getControlAttributeTypeCode())) {
0655: Element researchRiskElement = xmlDoc
0656: .createElement("RESEARCH_RISK");
0657:
0658: researchRiskElement
0659: .setAttribute(
0660: "SELECTED",
0661: formatBoolean(StringUtils
0662: .isNotEmpty(routingFormResearchRisk
0663: .getResearchRiskDescription())));
0664: researchRiskElement.setAttribute(
0665: "CTRL_ATTRIB_TYPE_CODE",
0666: routingFormResearchRisk.getResearchRiskType()
0667: .getControlAttributeTypeCode());
0668: researchRiskElement.setAttribute("TYPE_DESCRIPTION",
0669: ObjectUtils.toString(routingFormResearchRisk
0670: .getResearchRiskType()
0671: .getResearchRiskTypeDescription()));
0672:
0673: Element textDescription = xmlDoc.createElement("TEXT");
0674: textDescription
0675: .appendChild(xmlDoc.createTextNode(ObjectUtils
0676: .toString(routingFormResearchRisk
0677: .getResearchRiskDescription())));
0678: researchRiskElement.appendChild(textDescription);
0679:
0680: researchRisksElement.appendChild(researchRiskElement);
0681: } else if (KraConstants.RESEARCH_RISK_TYPE_ALL_COLUMNS
0682: .equals(routingFormResearchRisk
0683: .getResearchRiskType()
0684: .getControlAttributeTypeCode())
0685: || KraConstants.RESEARCH_RISK_TYPE_SOME_COLUMNS
0686: .equals(routingFormResearchRisk
0687: .getResearchRiskType()
0688: .getControlAttributeTypeCode())) {
0689: Element researchRiskElement = xmlDoc
0690: .createElement("RESEARCH_RISK");
0691:
0692: boolean selected = routingFormResearchRisk
0693: .getResearchRiskStudies().size() > 0;
0694: anyStudySelected |= selected;
0695:
0696: researchRiskElement.setAttribute("SELECTED",
0697: formatBoolean(selected));
0698: researchRiskElement.setAttribute(
0699: "CTRL_ATTRIB_TYPE_CODE",
0700: routingFormResearchRisk.getResearchRiskType()
0701: .getControlAttributeTypeCode());
0702: researchRiskElement.setAttribute("TYPE_DESCRIPTION",
0703: ObjectUtils.toString(routingFormResearchRisk
0704: .getResearchRiskType()
0705: .getResearchRiskTypeDescription()));
0706:
0707: for (RoutingFormResearchRiskStudy routingFormResearchRiskStudy : routingFormResearchRisk
0708: .getResearchRiskStudies()) {
0709: Element studyElement = xmlDoc
0710: .createElement("STUDY");
0711:
0712: Element studyNumber = xmlDoc
0713: .createElement("STUDY_NUMBER");
0714: studyNumber
0715: .appendChild(xmlDoc
0716: .createTextNode(ObjectUtils
0717: .toString(routingFormResearchRiskStudy
0718: .getResearchRiskStudyNumber())));
0719: studyElement.appendChild(studyNumber);
0720:
0721: String routingFormApprovalStatus = routingFormApprovalStatusValuesFinder
0722: .getKeyLabel(routingFormResearchRiskStudy
0723: .getResearchRiskStudyApprovalStatusCode());
0724: Element approvalStatus = xmlDoc
0725: .createElement("APPROVAL_STATUS");
0726: approvalStatus.appendChild(xmlDoc
0727: .createTextNode(routingFormApprovalStatus));
0728: studyElement.appendChild(approvalStatus);
0729:
0730: Element approvalDate = xmlDoc
0731: .createElement("APPROVAL_DATE");
0732: approvalDate
0733: .appendChild(xmlDoc
0734: .createTextNode(routingFormResearchRiskStudy
0735: .getResearchRiskStudyApprovalDate() == null ? ""
0736: : dateFormatter
0737: .format(routingFormResearchRiskStudy
0738: .getResearchRiskStudyApprovalDate())));
0739: studyElement.appendChild(approvalDate);
0740:
0741: Element expirationDate = xmlDoc
0742: .createElement("EXPIRATION_DATE");
0743: expirationDate
0744: .appendChild(xmlDoc
0745: .createTextNode(routingFormResearchRiskStudy
0746: .getResearchRiskStudyExpirationDate() == null ? ""
0747: : dateFormatter
0748: .format(routingFormResearchRiskStudy
0749: .getResearchRiskStudyExpirationDate())));
0750: studyElement.appendChild(expirationDate);
0751:
0752: String routingFormStudyReviewCode = routingFormStudyReviewCodeValuesFinder
0753: .getKeyLabel(routingFormResearchRiskStudy
0754: .getResearchRiskStudyReviewCode());
0755: Element studyReviewStatus = xmlDoc
0756: .createElement("STUDY_REVIEW_STATUS");
0757: studyReviewStatus
0758: .appendChild(xmlDoc
0759: .createTextNode(ObjectUtils
0760: .toString(routingFormStudyReviewCode)));
0761: studyElement.appendChild(studyReviewStatus);
0762:
0763: Element exemptionNbr = xmlDoc
0764: .createElement("EXEMPTION_NBR");
0765: exemptionNbr
0766: .appendChild(xmlDoc
0767: .createTextNode(ObjectUtils
0768: .toString(routingFormResearchRiskStudy
0769: .getResearchRiskExemptionNumber())));
0770: studyElement.appendChild(exemptionNbr);
0771:
0772: researchRiskElement.appendChild(studyElement);
0773: }
0774:
0775: researchRisksElement.appendChild(researchRiskElement);
0776: } else {
0777: LOG
0778: .warn("Found unknown controlAttributeTypeCode, ignoring: "
0779: + routingFormResearchRisk
0780: .getResearchRiskType()
0781: .getControlAttributeTypeCode());
0782: }
0783: }
0784:
0785: researchRisksElement.setAttribute("ANY_STUDY_SELECTED",
0786: formatBoolean(anyStudySelected));
0787:
0788: return researchRisksElement;
0789: }
0790:
0791: /**
0792: * Creates PROJECT_DETAIL node.
0793: *
0794: * @param routingFormDocument
0795: * @param xmlDoc
0796: * @return resulting node
0797: */
0798: private static Element createProjectDetailElement(
0799: RoutingFormDocument routingFormDocument, Document xmlDoc) {
0800: Element projectDetailElement = xmlDoc
0801: .createElement("PROJECT_DETAIL");
0802:
0803: for (RoutingFormQuestion routingFormQuestion : routingFormDocument
0804: .getRoutingFormQuestions()) {
0805: Element questionElement = xmlDoc.createElement("QUESTION");
0806:
0807: questionElement.setAttribute("SELECTED", ObjectUtils
0808: .toString(routingFormQuestion.getYesNoIndicator()));
0809: questionElement.appendChild(xmlDoc
0810: .createTextNode(ObjectUtils
0811: .toString(routingFormQuestion.getQuestion()
0812: .getQuestionTypeDescription())));
0813:
0814: projectDetailElement.appendChild(questionElement);
0815: }
0816:
0817: for (RoutingFormSubcontractor routingFormSubcontractor : routingFormDocument
0818: .getRoutingFormSubcontractors()) {
0819: Element subcontractorElement = xmlDoc
0820: .createElement("SUBCONTRACTOR");
0821:
0822: subcontractorElement
0823: .setAttribute("SOURCE", ObjectUtils
0824: .toString(routingFormSubcontractor
0825: .getSubcontractor()
0826: .getSubcontractorName()));
0827: subcontractorElement.setAttribute("AMOUNT", ObjectUtils
0828: .toString(routingFormSubcontractor
0829: .getRoutingFormSubcontractorAmount()));
0830:
0831: projectDetailElement.appendChild(subcontractorElement);
0832: }
0833:
0834: for (RoutingFormOrganization routingFormOrganization : routingFormDocument
0835: .getRoutingFormOrganizations()) {
0836: Element otherInstOrgElement = xmlDoc
0837: .createElement("OTHER_INST_ORG");
0838:
0839: otherInstOrgElement.setAttribute("CHART", ObjectUtils
0840: .toString(routingFormOrganization
0841: .getChartOfAccountsCode()));
0842: otherInstOrgElement.setAttribute("ORG", ObjectUtils
0843: .toString(routingFormOrganization
0844: .getOrganizationCode()));
0845: otherInstOrgElement.setAttribute("ORG_NAME", ObjectUtils
0846: .toString(routingFormOrganization.getOrganization()
0847: .getOrganizationName()));
0848:
0849: projectDetailElement.appendChild(otherInstOrgElement);
0850: }
0851:
0852: for (RoutingFormInstitutionCostShare routingFormInstitutionCostShare : routingFormDocument
0853: .getRoutingFormInstitutionCostShares()) {
0854: Element instCostShareElement = xmlDoc
0855: .createElement("INST_COST_SHARE");
0856:
0857: instCostShareElement.setAttribute("CHART", ObjectUtils
0858: .toString(routingFormInstitutionCostShare
0859: .getChartOfAccountsCode()));
0860: instCostShareElement.setAttribute("ORG", ObjectUtils
0861: .toString(routingFormInstitutionCostShare
0862: .getOrganizationCode()));
0863: instCostShareElement.setAttribute("ACCOUNT", ObjectUtils
0864: .toString(routingFormInstitutionCostShare
0865: .getAccountNumber()));
0866: instCostShareElement.setAttribute("AMOUNT", ObjectUtils
0867: .toString(routingFormInstitutionCostShare
0868: .getRoutingFormCostShareAmount()));
0869:
0870: projectDetailElement.appendChild(instCostShareElement);
0871: }
0872:
0873: for (RoutingFormOtherCostShare routingFormOtherCostShare : routingFormDocument
0874: .getRoutingFormOtherCostShares()) {
0875: Element otherCostShareElement = xmlDoc
0876: .createElement("OTHER_COST_SHARE");
0877:
0878: otherCostShareElement.setAttribute("SOURCE_NAME",
0879: ObjectUtils.toString(routingFormOtherCostShare
0880: .getRoutingFormCostShareSourceName()));
0881: otherCostShareElement.setAttribute("AMOUNT", ObjectUtils
0882: .toString(routingFormOtherCostShare
0883: .getRoutingFormCostShareAmount()));
0884:
0885: projectDetailElement.appendChild(otherCostShareElement);
0886: }
0887:
0888: if (routingFormDocument.getRoutingFormPersonnel().size() > 0
0889: || routingFormDocument
0890: .getRoutingFormOrganizationCreditPercents()
0891: .size() > 0) {
0892:
0893: for (RoutingFormPersonnel routingFormPerson : routingFormDocument
0894: .getRoutingFormPersonnel()) {
0895: Element percentCreditDescription = xmlDoc
0896: .createElement("PERCENT_CREDIT");
0897:
0898: if (routingFormPerson.isPersonToBeNamedIndicator()) {
0899: percentCreditDescription.setAttribute("NAME",
0900: TO_BE_NAMED);
0901: } else {
0902: percentCreditDescription.setAttribute("NAME",
0903: ObjectUtils.toString(routingFormPerson
0904: .getUser().getPersonName()));
0905: }
0906: percentCreditDescription.setAttribute("ROLE",
0907: ObjectUtils.toString(routingFormPerson
0908: .getPersonRoleText()));
0909: percentCreditDescription.setAttribute("CHART",
0910: ObjectUtils.toString(routingFormPerson
0911: .getChartOfAccountsCode()));
0912: percentCreditDescription.setAttribute("ORG",
0913: ObjectUtils.toString(routingFormPerson
0914: .getOrganizationCode()));
0915: percentCreditDescription.setAttribute("CREDIT",
0916: ObjectUtils.toString(routingFormPerson
0917: .getPersonCreditPercent()));
0918: percentCreditDescription.setAttribute("FA", ObjectUtils
0919: .toString(routingFormPerson
0920: .getPersonFinancialAidPercent()));
0921: projectDetailElement
0922: .appendChild(percentCreditDescription);
0923: }
0924:
0925: for (RoutingFormOrganizationCreditPercent routingFormOrganizationCreditPercent : routingFormDocument
0926: .getRoutingFormOrganizationCreditPercents()) {
0927: Element percentCreditDescription = xmlDoc
0928: .createElement("PERCENT_CREDIT");
0929: percentCreditDescription
0930: .setAttribute(
0931: "NAME",
0932: ObjectUtils
0933: .toString(routingFormOrganizationCreditPercent
0934: .getOrganization()
0935: .getOrganizationName()));
0936: percentCreditDescription
0937: .setAttribute(
0938: "ROLE",
0939: ObjectUtils
0940: .toString(routingFormOrganizationCreditPercent
0941: .getOrganizationCreditRoleText()));
0942: percentCreditDescription
0943: .setAttribute(
0944: "CHART",
0945: ObjectUtils
0946: .toString(routingFormOrganizationCreditPercent
0947: .getChartOfAccountsCode()));
0948: percentCreditDescription
0949: .setAttribute(
0950: "ORG",
0951: ObjectUtils
0952: .toString(routingFormOrganizationCreditPercent
0953: .getOrganizationCode()));
0954: percentCreditDescription
0955: .setAttribute(
0956: "CREDIT",
0957: ObjectUtils
0958: .toString(routingFormOrganizationCreditPercent
0959: .getOrganizationCreditPercent()));
0960: percentCreditDescription.setAttribute("FA", ObjectUtils
0961: .toString(routingFormOrganizationCreditPercent
0962: .getOrganizationFinancialAidPercent()));
0963: projectDetailElement
0964: .appendChild(percentCreditDescription);
0965: }
0966: }
0967:
0968: return projectDetailElement;
0969: }
0970:
0971: /**
0972: * Creates APPROVALS node.
0973: *
0974: * @param routingFormDocument
0975: * @param xmlDoc
0976: * @return resulting node
0977: */
0978: private static Element createApprovalsElement(
0979: RoutingFormDocument routingFormDocument, Document xmlDoc) {
0980: Element approvalsElement = xmlDoc.createElement("APPROVALS");
0981:
0982: try {
0983: ReportCriteriaVO criteria = new ReportCriteriaVO();
0984: criteria.setRouteHeaderId(routingFormDocument
0985: .getDocumentHeader().getWorkflowDocument()
0986: .getRouteHeaderId());
0987: WorkflowInfo info = new WorkflowInfo();
0988: DocumentDetailVO detail = info.routingReport(criteria);
0989:
0990: for (ActionRequestVO actionRequest : detail
0991: .getActionRequests()) {
0992: actionRequestTraversal(xmlDoc, approvalsElement,
0993: actionRequest);
0994: }
0995: } catch (WorkflowException e) {
0996: throw new RuntimeException(
0997: "Exception generating routing report: " + e);
0998: }
0999:
1000: return approvalsElement;
1001: }
1002:
1003: /**
1004: * Traversal of ActionRequestVO. This is useful because an ActionRequest may be for a user, role or a workgroup. We want to be
1005: * able to handle all of them.
1006: *
1007: * @param xmlDoc
1008: * @param approvalsElement
1009: * @param actionRequest
1010: */
1011: private static void actionRequestTraversal(Document xmlDoc,
1012: Element approvalsElement, ActionRequestVO actionRequest) {
1013: // Note that any actionRequest can have an actionTaken item. But currently our output only shows users
1014: // and not workgroups / roles. That's why the code drills down to the user level.
1015: if (EdenConstants.ACTION_REQUEST_USER_RECIPIENT_CD
1016: .equals(actionRequest.getRecipientTypeCd())) {
1017: // Base case
1018: if (actionRequest.getActionTaken() == null) {
1019: // Action not taken yet, leave date empty
1020: UserVO user = actionRequest.getUserVO();
1021: String actionName = ObjectUtils
1022: .toString(EdenConstants.ACTION_REQUEST_CD
1023: .get(actionRequest.getActionRequested()));
1024: createApproverElement(xmlDoc, approvalsElement, user,
1025: actionRequest.getNodeName(), actionName, "");
1026: } else if (actionRequest.getUserVO().getEmplId().equals(
1027: actionRequest.getActionTaken().getUserVO()
1028: .getEmplId())) {
1029: // Action was taken, show date
1030: DateFormat dateFormat = new SimpleDateFormat(
1031: KraConstants.LONG_TIMESTAMP_FORMAT);
1032: ActionTakenVO actionTaken = actionRequest
1033: .getActionTaken();
1034: UserVO user = actionTaken.getUserVO();
1035: String actionName = ObjectUtils
1036: .toString(EdenConstants.ACTION_TAKEN_CD
1037: .get(actionTaken.getActionTaken()));
1038: createApproverElement(xmlDoc, approvalsElement, user,
1039: actionRequest.getNodeName(), actionName,
1040: dateFormat.format(actionTaken.getActionDate()
1041: .getTime()));
1042: }
1043: // else ignore, it should be an actionRequest for a user whose requests are cleared out. Such as if
1044: // multiple requests were pending but one disapproved, then all of the users get disapprovals assigned
1045: // with actionTaken pointing to the person that truly disapproved.
1046: } else {
1047: // Recursion
1048: for (ActionRequestVO actionRequestDeep : actionRequest
1049: .getChildrenRequests()) {
1050: actionRequestTraversal(xmlDoc, approvalsElement,
1051: actionRequestDeep);
1052: }
1053: }
1054: }
1055:
1056: /**
1057: * Helper method for actionRequestTraversal to avoid duplicating code for APPROVER node.
1058: *
1059: * @param xmlDoc xmlDoc to be used
1060: * @param approvalsElement parent node to be used
1061: * @param workflowUser that took the action
1062: * @param nodeName will be used for the TITLE field
1063: * @param actionName will be used for the ACTION field
1064: * @param actionDate will be used for the ACTION_DATE field
1065: */
1066: private static void createApproverElement(Document xmlDoc,
1067: Element approvalsElement, UserVO workflowUser,
1068: String nodeName, String actionName, String actionDate) {
1069: Element approverElement = xmlDoc.createElement("APPROVER");
1070:
1071: UniversalUser kualiUser;
1072: UniversalUserService universalUserService = SpringContext
1073: .getBean(UniversalUserService.class);
1074: ChartUserService chartUserService = SpringContext
1075: .getBean(ChartUserService.class);
1076: try {
1077: kualiUser = universalUserService
1078: .getUniversalUser(workflowUser.getUuId());
1079: } catch (UserNotFoundException e) {
1080: LOG.error("Lookup for emplId=" + workflowUser.getEmplId()
1081: + " failed. Skipping putting person in XML.");
1082: return;
1083: }
1084:
1085: approverElement.setAttribute("TITLE", ObjectUtils
1086: .toString(nodeName));
1087: approverElement.setAttribute("CHART", ObjectUtils
1088: .toString(chartUserService
1089: .getDefaultChartCode(kualiUser)));
1090: approverElement.setAttribute("ORG", ObjectUtils
1091: .toString(chartUserService
1092: .getDefaultOrganizationCode(kualiUser)));
1093: approverElement.setAttribute("ACTION", ObjectUtils
1094: .toString(actionName));
1095: approverElement.setAttribute("ACTION_DATE", ObjectUtils
1096: .toString(actionDate));
1097:
1098: Element nameElement = xmlDoc.createElement("NAME");
1099: nameElement.setAttribute("FIRST", ObjectUtils
1100: .toString(workflowUser.getFirstName()));
1101: nameElement.setAttribute("LAST", ObjectUtils
1102: .toString(workflowUser.getLastName()));
1103: approverElement.appendChild(nameElement);
1104:
1105: approvalsElement.appendChild(approverElement);
1106: }
1107:
1108: /**
1109: * Creates KEYWORDS node.
1110: *
1111: * @param routingFormKeywords
1112: * @param xmlDoc
1113: * @return resulting node
1114: */
1115: private static Element createKeywordsElement(
1116: List<RoutingFormKeyword> routingFormKeywords,
1117: Document xmlDoc) {
1118: Element keywordsElement = xmlDoc.createElement("KEYWORDS");
1119:
1120: for (RoutingFormKeyword routingFormKeyword : routingFormKeywords) {
1121: Element keywordDescription = xmlDoc
1122: .createElement("KEYWORD");
1123: keywordDescription
1124: .appendChild(xmlDoc
1125: .createTextNode(ObjectUtils
1126: .toString(routingFormKeyword
1127: .getRoutingFormKeywordDescription())));
1128: keywordsElement.appendChild(keywordDescription);
1129: }
1130:
1131: return keywordsElement;
1132: }
1133:
1134: /**
1135: * Creates COMMENTS node.
1136: *
1137: * @param routingFormDocument
1138: * @param xmlDoc
1139: * @return resulting node
1140: */
1141: private static Element createCommentsElement(
1142: RoutingFormDocument routingFormDocument, Document xmlDoc) {
1143: Element commentsElement = xmlDoc.createElement("COMMENTS");
1144:
1145: DateFormat dateFormat = new SimpleDateFormat(
1146: KraConstants.LONG_TIMESTAMP_FORMAT);
1147: Iterator notes = routingFormDocument.getDocumentHeader()
1148: .getBoNotes().iterator();
1149:
1150: while (notes.hasNext()) {
1151: Note note = (Note) notes.next();
1152:
1153: Element commentElement = xmlDoc.createElement("COMMENT");
1154:
1155: Element commentatorDescription = xmlDoc
1156: .createElement("COMMENTATOR");
1157: commentatorDescription.appendChild(xmlDoc
1158: .createTextNode(ObjectUtils.toString(note
1159: .getAuthorUniversal().getPersonName())));
1160: commentElement.appendChild(commentatorDescription);
1161:
1162: Element commentTimestampDescription = xmlDoc
1163: .createElement("COMMENT_TIMESTAMP");
1164: commentTimestampDescription.appendChild(xmlDoc
1165: .createTextNode(dateFormat.format(note
1166: .getNotePostedTimestamp())));
1167: commentElement.appendChild(commentTimestampDescription);
1168:
1169: Element commentTopicDescription = xmlDoc
1170: .createElement("COMMENT_TOPIC");
1171: commentTopicDescription.appendChild(xmlDoc
1172: .createTextNode(ObjectUtils.toString(note
1173: .getNoteTopicText())));
1174: commentElement.appendChild(commentTopicDescription);
1175:
1176: Element commentTextDescription = xmlDoc
1177: .createElement("COMMENT_TEXT");
1178: commentTextDescription.appendChild(xmlDoc
1179: .createTextNode(ObjectUtils.toString(note
1180: .getNoteText())));
1181: commentElement.appendChild(commentTextDescription);
1182:
1183: commentsElement.appendChild(commentElement);
1184: }
1185:
1186: return commentsElement;
1187: }
1188:
1189: /**
1190: * Takes a boolean at returns its value as a "Y" or "N". This is how the xslts interpret indicators.
1191: *
1192: * @param bool
1193: * @return
1194: */
1195: private static String formatBoolean(boolean bool) {
1196: return bool ? "Y" : "N";
1197: }
1198: }
|