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 edu.iu.uis.eden.routeheader;
018:
019: import java.util.ArrayList;
020: import java.util.Collection;
021: import java.util.List;
022: import java.util.Set;
023:
024: import edu.iu.uis.eden.EdenConstants;
025: import edu.iu.uis.eden.KEWServiceLocator;
026: import edu.iu.uis.eden.WorkflowServiceErrorException;
027: import edu.iu.uis.eden.WorkflowServiceErrorImpl;
028: import edu.iu.uis.eden.doctype.DocumentType;
029: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
030: import edu.iu.uis.eden.routeheader.dao.DocumentRouteHeaderDAO;
031: import edu.iu.uis.eden.user.WorkflowUserId;
032:
033: public class RouteHeaderServiceImpl implements RouteHeaderService {
034:
035: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
036: .getLogger(RouteHeaderServiceImpl.class);
037:
038: private DocumentRouteHeaderDAO routeHeaderDAO;
039:
040: public DocumentRouteHeaderValue getRouteHeader(Long routeHeaderId) {
041: return getRouteHeaderDAO().findRouteHeader(routeHeaderId);
042: }
043:
044: public DocumentRouteHeaderValue getRouteHeader(Long routeHeaderId,
045: boolean clearCache) {
046: return getRouteHeaderDAO().findRouteHeader(routeHeaderId,
047: clearCache);
048: }
049:
050: public void lockRouteHeader(Long routeHeaderId, boolean wait) {
051: getRouteHeaderDAO().lockRouteHeader(routeHeaderId, wait);
052: LOG.debug("Successfully locked document [docId="
053: + routeHeaderId + "]");
054: }
055:
056: public void saveRouteHeader(DocumentRouteHeaderValue routeHeader) {
057: this .getRouteHeaderDAO().saveRouteHeader(routeHeader);
058: }
059:
060: public void deleteRouteHeader(DocumentRouteHeaderValue routeHeader) {
061: getRouteHeaderDAO().deleteRouteHeader(routeHeader);
062: }
063:
064: public Long getNextRouteHeaderId() {
065: return getRouteHeaderDAO().getNextRouteHeaderId();
066: }
067:
068: public Collection findPendingByResponsibilityIds(
069: Set responsibilityIds) {
070: return getRouteHeaderDAO().findPendingByResponsibilityIds(
071: responsibilityIds);
072: }
073:
074: public void clearRouteHeaderSearchValues(
075: DocumentRouteHeaderValue routeHeader) {
076: getRouteHeaderDAO().clearRouteHeaderSearchValues(routeHeader);
077: }
078:
079: public void validateRouteHeader(DocumentRouteHeaderValue routeHeader) {
080: LOG.debug("Enter validateRouteHeader(..)");
081: List errors = new ArrayList();
082:
083: if (routeHeader.getDocRouteStatus() == null
084: || routeHeader.getDocRouteStatus().trim().equals("")) {
085: errors.add(new WorkflowServiceErrorImpl(
086: "RouteHeader route status null.",
087: "routeheader.routestatus.empty"));
088: } else if (!EdenConstants.DOCUMENT_STATUSES
089: .containsKey(routeHeader.getDocRouteStatus())) {
090: errors.add(new WorkflowServiceErrorImpl(
091: "RouteHeader route status invalid.",
092: "routeheader.routestatus.invalid"));
093: }
094:
095: if (routeHeader.getDocRouteLevel() == null
096: || routeHeader.getDocRouteLevel().intValue() < 0) {
097: errors.add(new WorkflowServiceErrorImpl(
098: "RouteHeader route level invalid.",
099: "routeheader.routelevel.invalid"));
100: }
101:
102: if (routeHeader.getStatusModDate() == null) {
103: errors.add(new WorkflowServiceErrorImpl(
104: "RouteHeader status modification date empty.",
105: "routeheader.statusmoddate.empty"));
106: }
107:
108: if (routeHeader.getCreateDate() == null) {
109: errors.add(new WorkflowServiceErrorImpl(
110: "RouteHeader status create date empty.",
111: "routeheader.createdate.empty"));
112: }
113: if (routeHeader.getDocVersion() == null
114: || routeHeader.getDocVersion().intValue() < 0) {
115: errors.add(new WorkflowServiceErrorImpl(
116: "RouteHeader doc version invalid.",
117: "routeheader.docversion.invalid"));
118: }
119:
120: if (routeHeader.getInitiatorWorkflowId() == null
121: || routeHeader.getInitiatorWorkflowId().trim().equals(
122: "")) {
123: errors.add(new WorkflowServiceErrorImpl(
124: "RouteHeader initiator null.",
125: "routeheader.initiator.empty"));
126: } else {
127: try {
128: KEWServiceLocator.getUserService().getWorkflowUser(
129: new WorkflowUserId(routeHeader
130: .getInitiatorWorkflowId()));
131: } catch (EdenUserNotFoundException e) {
132: errors.add(new WorkflowServiceErrorImpl(
133: "RouteHeader initiator id invalid.",
134: "routeheader.initiator.invalid"));
135: }
136: }
137:
138: if (routeHeader.getDocumentTypeId() != null
139: && routeHeader.getDocumentTypeId().intValue() != 0) {
140: DocumentType docType = KEWServiceLocator
141: .getDocumentTypeService().findById(
142: routeHeader.getDocumentTypeId());
143: if (docType == null) {
144: errors.add(new WorkflowServiceErrorImpl(
145: "RouteHeader document type id invalid.",
146: "routeheader.doctypeid.invalid"));
147: }
148: }
149:
150: LOG.debug("Exit validateRouteHeader(..) ");
151: if (!errors.isEmpty()) {
152: throw new WorkflowServiceErrorException(
153: "RouteHeader Validation Error", errors);
154: }
155: }
156:
157: public String getMessageEntityByDocumentId(Long documentId) {
158: return getRouteHeaderDAO().getMessageEntityByDocumentId(
159: documentId);
160: }
161:
162: public DocumentRouteHeaderValueContent getContent(Long routeHeaderId) {
163: if (routeHeaderId == null) {
164: return new DocumentRouteHeaderValueContent();
165: }
166: DocumentRouteHeaderValueContent content = getRouteHeaderDAO()
167: .getContent(routeHeaderId);
168: if (content == null) {
169: content = new DocumentRouteHeaderValueContent(routeHeaderId);
170: }
171: return content;
172: }
173:
174: public DocumentRouteHeaderDAO getRouteHeaderDAO() {
175: return routeHeaderDAO;
176: }
177:
178: public void setRouteHeaderDAO(DocumentRouteHeaderDAO routeHeaderDAO) {
179: this.routeHeaderDAO = routeHeaderDAO;
180: }
181: }
|