001/* 002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * dmetzler 016 */ 017package org.nuxeo.ecm.restapi.jaxrs.io.documents; 018 019import java.io.IOException; 020 021import javax.ws.rs.Produces; 022import javax.ws.rs.core.MediaType; 023import javax.ws.rs.ext.Provider; 024 025import org.codehaus.jackson.JsonGenerator; 026import org.nuxeo.ecm.automation.jaxrs.io.EntityWriter; 027import org.nuxeo.ecm.core.api.security.ACE; 028import org.nuxeo.ecm.core.api.security.ACL; 029import org.nuxeo.ecm.core.api.security.ACP; 030import org.nuxeo.ecm.core.io.marshallers.json.document.ACPJsonWriter; 031import org.nuxeo.ecm.core.schema.utils.DateParser; 032import org.nuxeo.ecm.webengine.jaxrs.coreiodelegate.JsonCoreIODelegate; 033 034/** 035 * Json writer for ACP. 036 * 037 * @since 5.7.3 038 * @deprecated since 7.10 The Nuxeo JSON marshalling was migrated to nuxeo-core-io. This class is replaced by 039 * {@link ACPJsonWriter} which is registered by default and available to marshal {@link ACP} from the Nuxeo 040 * Rest API thanks to the JAX-RS marshaller {@link JsonCoreIODelegate}. 041 */ 042@Deprecated 043@Provider 044@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON + "+nxentity" }) 045public class ACPWriter extends EntityWriter<ACP> { 046 047 public static final String ENTITY_TYPE = "acls"; 048 049 @Override 050 protected void writeEntityBody(JsonGenerator jg, ACP item) throws IOException { 051 052 jg.writeArrayFieldStart("acl"); 053 for (ACL acl : item.getACLs()) { 054 jg.writeStartObject(); 055 jg.writeStringField("name", acl.getName()); 056 057 jg.writeArrayFieldStart("ace"); 058 059 for (ACE ace : acl.getACEs()) { 060 jg.writeStartObject(); 061 jg.writeStringField("id", ace.getId()); 062 jg.writeStringField("username", ace.getUsername()); 063 jg.writeStringField("permission", ace.getPermission()); 064 jg.writeBooleanField("granted", ace.isGranted()); 065 jg.writeStringField("creator", ace.getCreator()); 066 jg.writeStringField("begin", 067 ace.getBegin() != null ? DateParser.formatW3CDateTime(ace.getBegin().getTime()) : null); 068 jg.writeStringField("end", ace.getEnd() != null ? DateParser.formatW3CDateTime(ace.getEnd().getTime()) 069 : null); 070 jg.writeStringField("status", ace.getStatus().toString().toLowerCase()); 071 jg.writeEndObject(); 072 } 073 074 jg.writeEndArray(); 075 jg.writeEndObject(); 076 } 077 jg.writeEndArray(); 078 } 079 080 @Override 081 protected String getEntityType() { 082 return ENTITY_TYPE; 083 } 084}