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