001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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: package org.kuali.module.chart.service.impl;
017:
018: import java.lang.reflect.InvocationTargetException;
019: import java.util.LinkedHashMap;
020: import java.util.Map;
021:
022: import org.kuali.module.chart.dao.FiscalYearMakersCopyAction;
023: import org.kuali.module.chart.dao.FiscalYearMakersDao;
024: import org.kuali.module.chart.service.DateMakerService;
025: import org.kuali.module.gl.bo.UniversityDate;
026: import org.springframework.transaction.annotation.Transactional;
027:
028: /**
029: * This class implements the DataMakerService
030: */
031: @Transactional
032: public class DateMakerServiceImpl implements DateMakerService {
033: private FiscalYearMakersDao fiscalYearMakersDao;
034:
035: /**
036: *
037: * @see org.kuali.module.chart.service.DateMakerService#fiscalYearMakers(boolean)
038: */
039: public void fiscalYearMakers(boolean replaceMode) {
040: Integer BaseYear = fiscalYearMakersDao.fiscalYearFromToday();
041: fiscalYearMakers(BaseYear, replaceMode);
042: }
043:
044: /**
045: *
046: * @see org.kuali.module.chart.service.DateMakerService#fiscalYearMakers(java.lang.Integer, boolean)
047: */
048: public void fiscalYearMakers(Integer baseYear, boolean replaceMode) {
049: Integer requestYear = baseYear + 1;
050: // (remember that replaceMode will have no effect for UniversityDate--any
051: // new year rows in that table are always replaced)
052: if (replaceMode) {
053: // we are supposed to replace what is in the target year
054: fiscalYearMakersDao.deleteNewYearRows(requestYear);
055: }
056: //
057: // encapsulate this in a try structure
058: // we need to undo any OJB structure changes we have made if there is an error
059: try {
060: // now, we get the copy order and call each object's copy action method
061: // in turn
062: LinkedHashMap<String, FiscalYearMakersCopyAction> copyOrder = fiscalYearMakersDao
063: .setUpRun(baseYear, replaceMode);
064: for (Map.Entry<String, FiscalYearMakersCopyAction> objectToCopy : copyOrder
065: .entrySet()) {
066: objectToCopy.getValue().copyMethod(baseYear,
067: replaceMode);
068: }
069: //
070: // some institutions want to set up two coming years at a time for certain
071: // business objects. at IU, this is the case for UniversityDate
072: // to do this, RI requires that the parent classes exist for the extra year
073: //
074: // we CANNOT delete the rows in target year +1 for the parents of UniversityDate. we can only
075: // copy them if they do not exist. if we delete them, and other children for target year +1
076: // exist, we will get a constraint violation.
077: // if (replaceMode)
078: // {
079: // fiscalYearMakersDao.deleteYearAfterNewYearRowsForParents(requestYear,
080: // UniversityDate.class);
081: // }
082: // now we do the copy
083: // we could STILL run into a problem. Suppose A is a parent of UniversityDate. Suppose B is
084: // a parent of A, but not of UniversityDate. Copying A but not B will result in a constraint
085: // violation. there does not appear to be a good way out of this in time for phase II.
086: // (what we really need is a recursive call of some type, which will copy a table only if it has no parent)
087: // in practice, UniversityDate is keyed on universityFiscalYear, and therefore has only one
088: // parent (Options) which has no parents itself.
089: for (Map.Entry<String, FiscalYearMakersCopyAction> objectToCopy : copyOrder
090: .entrySet()) {
091: if (fiscalYearMakersDao.isAParentOf(objectToCopy
092: .getKey(), UniversityDate.class)) {
093: FiscalYearMakersCopyAction classCopy = objectToCopy
094: .getValue();
095: classCopy.copyMethod(requestYear, false);
096: }
097: }
098: FiscalYearMakersCopyAction universityDateCopy = copyOrder
099: .get(UniversityDate.class.getName());
100: universityDateCopy.copyMethod(baseYear + 1, true);
101: } finally {
102: // make certain we always do this
103: fiscalYearMakersDao.resetCascades();
104: }
105: }
106:
107: /**
108: *
109: * This method injects the FiscalYearMakersDao
110: * @param fiscalYearMakersDao
111: */
112: public void setFiscalYearMakersDao(
113: FiscalYearMakersDao fiscalYearMakersDao) {
114: this .fiscalYearMakersDao = fiscalYearMakersDao;
115: }
116:
117: // TODO: remove these
118: public void testRoutine() {
119: // here we test the date routine
120: // Integer currentFiscalYear =
121: // fiscalYearMakersDao.fiscalYearFromToday();
122: // fiscalYearMakersDao.makeOptions(2043,true);
123: // fiscalYearMakersDao.makeOptions(2044,true);
124: // this.DateMaker(2042);
125: // this.DateMaker(2043);
126: // fiscalYearMakersDao.makeOptions(2045,true);
127: // fiscalYearMakersDao.makeOptions(2046);
128: // fiscalYearMakersDao.makeOptions(2047);
129: // fiscalYearMakersDao.makeOptions(2048);
130: // this.setFiscalYearStartDate(StartJanuary);
131: // this.DateMaker(2046);
132: // this.setFiscalYearStartDate(StartFebruary);
133: // this.DateMaker(2048);
134: try {
135: fiscalYearMakersDao.testRIRelationships();
136: } catch (IllegalAccessException ex) {
137: ex.printStackTrace();
138: RuntimeException rex = new RuntimeException(
139: "\nproblem in RI test");
140: throw (rex);
141: } catch (InvocationTargetException ex) {
142: ex.printStackTrace();
143: RuntimeException rex = new RuntimeException(
144: "\nproblem in RI test");
145: throw (rex);
146: } catch (NoSuchMethodException ex) {
147: ex.printStackTrace();
148: RuntimeException rex = new RuntimeException(
149: "\nproblem in RI test");
150: throw (rex);
151: }
152: ;
153: }
154: }
|