001/*
002 *  Copyright 2010 Anyware Services
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 */
016package org.ametys.odf.orgunit;
017
018import java.util.Set;
019
020import javax.jcr.Node;
021
022import org.apache.avalon.framework.service.ServiceException;
023import org.apache.avalon.framework.service.ServiceManager;
024
025import org.ametys.cms.content.external.ExternalizableMetadataProviderExtensionPoint;
026import org.ametys.cms.repository.ContentFactory;
027import org.ametys.cms.repository.ModifiableContentFactory;
028import org.ametys.odf.cdmfr.ExportCDMfrManager;
029import org.ametys.plugins.repository.AmetysObjectResolver;
030import org.ametys.plugins.repository.AmetysRepositoryException;
031import org.ametys.plugins.repository.RepositoryConstants;
032
033/**
034 * {@link ContentFactory} for handling {@link OrgUnit}
035 */
036public class OrgUnitFactory extends ModifiableContentFactory
037{
038    /** {@link OrgUnit} nodetype for resources collection */
039    public static final String ORGUNIT_NODETYPE = RepositoryConstants.NAMESPACE_PREFIX + ":orgunitContent";
040
041    /** {@link OrgUnit} content type */
042    public static final String ORGUNIT_CONTENT_TYPE = "org.ametys.plugins.odf.Content.orgunit";
043
044    /** The root OrgUnit node name */
045    public static final String ODF_ORGUNIT_ROOT_NODE = "root-orgunit";
046
047    private RootOrgUnitProvider _rootOrgUnitProvider;
048    private ExportCDMfrManager _exportCDMfrManager;
049    private ExternalizableMetadataProviderExtensionPoint _extMetadataProviderEP;
050    
051    @Override
052    public void service(ServiceManager manager) throws ServiceException
053    {
054        super.service(manager);
055        _rootOrgUnitProvider = (RootOrgUnitProvider) manager.lookup(RootOrgUnitProvider.ROLE);
056        _exportCDMfrManager = (ExportCDMfrManager) manager.lookup(ExportCDMfrManager.ROLE);
057        _extMetadataProviderEP = (ExternalizableMetadataProviderExtensionPoint) manager.lookup(ExternalizableMetadataProviderExtensionPoint.ROLE);
058    }
059    
060    @Override
061    public OrgUnit getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException
062    {
063        return new OrgUnit(node, parentPath, this);
064    }
065
066    String _getRootOrgUnitUAI()
067    {
068        return _rootOrgUnitProvider.getRoot().getUAICode();
069    }
070    
071    AmetysObjectResolver _getResolver()
072    {
073        return _resolver;
074    }
075    
076    ExportCDMfrManager _getExportCDMfrManager()
077    {
078        return _exportCDMfrManager;
079    }
080    
081    Set<String> _getSynchronizedMetadata(OrgUnit orgunit)
082    {
083        return _extMetadataProviderEP.getExternalAndLocalMetadata(orgunit);
084    }
085}