private void validateItemTo(ItemVO<Integer, Integer> itemTo) { if (itemTo == null) { throw new IllegalArgumentException("missing ItemVO 'itemTo'"); } else if (itemTo.getItem() == null) { throw new IllegalArgumentException("missing value, ItemVO 'itemTo', missing 'id'"); } else if (itemTo.getType() == null) { throw new IllegalArgumentException("missing value, ItemVO 'itemTo', missing 'typeId'"); } }
private void validateItemFrom(ItemVO<Integer, Integer> itemFrom) { if (itemFrom == null) { throw new IllegalArgumentException("missing ItemVO 'itemFrom'"); } else if (itemFrom.getItem() == null) { throw new IllegalArgumentException("missing value, ItemVO 'itemFrom', missing 'id'"); } else if (itemFrom.getType() == null) { throw new IllegalArgumentException("missing value, ItemVO 'itemFrom', missing 'typeId'"); } }
public float match(ItemVO<Integer, String> item1, ItemVO<Integer, String> item2) { float ret = -1; try { ret = matchers.get(item1.getTenant()).get(item1.getType()).match(item1, item2); } catch (NullPointerException npe) { if (logger.isDebugEnabled()) { logger.debug("Could not match profiles! There seem to be no matchers defined for the given itemTypes!" + "TenantId: " + item1.getTenant() + " ItemTypeId1: " + item1.getType() + " ItemTypeId2: " + item2.getType()); } } return ret; }
public boolean didUserRateItem(final Integer userId, final ItemVO<Integer, Integer> item, final Integer actionTypeId) { final StringBuilder query = new StringBuilder("SELECT * FROM "); query.append(DEFAULT_TABLE_NAME); query.append(" WHERE "); query.append(DEFAULT_TENANT_COLUMN_NAME).append("=? AND "); query.append(DEFAULT_USER_COLUMN_NAME).append("=? AND "); query.append(DEFAULT_ITEM_COLUMN_NAME).append("=? AND "); query.append(DEFAULT_ITEM_TYPE_COLUMN_NAME).append("=? AND "); query.append(DEFAULT_ACTION_TYPE_COLUMN_NAME).append("=? LIMIT 1"); final Object[] args = new Object[]{item.getTenant(), userId, item.getItem(), item.getType(), actionTypeId}; final int[] argt = new int[]{Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER}; final int count = getJdbcTemplate().queryForList(query.toString(), args, argt).size(); return count > 0; }
public Deviation(@Nullable Integer id, ItemVO<Integer, Integer> item1, ItemVO<Integer, Integer> item2, double numerator, long denominator) { validateItems(item1, item2); this.item1Id = item1.getItem(); this.item2Id = item2.getItem(); this.tenantId = item1.getTenant(); this.item1TypeId = item1.getType(); this.item2TypeId = item2.getType(); this.id = id; this.numerator = numerator; this.denominator = denominator; }
public List<ItemVO<Integer, Integer>> getAvailableItemsForTenant(final Integer tenantId, final Integer itemTypeId) { Set<ItemVO<Integer, Integer>> result = new HashSet<ItemVO<Integer, Integer>>(); for (RatingVO<Integer, Integer> rating : ratings) { if (!tenantId.equals(rating.getItem().getTenant())) continue; if (!itemTypeId.equals(rating.getItem().getType())) continue; if (result.contains(rating.getItem())) continue; result.add(rating.getItem()); } return new ArrayList<ItemVO<Integer, Integer>>(result); }
public void setItem1(ItemVO<Integer, Integer> item1) { validateItem(item1); item1Id = item1.getItem(); item1TypeId = item1.getType(); }
public void setItem2(ItemVO<Integer, Integer> item2) { validateItem(item2); item2Id = item2.getItem(); item2TypeId = item2.getType(); }
public DeviationCalculationResult calculate(int userId, List<RatingVO<Integer, Integer>> ratings, Date oldRatingsBeforeThisDate) { if ((ratings == null) || ratings.isEmpty()) throw new IllegalArgumentException("Can't calculate deviations for null or empyty ratings list."); int tenantId = ratings.get(0).getItem().getTenant(); int itemTypeId = ratings.get(0).getItem().getType(); DeviationCalculationResult result = childStrategy.calculate(userId, ratings, oldRatingsBeforeThisDate); List<Deviation> deviations = result.getDeviations(); deviationDAO.insertDeviations(deviations); return new DeviationCalculationResult(deviations, deviations.size(), deviations.size()); } }
public int insertOrUpdateUserAssoc(final UserAssoc userAssoc) { ListIterator<UserAssoc> it = userAssocs.listIterator(); while (it.hasNext()) { UserAssoc ua = it.next(); if (!userAssoc.getTenantId().equals(ua.getTenantId())) continue; if (!userAssoc.getUserFrom().equals(ua.getUserFrom())) continue; if (!userAssoc.getItemTo().getItem().equals(ua.getItemTo().getItem())) continue; if (!userAssoc.getItemTo().getType().equals(ua.getItemTo().getType())) continue; if (!userAssoc.getSourceTypeId().equals(ua.getSourceTypeId())) continue; it.set(ua); return 1; } userAssocs.add(userAssoc); return 1; } }
public List<RatingVO<Integer, Integer>> getLatestRatingsForTenant(final Integer tenantId, final Integer itemTypeId, final Integer itemId, final Integer userId, final Date since) { List<RatingVO<Integer, Integer>> result = new LinkedList<RatingVO<Integer, Integer>>(); for (RatingVO<Integer, Integer> rating : ratings) { if (!rating.getItem().getTenant().equals(tenantId)) continue; if (!rating.getItem().getType().equals(itemTypeId)) continue; if (itemId != null && !rating.getItem().getItem().equals(itemId)) continue; if (userId != null && !rating.getUser().equals(userId)) continue; if (since != null && !rating.getLastActionTime().after(since)) continue; result.add(rating); } return result; }
private void validateUniqueKey(RecommendedItemVO<Integer, Integer> recommendedItem) { if (recommendedItem.getItem() == null) { throw new IllegalArgumentException( "missing constraints, unique key (itemId, itemTypeId, recommendationId) must be set, missing 'item'"); } if (recommendedItem.getItem().getItem() == null) { throw new IllegalArgumentException( "missing constraints, unique key (itemId, itemTypeId, recommendationId) must be set, missing 'itemId'"); } if (recommendedItem.getItem().getType() == null) { throw new IllegalArgumentException( "missing constraints, unique key (itemId, itemTypeId, recommendationId) must be set, missing 'itemTypeId'"); } if (recommendedItem.getRecommendationId() == null) { throw new IllegalArgumentException( "missing constraints, unique key (itemId, itemTypeId, recommendationId) must be set, missing 'recommendationId'"); } }
public boolean didUserRateItem(final Integer userId, final ItemVO<Integer, Integer> item, final Integer actionTypeId) { final Object[] args = new Object[]{item.getTenant(), userId, item.getItem(), item.getType(), actionTypeId}; final int count = getJdbcTemplate().queryForList(QUERY_RATED, args, ARGT_RATED).size(); return count > 0; }
public int insertAction(ActionVO<Integer, Integer> action) { String query = QUERY_INSERT + QUERY_INSERT_VALUE; query = query.substring(0, query.length() - 2); Object[] args = new Object[]{action.getTenant(), action.getUser(), action.getItem().getItem(), action.getItem().getType(), action.getRatingValue(), action.getActionTime()}; return getJdbcTemplate().update(query, args, ARGT_INSERT); }
@Override public ItemVO<Integer, String> convertItemVO(Integer tenantId, ItemVO<Integer, Integer> item) { if (item == null) { return null; } return new ItemVO<Integer, String>(item.getTenant(), item.getItem(), itemTypeDAO.getTypeById(tenantId, item.getType())); }
@Override public ItemVO<Integer, Integer> convertTypedItemVO(Integer tenantId, ItemVO<Integer, String> typedItem) { if (typedItem == null) { return null; } return new ItemVO<Integer, Integer>(typedItem.getTenant(), typedItem.getItem(), itemTypeDAO.getIdOfType(tenantId, typedItem.getType())); }
public int insertOrUpdateUserAssoc(final UserAssoc userAssoc) { final Object[] args = new Object[]{userAssoc.getTenantId(), userAssoc.getUserFrom(), userAssoc.getAssocValue(), userAssoc.getItemTo().getItem(), userAssoc.getItemTo().getType(), userAssoc.getSourceTypeId(), new Date()}; return getJdbcTemplate().update(QUERY_INSERT, args, ARGT_INSERT); } }
public ClusterVO apply( AssociatedItemVO<Integer, Integer> input) { return loadCluster(input.getItem().getTenant(),input.getItem().getItem(),input.getItem().getType()); } });
private void validateOneAttributeSet(ItemAssocVO<Integer,Integer> itemAssoc) { if (itemAssoc == null) { throw new IllegalArgumentException("missing 'itemAssoc'"); } if ((itemAssoc.getId() == null) && (itemAssoc.getTenant() == null) && ((itemAssoc.getItemFrom() == null) || ((itemAssoc.getItemFrom() .getItem() == null) && (itemAssoc.getItemFrom() .getType() == null))) && (itemAssoc.getAssocType() == null) && (itemAssoc.getAssocValue() == null) && ((itemAssoc.getItemTo() == null) || ((itemAssoc.getItemTo().getItem() == null) && (itemAssoc.getItemTo().getType() == null))) && (itemAssoc.getSourceType() == null) && (itemAssoc.getSourceInfo() == null) && (itemAssoc.getViewType() == null) && (itemAssoc.getChangeDate() == null)) { throw new IllegalArgumentException("missing constraints, at least one property of ItemAssocVO must be set"); } }