@Test public void testTagComponents() { em.getTransaction().begin(); em.persist(createComponentSpec("123", "xyz", "123", "123", "xyz", Collections.<Tag>emptyList(), Collections.<String,String>emptyMap())); em.getTransaction().commit(); Assert.assertFalse(serviceImpl.hasComponentsTaggedBy("testTag")); serviceImpl.tagComponents("testTag", Collections.singleton(serviceImpl.getComponent("123"))); Assert.assertTrue(serviceImpl.hasComponentsTaggedBy("testTag")); }
@Override public void tagComponents(String tag, Collection<AbstractComponent> components) { EntityManager em = entityManagerFactory.createEntityManager(); try { em.getTransaction().begin(); Tag t = em.find(Tag.class, tag); if (t == null) { t = new Tag(); t.setTagId(tag); em.persist(t); } for (AbstractComponent component:components) { ComponentSpec cs = em.find(ComponentSpec.class, component.getComponentId()); TagAssociation association = new TagAssociation(); TagAssociationPK tagPK = new TagAssociationPK(); tagPK.setComponentId(cs.getComponentId()); tagPK.setTagId(t.getTagId()); association.setTagAssociationPK(tagPK); cs.getTagAssociationCollection().add(association); } em.getTransaction().commit(); } finally { if(em.getTransaction().isActive()) em.getTransaction().rollback(); em.close(); } if (tag.startsWith("bootstrap:")) { bootstrapComponentIds.refresh(); } }
PersistenceServiceImpl implements PersistenceProvider { @Override public void tagComponents(String tag, Collection<AbstractComponent> components) { EntityManager em = entityManagerFactory.createEntityManager(); try { em.getTransaction().begin(); Tag t = em.find(Tag.class, tag); if (t == null) { t = new Tag(); t.setTagId(tag); em.persist(t); } for (AbstractComponent component:components) { ComponentSpec cs = em.find(ComponentSpec.class, component.getComponentId()); TagAssociation association = new TagAssociation(); TagAssociationPK tagPK = new TagAssociationPK(); tagPK.setComponentId(cs.getComponentId()); tagPK.setTagId(t.getTagId()); association.setTagAssociationPK(tagPK); cs.getTagAssociationCollection().add(association); } em.getTransaction().commit(); } finally { if(em.getTransaction().isActive()) em.getTransaction().rollback(); em.close(); } if (tag.startsWith("bootstrap:")) { bootstrapComponentIds.refresh(); } } }
PersistenceServiceImpl implements PersistenceProvider { @Override public void tagComponents(String tag, Collection<AbstractComponent> components) { EntityManager em = entityManagerFactory.createEntityManager(); try { em.getTransaction().begin(); Tag t = em.find(Tag.class, tag); if (t == null) { t = new Tag(); t.setTagId(tag); em.persist(t); } for (AbstractComponent component:components) { ComponentSpec cs = em.find(ComponentSpec.class, component.getComponentId()); TagAssociation association = new TagAssociation(); TagAssociationPK tagPK = new TagAssociationPK(); tagPK.setComponentId(cs.getComponentId()); tagPK.setTagId(t.getTagId()); association.setTagAssociationPK(tagPK); cs.getTagAssociationCollection().add(association); } em.getTransaction().commit(); } finally { if(em.getTransaction().isActive()) em.getTransaction().rollback(); em.close(); } if (tag.startsWith("bootstrap:")) { bootstrapComponentIds.refresh(); } }  }
PersistenceServiceImpl implements PersistenceProvider { @Override public void tagComponents(String tag, Collection<AbstractComponent> components) { EntityManager em = entityManagerFactory.createEntityManager(); try { em.getTransaction().begin(); Tag t = em.find(Tag.class, tag); if (t == null) { t = new Tag(); t.setTagId(tag); em.persist(t); } for (AbstractComponent component:components) { ComponentSpec cs = em.find(ComponentSpec.class, component.getComponentId()); TagAssociation association = new TagAssociation(); TagAssociationPK tagPK = new TagAssociationPK(); tagPK.setComponentId(cs.getComponentId()); tagPK.setTagId(t.getTagId()); association.setTagAssociationPK(tagPK); cs.getTagAssociationCollection().add(association); } em.getTransaction().commit(); } finally { if(em.getTransaction().isActive()) em.getTransaction().rollback(); em.close(); } if (tag.startsWith("bootstrap:")) { bootstrapComponentIds.refresh(); } }  void bind(Platform platform); void unbind(Platform platform); void setEntityManagerProperties(Properties p); void activate(ComponentContext context); @Override AbstractComponent getComponentFromStore(String componentId); @Override AbstractComponent getComponent(String componentId); @Override Collection<AbstractComponent> getReferences(AbstractComponent component); @Override void startRelatedOperations(); @Override void completeRelatedOperations(boolean save); @Override void addComponentToWorkUnit(AbstractComponent component); Collection<AbstractComponent> getCurrentComponents(); @Override Set<String> getAllUsers(); @Override Collection<String> getUsersInGroup(String group); @Override void persist(Collection<AbstractComponent> componentsToPersist); @Override void delete(Collection<AbstractComponent> componentsToDelete); @Override boolean hasComponentsTaggedBy(String tagId); @Override List<AbstractComponent> getReferencedComponents(
			AbstractComponent component); @Override User getUser(String userId); @SuppressWarnings("unchecked") QueryResult findComponentsByBaseDisplayedNamePattern(String pattern, Properties props); @Override T getComponent(String externalKey, Class<T> componentType); @Override void updateComponentsFromDatabase(); @Override List<AbstractComponent> getBootstrapComponents(); @Override void addNewUser(String userId, String groupId, AbstractComponent mysandbox, AbstractComponent dropbox); @Override Map<String, ExtendedProperties> getAllProperties(String componentId); @Override AbstractComponent getComponent(String externalKey,
			String componentType); @Override void tagComponents(String tag,
			Collection<AbstractComponent> components); }
PersistenceServiceImpl implements PersistenceProvider { @Override public void tagComponents(String tag, Collection<AbstractComponent> components) { EntityManager em = entityManagerFactory.createEntityManager(); try { em.getTransaction().begin(); Tag t = em.find(Tag.class, tag); if (t == null) { t = new Tag(); t.setTagId(tag); em.persist(t); } for (AbstractComponent component:components) { ComponentSpec cs = em.find(ComponentSpec.class, component.getComponentId()); TagAssociation association = new TagAssociation(); TagAssociationPK tagPK = new TagAssociationPK(); tagPK.setComponentId(cs.getComponentId()); tagPK.setTagId(t.getTagId()); association.setTagAssociationPK(tagPK); cs.getTagAssociationCollection().add(association); } em.getTransaction().commit(); } finally { if(em.getTransaction().isActive()) em.getTransaction().rollback(); em.close(); } if (tag.startsWith("bootstrap:")) { bootstrapComponentIds.refresh(); } }  void bind(Platform platform); void unbind(Platform platform); void setEntityManagerProperties(Properties p); void activate(ComponentContext context); @Override AbstractComponent getComponentFromStore(String componentId); @Override AbstractComponent getComponent(String componentId); @Override Collection<AbstractComponent> getReferences(AbstractComponent component); @Override void startRelatedOperations(); @Override void completeRelatedOperations(boolean save); @Override void addComponentToWorkUnit(AbstractComponent component); Collection<AbstractComponent> getCurrentComponents(); @Override Set<String> getAllUsers(); @Override Collection<String> getUsersInGroup(String group); @Override void persist(Collection<AbstractComponent> componentsToPersist); @Override void delete(Collection<AbstractComponent> componentsToDelete); @Override boolean hasComponentsTaggedBy(String tagId); @Override List<AbstractComponent> getReferencedComponents(
			AbstractComponent component); @Override User getUser(String userId); @SuppressWarnings("unchecked") QueryResult findComponentsByBaseDisplayedNamePattern(String pattern, Properties props); @Override T getComponent(String externalKey, Class<T> componentType); @Override void updateComponentsFromDatabase(); @Override List<AbstractComponent> getBootstrapComponents(); @Override void addNewUser(String userId, String groupId, AbstractComponent mysandbox, AbstractComponent dropbox); @Override Map<String, ExtendedProperties> getAllProperties(String componentId); @Override AbstractComponent getComponent(String externalKey,
			String componentType); @Override void tagComponents(String tag,
			Collection<AbstractComponent> components);  }