In the same manner as we've implemented the book:search
command, edit the BookshelfServiceProxy
class and declare the add()
method:
public String add(@Descriptor("username") String username, @Descriptor("password") String password, @Descriptor("ISBN") String isbn, @Descriptor("Title") String title, @Descriptor("Author") String author, @Descriptor("Category") String category, @Descriptor("Rating (0..10)") int rating) throws InvalidCredentialsException, BookAlreadyExistsException, InvalidBookException { BookshelfService service = lookupService(); String sessionId = service.login( username, password.toCharArray()); service.addBook( sessionId, isbn, title, author, category, rating); return isbn; }
This command is named "book:add" and will take the book's ISBN, title, author, category, and rating as arguments, in addition to the authentication user and password. Its implementation is straightforward.
To declare it as part of the exposed functions, we include the method name in the list of functions:
public static final String[] FUNCTIONS = new String[] {
"add", "search"
};
This new command implementation is ready. Since we've used the constant from this class during the service registration, we don't need to make any changes to the activator code.
To test the changes we've made, we'll need to rebuild the following bundles:
bookshelf-service:
Was modified to remove the test call at startup. This will be released with version 1.8.0
bookshelf-service-tui:
To which we've added the book:add
command. This will be released with version 1.8.1
Do you think you can do it on your own? (Hint: this was covered in Chapter 5.)
3.143.239.103