Commit 898cb702 authored by Brian Long's avatar Brian Long
Browse files

Merge branch 'develop' into stable

parents 8fcaed75 938ac213
Loading
Loading
Loading
Loading
+118 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
		<acs.baseUrl>https://api-explorer.alfresco.com/api-explorer</acs.baseUrl>
		<acs.platform.tag>acs7</acs.platform.tag>
		<swagger.basePackage>com.inteligr8.alfresco.acs</swagger.basePackage>
		<it.directory>src/test/none</it.directory>

		<junit.version>5.7.2</junit.version>
		<spring.version>5.2.14.RELEASE</spring.version>
@@ -124,6 +125,21 @@
							</sources>
						</configuration>
					</execution>
					<execution>
						<id>add-services</id>
						<phase>process-test-resources</phase>
						<goals>
							<goal>add-test-resource</goal>
						</goals>
						<configuration>
							<resources>
								<resource>
									<directory>${it.directory}</directory>
									<filtering>false</filtering>
								</resource>
							</resources>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
@@ -142,6 +158,12 @@
						<version>${junit.version}</version>
					</dependency>
				</dependencies>
				<configuration>
					<excludes>
						<exclude>**/*Jersey*</exclude>
						<exclude>**/*Cxf*</exclude>
					</excludes>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-failsafe-plugin</artifactId>
@@ -153,6 +175,12 @@
						<version>${junit.version}</version>
					</dependency>
				</dependencies>
				<configuration>
					<excludes>
						<exclude>**/*Jersey*</exclude>
						<exclude>**/*Cxf*</exclude>
					</excludes>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-javadoc-plugin</artifactId>
@@ -171,6 +199,96 @@
	</build>

	<profiles>
		<profile>
			<id>it-jersey</id>
			<properties>
				<it.directory>src/test/jersey</it.directory>
			</properties>
			<build>
				<plugins>
					<plugin>
						<artifactId>maven-surefire-plugin</artifactId>
						<version>3.0.0-M5</version>
						<dependencies>
							<dependency>
								<groupId>org.junit.jupiter</groupId>
								<artifactId>junit-jupiter-engine</artifactId>
								<version>${junit.version}</version>
							</dependency>
						</dependencies>
						<configuration>
							<includes>
								<include>**/*Jersey*</include>
							</includes>
							<excludes>
								<exclude>**/*IT.java</exclude>
							</excludes>
						</configuration>
					</plugin>
					<plugin>
						<artifactId>maven-failsafe-plugin</artifactId>
						<version>3.0.0-M5</version>
						<dependencies>
							<dependency>
								<groupId>org.junit.jupiter</groupId>
								<artifactId>junit-jupiter-engine</artifactId>
								<version>${junit.version}</version>
							</dependency>
						</dependencies>
						<configuration>
							<includes>
								<include>**/*Jersey*IT.java</include>
							</includes>
						</configuration>
					</plugin>
				</plugins>
			</build>
		</profile>
		<profile>
			<id>it-cxf</id>
			<properties>
				<it.directory>src/test/cxf</it.directory>
			</properties>
			<build>
				<plugins>
					<plugin>
						<artifactId>maven-surefire-plugin</artifactId>
						<version>3.0.0-M5</version>
						<dependencies>
							<dependency>
								<groupId>org.junit.jupiter</groupId>
								<artifactId>junit-jupiter-engine</artifactId>
								<version>${junit.version}</version>
							</dependency>
						</dependencies>
						<configuration>
							<includes>
								<include>**/*Cxf*</include>
							</includes>
							<excludes>
								<exclude>**/*IT.java</exclude>
							</excludes>
						</configuration>
					</plugin>
					<plugin>
						<artifactId>maven-failsafe-plugin</artifactId>
						<version>3.0.0-M5</version>
						<dependencies>
							<dependency>
								<groupId>org.junit.jupiter</groupId>
								<artifactId>junit-jupiter-engine</artifactId>
								<version>${junit.version}</version>
							</dependency>
						</dependencies>
						<configuration>
							<includes>
								<include>**/*Cxf*IT.java</include>
							</includes>
						</configuration>
					</plugin>
				</plugins>
			</build>
		</profile>
		<!-- Implement when descriptor is available -->
		<profile>
			<id>swagger-codegen</id>
+17 −4
Original line number Diff line number Diff line
package com.inteligr8.alfresco.acs.api;

import java.io.File;
import java.util.Date;
import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

import com.inteligr8.alfresco.acs.model.AssociationBody;
import com.inteligr8.alfresco.acs.model.AssociationEntry;
import com.inteligr8.alfresco.acs.model.ChildAssociationBody;
@@ -13,14 +29,11 @@ import com.inteligr8.alfresco.acs.model.NodeBodyMove;
import com.inteligr8.alfresco.acs.model.NodeBodyUpdate;
import com.inteligr8.alfresco.acs.model.NodeChildAssociationPaging;
import com.inteligr8.alfresco.acs.model.NodeEntry;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import java.io.File;
import java.util.Date;
import java.util.List;
import javax.ws.rs.*;

/**
 * Alfresco Content Services REST API
+2 −3
Original line number Diff line number Diff line
@@ -7,9 +7,8 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;

import com.inteligr8.alfresco.acs.model.Error;
import com.inteligr8.alfresco.acs.model.NodeBodyCreateMultipartCxf;
import com.inteligr8.alfresco.acs.model.NodeEntry;

import io.swagger.annotations.Api;
@@ -40,7 +39,7 @@ public interface NodesCxfApi {
        @ApiResponse(code = 200, message = "Unexpected error", response = Error.class) })
    public NodeEntry createNode(
    		@PathParam("nodeId") String nodeId,
    		MultipartBody body);
    		NodeBodyCreateMultipartCxf body);
/*
 * This better impl doesn't work
 *
+2 −15
Original line number Diff line number Diff line
package com.inteligr8.alfresco.acs.api;

import java.io.InputStream;
import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@@ -10,11 +7,8 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;

import com.inteligr8.alfresco.acs.model.Error;
import com.inteligr8.alfresco.acs.model.NodeBodyCreate;
import com.inteligr8.alfresco.acs.model.NodeBodyCreateMultipartJersey;
import com.inteligr8.alfresco.acs.model.NodeEntry;

import io.swagger.annotations.Api;
@@ -45,13 +39,6 @@ public interface NodesJerseyApi {
        @ApiResponse(code = 200, message = "Unexpected error", response = Error.class) })
    public NodeEntry createNode(
    		@PathParam("nodeId") String nodeId,
    		NodeBodyCreate nodeBodyCreate,
    		@FormDataParam("autoRename") Boolean autoRename,
    		@FormDataParam("majorVersion") Boolean majorVersion,
    		@FormDataParam("versioningEnabled") Boolean versioningEnabled,
    		@FormDataParam("include") List<String> include,
    		@FormDataParam("fields") List<String> fields,
    		@FormDataParam("filedata") InputStream filedataStream,
    		@FormDataParam("filedata") FormDataContentDisposition filedataDisposition);
    		NodeBodyCreateMultipartJersey file);

}
+26 −27
Original line number Diff line number Diff line
package com.inteligr8.alfresco.acs.api;
package com.inteligr8.alfresco.acs.model;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.ws.rs.core.MediaType;

import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.inteligr8.alfresco.acs.model.NodeBodyCreate;

public class NodeBodyCreateMultipart extends MultipartBody {
public class NodeBodyCreateMultipartCxf extends MultipartBody {
	
	private static final Logger logger = LoggerFactory.getLogger(NodeBodyCreateMultipartCxf.class);
	private static final ObjectMapper om = new ObjectMapper();
	
	public static NodeBodyCreateMultipart from(
	public static NodeBodyCreateMultipartCxf from(
			NodeBodyCreate nodeBody, String filename, InputStream istream,
			Boolean autoRename, Boolean majorVersion, Boolean versioningEnabled) throws IOException {
		List<Attachment> atts = new LinkedList<>();
@@ -34,14 +35,14 @@ public class NodeBodyCreateMultipart extends MultipartBody {
		if (versioningEnabled != null)
			atts.add(toAttachment("versioningEnabled", String.valueOf(versioningEnabled)));
		atts.add(toAttachment(filename, istream));
		return new NodeBodyCreateMultipart(atts, true);
		return new NodeBodyCreateMultipartCxf(atts, true);
	}
 	
	public NodeBodyCreateMultipart(List<Attachment> atts) throws IOException {
	public NodeBodyCreateMultipartCxf(List<Attachment> atts) throws IOException {
		super(atts);
	}
 	
	public NodeBodyCreateMultipart(List<Attachment> atts, boolean outbound) throws IOException {
	public NodeBodyCreateMultipartCxf(List<Attachment> atts, boolean outbound) throws IOException {
		super(atts, outbound);
	}
	
@@ -63,37 +64,35 @@ public class NodeBodyCreateMultipart extends MultipartBody {
	
	
	
	@SuppressWarnings("unchecked")
	private static List<Attachment> toAttachments(NodeBodyCreate nodeBody) throws IOException {
		List<Attachment> atts = new LinkedList<>();
		atts.add(toAttachment("name", nodeBody.getName()));
		atts.add(toAttachment("nodeType", nodeBody.getNodeType()));
		if (nodeBody.getAspectNames() != null)
			atts.add(toAttachment("aspectNames", nodeBody.getAspectNames()));
		if (nodeBody.getProperties() != null)
			atts.add(toAttachment("properties", (Map<String, Object>)nodeBody.getProperties()));
		return atts;
		if (nodeBody.getAspectNames() != null && !nodeBody.getAspectNames().isEmpty())
			logger.warn("The ACS Public REST API does not support the explicit inclusion of aspects while creating content");
		if (nodeBody.getProperties() != null) {
			@SuppressWarnings("unchecked")
			Map<String, Object> props = (Map<String, Object>)nodeBody.getProperties();
			for (Entry<String, Object> prop : props.entrySet()) {
				if (prop.getValue() != null) {
					// FIXME convert dates as ACS would expect them to be formatted
					atts.add(toAttachment(prop.getKey(), prop.getValue().toString()));
				}
	
	private static Attachment toAttachment(String name, String value) {
		return new Attachment(name, new ByteArrayInputStream(value.getBytes()), new ContentDisposition("form-data; name=\"" + name + "\""));
			}
	
	private static Attachment toAttachment(String name, Collection<String> c) throws JsonProcessingException {
		return toJsonAttachment(name, c);
		}
	
	private static Attachment toAttachment(String name, Map<String, Object> map) throws JsonProcessingException {
		return toJsonAttachment(name, map);
		return atts;
	}
	
	private static Attachment toJsonAttachment(String name, Object obj) throws JsonProcessingException {
		String json = om.writeValueAsString(obj);
		return new Attachment(name, new ByteArrayInputStream(json.getBytes()), new ContentDisposition("form-data; name=\"" + name + "\""));
	private static Attachment toAttachment(String name, String value) {
		return new Attachment(name, new ByteArrayInputStream(value.getBytes()), new ContentDisposition("form-data; name=\"" + name + "\""));
	}

	private static Attachment toAttachment(String filename, InputStream istream) {
		if (filename == null) {
			return new Attachment("filedata", istream, new ContentDisposition("form-data; name=\"filedata\""));
		} else {
			return new Attachment("filedata", istream, new ContentDisposition("form-data; name=\"filedata\"; filename=\"" + filename + "\""));
		}
	}

}
Loading