Source:
public Credential createAdminAccountAndPassword(String username, String password, String name) { if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) { throw new ClientVisibleException(ResponseCodes.BAD_REQUEST, "UserCredentialCreation", "Cannot have blank username or password.", null); } validatePassword(password); Account account; if (create().selectFrom(CREDENTIAL) .where(CREDENTIAL.PUBLIC_VALUE.eq(username) .and(CREDENTIAL.STATE.eq(CommonStatesConstants.ACTIVE) .and(CREDENTIAL.KIND.eq(CredentialConstants.KIND_PASSWORD)))).fetchAny() != null){ throw new ClientVisibleException(ResponseCodes.CONFLICT, "UsernameIsTaken", "Username: " + username +" is taken", null); } account = create() .selectFrom(ACCOUNT) .where(ACCOUNT.STATE.eq(CommonStatesConstants.ACTIVE) .and(ACCOUNT.KIND.eq(AccountConstants.ADMIN_KIND))) .orderBy(ACCOUNT.ID.asc()).limit(1).fetchOne(); Date now = new Date(System.currentTimeMillis()); create().update(CREDENTIAL).set(CREDENTIAL.STATE, CommonStatesConstants.PURGED) .set(CREDENTIAL.REMOVED, now) .set(CREDENTIAL.REMOVE_TIME, now) .where(CREDENTIAL.ACCOUNT_ID.eq(account.getId()) .and(CREDENTIAL.KIND.eq("password"))) .execute(); if (StringUtils.isNotEmpty(name)) { account.setName(name); } Map<Object, Object> properties = new HashMap<>(); properties.put(CREDENTIAL.PUBLIC_VALUE, username); properties.put(CREDENTIAL.SECRET_VALUE, transformationService.transform(password, EncryptionConstants.HASH)); properties.put(CREDENTIAL.KIND, LocalAuthConstants.PASSWORD); properties.put(CREDENTIAL.ACCOUNT_ID, account.getId()); properties.put(CREDENTIAL.STATE, CommonStatesConstants.ACTIVE); DataAccessor.fields(account).withKey(SecurityConstants.HAS_LOGGED_IN).set(true); objectManager.persist(account); return objectManager.create(Credential.class, objectManager.convertToPropertiesFor(Credential.class, properties)); }

Target:
public Credential createAdminAccountAndPassword(String username, String password, String name) { if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) { throw new ClientVisibleException(ResponseCodes.BAD_REQUEST, "UserCredentialCreation", "Cannot have blank username or password.", null); } Account account; if (create().selectFrom(CREDENTIAL) .where(CREDENTIAL.PUBLIC_VALUE.eq(username) .and(CREDENTIAL.STATE.eq(CommonStatesConstants.ACTIVE) .and(CREDENTIAL.KIND.eq(CredentialConstants.KIND_PASSWORD)))).fetchAny() != null){ throw new ClientVisibleException(ResponseCodes.CONFLICT, "UsernameIsTaken", "Username: " + username +" is taken", null); } account = create() .selectFrom(ACCOUNT) .where(ACCOUNT.STATE.eq(CommonStatesConstants.ACTIVE) .and(ACCOUNT.KIND.eq(AccountConstants.ADMIN_KIND))) .orderBy(ACCOUNT.ID.asc()).limit(1).fetchOne(); Date now = new Date(System.currentTimeMillis()); create().update(CREDENTIAL).set(CREDENTIAL.STATE, CommonStatesConstants.PURGED) .set(CREDENTIAL.REMOVED, now) .set(CREDENTIAL.REMOVE_TIME, now) .where(CREDENTIAL.ACCOUNT_ID.eq(account.getId()) .and(CREDENTIAL.KIND.eq("password"))) .execute(); if (StringUtils.isNotEmpty(name)) { account.setName(name); } Map<Object, Object> properties = new HashMap<>(); properties.put(CREDENTIAL.PUBLIC_VALUE, username); properties.put(CREDENTIAL.SECRET_VALUE, transformationService.transform(password, EncryptionConstants.HASH)); properties.put(CREDENTIAL.KIND, LocalAuthConstants.PASSWORD); properties.put(CREDENTIAL.ACCOUNT_ID, account.getId()); properties.put(CREDENTIAL.STATE, CommonStatesConstants.ACTIVE); DataAccessor.fields(account).withKey(SecurityConstants.HAS_LOGGED_IN).set(true); objectManager.persist(account); return objectManager.create(Credential.class, objectManager.convertToPropertiesFor(Credential.class, properties)); }