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

DD-387 Add license entity and api #57

Merged
merged 9 commits into from
Mar 31, 2021
Merged

DD-387 Add license entity and api #57

merged 9 commits into from
Mar 31, 2021

Conversation

JingMa87
Copy link

What this PR does / why we need it: Adds DB table, API and business logic for multiple licenses.

Which issue(s) this PR closes: -

Closes #-

Special notes for your reviewer: -

Suggestions on how to test this: Use postman or curl to GET, POST, PUT and DELETE. Here's an example json you can post:

{
    "name": "Apache License",
    "shortDescription": "License description",
    "uri": "www.apache.com",
    "iconUrl": "www.icon.com",
    "active": false
}

Does this PR introduce a user interface change? If mockups are available, please link/include them here: -

Is there a release notes update needed for this change?: -

Additional documentation: -

@JingMa87 JingMa87 changed the title Add license entity and api DD-387 Add license entity and api Mar 16, 2021
@PaulBoon PaulBoon changed the base branch from develop to multi-license March 17, 2021 11:07
@PaulBoon
Copy link

Just changed the base, original PR was done against the develop branch and it should have been done against the multi-license feature branch

Copy link

@PaulBoon PaulBoon left a comment

Choose a reason for hiding this comment

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

About the API

  • you don't specify an ID, this is 'generated' by the db I guess, or otherwise. The caller of a create /POST does not know this ID and it would be nice to return it in the response for further processing later on by the client.
  • Why not and endpoint with the name as a 'selector', this one is constained unique and the caller knows it when creating, same for URI, but that probably always needs url escaping. So @Path("/licenses/{name}") actually, if you have name as selector, you can do without the ID selector.

.setInfo(name + ": " + shortDescription + ": " + uri + ": " + iconUrl + ": " + active));
return l;
} else {
return null;

Choose a reason for hiding this comment

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

What would cause this to happen, returning null is not very informative. Maybe we could have this throw an exception with some meaningful information

Choose a reason for hiding this comment

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

I agree.

Copy link
Author

@JingMa87 JingMa87 Mar 22, 2021

Choose a reason for hiding this comment

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

That's also how I prefer to do it, but in the dataverse code base you'll see that it's quite common to log some info and return null. I can throw more exceptions but we will be diverting from the dataverse code base.

Choose a reason for hiding this comment

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

There are many things in the Dataverse code base that are suboptimal practises. Let's not adjust to the lowest common denominator so te speak.

@PaulBoon
Copy link

PaulBoon commented Mar 18, 2021

After some discussion it seems best to add @path("/licenses/{name}"), but leave the ones with id 'as-is'.

Copy link

@janvanmansum janvanmansum left a comment

Choose a reason for hiding this comment

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

A good start, following the established patterns of Dataverse.

Points for improvement:

  • The practise of returning null when there is a problem and assuming what the problem was at the calling end is cutting corners a bit too much. See comments in the text.
  • I see you like short variable names. I agree for small scopes such as these. For larger scopes they should be longer. (See Robert C Martin's Clean Code, rule N5: choose long names for long scopes.)
  • Don't use l or O as variable names though. They look too much like 1 and 0 in many fonts.
  • There seems to be no formatting policy in the Dataverse code base, but keep indenting consitent in the sections you edit.

src/main/java/edu/harvard/iq/dataverse/api/Admin.java Outdated Show resolved Hide resolved
scripts/api/data/license.json Outdated Show resolved Hide resolved
scripts/api/data/licenseError.json Outdated Show resolved Hide resolved
.setInfo(name + ": " + shortDescription + ": " + uri + ": " + iconUrl + ": " + active));
return l;
} else {
return null;

Choose a reason for hiding this comment

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

I agree.

src/main/java/edu/harvard/iq/dataverse/api/Admin.java Outdated Show resolved Hide resolved
@JingMa87
Copy link
Author

@janvanmansum I addressed the requested changes, you can test it if you want.

}

public URL getIconUrl() {
return iconUrl;
public URI getIconUrl() throws URISyntaxException {
Copy link

@janvanmansum janvanmansum Mar 30, 2021

Choose a reason for hiding this comment

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

When would this throw a URISyntaxException? And how could this realistically happen?

Copy link
Author

@JingMa87 JingMa87 Mar 30, 2021

Choose a reason for hiding this comment

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

@janvanmansum This would throw a URISyntaxException if the URI String in the DB isn't a valid URI. Realistically this would never happen because a URI can only be inserted or updated in the DB if it's a correct URI object, I tested this. However, if someone directly tampers with the data in the DB, the exception might be thrown. Also, the exception is automatically thrown when trying to form a URI object so it has to be handled.

Choose a reason for hiding this comment

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

As discussed, please wrap in an IllegalStateException. Rationale: the database has been corrupted in some way.

Copy link

@janvanmansum janvanmansum left a comment

Choose a reason for hiding this comment

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

@JingMa87: The specs have not been fully implemented yet. I would like to merge this PR and then see small PRs to fix all the problems and unimplemented parts. Also, let's get rid of Rick Astley references.

I have planned a call for tomorrow to finish up this PR.

@janvanmansum janvanmansum merged commit 4b6c367 into DANS-KNAW:multi-license Mar 31, 2021
PaulBoon pushed a commit to PaulBoon/dataverse that referenced this pull request Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants