"Hello, soldier!"
"Congratulations on upgrading your skills. We need guys who are prepared to do anything."
"I'm sure you still have many unfinished tasks. It's time to finish some of them!"
10
Task
Java Collections,
level 8,
lesson 15
Locked
Aggregator (part 1)
It's time to work with information from the Internet a little. In this task, you'll be writing an aggregator for Java job posting.
What do we need?
There should be a list of websites we are searching for jobs.
First, we'll use https://www.linkedin.com/jobs/. We'll add other job search sites later.
18
Task
Java Collections,
level 8,
lesson 15
Locked
Aggregator (part 2)
1. Create a Controller class which will contain business logic.
2. Add a public constructor to Controller. It should accept as many providers as are passed to it.
Save them to a private providers field.
Do you remember how to do that?
18
Task
Java Collections,
level 8,
lesson 15
Locked
Aggregator (part 3)
Starting in this task, you will begin writing the logic for fetching data from a website.
This logic will be contained entirely in the classes that implement Strategy.
Speaking in terms of the Strategy pattern, the provider acts as the context.
18
Task
Java Collections,
level 8,
lesson 15
Locked
Aggregator (part 4)
Open the Linkedin website (https://www.linkedin.com/jobs/)
Type "Java San Francisco" in the search bar. At the bottom, navigate to the second page, since URLs often differ between the first and subsequent pages.
18
Task
Java Collections,
level 8,
lesson 15
Locked
Aggregator (part 5)
1. Add a getJobPostings(String searchString) method to the interface. It will return a list of job postings.
2. Correct the errors in the LinkedinStrategy class.
3. Return to the Provider class's getJavaJobPostings method. Implement it assuming that all the data is adequate.
36
Task
Java Collections,
level 8,
lesson 15
Locked
Aggregator (part 6)
1. On the left in the Project panel, find "External Libraries" at the bottom. Find the examples package in jsoup, and look at the classes in this package.
2. Similar to the implementations in the jsoup examples, connect to the Linkedin URL using the GET method.
18
Task
Java Collections,
level 8,
lesson 15
Locked
Aggregator (part 7)
To let Linkedin know who's connecting to it, we'll add Request Headers to our request.
There are developer tools that show various information about requests.
I'll tell you about two tools.
***Chrome****
1. In the Chrome browser, go to Menu -> Tools -> Developer Tools, or press Ctrl+Shift+I.
36
Task
Java Collections,
level 8,
lesson 15
Locked
Aggregator (part 8)
Run the program in debug mode again.
Copy the value of document.html() into the HTML file we created earlier.
Format it and find the tags with job postings.
Read additional lesson material about attribute selectors in the Community.
PLEASE NOTE THIS SPECIAL RULE FOR TESTING THIS TASK!
18
Task
Java Collections,
level 8,
lesson 15
Locked
Aggregator (part 9)
It's time to refactor the code a little.
Read about the Model-View-Controller (MVC) pattern on the Internet.
In short, the user uses the view to generate events that are processed by the controller.
The controller decides what data it needs, and accesses the correct model.
18
Task
Java Collections,
level 8,
lesson 15
Locked
Aggregator (part 10)
View has an update method. The list of job postings is passed to it to be displayed.
Obviously, only the model will call this method, since only the model gets the data.
It's time to create the model.
1. Create a Model class in the model package.
10
Task
Java Collections,
level 8,
lesson 15
Locked
Aggregator (part 11)
Model has a selectCity method to which the name of the city for the job search is passed.
Obviously, this method will be called by the controller, since it decides which model to use.
1. Add a new Model model field to the Controller.
10
Task
Java Collections,
level 8,
lesson 15
Locked
Aggregator (part 12)
To run the application, you need to emulate a user event:
1. In the HtmlView class, create a public void emulateCitySelection() method.
Let this method call the controller using the city "Odessa".
18
Task
Java Collections,
level 8,
lesson 15
Locked
Aggregator (part 13)
Check it out — there are two new files in the view package:
jobPostings.html (you will write data here),
backup.html (a copy of jobPostings.html for data recovery if the data in jobPostings.html is erased somehow).
Hover over and right-click jobPostings.html in the project tree on the left.
18
Task
Java Collections,
level 8,
lesson 15
Locked
Aggregator (part 14)
There are still two empty methods in the HtmlView class.
In this task, I'll describe what the updateFile method should do. And I'll also tell you how to debug it.
It accepts the file's body as a String. You need to write it to the file located at the filePath path.
36
Task
Java Collections,
level 8,
lesson 15
Locked
Aggregator (part 15)
In the HtmlView class, only the getUpdatedFileContents method is still empty. In this task, I'll describe what it should do.
1. In HtmlView, create a protected Document getDocument() throws IOException method that
parses the jobPostings.html file using jsoup. The file's encoding is UTF-8.
36
Task
Java Collections,
level 8,
lesson 15
Locked
Aggregator (part 16)
You are doing great! You've done a lot of work! Now it will be easy for you to monitor job vacancies :)
Aggregator currently uses only one strategy for collecting job postings (from Linkedin).
1. Add a strategy for Indeed by analogy with LinkedinStrategy.
10
Task
Java Collections,
level 8,
lesson 15
Locked
Aggregator (part 17)
Stuff you can do on your own (we won't test you on any of these items):
1. Add a bazillion other job sites for aggregating job postings.
You just need to create a strategy, and then add a provider for that strategy to the model.
2. Sort all of the job postings.
GO TO FULL VERSION