protected void assertTrue (boolean condition, String message) throws BLException { if (!condition) throw new BLException (message); } protected void assertFalse (boolean condition, String message)
protected void assertFalse (boolean condition, String message) throws BLException { if (condition) throw new BLException (message); } protected void assertTrue
protected void assertNull (Object obj, String message) throws BLException { if (obj != null) throw new BLException (message); } protected void assertNull (Object obj, String message, String detail)
protected void assertNotNull (Object obj, String message) throws BLException { if (obj == null) throw new BLException (message); } protected void assertNotNull (Object obj, String message, String detail)
protected void assertNotNull (Object obj, String error) throws BLException { if (obj == null) throw new BLException (error); } protected void assertTrue (boolean condition, String error)
protected void assertFalse (boolean condition, String message, String detail) throws BLException { if (condition) throw new BLException (message, detail); } protected void assertNotNull (Object obj, String message)
protected void assertTrue (boolean condition, String message, String detail) throws BLException { if (!condition) throw new BLException (message, detail); } protected void assertFalse
protected void assertNotNull (Object obj, String message, String detail) throws BLException { if (obj == null) throw new BLException (message, detail); } protected void assertNotNull (Object obj, int resultCode)
protected void assertNull (Object obj, String message, String detail) throws BLException { if (obj != null) throw new BLException (message, detail); } protected void checkPoint (Context ctx) {
protected void assertTrue (boolean condition, String error) throws BLException { if (!condition) throw new BLException (error); }
protected void assertNotNull (Object obj, int resultCode) throws BLException { if (obj == null) throw new BLException (Integer.toString (resultCode)); } protected void assertNotNull (Object obj, int resultCode, String detail)
protected void assertNotNull (Object obj, int resultCode, String detail) throws BLException { if (obj == null) throw new BLException (Integer.toString (resultCode), detail); } protected void assertNotNull (Map map, String[] props, String message)
public void validate () throws BLException { if (transaction.getEntries().size() == 0) { setComponentError(new UserError("Transaction has no entries")); throw new BLException("Transaction has no entries"); } }
private void checkMandatoryJson (Context ctx) throws BLException { for (Map.Entry<String,JsonSchema> entry : mandatoryJson.entrySet()) { String value = ctx.getString(entry.getKey()); ProcessingReport report; if (value != null) { try { JsonSchema schema = entry.getValue(); JsonNode node = JsonLoader.fromString(value); report = schema.validate(node); } catch(Exception ex) { throw new BLException(ex.getMessage()); } assertTrue(report.isSuccess(), report.toString()); } } }
private void checkOptionalJson (Context ctx) throws BLException { for (Map.Entry<String,JsonSchema> entry : optionalJson.entrySet()) { String value = ctx.getString(entry.getKey()); ProcessingReport report; if (value != null) { try { JsonSchema schema = entry.getValue(); JsonNode node = JsonLoader.fromString(value); report = schema.validate(node); } catch(Exception ex) { throw new BLException(ex.getMessage()); } assertTrue(report.isSuccess(), report.toString()); } } } }
@Override public boolean updateEntity (Binder binder) throws BLException { try { return (boolean) DB.execWithTransaction( (db) -> { Role oldRole = (Role) ((Role) getOriginalEntity()).clone(); binder.writeBean(getOriginalEntity()); Role r = (Role) getOriginalEntity(); db.session().merge(r); return addRevisionUpdated(db, getEntityName(), String.valueOf(r.getId()), oldRole, r, new String[]{"name", "permissions"}); }); } catch (Exception e) { throw new BLException(e.getMessage()); } }
@Override public boolean saveEntity (Binder binder) throws BLException { SysConfig entity = (SysConfig) getOriginalEntity(); if (binder.writeBeanIfValid(getOriginalEntity())) { String id = entity.getId(); id = prefix != null ? prefix + id : id; if (getSysConfig(id) == null) { final String finalId = id; try { return (boolean) DB.execWithTransaction((db) -> { SysConfigManager mgr = new SysConfigManager(db, prefix); mgr.put(entity.getId(), entity.getValue()); addRevisionCreated(db, "SYSCONFIG", finalId); return true; }); } catch (Exception e) { QI.getQI().getLog().error(e); return false; } } else { throw new BLException("SysConfig " + id + " already exists."); } } else { throw new BLException("Invalid SysConfig"); } }
@Override public Result<Account> convertToModel(String value, ValueContext valueContext) { if (value != null && !value.isEmpty()) { try { Account acct = (Account) DB.exec(db -> { GLSession session = new GLSession(db); Account res = session.getAccount("jcard",value); if (res == null && createNew) { if (createFinal) res = new FinalAccount(); else res = new CompositeAccount(); res.setCode(value); } else if (res == null) { throw new BLException("Invalid Account Code"); } return res; }); return Result.ok(acct); } catch (Exception e) { return Result.error(e.getMessage()); } } if (required) return Result.error(QI.getQI().getMessage("errorMessage.req", QI.getQI().getMessage("account"))); else return Result.ok(null); }
protected boolean saveEntity (Binder binder, EntryGrid entryGrid) throws BLException { try { return (boolean) DB.execWithTransaction(db -> { if (binder.writeBeanIfValid(getOriginalEntity())) { GLTransaction txn = (GLTransaction) getOriginalEntity(); List<GLEntry> entries = entryGrid.getValue().getEntries(); //Reset ids to 0 for (GLEntry e : entries) e.setId(0); txn.setEntries(entries); txn.setTimestamp(new Date()); GLSession glSession = new GLSession(db); glSession.post(txn.getJournal(), txn); addRevisionCreated(db, getEntityName(), getItemId(getOriginalEntity())); return true; } return false; }); } catch (Exception e) { throw new BLException(e.getMessage()); } }
public boolean saveUser (Binder binder, String clearPass) throws BLException { User u = (User) getOriginalEntity(); if (binder.writeBeanIfValid(getOriginalEntity())) { try { return (boolean) DB.execWithTransaction((db) -> { db.save(u); if (clearPass != null && !clearPass.isEmpty()) { UserManager mgr = new UserManager(db); try { mgr.setPassword(u, clearPass); } catch (BLException e) { return false; } addRevisionCreated(db, getEntityName(), u.getId().toString()); u.setForcePasswordChange(true); db.session().update(u); return true; } return false; }); } catch (Exception e) { getApp().getLog().error(e); return false; } } else { throw new BLException("Invalid user"); } }