Skip to content

Commit

Permalink
Merge pull request vivo-project#430 from litvinovg/value-set-factory-fix
Browse files Browse the repository at this point in the history
fix: added a check that the data set key is empty to prevent incorrec…
  • Loading branch information
chenejac committed Dec 4, 2023
2 parents 5bc701e + 8349a94 commit 6005bdd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
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);
}
}

0 comments on commit 6005bdd

Please sign in to comment.