001/* 002 * (C) Copyright 2019 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 * Nour Al Kotob 018 */ 019 020package org.nuxeo.ecm.restapi.jaxrs.io.management; 021 022import static org.nuxeo.ecm.core.io.registry.reflect.Instantiations.SINGLETON; 023import static org.nuxeo.ecm.core.io.registry.reflect.Priorities.REFERENCE; 024 025import java.io.IOException; 026 027import org.nuxeo.ecm.admin.runtime.SimplifiedBundleInfo; 028import org.nuxeo.ecm.admin.runtime.SimplifiedServerInfo; 029import org.nuxeo.ecm.core.io.marshallers.json.ExtensibleEntityJsonWriter; 030import org.nuxeo.ecm.core.io.registry.reflect.Setup; 031 032import com.fasterxml.jackson.core.JsonGenerator; 033 034/** 035 * @since 11.3 036 */ 037@Setup(mode = SINGLETON, priority = REFERENCE) 038public class SimplifiedServerInfoJsonWriter extends ExtensibleEntityJsonWriter<SimplifiedServerInfo> { 039 040 public static final String ENTITY_TYPE = "serverInfo"; 041 042 public SimplifiedServerInfoJsonWriter() { 043 super(ENTITY_TYPE, SimplifiedServerInfo.class); 044 } 045 046 @Override 047 protected void writeEntityBody(SimplifiedServerInfo entity, JsonGenerator jg) throws IOException { 048 jg.writeStringField("applicationName", entity.getApplicationName()); 049 jg.writeStringField("applicationVersion", entity.getApplicationVersion()); 050 jg.writeStringField("distributionName", entity.getDistributionName()); 051 jg.writeStringField("distributionVersion", entity.getDistributionVersion()); 052 jg.writeStringField("distributionDate", entity.getDistributionDate()); 053 054 jg.writeArrayFieldStart("bundles"); 055 for (SimplifiedBundleInfo b : entity.getBundleInfos()) { 056 jg.writeStartObject(); 057 jg.writeStringField("name", b.getName()); 058 jg.writeStringField("version", b.getVersion()); 059 jg.writeEndObject(); 060 } 061 jg.writeEndArray(); 062 063 jg.writeArrayFieldStart("warnings"); 064 for (String w : entity.getWarnings()) { 065 jg.writeStartObject(); 066 jg.writeStringField("message", w); 067 jg.writeEndObject(); 068 } 069 jg.writeEndArray(); 070 071 jg.writeArrayFieldStart("errors"); 072 for (String w : entity.getErrors()) { 073 jg.writeStartObject(); 074 jg.writeStringField("message", w); 075 jg.writeEndObject(); 076 } 077 jg.writeEndArray(); 078 } 079 080}