Search in sources :

Example 1 with IllegalMessageForAtomStateException

use of won.protocol.exception.IllegalMessageForAtomStateException in project webofneeds by researchstudio-sat.

the class DeleteAtomMessageFromOwnerProcessor method process.

public void process(final Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    Optional<Atom> atom = atomService.getAtom(wonMessage.getAtomURI());
    if (!atom.isPresent()) {
        throw new NoSuchAtomException(wonMessage.getAtomURI());
    }
    if (atom.get().getState() == AtomState.DELETED) {
        throw new IllegalMessageForAtomStateException(atom.get().getAtomURI(), "DELETE", atom.get().getState());
    }
// the rest of the delete tasks are done in the reaction processor
}
Also used : Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) NoSuchAtomException(won.protocol.exception.NoSuchAtomException) WonMessage(won.protocol.message.WonMessage) Atom(won.protocol.model.Atom) IllegalMessageForAtomStateException(won.protocol.exception.IllegalMessageForAtomStateException)

Example 2 with IllegalMessageForAtomStateException

use of won.protocol.exception.IllegalMessageForAtomStateException in project webofneeds by researchstudio-sat.

the class MatcherCLI method run.

@Override
public void run(String... args) throws Exception {
    String atom1 = "http://localhost:8080/won/resource/atom/1";
    String atom2 = "http://localhost:8080/won/resource/atom/2";
    String org = "http://localhost:8080/matcher";
    double score = 1;
    for (int i = 0; i < args.length; i++) {
        switch(args[i]) {
            case "-h":
                System.out.println("USAGE: java MatcherCLI [-n1 atom1] [-n2 atom2] [-o originator] [-s score] [-h]");
                System.exit(0);
            case "-n1":
                atom1 = args[++i];
                break;
            case "-n2":
                atom2 = args[++i];
                break;
            case "-o":
                org = args[++i];
                break;
            case "-s":
                score = Double.parseDouble(args[++i]);
                break;
        }
    }
    try {
        // TODO: Add rdf content
        client.hint(new URI(atom1), new URI(atom2), score, new URI(org), null, createWonMessage(URI.create(atom1), URI.create(atom2), score, URI.create(org)));
    } catch (URISyntaxException e) {
        logger.error("Exception caught:", e);
    } catch (IllegalMessageForAtomStateException e) {
        logger.error("Exception caught:", e);
    } catch (NoSuchAtomException e) {
        logger.error("Exception caught:", e);
    } catch (Exception e) {
        // To change body of catch statement use File | Settings | File Templates.
        e.printStackTrace();
    }
}
Also used : NoSuchAtomException(won.protocol.exception.NoSuchAtomException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) WonMessageBuilderException(won.protocol.exception.WonMessageBuilderException) URISyntaxException(java.net.URISyntaxException) IllegalMessageForAtomStateException(won.protocol.exception.IllegalMessageForAtomStateException) NoSuchAtomException(won.protocol.exception.NoSuchAtomException) IllegalMessageForAtomStateException(won.protocol.exception.IllegalMessageForAtomStateException)

Aggregations

IllegalMessageForAtomStateException (won.protocol.exception.IllegalMessageForAtomStateException)2 NoSuchAtomException (won.protocol.exception.NoSuchAtomException)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Message (org.apache.camel.Message)1 WonMessageBuilderException (won.protocol.exception.WonMessageBuilderException)1 WonMessage (won.protocol.message.WonMessage)1 Atom (won.protocol.model.Atom)1