From Reactive Programming to Your Legacy
You walk through the memory corridor. That's what it's called. Before now, you didn't know anything about this place. A lot of times in the past, unconsciously, you wandered here, peeking a piece of someone's memory. Sometimes it's a beautiful memory. Sometimes it's painful.
Nevertheless, you always adore those memories. They give you meaning and strength. Although you don't understand why you have been given this kind of authority. Maybe so you can try to understand your co-worker. However, something is missing. Why didn't you get the chance to know your own past? As if your knowledge of your past is stopped the day you were transferred to this world. After knowing what happens with your co-worker, you feel something similar may have to you. That question is yet to have an answer.
That night you see Rory, your division manager, alone in her office. It isn't the most beautiful of nights. When you look through the window, all you can see is the pitch-black sky covered by heavy rain. The strong wind knocking on everything in their path accompanied by thunderstorms are the only things you can hear besides. You can easily guess that poor Rory is trapped just like you here. However, Rory doesn't seem to be working or resting in her office. Instead, she looks at the night sky, almost like praying. After a good look, you realize it is not a hopeful prayer. She is definitely scared of something. Her whole body is trembling. Rory holds her necklace still and, a few times, looks at the picture in it. After doing so, she seems more relieved. It was nearly 10 years ago when everything began and ended for Rory, in the middle of the night of a heavy storm.
Stella, The City of The Stars
She was in a hurry to meet with her client, an important figure from Stella. The great city of Stella was the centre of the population. Many problems led to a need for a system to manage many aspects of the town. However, the resources were so limited as the effect of the great war. Rory and her team were the only developers available right now. The condition couldn't be any worse as the weather in Stella wasn't stable either. The heavy rain in the middle of the storm wasn't helping her at all. After all Rory's effort, she still arrived late at the meeting.
"You are late.."
A man in his thirties did not seem impressed. The meeting hadn't started yet, but Eddie still scolded his late co-worker. The government of Stella usually came late to a meeting, so late for some minutes should still do it. But, this man, Eddie, really didn't like the indiscipline act.
"I am sorry. "Rory simply apologized and did not try to argue with her co-worker. She didn't want to make any more trouble after the fuss of her late arrival. Rory then sat silently beside Eddie.
The whole meeting went on without a hitch. The pair then spent some minutes in the meeting room to discuss.
"Property management, huh?" That was the first thing that came out of Eddie's mouth after the meeting.
Stella's government does not have control over many resources. It is mainly because Stella is a city of travellers in the first place. It does not have a native tribe. However, their position is strategic, perfect for trading routes. So the Stella government saw this as an opportunity. They offer residency to outsiders that want to conduct business in Stella. They gain access to many properties that the government sells by applying for residency. Buildings are essential for trading. So this is its main business of Stella.
"Stella's primary business is trading, after all. It's what makes money. So what we want to create here is a system to automate that business process. "Rory replied. Her eyes wandered to Eddie's screen. He's already made some designs of the system. "This is..?"
"My initial system. I guess. "
"Can you explain? "
"Sure! Generally, there are three entities in the system. Proprietor, Property, and License. The Proprietor could be a resident or a guild. Every Proprietor could own 0 or more properties. So, a traveller who wants to buy or rent a property in Stella has to be a resident or affiliated with a guild first. Every property has its own License. Whether it is for occupancy or business. I also have a document of the data design in that suitcase."
"Is that the document Stella's representative gave during the meeting? "
Eddie nodded. "They have created the base endpoints and models for Proprietor. Our task is to complete the remaining two models: Property and License. We will need to create an API for Create, Update, and Read. We won't need DELETE endpoints. You can only update the property owner id field when you update a Property. The License doesn't have an UPDATE endpoint. Add License should be done via property/add-license
, assigning them to a property."
Rory checked the codebase mentioned by Eddie. The codebase was basically a bit familiar, but at the same time, it didn't. "Reactive style.." she mumbled.
"Yeah, it makes us need to use different styles in the development. "
" The Flux
and Mono
? " Rory asked.
"Yeah. Are you familiar with these two? "
Rory only froze in her place for seconds before Eddie understood that his colleague was broken.
" So you didn't know..."
"Yeah. I have never had the experience with web flux after all. "
Eddie sighed. Not so surprising, really. He had expected that but was still disappointed.
" In Reactive style, we do not return an ordinary model or DTO (Data Transfer Object Directly) directly; instead, we return Mono
and Flux
, as you can see. Mono is used when we return a single object, like in getObjectById
or objects returned by CREATE
, UPDATE
, or DELETE
endpoints. Flux is used when we have a stream of objects or a list of objects."
" Ah, I see. "
" Okay, I think we can start to work on the application. Can you help me complete the rest of the application? "
"Sure."
"But, We must hurry up. "Eddie looked outside the window. The storm was getting worse. The face of Eddie and Rory were definitely hopeless. They didn't have the time or the resources to complete the system. "I don't want to stay here for so long. "
"What do you mean? "
"Soon, this city will be destroyed. "
Those are the last words Rory heard from Eddie before her friend went entirely quiet. As she had no other choice, she proceeded to help her colleagues without asking any more questions.
The Requirements Documents and Guidelines
This section is listing all the models you need to create to complete the application. You need to convert the definition to Spring Data Entities first. For instance, BigInt can be translated into Long in the model definition.
Data Definition
- Property
1 2 3 4 5 6
Property id - Big Int - Auto Generated - Primary Key Property Name - Varchar(100) - Not Null Property Type - Varchar (100) - Not Null Description - Text - Not Null Property owner id - Big Int - Nullable Property Base price - Int - Not Null
- License
1 2 3 4 5
License Id - Big Int - Auto Generated - Primary Key IssuedDate - Date - Not Null - Auto Generated - Now validUntil - Date - Not Null Description - text - Not Null property id - Not Null
Read the section above. There are rules you need to follow. Please read it carefully. The application in this practical is in the form of REST Web Service. You can use Postman to assist you doing this practical. You may try to run the application first and access some endpoints provided by Master Robert.
Sample Request to list all Proprietor
Target: http://localhost:8080/proprietor/find-all
Method: Get
Sample Request to create new Resident
Target http://localhost:8080/proprietor/resident/create
Method: Post
Sample Request Body
1 2 3 4 5 6 7 8 |
|
You need to create the Reactive endpoints for the other two entities. Please read carefully the previous section to understand the whole requirements.
Postman
After you analyze the requirements for this particular problem, you realize that you will be using REST API, which means you can't just testing the program's functionality by usual means (such as accessing it on HTML page rendered by browser). This means you need to use another tool for testing the program's functionality. Postman is one of those tools.
Motivation
Contrary to what many programmers in this world think, there are many HTTP Request Methods other than GET
and POST
(the prominent examples are : PUT
, PATCH
, and DELETE
). Unfortunately, requests that use those methods can't be sent by HTML pages rendered by browsers, since HTML only supports GET
and POST
methods.
Postman, unlike HTML, can send such requests. In fact, one of its common uses is to deliver HTTP Request directly to the web services or web applications.
Installation
It's preferable to install Postman in your own computer instead of relying on its web version. As such, you must download the application here.
Creating and Sending Request
As it's stated earlier, one of Postman's common uses is to create HTTP Request and send it directly to the web services or web application.
First, open the Postman application. You will see the program like this:
At the right side of the app, there is a form to create request
To create a request, you must enter the URL of the web service/application alongside its endpoint you want to access.
After that, you need to specify what method to use for that particular request. Just click one of the options you want to choose.
If the endpoint requires you to include information (for example, you need to add data into the service), include said information into the request. You can do it by using request parameters or RequestBody. This tutorial will show you how to include that information using RequestBody written in JSON.
First, to include JSON data into the request body, select "Body" from this particular part of the app:
Next, select the option "raw" from the radio button option and select "JSON" from the dropdown option:
After that, you can write the JSON data you want to include.
After you make such a request, send it by pressing the "Send" button and then wait for Postman to deliver the response.
Examples : These examples will be using this web service that has been used earlier in Practice-6.
This example will show how to access endpoints that need no additional information other than endpoints and the request method alongside its response.
This example will show you how to access endpoints that need some additional information alongside its response.
Notes : While in this example the response is written in JSON, it's not always the case with other web services/applications. Response by the service/application can be written using formats such as JSON, XML, HTML, and no format, in a very rare case.
Creating Collection
Sometimes you need to write your already-given-response request in a separate files, programs, or other things so you can execute it again later for testing some functionality after other request (or perhaps because you forgot to execute one before). You can do it by using one Postman tab by changing the request method, the endpoint, the data inside the request body, and many other things whenever you want to execute different requests. Keeping requests and executing it this way, however, is not very time-efficient. Fortunately, Postman has a feature called Collection.
Collection is a feature in Postman that can be used to store multiple requests that can be executed later. While technically it can be used to store requests regardless of what web service/application of the requests's destination, most of the time, a collection is only used for storing requests from one web service/application. This tutorial will show how to make a collection and use it to store requests.
First, in the left side of the application, you will see the app like this:
Click the "Create Collection" hyperlink and you will see something like this:
For this tutorial, just rename the collection into something else and let other things unchanged.
You can add request to the collection by right-clicking the collection's row bar and left-clicking the "Add Request option"
After you choose to add a request, you can make requests in the same way as explained in the previous section. However, requests stored inside a collection can have a name to differentiate it from other requests.
Just as it's stated earlier, Collection can be used to store requests to be executed later. Those stored requests can be found at the left panel of the Postman application.
You can access the request by left-clicking it and Postman will open a new Postman tab for that request. In that tab, you can modify the request and send the request to the destination just like usual.
Rory Auden
That job was Eddie and Rory's last. Both of them had wandered around the great land of Gothia for years. Doing jobs here and there. While both of them were programmers, they were really adventurers at heart. The wheel of fate had them come to the great city of Stella. Something that they may have regretted. Stella was in a great war. When you play with fire, you should be ready to get burned. An attack from the enemies would come soon enough. That was something they knew they would face. However, they had no money, so this was their only choice.
The storm was one thing; the attack of a nearby kingdom had them scattered. It was too late by the time Eddie and Rory finished the job. In the middle of a great storm, that night Stella was attacked. Both Eddie and Rory were running for their life. They didn't know where to go. Should they have stayed and gotten destroyed by the storm? Or run and get murdered by the attacker. In that condition, they were separated after the eye of the storm enveloped city. Rory was unconscious for hours after being knocked by the strong wind.
The first thing she thought after she awoke was Eddie. She could barely stand and yet still forced her way to find her one and only colleague. She tried to run. Only the debris of the formerly great city was present. She ignored the already destroyed city and thought positively, hoping that Eddie was still alive.
" Eddie! Where are you?" She screamed. Her steps were shaking. She could barely stand and was in grave danger herself. But the only thing on her mind was Eddie. Since the beginning of her journey with no goal, what she had was Eddie. Of course, Eddie was everything for Rory.
" Eddie..." She cried but was still hopeful. Maybe you couldn't say that either. She was desperate but denied everything that might come to her mind. Her body was fragile at the time, but she still forced her way. After hours of searching, she found nothing. She finally collapsed. Her body couldn't take it anymore. But just before she lost consciousness, she found Eddie's necklace. With the last of her strength, she reached out to the necklace.
Years after that, she never knew Eddie's whereabouts. Rory didn't even know whether her partner was still alive or not. Rory's biggest regret is that she didn't get to know Eddie more. The only thing she knew was Eddie came from another world. At the beginning of her journey, she met Eddie. He taught her all the programming knowledge, and they decided to go on an adventure together. Strange at is was, as a wandering programmer. But now, she was alone.
She continued the job as a programmer and found some other people she could call friends. They made a company together. At first, she was only doing jobs blindly. After all, she didn't have any dreams anymore. However, one day, she found there were other people transported from another world. She met Maya, who cried and tried to find someone at that time. Sadly enough, Maya didn't retain her memory of the past and didn't even know the said person's name. She felt looking at her past self when she looked at Maya. Rory couldn't leave her. So Rory took Maya as her stepsister and taught her programming. She then had a new goal. To find and help other people that came from another world. She didn't know why but she felt it was Eddie's legacy. So she gathered them in her company.
"Miss Rory, are you not going home? " You asked after a couple of minutes. Rory appears lost in her thoughts. She doesn't respond and freezes for some seconds and then suddenly laughs.
" Yes, I will," she replied.
Rory then looks at the night sky once again. She is glad that Maya finally found the person she sought years ago. And in her silence, Rory continues to help the people from the other world. So she can prevent the same tragedy happen to them. Before leaving her room, she once again looks like she is praying.
" Are you happy over there, Eddie? "
Checklist
You will need to implement the task using REST Controller and Reactive Web Service. Please follow the structure of the MVC Design Pattern as well. You can use the current project structure or previous practicals as reference to implement the solution.
Checklist
- Read Stella, The City of The Stars, write the requirements (restriction, todo etc) you found in
README.md
- Read The Requirements document and Guidelines section.
- Implement endpoints for Property and License. Please refer to the Stella Property Management Section.
- Test your implementation using postman or similar tools. Read the postman section for more details about Postman
- Create
gitlab-ci.yml
Minimun create: build and test job
Hint
- The basic information you need is in the The Requirements Document and Guidelines
section. Read it first.
- Try to run the application first.
- Don’t forget to change the application.properties
to match your local configuration.
Created: 2022-05-18 17:02:16