Skip to content

Commit fa712dd

Browse files
AS-3064: Adapt the /import/bpu endpoint to work with Custom Connector.
1 parent 9308eb9 commit fa712dd

File tree

5 files changed

+20
-32
lines changed

5 files changed

+20
-32
lines changed

.github/workflows/build-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
export NODE_OPTIONS="--max-old-space-size=4096"
5757
export RELEASE_URL=${{ vars.RELEASE_URL }}
5858
export SNAPSHOT_URL=${{ vars.SNAPSHOT_URL }}
59-
mvn --settings=settings.xml --batch-mode --update-snapshots -f ${{ inputs.MICROSERVICE_NAME }}/pom.xml -Drepo.login=${{ secrets.IDIR_AS_EMAIL }} -Drepo.password=${{ secrets.IDIR_PASSWORD }} -DopenshiftRepo.login=${{ secrets.OPENSHIFT_ACCOUNT }} -DopenshiftRepo.password=${{ secrets.OPENSHIFT_PASSWORD }} -Dtenant.id=${{ secrets.TENANT_ID }} -Dclient.id=${{ secrets.CLIENT_ID }} deploy
59+
mvn --settings=settings.xml --batch-mode --update-snapshots -f ${{ inputs.MICROSERVICE_NAME }}/pom.xml -Drepo.login=${{ secrets.IDIR_AS_EMAIL }} -Drepo.password=${{ secrets.IDIR_PASSWORD }} -DopenshiftRepo.login=${{ secrets.OPENSHIFT_ACCOUNT }} -DopenshiftRepo.password=${{ secrets.OPENSHIFT_PASSWORD }} -Dclient.id=${{ secrets.CLIENT_ID }} deploy
6060
6161
- name: Cache local Maven repository
6262
uses: actions/cache@v4

farms-api/farms-api-rest-endpoints/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@
6363
<groupId>org.springframework.boot</groupId>
6464
<artifactId>spring-boot-starter-log4j2</artifactId>
6565
</dependency>
66+
<dependency>
67+
<groupId>com.azure.spring</groupId>
68+
<artifactId>spring-cloud-azure-starter-active-directory</artifactId>
69+
<version>4.20.0</version>
70+
</dependency>
6671
<dependency>
6772
<groupId>org.springframework.boot</groupId>
6873
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
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")
20-
@Consumes(MediaType.MULTIPART_FORM_DATA)
15+
@Path("/bpu/{fileName}")
16+
@Consumes(MediaType.TEXT_PLAIN)
2117
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
22-
Response importBPU(@FormDataParam("file") InputStream fileInputStream,
23-
@FormDataParam("file") FormDataContentDisposition fileDetail) throws Exception;
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
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
spring.application.name=farms-api-rest-endpoints
2-
spring.security.oauth2.resourceserver.jwt.issuer-uri=https://sts.windows.net/@tenant.id@/
3-
spring.security.oauth2.resourceserver.jwt.audiences=api://@client.id@
2+
#spring.security.oauth2.resourceserver.jwt.issuer-uri=https://sts.windows.net/@tenant.id@/
3+
#spring.security.oauth2.resourceserver.jwt.audiences=api://@client.id@,https://apihub.azure.com
4+
5+
spring.cloud.azure.active-directory.enabled=true
6+
spring.cloud.azure.active-directory.credential.client-id=@client.id@
7+
spring.cloud.azure.active-directory.app-id-uri=api://@client.id@

0 commit comments

Comments
 (0)