Search in sources :

Example 6 with Shacl2JavaInstanceFactory

use of won.shacl2java.Shacl2JavaInstanceFactory in project webofneeds by researchstudio-sat.

the class InstantiationTest method test_basic_005.

@Test
public void test_basic_005() throws IOException {
    Shapes shapes = loadShapes(shapesDef);
    Shacl2JavaInstanceFactory factory = new Shacl2JavaInstanceFactory(shapes, "won.auth.model");
    Graph data = loadGraph(loader.getResource("classpath:/won/basic/basic-005.ttl"));
    Shacl2JavaInstanceFactory.Accessor accessor = factory.accessor(new Union(shapes.getGraph(), data));
    logger.debug("done instantiating");
    Assert.assertEquals(3, accessor.size());
}
Also used : Graph(org.apache.jena.graph.Graph) Shapes(org.apache.jena.shacl.Shapes) Union(org.apache.jena.graph.compose.Union) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) Test(org.junit.Test)

Example 7 with Shacl2JavaInstanceFactory

use of won.shacl2java.Shacl2JavaInstanceFactory in project webofneeds by researchstudio-sat.

the class AclTests method testModifyOnBehalf.

@Test(timeout = 60 * 1000)
public void testModifyOnBehalf() throws Exception {
    final AtomicBoolean atom1Created = new AtomicBoolean(false);
    final AtomicBoolean atom2Created = new AtomicBoolean(false);
    final CountDownLatch latch = new CountDownLatch(2);
    final AtomicReference<URI> createMessageUri1 = new AtomicReference();
    final AtomicReference<URI> createMessageUri2 = new AtomicReference();
    runTest(ctx -> {
        EventBus bus = ctx.getEventBus();
        final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
        final URI atomUri1 = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
        final URI atomUri2 = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
        BotBehaviour bbAtom1 = new BotBehaviour(ctx) {

            @Override
            protected void onActivate(Optional<Object> message) {
                final String atomUriString = atomUri1.toString();
                final AtomContent atomContent = AtomContent.builder(atomUriString).addTitle("Granting atom").addSocket(Socket.builder(atomUriString + "#chatSocket").setSocketDefinition(WXCHAT.ChatSocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
                Authorization auth = Authorization.builder().addGranteesAtomExpression(ae -> ae.addAtomsURI(atomUri2)).addGrant(ase -> ase.addOperationsSimpleOperationExpression(OP_READ).addGraph(g -> g.addGraphType(GraphType.CONTENT_GRAPH).addOperationsMessageOperationExpression(moe -> moe.addMessageOnBehalfsMessageType(MessageType.REPLACE_MESSAGE)))).build();
                WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri1).content().graph("#content", RdfOutput.toGraph(atomContent)).content().aclGraph(won.auth.model.RdfOutput.toGraph(auth)).build();
                createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
                ctx.getBotContextWrapper().rememberAtomUri(atomUri1);
                final String action = "Create granting atom";
                EventListener successCallback = event -> {
                    logger.debug("Granting atom created");
                    createMessageUri1.set(((SuccessResponseEvent) event).getOriginalMessageURI());
                    deactivate();
                };
                EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, action);
                EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
                ctx.getWonMessageSender().sendMessage(createMessage);
            }
        };
        BotBehaviour bbAtom2 = new BotBehaviour(ctx) {

            @Override
            protected void onActivate(Optional<Object> message) {
                final String atomUriString = atomUri2.toString();
                final AtomContent atomContent = AtomContent.builder(atomUriString).addTitle("Grantee atom").addSocket(Socket.builder(atomUriString + "#chatSocket").setSocketDefinition(WXCHAT.ChatSocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
                WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri2).content().graph(RdfOutput.toGraph(atomContent)).content().aclGraph(won.auth.model.RdfOutput.toGraph(getNobodyMayDoNothing())).build();
                createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
                ctx.getBotContextWrapper().rememberAtomUri(atomUri2);
                final String action = "Create grantee atom";
                EventListener successCallback = event -> {
                    logger.debug("Grantee atom created");
                    createMessageUri2.set(((SuccessResponseEvent) event).getOriginalMessageURI());
                    deactivate();
                };
                EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, action);
                EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
                ctx.getWonMessageSender().sendMessage(createMessage);
            }
        };
        BotBehaviour bbReplaceAtom1FromAtom2 = new BotBehaviour(ctx) {

            @Override
            protected void onActivate(Optional<Object> message) {
                WonMessage replaceMessage = WonMessageBuilder.replace().atom(atomUri1).content().graph("#content", RdfOutput.toGraph(AtomContent.builder(atomUri1).addTitle("Replaced Title").addTag("A-New-Tag").addType(URI.create(WON.Atom.getURI())).addType(URI.create(WON.Persona.getURI())).addSocket(Socket.builder(atomUri1.toString() + "#buddySocket").setSocketDefinition(WXBUDDY.BuddySocket.asURI()).build()).addSocket(Socket.builder(atomUri1.toString() + "#holderSocket").setSocketDefinition(WXHOLD.HolderSocket.asURI()).build()).build())).build();
                String action = "replace content of atom1 using webid of atom2";
                EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, action);
                replaceMessage = ctx.getWonMessageSender().prepareMessageOnBehalf(replaceMessage, atomUri2);
                EventListener successCallback = makeLoggingCallback(bot, bus, action, () -> deactivate());
                EventBotActionUtils.makeAndSubscribeResponseListener(replaceMessage, successCallback, failureCallback, ctx);
                ctx.getWonMessageSender().sendMessage(replaceMessage);
            }
        };
        BotBehaviour readModified = new BotBehaviour(ctx) {

            @Override
            protected void onActivate(Optional<Object> message) {
                Dataset atomData = ctx.getLinkedDataSource().getDataForResource(atomUri1, atomUri1);
                Set<String> expectedGraphNames = Set.of(atomUri1 + "#acl", atomUri1 + "#acl-sig", atomUri1 + "#socket-acl", atomUri1 + "#content", atomUri1 + "#content-sig", atomUri1 + "#key", atomUri1 + "#key-sig", atomUri1 + "#sysinfo");
                Iterator<String> it = atomData.listNames();
                Set<String> actualNames = new HashSet<>();
                while (it.hasNext()) {
                    actualNames.add(it.next());
                }
                Assert.assertEquals(expectedGraphNames, actualNames);
                Shacl2JavaInstanceFactory instanceFactory = ContentUtils.newInstanceFactory();
                Shacl2JavaInstanceFactory.Accessor accessor = instanceFactory.accessor(atomData.getNamedModel(atomUri1 + "#content").getGraph());
                Optional<AtomContent> atomContent = accessor.getInstanceOfType(atomUri1.toString(), AtomContent.class);
                Assert.assertTrue("replacing content failed: replaced title not found", atomContent.get().getTitles().contains("Replaced Title"));
                Assert.assertFalse("replacing content failed: old title still there", atomContent.get().getTitles().contains("Granting atom"));
                passTest(bus);
            }
        };
        BehaviourBarrier barrier = new BehaviourBarrier(ctx);
        barrier.waitFor(bbAtom1, bbAtom2);
        barrier.thenStart(bbReplaceAtom1FromAtom2);
        barrier.activate();
        bbAtom1.activate();
        bbAtom2.activate();
        bbReplaceAtom1FromAtom2.onDeactivateActivate(readModified);
        logger.debug("Finished initializing test 'testQueryBasedMatch()'");
    });
}
Also used : EventBotAction(won.bot.framework.eventbot.action.EventBotAction) SuccessResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.SuccessResponseEvent) LoggerFactory(org.slf4j.LoggerFactory) won.auth.model(won.auth.model) EventBus(won.bot.framework.eventbot.bus.EventBus) CachingLinkedDataSource(won.protocol.util.linkeddata.CachingLinkedDataSource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConnectFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherAtomEvent) BehaviourBarrier(won.bot.framework.eventbot.behaviour.BehaviourBarrier) ContentUtils(won.utils.content.ContentUtils) AtomicReference(java.util.concurrent.atomic.AtomicReference) WonMessage(won.protocol.message.WonMessage) HashSet(java.util.HashSet) WonMessageBuilder(won.protocol.message.builder.WonMessageBuilder) MessageFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.MessageFromOtherAtomEvent) ActionOnceAfterNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) Individuals(won.auth.model.Individuals) URI(java.net.URI) Dataset(org.apache.jena.query.Dataset) Socket(won.utils.content.model.Socket) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) BotBehaviour(won.bot.framework.eventbot.behaviour.BotBehaviour) MethodHandles(java.lang.invoke.MethodHandles) RdfOutput(won.utils.content.model.RdfOutput) Set(java.util.Set) Test(org.junit.Test) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) EventBotActionUtils(won.bot.framework.eventbot.action.EventBotActionUtils) LinkedDataFetchingException(won.protocol.rest.LinkedDataFetchingException) AtomContent(won.utils.content.model.AtomContent) AuthEnabledLinkedDataSource(won.auth.linkeddata.AuthEnabledLinkedDataSource) CountDownLatch(java.util.concurrent.CountDownLatch) Event(won.bot.framework.eventbot.event.Event) won.protocol.vocabulary(won.protocol.vocabulary) Optional(java.util.Optional) EventFilter(won.bot.framework.eventbot.filter.EventFilter) EventListener(won.bot.framework.eventbot.listener.EventListener) Assert(org.junit.Assert) GraphFactory(org.apache.jena.sparql.graph.GraphFactory) BotBehaviour(won.bot.framework.eventbot.behaviour.BotBehaviour) SuccessResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.SuccessResponseEvent) Optional(java.util.Optional) Dataset(org.apache.jena.query.Dataset) BehaviourBarrier(won.bot.framework.eventbot.behaviour.BehaviourBarrier) AtomicReference(java.util.concurrent.atomic.AtomicReference) EventBus(won.bot.framework.eventbot.bus.EventBus) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WonMessage(won.protocol.message.WonMessage) EventListener(won.bot.framework.eventbot.listener.EventListener) AtomContent(won.utils.content.model.AtomContent) HashSet(java.util.HashSet) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) Test(org.junit.Test)

Example 8 with Shacl2JavaInstanceFactory

use of won.shacl2java.Shacl2JavaInstanceFactory in project webofneeds by researchstudio-sat.

the class AclTests method testModifyOnBehalf_addGraph.

@Test(timeout = 60 * 1000)
public void testModifyOnBehalf_addGraph() throws Exception {
    final AtomicBoolean atom1Created = new AtomicBoolean(false);
    final AtomicBoolean atom2Created = new AtomicBoolean(false);
    final CountDownLatch latch = new CountDownLatch(2);
    final AtomicReference<URI> createMessageUri1 = new AtomicReference();
    final AtomicReference<URI> createMessageUri2 = new AtomicReference();
    runTest(ctx -> {
        EventBus bus = ctx.getEventBus();
        final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
        final URI atomUri1 = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
        final URI atomUri2 = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
        BotBehaviour bbAtom1 = new BotBehaviour(ctx) {

            @Override
            protected void onActivate(Optional<Object> message) {
                final String atomUriString = atomUri1.toString();
                final AtomContent atomContent = AtomContent.builder(atomUriString).addTitle("Granting atom").addSocket(Socket.builder(atomUriString + "#chatSocket").setSocketDefinition(WXCHAT.ChatSocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
                Authorization auth = Authorization.builder().addGranteesAtomExpression(ae -> ae.addAtomsURI(atomUri2)).addGrant(ase -> ase.addOperationsSimpleOperationExpression(OP_READ).addGraph(g -> g.addGraphType(GraphType.CONTENT_GRAPH).addOperationsMessageOperationExpression(moe -> moe.addMessageOnBehalfsMessageType(MessageType.REPLACE_MESSAGE)))).build();
                WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri1).content().graph("#content", RdfOutput.toGraph(atomContent)).content().aclGraph(won.auth.model.RdfOutput.toGraph(auth)).build();
                createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
                ctx.getBotContextWrapper().rememberAtomUri(atomUri1);
                final String action = "Create granting atom";
                EventListener successCallback = event -> {
                    logger.debug("Granting atom created");
                    createMessageUri1.set(((SuccessResponseEvent) event).getOriginalMessageURI());
                    deactivate();
                };
                EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, action);
                EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
                ctx.getWonMessageSender().sendMessage(createMessage);
            }
        };
        BotBehaviour bbAtom2 = new BotBehaviour(ctx) {

            @Override
            protected void onActivate(Optional<Object> message) {
                final String atomUriString = atomUri2.toString();
                final AtomContent atomContent = AtomContent.builder(atomUriString).addTitle("Grantee atom").addSocket(Socket.builder(atomUriString + "#chatSocket").setSocketDefinition(WXCHAT.ChatSocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
                WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri2).content().graph(RdfOutput.toGraph(atomContent)).content().aclGraph(won.auth.model.RdfOutput.toGraph(getNobodyMayDoNothing())).build();
                createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
                ctx.getBotContextWrapper().rememberAtomUri(atomUri2);
                final String action = "Create grantee atom";
                EventListener successCallback = event -> {
                    logger.debug("Grantee atom created");
                    createMessageUri2.set(((SuccessResponseEvent) event).getOriginalMessageURI());
                    deactivate();
                };
                EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, action);
                EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
                ctx.getWonMessageSender().sendMessage(createMessage);
            }
        };
        BotBehaviour bbReplaceAtom1FromAtom2 = new BotBehaviour(ctx) {

            @Override
            protected void onActivate(Optional<Object> message) {
                WonMessage replaceMessage = WonMessageBuilder.replace().atom(atomUri1).content().graph("#content", RdfOutput.toGraph(AtomContent.builder(atomUri1).addTitle("Replaced Title").addTag("A-New-Tag").addType(URI.create(WON.Atom.getURI())).addType(URI.create(WON.Persona.getURI())).addSocket(Socket.builder(atomUri1.toString() + "#buddySocket").setSocketDefinition(WXBUDDY.BuddySocket.asURI()).build()).addSocket(Socket.builder(atomUri1.toString() + "#holderSocket").setSocketDefinition(WXHOLD.HolderSocket.asURI()).build()).build())).content().graph("#content2", RdfOutput.toGraph(AtomContent.builder(atomUri1).addTitle("New Title").addType(URI.create(WON.Atom.getURI())).addSocket(Socket.builder(atomUri1.toString() + "#chatSocket").setSocketDefinition(WXCHAT.ChatSocket.asURI()).build()).build())).build();
                String action = "replace content of atom1 using webid of atom2, adding a graph";
                EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, action);
                replaceMessage = ctx.getWonMessageSender().prepareMessageOnBehalf(replaceMessage, atomUri2);
                EventListener successCallback = makeLoggingCallback(bot, bus, action, () -> deactivate());
                EventBotActionUtils.makeAndSubscribeResponseListener(replaceMessage, successCallback, failureCallback, ctx);
                ctx.getWonMessageSender().sendMessage(replaceMessage);
            }
        };
        BotBehaviour readModified = new BotBehaviour(ctx) {

            @Override
            protected void onActivate(Optional<Object> message) {
                Dataset atomData = ctx.getLinkedDataSource().getDataForResource(atomUri1, atomUri1);
                Set<String> expectedGraphNames = Set.of(atomUri1 + "#acl", atomUri1 + "#acl-sig", atomUri1 + "#content", atomUri1 + "#content-sig", atomUri1 + "#content2", atomUri1 + "#content2-sig", atomUri1 + "#key", atomUri1 + "#key-sig", atomUri1 + "#sysinfo");
                Iterator<String> it = atomData.listNames();
                Set<String> actualNames = new HashSet<>();
                while (it.hasNext()) {
                    actualNames.add(it.next());
                }
                Assert.assertEquals(expectedGraphNames, actualNames);
                Shacl2JavaInstanceFactory instanceFactory = ContentUtils.newInstanceFactory();
                Shacl2JavaInstanceFactory.Accessor accessor = instanceFactory.accessor(atomData.getNamedModel(atomUri1 + "#content").getGraph());
                Optional<AtomContent> atomContent = accessor.getInstanceOfType(atomUri1.toString(), AtomContent.class);
                assertTrue(bus, "replacing content failed: replaced title not found", atomContent.get().getTitles().contains("Replaced Title"));
                assertFalse(bus, "replacing content failed: old title still there", atomContent.get().getTitles().contains("Granting atom"));
                accessor = instanceFactory.accessor(atomData.getNamedModel(atomUri1 + "#content2").getGraph());
                atomContent = accessor.getInstanceOfType(atomUri1.toString(), AtomContent.class);
                assertTrue(bus, "adding content failed: new title not found", atomContent.get().getTitles().contains("New Title"));
                passTest(bus);
            }
        };
        BehaviourBarrier barrier = new BehaviourBarrier(ctx);
        barrier.waitFor(bbAtom1, bbAtom2);
        barrier.thenStart(bbReplaceAtom1FromAtom2);
        barrier.activate();
        bbAtom1.activate();
        bbAtom2.activate();
        bbReplaceAtom1FromAtom2.onDeactivateActivate(readModified);
        logger.debug("Finished initializing test 'testQueryBasedMatch()'");
    });
}
Also used : EventBotAction(won.bot.framework.eventbot.action.EventBotAction) SuccessResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.SuccessResponseEvent) LoggerFactory(org.slf4j.LoggerFactory) won.auth.model(won.auth.model) EventBus(won.bot.framework.eventbot.bus.EventBus) CachingLinkedDataSource(won.protocol.util.linkeddata.CachingLinkedDataSource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConnectFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherAtomEvent) BehaviourBarrier(won.bot.framework.eventbot.behaviour.BehaviourBarrier) ContentUtils(won.utils.content.ContentUtils) AtomicReference(java.util.concurrent.atomic.AtomicReference) WonMessage(won.protocol.message.WonMessage) HashSet(java.util.HashSet) WonMessageBuilder(won.protocol.message.builder.WonMessageBuilder) MessageFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.MessageFromOtherAtomEvent) ActionOnceAfterNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) Individuals(won.auth.model.Individuals) URI(java.net.URI) Dataset(org.apache.jena.query.Dataset) Socket(won.utils.content.model.Socket) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) BotBehaviour(won.bot.framework.eventbot.behaviour.BotBehaviour) MethodHandles(java.lang.invoke.MethodHandles) RdfOutput(won.utils.content.model.RdfOutput) Set(java.util.Set) Test(org.junit.Test) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) EventBotActionUtils(won.bot.framework.eventbot.action.EventBotActionUtils) LinkedDataFetchingException(won.protocol.rest.LinkedDataFetchingException) AtomContent(won.utils.content.model.AtomContent) AuthEnabledLinkedDataSource(won.auth.linkeddata.AuthEnabledLinkedDataSource) CountDownLatch(java.util.concurrent.CountDownLatch) Event(won.bot.framework.eventbot.event.Event) won.protocol.vocabulary(won.protocol.vocabulary) Optional(java.util.Optional) EventFilter(won.bot.framework.eventbot.filter.EventFilter) EventListener(won.bot.framework.eventbot.listener.EventListener) Assert(org.junit.Assert) GraphFactory(org.apache.jena.sparql.graph.GraphFactory) BotBehaviour(won.bot.framework.eventbot.behaviour.BotBehaviour) SuccessResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.SuccessResponseEvent) Optional(java.util.Optional) Dataset(org.apache.jena.query.Dataset) BehaviourBarrier(won.bot.framework.eventbot.behaviour.BehaviourBarrier) AtomicReference(java.util.concurrent.atomic.AtomicReference) EventBus(won.bot.framework.eventbot.bus.EventBus) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WonMessage(won.protocol.message.WonMessage) EventListener(won.bot.framework.eventbot.listener.EventListener) AtomContent(won.utils.content.model.AtomContent) HashSet(java.util.HashSet) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) Test(org.junit.Test)

Example 9 with Shacl2JavaInstanceFactory

use of won.shacl2java.Shacl2JavaInstanceFactory in project webofneeds by researchstudio-sat.

the class InstantiationTest method test_basic_006.

@Test
public void test_basic_006() throws IOException {
    Shapes shapes = loadShapes(shapesDef);
    Shacl2JavaInstanceFactory factory = new Shacl2JavaInstanceFactory(shapes, "won.auth.model");
    Graph data = loadGraph(loader.getResource("classpath:/won/basic/basic-006.ttl"));
    Shacl2JavaInstanceFactory.Accessor accessor = factory.accessor(new Union(shapes.getGraph(), data));
    logger.debug("done instantiating");
    Assert.assertEquals(3, accessor.size());
}
Also used : Graph(org.apache.jena.graph.Graph) Shapes(org.apache.jena.shacl.Shapes) Union(org.apache.jena.graph.compose.Union) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) Test(org.junit.Test)

Example 10 with Shacl2JavaInstanceFactory

use of won.shacl2java.Shacl2JavaInstanceFactory in project webofneeds by researchstudio-sat.

the class LDSocketAuthorizationSource method getSocketAuthorizations.

@Override
public Optional<SocketAuthorizations> getSocketAuthorizations(URI socketDefinitionURI) {
    Dataset data = linkedDataSource.getDataForPublicResource(socketDefinitionURI);
    if (data == null || data.isEmpty()) {
        throw new IllegalStateException(String.format("Could not load RDF for socket definition %s", socketDefinitionURI));
    }
    Shacl2JavaInstanceFactory factory = AuthUtils.instanceFactory();
    Optional<SocketDefinition> sd = factory.accessor(data.getDefaultModel().getGraph()).getInstanceOfType(socketDefinitionURI.toString(), SocketDefinition.class);
    if (sd.isEmpty()) {
        return Optional.empty();
    }
    return Optional.of(new SocketAuthorizations(socketDefinitionURI, sd.get().getLocalAuths(), sd.get().getTargetAuths()));
}
Also used : Dataset(org.apache.jena.query.Dataset) SocketAuthorizations(won.auth.socket.SocketAuthorizations) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) SocketDefinition(won.auth.model.SocketDefinition)

Aggregations

Shacl2JavaInstanceFactory (won.shacl2java.Shacl2JavaInstanceFactory)13 Test (org.junit.Test)11 Graph (org.apache.jena.graph.Graph)10 ClassPathResource (org.springframework.core.io.ClassPathResource)7 Resource (org.springframework.core.io.Resource)7 SocketDefinition (won.auth.model.SocketDefinition)7 SocketAclAlgorithms (won.auth.socket.support.SocketAclAlgorithms)6 URI (java.net.URI)3 HashSet (java.util.HashSet)3 Optional (java.util.Optional)3 Set (java.util.Set)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Dataset (org.apache.jena.query.Dataset)3 Shapes (org.apache.jena.shacl.Shapes)3 won.auth.model (won.auth.model)3 MethodHandles (java.lang.invoke.MethodHandles)2 Iterator (java.util.Iterator)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Difference (org.apache.jena.graph.compose.Difference)2