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

Feat/shacl bnodes #1213

Merged
merged 9 commits into from
Mar 25, 2024
Merged

Feat/shacl bnodes #1213

merged 9 commits into from
Mar 25, 2024

Conversation

pj-cegeka
Copy link
Contributor

No description provided.

Comment on lines 32 to 34
}
@ParameterizedTest
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you format this properly? Now no space between the two methods is provided

Comment on lines 46 to 49
}
}
static class CorrectMemberArgumentsProvider implements ArgumentsProvider {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be formatted as well?

Comment on lines 57 to 60
private static Model readModelFromFile(String fileName) throws URISyntaxException {
ClassLoader classLoader = IncorrectMemberArgumentsProvider.class.getClassLoader();
String uri = Objects.requireNonNull(classLoader.getResource(fileName)).toURI()
.toString();
return RDFDataMgr.loadModel(uri);
}

private static Model readModelFromFileCorrectMember(String fileName) throws URISyntaxException {
ClassLoader classLoader = CorrectMemberArgumentsProvider.class.getClassLoader();
String uri = Objects.requireNonNull(classLoader.getResource(fileName)).toURI()
.toString();
return RDFDataMgr.loadModel(uri);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason why two almost the same methods are provided, but only a different classloader used? Because I think the class loader of the test class itself would work as well. In addition, I think RDFDataMgr.loadModel(fileName) would work fine as well

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have the same remarks here as with the NodesIngestValidatorTest about formatting and the readModel methods

verify(memberIngester, times(1)).ingest(anyString(), any(Model.class));
.andExpect(status().isBadRequest())
.andExpect(content().string(containsString("Member ingested on collection mobility-hindrances should contain the timestamp path: http://www.w3.org/ns/prov#generatedAtTime exactly once.")));
verify(memberIngester, never()).ingest(anyString(), any(Model.class));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you expecting other interactions with this mock? Otherwise, I would propose to use verifyNoInteractions()

}

private void validateModel(Model model, EventStream eventStream) {
Set<Resource> namedSubjects = model.listStatements().mapWith(Statement::getSubject).filterDrop(RDFNode::isAnon).toSet();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could the listStatements().mapWith(..) be replaced with the listSubjects()

Comment on lines 54 to 71
message.append(eventStream.getCollection());
message.append(" should ");
if (eventStream.isVersionCreationEnabled()) {
message.append("not ");
}
message.append("contain ");
if (!conformsTimePath) {
message.append("the timestamp path: ");
message.append(eventStream.getTimestampPath());
}
if (!(conformsTimePath || conformsVersionPath)) {
message.append(" and ");
}
if (!conformsVersionPath) {
message.append("the version of path: ");
message.append(eventStream.getVersionOfPath());
}
message.append(" exactly once.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

.append() can the chained together, so I would propose to chainse all the appends which are directly above/below each other, which would result in less bulky code (in my opinion)

Comment on lines 23 to 24
private final String TIMESTAMP_PATH = "http://purl.org/dc/terms/created";
private final String VERSIONOF_PATH = "http://purl.org/dc/terms/isVersionOf";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you make these variables static please?

Comment on lines 44 to 45
boolean conformsTimePath = model.listStatements(memberSubject, ResourceFactory.createProperty(eventStream.getTimestampPath()), (RDFNode) null).toList().size() == 1 ^ eventStream.isVersionCreationEnabled();
boolean conformsVersionPath = model.listStatements(memberSubject, ResourceFactory.createProperty(eventStream.getVersionOfPath()), (RDFNode) null).toList().size() == 1 ^ eventStream.isVersionCreationEnabled();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not completely correct: namely when a member contains two versionOfPaths when version creation is enabled, the conforms boolean would be true when expecting false

Copy link
Collaborator

Choose a reason for hiding this comment

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

Idem for timestamps

@ParameterizedTest
@ArgumentsSource(IncorrectMemberArgumentsProvider.class)
void when_IncorrectMemberReceived_Then_ValidationThrowsException(Model model, String collectionName) {
assertThrows(IngestValidationException.class, () -> validator.validate(model, collectionName));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can the error message be tested as well, to verify what the validation violation is? This could have detected the mentioned bug above

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I forgot a remark, (I got distracting while reviewing this file), but I do not see the need for using logging when the bean is created (but this could be very valuable when you have something like @ConditionalOn(), which is not the case here). Also, the @Order() annotation works fine as well at the IngestValidator implemenations, so could you drop this class and at the @Component and @Order to the implementation classes?

Comment on lines 4 to 13
private final String message;

public IngestValidationException(String message) {
this.message = message;
}

@Override
public String getMessage() {
return message;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe I should have noticed this earlier, but can you drop the message propery and use super(message) instead?

@Component
@Order(2)
public class MemberIngestValidator implements IngestValidator {
private final List<EventStream> eventstreams = new ArrayList<>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be a set please, as indices are not used and elements are searched by their id/collectionName. Also, as event stream is unique by their id/collectionName, there can be no duplicates present in a set.

Comment on lines +59 to +63
Dataset dataset = RDFParser.source(inputMessage.getBody()).context(rdfModelConverter.getContext()).lang(lang).toDataset();
if (dataset.listModelNames().hasNext()) {
throw new IngestValidationException("Member can not contain named graphs");
}
return dataset.getDefaultModel();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not a big fan of performing validation here, but I don't see where else it could happen (or the request body should be converted to a dataset instead of a model), so I am going to leave it like this for now

Copy link

sonarcloud bot commented Mar 25, 2024

@pj-cegeka pj-cegeka merged commit 2a5431c into develop Mar 25, 2024
3 checks passed
@pj-cegeka pj-cegeka deleted the feat/shacl-bnodes branch March 25, 2024 10:53
@pj-cegeka pj-cegeka restored the feat/shacl-bnodes branch March 25, 2024 12:04
@pj-cegeka pj-cegeka deleted the feat/shacl-bnodes branch March 25, 2024 12:47
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.

2 participants