public int insertTenant(TenantVO tenant) { if (logger.isDebugEnabled()) { logger.debug("inserting tenant '" + tenant.getStringId() + "'"); } StringBuilder query = new StringBuilder("INSERT INTO "); query.append(DEFAULT_TABLE_NAME); query.append(" SET "); query.append(DEFAULT_ID_COLUMN_NAME); query.append(" =?, "); query.append(DEFAULT_STRING_ID_COLUMN_NAME); query.append(" =?, "); query.append(DEFAULT_DESCRIPTION_COLUMN_NAME); query.append(" =?, "); query.append(DEFAULT_RATING_RANGE_MIN_COLUMN_NAME); query.append(" =?, "); query.append(DEFAULT_RATING_RANGE_MAX_COLUMN_NAME); query.append(" =?, "); query.append(DEFAULT_RATING_RANGE_NEUTRAL_COLUMN_NAME); query.append(" =?"); tenant.setId(getNewTenantId()); Object[] args = {tenant.getId(), tenant.getStringId(), tenant.getDescription(), tenant.getRatingRangeMin(), tenant.getRatingRangeMax(), tenant.getRatingRangeNeutral()}; int[] argTypes = {Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.DOUBLE}; PreparedStatementCreatorFactory factory = new PreparedStatementCreatorFactory(query.toString(), argTypes); getJdbcTemplate().update(factory.newPreparedStatementCreator(args)); return tenant.getId(); }
public int setTenantActive(TenantVO tenant, boolean active) { if (logger.isDebugEnabled()) { logger.debug("setting tenant '" + tenant.getStringId() + "' to " + active); } StringBuilder query = new StringBuilder("UPDATE "); query.append(DEFAULT_TABLE_NAME); query.append(" SET "); query.append(DEFAULT_ACTIVE_COLUMN_NAME).append("=?"); query.append(" WHERE "); query.append(DEFAULT_ID_COLUMN_NAME).append("=?"); Object[] args = {active, tenant.getId()}; int[] argTypes = {Types.BOOLEAN, Types.INTEGER}; PreparedStatementCreatorFactory factory = new PreparedStatementCreatorFactory(query.toString(), argTypes); return getJdbcTemplate().update(factory.newPreparedStatementCreator(args)); }
private void performForTenant(final TenantVO tenant) { if (tenant == null) throw new IllegalArgumentException("tenant is null"); final Integer tenantId = tenant.getId(); final Integer actionTypeId = typeMappingService.getIdOfActionType(tenantId, settings.getActionType()); final Integer itemTypeId = typeMappingService.getIdOfItemType(tenantId, settings.getItemType()); final Integer sourceTypeId = typeMappingService.getIdOfSourceType(tenantId, settings.getSourceType()); final Integer minRatingValue = tenant.getRatingRangeMin(); final Integer maxRatingValue = tenant.getRatingRangeMax(); final Date changeDate = new Date(); final List<User> users = userDao.getUsersForTenant(tenantId); final Map<Integer, Double> averageRatings = getAverageUserRatingMap(tenantId, itemTypeId); logger.info("Starting weight calculation."); Date start = new Date(); // calculateWeights(tenantId, actionTypeId, itemTypeId, users, averageRatings); Date end = new Date(); double time = (end.getTime() - start.getTime()) / 1000L; logger.info(String.format("Calculating weights for %s took %.2f seconds", tenant.getStringId(), time)); logger.info("Starting predictions."); start = new Date(); predict(tenantId, actionTypeId, itemTypeId, sourceTypeId, changeDate, users, averageRatings, minRatingValue, maxRatingValue); end = new Date(); time = (end.getTime() - start.getTime()) / 1000L; logger.info(String.format("Calculating USER-ITEM predictions for %s took %.2f seconds", tenant.getStringId(), time)); }
public void afterPropertiesSet() { // for each tenant //build tree from itemassoc List<TenantVO> tenants = tenantService.getAllTenants(); for (TenantVO tenantVO : tenants) { initTenantForClusters(tenantVO); DelegateTree<ClusterVO, ItemAssocVO<Integer,Integer>> tenantClusters = clusters.get(tenantVO.getId()); buildTree(tenantClusters, tenantClusters.getRoot()); //clusters.put(tenantVO.getId(), tenantClusters); } }
tenant.setId(tenantDAO.insertTenant(tenant)); defaultTenantConfig.getActionTypes(); for (String actionType : actionTypes) { actionTypeDAO.insertOrUpdate(tenant.getId(), actionType, i++); if ("RATE".equals(actionType)) { actionTypeDAO.insertOrUpdate(tenant.getId(), actionType, i, true); defaultTenantConfig.getItemTypes(); for (String itemType : itemTypes) { itemTypeDAO.insertOrUpdate(tenant.getId(), itemType, i++); defaultTenantConfig.getAssocTypes(); for (String assocType : assocTypes) { assocTypeDAO.insertOrUpdate(tenant.getId(), assocType, i++); defaultTenantConfig.getAggregateTypes(); for (String aggregateType : aggregateTypes) { aggregateTypeDAO.insertOrUpdate(tenant.getId(), aggregateType, i++); defaultTenantConfig.getSourceTypes(); for (String sourceType : sourceTypes) { sourceTypeDAO.insertOrUpdate(tenant.getId(), sourceType, i++); defaultTenantConfig.getViewTypes(); for (String viewType : viewTypes) { viewTypeDAO.insertOrUpdate(tenant.getId(), viewType, i++); defaultTenantConfig.getAuthenticationDomains();
public TenantVO mapRow(ResultSet rs, int rowNum) throws SQLException { TenantVO tenant = new TenantVO(DaoUtils.getInteger(rs, DEFAULT_ID_COLUMN_NAME), DaoUtils.getStringIfPresent(rs, DEFAULT_STRING_ID_COLUMN_NAME), DaoUtils.getStringIfPresent(rs, DEFAULT_DESCRIPTION_COLUMN_NAME), DaoUtils.getInteger(rs, DEFAULT_RATING_RANGE_MIN_COLUMN_NAME), DaoUtils.getInteger(rs, DEFAULT_RATING_RANGE_MAX_COLUMN_NAME), DaoUtils.getDouble(rs, DEFAULT_RATING_RANGE_NEUTRAL_COLUMN_NAME), DaoUtils.getBoolean(rs, DEFAULT_ACTIVE_COLUMN_NAME)); return tenant; } }
sourceTypeId = typeMappingService.getIdOfSourceType(tenant.getId(), sourceType); } catch (IllegalArgumentException iae) { logger.info(String.format("Source type %s not defined for tenant %d", sourceType, tenant.getId())); continue; int removedRows = itemAssocDAO.removeItemAssocByTenant(tenant.getId(), null, sourceTypeId, null); removedRows, sourceTypeId, tenant.getId()));
itemTypeId = itemTypeDAO.getIdOfType(tenantVO.getId(), ClusterService.ITEMTYPE_CLUSTER); itemTypeDAO.insertOrUpdate(tenantVO.getId(), ClusterService.ITEMTYPE_CLUSTER, false); } catch (IllegalArgumentException iae) { itemTypeId = tenantService.insertItemTypeForTenant(tenantVO.getId(), ClusterService.ITEMTYPE_CLUSTER, false); assocTypeDAO.getIdOfType(tenantVO.getId(), ClusterService.ASSOCTYPE_CLUSTER); assocTypeDAO.insertOrUpdate(tenantVO.getId(), ClusterService.ASSOCTYPE_CLUSTER, false); } catch (IllegalArgumentException iae2) { tenantService.insertAssocTypeForTenant(tenantVO.getId(), ClusterService.ASSOCTYPE_CLUSTER, false); assocTypeDAO.getIdOfType(tenantVO.getId(), ClusterService.ASSOCTYPE_BELONGSTO); assocTypeDAO.insertOrUpdate(tenantVO.getId(), ClusterService.ASSOCTYPE_BELONGSTO, false); } catch (IllegalArgumentException iae2) { tenantService.insertAssocTypeForTenant(tenantVO.getId(), ClusterService.ASSOCTYPE_BELONGSTO, false); ClusterVO root = loadCluster(tenantVO.getId(), idMappingDAO.lookup(ClusterService.ROOT), itemTypeId); logger.info("No ROOT cluster found for tenant " + tenantVO.getStringId() + "! Creating new ROOT."); root = new ClusterVO(tenantVO.getId(), idMappingDAO.lookup(ClusterService.ROOT), itemTypeId, new DelegateTree<ClusterVO, ItemAssocVO<Integer,Integer>>(); tenantClusters.setRoot(root); clusters.put(tenantVO.getId(), tenantClusters);
tenantService.insertAssocTypeForTenant(tenantVO.getId(), AssocTypeDAO.ASSOCTYPE_IS_RELATED, true);
TenantVO tenant = tenantService.getTenantById(configuration.getTenantId()); LogEntry lastRun = logEntryDAO.getLatestLogEntry(tenant.getId()); Date execution = new Date(); Set<TenantItem> changedItemIds = Sets.newHashSet(); int tenantId = tenant.getId(); changedItemIds = deviationDAO.getItemIds(tenant.getId(), itemTypes);