001/*
002 *  Copyright 2024 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.cdmfr;
017
018import java.io.IOException;
019import java.io.InputStream;
020import java.util.HashMap;
021import java.util.Map;
022
023import org.apache.cocoon.util.log.SLF4JLoggerAdapter;
024
025import org.ametys.cms.repository.DefaultContent;
026import org.ametys.odf.CallWSHelper;
027import org.ametys.odf.ProgramItem;
028import org.ametys.odf.program.Program;
029
030/**
031 * Processor to delete the program on remote servers.
032 */
033public class DeleteRemoteProgramProcessor extends SendCDMfrProcessor
034{
035    /** The component role. */
036    @SuppressWarnings("hiding")
037    public static final String ROLE = DeleteRemoteProgramProcessor.class.getName();
038    
039    @Override
040    protected InputStream _getCDMfrContent(Program program) throws IOException
041    {
042        // We don't need the CDM-fr content for this process
043        return null;
044    }
045    
046    @Override
047    protected void processProgram(Program program, InputStream cdmfrContent) throws IOException
048    {
049        Map<String, String> params = new HashMap<>();
050        params.put(ProgramItem.CODE, program.getCode());
051        params.put(ProgramItem.CATALOG, program.getCatalog());
052        params.put(DefaultContent.METADATA_LANGUAGE, program.getLanguage());
053        
054        // Delete program on remote application
055        CallWSHelper.callWS("_odf-sync/delete-program", params, new SLF4JLoggerAdapter(getLogger()));
056    }
057}