001/*
002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and others.
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 *
016 * Contributors:
017 *     dmetzler
018 */
019package org.nuxeo.ecm.automation.io.services.enricher;
020
021import java.util.ArrayList;
022import java.util.HashMap;
023import java.util.List;
024import java.util.Map;
025
026import org.apache.commons.logging.Log;
027import org.apache.commons.logging.LogFactory;
028import org.nuxeo.common.xmap.annotation.XNode;
029import org.nuxeo.common.xmap.annotation.XNodeList;
030import org.nuxeo.common.xmap.annotation.XNodeMap;
031import org.nuxeo.common.xmap.annotation.XObject;
032import org.nuxeo.ecm.platform.actions.ActionFilter;
033import org.nuxeo.ecm.platform.actions.DefaultActionFilter;
034
035/**
036 * @since 5.7.3
037 * @deprecated The JSON marshalling was migrated to nuxeo-core-io. An enricher system is also available. See
038 *             org.nuxeo.ecm.core.io.marshallers.json.enrichers.BreadcrumbJsonEnricher for an example. To migrate an
039 *             existing enricher, keep the marshalling code and use it in class implementing
040 *             AbstractJsonEnricher<DocumentModel> (the use of contextual parameters is a bit different but
041 *             compatible / you have to manage the enricher's parameters yourself). Don't forget to contribute to
042 *             service org.nuxeo.ecm.core.io.registry.MarshallerRegistry to register your enricher.
043 */
044@Deprecated
045@XObject("enricher")
046public class ContentEnricherDescriptor {
047
048    protected static final Log log = LogFactory.getLog(ContentEnricherDescriptor.class);
049
050    @XNode("@name")
051    public String name;
052
053    @XNodeList(value = "category", type = ArrayList.class, componentType = String.class)
054    List<String> categories;
055
056    @XNode("@class")
057    public Class<? extends ContentEnricher> klass;
058
059    @XNodeList(value = "filter-id", type = ArrayList.class, componentType = String.class)
060    protected List<String> filterIds;
061
062    @XNodeList(value = "filter", type = ActionFilter[].class, componentType = DefaultActionFilter.class)
063    protected ActionFilter[] filters;
064
065    @XNodeMap(value = "parameter", key = "@name", type = HashMap.class, componentType = String.class)
066    protected Map<String, String> parameters;
067
068    /**
069     * @return
070     */
071    public ContentEnricher getContentEnricher() {
072        try {
073            ContentEnricher enricher = klass.newInstance();
074            enricher.setParameters(parameters);
075            return enricher;
076        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException e) {
077            log.error(String.format("Failed to create %s content enricher: %s", name, e.getMessage()));
078            return null;
079        }
080    }
081
082}