/** * We need to make sure that we account for failed upgrades - the QA-EACJ migration showed that * the table may linger but the sequence ids go * * @param entityName * @param nextId * @throws GenericEntityException */ private void setNextId(String entityName, Long nextId) throws GenericEntityException { final GenericDelegator delegator = getDelegator(); // First ensure we have an entry in SequenecValueItem table delegator.getNextSeqId(entityName); // Now set it to nextId GenericValue sequenceItem = EntityUtil.getOnly( delegator.findByAnd("SequenceValueItem", ImmutableMap.of("seqName", entityName))); if (sequenceItem != null) { sequenceItem.set("seqId", nextId); sequenceItem.store(); delegator.refreshSequencer(); } }
/** * Creates a reward type * * @param rt the type of the reward, e.g. 'Beer' * @return the reward type, created */ @Override public RewardType addRewardType(RewardType rt) { try { long id = delegator.getNextSeqId(ENTITY); rt.setId(id); delegator.create(toGenericValue(rt)); return rt; } catch (GenericEntityException e) { String msg = String.format( "Could not create reward type ('%s', '%s') ?!?", rt.getName(), rt.getDescription()); LOG.error(msg); throw new OfbizDataException(msg, e); } }
@Test public void testGetCredentialHistory() throws Exception { final User createdUser = userDao.add(TestData.User.getTestData(), TestData.User.CREDENTIAL); OfBizHelper ofBiz = new OfBizHelper(GenericDelegator.getGenericDelegator("default")); ofBiz.createValue( UserCredentialHistoryEntity.ENTITY, UserCredentialHistoryEntity.getData(((OfBizUser) createdUser).getId(), "secret1", 2)); ofBiz.createValue( UserCredentialHistoryEntity.ENTITY, UserCredentialHistoryEntity.getData(((OfBizUser) createdUser).getId(), "secret3", 1)); ofBiz.createValue( UserCredentialHistoryEntity.ENTITY, UserCredentialHistoryEntity.getData(((OfBizUser) createdUser).getId(), "secret2", 3)); final List<PasswordCredential> credentials = userDao.getCredentialHistory(TestData.DIRECTORY_ID, TestData.User.NAME); assertEquals(3, credentials.size()); assertEquals( Arrays.asList( new PasswordCredential("secret3", true), new PasswordCredential("secret1", true), new PasswordCredential("secret2", true)), credentials); }
private GenericValue toGenericValue(RewardType rt) { Map<String, Object> map = new HashMap<String, Object>(); map.put(ID_FIELD, rt.getId()); map.put(NAME_FIELD, rt.getName()); map.put(NAMEPL_FIELD, rt.getNamePluralForm()); map.put(DESC_FIELD, rt.getDescription()); map.put(ICON_FIELD, rt.getIconURL()); return delegator.makeValue(ENTITY, map); }
/** * Gets all the reward types * * @return the reward */ @Override public List<RewardType> getRewardTypes() { try { List<GenericValue> list = delegator.findAll(ENTITY); return fromGenericValue(list); } catch (GenericEntityException e) { String msg = "Could not load all rewards types ?!?"; LOG.error(msg); throw new OfbizDataException(msg, e); } }
/** * Gets the types * * @param id the id * @return the RewardType */ @Override public RewardType getRewardType(long id) { try { GenericValue ret = delegator.findByPrimaryKey(ENTITY, makePk(id)); return (ret != null ? fromGenericValue(ret) : null); } catch (GenericEntityException e) { String msg = String.format("Could not load reward type (id=%d) ?!?", id); LOG.error(msg); throw new OfbizDataException(msg, e); } }
private GenericPK makePk(long id) { Map<String, Object> map = new HashMap<String, Object>(); map.put(ID_FIELD, id); return delegator.makePK(ENTITY, map); }
/** Constructor */ public RewardTypeDataServiceImpl() { this.delegator = GenericDelegator.getGenericDelegator("default"); }