Skip to content

Instantly share code, notes, and snippets.

@ar
Created April 15, 2011 20:54
Show Gist options
  • Save ar/922464 to your computer and use it in GitHub Desktop.
Save ar/922464 to your computer and use it in GitHub Desktop.
public class CustomerCreate extends RestActionSupport {
private final String name = "304.301.CUSTOMER";
@Override
protected Map<String, Object> doExecute(DB db, JPublishContext jpc, Configuration c) throws BLException, ISOException {
final ISOMsg request = new ISOMsg("2304");
final Date date = new Date();
request.set(7, getDate(date));
request.set(11, getStan());
request.set(12, getDate(date, "yyyyMMddHHmmss"));
request.set(24, "301");
request.set(101, "CUSTOMER");
final ISOMsg response = sendISOMsg(request, name);
assertResultCode(response);
final String code = response.getString(2);
assertNotNull(code, "Customer id not found on response");
//Extra parameter set
final CardHolderManager chm = new CardHolderManager(db);
final CardHolder ch = chm.getByRealId(code);
assertNotNull(ch, "Customer was not created.");
final Transaction tx = db.beginTransaction();
try {
ch.setFirstName(getParameter("firstName", jpc, false));
ch.setLastName(getParameter("lastName", jpc, false));
ch.setLastName2(getParameter("lastName2", jpc, false));
ch.setGender(getParameter("gender", jpc, false));
ch.setMiddleName(getParameter("middleName", jpc, false));
ch.setHonorific(getParameter("honorific", jpc, false));
db.session().update(ch);
tx.commit();
} catch (HibernateException hibernateException) {
logError(jpc, hibernateException);
tx.rollback();
}
assertFalse(ch.getCards().isEmpty(), "Card holder does not have a card");
final Card card = (Card) ch.getCards().toArray()[0];
//Building result
final Map<String, Object> result = new HashMap<String, Object>();
result.put("id", code);
return result;
}
@Override
protected int getSuccessCode() {
return HTTP_CREATED;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment