Skip to content

Commit

Permalink
Fixed dynamic api classes and tests to align with configuration bean …
Browse files Browse the repository at this point in the history
…loader modification
  • Loading branch information
litvinovg committed Mar 21, 2024
1 parent 001b8fe commit 9f0d600
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 39 deletions.
Expand Up @@ -2,8 +2,6 @@

package edu.cornell.mannlib.vitro.webapp.dynapi;

import static edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary.RDF_TYPE;
import static edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoader.toJavaUri;
import static java.lang.String.format;

import java.util.List;
Expand All @@ -17,11 +15,6 @@
import edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoaderException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.NodeIterator;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.rdf.model.Resource;

public abstract class AbstractPool<K, C extends Poolable<K>, P extends Pool<K, C>> implements Pool<K, C> {

Expand Down Expand Up @@ -96,25 +89,20 @@ public void add(String uri, C component) {
.getName(), key, uri));
}

if (isInModel(uri)) {
synchronized (mutex) {
K oldKey = components.putUriMapping(uri, key);
if (oldKey != null && !oldKey.equals(key)) {
C oldComponent = components.get(oldKey);
if (oldComponent != null) {
obsoleteComponents.add(oldComponent);
unloadObsoleteComponents();
}
}
C oldComponent = components.put(key, component);
synchronized (mutex) {
K oldKey = components.putUriMapping(uri, key);
if (oldKey != null && !oldKey.equals(key)) {
C oldComponent = components.get(oldKey);
if (oldComponent != null) {
obsoleteComponents.add(oldComponent);
unloadObsoleteComponents();
}
}
} else {
throw new RuntimeException(format("%s %s with URI %s not found in model. Not adding to pool.", getType()
.getName(), key, uri));
C oldComponent = components.put(key, component);
if (oldComponent != null) {
obsoleteComponents.add(oldComponent);
unloadObsoleteComponents();
}
}
}

Expand Down Expand Up @@ -147,24 +135,6 @@ public void unload() {
}
}

private boolean isInModel(String uri) {
Model dynamicAPIModel = DynapiModelProvider.getInstance().getModel();
Resource s = dynamicAPIModel.getResource(uri);
Property p = dynamicAPIModel.getProperty(RDF_TYPE);

String javaUri = toJavaUri(getType());

NodeIterator nit = dynamicAPIModel.listObjectsOfProperty(s, p);
while (nit.hasNext()) {
RDFNode node = nit.next();
if (node.isResource() && node.toString().replace("#", ".").equals(javaUri)) {
return true;
}
}

return false;
}

public void load(String uri) {
try {
add(uri, loader.loadInstance(uri, getType()));
Expand Down
Expand Up @@ -16,6 +16,7 @@
import edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoaderException;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

public class ProcedurePoolTest extends ServletContextTest {
Expand Down Expand Up @@ -125,6 +126,7 @@ public void testAddHasClient() throws IOException, ConfigurationBeanLoaderExcept
procedureHasClient.removeClient();
}

@Ignore
@Test(expected = RuntimeException.class)
public void testAddWithoutModelLoaded() throws IOException, ConfigurationBeanLoaderException {
ProcedurePool procedurePool = initWithDefaultModel();
Expand Down
Expand Up @@ -17,6 +17,7 @@
import edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoaderException;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

public class ResourceAPIPoolTest extends ServletContextTest {
Expand Down Expand Up @@ -349,6 +350,7 @@ public void testAddHasClient() throws IOException, ConfigurationBeanLoaderExcept
resourceAPIHasClient.removeClient();
}

@Ignore
@Test(expected = RuntimeException.class)
public void testAddWithoutModelLoaded() throws IOException, ConfigurationBeanLoaderException {
ResourceAPIPool resourceAPIPool = initWithDefaultModel();
Expand Down

0 comments on commit 9f0d600

Please sign in to comment.