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.AmetysRepositoryException;
030import org.ametys.plugins.repository.RepositoryConstants;
031
032/**
033 * {@link ContentFactory} for handling {@link OrgUnit}
034 */
035public class OrgUnitFactory extends ModifiableContentFactory
036{
037    /** {@link OrgUnit} nodetype for resources collection */
038    public static final String ORGUNIT_NODETYPE = RepositoryConstants.NAMESPACE_PREFIX + ":orgunitContent";
039
040    /** {@link OrgUnit} content type */
041    public static final String ORGUNIT_CONTENT_TYPE = "org.ametys.plugins.odf.Content.orgunit";
042
043    /** The root OrgUnit node name */
044    public static final String ODF_ORGUNIT_ROOT_NODE = "root-orgunit";
045
046    private RootOrgUnitProvider _rootOrgUnitProvider;
047    private ExportCDMfrManager _exportCDMfrManager;
048    private ExternalizableMetadataProviderExtensionPoint _extMetadataProviderEP;
049    
050    @Override
051    public void service(ServiceManager manager) throws ServiceException
052    {
053        super.service(manager);
054        _rootOrgUnitProvider = (RootOrgUnitProvider) manager.lookup(RootOrgUnitProvider.ROLE);
055        _exportCDMfrManager = (ExportCDMfrManager) manager.lookup(ExportCDMfrManager.ROLE);
056        _extMetadataProviderEP = (ExternalizableMetadataProviderExtensionPoint) manager.lookup(ExternalizableMetadataProviderExtensionPoint.ROLE);
057    }
058    
059    @Override
060    public OrgUnit getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException
061    {
062        return new OrgUnit(node, parentPath, this);
063    }
064
065    String _getRootOrgUnitUAI()
066    {
067        return _rootOrgUnitProvider.getRoot().getUAICode();
068    }
069    
070    ExportCDMfrManager _getExportCDMfrManager()
071    {
072        return _exportCDMfrManager;
073    }
074    
075    Set<String> _getSynchronizedMetadata(OrgUnit orgunit)
076    {
077        return _extMetadataProviderEP.getExternalAndLocalMetadata(orgunit);
078    }
079}