/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see .
*/
package org.alfresco.repo.dictionary;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.EmptyContentReader;
import org.alfresco.repo.i18n.MessageDeployer;
import org.alfresco.repo.i18n.MessageService;
import org.alfresco.repo.policy.ClassPolicyDelegate;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.tenant.TenantAdminService;
import org.alfresco.repo.tenant.TenantDeployer;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.Pair;
import org.alfresco.util.PropertyCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.extensions.surf.util.AbstractLifecycleBean;
import org.alfresco.repo.dictionary.DynamicModelPolicies.OnLoadDynamicModel;
/**
* Bootstrap the dictionary from specified locations within the repository
*
* @author Roy Wetherall, JanV, sglover
*/
public class DictionaryRepositoryBootstrap extends AbstractLifecycleBean
implements TenantDeployer, DictionaryListener, /*TenantDictionaryListener, */MessageDeployer
{
// Logging support
private static Log logger = LogFactory.getLog(DictionaryRepositoryBootstrap.class);
/** Locations in the repository from which models should be loaded */
private List repositoryModelsLocations = new ArrayList();
/** Locations in the repository from which messages should be loaded */
private List repositoryMessagesLocations = new ArrayList();
/** Dictionary DAO */
private DictionaryDAO dictionaryDAO = null;
/** The content service */
private ContentService contentService;
/** The node service */
private NodeService nodeService;
/** The tenant admin service */
private TenantAdminService tenantAdminService;
/** The namespace service */
private NamespaceService namespaceService;
/** The message service */
private MessageService messageService;
/** The transaction service */
private TransactionService transactionService;
/** The policy component */
private PolicyComponent policyComponent;
/**
* Sets the Dictionary DAO
*
* @param dictionaryDAO
*/
public void setDictionaryDAO(DictionaryDAO dictionaryDAO)
{
this.dictionaryDAO = dictionaryDAO;
}
/**
* Set the content service
*
* @param contentService the content service
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* Set the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public PolicyComponent getPolicyComponent()
{
return policyComponent;
}
public void setPolicyComponent(PolicyComponent policyComponent)
{
this.policyComponent = policyComponent;
}
/**
* Set the tenant admin service
*
* @param tenantAdminService the tenant admin service
*/
public void setTenantAdminService(TenantAdminService tenantAdminService)
{
this.tenantAdminService = tenantAdminService;
}
/**
* Set the namespace service
*
* @param namespaceService the namespace service
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* Set the message service
*
* @param messageService the message service
*/
public void setMessageService(MessageService messageService)
{
this.messageService = messageService;
}
/**
* Set the transaction service
*
* @param transactionService the transaction service
*/
public void setTransactionService(TransactionService transactionService)
{
this.transactionService = transactionService;
}
/**
* Set the repository models locations
*
* @param repositoryModelsLocations list of the repository models locations
*/ public void setRepositoryModelsLocations(
List repositoryLocations)
{
this.repositoryModelsLocations = repositoryLocations;
}
/**
* Set the repository messages (resource bundle) locations
*
* @param repositoryLocations
* list of the repository messages locations
*/
public void setRepositoryMessagesLocations(
List repositoryLocations)
{
this.repositoryMessagesLocations = repositoryLocations;
}
private ClassPolicyDelegate onLoadDynamicModelDelegate;
/**
* Initialise - after bootstrap of schema and tenant admin service
*/
public void init()
{
PropertyCheck.mandatory(this, "dictionaryDAO", dictionaryDAO);
PropertyCheck.mandatory(this, "contentService", contentService);
PropertyCheck.mandatory(this, "nodeService", nodeService);
PropertyCheck.mandatory(this, "tenantAdminService", tenantAdminService);
PropertyCheck.mandatory(this, "namespaceService", namespaceService);
PropertyCheck.mandatory(this, "messageService", messageService);
PropertyCheck.mandatory(this, "transactionService", transactionService);
PropertyCheck.mandatory(this, "policyComponent", policyComponent);
if(onLoadDynamicModelDelegate == null)
{
onLoadDynamicModelDelegate = policyComponent.registerClassPolicy(DynamicModelPolicies.OnLoadDynamicModel.class);
}
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback