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

fix: added a check that the data set key is empty to prevent incorrec… #430

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public AttributeValueKey clone() {
return new AttributeValueKey(ao, aot, role, type);
}

public boolean isEmpty() {
return ao == null && aot == null && role == null && type == null;
}

@Override
public boolean equals(Object object) {
if (!(object instanceof AttributeValueKey)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ValueSetFactory {

public static AttributeValueSet create(String value, QuerySolution qs, AttributeValueKey dataSetKey) {
Optional<String> type = getSetElementsType(qs);
if (!type.isPresent() || dataSetKey == null) {
if (!type.isPresent() || dataSetKey == null || dataSetKey.isEmpty()) {
return new MutableAttributeValueSet(value);
} else {
AttributeValueKey avcKey = getAttributeValueSetKey(dataSetKey, type.get());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package edu.cornell.mannlib.vitro.webapp.auth.attributes;

import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import org.apache.jena.query.QuerySolutionMap;
import org.apache.jena.rdf.model.ResourceFactory;
import org.junit.Test;

public class ValueSetFactoryTest {

@Test
public void testCreate() {
QuerySolutionMap qs = new QuerySolutionMap();
qs.add("setElementsType", ResourceFactory.createPlainLiteral("some type"));
AttributeValueKey key = new AttributeValueKey();
String oldValue = "value";
AttributeValueSet valueSet1 = ValueSetFactory.create(oldValue, qs, key);
assertTrue(valueSet1.contains(oldValue));
String newValue = "new value";
AttributeValueSet valueSet2 = ValueSetFactory.create(newValue, qs, key);
assertNotEquals(valueSet1, valueSet2);
}
}