File tree Expand file tree Collapse file tree 6 files changed +414
-1
lines changed
java/com/baeldung/gcp/firebase/firestore
test/java/com/baeldung/gcp/firebase/firestore Expand file tree Collapse file tree 6 files changed +414
-1
lines changed Original file line number Diff line number Diff line change 2626 <artifactId >spring-boot-configuration-processor</artifactId >
2727 <optional >true</optional >
2828 </dependency >
29+ <dependency >
30+ <groupId >org.testcontainers</groupId >
31+ <artifactId >gcloud</artifactId >
32+ <scope >test</scope >
33+ </dependency >
34+ <dependency >
35+ <groupId >org.instancio</groupId >
36+ <artifactId >instancio-junit</artifactId >
37+ <version >${instancio.version} </version >
38+ <scope >test</scope >
39+ </dependency >
2940 </dependencies >
3041
3142 <build >
3243 <plugins >
3344 <plugin >
3445 <groupId >org.springframework.boot</groupId >
3546 <artifactId >spring-boot-maven-plugin</artifactId >
47+ <configuration >
48+ <mainClass >com.baeldung.gcp.firebase.firestore.Application</mainClass >
49+ </configuration >
3650 </plugin >
3751 </plugins >
3852 </build >
3953
4054 <properties >
41- <firebase-admin .version>9.1.1</firebase-admin .version>
55+ <java .version>17</java .version>
56+ <firebase-admin .version>9.3.0</firebase-admin .version>
57+ <instancio .version>5.0.1</instancio .version>
4258 </properties >
4359
4460</project >
Original file line number Diff line number Diff line change 1+ package com .baeldung .gcp .firebase .firestore ;
2+
3+ import org .springframework .boot .SpringApplication ;
4+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5+
6+ @ SpringBootApplication
7+ public class Application {
8+
9+ public static void main (String [] args ) {
10+ SpringApplication .run (Application .class , args );
11+ }
12+
13+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .gcp .firebase .firestore ;
2+
3+ import java .io .ByteArrayInputStream ;
4+ import java .io .IOException ;
5+ import java .io .InputStream ;
6+
7+ import org .springframework .beans .factory .annotation .Value ;
8+ import org .springframework .context .annotation .Bean ;
9+ import org .springframework .context .annotation .Configuration ;
10+ import org .springframework .context .annotation .Profile ;
11+ import org .springframework .core .io .Resource ;
12+
13+ import com .google .auth .oauth2 .GoogleCredentials ;
14+ import com .google .cloud .firestore .Firestore ;
15+ import com .google .firebase .FirebaseApp ;
16+ import com .google .firebase .FirebaseOptions ;
17+ import com .google .firebase .cloud .FirestoreClient ;
18+
19+ @ Configuration
20+ @ Profile ("!integration-test" )
21+ public class FirestoreConfiguration {
22+
23+ @ Value ("classpath:/private-key.json" )
24+ private Resource privateKey ;
25+
26+ @ Bean
27+ public Firestore firestore () throws IOException {
28+ InputStream credentials = new ByteArrayInputStream (privateKey .getContentAsByteArray ());
29+ FirebaseOptions firebaseOptions = FirebaseOptions .builder ()
30+ .setCredentials (GoogleCredentials .fromStream (credentials ))
31+ .build ();
32+
33+ FirebaseApp firebaseApp = FirebaseApp .initializeApp (firebaseOptions );
34+ return FirestoreClient .getFirestore (firebaseApp );
35+ }
36+
37+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .gcp .firebase .firestore ;
2+
3+ import java .util .Date ;
4+
5+ public class Task {
6+
7+ public static final String PATH = "tasks" ;
8+
9+ private String title ;
10+
11+ private String description ;
12+
13+ private String status ;
14+
15+ private Date dueDate ;
16+
17+ public String getTitle () {
18+ return title ;
19+ }
20+
21+ public void setTitle (String title ) {
22+ this .title = title ;
23+ }
24+
25+ public String getDescription () {
26+ return description ;
27+ }
28+
29+ public void setDescription (String description ) {
30+ this .description = description ;
31+ }
32+
33+ public String getStatus () {
34+ return status ;
35+ }
36+
37+ public void setStatus (String status ) {
38+ this .status = status ;
39+ }
40+
41+ public Date getDueDate () {
42+ return dueDate ;
43+ }
44+
45+ public void setDueDate (Date dueDate ) {
46+ this .dueDate = dueDate ;
47+ }
48+
49+ }
Original file line number Diff line number Diff line change 1+ {
2+ "type" : " service_account" ,
3+ "project_id" : " <PROJECT_ID>" ,
4+ "private_key_id" : " <PRIVATE_KEY_ID>" ,
5+ "private_key" : " <PRIVATE_KEY>" ,
6+ "client_email" : " <CLIENT_EMAIL>" ,
7+ "client_id" : " <CLIENT_ID>" ,
8+ "client_x509_cert_url" : " <CLIENT_X509_CERT_URL>" ,
9+ "auth_uri" : " https://accounts.google.com/o/oauth2/auth" ,
10+ "token_uri" : " https://oauth2.googleapis.com/token" ,
11+ "auth_provider_x509_cert_url" : " https://www.googleapis.com/oauth2/v1/certs" ,
12+ "universe_domain" : " googleapis.com"
13+ }
You can’t perform that action at this time.
0 commit comments