Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding asMap to ExtensionMetadata Interface #288

Merged

Conversation

evanhalley
Copy link
Contributor

Adding asMap to ExtensionMetadata interface. Implemented asMap in all subclasses.

Fixes #287

Map<String, String[]> map = new HashMap<>();

if (loc != null) {
map.put("loc", new String[]{ loc.toString() });
Copy link
Contributor

Choose a reason for hiding this comment

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

For this, and all other xxxAttributes classes, are there well defined map key name constants we could use?

If not, then I would be in favor of adding them as public constants to the xxxAttribute classes, to avoid raw string constant usage in consumer code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are not constants that I could fine. I'll add some and use those instead of strings.

if (params != null) {

for (Entry<String, String> entry : params.entrySet()) {
map.put(entry.getKey(), new String[] { entry.getValue() });
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we guaranteed that non of these entries has a key = href? I think it would be safer and clearer to make the map key something like params.xxx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call out, it is not a guarantee. I'll prefix these parameters to avoid conflicts and potential overwrites.

@evanhalley
Copy link
Contributor Author

@kkrugler This should be ready for another review. I addressed both points of feedback. Thanks again.

@@ -32,6 +34,10 @@
* you to check for mistakes.</blockquote>
*/
public class LinkAttributes extends ExtensionMetadata {

public static final String HREF = "href";
public static final String PARAMS = "params.%s";
Copy link
Contributor

Choose a reason for hiding this comment

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

My only comment here is that PARAMS is a bit different from the other keys. Not a big deal, but I'd probably call it PARAMS_PREFIX, and make its value just params.

In any case I'd add a comment explaining how it's used for the map key.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thinking about PARAMS_PREFIX a little more, does it make sense to decrease the visiblity? I'm not sure how useful it is outside of the class.

Copy link
Contributor

@kkrugler kkrugler left a comment

Choose a reason for hiding this comment

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

lgtm

adding a comment explaining it's usage
@jnioche jnioche added this to the 1.1 milestone Jun 10, 2020
@jnioche
Copy link
Contributor

jnioche commented Jun 10, 2020

am getting an error when running the tests

_[ERROR] Failures:
[ERROR] SiteMapParserExtensionTest.testNewsSitemap:194 expected: <News name: The Example Times, title: Companies A, B in Merger Talks, language: en, publication-date: 2008-11-23T00:00Z, keywords: business, merger, acquisition, A, B, genres: PressRelease,Blog, keywords: NASDAQ:A, NASDAQ:B> but was: <News name: The Example Times, title: Companies A, B in Merger Talks, language: en, publication-date: 2008-12-23T00:00Z, keywords: business, merger, acquisition, A, B, genres: PressRelease,Blog, keywords: NASDAQ:A, NASDAQ:B>
_

a quick debug shows that the equality of the results being based on identity (==) not equals to.

@evanhalley could you please add a line to CHANGES.txt as part of the PR? Thanks!

@evanhalley
Copy link
Contributor Author

I know what happened with that test failure,

I made the following change:

https://github.com/crawler-commons/crawler-commons/pull/288/files#diff-a388a7c2f0d8025d9383ed21659eaad1R164

I'll fix the unit tests.

@evanhalley
Copy link
Contributor Author

Building on my last response, I reverted my change to NewsAttributes.equals(..) and will open an issue (if one doesn't already exist).

NewsAttributes.equals(..) is executing an Object.equals operation on the same instance of publicationDate instead of comparing it against the NewsAttribute that's publicationDate variable

@jnioche
Copy link
Contributor

jnioche commented Jun 15, 2020

hi @evanhalley, is more work needed on this or is it ready to be merged? It now passes the tests, thanks

@evanhalley
Copy link
Contributor Author

@jnioche this is ready to be merged.

@jnioche jnioche merged commit c04e3f1 into crawler-commons:master Jun 15, 2020
@jnioche
Copy link
Contributor

jnioche commented Jun 15, 2020

thanks again @evanhalley, your contribution is greatly appreciated

jnioche added a commit that referenced this pull request Jun 15, 2020
@evanhalley
Copy link
Contributor Author

@jnioche @kkrugler thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ExtensionMetadata should be able to express itself as a Map
3 participants