001/* 002 * Copyright 2018 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.plugins.odfsync.apogee.scc; 017 018import java.util.List; 019 020import org.apache.avalon.framework.service.ServiceException; 021import org.apache.avalon.framework.service.ServiceManager; 022 023import org.ametys.odf.ProgramItem; 024import org.ametys.odf.catalog.CatalogsManager; 025import org.ametys.odf.orgunit.OrgUnit; 026import org.ametys.plugins.repository.metadata.ModifiableCompositeMetadata; 027import org.ametys.plugins.repository.query.expression.Expression; 028import org.ametys.plugins.repository.query.expression.Expression.Operator; 029import org.ametys.plugins.repository.query.expression.StringExpression; 030 031/** 032 * Abstract class for Apogee synchronization, contents with catalog (not {@link OrgUnit}). 033 */ 034public abstract class AbstractApogeeSynchronizableContentsWithCatalogCollection extends AbstractApogeeSynchronizableContentsCollection 035{ 036 /** The catalog manager */ 037 protected CatalogsManager _catalogsManager; 038 039 @Override 040 public void service(ServiceManager manager) throws ServiceException 041 { 042 super.service(manager); 043 _catalogsManager = (CatalogsManager) manager.lookup(CatalogsManager.ROLE); 044 } 045 046 @Override 047 protected boolean _handleAdditionalMetadata(ModifiableCompositeMetadata holder, boolean create) 048 { 049 if (create) 050 { 051 String defaultCatalog = _catalogsManager.getDefaultCatalogName(); 052 if (defaultCatalog != null) 053 { 054 holder.setMetadata(ProgramItem.METADATA_CATALOG, defaultCatalog); 055 return true; 056 } 057 } 058 return false; 059 } 060 061 @Override 062 protected List<Expression> _getExpressionsList(String lang, String idValue, String contentType) 063 { 064 List<Expression> expList = super._getExpressionsList(lang, idValue, contentType); 065 String defaultCatalog = _catalogsManager.getDefaultCatalogName(); 066 if (defaultCatalog != null) 067 { 068 expList.add(new StringExpression(ProgramItem.METADATA_CATALOG, Operator.EQ, defaultCatalog)); 069 } 070 return expList; 071 } 072}