001/*
002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     dmetzler
016 */
017package org.nuxeo.ecm.automation.io.services.enricher;
018
019import java.util.ArrayList;
020import java.util.HashMap;
021import java.util.List;
022import java.util.Map;
023
024import org.apache.commons.logging.Log;
025import org.apache.commons.logging.LogFactory;
026import org.nuxeo.common.xmap.annotation.XNode;
027import org.nuxeo.common.xmap.annotation.XNodeList;
028import org.nuxeo.common.xmap.annotation.XNodeMap;
029import org.nuxeo.common.xmap.annotation.XObject;
030import org.nuxeo.ecm.platform.actions.ActionFilter;
031import org.nuxeo.ecm.platform.actions.DefaultActionFilter;
032
033/**
034 * @since 5.7.3
035 * @deprecated The JSON marshalling was migrated to nuxeo-core-io. An enricher system is also available. See
036 *             org.nuxeo.ecm.core.io.marshallers.json.enrichers.BreadcrumbJsonEnricher for an example. To migrate an
037 *             existing enricher, keep the marshalling code and use it in class implementing
038 *             AbstractJsonEnricher<DocumentModel> (the use of contextual parameters is a bit different but
039 *             compatible / you have to manage the enricher's parameters yourself). Don't forget to contribute to
040 *             service org.nuxeo.ecm.core.io.registry.MarshallerRegistry to register your enricher.
041 */
042@Deprecated
043@XObject("enricher")
044public class ContentEnricherDescriptor {
045
046    protected static final Log log = LogFactory.getLog(ContentEnricherDescriptor.class);
047
048    @XNode("@name")
049    public String name;
050
051    @XNodeList(value = "category", type = ArrayList.class, componentType = String.class)
052    List<String> categories;
053
054    @XNode("@class")
055    public Class<? extends ContentEnricher> klass;
056
057    @XNodeList(value = "filter-id", type = ArrayList.class, componentType = String.class)
058    protected List<String> filterIds;
059
060    @XNodeList(value = "filter", type = ActionFilter[].class, componentType = DefaultActionFilter.class)
061    protected ActionFilter[] filters;
062
063    @XNodeMap(value = "parameter", key = "@name", type = HashMap.class, componentType = String.class)
064    protected Map<String, String> parameters;
065
066    /**
067     * @return
068     */
069    public ContentEnricher getContentEnricher() {
070        try {
071            ContentEnricher enricher = klass.newInstance();
072            enricher.setParameters(parameters);
073            return enricher;
074        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException e) {
075            log.error(String.format("Failed to create %s content enricher: %s", name, e.getMessage()));
076            return null;
077        }
078    }
079
080}