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 *     Vladimir Pasquier <vpasquier@nuxeo.com>
018 */
019package org.nuxeo.ecm.automation.jaxrs.io.audit;
020
021import java.io.IOException;
022import java.lang.annotation.Annotation;
023import java.lang.reflect.Type;
024
025import javax.ws.rs.Produces;
026import javax.ws.rs.core.MediaType;
027import javax.ws.rs.ext.Provider;
028
029import org.nuxeo.ecm.automation.jaxrs.io.EntityListWriter;
030import org.nuxeo.ecm.platform.audit.api.LogEntry;
031import org.nuxeo.ecm.platform.audit.api.LogEntryList;
032import org.nuxeo.ecm.webengine.jaxrs.coreiodelegate.JsonCoreIODelegate;
033
034import com.fasterxml.jackson.core.JsonGenerator;
035
036/**
037 * @since 5.7.3 - LogEntries Writer for Audit
038 * @deprecated since 7.2 this marshaller was migrated to org.nuxeo.ecm.platform.audit.io.LogEntryListJsonWriter. To use
039 *             it in JAX-RS, register the {@link JsonCoreIODelegate} to forward the JAX-RS marshalling to nuxeo-core-io.
040 */
041@Deprecated
042@Provider
043@Produces(MediaType.APPLICATION_JSON)
044public class LogEntryListWriter extends EntityListWriter<LogEntry> {
045
046    @Override
047    protected String getEntityType() {
048        return "logEntries";
049    }
050
051    @Override
052    public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
053        if (LogEntryList.class.isAssignableFrom(arg0)) {
054            return true;
055        } else {
056            return super.isWriteable(arg0, arg1, arg2, arg3);
057        }
058    }
059
060    @Override
061    protected void writeItem(JsonGenerator jg, LogEntry item) throws IOException {
062        LogEntryWriter ngw = new LogEntryWriter();
063        ngw.writeEntity(jg, item);
064    }
065
066}