Skip to content

Commit 050ad44

Browse files
AS-3064: Adapt the /import/bpu endpoint to work with Custom Connector.
1 parent 658d524 commit 050ad44

File tree

2 files changed

+8
-29
lines changed

2 files changed

+8
-29
lines changed
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
package ca.bc.gov.farms.api.rest.v1.endpoints;
22

3-
import java.io.InputStream;
4-
53
import javax.ws.rs.Consumes;
64
import javax.ws.rs.POST;
75
import javax.ws.rs.Path;
6+
import javax.ws.rs.PathParam;
87
import javax.ws.rs.Produces;
98
import javax.ws.rs.core.MediaType;
109
import javax.ws.rs.core.Response;
1110

12-
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
13-
import org.glassfish.jersey.media.multipart.FormDataParam;
14-
1511
@Path("/import")
1612
public interface ImportEndpoints {
1713

1814
@POST
19-
@Path("/bpu")
15+
@Path("/bpu/{fileName}")
2016
@Consumes(MediaType.MULTIPART_FORM_DATA)
21-
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
22-
Response importBPU(@FormDataParam("file") InputStream fileInputStream,
23-
@FormDataParam("file") FormDataContentDisposition fileDetail) throws Exception;
17+
@Produces({ MediaType.TEXT_PLAIN })
18+
Response importBPU(@PathParam("fileName") String fileName,
19+
String fileContent) throws Exception;
2420
}

farms-api/farms-api-rest-endpoints/src/main/java/ca/bc/gov/farms/api/rest/v1/endpoints/impl/ImportEndpointsImpl.java

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package ca.bc.gov.farms.api.rest.v1.endpoints.impl;
22

33
import java.io.ByteArrayInputStream;
4-
import java.io.ByteArrayOutputStream;
5-
import java.io.IOException;
64
import java.io.InputStream;
75

86
import javax.ws.rs.core.Response;
97

10-
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
118
import org.slf4j.Logger;
129
import org.slf4j.LoggerFactory;
1310
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,24 +26,21 @@ public class ImportEndpointsImpl extends BaseEndpointsImpl implements ImportEndp
2926
private ImportBPUService importBPUService;
3027

3128
@Override
32-
public Response importBPU(InputStream fileInputStream, FormDataContentDisposition fileDetail) throws Exception {
29+
public Response importBPU(String fileName, String fileContent) throws Exception {
3330
logger.debug("<importBPU");
3431

3532
Response response = null;
3633

3734
logRequest();
3835

3936
try {
40-
byte[] fileContent = readBytes(fileInputStream);
41-
String fileName = fileDetail.getFileName();
42-
4337
// Call the service layer to handle the import
4438
ImportVersionDto importVersionDto = importService.createImportVersion(
4539
ImportClassCodes.BPU, ImportStateCodes.SCHEDULED_FOR_STAGING, ImportClassCodes.BPU_DESCRIPTION,
46-
fileName, fileContent, "UserId");
40+
fileName, fileContent.getBytes(), "UserId");
4741

4842
Long importVersionId = importVersionDto.getImportVersionId();
49-
InputStream inputStream = new ByteArrayInputStream(fileContent);
43+
InputStream inputStream = new ByteArrayInputStream(fileContent.getBytes());
5044
String userId = "UserId";
5145
importBPUService.importCSV(importVersionId, inputStream, userId);
5246

@@ -63,15 +57,4 @@ public Response importBPU(InputStream fileInputStream, FormDataContentDispositio
6357
return response;
6458
}
6559

66-
private byte[] readBytes(InputStream inputStream) throws IOException {
67-
try (ByteArrayOutputStream buffer = new ByteArrayOutputStream()) {
68-
int nRead;
69-
byte[] data = new byte[4096];
70-
while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
71-
buffer.write(data, 0, nRead);
72-
}
73-
return buffer.toByteArray();
74-
}
75-
}
76-
7760
}

0 commit comments

Comments
 (0)