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

Story/VOGRE-32 #33

Closed
wants to merge 19 commits into from
Closed

Story/VOGRE-32 #33

wants to merge 19 commits into from

Conversation

rajvi-patel-22
Copy link
Member

@rajvi-patel-22 rajvi-patel-22 commented Dec 16, 2024

Guidelines for Pull Requests

If you haven't yet read our code review guidelines, please do so, You can find them here.

Please confirm the following by adding an x for each item (turn [ ] into [x]).

  • I have removed all code style changes that are not necessary (e.g. changing blanks across the whole file that don’t need to be changed, adding empty lines in parts other than your own code)
  • I am not making any changes to files that don’t have any effect (e.g. imports added that don’t need to be added)
  • I do not have any sysout statements in my code or commented out code that isn’t needed anymore
  • I am not reformatting any files in the wrong format or without cause.
  • I am not changing file encoding or line endings to something else than UTF-8, LF
  • My pull request does not show an insane amount of files being changed although my ticket only requires a few files being changed
  • I have added Javadoc/documentation where appropriate
  • I have added test cases where appropriate
  • I have explained any part of my code/implementation decisions that is not be self-explanatory

Please provide a brief description of your ticket

Workflow

User goes to concept list page

User selects a concept that has not be resolved

If there is a viaf url, Vogon will search Conceptpower for that viaf url and show the result. If there is exactly one result, user should be able to say “approve”, if there are more, user should select one

User should also have the chance to do a conceptpower search for a search term and select one of the results.

If there is no viaf url, user should get a search field to search conceptpower and then be able to select one of the results or do a new search

For all of these options, there should also be a button to create a new concept in conceptpower.

Once a concept has been selected and approved, Vogon concept is RESOLVED

We will likely only have “Pending” and “resolved” as concept states.

... Put ticket description here and add link to ticket ...
https://diging.atlassian.net/browse/VOGRE-32

Are there any other pull requests that this one depends on?

Anything else the reviewer needs to know?

Below bug is fixed along with this PR:

  • Fix this.label for new concept name/label

@diging-jenkins
Copy link
Collaborator

Can one of the admins verify this patch?

response = requests.post(url=url, data=json.dumps(concept_data), auth=auth)

if response.status_code != requests.codes.ok:
raise RuntimeError(response.status_code, response.text)
Copy link
Member

Choose a reason for hiding this comment

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

this should happen in a conceptpower class not directly here.

@@ -230,10 +172,16 @@ def merge_with(self, uri):
children_queryset.update(merged_with=target)

def add(self):

Copy link
Member

Choose a reason for hiding this comment

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

remove empty line

if 'conceptEntries' in data:
for concept_entry in data['conceptEntries']:
concept = self.parse_concept(concept_entry)
concepts.append(concept)
Copy link
Member

Choose a reason for hiding this comment

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

same as above, should not happen in this class

if 'conceptEntries' in data:
for concept_entry in data['conceptEntries']:
concept = self.parse_concept(concept_entry)
concepts.append(concept)
Copy link
Member

Choose a reason for hiding this comment

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

same

data = response.json()
concept_entry = data.get('conceptEntries', [{}])[0]
else:
raise ValueError(f"Error fetching concept data: {response.status_code}")
Copy link
Member

Choose a reason for hiding this comment

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

same, there should be a conceptpower class that does all the communication with conceptpower (isn't there one already?)

@jdamerow jdamerow closed this Dec 19, 2024
@rajvi-patel-22 rajvi-patel-22 mentioned this pull request Jan 3, 2025
9 tasks
@rajvi-patel-22 rajvi-patel-22 reopened this Jan 3, 2025
@rajvi-patel-22 rajvi-patel-22 mentioned this pull request Jan 7, 2025
9 tasks
# Give first priority to the class definition, if endpoint or namespace are defined (and not None).
if self.endpoint is None:
self.endpoint = kwargs.get(
"endpoint", "http://chps.asu.edu/conceptpower/rest/")
Copy link
Member

Choose a reason for hiding this comment

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

these should not be hard-coded; if a default is needed it should come from environment variables/settings.


if self.namespace is None:
self.namespace = kwargs.get(
"namespace", "{http://www.digitalhps.org/}")
Copy link
Member

Choose a reason for hiding this comment

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

same here


response = requests.get(url, headers=headers, params=params)
concepts = []
if response.status_code == 200:
Copy link
Member

Choose a reason for hiding this comment

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

if not, we definitely want to log what else is returned and an error message if there is one.

Copy link
Member

Choose a reason for hiding this comment

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

also, you want to use a constant (requests probably has one) and not a magic number (even though it's an obvious one if you have done web application development before).

url = "{0}Concept?id={1}".format(self.endpoint, uri)
response = requests.get(url, headers=headers)
data = {}
if response.status_code == 200:
Copy link
Member

Choose a reason for hiding this comment

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

same here


def parse_concept(self,concept_entry):
"""
Parse a concept and return a dictionary with the required fields.
Copy link
Member

Choose a reason for hiding this comment

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

needs parameter description (what does this method accept to get in concept_entry? maybe even put in example json (think about what would someone need to know to use this method if they don't see the code)).

@jdamerow jdamerow closed this Jan 8, 2025


class Conceptpower:
# Default behavior is to leave these to the constructor.
Copy link
Member

Choose a reason for hiding this comment

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

what does this mean?

namespace = None

def __init__(self, **kwargs):
# Give first priority to the class definition, if endpoint or namespace are defined (and not None).
Copy link
Member

Choose a reason for hiding this comment

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

what does that mean?

CONCEPTPOWER_ENDPOINT = os.environ.get('CONCEPTPOWER_ENDPOINT')
CONCEPTPOWER_NAMESPACE = os.environ.get('CONCEPTPOWER_NAMESPACE')
CONCEPTPOWER_ENDPOINT = os.environ.get('CONCEPTPOWER_ENDPOINT', 'http://chps.asu.edu/conceptpower/rest/')
CONCEPTPOWER_NAMESPACE = os.environ.get('CONCEPTPOWER_NAMESPACE', '{http://www.digitalhps.org/}')
Copy link
Member

Choose a reason for hiding this comment

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

why is the namespace in curly brackets?

Copy link
Member

Choose a reason for hiding this comment

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

this one is fine, it's just a static github page

@@ -198,8 +198,8 @@

CONCEPTPOWER_USERID = os.environ.get('CONCEPTPOWER_USERID')
CONCEPTPOWER_PASSWORD = os.environ.get('CONCEPTPOWER_PASSWORD')
CONCEPTPOWER_ENDPOINT = os.environ.get('CONCEPTPOWER_ENDPOINT')
CONCEPTPOWER_NAMESPACE = os.environ.get('CONCEPTPOWER_NAMESPACE')
CONCEPTPOWER_ENDPOINT = os.environ.get('CONCEPTPOWER_ENDPOINT', 'http://chps.asu.edu/conceptpower/rest/')
Copy link
Member

Choose a reason for hiding this comment

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

and let's not put that url here. even though it is in the github commit history now, we want to keep bot traffic to our servers as low as possible

@jdamerow jdamerow closed this Jan 24, 2025
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