private void validateNonEmptyFields(ActionVO<Integer, Integer> action, boolean useDateFromVO) { if (action.getTenant() == null) { throw new IllegalArgumentException( "missing constraints, unique key (tenantId, itemTypeId, actionTypeId, actionTime) must be set, missing 'tenantId'"); } if (action.getItem() == null) { throw new IllegalArgumentException( "missing constraints, unique key (tenantId, itemTypeId, actionTypeId, actionTime) must be set, missing 'item'"); } if (action.getItem().getType() == null) { throw new IllegalArgumentException( "missing constraints, unique key (tenantId, itemTypeId, actionTypeId, actionTime) must be set, missing 'itemTypeId'"); } if (action.getActionType() == null) { throw new IllegalArgumentException( "missing constraints, unique key (tenantId, itemTypeId, actionTypeId, actionTime) must be set, missing 'actionTypeId'"); } // in case of automatically generated 'actionTime' on database level leave out check for null if (useDateFromVO && action.getActionTime() == null) { throw new IllegalArgumentException( "missing constraints, unique key (tenantId, itemTypeId, actionTypeId, actionTime) must be set, missing 'actionTime'"); } }
sumCurrentRatingValues += actionMapping.get(currentAction.getActionType()).floatValue(); countCurrentActions++; action = currentAction; action = actionsIterator.next(); return new RatingVO<Integer, String>(action.getItem(), actionMapping.get(action.getActionType()), actionsForTenantUserItemTriple.size(), action.getActionTime(), action.getUser()); Double currentRatingValue; for (ActionVO<Integer, String> currentAction : actionsForTenantUserItemTriple) { currentRatingValue = actionMapping.get(currentAction.getActionType()); if (currentRatingValue > maxRatingValue) { maxRatingValue = currentRatingValue; actionMapping.get(action.getActionType()), actionsForTenantUserItemTriple.size(), action.getActionTime(), action.getUser()); } else if (TypeMappingService.AGGREGATE_TYPE_MOST_FREQUENT.equals(aggregateType)) { Integer currentCounter = actionCounter.get(currentAction.getActionType()); if (currentCounter != null) { currentCounter++; actionCounter.put(currentAction.getActionType(), currentCounter); if (currentAction.getActionType() == actionType) { return new RatingVO<Integer, String>(currentAction.getItem(), actionMapping.get(currentAction.getActionType()), actionsForTenantUserItemTriple.size(), action.getActionTime(), currentAction.getUser());
public int generateActions(int tenantId, TIntSet itemTypeIds, int actionTypeId, Date since) { Preconditions.checkNotNull(itemTypeIds); Preconditions.checkArgument(itemTypeIds.size() > 0, "at least one itemtype must be given"); if (since == null) since = getNewestActionDate(tenantId, itemTypeIds); if (isOnSameDataSourceAsEasyrec()) { Object[] args = new Object[]{tenantId, actionTypeId, since}; String query = QUERY_GENERATE.replace("@@@", generateItemTypeInClause(itemTypeIds)); return getJdbcTemplate().update(query, args, ARGT_GENERATE); } // when not on same datasource the tenantId is ignored and all actions are copied Iterator<ActionVO<Integer, Integer>> actions = actionDAO .getActionIterator(5000, new TimeConstraintVO(since, null)); int result = 0; while (actions.hasNext()) { ActionVO<Integer, Integer> actionVO = actions.next(); if (actionVO.getTenant() != tenantId) continue; if (actionVO.getActionType() != actionTypeId) continue; if (!itemTypeIds.contains(actionVO.getItem().getType())) continue; result += insertAction(actionVO); } return result; }
if (action.getActionType() == null) { AutoImportUtils.logSkippedLine(logger, lineCounter, line, "no value for field 'actionTypeId' is set");
public int generateActions(final Integer tenantId, final Date since) { if (isOnSameDataSourceAsEasyrec()) { String query; int[] argt; Object[] args; if (since == null) { query = QUERY_GENERATE; argt = ARGT_GENERATE; args = new Object[]{tenantId}; } else { query = QUERY_GENERATE_SINCE; argt = ARGT_GENERATE_SINCE; args = new Object[]{tenantId, since}; } return getJdbcTemplate().update(query, args, argt); } Iterator<ActionVO<Integer, Integer>> actions = actionDAO .getActionIterator(5000, new TimeConstraintVO(since, null)); int result = 0; while (actions.hasNext()) { ActionVO<Integer, Integer> actionVO = actions.next(); Object[] args = new Object[]{actionVO.getTenant(), actionVO.getUser(), actionVO.getItem().getItem(), actionVO.getItem().getType(), actionVO.getActionType(), actionVO.getRatingValue(), actionVO.getActionTime()}; result += getJdbcTemplate().update(QUERY_INSERT, args, ARGT_INSERT); } return result; }
@Override public int insertAction(ActionVO<Integer, Integer> action, boolean useDateFromVO) { if (logger.isTraceEnabled()) { logger.trace("inserting action=" + action); } // validate non-empty fields (NOT NULL) validateNonEmptyFields(action, useDateFromVO); Object[] args = {action.getTenant(), action.getUser(), action.getSessionId(), action.getIp(), ((action.getItem() != null) ? action.getItem().getItem() : null), ((action.getItem() != null) ? action.getItem().getType() : null), action.getActionType(), action.getRatingValue(), action.getSearchSucceeded(), action.getNumberOfFoundItems(), action.getDescription(), ((useDateFromVO && action.getActionTime() != null) ? action.getActionTime() : new Date(System.currentTimeMillis()))}; KeyHolder keyHolder = new GeneratedKeyHolder(); int rowsAffected = getJdbcTemplate().update(PS_INSERT_ACTION.newPreparedStatementCreator(args), keyHolder); // retrieve auto increment id, and set to VO action.setId(keyHolder.getKey().intValue()); return rowsAffected; }
@Override public ActionVO<Integer, String> convertActionVO(Integer tenantId, ActionVO<Integer, Integer> action) { if (action == null) { return null; } return new ActionVO<Integer, String>( action.getId(), action.getTenant(), action.getUser(), action.getSessionId(), action.getIp(), convertItemVO(tenantId, action.getItem()), actionTypeDAO.getTypeById(tenantId, action.getActionType()), action.getRatingValue(), action.getSearchSucceeded(), action.getNumberOfFoundItems(), action.getDescription(), action.getActionTime()); }
@Override public ActionVO<Integer, Integer> convertTypedActionVO(Integer tenantId, ActionVO<Integer, String> typedAction) { if (typedAction == null) { return null; } return new ActionVO<Integer, Integer>( typedAction.getId(), typedAction.getTenant(), typedAction.getUser(), typedAction.getSessionId(), typedAction.getIp(), convertTypedItemVO(tenantId, typedAction.getItem()), actionTypeDAO.getIdOfType(tenantId, typedAction.getActionType()), typedAction.getRatingValue(), typedAction.getSearchSucceeded(), typedAction.getNumberOfFoundItems(), typedAction.getDescription(), typedAction.getActionTime()); }