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.gl.service.impl.scrubber;
017:
018: import java.sql.Date;
019: import java.util.ArrayList;
020: import java.util.Collection;
021:
022: import org.kuali.core.service.DateTimeService;
023: import org.kuali.core.service.KualiConfigurationService;
024: import org.kuali.core.service.PersistenceService;
025: import org.kuali.kfs.context.SpringContext;
026: import org.kuali.module.gl.batch.collector.CollectorBatch;
027: import org.kuali.module.gl.bo.OriginEntryGroup;
028: import org.kuali.module.gl.dao.UniversityDateDao;
029: import org.kuali.module.gl.service.CollectorScrubberService;
030: import org.kuali.module.gl.service.OriginEntryGroupService;
031: import org.kuali.module.gl.service.OriginEntryService;
032: import org.kuali.module.gl.service.ScrubberService;
033: import org.kuali.module.gl.util.CollectorReportData;
034: import org.kuali.module.gl.util.CollectorScrubberStatus;
035: import org.springframework.transaction.annotation.Transactional;
036:
037: /**
038: * An implementation of CollectorScrubberService
039: */
040: @Transactional
041: public class CollectorScrubberServiceImpl implements
042: CollectorScrubberService {
043: private DateTimeService dateTimeService;
044: private UniversityDateDao universityDateDao;
045: private KualiConfigurationService kualiConfigurationService;
046: private PersistenceService persistenceService;
047: private ScrubberService scrubberService;
048:
049: /**
050: * uns the scrubber on the origin entries in the batch. Any OEs edits/removals result of the scrub and demerger are removed
051: * from the batch, and the same changes are reflected in the details in the same batch.
052: *
053: * @param batch the data read in by the Collector
054: * @param collectorReportData statistics generated by the scrub run on the Collector data
055: * @return an object with the collector scrubber status.
056: * @see org.kuali.module.gl.service.CollectorScrubberService#scrub(org.kuali.module.gl.batch.collector.CollectorBatch,
057: * org.kuali.module.gl.util.CollectorReportData)
058: */
059: public CollectorScrubberStatus scrub(CollectorBatch batch,
060: CollectorReportData collectorReportData) {
061: CollectorScrubberProcess collectorScrubberProcess = new CollectorScrubberProcess(
062: batch, SpringContext.getBean(OriginEntryService.class),
063: SpringContext.getBean(OriginEntryGroupService.class),
064: kualiConfigurationService, persistenceService,
065: scrubberService, collectorReportData);
066: return collectorScrubberProcess.scrub();
067: }
068:
069: /**
070: * Removes any temporarily created origin entries and origin entry groups so that they won't be persisted after the transaction
071: * is committed.
072: *
073: * @param allStatusObjectsFromCollectorExecution a Collection of ScrubberStatus records to help find bad Collector data
074:
075: * @see org.kuali.module.gl.service.CollectorScrubberService#removeTempGroups(java.util.Collection)
076: */
077: public void removeTempGroups(
078: Collection<CollectorScrubberStatus> allStatusObjectsFromCollectorExecution) {
079: for (CollectorScrubberStatus collectorScrubberStatus : allStatusObjectsFromCollectorExecution) {
080: OriginEntryGroupService originEntryGroupService = collectorScrubberStatus
081: .getOriginEntryGroupService();
082: Collection<OriginEntryGroup> groupsToDelete = new ArrayList<OriginEntryGroup>();
083:
084: if (collectorScrubberStatus.getInputGroup() != null
085: && collectorScrubberStatus.getInputGroup().getId() != null) {
086: groupsToDelete.add(collectorScrubberStatus
087: .getInputGroup());
088: }
089: if (collectorScrubberStatus.getValidGroup() != null
090: && collectorScrubberStatus.getValidGroup().getId() != null) {
091: groupsToDelete.add(collectorScrubberStatus
092: .getValidGroup());
093: }
094: if (collectorScrubberStatus.getExpiredGroup() != null
095: && collectorScrubberStatus.getExpiredGroup()
096: .getId() != null) {
097: groupsToDelete.add(collectorScrubberStatus
098: .getExpiredGroup());
099: }
100: if (collectorScrubberStatus.getErrorGroup() != null
101: && collectorScrubberStatus.getErrorGroup().getId() != null) {
102: groupsToDelete.add(collectorScrubberStatus
103: .getErrorGroup());
104: }
105: if (!groupsToDelete.isEmpty()) {
106: originEntryGroupService.deleteGroups(groupsToDelete);
107: }
108: }
109: }
110:
111: /**
112: * Finds the run date of the current Collector scrubber process
113: * @return the date of the process
114: */
115: protected Date calculateRunDate() {
116: return dateTimeService.getCurrentSqlDate();
117: }
118:
119: /**
120: * Gets the dateTimeService attribute.
121: *
122: * @return Returns the dateTimeService.
123: */
124: public DateTimeService getDateTimeService() {
125: return dateTimeService;
126: }
127:
128: /**
129: * Sets the dateTimeService attribute value.
130: *
131: * @param dateTimeService The dateTimeService to set.
132: */
133: public void setDateTimeService(DateTimeService dateTimeService) {
134: this .dateTimeService = dateTimeService;
135: }
136:
137: /**
138: * Gets the kualiConfigurationService attribute.
139: *
140: * @return Returns the kualiConfigurationService.
141: */
142: public KualiConfigurationService getKualiConfigurationService() {
143: return kualiConfigurationService;
144: }
145:
146: /**
147: * Sets the kualiConfigurationService attribute value.
148: *
149: * @param kualiConfigurationService The kualiConfigurationService to set.
150: */
151: public void setKualiConfigurationService(
152: KualiConfigurationService kualiConfigurationService) {
153: this .kualiConfigurationService = kualiConfigurationService;
154: }
155:
156: /**
157: * Sets the universityDateDao attribute value.
158: *
159: * @param universityDateDao The universityDateDao to set.
160: */
161: public void setUniversityDateDao(UniversityDateDao universityDateDao) {
162: this .universityDateDao = universityDateDao;
163: }
164:
165: /**
166: * Gets the persistenceService attribute.
167: *
168: * @return Returns the persistenceService.
169: */
170: public PersistenceService getPersistenceService() {
171: return persistenceService;
172: }
173:
174: /**
175: * Sets the persistenceService attribute value.
176: *
177: * @param persistenceService The persistenceService to set.
178: */
179: public void setPersistenceService(
180: PersistenceService persistenceService) {
181: this .persistenceService = persistenceService;
182: }
183:
184: /**
185: * Gets the universityDateDao attribute.
186: *
187: * @return Returns the universityDateDao.
188: */
189: public UniversityDateDao getUniversityDateDao() {
190: return universityDateDao;
191: }
192:
193: /**
194: * Sets the scrubberService attribute value.
195: *
196: * @param scrubberService The scrubberService to set.
197: */
198: public void setScrubberService(ScrubberService scrubberService) {
199: this.scrubberService = scrubberService;
200: }
201:
202: }
|