001/* 002 * (C) Copyright 2018 Nuxeo (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 * Funsho David 018 */ 019package org.nuxeo.ecm.core.bulk.io; 020 021import static org.nuxeo.ecm.core.bulk.io.BulkConstants.BULK_COMMAND; 022import static org.nuxeo.ecm.core.bulk.io.BulkConstants.BULK_COUNT; 023import static org.nuxeo.ecm.core.bulk.io.BulkConstants.BULK_ENTITY_TYPE; 024import static org.nuxeo.ecm.core.bulk.io.BulkConstants.BULK_ID; 025import static org.nuxeo.ecm.core.bulk.io.BulkConstants.BULK_STATE; 026import static org.nuxeo.ecm.core.bulk.io.BulkConstants.BULK_SUBMIT; 027import static org.nuxeo.ecm.core.io.registry.reflect.Instantiations.SINGLETON; 028import static org.nuxeo.ecm.core.io.registry.reflect.Priorities.REFERENCE; 029 030import java.io.IOException; 031 032import org.nuxeo.ecm.core.bulk.BulkStatus; 033import org.nuxeo.ecm.core.io.marshallers.json.ExtensibleEntityJsonWriter; 034import org.nuxeo.ecm.core.io.registry.reflect.Setup; 035 036import com.fasterxml.jackson.core.JsonGenerator; 037 038/** 039 * @since 10.2 040 */ 041@Setup(mode = SINGLETON, priority = REFERENCE) 042public class BulkJsonWriter extends ExtensibleEntityJsonWriter<BulkStatus> { 043 044 public BulkJsonWriter() { 045 super(BULK_ENTITY_TYPE, BulkStatus.class); 046 } 047 048 @Override 049 public void writeEntityBody(BulkStatus entity, JsonGenerator jg) throws IOException { 050 jg.writeStringField(BULK_ID, entity.getId()); 051 jg.writeStringField(BULK_STATE, entity.getState().toString()); 052 jg.writeStringField(BULK_SUBMIT, entity.getSubmitTime().toString()); 053 writeEntityField(BULK_COMMAND, entity.getCommand(), jg); 054 if (entity.getCount() != null) { 055 jg.writeNumberField(BULK_COUNT, entity.getCount().longValue()); 056 } 057 } 058 059}