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

Search - Adds the ability to search within an LCV and create an Alias without a context #16

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

bayfaub
Copy link

@bayfaub bayfaub commented Dec 6, 2024

How to Test

  1. Upload the ADL language set and ZeroTrust Language sets.
  2. Navigate to http://localhost:8010/uid/search to view the search page.
  3. Verify that searching by Alias, Definition, and Context returns the correct values.
  4. Testing Alias without context: Go to the neoterms page in the admin UI and select "Add neoterm"
  5. Fill in the alias form field and fill in the definition form field with an already existing definition. Leave the context and context description fields blank. Submit the new Alias. You should see a warning that says something to the effect of "creating an alias without a context is not recommended." as well as a message saying that a new term has been created. The message about a new term being created is an error that has been handled by updating Django and Django-neomodel versions in a different branch. Ignore it.
  6. In another tab navigate to http://localhost:7474/ and sign into the neo4j using username: neo4j and password: password
  7. run match(n) return n to view all nodes.
  8. Locate your NeoAlias and verify that it has a relationship with the correct NeoTerm node and doesn't have a relationship to a context.

app/uid/forms.py Outdated
Comment on lines 87 to 102
class AliasForm(forms.Form):
alias = forms.CharField(max_length=255, required=True) # The alias name
context = forms.CharField(max_length=255, required=False) # Context as a string (the term's name)

def save(self):
# Create and save Alias
alias = Alias(alias=self.cleaned_data['alias'], context=self.cleaned_data.get('context'))
alias.save()

# Optionally, if context is provided, link to the NeoTerm
if alias.context:
term = NeoTerm.nodes.get_or_none(name=alias.context)
if term:
alias.link_to_term(term) # Link this alias to the found NeoTerm

return alias
Copy link
Author

Choose a reason for hiding this comment

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

Is there anyway to make this work with NeoAlias?

Comment on lines 30 to 73
class Alias(StructuredNode):
alias = StringProperty(unique_index=True) # The alias name
context = StringProperty(required=False, default=None) # Optional context
points_to = RelationshipTo('NeoTerm', 'POINTS_TO') # The relationship to NeoTerm
context_error = StringProperty(required=False) # Optional field to store error message

def __str__(self):
return self.alias

def link_to_term(self, neo_term):
"""Link this alias to a NeoTerm."""
if isinstance(neo_term, NeoTerm):
self.points_to.connect(neo_term)

def save(self, *args, **kwargs):
"""Override the save method to automatically link the alias to a NeoTerm if context is provided."""
context_error = None # Initialize an error variable

# Call the parent class save method
super(Alias, self).save(*args, **kwargs)

if self.context:
# Get or create the NeoTerm based on the context
term, created = NeoTerm.get_or_create(uid=self.context)
if term:
# Set relationships for the NeoTerm, including the alias
term.set_relationships(definition_node, context_node, self)
else:
context_error = f"No matching NeoTerm found for context: {self.context}"
else:
# If no context is provided, link to a default NeoTerm (first available NeoTerm)
term = NeoTerm.nodes.first() # You can change this to a specific fallback logic
if term:
self.link_to_term(term)
else:
context_error = "No NeoTerm available to link."

# If an error was encountered, raise it so it can be caught in the view or returned to the form
if context_error:
self.context_error = context_error # Store the error message in the instance
self.save()

return context_error # Return the error message, if any

Copy link
Author

Choose a reason for hiding this comment

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

I really like the way you wrote this class. Is there anyway you can make NeoAlias work in a similar way?

EdblackGitHub and others added 6 commits December 10, 2024 13:43
Updated views.py for alias with/without context and using Neoalias. Commend old working code.
Updated Forms.py to include new NeoAlias changes.
Updated models.py to manage the linking NeoAlias, NeoTerm and NeoContext even if context is not provided default to first available NeoTerm. THis is now handled by the addition of the NeoAliasManager class.
@bayfaub bayfaub requested a review from hsmith-adl December 17, 2024 19:46
Copy link

@hsmith-adl hsmith-adl left a comment

Choose a reason for hiding this comment

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

Bay is going to move the search functionality to the Core application from under UID and then merge into main. Search is working, Alias without context is working for existing defintions that have a TermID associated with them. Alias without context on CSV Upload for new defintions still has to be implemented at a later date/

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