forked from microsoft/spring-cloud-azure
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates Feature Management Web Demo, Adds App Conversion Demo (micros…
…oft#571) * Updates Feature Management Web Demo, Adds App Conversion Demo
- Loading branch information
Showing
22 changed files
with
956 additions
and
82 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
spring-cloud-azure-samples/azure-appconfiguration-conversion-sample-complete/pom.xml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>spring-cloud-azure-samples</artifactId> | ||
<groupId>com.microsoft.azure</groupId> | ||
<version>1.2.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>spring-cloud-azure-appconfiguration-convert-sample-complete</artifactId> | ||
<name>Azure App Configuration Conversion Sample</name> | ||
<description>Sample project to show conversion to Azure App Configuration</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.microsoft.azure</groupId> | ||
<artifactId>azure-cosmosdb-spring-boot-starter</artifactId> | ||
<version>2.2.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>27.1-jre</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.microsoft.azure</groupId> | ||
<artifactId>spring-cloud-starter-azure-appconfiguration-config</artifactId> | ||
<version>1.1.0.M6</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
77 changes: 77 additions & 0 deletions
77
...ion-conversion-sample-complete/src/main/java/sample/convert/ConvertSampleApplication.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for | ||
* license information. | ||
*/ | ||
package sample.convert; | ||
|
||
import java.util.Optional; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.util.Assert; | ||
|
||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@SpringBootApplication | ||
public class ConvertSampleApplication implements CommandLineRunner { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(ConvertSampleApplication.class); | ||
|
||
@Autowired | ||
private UserRepository repository; | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(ConvertSampleApplication.class, args); | ||
} | ||
|
||
public void run(String... var1) throws Exception { | ||
|
||
final User testUser = new User("testId", "testFirstName", "testLastName", | ||
"test address line one"); | ||
|
||
// Save the User class to Azure CosmosDB database. | ||
final Mono<User> saveUserMono = repository.save(testUser); | ||
|
||
final Flux<User> firstNameUserFlux = repository.findByFirstName("testFirstName"); | ||
|
||
// Nothing happens until we subscribe to these Monos. | ||
// findById will not return the user as user is not present. | ||
final Mono<User> findByIdMono = repository.findById(testUser.getId()); | ||
final User findByIdUser = findByIdMono.block(); | ||
Assert.isNull(findByIdUser, "User must be null"); | ||
|
||
final User savedUser = saveUserMono.block(); | ||
Assert.state(savedUser != null, | ||
"Saved user must not be null"); | ||
Assert.state(savedUser.getFirstName().equals(testUser.getFirstName()), | ||
"Saved user first name doesn't match"); | ||
|
||
firstNameUserFlux.collectList().block(); | ||
|
||
final Optional<User> optionalUserResult = repository.findById(testUser.getId()).blockOptional(); | ||
Assert.isTrue(optionalUserResult.isPresent(), "Cannot find user."); | ||
|
||
final User result = optionalUserResult.get(); | ||
Assert.state(result.getFirstName().equals(testUser.getFirstName()), | ||
"query result firstName doesn't match!"); | ||
Assert.state(result.getLastName().equals(testUser.getLastName()), | ||
"query result lastName doesn't match!"); | ||
|
||
LOGGER.info("findOne in User collection get result: {}", result.getFirstName()); | ||
} | ||
|
||
@PostConstruct | ||
public void setup() { | ||
// For this example, remove all of the existing records. | ||
this.repository.deleteAll().block(); | ||
} | ||
|
||
} |
95 changes: 95 additions & 0 deletions
95
.../azure-appconfiguration-conversion-sample-complete/src/main/java/sample/convert/User.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for | ||
* license information. | ||
*/ | ||
|
||
package sample.convert; | ||
|
||
import org.springframework.data.annotation.Id; | ||
|
||
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.Document; | ||
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.PartitionKey; | ||
|
||
@Document(collection = "mycollection") | ||
public class User { | ||
@Id | ||
private String id; | ||
|
||
private String firstName; | ||
|
||
@PartitionKey | ||
private String lastName; | ||
|
||
private String address; | ||
|
||
public User() {} | ||
|
||
public User(String id, String firstName, String lastName, String address) { | ||
this.id = id; | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
this.address = address; | ||
} | ||
|
||
/** | ||
* @return the id | ||
*/ | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* @param id the id to set | ||
*/ | ||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
/** | ||
* @return the firstName | ||
*/ | ||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
/** | ||
* @param firstName the firstName to set | ||
*/ | ||
public void setFirstName(String firstName) { | ||
this.firstName = firstName; | ||
} | ||
|
||
/** | ||
* @return the lastName | ||
*/ | ||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
/** | ||
* @param lastName the lastName to set | ||
*/ | ||
public void setLastName(String lastName) { | ||
this.lastName = lastName; | ||
} | ||
|
||
/** | ||
* @return the address | ||
*/ | ||
public String getAddress() { | ||
return address; | ||
} | ||
|
||
/** | ||
* @param address the address to set | ||
*/ | ||
public void setAddress(String address) { | ||
this.address = address; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("%s %s, %s", firstName, lastName, address); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...configuration-conversion-sample-complete/src/main/java/sample/convert/UserRepository.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for | ||
* license information. | ||
*/ | ||
|
||
package sample.convert; | ||
|
||
import com.microsoft.azure.spring.data.cosmosdb.repository.ReactiveCosmosRepository; | ||
import org.springframework.stereotype.Repository; | ||
import reactor.core.publisher.Flux; | ||
|
||
@Repository | ||
public interface UserRepository extends ReactiveCosmosRepository<User, String> { | ||
|
||
Flux<User> findByFirstName(String firstName); | ||
} |
1 change: 1 addition & 0 deletions
1
...azure-appconfiguration-conversion-sample-complete/src/main/resources/bootstrap.properties
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
spring.cloud.azure.appconfiguration.stores[0].connection-string=${CONFIG_STORE_CONNECTION_STRING} |
Oops, something went wrong.