001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package mocks.elements;
018:
019: import mocks.MockChartOrgService;
020:
021: import org.jdom.Element;
022:
023: import edu.iu.uis.eden.WorkflowServiceErrorImpl;
024: import edu.iu.uis.eden.exception.InvalidXmlException;
025: import edu.iu.uis.eden.exception.ResourceUnavailableException;
026: import edu.iu.uis.eden.services.InconsistentDocElementStateException;
027: import edu.iu.uis.eden.services.ServiceErrorConstants;
028:
029: /**
030: * <p>
031: * Title: UniversityOrganizationElement
032: * </p>
033: * <p>
034: * Description: Compound Doc Element. Brings ChartElement and OrgCodeElement together into a single route control.
035: * </p>
036: * <p>
037: * Copyright: Copyright (c) 2002
038: * </p>
039: * <p>
040: * Company: Indiana University
041: * </p>
042: *
043: * @author Ryan Kirkendall
044: * @version 1.0
045: */
046: public class UniversityOrganizationElement implements IDocElement {
047: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
048: .getLogger(UniversityOrganizationElement.class);
049: private static final String ELEMENT_NAME = "university_organization_eok";
050: private boolean routeControl;
051: private ChartElement chartElement;
052: private OrgCodeElement orgCodeElement;
053:
054: public UniversityOrganizationElement() {
055: LOG.debug("constructing . . .");
056: this .routeControl = true;
057: chartElement = new ChartElement();
058: orgCodeElement = new OrgCodeElement();
059: }
060:
061: public Element getXMLContent() {
062: LOG.debug("getXMLContent");
063:
064: if (this .isEmpty()) {
065: return null;
066: }
067:
068: Element me = new Element(ELEMENT_NAME);
069:
070: if (this .routeControl) {
071: me.setAttribute("route-control", "yes");
072: }
073:
074: if (!this .chartElement.isEmpty()) {
075: LOG.debug("inserting chart element");
076: me.addContent(chartElement.getXMLContent());
077: }
078:
079: if (!this .orgCodeElement.isEmpty()) {
080: LOG.debug("inserting org element");
081: me.addContent(orgCodeElement.getXMLContent());
082: }
083:
084: LOG.debug("return XMLContent " + me.toString());
085:
086: return me;
087: }
088:
089: public void loadFromXMLContent(Element element, boolean allowBlank)
090: throws InvalidXmlException,
091: InconsistentDocElementStateException {
092: LOG.debug("loadFromXMLContent");
093:
094: if (DocElementValidator.returnWithNoWorkDone(this , element,
095: allowBlank)) {
096: LOG.debug("returning without setting");
097:
098: return;
099: }
100:
101: //it's good load kiddies with their elements
102: chartElement.loadFromXMLContent(element.getChild(chartElement
103: .getElementName()), allowBlank);
104:
105: orgCodeElement.loadFromXMLContent(element
106: .getChild(orgCodeElement.getElementName()), allowBlank);
107:
108: LOG.debug("loaded UniversityOrganizationElement");
109: }
110:
111: public WorkflowServiceErrorImpl validate() {
112: LOG.debug("validate");
113:
114: boolean inError = false;
115:
116: WorkflowServiceErrorImpl myErrors = new WorkflowServiceErrorImpl(
117: "University Organization Children In Error",
118: ServiceErrorConstants.CHILDREN_IN_ERROR);
119:
120: WorkflowServiceErrorImpl chartError = chartElement.validate();
121:
122: if (chartError != null) {
123: LOG.debug("chart is in error");
124: inError = true;
125: myErrors.addChild(chartError);
126: }
127:
128: WorkflowServiceErrorImpl orgError = orgCodeElement.validate();
129:
130: if (orgError != null) {
131: LOG.debug("OrgCode is in error");
132: inError = true;
133: myErrors.addChild(orgError);
134: }
135:
136: if (inError) {
137: LOG.debug("in error returning a DocElementError");
138:
139: return myErrors;
140: }
141:
142: /*
143: * database validation - the chart and org must exist in the IU org table
144: */
145: if (!this .databaseValidate()) {
146: String msg = "Chart " + this .getChart() + " and Org "
147: + this .getOrgCode() + " don't exist";
148: LOG.debug(msg);
149:
150: return new WorkflowServiceErrorImpl(
151: msg,
152: ServiceErrorConstants.UNIVERSITY_ORGANIZATION_INVALID);
153: }
154:
155: LOG.debug("valid returning null");
156:
157: return null;
158: }
159:
160: public boolean isEmpty() {
161: if (this .chartElement.isEmpty()
162: && this .orgCodeElement.isEmpty()) {
163: return true;
164: }
165:
166: return false;
167: }
168:
169: public String getElementName() {
170: return ELEMENT_NAME;
171: }
172:
173: public void setRouteControl(boolean routeControl) {
174: }
175:
176: public boolean isRouteControl() {
177: return this .routeControl;
178: }
179:
180: /**
181: * Validates that the chart and org exist within the IU Hierarchy.
182: *
183: * @return true if the object is valid false if not
184: * @throws ResourceUnavailableException
185: */
186: protected boolean databaseValidate() {
187: return new MockChartOrgService().findOrganization(getChart(),
188: getOrgCode()) != null;
189: }
190:
191: public String getOrgCode() {
192: return this .orgCodeElement.getOrgCode();
193: }
194:
195: public void setOrgCode(String orgCode) {
196: this .orgCodeElement.setOrgCode(orgCode);
197: }
198:
199: public void setChart(String chart) {
200: this .chartElement.setChart(chart);
201: }
202:
203: public String getChart() {
204: return this .chartElement.getChart();
205: }
206:
207: /**
208: * validates underlying chart outside of the context of being in a UniversityOrganizationElement
209: *
210: * @return DocElementError of underlying chart's error(s)
211: */
212: public WorkflowServiceErrorImpl validateChart()
213: throws ResourceUnavailableException {
214: return this .chartElement.validate();
215: }
216:
217: /**
218: * validates underlying OrgCode outside of the context of being in a UniversityOrganizationElement
219: *
220: * @return DocElementError of underlying orgCode's error(s)
221: */
222: public WorkflowServiceErrorImpl validateOrgCode()
223: throws ResourceUnavailableException {
224: return this.orgCodeElement.validate();
225: }
226: }
|