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.cdmfr.components.impl; 017 018import java.io.IOException; 019import java.util.Map; 020 021import javax.jcr.RepositoryException; 022 023import org.apache.cocoon.ProcessingException; 024import org.apache.commons.lang3.StringUtils; 025import org.slf4j.Logger; 026import org.w3c.dom.Document; 027import org.w3c.dom.Node; 028import org.xml.sax.SAXException; 029 030import org.ametys.cms.repository.ModifiableDefaultContent; 031import org.ametys.plugins.odfsync.cdmfr.RemoteCDMFrSynchronizableContentsCollection; 032import org.ametys.plugins.odfsync.cdmfr.components.AbstractImportCDMFrComponent; 033 034/** 035 * Component to import a CDM-fr input stream from a remote server. 036 */ 037public class RemoteImportCDMFrComponent extends AbstractImportCDMFrComponent 038{ 039 /** Avalon Role */ 040 @SuppressWarnings("hiding") 041 public static final String ROLE = RemoteImportCDMFrComponent.class.getName(); 042 043 /** Forced catalog */ 044 protected String _forcedCatalog; 045 046 /** Validate after import */ 047 protected boolean _validateAfterImport; 048 049 @Override 050 protected void additionalParameters(Map<String, Object> parameters) 051 { 052 _forcedCatalog = (String) parameters.getOrDefault(RemoteCDMFrSynchronizableContentsCollection.PARAM_CDMFR_CATALOG, null); 053 _validateAfterImport = (boolean) parameters.getOrDefault(RemoteCDMFrSynchronizableContentsCollection.PARAM_CDMFR_VALIDATE_AFTER_IMPORT, false); 054 } 055 056 @Override 057 protected void additionalOperationsBeforeSave(ModifiableDefaultContent content, Logger logger) throws RepositoryException 058 { 059 // Nothing to do 060 } 061 062 @Override 063 protected String getCatalogName(Node contentNode) 064 { 065 if (StringUtils.isNotEmpty(_forcedCatalog)) 066 { 067 return _forcedCatalog; 068 } 069 070 return super.getCatalogName(contentNode); 071 } 072 073 @Override 074 protected Document transformDocument(Document document, Map<String, Object> parameters, Logger logger) throws IOException, SAXException, ProcessingException 075 { 076 parameters.put("importRootOrgUnitOnly", true); 077 return super.transformDocument(document, parameters, logger); 078 } 079 080 @Override 081 protected boolean validateAfterImport() 082 { 083 return _validateAfterImport; 084 } 085 086 @Override 087 protected boolean removalSync() 088 { 089 return true; 090 } 091 092 @Override 093 protected boolean ignoreRights() 094 { 095 return true; 096 } 097}