Last active
March 12, 2024 02:50
-
-
Save A-pZ/0bc5664a3a1a4fc796f0cd33000f3696 to your computer and use it in GitHub Desktop.
Bulk API 2.0を使ったクエリの登録
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.apz.salesforcesample.repository; | |
import com.github.apz.salesforcesample.config.SalesforceProperties; | |
import com.github.apz.salesforcesample.model.AuthenticationResult; | |
import com.github.apz.salesforcesample.model.Company; | |
import lombok.AllArgsConstructor; | |
import lombok.Getter; | |
import lombok.extern.slf4j.Slf4j; | |
import org.springframework.http.MediaType; | |
import org.springframework.stereotype.Repository; | |
import org.springframework.web.reactive.function.client.WebClient; | |
import reactor.core.publisher.Mono; | |
import java.io.IOException; | |
import java.util.List; | |
@Repository | |
@AllArgsConstructor | |
@Slf4j | |
public class CompanyQueryRepository { | |
SalesforceProperties salesforceProperties; | |
WebClient salesforceWebClient; | |
public String createBulkQuery(AuthenticationResult authenticationResult) { | |
BulkQuery bulkQuery = new BulkQuery("SELECT Id, name, RecordTypeId FROM Account", "query"); | |
String result = salesforceWebClient.post() | |
.uri(salesforceProperties.getApplicationPath()+ "/jobs/query") | |
.header("Authorization", authenticationResult.bearerToken()) | |
.contentType(MediaType.APPLICATION_JSON) | |
.body(Mono.just(bulkQuery), BulkQuery.class).retrieve() | |
.bodyToMono(String.class) | |
.block(); | |
log.info("result: {}", result); | |
return result; | |
} | |
@Getter @AllArgsConstructor | |
public static class BulkQuery { | |
private String query; | |
private String operation; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.apz.salesforcesample.repository | |
import org.springframework.beans.factory.annotation.Autowired | |
import org.springframework.boot.test.context.SpringBootTest | |
import spock.lang.Specification | |
@SpringBootTest | |
class SalesforceBulkQueryJobRegisterTest extends Specification{ | |
@Autowired | |
SalesforceAuthentication authentication | |
@Autowired | |
CompanyQueryRepository repository | |
def "クエリジョブ作成"() { | |
when: | |
def authenticationResult = authentication.authentication() | |
String id = repository.createBulkQuery(authenticationResult) | |
then: | |
noExceptionThrown() | |
id | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INFO 24164 --- [ Test worker] c.g.a.s.r.CompanyQueryRepository : | |
result: { | |
"id":"7500l000008qaGLAAY", | |
"operation":"query", | |
"object":"Account", | |
"createdById":"0050l000007kmChAAI", | |
"createdDate":"2023-08-07T09:08:25.000+0000", | |
"systemModstamp":"2023-08-07T09:08:25.000+0000", | |
"state":"UploadComplete", | |
"concurrencyMode":"Parallel", | |
"contentType":"CSV", | |
"apiVersion":53.0, | |
"lineEnding":"LF", | |
"columnDelimiter":"COMMA" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment