001/* 002 * (C) Copyright 2010 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 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 * Contributors: 017 * Nuxeo - initial API and implementation 018 */ 019package org.nuxeo.ecm.platform.routing.web; 020 021import java.util.ArrayList; 022import java.util.List; 023 024import org.jboss.seam.ScopeType; 025import org.jboss.seam.annotations.Factory; 026import org.jboss.seam.annotations.In; 027import org.jboss.seam.annotations.Name; 028import org.jboss.seam.annotations.Scope; 029import org.nuxeo.ecm.core.api.CoreSession; 030import org.nuxeo.ecm.core.api.DocumentModel; 031import org.nuxeo.ecm.platform.routing.api.DocumentRoute; 032import org.nuxeo.ecm.platform.routing.api.DocumentRoutingService; 033import org.nuxeo.ecm.platform.ui.web.api.NavigationContext; 034import org.nuxeo.runtime.api.Framework; 035 036/** 037 * @author <a href="mailto:[email protected]">Alexandre Russel</a> 038 */ 039@Name("relatedRouteAction") 040@Scope(ScopeType.EVENT) 041public class RelatedRouteActionBean { 042 043 @In(required = true, create = true) 044 protected NavigationContext navigationContext; 045 046 @In(create = true, required = false) 047 protected CoreSession documentManager; 048 049 @Factory(value = "relatedRoutes") 050 public List<DocumentModel> findRelatedRoute() { 051 DocumentModel currentDoc = navigationContext.getCurrentDocument(); 052 if (currentDoc != null) { 053 return findRelatedRoute(currentDoc.getId()); 054 } 055 return new ArrayList<DocumentModel>(); 056 } 057 058 public List<DocumentModel> findRelatedRoute(String documentId) { 059 List<DocumentModel> docs = new ArrayList<DocumentModel>(); 060 if (documentId == null || "".equals(documentId)) { 061 return docs; 062 } 063 List<DocumentRoute> relatedRoutes = getDocumentRoutingService().getDocumentRoutesForAttachedDocument( 064 documentManager, documentId); 065 for (DocumentRoute documentRoute : relatedRoutes) { 066 docs.add(documentRoute.getDocument()); 067 } 068 return docs; 069 } 070 071 public boolean hasRelatedRoute(String documentId) { 072 return !findRelatedRoute(documentId).isEmpty(); 073 } 074 075 public boolean hasRelatedRoute() { 076 return !findRelatedRoute().isEmpty(); 077 } 078 079 public DocumentRoutingService getDocumentRoutingService() { 080 return Framework.getService(DocumentRoutingService.class); 081 } 082 083}