1 16 package org.outerj.daisy.repository.serverimpl; 17 18 import org.outerj.daisy.repository.commonimpl.*; 19 import org.outerj.daisy.repository.commonimpl.comment.CommentStrategy; 20 import org.outerj.daisy.repository.commonimpl.variant.VariantStrategy; 21 import org.outerj.daisy.repository.commonimpl.acl.AclStrategy; 22 import org.outerj.daisy.repository.commonimpl.schema.SchemaStrategy; 23 import org.outerj.daisy.repository.commonimpl.user.UserManagementStrategy; 24 import org.outerj.daisy.repository.RepositoryException; 25 import org.outerj.daisy.repository.DocumentReadDeniedException; 26 import org.outerj.daisy.repository.AvailableVariants; 27 import org.outerj.daisy.repository.Document; 28 import org.outerj.daisy.repository.serverimpl.query.LocalQueryManager; 29 import org.outerj.daisy.repository.query.QueryManager; 30 import org.outerj.daisy.repository.acl.AclResultInfo; 31 import org.outerj.daisy.repository.acl.AclPermission; 32 import org.outerj.daisy.cache.DocumentCache; 33 import org.outerj.daisy.jdbcutil.JdbcHelper; 34 import org.apache.avalon.framework.logger.Logger; 35 36 import java.util.Map ; 37 38 41 public class LocalCommonRepository extends CommonRepository { 42 private DocumentCache cache; 43 private AuthenticatedUser systemUser; 44 private Logger logger; 45 private LocalRepositoryManager.Context context; 46 private JdbcHelper jdbcHelper; 47 48 public LocalCommonRepository(DocumentStrategy documentStrategy, SchemaStrategy schemaStrategy, 49 AclStrategy aclStrategy, UserManagementStrategy userManagementStrategy, VariantStrategy variantStrategy, 50 CollectionStrategy collectionStrategy, CommentStrategy commentStrategy, 51 LocalRepositoryManager.Context context, Logger logger, AuthenticatedUser systemUser, DocumentCache cache, 52 Map extensions, JdbcHelper jdbcHelper) { 53 super(documentStrategy, schemaStrategy, aclStrategy, userManagementStrategy, variantStrategy, 54 collectionStrategy, commentStrategy, extensions, systemUser); 55 56 this.context = context; 57 this.logger = logger; 58 this.cache = cache; 59 this.systemUser = systemUser; 60 this.jdbcHelper = jdbcHelper; 61 } 62 63 public QueryManager getQueryManager(AuthenticatedUser user) { 64 return new LocalQueryManager(context, user, systemUser, logger, jdbcHelper); 65 } 66 67 public Document getDocument(long documentId, long branchId, long languageId, boolean updateable, AuthenticatedUser user) throws RepositoryException { 68 if (updateable) 69 return super.getDocument(documentId, branchId, languageId, updateable, user); 70 else { 71 Document document = cache.get(documentId, branchId, languageId); 72 73 if (document == null) { 74 document = super.getDocument(documentId, branchId, languageId, updateable, systemUser); 75 cache.put(documentId, branchId, languageId, (DocumentImpl)document); 76 } 77 78 AclResultInfo aclInfo = getAccessManager().getAclInfoOnLive(systemUser, user.getId(), user.getActiveRoleIds(), document); 79 if (!aclInfo.isAllowed(AclPermission.READ)) { 80 if (aclInfo.isAllowed(AclPermission.READ_LIVE)) { 81 return new ReadLiveOnlyDocument(((DocumentWrapper)document).getWrappedDocument(documentStrategy), documentStrategy); 82 } else { 83 throw new DocumentReadDeniedException(documentId, user.getLogin(), user.getId()); 84 } 85 } 86 87 return document; 88 } 89 } 90 91 public AvailableVariants getAvailableVariants(long documentId, AuthenticatedUser user) throws RepositoryException { 92 AvailableVariants availableVariants = cache.getAvailableVariants(documentId); 93 if (availableVariants == null) { 94 availableVariants = super.getAvailableVariants(documentId, user); 95 cache.put(documentId, availableVariants); 96 } 97 return availableVariants; 98 } 99 } 100 | Popular Tags |