11package ca .bc .gov .farms .api .rest .v1 .endpoints .impl ;
22
33import java .io .ByteArrayInputStream ;
4- import java .io .ByteArrayOutputStream ;
5- import java .io .IOException ;
64import java .io .InputStream ;
75
86import javax .ws .rs .core .Response ;
97
10- import org .glassfish .jersey .media .multipart .FormDataContentDisposition ;
118import org .slf4j .Logger ;
129import org .slf4j .LoggerFactory ;
1310import 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