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; 017 018import java.io.InputStream; 019import java.util.Map; 020import java.util.Set; 021 022import org.apache.cocoon.ProcessingException; 023import org.slf4j.Logger; 024import org.w3c.dom.Element; 025 026import org.ametys.cms.data.ContentSynchronizationResult; 027import org.ametys.cms.repository.ModifiableContent; 028import org.ametys.plugins.contentio.synchronize.SynchronizableContentsCollection; 029import org.ametys.plugins.odfsync.cdmfr.ImportCDMFrContext; 030import org.ametys.plugins.odfsync.utils.ContentWorkflowDescription; 031 032/** 033 * Interface for component to import a CDM-fr input stream. 034 */ 035public interface ImportCDMFrComponent 036{ 037 /** Avalon Role */ 038 public static final String ROLE = ImportCDMFrComponent.class.getName(); 039 040 /** 041 * Return the attribute identifier for CDM-fr synchronization. 042 * @return The attribute name (cdmfrSyncCode) 043 */ 044 public String getIdField(); 045 046 /** 047 * Get the path of tri-state fields (with local and external values) 048 * @param additionalParameters Additional parameters 049 * @return the synchronized fields 050 */ 051 public Set<String> getLocalAndExternalFields(Map<String, Object> additionalParameters); 052 053 /** 054 * Handle the CDM-fr input stream to import all the programs and its dependencies containing into it. 055 * @param input The CDM-fr input stream 056 * @param parameters The parameters useful for the operation 057 * @param scc The {@link SynchronizableContentsCollection} calling this component 058 * @param logger The logger 059 * @return The list of imported/synchronized programs 060 * @throws ProcessingException If an error occurs 061 */ 062 public Map<String, Object> handleInputStream(InputStream input, Map<String, Object> parameters, SynchronizableContentsCollection scc, Logger logger) throws ProcessingException; 063 064 /** 065 * Import or synchronize the content. 066 * @param contentElement Element of the content 067 * @param wfDescription The workflow description 068 * @param title The title 069 * @param syncCode The synchronization code 070 * @param context the import context 071 * @return The imported or synchronized content 072 */ 073 public ModifiableContent importOrSynchronizeContent(Element contentElement, ContentWorkflowDescription wfDescription, String title, String syncCode, ImportCDMFrContext context); 074 075 /** 076 * Get the content from the synchronization code, the content type and the context. 077 * @param contentType The content type 078 * @param syncCode The synchronization code 079 * @param context the import context 080 * @return the retrieved content 081 */ 082 public ModifiableContent getContent(String contentType, String syncCode, ImportCDMFrContext context); 083 084 /** 085 * Get the name of catalog to use for import 086 * @param contentElement Element of the content 087 * @return The catalog to used 088 */ 089 public String getCatalogName(Element contentElement); 090 091 /** 092 * Get the content ID from the CDM code, if there is no match with the CDM code, then we search with the code. 093 * If nothing is found we return null. 094 * @param tableRefId The reference table ID 095 * @param cdmCode The CDM code 096 * @return A content ID or <code>null</code> 097 */ 098 public String getIdFromCDMThenCode(String tableRefId, String cdmCode); 099 100 /** 101 * Add specific fields to the content during import or synchronization. 102 * @param content Content to update 103 * @param additionalParameters Additional parameters 104 * @param logger The logger 105 * @return The synchronization result of the additional operations 106 */ 107 public ContentSynchronizationResult additionalOperations(ModifiableContent content, Map<String, Object> additionalParameters, Logger logger); 108}