public List<ItemVO<Integer, Integer>> getItemsOfCluster(ClusterVO cluster, String strategy, Boolean useFallback, int numberOfResults, Integer itemType) { Preconditions.checkNotNull(cluster); Preconditions.checkNotNull(cluster.getItem()); Preconditions.checkNotNull(cluster.getItem().getTenant()); Preconditions.checkNotNull(cluster.getName()); Integer tenantId = cluster.getItem().getTenant(); ClusterStrategy clusterStrategy = strategy == null ? null : strategies.get(strategy); if (clusterStrategy == null) clusterStrategy = strategies.get(ClusterService.DEFAULT_STRATEGY); List<AssociatedItemVO<Integer, Integer>> itemAssocs; if (!useFallback) { itemAssocs = clusterStrategy.getItemsFromCluster(tenantId, cluster, numberOfResults, itemType); } else { itemAssocs = fallBack(tenantId, cluster, clusterStrategy, numberOfResults, itemType); } return Lists.transform(itemAssocs, new Function<AssociatedItemVO<Integer, Integer>, ItemVO<Integer, Integer>>() { public ItemVO<Integer, Integer> apply( AssociatedItemVO<Integer, Integer> input) { return input.getItem(); } }); }
public List<ItemVO<Integer, Integer>> getItemsOfCluster(ClusterVO cluster, Integer itemType) { Preconditions.checkNotNull(cluster); Preconditions.checkNotNull(cluster.getItem()); Preconditions.checkNotNull(cluster.getItem().getTenant()); Preconditions.checkNotNull(cluster.getName()); Integer tenantId = cluster.getItem().getTenant(); Integer assocTypeBelongsTo = assocTypeDAO.getIdOfType(tenantId, ClusterService.ASSOCTYPE_BELONGSTO); IAConstraintVO<Integer, Integer> constraint = new IAConstraintVO<Integer, Integer>( null, null, null, null, tenantId, true, null); List<AssociatedItemVO<Integer, Integer>> itemAssocs = itemAssocService.getItemsFrom(itemType, assocTypeBelongsTo, cluster.getItem(), constraint); return Lists.transform(itemAssocs, new Function<AssociatedItemVO<Integer, Integer>, ItemVO<Integer, Integer>>() { public ItemVO<Integer, Integer> apply( AssociatedItemVO<Integer, Integer> input) { return input.getItem(); } }); }
logger.info("Found " + curNumberOfResults + " items for cluster " + sibling.getName());
public int removeItemFromCluster(ClusterVO cluster, ItemVO<Integer, Integer> item) throws ClusterException { Preconditions.checkNotNull(cluster); Preconditions.checkNotNull(cluster.getItem()); Preconditions.checkNotNull(cluster.getItem().getTenant()); Preconditions.checkNotNull(cluster.getName()); Preconditions.checkNotNull(item); Preconditions.checkNotNull(item.getItem()); Preconditions.checkNotNull(item.getType()); Preconditions.checkArgument(cluster.getItem().getTenant().equals(item.getTenant()), "cluster's tenantId (%s) must be the same as item's tenant id (%s)", cluster.getItem().getTenant(), item.getTenant()); Integer tenantId = cluster.getItem().getTenant(); Integer assocTypeBelongsTo = assocTypeDAO.getIdOfType(tenantId, ClusterService.ASSOCTYPE_BELONGSTO); ItemAssocVO<Integer,Integer> itemAssoc = new ItemAssocVO<Integer,Integer>(tenantId, item, assocTypeBelongsTo, null, cluster.getItem(), null, null, null, null, null); int rowsModified = itemAssocService.removeItemAssocQBE(itemAssoc); if (rowsModified == 0) throw new ClusterException( "The item was not removed from the cluster, maybe the item was not in the cluster."); return rowsModified; }
public void addCluster(Integer tenantId, String clusterName, String clusterDescription, String parent) throws ClusterException { ClusterVO parentCluster = loadCluster(tenantId, idMappingDAO.lookup(parent), itemTypeDAO.getIdOfType(tenantId, ClusterService.ITEMTYPE_CLUSTER)); if (parentCluster == null) throw new ClusterException("Cannot add cluster at this position! No parent cluster selected!"); logger.info(parentCluster.getName()); ClusterVO childCluster = new ClusterVO(tenantId, idMappingDAO.lookup(clusterName), itemTypeDAO.getIdOfType(tenantId, ClusterService.ITEMTYPE_CLUSTER), clusterName, clusterDescription); addCluster(childCluster, parentCluster); }
public int addItemToCluster(ClusterVO cluster, ItemVO<Integer, Integer> item) throws ClusterException { Preconditions.checkNotNull(cluster); Preconditions.checkNotNull(cluster.getItem()); Preconditions.checkNotNull(cluster.getItem().getTenant()); Preconditions.checkNotNull(cluster.getName()); Preconditions.checkNotNull(item); Preconditions.checkNotNull(item.getItem()); Preconditions.checkNotNull(item.getType()); Preconditions.checkArgument(cluster.getItem().getTenant().equals(item.getTenant()), "cluster's tenantId (%s) must be the same as item's tenant id (%s)", cluster.getItem().getTenant(), item.getTenant()); Integer tenantId = cluster.getItem().getTenant(); Integer assocTypeBelongsTo = assocTypeDAO.getIdOfType(tenantId, ClusterService.ASSOCTYPE_BELONGSTO); Integer sourceTypeManuallyCreated = sourceTypeDAO.getIdOfType(tenantId, SourceTypeDAO.SOURCETYPE_MANUALLY_CREATED); Integer viewTypeAdmin = viewTypeDAO.getIdOfType(tenantId, ViewTypeDAO.VIEWTYPE_ADMIN); ItemAssocVO<Integer,Integer> itemAssoc = new ItemAssocVO<Integer,Integer>(tenantId, item, assocTypeBelongsTo, 1.0, cluster.getItem(), sourceTypeManuallyCreated, null, viewTypeAdmin, true, new Date()); try { return itemAssocService.insertOrUpdateItemAssoc(itemAssoc); } catch (DuplicateKeyException e) { throw new ClusterException( "The item was not added to the cluster because the item already was in the cluster."); } }
public void renameCluster(Integer tenantId, String clusterName, String newName) throws ClusterException { ClusterVO cluster = loadCluster(tenantId, idMappingDAO.lookup(clusterName), itemTypeDAO.getIdOfType(tenantId, ClusterService.ITEMTYPE_CLUSTER)); DelegateTree<ClusterVO, ItemAssocVO<Integer,Integer>> tree = clusters.get(tenantId); if (tree.isRoot(cluster)) throw new ClusterException("ROOT cluster cannot be renamed!"); ClusterVO parent = tree.getParent(cluster); ClusterVO newCluster = new ClusterVO(tenantId, idMappingDAO.lookup(newName), itemTypeDAO.getIdOfType(tenantId, ClusterService.ITEMTYPE_CLUSTER), newName, cluster.getDescription()); // add the new cluster addCluster(newCluster, parent); // move all children to the new cluster for (ClusterVO child : tree.getChildren(cluster)) { moveCluster(tenantId, child.getName(), newName); } if (logger.isDebugEnabled()) { logger.debug("removed all children: " + tree.isLeaf(cluster)); } // move all items to the new cluster for (ItemVO<Integer, Integer> item : getItemsOfCluster(cluster)) { addItemToCluster(newCluster, item); } // delete the old cluster removeCluster(tenantId, clusterName); }