Search in sources :

Example 1 with Do

use of org.w3._2007.rif.Do in project nhin-d by DirectProject.

the class DirectXdMailet method service.

/*
     * (non-Javadoc)
     * 
     * @see org.apache.mailet.base.GenericMailet#service(org.apache.mailet.Mail)
     */
@Override
public void service(Mail mail) throws MessagingException {
    LOGGER.info("Servicing DirectXdMailet");
    if (StringUtils.isBlank(endpointUrl)) {
        LOGGER.error("DirectXdMailet endpoint URL cannot be empty or null.");
        throw new MessagingException("DirectXdMailet endpoint URL cannot be empty or null.");
    }
    boolean successfulTransaction = false;
    final MimeMessage msg = mail.getMessage();
    final boolean isReliableAndTimely = TxUtil.isReliableAndTimelyRequested(msg);
    final NHINDAddressCollection initialRecipients = getMailRecipients(mail);
    final NHINDAddressCollection xdRecipients = new NHINDAddressCollection();
    final NHINDAddress sender = getMailSender(mail);
    Tx txToTrack = null;
    // Get recipients and create a collection of Strings
    final List<String> recipAddresses = new ArrayList<String>();
    for (NHINDAddress addr : initialRecipients) {
        recipAddresses.add(addr.getAddress());
    }
    // Service XD* addresses
    if (getResolver().hasXdEndpoints(recipAddresses)) {
        LOGGER.info("Recipients include XD endpoints");
        try {
            //List<Address> xdAddresses = new ArrayList<Address>();
            for (String s : getResolver().getXdEndpoints(recipAddresses)) {
                //xdAddresses.add((new MailAddress(s)).toInternetAddress());
                xdRecipients.add(new NHINDAddress(s));
            }
            txToTrack = this.getTxToTrack(msg, sender, xdRecipients);
            // Replace recipients with only XD* addresses
            //msg.setRecipients(RecipientType.TO, xdAddresses.toArray(new Address[0]));
            msg.setRecipients(RecipientType.TO, xdRecipients.toArray(new Address[0]));
            // Transform MimeMessage into ProvideAndRegisterDocumentSetRequestType object
            ProvideAndRegisterDocumentSetRequestType request = getMimeXDSTransformer().transform(msg);
            for (String directTo : recipAddresses) {
                String response = getDocumentRepository().forwardRequest(endpointUrl, request, directTo, sender.toString());
                if (!isSuccessful(response)) {
                    LOGGER.error("DirectXdMailet failed to deliver XD message.");
                    LOGGER.error(response);
                } else {
                    successfulTransaction = true;
                    if (isReliableAndTimely && txToTrack != null && txToTrack.getMsgType() == TxMessageType.IMF) {
                        // send MDN dispatch for messages the recipients that were successful
                        final Collection<NotificationMessage> notifications = notificationProducer.produce(new Message(msg), xdRecipients.toInternetAddressCollection());
                        if (notifications != null && notifications.size() > 0) {
                            LOGGER.debug("Sending MDN \"dispathed\" messages");
                            // create a message for each notification and put it on James "stack"
                            for (NotificationMessage message : notifications) {
                                try {
                                    getMailetContext().sendMail(message);
                                } catch (Throwable t) {
                                    // don't kill the process if this fails
                                    LOGGER.error("Error sending MDN dispatched message.", t);
                                }
                            }
                        }
                    }
                }
            }
        } catch (Throwable e) {
            LOGGER.error("DirectXdMailet delivery failure", e);
        }
    }
    // this basically sets the message back to it's original state with SMTP addresses only
    if (getResolver().hasSmtpEndpoints(recipAddresses)) {
        LOGGER.info("Recipients include SMTP endpoints");
        mail.setRecipients(getSmtpRecips(recipAddresses));
    } else {
        LOGGER.info("Recipients do not include SMTP endpoints");
        // No SMTP addresses, ghost it
        mail.setState(Mail.GHOST);
    }
    if (!successfulTransaction) {
        if (txToTrack != null && txToTrack.getMsgType() == TxMessageType.IMF) {
            // for good measure, send DSN messages back to the original sender on failure
            // create a DSN message
            this.sendDSN(txToTrack, xdRecipients, false);
        }
    }
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) Address(javax.mail.Address) MailAddress(org.apache.mailet.MailAddress) NHINDAddress(org.nhindirect.stagent.NHINDAddress) NotificationMessage(org.nhindirect.stagent.mail.notifications.NotificationMessage) Message(org.nhindirect.stagent.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) NHINDAddressCollection(org.nhindirect.stagent.NHINDAddressCollection) ArrayList(java.util.ArrayList) NHINDAddress(org.nhindirect.stagent.NHINDAddress) NotificationMessage(org.nhindirect.stagent.mail.notifications.NotificationMessage) MimeMessage(javax.mail.internet.MimeMessage) ProvideAndRegisterDocumentSetRequestType(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType)

Example 2 with Do

use of org.w3._2007.rif.Do in project hale by halestudio.

the class TestModelRifToRifTranslator method checkDoElements.

private void checkDoElements(Do do1) {
    assertNotNull(do1.getActionVar());
    assertTrue(do1.getActionVar().size() >= 1);
    // count number of news and frames in the collection
    int numNews = 0;
    int numFrames = 0;
    for (ActionVar v : do1.getActionVar()) {
        assertNotNull(v);
        if (v.getNew() != null) {
            numNews++;
            checkActionVarTypeNew(v);
        }
        if (v.getFrame() != null) {
            numFrames++;
            checkActionVarTypeFrame(v);
        }
    }
    assertThat(numNews, is(equalTo(1)));
    int numAsserts = 0;
    for (Object action : do1.getActions().getACTION()) {
        assertTrue(action instanceof org.w3._2007.rif.Assert);
        numAsserts++;
        org.w3._2007.rif.Assert a = (org.w3._2007.rif.Assert) action;
        assertNotNull(a);
        checkAssertTarget(a);
    }
    // CHECKSTYLE:OFF
    assertThat(numAsserts, is(equalTo(3)));
// CHECKSTYLE:ON
}
Also used : ActionVar(org.w3._2007.rif.Do.ActionVar) Assert(org.w3._2007.rif.Assert) Assert(org.w3._2007.rif.Assert)

Example 3 with Do

use of org.w3._2007.rif.Do in project hale by halestudio.

the class ModelRifToRifTranslator method buildSentence.

private Sentence buildSentence(ModelSentence s) {
    // sort variables within sentence
    final Sentence sentence = factory.createSentence();
    final Implies implies = factory.createImplies();
    sentence.setImplies(implies);
    final If if1 = factory.createIf();
    implies.setIf(if1);
    final Exists exists = factory.createExists();
    if1.setExists(exists);
    ThenPart then = factory.createThenPart();
    implies.setThen(then);
    Do do1 = factory.createDo();
    then.setDo(do1);
    processChildren(s, exists, do1);
    return sentence;
}
Also used : Implies(org.w3._2007.rif.Implies) Exists(org.w3._2007.rif.Exists) ThenPart(org.w3._2007.rif.ThenPart) Do(org.w3._2007.rif.Do) ModelSentence(com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelSentence) Sentence(org.w3._2007.rif.Sentence) If(org.w3._2007.rif.If)

Example 4 with Do

use of org.w3._2007.rif.Do in project hale by halestudio.

the class ModelRifToRifTranslator method recurseChildren.

private void recurseChildren(final Exists exists, Do do1, RifVariable variable, ModelSentence sentence, boolean isSource) {
    List<RifVariable> children = sentence.findChildren(variable);
    if (isSource) {
        exists.getDeclare().add(createSourceDeclare(variable));
        if (variable.getType().equals(Type.INSTANCE)) {
            exists.getFormula().getAnd().getFormula().add(createSourceInstanceMembershipFormula(sentence, variable));
        }
    } else {
        // if (!children.isEmpty()) // problem?
        do1.getActionVar().add(createTargetVariableDeclare(variable));
        if (variable.getType() == Type.INSTANCE) {
            do1.getActions().getACTION().add(createTargetInstanceMembershipFormula(do1.getActions(), sentence, variable));
        }
    }
    if (!children.isEmpty()) {
        if (isSource) {
            Frame frame = initialiseFrame(variable);
            for (RifVariable child : children) {
                recurseChildren(exists, do1, child, sentence, isSource);
                createBindingSlot(child, frame);
            }
            Formula frameFormula = factory.createFormula();
            frameFormula.setFrame(frame);
            exists.getFormula().getAnd().getFormula().add(frameFormula);
        } else {
            for (RifVariable child : children) {
                recurseChildren(exists, do1, child, sentence, isSource);
            }
        }
    }
}
Also used : Formula(org.w3._2007.rif.Formula) Frame(org.w3._2007.rif.Frame) RifVariable(com.onespatial.jrc.tns.oml_to_rif.translate.context.RifVariable)

Example 5 with Do

use of org.w3._2007.rif.Do in project hale by halestudio.

the class ModelRifToRifTranslator method processChildren.

private void processChildren(ModelSentence s, final Exists exists, Do do1) {
    Formula existsFormula = factory.createFormula();
    And and = factory.createAnd();
    existsFormula.setAnd(and);
    exists.setFormula(existsFormula);
    Actions actions = factory.createDoActions();
    do1.setActions(actions);
    for (RifVariable instanceVariable : s.getVariables(Type.INSTANCE)) {
        // source instance variables
        if (!instanceVariable.isActionVar()) {
            recurseChildren(exists, do1, instanceVariable, s, true);
        } else // target instance variables
        {
            recurseChildren(exists, do1, instanceVariable, s, false);
        }
    }
    Map<RifVariable, Frame> map = new LinkedHashMap<RifVariable, Frame>();
    for (PropertyMapping mapping : s.getPropertyMappings()) {
        RifVariable contextVariable = mapping.getTarget().getContextVariable();
        Frame match = map.get(contextVariable);
        if (match == null) {
            map.put(contextVariable, initialiseFrame(contextVariable));
        }
    }
    for (StaticAssignment staticAssignment : s.getStaticAssignments()) {
        RifVariable contextVariable = staticAssignment.getTarget().getContextVariable();
        Frame match = map.get(contextVariable);
        if (match == null) {
            map.put(contextVariable, initialiseFrame(contextVariable));
        }
    }
    for (PropertyMapping mapping : s.getPropertyMappings()) {
        Frame frame = map.get(mapping.getTarget().getContextVariable());
        createAssignmentSlot(mapping, frame);
    }
    for (StaticAssignment staticAssignment : s.getStaticAssignments()) {
        Frame frame = map.get(staticAssignment.getTarget().getContextVariable());
        createStaticAssignmentSlot(staticAssignment, frame);
    }
    for (ModelRifMappingCondition mappingCondition : s.getMappingConditions()) {
        createFilter(exists.getFormula().getAnd().getFormula(), mappingCondition);
    }
    for (Frame frame : map.values()) {
        Assert assert1 = factory.createAssert();
        Target target = factory.createAssertTarget();
        target.setFrame(frame);
        assert1.setTarget(target);
        actions.getACTION().add(assert1);
    }
}
Also used : Formula(org.w3._2007.rif.Formula) StaticAssignment(com.onespatial.jrc.tns.oml_to_rif.model.rif.StaticAssignment) Frame(org.w3._2007.rif.Frame) Target(org.w3._2007.rif.Assert.Target) Assert(org.w3._2007.rif.Assert) Actions(org.w3._2007.rif.Do.Actions) And(org.w3._2007.rif.And) ModelRifMappingCondition(com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelRifMappingCondition) PropertyMapping(com.onespatial.jrc.tns.oml_to_rif.model.rif.PropertyMapping) RifVariable(com.onespatial.jrc.tns.oml_to_rif.translate.context.RifVariable) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

RifVariable (com.onespatial.jrc.tns.oml_to_rif.translate.context.RifVariable)2 ArrayList (java.util.ArrayList)2 Assert (org.w3._2007.rif.Assert)2 Formula (org.w3._2007.rif.Formula)2 Frame (org.w3._2007.rif.Frame)2 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 ModelRifMappingCondition (com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelRifMappingCondition)1 ModelSentence (com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelSentence)1 PropertyMapping (com.onespatial.jrc.tns.oml_to_rif.model.rif.PropertyMapping)1 StaticAssignment (com.onespatial.jrc.tns.oml_to_rif.model.rif.StaticAssignment)1 ProvideAndRegisterDocumentSetRequestType (ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType)1 LocalDateTime (java.time.LocalDateTime)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1