Search in sources :

Example 56 with Interaction

use of org.sbolstandard.core2.Interaction in project libSBOLj by SynBioDex.

the class SBOLDocument method updateReferences.

// TODO: need to update persistentIdentities too
private void updateReferences(HashMap<URI, URI> uriMap) throws SBOLValidationException {
    for (TopLevel topLevel : getTopLevels()) {
        for (URI wasDerivedFrom : topLevel.getWasDerivedFroms()) {
            if (uriMap.get(wasDerivedFrom) != null) {
                topLevel.removeWasDerivedFrom(wasDerivedFrom);
                topLevel.addWasDerivedFrom(uriMap.get(wasDerivedFrom));
            }
        }
        for (URI wasGeneratedBy : topLevel.getWasGeneratedBys()) {
            if (uriMap.get(wasGeneratedBy) != null) {
                topLevel.removeWasGeneratedBy(wasGeneratedBy);
                topLevel.addWasGeneratedBy(uriMap.get(wasGeneratedBy));
            }
        }
        for (URI attachmentURI : topLevel.getAttachmentURIs()) {
            if (uriMap.get(attachmentURI) != null) {
                topLevel.removeAttachment(attachmentURI);
                topLevel.addAttachment(uriMap.get(attachmentURI));
            }
        }
    }
    for (Collection collection : getCollections()) {
        for (URI memberURI : collection.getMemberURIs()) {
            if (uriMap.get(memberURI) != null) {
                collection.removeMember(memberURI);
                collection.addMember(uriMap.get(memberURI));
            }
        }
        updateReferences(collection, uriMap);
    }
    for (ComponentDefinition componentDefinition : getComponentDefinitions()) {
        updateReferences(componentDefinition, uriMap);
        for (Component component : componentDefinition.getComponents()) {
            if (uriMap.get(component.getDefinitionURI()) != null) {
                component.setDefinition(uriMap.get(component.getDefinitionURI()));
                for (MapsTo mapsTo : component.getMapsTos()) {
                    ComponentDefinition cd = getComponentDefinition(component.getDefinitionURI());
                    if (cd != null) {
                        String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
                        URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
                        mapsTo.setRemote(newURI);
                    }
                }
            }
            updateReferences(component, uriMap);
            for (MapsTo mapsTo : component.getMapsTos()) {
                updateReferences(mapsTo, uriMap);
            }
        }
        for (SequenceAnnotation sa : componentDefinition.getSequenceAnnotations()) {
            for (Location loc : sa.getLocations()) {
                updateReferences(loc, uriMap);
            }
            updateReferences(sa, uriMap);
        }
        for (SequenceConstraint sc : componentDefinition.getSequenceConstraints()) {
            updateReferences(sc, uriMap);
        }
        for (URI sequenceURI : componentDefinition.getSequenceURIs()) {
            if (uriMap.get(sequenceURI) != null) {
                componentDefinition.removeSequence(sequenceURI);
                componentDefinition.addSequence(uriMap.get(sequenceURI));
            }
        }
    }
    for (ModuleDefinition moduleDefinition : getModuleDefinitions()) {
        updateReferences(moduleDefinition, uriMap);
        for (FunctionalComponent functionalComponent : moduleDefinition.getFunctionalComponents()) {
            if (uriMap.get(functionalComponent.getDefinitionURI()) != null) {
                functionalComponent.setDefinition(uriMap.get(functionalComponent.getDefinitionURI()));
                for (MapsTo mapsTo : functionalComponent.getMapsTos()) {
                    ComponentDefinition cd = getComponentDefinition(functionalComponent.getDefinitionURI());
                    if (cd != null) {
                        String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
                        URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
                        mapsTo.setRemote(newURI);
                    }
                }
            }
            updateReferences(functionalComponent, uriMap);
            for (MapsTo mapsTo : functionalComponent.getMapsTos()) {
                updateReferences(mapsTo, uriMap);
            }
        }
        for (Module module : moduleDefinition.getModules()) {
            if (uriMap.get(module.getDefinitionURI()) != null) {
                module.setDefinition(uriMap.get(module.getDefinitionURI()));
                for (MapsTo mapsTo : module.getMapsTos()) {
                    ModuleDefinition md = getModuleDefinition(module.getDefinitionURI());
                    if (md != null) {
                        String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
                        URI newURI = URIcompliance.createCompliantURI(md.getPersistentIdentity().toString(), displayId, md.getVersion());
                        mapsTo.setRemote(newURI);
                    }
                }
            }
            updateReferences(module, uriMap);
            for (MapsTo mapsTo : module.getMapsTos()) {
                updateReferences(mapsTo, uriMap);
            }
        }
        for (Interaction interaction : moduleDefinition.getInteractions()) {
            updateReferences(interaction, uriMap);
            for (Participation participation : interaction.getParticipations()) {
                updateReferences(participation, uriMap);
            }
        }
        for (URI modelURI : moduleDefinition.getModelURIs()) {
            if (uriMap.get(modelURI) != null) {
                moduleDefinition.removeModel(modelURI);
                moduleDefinition.addModel(uriMap.get(modelURI));
            }
        }
    }
    for (Model model : getModels()) {
        updateReferences(model, uriMap);
    }
    for (Sequence sequence : getSequences()) {
        updateReferences(sequence, uriMap);
    }
    for (Attachment attachment : getAttachments()) {
        updateReferences(attachment, uriMap);
    }
    for (Implementation implementation : getImplementations()) {
        if (implementation.isSetBuilt()) {
            URI built = implementation.getBuiltURI();
            if (uriMap.get(built) != null) {
                implementation.setBuilt(uriMap.get(built));
            }
        }
        updateReferences(implementation, uriMap);
    }
    for (GenericTopLevel genericTopLevel : getGenericTopLevels()) {
        updateReferences(genericTopLevel, uriMap);
    }
    for (CombinatorialDerivation combinatorialDerivation : getCombinatorialDerivations()) {
        updateReferences(combinatorialDerivation, uriMap);
        if (uriMap.get(combinatorialDerivation.getTemplateURI()) != null) {
            combinatorialDerivation.setTemplate(uriMap.get(combinatorialDerivation.getTemplateURI()));
            ComponentDefinition cd = getComponentDefinition(combinatorialDerivation.getTemplateURI());
            if (cd != null) {
                for (VariableComponent variableComponent : combinatorialDerivation.getVariableComponents()) {
                    String displayId = URIcompliance.extractDisplayId(variableComponent.getVariableURI());
                    URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
                    variableComponent.setVariable(newURI);
                }
            }
        }
        for (VariableComponent variableComponent : combinatorialDerivation.getVariableComponents()) {
            updateReferences(variableComponent, uriMap);
        }
    }
    for (Activity activity : getActivities()) {
        updateReferences(activity, uriMap);
        for (Association association : activity.getAssociations()) {
            if (uriMap.get(association.getAgentURI()) != null) {
                association.setAgent(uriMap.get(association.getAgentURI()));
            }
            if (uriMap.get(association.getPlanURI()) != null) {
                association.setPlan(uriMap.get(association.getPlanURI()));
            }
            updateReferences(association, uriMap);
        }
        for (Usage usage : activity.getUsages()) {
            if (uriMap.get(usage.getEntityURI()) != null) {
                usage.setEntity(uriMap.get(usage.getEntityURI()));
            }
            updateReferences(usage, uriMap);
        }
    }
    for (Agent agent : getAgents()) {
        updateReferences(agent, uriMap);
    }
    for (Plan plan : getPlans()) {
        updateReferences(plan, uriMap);
    }
}
Also used : URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI)

Example 57 with Interaction

use of org.sbolstandard.core2.Interaction in project libSBOLj by SynBioDex.

the class ModuleDefinition method flattenRecurse.

/**
 * @return flattened ModuleDefinition
 * @throws SBOLValidationException if either of the following condition is satisfied:
 * <ul>
 * <li>The following SBOL validation rule was violated: 10811; or</li>
 *
 * <li>if an SBOL validation rule violation occurred in any of the following methods:</li>
 *	 <ul>
 *     	<li>{@link #deepCopy()},</li>
 * 		<li>{@link #flattenRecurse()},</li>
 * 		<li>{@link FunctionalComponent#setDefinition(URI)},</li>
 * 		<li>{@link FunctionalComponent#deepCopy()},</li>
 * 		<li>{@link FunctionalComponent#updateCompliantURI(String, String, String)},</li>
 * 		<li>{@link #addFunctionalComponent(FunctionalComponent)},</li>
 * 		<li>{@link Participation#setParticipant(URI)},</li>
 * 		<li>{@link #addInteraction(Interaction)}, or</li>
 * 		<li>{@link Interaction#deepCopy()}.</li>
 * 	</ul>
 * </ul>
 */
private ModuleDefinition flattenRecurse() throws SBOLValidationException {
    ModuleDefinition flatModuleDefinition = this.deepCopy();
    for (Module module : this.getModules()) {
        ModuleDefinition flatModule = module.getDefinition().flattenRecurse();
        for (FunctionalComponent fc : flatModule.getFunctionalComponents()) {
            boolean foundIt = false;
            URI oldURI = fc.getIdentity();
            URI newURI = null;
            for (MapsTo mapsTo : module.getMapsTos()) {
                if (mapsTo.getRemoteURI().equals(fc.getIdentity())) {
                    newURI = mapsTo.getLocalURI();
                    FunctionalComponent topFc = flatModuleDefinition.getFunctionalComponent(newURI);
                    if (mapsTo.getRefinement() == RefinementType.USEREMOTE) {
                        topFc.setDefinition(fc.getDefinitionURI());
                    } else if (mapsTo.getRefinement() == RefinementType.VERIFYIDENTICAL) {
                        if (!topFc.getDefinitionURI().equals(fc.getDefinitionURI())) {
                            // + "' are not identical.");
                            throw new SBOLValidationException("sbol-10811", mapsTo);
                        }
                    } else if (mapsTo.getRefinement() == RefinementType.MERGE) {
                    // TODO: merge?
                    }
                    foundIt = true;
                    break;
                }
            }
            if (!foundIt) {
                FunctionalComponent newFC = fc.deepCopy();
                newFC.updateCompliantURI(this.getPersistentIdentity().toString(), module.getDisplayId() + "__" + fc.getDisplayId(), this.getVersion());
                newURI = newFC.getIdentity();
                flatModuleDefinition.addFunctionalComponent(newFC);
            }
            for (Interaction i : flatModule.getInteractions()) {
                for (Participation p : i.getParticipations()) {
                    if (p.getParticipantURI().equals(oldURI)) {
                        p.setParticipant(newURI);
                    }
                }
            }
        }
        for (Interaction i : flatModule.getInteractions()) {
            flatModuleDefinition.addInteraction(i.deepCopy());
        }
    }
    flatModuleDefinition.clearModules();
    return flatModuleDefinition;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 58 with Interaction

use of org.sbolstandard.core2.Interaction in project qpid-broker-j by apache.

the class AuthenticationTimeoutTest method authenticationTimeout.

@Test
public void authenticationTimeout() throws Exception {
    InetSocketAddress brokerAddress = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.AMQP);
    try (FrameTransport transport = new FrameTransport(brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        final ConnectionStart start = interaction.negotiateProtocol().consumeResponse().consumeResponse().getLatestResponse(ConnectionStart.class);
        assertThat(start.getMechanisms(), CoreMatchers.hasItem("PLAIN"));
        transport.assertNoMoreResponsesAndChannelClosed();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v0_10.FrameTransport) InetSocketAddress(java.net.InetSocketAddress) Interaction(org.apache.qpid.tests.protocol.v0_10.Interaction) ConnectionStart(org.apache.qpid.server.protocol.v0_10.transport.ConnectionStart) Test(org.junit.Test)

Example 59 with Interaction

use of org.sbolstandard.core2.Interaction in project qpid-broker-j by apache.

the class TransactionTimeoutTest method publishTransactionTimeout.

@Test
public void publishTransactionTimeout() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        byte[] sessionName = "test".getBytes(UTF_8);
        interaction.openAnonymousConnection().channelId(1).attachSession(sessionName).tx().selectId(0).select().message().transferDestination(BrokerAdmin.TEST_QUEUE_NAME).transferId(1).transfer().session().flushCompleted().flush();
        SessionCompleted completed;
        do {
            completed = interaction.consumeResponse().getLatestResponse(SessionCompleted.class);
        } while (!completed.getCommands().includes(1));
        int queueDepthMessages = getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME);
        assertThat(queueDepthMessages, is(equalTo(0)));
        ConnectionClose close = receiveResponse(interaction, ConnectionClose.class);
        assertThat(close.getReplyCode(), is(equalTo(ConnectionCloseCode.CONNECTION_FORCED)));
        assertThat(close.getReplyText(), containsString("transaction timed out"));
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v0_10.FrameTransport) SessionCompleted(org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted) Interaction(org.apache.qpid.tests.protocol.v0_10.Interaction) ConnectionClose(org.apache.qpid.server.protocol.v0_10.transport.ConnectionClose) Test(org.junit.Test)

Example 60 with Interaction

use of org.sbolstandard.core2.Interaction in project qpid-broker-j by apache.

the class AnonymousTerminusTest method transferPreSettledInTransactionToUnknownDestinationWhenRejectOutcomeSupportedByTxController.

@SpecificationTest(section = "Using the Anonymous Terminus for Message Routing. 2.2.2 Routing Errors", description = "It is possible that a message sent to a routing node has an address in the to field" + " of properties which, if used in the address field of target of an attach," + " would result in an unsuccessful link establishment (for example," + " if the address cannot be resolved to a node). In this case the routing node" + " MUST communicate the error back to the sender of the message." + " [...]" + " <Not in spec yet>" + " AMQP-140" + " If a message cannot be routed to the destination implied in the \"to:\" field," + " and the source does not allow for the rejected outcome" + " [...] when messages are being sent within a transaction and have been sent pre-settled." + " In this case the behaviour defined for transactions (of essentially marking" + " the transaction as rollback only) should take precedence. " + "" + " AMQP spec 4.3 Discharging a Transaction" + " If the coordinator is unable to complete the discharge, the coordinator MUST convey" + " the error to the controller as a transaction-error. If the source for the link to" + " the coordinator supports the rejected outcome, then the message MUST be rejected" + " with this outcome carrying the transaction-error.")
@Test
public void transferPreSettledInTransactionToUnknownDestinationWhenRejectOutcomeSupportedByTxController() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final UnsignedInteger linkHandle = UnsignedInteger.ONE;
        final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
        final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
        interaction.begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(txnState).txnDeclare(txnState).attachRole(Role.SENDER).attachHandle(linkHandle).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination("Unknown")).transferDeliveryTag(_deliveryTag).transferTransactionalState(txnState.getCurrentTransactionId()).transferSettled(Boolean.TRUE).transferDeliveryId(UnsignedInteger.valueOf(1)).transfer();
        final Discharge discharge = new Discharge();
        discharge.setTxnId(txnState.getCurrentTransactionId());
        discharge.setFail(false);
        interaction.transferHandle(txnState.getHandle()).transferDeliveryId(UnsignedInteger.valueOf(2)).transferSettled(Boolean.FALSE).transferDeliveryTag(new Binary(("transaction-" + 2).getBytes(StandardCharsets.UTF_8))).transferPayloadData(discharge).transfer();
        Disposition dischargeTransactionDisposition = getDispositionForDeliveryId(interaction, UnsignedInteger.valueOf(2));
        assertThat(dischargeTransactionDisposition.getSettled(), is(equalTo(true)));
        assertThat(dischargeTransactionDisposition.getState(), is(instanceOf(Rejected.class)));
        Rejected rejected = (Rejected) dischargeTransactionDisposition.getState();
        Error error = rejected.getError();
        assertThat(error, is(notNullValue()));
        assertThat(error.getCondition(), is(equalTo(TransactionError.TRANSACTION_ROLLBACK)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InteractionTransactionalState(org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Rejected(org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Discharge(org.apache.qpid.server.protocol.v1_0.type.transaction.Discharge) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

Test (org.junit.Test)112 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)101 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)100 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)91 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)53 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)48 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)33 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)31 InetSocketAddress (java.net.InetSocketAddress)28 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)28 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)28 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)28 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)24 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)16 URI (java.net.URI)13 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)13 Close (org.apache.qpid.server.protocol.v1_0.type.transport.Close)12 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)12 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)11 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)10