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.restapi.jaxrs.io.usermanager; 020 021import java.io.IOException; 022 023import javax.ws.rs.Produces; 024import javax.ws.rs.ext.Provider; 025 026import org.codehaus.jackson.JsonGenerationException; 027import org.codehaus.jackson.JsonGenerator; 028import org.nuxeo.ecm.automation.jaxrs.io.EntityWriter; 029import org.nuxeo.ecm.core.api.NuxeoGroup; 030import org.nuxeo.ecm.platform.usermanager.io.NuxeoGroupJsonWriter; 031import org.nuxeo.ecm.webengine.jaxrs.coreiodelegate.JsonCoreIODelegate; 032 033/** 034 * @since 5.7.3 035 * @deprecated since 7.10 The Nuxeo JSON marshalling was migrated to nuxeo-core-io. This class is replaced by 036 * {@link NuxeoGroupJsonWriter} which is registered by default and available to marshal {@link NuxeoGroup} 037 * from the Nuxeo Rest API thanks to the JAX-RS marshaller {@link JsonCoreIODelegate} 038 */ 039@Deprecated 040@Provider 041@Produces({ "application/json+nxentity", "application/json" }) 042public class NuxeoGroupWriter extends EntityWriter<NuxeoGroup> { 043 044 /** 045 * 046 */ 047 public static final String ENTITY_TYPE = "group"; 048 049 /** 050 * @param createGenerator 051 * @param group 052 * @return 053 * @throws IOException 054 * @throws JsonGenerationException 055 */ 056 @Override 057 public void writeEntityBody(JsonGenerator jg, NuxeoGroup group) throws JsonGenerationException, 058 IOException { 059 jg.writeStringField("groupname", group.getName()); 060 061 jg.writeStringField("grouplabel", group.getLabel()); 062 063 jg.writeArrayFieldStart("memberUsers"); 064 for (String user : group.getMemberUsers()) { 065 jg.writeString(user); 066 } 067 jg.writeEndArray(); 068 069 jg.writeArrayFieldStart("memberGroups"); 070 for (String user : group.getMemberGroups()) { 071 jg.writeString(user); 072 } 073 jg.writeEndArray(); 074 075 } 076 077 @Override 078 protected String getEntityType() { 079 return ENTITY_TYPE; 080 } 081 082}