use of ca.uhn.hl7v2.HL7Exception in project tdi-studio-se by Talend.
the class HL7PublicUtil method getFirstLevelChild.
public List getFirstLevelChild(Object parentElement) {
List values = new ArrayList();
if (parentElement instanceof Message) {
Message messParent = (Message) parentElement;
String[] childNames = messParent.getNames();
if (!values.isEmpty()) {
values.clear();
}
for (int i = 0; i < childNames.length; i++) {
try {
Structure[] childReps = messParent.getAll(childNames[i]);
for (int j = 0; j < childReps.length; j++) {
if (childReps[j] instanceof Message) {
values.add(childReps[j]);
}
if (childReps[j] instanceof Group) {
values.add(childReps[j]);
allSegmentFromGroup.clear();
getAllSegmentsFromGroup((Group) childReps[j]);
}
if (childReps[j] instanceof Segment) {
SegmentModel sModel = new SegmentModel((Segment) childReps[j], messParent, i, j);
if (sModel.getTypes() != null && sModel.getTypes().length > 0) {
values.add(sModel);
if (!allSegmentsForMessage.contains(sModel)) {
allSegmentsForMessage.add(sModel);
}
}
}
}
} catch (HL7Exception e) {
e.printStackTrace();
}
}
}
return values;
}
use of ca.uhn.hl7v2.HL7Exception in project tdi-studio-se by Talend.
the class TypeModel method getComponent.
private Type getComponent(Type type, int comp) {
Type ret = null;
if (Varies.class.isAssignableFrom(type.getClass())) {
Varies v = (Varies) type;
try {
if (comp > 1 && GenericPrimitive.class.isAssignableFrom(v.getData().getClass())) {
v.setData(new GenericComposite(v.getMessage()));
}
} catch (DataTypeException de) {
String message = "Unexpected exception copying data to generic composite: " + de.getMessage();
throw new Error(message);
}
ret = getComponent(v.getData(), comp);
} else {
if (Primitive.class.isAssignableFrom(type.getClass()) && comp == 1) {
ret = type;
} else if (GenericComposite.class.isAssignableFrom(type.getClass()) || (Composite.class.isAssignableFrom(type.getClass()) && comp <= numStandardComponents(type))) {
try {
ret = ((Composite) type).getComponent(comp - 1);
} catch (Exception e) {
throw new Error("Internal error: HL7Exception thrown on getComponent(x) where x < # standard components.", e);
}
} else {
ret = type.getExtraComponents().getComponent(comp - numStandardComponents(type) - 1);
}
}
return ret;
}
use of ca.uhn.hl7v2.HL7Exception in project tdi-studio-se by Talend.
the class SegmentModel method generateDataTypes.
private void generateDataTypes() {
int number = this.seg.numFields();
ArrayList<TypeModel> datatypes = new ArrayList<TypeModel>();
Method method = null;
try {
for (Method curMethod : seg.getClass().getDeclaredMethods()) {
if (curMethod.getName().equals("createNewTypeWithoutReflection")) {
method = curMethod;
method.setAccessible(true);
break;
}
}
if (method != null) {
// so add test of null in case this method doesn't exist, even if it should be in every subclass.
for (int i = 0; i < number; i++) {
Type type = (Type) method.invoke(seg, i);
TypeModel tm = new TypeModel(type, seg, 0, i + 1);
datatypes.add(tm);
}
}
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (method == null) {
// but it means it won't get optional fields.
try {
int lastNotEmptyFiledIndex = 0;
for (int i = 1; i < number; i++) {
Type[] reps = seg.getField(i);
if (reps.length > 0) {
lastNotEmptyFiledIndex = i;
}
}
for (int i = 1; i <= lastNotEmptyFiledIndex; i++) {
Type[] reps = seg.getField(i);
if (reps.length > 0) {
for (int j = 0; j < reps.length; j++) {
TypeModel tm = new TypeModel(reps[j], seg, j, i);
datatypes.add(tm);
}
} else {
// for empty column
TypeModel tm = new TypeModel(null, seg, 0, i);
datatypes.add(tm);
}
}
} catch (HL7Exception e) {
e.printStackTrace();
}
}
this.types = datatypes.toArray(new TypeModel[0]);
}
use of ca.uhn.hl7v2.HL7Exception in project tdi-studio-se by Talend.
the class HL7PublicUtil method getChildren.
public Set getChildren(Object parentElement) {
// List values = new ArrayList();
Set values = new HashSet();
if (parentElement instanceof Message) {
Message messParent = (Message) parentElement;
String[] childNames = messParent.getNames();
if (!values.isEmpty()) {
values.clear();
}
for (int i = 0; i < childNames.length; i++) {
try {
Structure[] childReps = messParent.getAll(childNames[i]);
for (int j = 0; j < childReps.length; j++) {
if (childReps[j] instanceof Message) {
values.add(childReps[j]);
if (getChildren(childReps[j]).size() > 0) {
values.addAll(getChildren(childReps[j]));
}
}
if (childReps[j] instanceof Group) {
values.add(childReps[j]);
allSegmentFromGroup.clear();
getAllSegmentsFromGroup((Group) childReps[j]);
}
if (childReps[j] instanceof Segment) {
SegmentModel sModel = new SegmentModel((Segment) childReps[j], messParent, i, j);
if (sModel.getTypes() != null && sModel.getTypes().length > 0) {
values.add(sModel);
if (getChildren(sModel).size() > 0) {
values.addAll(getChildren(sModel));
}
if (!allSegmentsForMessage.contains(sModel)) {
allSegmentsForMessage.add(sModel);
}
}
}
}
// values.addAll(Arrays.asList(childReps));
} catch (HL7Exception e) {
e.printStackTrace();
}
}
return values;
}
if (parentElement instanceof Segment) {
values.clear();
Segment segment = (Segment) parentElement;
SegmentModel sm = new SegmentModel(segment, segment, 0, 0);
TypeModel[] models = sm.getTypes();
for (TypeModel model : models) {
values.add(model);
if (getChildren(model).size() > 0) {
values.addAll(getChildren(model));
}
}
return values;
}
if (parentElement instanceof SegmentModel) {
SegmentModel sm = (SegmentModel) parentElement;
TypeModel[] models = sm.getTypes();
for (TypeModel model : models) {
values.add(model);
if (getChildren(model).size() > 0) {
values.addAll(getChildren(model));
}
}
return values;
}
if (parentElement instanceof TypeModel) {
TypeModel tm = (TypeModel) parentElement;
PrimitiveModel[] models = tm.getPrimitives();
for (PrimitiveModel model : models) {
values.add(model);
if (getChildren(model).size() > 0) {
values.addAll(getChildren(model));
}
}
return values;
// return tm.getPrimitives();
}
if (parentElement instanceof Group) {
values.clear();
Group group = (Group) parentElement;
String[] childNames = group.getNames();
for (int i = 0; i < childNames.length; i++) {
try {
Structure[] childReps = group.getAll(childNames[i]);
for (int j = 0; j < childReps.length; j++) {
if (childReps[j] instanceof Segment) {
SegmentModel sm = new SegmentModel((Segment) childReps[j], group, i, j);
if (sm.getTypes() != null && sm.getTypes().length > 0) {
values.add(sm);
if (getChildren(sm).size() > 0) {
values.addAll(getChildren(sm));
}
}
} else {
values.add(childReps[j]);
if (getChildren(childReps[j]).size() > 0) {
values.addAll(getChildren(childReps[j]));
}
}
}
// values.addAll(Arrays.asList(childReps));
} catch (HL7Exception e) {
e.printStackTrace();
}
}
return values;
}
return values;
}
use of ca.uhn.hl7v2.HL7Exception in project camel by apache.
the class ValidationContextPredicate method matches.
@Override
public boolean matches(Exchange exchange) {
try {
Message message = exchange.getIn().getBody(Message.class);
ValidationContext context = validatorExpression != null ? validatorExpression.evaluate(exchange, ValidationContext.class) : dynamicValidationContext(message, exchange.getIn().getHeader(HL7Constants.HL7_CONTEXT, HapiContext.class));
MessageValidator validator = new MessageValidator(context, false);
return validator.validate(message);
} catch (HL7Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
}
Aggregations