Search in sources :

Example 1 with DefaultAtomModelWrapper

use of won.protocol.util.DefaultAtomModelWrapper in project webofneeds by researchstudio-sat.

the class WonOwnerMailSender method sendCloseNotificationMessage.

public void sendCloseNotificationMessage(String toEmail, String localAtom, String targetAtom, String localConnection, String localSocket, String targetSocket, String textMsg) {
    StringWriter writer = new StringWriter();
    VelocityContext context = createContext(toEmail, localAtom, targetAtom, localConnection, localSocket, targetSocket, textMsg);
    closeNotificationTemplate.merge(context, writer);
    Dataset atomDataset = linkedDataSource.getDataForPublicResource(URI.create(localAtom));
    DefaultAtomModelWrapper wrapper = new DefaultAtomModelWrapper(atomDataset);
    String subject = SUBJECT_CLOSE;
    if (isChatSocket(wrapper, localSocket)) {
        subject = SUBJECT_CLOSE_CHAT;
    }
    logger.debug("sending {} to {}", subject, toEmail);
    this.wonMailSender.sendTextMessage(toEmail, subject, writer.toString());
}
Also used : StringWriter(java.io.StringWriter) DefaultAtomModelWrapper(won.protocol.util.DefaultAtomModelWrapper) VelocityContext(org.apache.velocity.VelocityContext) Dataset(org.apache.jena.query.Dataset)

Example 2 with DefaultAtomModelWrapper

use of won.protocol.util.DefaultAtomModelWrapper in project webofneeds by researchstudio-sat.

the class WonOwnerMailSender method createContext.

private VelocityContext createContext(String toEmail, String localAtom, String targetAtom, String localConnection, String localSocket, String targetSocket, String textMsg) {
    String ownerAppLink = uriService.getOwnerProtocolOwnerURI().toString();
    VelocityContext velocityContext = new VelocityContext();
    if (targetAtom != null) {
        Dataset atomDataset = linkedDataSource.getDataForPublicResource(URI.create(targetAtom));
        DefaultAtomModelWrapper targetAtomWrapper = new DefaultAtomModelWrapper(atomDataset);
        velocityContext.put("targetAtomTitle", getLabelForAtomInMail(targetAtomWrapper));
        velocityContext.put("targetAtomIsPersona", isPersonaAtom(targetAtomWrapper));
        velocityContext.put("targetSocketIsGroupSocket", isGroupChatSocket(targetAtomWrapper, targetSocket));
        velocityContext.put("targetSocketIsChatSocket", isChatSocket(targetAtomWrapper, targetSocket));
        String linkTargetAtom = uriService.getOwnerProtocolOwnerURI() + OWNER_TARGET_ATOM_LINK + targetAtom;
        velocityContext.put("linkTargetAtom", linkTargetAtom);
    }
    if (localAtom != null) {
        Dataset localAtomDataset = linkedDataSource.getDataForPublicResource(URI.create(localAtom));
        DefaultAtomModelWrapper localAtomWrapper = new DefaultAtomModelWrapper(localAtomDataset);
        String linkLocalAtom = ownerAppLink + OWNER_LOCAL_ATOM_LINK + localAtom;
        velocityContext.put("linkLocalAtom", linkLocalAtom);
        velocityContext.put("localAtomTitle", getLabelForAtomInMail(localAtomWrapper));
        velocityContext.put("localAtomIsPersona", isPersonaAtom(localAtomWrapper));
        velocityContext.put("localSocketIsGroupSocket", isGroupChatSocket(localAtomWrapper, localSocket));
        velocityContext.put("localSocketIsChatSocket", isChatSocket(localAtomWrapper, localSocket));
    }
    if (localConnection != null && localAtom != null) {
        String linkConnection = ownerAppLink + String.format(OWNER_CONNECTION_LINK, localAtom, localConnection);
        velocityContext.put("linkConnection", linkConnection);
    }
    if (textMsg != null) {
        velocityContext.put("textMsg", textMsg);
    }
    if (this.ownerWebappUri != null) {
        velocityContext.put("serviceName", this.ownerWebappUri);
    }
    return velocityContext;
}
Also used : DefaultAtomModelWrapper(won.protocol.util.DefaultAtomModelWrapper) VelocityContext(org.apache.velocity.VelocityContext) Dataset(org.apache.jena.query.Dataset)

Example 3 with DefaultAtomModelWrapper

use of won.protocol.util.DefaultAtomModelWrapper in project webofneeds by researchstudio-sat.

the class WonOwnerMailSender method sendConnectNotificationMessage.

public void sendConnectNotificationMessage(String toEmail, String localAtom, String targetAtom, String localConnection, String localSocket, String targetSocket, String textMsg) {
    StringWriter writer = new StringWriter();
    VelocityContext context = createContext(toEmail, localAtom, targetAtom, localConnection, localSocket, targetSocket, textMsg);
    connectNotificationTemplate.merge(context, writer);
    Dataset atomDataset = linkedDataSource.getDataForPublicResource(URI.create(localAtom));
    DefaultAtomModelWrapper wrapper = new DefaultAtomModelWrapper(atomDataset);
    String subject = SUBJECT_CONNECT;
    if (isChatSocket(wrapper, localSocket)) {
        subject = SUBJECT_CONNECT_CHAT;
    }
    logger.debug("sending {} to {}", subject, toEmail);
    this.wonMailSender.sendTextMessage(toEmail, subject, writer.toString());
}
Also used : StringWriter(java.io.StringWriter) DefaultAtomModelWrapper(won.protocol.util.DefaultAtomModelWrapper) VelocityContext(org.apache.velocity.VelocityContext) Dataset(org.apache.jena.query.Dataset)

Example 4 with DefaultAtomModelWrapper

use of won.protocol.util.DefaultAtomModelWrapper in project webofneeds by researchstudio-sat.

the class WonOwnerMailSender method createMultipleHintsContext.

private VelocityContext createMultipleHintsContext(Map<String, Long> hintCountPerAtom) {
    String ownerAppLink = uriService.getOwnerProtocolOwnerURI().toString();
    VelocityContext velocityContext = new VelocityContext();
    velocityContext.put("hintCount", hintCountPerAtom);
    velocityContext.put("serviceName", this.ownerWebappUri);
    velocityContext.put("atoms", hintCountPerAtom.keySet());
    Map<String, String> atomLinks = new HashMap<>();
    Map<String, String> atomTitles = new HashMap<>();
    Map<String, Boolean> atomIsPersonas = new HashMap<>();
    hintCountPerAtom.keySet().stream().forEach(localAtom -> {
        Dataset localAtomDataset = linkedDataSource.getDataForPublicResource(URI.create(localAtom));
        DefaultAtomModelWrapper localAtomWrapper = new DefaultAtomModelWrapper(localAtomDataset);
        String linkLocalAtom = ownerAppLink + OWNER_LOCAL_ATOM_LINK + localAtom;
        atomLinks.put(localAtom, linkLocalAtom);
        atomTitles.put(localAtom, getLabelForAtomInMail(localAtomWrapper));
        atomIsPersonas.put(localAtom, isPersonaAtom(localAtomWrapper));
    });
    velocityContext.put("atomTitle", atomTitles);
    velocityContext.put("atomLink", atomLinks);
    velocityContext.put("atomIsPersona", atomIsPersonas);
    return velocityContext;
}
Also used : DefaultAtomModelWrapper(won.protocol.util.DefaultAtomModelWrapper) HashMap(java.util.HashMap) VelocityContext(org.apache.velocity.VelocityContext) Dataset(org.apache.jena.query.Dataset)

Example 5 with DefaultAtomModelWrapper

use of won.protocol.util.DefaultAtomModelWrapper in project webofneeds by researchstudio-sat.

the class SolrMatcherEvaluation method createAtomId.

public static String createAtomId(Dataset atom) {
    String title = "";
    String description = "";
    try {
        DefaultAtomModelWrapper atomModelWrapper = new DefaultAtomModelWrapper(atom);
        title = atomModelWrapper.getAllTitles().iterator().next();
        title = title.replaceAll("[^A-Za-z0-9 ]", "_");
        title = title.replaceAll("NOT", "_");
        title = title.replaceAll("AND", "_");
        title = title.replaceAll("OR", "_");
        description = atomModelWrapper.getSomeDescription();
    } catch (IncorrectPropertyCountException e) {
    // do nothing
    }
    if (title.isEmpty()) {
        throw new IllegalArgumentException("atom has no title!!");
    }
    return title + "_" + (title + description).hashCode();
}
Also used : DefaultAtomModelWrapper(won.protocol.util.DefaultAtomModelWrapper) IncorrectPropertyCountException(won.protocol.exception.IncorrectPropertyCountException)

Aggregations

DefaultAtomModelWrapper (won.protocol.util.DefaultAtomModelWrapper)8 Dataset (org.apache.jena.query.Dataset)5 VelocityContext (org.apache.velocity.VelocityContext)4 StringWriter (java.io.StringWriter)3 Resource (org.apache.jena.rdf.model.Resource)2 JsonLdOptions (com.github.jsonldjava.core.JsonLdOptions)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 MimeMessage (javax.mail.internet.MimeMessage)1 MimeMessageParser (org.apache.commons.mail.util.MimeMessageParser)1 Document (org.jsoup.nodes.Document)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1 IncorrectPropertyCountException (won.protocol.exception.IncorrectPropertyCountException)1 Coordinate (won.protocol.model.Coordinate)1