use of org.jaffa.transaction.domain.TransactionField in project jaffa-framework by jaffa-projects.
the class JaffaTransactionMessageService method getTransactionField.
/**
* Gets the TransactionField with the input Transaction ID and field name.
*
* @param transactionId the ID of the Transaction the TransactionField is part of
* @param fieldName the field name of the TransactionField to return
* @return the TransactionField with the input Transaction ID and field name
* @throws FrameworkException
*/
@Override
public TransactionField getTransactionField(String transactionId, String fieldName) throws FrameworkException {
UOW uow = null;
TransactionField field = null;
try {
uow = new UOW();
Criteria criteria = new Criteria();
criteria.setTable(TransactionFieldMeta.getName());
criteria.addCriteria(TransactionFieldMeta.TRANSACTION_ID, transactionId);
criteria.addCriteria(TransactionFieldMeta.FIELD_NAME, fieldName);
for (Object result : uow.query(criteria)) {
if (result instanceof TransactionField) {
field = (TransactionField) result;
break;
}
}
} finally {
if (uow != null) {
uow.close();
}
}
return field;
}
use of org.jaffa.transaction.domain.TransactionField in project jaffa-framework by jaffa-projects.
the class JaffaTransactionMessageService method getFieldByNameValue.
/**
* Get a TansactionField given its name and value.
*
* @param fieldName the name of the field to return
* @param fieldValue the value of the field to return
* @return the TransactionField with the input fieldName and value
* @throws FrameworkException
*/
@Override
public TransactionField getFieldByNameValue(String fieldName, String fieldValue) throws FrameworkException {
UOW uow = null;
TransactionField transactionField = null;
try {
uow = new UOW();
Criteria criteria = new Criteria();
criteria.setTable(TransactionFieldMeta.getName());
AtomicCriteria ac = new AtomicCriteria();
ac.addCriteria(TransactionFieldMeta.FIELD_NAME, fieldName);
criteria.addAtomic(ac);
criteria.addCriteria(TransactionFieldMeta.VALUE, fieldValue);
for (Object result : uow.query(criteria)) {
if (!(result instanceof TransactionField)) {
continue;
}
transactionField = (TransactionField) result;
}
} finally {
if (uow != null) {
uow.close();
}
}
return transactionField;
}
use of org.jaffa.transaction.domain.TransactionField in project jaffa-framework by jaffa-projects.
the class JaffaTransactionMessageService method createTransactionFields.
/**
* Create an array of {@link org.jaffa.transaction.domain.TransactionField} based on the fields of the {@link org
* .jaffa.transaction.domain.Transaction}
*
* @param transaction the transaction to create fields for
* @param dataBean the internal object of the transaction payload
* @return an array of {@link org.jaffa.transaction.domain.TransactionField}
* @throws FrameworkException
* @throws ApplicationExceptions
*/
private Collection<TransactionField> createTransactionFields(Transaction transaction, Object dataBean) throws FrameworkException, ValidationException, ApplicationExceptions {
Collection<TransactionField> transactionFields = new LinkedList<TransactionField>();
// Create a TransactionField object for each header element as defined in the configuration file
final TransactionInfo transactionInfo = transaction.getTransactionInfo();
if ((transactionInfo.getHeader() != null) && (transactionInfo.getHeader().getParam() != null)) {
for (Param param : transactionInfo.getHeader().getParam()) {
// get the value of the header parameter
String value = TransactionEngine.obtainParamValue(param, dataBean);
// create a transaction field and set its ID
TransactionField transactionField = new TransactionField();
transactionField.setTransactionId(transaction.getId());
// set the name and value of the transaction field, then add it to the list of all transaction fields
transactionField.setFieldName(param.getName());
transactionField.setValue(value);
transactionFields.add(transactionField);
}
}
return transactionFields;
}
use of org.jaffa.transaction.domain.TransactionField in project jaffa-framework by jaffa-projects.
the class TransactionAdmin method createMessageGraph.
/**
* Molds the input Transaction into a MessageGraph.
*/
private static MessageGraph createMessageGraph(Transaction transaction, PropertyFilter pf) throws FrameworkException {
MessageGraph graph = new MessageGraph();
graph.setQueueMetaData(createQueueMetaData(transaction.getSubType(), pf));
if (pf.isFieldIncluded("type")) {
graph.setType(transaction.getType());
}
if (pf.isFieldIncluded("subType")) {
graph.setSubType(transaction.getSubType());
}
if (pf.isFieldIncluded("messageId")) {
graph.setMessageId(transaction.getId());
}
if (pf.isFieldIncluded("direction")) {
graph.setDirection(transaction.getDirection());
}
if (pf.isFieldIncluded("status")) {
graph.setStatus(transactionToMessageStatus(transaction.getStatus()));
}
if (pf.isFieldIncluded("createdOn")) {
graph.setCreatedOn(transaction.getCreatedOn());
}
if (pf.isFieldIncluded("createdBy")) {
graph.setCreatedBy(transaction.getCreatedBy());
}
if (pf.isFieldIncluded("lastChangedOn")) {
graph.setLastChangedOn(transaction.getLastChangedOn());
}
if (pf.isFieldIncluded("lastChangedBy")) {
graph.setLastChangedBy(transaction.getLastChangedBy());
}
if (pf.isFieldIncluded("errorMessage")) {
graph.setErrorMessage(transaction.getErrorMessage());
}
if (pf.isFieldIncluded("payload")) {
graph.setPayload(transaction.getTransactionPayloadObject() != null ? transaction.getTransactionPayloadObject().returnInternalPayload() : null);
}
if (pf.isFieldIncluded("hasAdminAccess")) {
graph.setHasAdminAccess(TransactionEngine.getInstance().hasAdminAccess(transaction.getType()));
}
if (pf.isFieldIncluded("applicationFields")) {
Map<String, MessageField> applicationFields = new LinkedHashMap<String, MessageField>();
TransactionField[] transactionFields = transaction.getTransactionFieldArray();
if (transactionFields != null && transactionFields.length > 0) {
for (int i = 0; i < transactionFields.length; i++) {
TransactionField transactionField = transactionFields[i];
MessageField applicationField = new MessageField();
applicationField.setName(transactionField.getFieldName());
applicationField.setValue(transactionField.getValue());
applicationFields.put(applicationField.getName(), applicationField);
}
}
// Add labels to the application-fields from the configuration-file
TypeInfo typeInfo = ConfigurationService.getInstance().getTypeInfo(transaction.getType());
if (typeInfo != null && typeInfo.getDisplayParam() != null) {
for (DisplayParam displayParam : typeInfo.getDisplayParam()) {
if (displayParam.getLabel() != null && applicationFields.containsKey(displayParam.getName())) {
applicationFields.get(displayParam.getName()).setLabel(MessageHelper.replaceTokens(displayParam.getLabel()));
}
}
}
if (!applicationFields.isEmpty()) {
graph.setApplicationFields(applicationFields.values().toArray(new MessageField[applicationFields.size()]));
}
}
if (pf.isFieldIncluded("messageDependencies")) {
TransactionDependency[] transactionDependencies = transaction.getTransactionDependencyArray();
if (transactionDependencies != null && transactionDependencies.length > 0) {
MessageDependency[] messageDependencies = new MessageDependency[transactionDependencies.length];
for (int i = 0; i < transactionDependencies.length; i++) {
TransactionDependency transactionDependency = transactionDependencies[i];
MessageDependency messageDependency = new MessageDependency();
messageDependency.setDependsOnId(transactionDependency.getDependsOnId());
if (transactionDependency.getStatus() != null) {
MessageDependency.Status messageDependencyStatus = null;
TransactionDependency.Status transactionDependencyStatus = TransactionDependency.Status.valueOf(transactionDependency.getStatus());
switch(transactionDependencyStatus) {
case O:
messageDependencyStatus = MessageDependency.Status.OPEN;
break;
case S:
messageDependencyStatus = MessageDependency.Status.SUCCESS;
break;
}
messageDependency.setStatus(messageDependencyStatus);
}
messageDependencies[i] = messageDependency;
}
graph.setMessageDependencies(messageDependencies);
}
}
return graph;
}
use of org.jaffa.transaction.domain.TransactionField in project jaffa-framework by jaffa-projects.
the class TransactionAdmin method invokeHandler.
/**
* Invokes the intended handler. This Handler must implement the IMessageHandler Interface in order to be invoked.
*
* @param uow
* @param transaction
* @param methodName
* @throws JaffaMessagingFrameworkException
*/
private static void invokeHandler(UOW uow, Transaction transaction, String methodName) throws Exception {
try {
TransactionPayload tp = transaction.getTransactionPayloadObject();
Object dataBean = tp != null ? tp.moldInternalPayload() : null;
if (dataBean != null) {
// Load transaction configuration
TransactionInfo transactionInfo = ConfigurationService.getInstance().getTransactionInfo(tp.getInternalMessageClass());
if (transactionInfo == null) {
throw new JaffaMessagingFrameworkException(JaffaTransactionFrameworkException.TRANSACTION_INFO_MISSING, new Object[] { tp.getInternalMessageClass() });
}
// Obtain the handlerClass
if (transactionInfo.getToClass() == null || transactionInfo.getToClass().length() == 0) {
if (log.isDebugEnabled()) {
log.debug(methodName + " toClass is not defined in data bean configuration: " + transactionInfo.getDataBean());
}
return;
}
Class handlerClass = Class.forName(transactionInfo.getToClass());
// Class dataBeanClass = Class.forName(transactionInfo.getDataBean());
if (IMessageHandler.class.isAssignableFrom(handlerClass)) {
// Unmarshals the Message payload into a dataBean using the dataBeanClassName
Method handlerMethod = null;
Object handlerObject = null;
// Obtain the handler method
try {
handlerMethod = handlerClass.getMethod(methodName, new Class[] { UOW.class, Map.class, Object.class });
} catch (NoSuchMethodException e) {
// Hence use the dataBeanClass specified in the messageInfo to get the appropriate handlerMethod
if (log.isDebugEnabled()) {
log.debug(methodName + " method not found in " + handlerClass.getName());
}
return;
}
handlerObject = handlerClass.newInstance();
Map<String, String> headerMap = new HashMap<String, String>();
// Sets the transactionField elements as defined in the configuration file.
TransactionField[] fields = transaction.getTransactionFieldArray();
if (fields != null) {
for (TransactionField field : fields) {
headerMap.put(field.getFieldName(), field.getValue());
}
}
// Invoke the handler
if (log.isDebugEnabled()) {
log.debug("Invoking the handler " + handlerMethod);
}
handlerMethod.invoke(handlerObject, new Object[] { uow, headerMap, dataBean });
}
}
} catch (Exception e) {
// Just log the error
log.error("Exception thrown while deleting the transaction. Transaction was: " + transaction, e);
throw e;
}
}
Aggregations