Compare commits

..
8 Commits
Author SHA1 Message Date
brian.long 8ab396fc57 fixed multipart (upload) support 2022-04-07 23:41:08 -04:00
brian.long 9a24fff0de fixed testing support 2022-04-07 23:40:32 -04:00
brian.long e971cfdaea fixed CXF createNode 2022-03-08 13:37:22 -05:00
brian.long ba3aaa97f3 added upload vscode test 2022-03-08 13:37:17 -05:00
brian.long b1f4399412 added log4j logging for testing 2022-03-08 13:37:12 -05:00
brian.long 8f4370a55f fixed CXF upload attachment 2022-03-03 10:29:27 -05:00
brian.long e07a8f9c0e extensibility fix 2021-10-27 13:26:45 -04:00
brian.long 41c7bd062b constraint serialization fix 2021-09-03 16:02:06 -04:00
20 changed files with 600 additions and 77 deletions
+126 -2
View File
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.inteligr8.alfresco</groupId>
<artifactId>acs-public-rest-api</artifactId>
<version>1.1.3</version>
<version>1.1-SNAPSHOT</version>
<name>Alfresco Content Services ReST API Client for Java</name>
<properties>
@@ -17,6 +17,7 @@
<acs.baseUrl>http://localhost:8080/api-explorer</acs.baseUrl>
<acs.platform.tag>acs6</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>
@@ -30,7 +31,7 @@
<dependency>
<groupId>com.inteligr8</groupId>
<artifactId>common-rest-api</artifactId>
<version>1.1.1</version>
<version>1.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
@@ -97,6 +98,12 @@
<version>4.5.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.16.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@@ -118,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>
@@ -136,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>
@@ -147,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>
@@ -165,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>
@@ -1,5 +1,21 @@
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
@@ -25,7 +25,7 @@ public class AcsClientCxfImpl extends ClientCxfImpl {
/**
* This constructor is for Spring use.
*/
AcsClientCxfImpl() {
protected AcsClientCxfImpl() {
}
/**
@@ -25,7 +25,7 @@ public class AcsClientJerseyImpl extends ClientJerseyImpl {
/**
* This constructor is for Spring use.
*/
AcsClientJerseyImpl() {
protected AcsClientJerseyImpl() {
}
/**
@@ -25,7 +25,7 @@ public class AcsPublicRestApiCxfImpl extends AcsPublicRestApi {
/**
* This constructor is for Spring use.
*/
AcsPublicRestApiCxfImpl() {
protected AcsPublicRestApiCxfImpl() {
}
/**
@@ -25,7 +25,7 @@ public class AcsPublicRestApiJerseyImpl extends AcsPublicRestApi {
/**
* This constructor is for Spring use.
*/
AcsPublicRestApiJerseyImpl() {
protected AcsPublicRestApiJerseyImpl() {
}
/**
@@ -1,18 +1,14 @@
package com.inteligr8.alfresco.acs.api;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import javax.ws.rs.core.MediaType;
import com.inteligr8.alfresco.acs.model.Error;
import com.inteligr8.alfresco.acs.model.NodeBodyCreate;
import com.inteligr8.alfresco.acs.model.NodeBodyCreateMultipartCxf;
import com.inteligr8.alfresco.acs.model.NodeEntry;
import io.swagger.annotations.Api;
@@ -26,10 +22,10 @@ public interface NodesCxfApi {
@POST
@Path("/nodes/{nodeId}/children")
@Consumes({ "application/json", "multipart/form-data" })
@Produces({ "application/json" })
@Consumes({ MediaType.MULTIPART_FORM_DATA })
@Produces({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Create a node", tags={ })
@ApiResponses(value = {
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Successful response", response = NodeEntry.class),
@ApiResponse(code = 400, message = "Invalid parameter: **nodeId** is not a valid format or **nodeBodyCreate** is invalid "),
@ApiResponse(code = 401, message = "Authentication failed"),
@@ -43,12 +39,35 @@ public interface NodesCxfApi {
@ApiResponse(code = 200, message = "Unexpected error", response = Error.class) })
public NodeEntry createNode(
@PathParam("nodeId") String nodeId,
NodeBodyCreate nodeBodyCreate,
@QueryParam("autoRename") Boolean autoRename,
@QueryParam("majorVersion") Boolean majorVersion,
@QueryParam("versioningEnabled") Boolean versioningEnabled,
@QueryParam("include") List<String> include,
@QueryParam("fields") List<String> fields,
List<Attachment> attachments);
NodeBodyCreateMultipartCxf body);
/*
* This better impl doesn't work
*
@POST
@Path("/nodes/{nodeId}/children")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
@Produces({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Create a node", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Successful response", response = NodeEntry.class),
@ApiResponse(code = 400, message = "Invalid parameter: **nodeId** is not a valid format or **nodeBodyCreate** is invalid "),
@ApiResponse(code = 401, message = "Authentication failed"),
@ApiResponse(code = 403, message = "Current user does not have permission to create children of **nodeId**"),
@ApiResponse(code = 404, message = "**nodeId** or **renditionId** does not exist "),
@ApiResponse(code = 409, message = "New name clashes with an existing node in the current parent folder"),
@ApiResponse(code = 413, message = "Content exceeds individual file size limit configured for the network or system"),
@ApiResponse(code = 415, message = "Content Type is not supported"),
@ApiResponse(code = 422, message = "Model integrity exception including a file name containing invalid characters"),
@ApiResponse(code = 507, message = "Content exceeds overall storage quota limit configured for the network or system"),
@ApiResponse(code = 200, message = "Unexpected error", response = Error.class) })
public NodeEntry createNode(
@PathParam("nodeId") String nodeId,
@Multipart("name") String name,
@Multipart("nodeType") String nodeType,
@Multipart("filedata") InputStream fileStream,
@Multipart("filedata") ContentDisposition disposition,
@Multipart(value = "autoRename", required = false) Boolean autoRename,
@Multipart(value = "majorVersion", required = false) Boolean majorVersion,
@Multipart(value = "versioningEnabled", required = false) Boolean versioningEnabled);
*/
}
@@ -1,20 +1,14 @@
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;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import javax.ws.rs.core.MediaType;
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;
@@ -28,8 +22,8 @@ public interface NodesJerseyApi {
@POST
@Path("/nodes/{nodeId}/children")
@Consumes({ "application/json", "multipart/form-data" })
@Produces({ "application/json" })
@Consumes({ MediaType.MULTIPART_FORM_DATA })
@Produces({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Create a node", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Successful response", response = NodeEntry.class),
@@ -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,
@QueryParam("autoRename") Boolean autoRename,
@QueryParam("majorVersion") Boolean majorVersion,
@QueryParam("versioningEnabled") Boolean versioningEnabled,
@QueryParam("include") List<String> include,
@QueryParam("fields") List<String> fields,
@FormDataParam("filedata") InputStream filedataStream,
@FormDataParam("filedata") FormDataContentDisposition filedataDisposition);
NodeBodyCreateMultipartJersey file);
}
@@ -1,28 +0,0 @@
package com.inteligr8.alfresco.acs.model;
import java.io.File;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
public class NodeBodyCreateFile extends NodeBodyCreate {
@ApiModelProperty
private File filedata;
@JsonProperty
public File getFiledata() {
return this.filedata;
}
public void setFiledata(File filedata) {
this.filedata = filedata;
}
public NodeBodyCreateFile filedata(File filedata) {
this.filedata = filedata;
return this;
}
}
@@ -0,0 +1,98 @@
package com.inteligr8.alfresco.acs.model;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
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.databind.ObjectMapper;
public class NodeBodyCreateMultipartCxf extends MultipartBody {
private static final Logger logger = LoggerFactory.getLogger(NodeBodyCreateMultipartCxf.class);
private static final ObjectMapper om = new ObjectMapper();
public static NodeBodyCreateMultipartCxf from(
NodeBodyCreate nodeBody, String filename, InputStream istream,
Boolean autoRename, Boolean majorVersion, Boolean versioningEnabled) throws IOException {
List<Attachment> atts = new LinkedList<>();
atts.addAll(toAttachments(nodeBody));
if (autoRename != null)
atts.add(toAttachment("autoRename", String.valueOf(autoRename)));
if (majorVersion != null)
atts.add(toAttachment("majorVersion", String.valueOf(majorVersion)));
if (versioningEnabled != null)
atts.add(toAttachment("versioningEnabled", String.valueOf(versioningEnabled)));
atts.add(toAttachment(filename, istream));
return new NodeBodyCreateMultipartCxf(atts, true);
}
public NodeBodyCreateMultipartCxf(List<Attachment> atts) throws IOException {
super(atts);
}
public NodeBodyCreateMultipartCxf(List<Attachment> atts, boolean outbound) throws IOException {
super(atts, outbound);
}
public NodeBodyCreate getBody() throws IOException {
if (!MediaType.APPLICATION_JSON_TYPE.equals(this.getRootAttachment().getContentType()))
throw new IllegalStateException();
InputStream istream = this.getRootAttachment().getDataHandler().getInputStream();
try {
return om.readValue(istream, NodeBodyCreate.class);
} finally {
istream.close();
}
}
public Attachment getFiledataAttachment() {
return this.getAttachment("filedata");
}
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 && !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()));
}
}
}
return atts;
}
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 + "\""));
}
}
}
@@ -0,0 +1,95 @@
package com.inteligr8.alfresco.acs.model;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
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.glassfish.jersey.media.multipart.BodyPart;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
public class NodeBodyCreateMultipartJersey extends FormDataMultiPart {
private static final Logger logger = LoggerFactory.getLogger(NodeBodyCreateMultipartJersey.class);
private static final ObjectMapper om = new ObjectMapper();
public static NodeBodyCreateMultipartJersey from(
NodeBodyCreate nodeBody, String filename, InputStream istream,
Boolean autoRename, Boolean majorVersion, Boolean versioningEnabled) throws IOException, ParseException {
NodeBodyCreateMultipartJersey multipart = new NodeBodyCreateMultipartJersey();
multipart.field("autoRename", String.valueOf(autoRename))
.field("majorVersion", String.valueOf(majorVersion))
.field("versioningEnabled", String.valueOf(versioningEnabled))
.bodyPart(toBodyPart(filename, istream))
.getBodyParts().addAll(toFields(nodeBody));
return multipart;
}
private NodeBodyCreateMultipartJersey() throws IOException {
}
public NodeBodyCreate getBody() throws IOException {
BodyPart bodyPart = this.getField("");
if (bodyPart == null)
throw new IllegalStateException();
if (!MediaType.APPLICATION_JSON_TYPE.equals(bodyPart.getMediaType()))
throw new IllegalStateException();
InputStream istream = bodyPart.getEntityAs(InputStream.class);
try {
return om.readValue(istream, NodeBodyCreate.class);
} finally {
istream.close();
}
}
public FormDataBodyPart getFiledataAttachment() {
return this.getField("filedata");
}
private static List<FormDataBodyPart> toFields(NodeBodyCreate nodeBody) throws IOException {
List<FormDataBodyPart> fields = new LinkedList<>();
fields.add(new FormDataBodyPart("name", nodeBody.getName()));
fields.add(new FormDataBodyPart("nodeType", nodeBody.getNodeType()));
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
fields.add(new FormDataBodyPart(prop.getKey(), prop.getValue().toString()));
}
}
}
return fields;
}
private static BodyPart toBodyPart(String filename, InputStream istream) throws ParseException {
if (filename == null) {
return new FormDataBodyPart()
.contentDisposition(new FormDataContentDisposition("form-data; name=\"filedata\""))
.entity(istream);
} else {
return new FormDataBodyPart()
.contentDisposition(new FormDataContentDisposition("form-data; name=\"filedata\"; filename=\"" + filename + "\""))
.entity(istream);
}
}
}
@@ -13,7 +13,7 @@ public class ConstraintInfo {
private String type;
@JsonProperty
private List<Map<String, String>> parameters;
private List<Map<String, Object>> parameters;
public String getType() {
return type;
@@ -23,11 +23,11 @@ public class ConstraintInfo {
this.type = type;
}
public List<Map<String, String>> getParameters() {
public List<Map<String, Object>> getParameters() {
return parameters;
}
public void setParameters(List<Map<String, String>> parameters) {
public void setParameters(List<Map<String, Object>> parameters) {
this.parameters = parameters;
}
@@ -0,0 +1 @@
org.apache.cxf.jaxrs.client.spec.ClientBuilderImpl
@@ -13,7 +13,7 @@ public class ConnectionCxfClientIT extends ConnectionClientIT {
@Autowired
@Qualifier("acs.api.cxf")
private AcsPublicRestApi client;
private AcsPublicRestApiCxfImpl client;
@Override
public AcsPublicRestApi getClient() {
@@ -0,0 +1,57 @@
package com.inteligr8.alfresco.acs;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Collections;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import com.inteligr8.alfresco.acs.model.Node;
import com.inteligr8.alfresco.acs.model.NodeBodyCreate;
import com.inteligr8.alfresco.acs.model.NodeBodyCreateMultipartCxf;
import com.inteligr8.rs.ClientConfiguration;
@TestPropertySource(locations = {"/local.properties"})
@SpringJUnitConfig(classes = {AcsClientConfiguration.class, AcsPublicRestApiCxfImpl.class, AcsClientCxfImpl.class})
public class CxfUploadIT extends UploadIT {
@Autowired
@Qualifier("acs.api.cxf")
private AcsPublicRestApiCxfImpl client;
@Override
public AcsPublicRestApi getClient() {
return this.client;
}
@Override
public ClientConfiguration getConfiguration() {
return this.client.getConfig();
}
@Test
@EnabledIf("hostExists")
public void uploadFile() throws IOException {
String folderNodeId = this.getSharedFolder();
NodeBodyCreate nodeBody = new NodeBodyCreate().nodeType("trx:transferReport").name("test-name1.txt")
.properties(Collections.singletonMap("cm:author", "Brian"));
ByteArrayInputStream istream = new ByteArrayInputStream("This is a test".getBytes());
NodeBodyCreateMultipartCxf body = NodeBodyCreateMultipartCxf.from(nodeBody, "test-name2.txt", istream, true, null, null);
Node newNode = this.client.getNodesExtApi().createNode(folderNodeId, body).getEntry();
Assertions.assertNotNull(newNode);
Assertions.assertNotNull(newNode.getId());
Assertions.assertEquals(folderNodeId, newNode.getParentId());
Assertions.assertEquals(nodeBody.getNodeType(), newNode.getNodeType());
Assertions.assertTrue(newNode.getName().startsWith("test-name1"));
}
}
@@ -0,0 +1,58 @@
package com.inteligr8.alfresco.acs;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.text.ParseException;
import java.util.Collections;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import com.inteligr8.alfresco.acs.model.Node;
import com.inteligr8.alfresco.acs.model.NodeBodyCreate;
import com.inteligr8.alfresco.acs.model.NodeBodyCreateMultipartJersey;
import com.inteligr8.rs.ClientConfiguration;
@TestPropertySource(locations = {"/local.properties"})
@SpringJUnitConfig(classes = {AcsClientConfiguration.class, AcsPublicRestApiJerseyImpl.class, AcsClientJerseyImpl.class})
public class JerseyUploadIT extends UploadIT {
@Autowired
@Qualifier("acs.api.jersey")
private AcsPublicRestApiJerseyImpl client;
@Override
public AcsPublicRestApi getClient() {
return this.client;
}
@Override
public ClientConfiguration getConfiguration() {
return this.client.getConfig();
}
@Test
@EnabledIf("hostExists")
public void uploadFile() throws IOException, ParseException {
String folderNodeId = this.getSharedFolder();
NodeBodyCreate nodeBody = new NodeBodyCreate().nodeType("trx:transferReport").name("test-name1.txt")
.properties(Collections.singletonMap("cm:author", "Brian"));
ByteArrayInputStream istream = new ByteArrayInputStream("This is a test".getBytes());
NodeBodyCreateMultipartJersey body = NodeBodyCreateMultipartJersey.from(nodeBody, "test-name2.txt", istream, true, null, null);
Node newNode = this.client.getNodesExtApi().createNode(folderNodeId, body).getEntry();
Assertions.assertNotNull(newNode);
Assertions.assertNotNull(newNode.getId());
Assertions.assertEquals(folderNodeId, newNode.getParentId());
Assertions.assertEquals(nodeBody.getNodeType(), newNode.getNodeType());
Assertions.assertTrue(newNode.getName().startsWith("test-name1"));
}
}
@@ -0,0 +1,26 @@
package com.inteligr8.alfresco.acs;
import com.inteligr8.alfresco.acs.model.RequestQuery;
import com.inteligr8.alfresco.acs.model.RequestQuery.LanguageEnum;
import com.inteligr8.alfresco.acs.model.ResultNode;
import com.inteligr8.alfresco.acs.model.ResultSetPaging;
import com.inteligr8.alfresco.acs.model.SearchRequest;
public abstract class UploadIT extends ConditionalIT {
public abstract AcsPublicRestApi getClient();
public String getSharedFolder() {
RequestQuery query = new RequestQuery();
query.setLanguage(LanguageEnum.AFTS);
query.setQuery("=@cm:name:'Shared'");
SearchRequest searchRequest = new SearchRequest();
searchRequest.setQuery(query);
ResultSetPaging paging = this.getClient().getSearchApi().search(searchRequest);
ResultNode folderNode = paging.getList().getEntries().iterator().next().getEntry();
return folderNode.getId();
}
}
@@ -0,0 +1 @@
org.glassfish.jersey.client.JerseyClientBuilder
+19
View File
@@ -0,0 +1,19 @@
rootLogger.level=trace
rootLogger.appenderRef.stdout.ref=STDOUT
logger.spring.name=org.springframework
logger.spring.level=info
logger.common-rest-api.name=com.inteligr8.rs
logger.common-rest-api.level=trace
logger.this.name=com.inteligr8.alfresco.acs
logger.this.level=trace
logger.jaxrslog.name=jaxrs.request
logger.jaxrslog.level=trace
appender.stdout.type=Console
appender.stdout.name=STDOUT
appender.stdout.layout.type=PatternLayout
appender.stdout.layout.pattern=%C [%t] %m%n
+53
View File
@@ -0,0 +1,53 @@
@baseUrl = http://localhost:8080/alfresco
@username = admin
@password = admin
### Find Folder
# @name find
POST {{baseUrl}}/api/-default-/public/search/versions/1/search HTTP/1.1
Authorization: Basic {{username}}:{{password}}
{
"query": {
"language": "afts",
"query": "=@cm:name:'Shared'"
}
}
@folderNodeId = {{find.response.body.list.entries[0].entry.id}}
### Upload File
# @name upload
POST {{baseUrl}}/api/-default-/public/alfresco/versions/1/nodes/{{folderNodeId}}/children?autoRename=true
Authorization: Basic {{username}}:{{password}}
Content-type: application/json
{
"name": "TestFolder",
"nodeType": "cm:content",
"properties": null
}
### Upload File
# @name upload-form
POST {{baseUrl}}/api/-default-/public/alfresco/versions/1/nodes/{{folderNodeId}}/children
Authorization: Basic {{username}}:{{password}}
Content-type: multipart/form-data; boundary=----Test
------Test
Content-disposition: form-data; name="name"
TestFolder
------Test
Content-disposition: form-data; name="nodeType"
cm:content
------Test
Content-disposition: form-data; name="autoRename"
true
------Test
Content-disposition: form-data; name="filedata"; filename="test.txt"
This is a test
------Test--