Skip to content

Conversation

@weikanglim
Copy link
Contributor

This PR adds SimpleTodo templates for Java AppService and Container Apps. Fixes #415. Note: Java support was added in azd with #773.

Manually tested:

  • azd up, monitor, down commands
  • playwright tests
  • VSCode Debugging experience
  • Remote Containers experience

Thanks @jdubois and @brunoborges for the initial SimpleTodo API implementation.

Copy link
Contributor

@wbreza wbreza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall. I would recommend someone with more Java experience review the Java specific bits.

@weikanglim
Copy link
Contributor Author

@jdubois, @brunoborges, @roryp or @bbenz if any one of you can help sanity check the Java portion of changes to make sure nothing is amiss, that'd be appreciated.

I'm still waiting to get a daily azd build published so that you can run without having to compile a dev build locally. In the meantime, it requires following contributing.md to build an azd locally..

@jdubois
Copy link

jdubois commented Oct 5, 2022

@weikanglim did you copy/paste the Java application I coded about 6 months ago? If that's the case, it should be all good. Maybe we can update it to the latest Spring Boot 2.x release, that shouldn't change anything (and remove a few CVE advisories).

@weikanglim
Copy link
Contributor Author

weikanglim commented Oct 5, 2022

@jdubois That is correct. All the Java code was lifted from your existing implementation. Only slight modifications based on app properties, keyvault and appinsights integration.

Upgraded spring-starter dependency as you suggested.

@jdubois
Copy link

jdubois commented Oct 5, 2022

@weikanglim then that should be all good. I'll have a look to update it to the latest Spring Boot version, but that's not urgent, it's already very recent.

@azure-sdk
Copy link
Collaborator

Repoman Generation Results

Repoman pushed changes to remotes for the following projects:

Project: todo-csharp-cosmos-sql

Remote: azure-samples-staging

Branch: pr/799

You can initialize this project with:

azd init -t Azure-Samples/todo-csharp-cosmos-sql -b pr/799

View Changes | Compare Changes


Project: todo-csharp-sql

Remote: azure-samples-staging

Branch: pr/799

You can initialize this project with:

azd init -t Azure-Samples/todo-csharp-sql -b pr/799

View Changes | Compare Changes


Project: todo-java-mongo-aca

Remote: azure-samples-staging

Branch: pr/799

You can initialize this project with:

azd init -t Azure-Samples/todo-java-mongo-aca -b pr/799

View Changes | Compare Changes


Project: todo-java-mongo

Remote: azure-samples-staging

Branch: pr/799

You can initialize this project with:

azd init -t Azure-Samples/todo-java-mongo -b pr/799

View Changes | Compare Changes


Project: todo-nodejs-mongo-aca

Remote: azure-samples-staging

Branch: pr/799

You can initialize this project with:

azd init -t Azure-Samples/todo-nodejs-mongo-aca -b pr/799

View Changes | Compare Changes


Project: todo-nodejs-mongo-swa-func

Remote: azure-samples-staging

Branch: pr/799

You can initialize this project with:

azd init -t Azure-Samples/todo-nodejs-mongo-swa-func -b pr/799

View Changes | Compare Changes


Project: todo-nodejs-mongo

Remote: azure-samples-staging

Branch: pr/799

You can initialize this project with:

azd init -t Azure-Samples/todo-nodejs-mongo -b pr/799

View Changes | Compare Changes


Project: todo-nodejs-mongo-terraform

Remote: azure-samples-staging

Branch: pr/799

You can initialize this project with:

azd init -t Azure-Samples/todo-nodejs-mongo-terraform -b pr/799

View Changes | Compare Changes


Project: todo-python-mongo-aca

Remote: azure-samples-staging

Branch: pr/799

You can initialize this project with:

azd init -t Azure-Samples/todo-python-mongo-aca -b pr/799

View Changes | Compare Changes


Project: todo-python-mongo-swa-func

Remote: azure-samples-staging

Branch: pr/799

You can initialize this project with:

azd init -t Azure-Samples/todo-python-mongo-swa-func -b pr/799

View Changes | Compare Changes


Project: todo-python-mongo

Remote: azure-samples-staging

Branch: pr/799

You can initialize this project with:

azd init -t Azure-Samples/todo-python-mongo -b pr/799

View Changes | Compare Changes


Project: todo-python-mongo-terraform

Remote: azure-samples-staging

Branch: pr/799

You can initialize this project with:

azd init -t Azure-Samples/todo-python-mongo-terraform -b pr/799

View Changes | Compare Changes


@azure-sdk
Copy link
Collaborator

Azure Dev CLI Install Instructions

Install scripts

MacOS/Linux

May elevate using sudo on some platforms and configurations

bash:

curl -fsSL https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/799/uninstall-azd.sh | bash;
curl -fsSL https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/799/install-azd.sh | bash -s -- --base-url https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/799 --version '' --verbose

pwsh:

Invoke-RestMethod 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/799/uninstall-azd.ps1' -OutFile uninstall-azd.ps1; ./uninstall-azd.ps1
Invoke-RestMethod 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/799/install-azd.ps1' -OutFile install-azd.ps1; ./install-azd.ps1 -BaseUrl 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/799' -Version '' -Verbose

Windows

powershell -c "Set-ExecutionPolicy Bypass Process; irm 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/799/uninstall-azd.ps1' > uninstall-azd.ps1; ./uninstall-azd.ps1;"
powershell -c "Set-ExecutionPolicy Bypass Process; irm 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/799/install-azd.ps1' > install-azd.ps1; ./install-azd.ps1 -BaseUrl 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/799' -Version '' -Verbose;"

Standalone Binary

Container

docker run -it azdevcliextacr.azurecr.io/azure-dev:pr-799

@weikanglim weikanglim merged commit e8b8da3 into Azure:main Oct 5, 2022
@roryp
Copy link

roryp commented Oct 6, 2022 via email

@roryp
Copy link

roryp commented Oct 6, 2022 via email

@roryp
Copy link

roryp commented Oct 6, 2022 via email

@roryp
Copy link

roryp commented Oct 6, 2022 via email

@roryp
Copy link

roryp commented Oct 6, 2022 via email

@roryp
Copy link

roryp commented Oct 6, 2022

I just tested the github actions via a private repo and it works great! When will you publish the live template @weikanglim ?
image

wbreza pushed a commit to wbreza/azure-dev that referenced this pull request Oct 6, 2022
Add SimpleTodo templates for Java AppService and Container Apps

Co-authored-by: @jdubois and @brunoborges
Optional<TodoItem> todoItem = getTodoItem(listId, itemId);
if (todoItem.isPresent()) {
todoItemRepository.deleteById(itemId);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResponseEntity.noContent().build();

Optional<TodoItem> todoItem = getTodoItem(listId, itemId);
if (todoItem.isPresent()) {
todoItemRepository.deleteById(itemId);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResponseEntity.noContent().build()

this.name = name;
}

public TodoItem description(String description) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't usually use both fluent/chainable accessors and getter/setters at the same time.
We suggest to keep only getters/setters because they are more generally used and supported by other tools such as jackson

Objects.equals(this.description, todoItem.description) &&
Objects.equals(this.state, todoItem.state) &&
Objects.equals(this.dueDate, todoItem.dueDate) &&
Objects.equals(this.completedDate, todoItem.completedDate);
Copy link
Contributor

@wangmingliang-ms wangmingliang-ms Nov 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the same Todo item, no matter it is in the initial state, in progress, or done.
that is, I don't think properties like state should be used to implement equals()/hashCode() methods, because state is naturally to be updated for a todo item.
I would suggest keep only listId and id.

TodoList todoList = (TodoList) o;
return Objects.equals(this.id, todoList.id) &&
Objects.equals(this.name, todoList.name) &&
Objects.equals(this.description, todoList.description);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here,

@Override
public ResponseEntity<List<TodoItem>> getItemsByListId(String listId, BigDecimal top, BigDecimal skip) {
if (top == null) {
top = new BigDecimal(20);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use @RequestParam(defaultValue=20) to simplify code here and other.
https://www.baeldung.com/spring-request-param#a-default-value-for-the-request-parameter

public interface TodoItemRepository extends MongoRepository<TodoItem, String> {

@Query("{ 'listId' : ?0 }")
List<TodoItem> findTodoItemsByTodoList(String listId);
Copy link
Contributor

@wangmingliang-ms wangmingliang-ms Nov 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you don't need to add this @Query if this method is renamed as
findTodoItemsBy**ListId**(String listId);, because TodoItem itself has a property named listId, spring-data would generate the query by itself.

public ResponseEntity<TodoList> updateListById(String listId, TodoList todoList) {
return todoListRepository
.findById(listId)
.map(t -> ResponseEntity.ok(todoListRepository.save(t)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be
ResponseEntity.ok(todoListRepository.save(**todoList**)))

otherwise the todolist won't be updated.

Copy link
Contributor

@wangmingliang-ms wangmingliang-ms Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also make sure the listId is set into todoList before saving. a new Todo List would be created after saving if its id is not set.

return todoListRepository
.findById(listId)
.map(t -> ResponseEntity.ok(todoListRepository.save(t)))
.orElseGet(() -> ResponseEntity.badRequest().build());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure, but I think it should return notFound() here.

@JsonCreator
public static TodoState fromValue(String value) {
for (TodoState b : TodoState.values()) {
if (b.value.equals(value)) {
Copy link
Contributor

@wangmingliang-ms wangmingliang-ms Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend to use equalsIgnoreCase() to be more robust.

}

@Override
public ResponseEntity<Void> updateItemsStateByListId(String listId, TodoState state, List<String> requestBody) {
Copy link
Contributor

@wangmingliang-ms wangmingliang-ms Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove param requestBody if not used.

@jdubois
Copy link

jdubois commented Nov 8, 2022

@wangmingliang-ms I agree with your PR review but be careful: many of the issues come because we inherit com.microsoft.azure.simpletodo.api.ListsApi which clearly isn't perfect, but is automatically generated using https://openapi-generator.tech (and to be more specific: their Spring code generator).

As a result, unfortunately some of the methods cannot be changed, as they are inherited from this base class: sometimes that's because our Swagger contract isn't good (I found 3 errors in the contract that way), sometimes it's because OpenAPI doesn't generate perfect code (but we can contribute back to the project and fix it).

@jongio
Copy link
Member

jongio commented Nov 8, 2022

@wangmingliang-ms - Would you like to do a PR for these changes? Thanks! Jon

@wangmingliang-ms
Copy link
Contributor

@wangmingliang-ms - Would you like to do a PR for these changes? Thanks! Jon

sure, I am happy to do that.

@jongio
Copy link
Member

jongio commented Nov 9, 2022

Thanks you!

@wangmingliang-ms
Copy link
Contributor

@wangmingliang-ms - Would you like to do a PR for these changes? Thanks! Jon

Hi, @jongio here is the PR: #1122, it also fixes some other issues in addition to the above.

@weikanglim weikanglim deleted the weilim/java-appservice branch February 28, 2023 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add Java ToDo API

8 participants