-
Notifications
You must be signed in to change notification settings - Fork 86
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
Audit module (Change Tracking) #390
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
9794e55
merged changeset_user_info
litvinovg edf94db
changed default graph uri
litvinovg 6d7fe36
audit code
litvinovg d8de8ae
Modified audit controller
litvinovg d7c0dc5
Audit controller added user information
litvinovg edeef81
Add listener to RDFService configuration models
litvinovg d44b1f3
added some filters for audit history
litvinovg b93db9e
More filtering options for audit controller
litvinovg 591db33
added user id in audit history table
litvinovg 5aa66e5
Allow only admins to access audit page
litvinovg b92aa85
fix for prev commit
litvinovg 6bc75f7
Set default end date to be the next day to avoid empty results
litvinovg b8b280b
Removed not implemented AuditDaoFS implementation, added tests for Au…
litvinovg 388ae28
added example configuration
litvinovg 29d319a
Fixed some typos
litvinovg 3446c27
Don't show empty changes on audit history page
litvinovg b238eae
fix: release dataset before close
litvinovg 4292ffb
remove empty test file
litvinovg 290373d
chore: fixed formatting
litvinovg 6db6aa7
Don't delete TDB dataset from temporary directory as it results in te…
litvinovg 6060ba8
refactored and improved sparql queries
litvinovg e102dc1
style fixes
litvinovg 1eb38b5
fixes
litvinovg 2d7621e
one more fix
litvinovg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
api/src/main/java/edu/cornell/mannlib/vitro/webapp/audit/AbstractListStatementsMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* $This file is distributed under the terms of the license in LICENSE$ */ | ||
|
||
package edu.cornell.mannlib.vitro.webapp.audit; | ||
|
||
import java.util.List; | ||
|
||
import freemarker.ext.beans.StringModel; | ||
import freemarker.template.SimpleScalar; | ||
import freemarker.template.TemplateMethodModelEx; | ||
import freemarker.template.TemplateModelException; | ||
|
||
/** | ||
* Base helper method for Freemarker | ||
*/ | ||
public abstract class AbstractListStatementsMethod implements TemplateMethodModelEx { | ||
@Override | ||
public Object exec(List arguments) throws TemplateModelException { | ||
// We expect two arguments | ||
// 1 - an AuditChangeSet | ||
// 2 - a graph URI | ||
if (arguments.size() == 2) { | ||
Object arg1 = arguments.get(0); | ||
Object arg2 = arguments.get(1); | ||
|
||
// This looks odd, but the AuditChangeSet is wrapped in a StringModel | ||
if (arg1 instanceof StringModel) { | ||
arg1 = ((StringModel) arg1).getWrappedObject(); | ||
} | ||
|
||
if (arg1 instanceof AuditChangeSet && arg2 instanceof SimpleScalar) { | ||
AuditChangeSet dataset = (AuditChangeSet) arg1; | ||
String graphUri = ((SimpleScalar) arg2).getAsString(); | ||
|
||
// Get the statements from the changeset for the named graph | ||
return getStatements(dataset, graphUri); | ||
} | ||
} | ||
|
||
throw new TemplateModelException("Wrong arguments"); | ||
} | ||
|
||
/** | ||
* Abstract method to be implemented for Added / Removed statements | ||
* | ||
* @param dataset | ||
* @param graphUri | ||
* @return | ||
*/ | ||
protected abstract Object getStatements(AuditChangeSet dataset, String graphUri); | ||
} |
63 changes: 63 additions & 0 deletions
63
api/src/main/java/edu/cornell/mannlib/vitro/webapp/audit/AuditChangeListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* $This file is distributed under the terms of the license in LICENSE$ */ | ||
|
||
package edu.cornell.mannlib.vitro.webapp.audit; | ||
|
||
import edu.cornell.mannlib.vitro.webapp.audit.storage.AuditDAOFactory; | ||
import edu.cornell.mannlib.vitro.webapp.audit.storage.AuditVocabulary; | ||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeListener; | ||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ModelChange; | ||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.jena.rdf.listeners.StatementListener; | ||
import org.apache.jena.rdf.model.Model; | ||
import org.apache.jena.rdf.model.ModelChangedListener; | ||
|
||
/** | ||
* Listener for changes in the RDFService | ||
*/ | ||
public class AuditChangeListener extends StatementListener implements ModelChangedListener, ChangeListener { | ||
private static final Log log = LogFactory.getLog(AuditChangeListener.class); | ||
|
||
@Override | ||
public void notifyModelChange(ModelChange modelChange) { | ||
|
||
// Convert the serialized statements into a Jena Model | ||
Model changes = | ||
RDFServiceUtils.parseModel(modelChange.getSerializedModel(), modelChange.getSerializationFormat()); | ||
|
||
// Get the changeset for the current request | ||
AuditChangeSet auditChangeset = new AuditChangeSet(); | ||
Model additions = auditChangeset.getAddedModel(modelChange.getGraphURI()); | ||
|
||
String userId = modelChange.getUserId(); | ||
if (StringUtils.isBlank(userId)) { | ||
Exception e = new Exception(); | ||
log.debug("User id is not provided.", e); | ||
userId = AuditVocabulary.RESOURCE_UNKNOWN; | ||
} | ||
auditChangeset.setUserId(userId); | ||
|
||
// Is the change adding or removing statements? | ||
if (modelChange.getOperation() == ModelChange.Operation.REMOVE) { | ||
// If we are removing statements, make sure we don't retain them in the additions | ||
additions.remove(changes); | ||
|
||
// Record all of the changes in the Model of removed statements | ||
Model removed = auditChangeset.getRemovedModel(modelChange.getGraphURI()); | ||
removed.add(changes); | ||
} else { | ||
// Record all of the changes in the Model of added statements | ||
additions.add(changes); | ||
} | ||
if (!auditChangeset.isEmpty()) { | ||
// Write the changes to the audit store | ||
AuditDAOFactory.getAuditDAO().write(auditChangeset); | ||
} | ||
} | ||
|
||
@Override | ||
public void notifyEvent(String graphURI, Object event) { | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to require a null check.
A Freemarker SimpleMethodModel
https://github.com/litvinovg/Vitro/blob/c0b48511e2b7b4446b90a4096ed19de3bae6d7bd/api/src/main/java/freemarker/ext/dump/BaseDumpDirective.java#L433C25-L433C43 calling with null. May be a red herring.
However, the API does not indicate the argument to be non-null.
https://freemarker.apache.org/docs/api/freemarker/ext/beans/SimpleMethodModel.html#exec-java.util.List-