use of org.eclipse.jetty.http2.parser.Parser in project pentaho-kettle by pentaho.
the class HL7MLLPAcknowledge method execute.
public Result execute(Result previousResult, int nr) {
Result result = previousResult;
try {
String serverName = environmentSubstitute(server);
int portNumber = Integer.parseInt(environmentSubstitute(port));
String variable = environmentSubstitute(variableName);
MLLPSocketCacheEntry entry = MLLPSocketCache.getInstance().getServerSocketStreamSource(serverName, portNumber);
MLLPTransport transport = entry.getTransport();
//
synchronized (transport) {
String message = getVariable(variable);
// Parse the message and extract the acknowledge message.
//
Parser parser = new GenericParser();
ValidationContext validationContext = new NoValidation();
parser.setValidationContext(validationContext);
Message msg = parser.parse(message);
Message ack = msg.generateACK();
String ackMessage = ack.encode();
String APPNAME = "PDI4";
if (ack instanceof ca.uhn.hl7v2.model.v21.message.ACK) {
ca.uhn.hl7v2.model.v21.message.ACK mod = (ca.uhn.hl7v2.model.v21.message.ACK) ack;
mod.getMSH().getSENDINGAPPLICATION().setValue(APPNAME);
mod.getMSH().getSENDINGFACILITY().setValue(APPNAME);
ackMessage = mod.encode();
} else if (ack instanceof ca.uhn.hl7v2.model.v22.message.ACK) {
ca.uhn.hl7v2.model.v22.message.ACK mod = (ca.uhn.hl7v2.model.v22.message.ACK) ack;
mod.getMSH().getSendingApplication().setValue(APPNAME);
mod.getMSH().getSendingFacility().setValue(APPNAME);
ackMessage = mod.encode();
} else if (ack instanceof ca.uhn.hl7v2.model.v23.message.ACK) {
ca.uhn.hl7v2.model.v23.message.ACK mod = (ca.uhn.hl7v2.model.v23.message.ACK) ack;
mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
ackMessage = mod.encode();
} else if (ack instanceof ca.uhn.hl7v2.model.v231.message.ACK) {
ca.uhn.hl7v2.model.v231.message.ACK mod = (ca.uhn.hl7v2.model.v231.message.ACK) ack;
mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
ackMessage = mod.encode();
} else if (ack instanceof ca.uhn.hl7v2.model.v24.message.ACK) {
ca.uhn.hl7v2.model.v24.message.ACK mod = (ca.uhn.hl7v2.model.v24.message.ACK) ack;
mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
ackMessage = mod.encode();
} else if (ack instanceof ca.uhn.hl7v2.model.v25.message.ACK) {
ca.uhn.hl7v2.model.v25.message.ACK mod = (ca.uhn.hl7v2.model.v25.message.ACK) ack;
mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
ackMessage = mod.encode();
} else if (ack instanceof ca.uhn.hl7v2.model.v251.message.ACK) {
ca.uhn.hl7v2.model.v251.message.ACK mod = (ca.uhn.hl7v2.model.v251.message.ACK) ack;
mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
ackMessage = mod.encode();
} else if (ack instanceof ca.uhn.hl7v2.model.v26.message.ACK) {
ca.uhn.hl7v2.model.v26.message.ACK mod = (ca.uhn.hl7v2.model.v26.message.ACK) ack;
mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
ackMessage = mod.encode();
} else {
logError("This job entry does not support the HL7 dialect used. Found ACK class: " + ack.getClass().getName());
}
Transportable transportable = new TransportableImpl(ackMessage);
transport.doSend(transportable);
}
// All went well..
//
result.setNrErrors(0);
result.setResult(true);
} catch (Exception e) {
log.logError(BaseMessages.getString(PKG, "HL7MLLPInput.Exception.UnexpectedError"), e);
result.setNrErrors(1);
result.setResult(false);
}
return result;
}
use of org.eclipse.jetty.http2.parser.Parser in project pentaho-kettle by pentaho.
the class HL7MLLPInput method execute.
public Result execute(Result previousResult, int nr) {
Result result = previousResult;
try {
String serverName = environmentSubstitute(server);
int portNumber = Integer.parseInt(environmentSubstitute(port));
String messageVariable = environmentSubstitute(messageVariableName);
String messageTypeVariable = environmentSubstitute(messageTypeVariableName);
String versionVariable = environmentSubstitute(versionVariableName);
MLLPSocketCacheEntry entry = MLLPSocketCache.getInstance().getServerSocketStreamSource(serverName, portNumber);
if (entry.getJobListener() != null) {
parentJob.addJobListener(entry.getJobListener());
}
MLLPTransport transport = entry.getTransport();
//
synchronized (transport) {
Transportable transportable = transport.doReceive();
String message = transportable.getMessage();
logDetailed("Received message: " + message);
parentJob.setVariable(messageVariable, message);
// Parse the message and extract the control ID.
//
Parser parser = new GenericParser();
ValidationContext validationContext = new NoValidation();
parser.setValidationContext(validationContext);
Message msg = parser.parse(message);
Structure structure = msg.get("MSH");
String messageType = null;
String version = msg.getVersion();
if (structure instanceof ca.uhn.hl7v2.model.v21.segment.MSH) {
messageType = ((ca.uhn.hl7v2.model.v21.segment.MSH) structure).getMESSAGETYPE().encode();
} else if (structure instanceof ca.uhn.hl7v2.model.v22.segment.MSH) {
messageType = ((ca.uhn.hl7v2.model.v22.segment.MSH) structure).getMessageType().encode();
} else if (structure instanceof ca.uhn.hl7v2.model.v23.segment.MSH) {
messageType = ((ca.uhn.hl7v2.model.v23.segment.MSH) structure).getMessageType().encode();
} else if (structure instanceof ca.uhn.hl7v2.model.v231.segment.MSH) {
messageType = ((ca.uhn.hl7v2.model.v231.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
} else if (structure instanceof ca.uhn.hl7v2.model.v24.segment.MSH) {
messageType = ((ca.uhn.hl7v2.model.v24.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
} else if (structure instanceof ca.uhn.hl7v2.model.v25.segment.MSH) {
messageType = ((ca.uhn.hl7v2.model.v25.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
} else if (structure instanceof ca.uhn.hl7v2.model.v251.segment.MSH) {
messageType = ((ca.uhn.hl7v2.model.v251.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
} else if (structure instanceof ca.uhn.hl7v2.model.v26.segment.MSH) {
messageType = ((ca.uhn.hl7v2.model.v26.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
} else {
logError("This job entry does not support the HL7 dialect used. Found MSH class: " + structure.getClass().getName());
}
if (!Utils.isEmpty(messageTypeVariable)) {
parentJob.setVariable(messageTypeVariable, messageType);
}
if (!Utils.isEmpty(versionVariable)) {
parentJob.setVariable(versionVariable, version);
}
}
// All went well..
//
result.setNrErrors(0);
result.setResult(true);
} catch (Exception e) {
log.logError(BaseMessages.getString(PKG, "HL7MLLPInput.Exception.UnexpectedError"), e);
result.setNrErrors(1);
result.setResult(false);
}
return result;
}
use of org.eclipse.jetty.http2.parser.Parser in project syncope by apache.
the class AbstractAnyDAO method getWhereClause.
/**
* Generate one where clause for each different attribute schema into the derived schema expression provided.
*
* @param expression derived schema expression
* @param value derived attribute value
* @param attrUtils USER / GROUP
* @return where clauses to use to build the query
*/
private Set<String> getWhereClause(final String expression, final String value) {
Parser parser = new Parser(new StringReader(expression));
// Schema names
List<String> identifiers = new ArrayList<>();
// Literals
List<String> literals = new ArrayList<>();
// Get schema names and literals
for (Token token = parser.getNextToken(); token != null && StringUtils.isNotBlank(token.toString()); token = parser.getNextToken()) {
if (token.kind == ParserConstants.STRING_LITERAL) {
literals.add(token.toString().substring(1, token.toString().length() - 1));
}
if (token.kind == ParserConstants.IDENTIFIER) {
identifiers.add(token.toString());
}
}
// Sort literals in order to process later literals included into others
Collections.sort(literals, (final String t, final String t1) -> {
if (t == null && t1 == null) {
return 0;
} else if (t != null && t1 == null) {
return -1;
} else if (t == null && t1 != null) {
return 1;
} else if (t.length() == t1.length()) {
return 0;
} else if (t.length() > t1.length()) {
return -1;
} else {
return 1;
}
});
// Split value on provided literals
List<String> attrValues = split(value, literals);
if (attrValues.size() != identifiers.size()) {
LOG.error("Ambiguous JEXL expression resolution: literals and values have different size");
return Collections.emptySet();
}
// clauses to be used with INTERSECTed queries
Set<String> clauses = new HashSet<>();
// builder to build the clauses
StringBuilder bld = new StringBuilder();
// Contains used identifiers in order to avoid replications
Set<String> used = new HashSet<>();
// Create several clauses: one for eanch identifiers
for (int i = 0; i < identifiers.size(); i++) {
if (!used.contains(identifiers.get(i))) {
// verify schema existence and get schema type
PlainSchema schema = plainSchemaDAO().find(identifiers.get(i));
if (schema == null) {
LOG.error("Invalid schema '{}', ignoring", identifiers.get(i));
} else {
// clear builder
bld.delete(0, bld.length());
bld.append("(");
// set schema name
bld.append("s.id = '").append(identifiers.get(i)).append("'");
bld.append(" AND ");
bld.append("s.id = a.schema_id").append(" AND ");
bld.append("a.id = v.attribute_id");
bld.append(" AND ");
// use a value clause different for eanch different schema type
switch(schema.getType()) {
case Boolean:
bld.append("v.booleanValue = '").append(attrValues.get(i)).append("'");
break;
case Long:
bld.append("v.longValue = ").append(attrValues.get(i));
break;
case Double:
bld.append("v.doubleValue = ").append(attrValues.get(i));
break;
case Date:
bld.append("v.dateValue = '").append(attrValues.get(i)).append("'");
break;
default:
bld.append("v.stringValue = '").append(attrValues.get(i)).append("'");
}
bld.append(")");
used.add(identifiers.get(i));
clauses.add(bld.toString());
}
}
}
LOG.debug("Generated where clauses {}", clauses);
return clauses;
}
use of org.eclipse.jetty.http2.parser.Parser in project if688.github.io by if688.
the class App method main.
public static void main(String[] args) throws NotLL1Exception, ErrorOnParseException {
/*
* Gramática de exemplo:
* A -> aB
* B -> cC
* C -> d
*
*/
Nonterminal start = new Nonterminal("A");
Nonterminal B = new Nonterminal("B");
Nonterminal C = new Nonterminal("C");
Terminal a = new Terminal("a");
Terminal c = new Terminal("c");
Terminal d = new Terminal("d");
List<GeneralSymbol> prodA = new ArrayList<GeneralSymbol>();
prodA.add(a);
prodA.add(B);
List<GeneralSymbol> prodB = new ArrayList<GeneralSymbol>();
prodB.add(c);
prodB.add(C);
List<GeneralSymbol> prodC = new ArrayList<GeneralSymbol>();
prodC.add(d);
Production fpA = new Production(start, prodA);
Production pB = new Production(B, prodB);
Production pC = new Production(C, prodC);
Collection<Production> col = new ArrayList<Production>();
col.add(fpA);
col.add(pB);
col.add(pC);
List<Terminal> example = new ArrayList<Terminal>();
example.add(a);
example.add(c);
example.add(d);
Grammar g = new Grammar(col, start);
Map<Nonterminal, Set<GeneralSymbol>> first = SetGenerator.getFirst(g);
Map<Nonterminal, Set<GeneralSymbol>> follow = SetGenerator.getFollow(g, first);
Map<LL1Key, List<GeneralSymbol>> table = Table.createTable(g);
Parser parser = ParserGenerator.createParser(g);
ParseTree parseTree = ParserUtils.parseSequence(parser, example);
System.out.println("Exemplo 1:\n" + "A -> aB\n" + "B -> cC\n" + "C -> d");
System.out.println("Conjunto first: " + first.toString());
System.out.println("Conjunto follow: " + follow.toString());
System.out.println("Tabela de parsing: " + table.toString());
System.out.println("Exemplo de parsing: " + parseTree.toString() + "\n");
}
use of org.eclipse.jetty.http2.parser.Parser in project if688.github.io by if688.
the class PosFixa method main.
public static void main(String[] args) throws IOException {
String expression = readFile(file, StandardCharsets.UTF_8);
Lexer lexer = new Lexer(expression);
// System.out.println(lexer.tokens());
Parser parse = new Parser(lexer);
parse.expr();
System.out.write('\n');
/**/
}
Aggregations