@Test public void testAddNewUser() { String userId = "testUser"; String sandboxId = "mysandbox"; User mockUser = Mockito.mock(User.class); AbstractComponent mockBoxes = createAbstractComponent("Drop Boxes", "dropboxes"); Mockito.when(mockPlatform.getUserDropboxes()).thenReturn(mockBoxes); Mockito.when(mockPlatform.getCurrentUser()).thenReturn(mockUser); Mockito.when(mockUser.getUserId()).thenReturn(userId); em.getTransaction().begin(); em.persist(createComponentSpec( "dropboxes", "xyz", "123", "123", "xyz", new ArrayList<Tag>(), Collections.<String,String>emptyMap())); em.getTransaction().commit(); Assert.assertEquals(serviceImpl.getBootstrapComponents().size(), 0); serviceImpl.bind(mockPlatform); serviceImpl.addNewUser( userId, "testGroup", createAbstractComponent("My Sandbox", sandboxId , userId), createAbstractComponent("My Dropbox", "mydropbox", userId)); Assert.assertEquals(serviceImpl.getBootstrapComponents().get(0).getComponentId(), sandboxId); }
@Override public void addNewUser(String userId, String groupId, AbstractComponent mysandbox, AbstractComponent dropbox) { String userDropboxesId = platform.getUserDropboxes().getComponentId(); EntityManager em = entityManagerFactory.createEntityManager(); try { em.getTransaction().begin(); Disciplines group = em.find(Disciplines.class, groupId); if (group == null) { group = new Disciplines(); group.setDisciplineId(groupId); em.persist(group); } MctUsers user = new MctUsers(); user.setUserId(userId); user.setDisciplineId(group); em.persist(user); ComponentSpec mysandboxComponentSpec = new ComponentSpec(); updateComponentSpec(mysandbox, mysandboxComponentSpec, em, true); em.persist(mysandboxComponentSpec); TagAssociationPK tagAssociationPK = new TagAssociationPK(); tagAssociationPK.setComponentId(mysandbox.getComponentId()); tagAssociationPK.setTagId("bootstrap:creator"); TagAssociation tagAssociation = new TagAssociation(); tagAssociation.setTagAssociationPK(tagAssociationPK); em.persist(tagAssociation); ComponentSpec dropboxComponentSpec = new ComponentSpec(); updateComponentSpec(dropbox, dropboxComponentSpec, em, true); em.persist(dropboxComponentSpec); ComponentSpec userDropboxes = em.find(ComponentSpec.class, userDropboxesId); userDropboxes.getReferencedComponents().add(dropboxComponentSpec); mysandboxComponentSpec.getReferencedComponents().add(dropboxComponentSpec); em.persist(userDropboxes); em.persist(mysandboxComponentSpec); em.getTransaction().commit(); } finally { if(em.getTransaction().isActive()) em.getTransaction().rollback(); em.close(); } bootstrapComponentIds.refresh(); }
PersistenceServiceImpl implements PersistenceProvider { @Override public void addNewUser(String userId, String groupId, AbstractComponent mysandbox, AbstractComponent dropbox) { String userDropboxesId = platform.getUserDropboxes().getComponentId(); EntityManager em = entityManagerFactory.createEntityManager(); try { em.getTransaction().begin(); Disciplines group = em.find(Disciplines.class, groupId); if (group == null) { group = new Disciplines(); group.setDisciplineId(groupId); em.persist(group); } MctUsers user = new MctUsers(); user.setUserId(userId); user.setDisciplineId(group); em.persist(user); ComponentSpec mysandboxComponentSpec = new ComponentSpec(); updateComponentSpec(mysandbox, mysandboxComponentSpec, em, true); em.persist(mysandboxComponentSpec); TagAssociationPK tagAssociationPK = new TagAssociationPK(); tagAssociationPK.setComponentId(mysandbox.getComponentId()); tagAssociationPK.setTagId("bootstrap:creator"); TagAssociation tagAssociation = new TagAssociation(); tagAssociation.setTagAssociationPK(tagAssociationPK); em.persist(tagAssociation); ComponentSpec dropboxComponentSpec = new ComponentSpec(); updateComponentSpec(dropbox, dropboxComponentSpec, em, true); em.persist(dropboxComponentSpec); ComponentSpec userDropboxes = em.find(ComponentSpec.class, userDropboxesId); userDropboxes.getReferencedComponents().add(dropboxComponentSpec); mysandboxComponentSpec.getReferencedComponents().add(dropboxComponentSpec); em.persist(userDropboxes); em.persist(mysandboxComponentSpec); em.getTransaction().commit(); } finally { if(em.getTransaction().isActive()) em.getTransaction().rollback(); em.close(); } bootstrapComponentIds.refresh(); } }
PersistenceServiceImpl implements PersistenceProvider { @Override public void addNewUser(String userId, String groupId, AbstractComponent mysandbox, AbstractComponent dropbox) { String userDropboxesId = platform.getUserDropboxes().getComponentId(); EntityManager em = entityManagerFactory.createEntityManager(); try { em.getTransaction().begin(); Disciplines group = em.find(Disciplines.class, groupId); if (group == null) { group = new Disciplines(); group.setDisciplineId(groupId); em.persist(group); } MctUsers user = new MctUsers(); user.setUserId(userId); user.setDisciplineId(group); em.persist(user); ComponentSpec mysandboxComponentSpec = new ComponentSpec(); updateComponentSpec(mysandbox, mysandboxComponentSpec, em, true); em.persist(mysandboxComponentSpec); TagAssociationPK tagAssociationPK = new TagAssociationPK(); tagAssociationPK.setComponentId(mysandbox.getComponentId()); tagAssociationPK.setTagId("bootstrap:creator"); TagAssociation tagAssociation = new TagAssociation(); tagAssociation.setTagAssociationPK(tagAssociationPK); em.persist(tagAssociation); ComponentSpec dropboxComponentSpec = new ComponentSpec(); updateComponentSpec(dropbox, dropboxComponentSpec, em, true); em.persist(dropboxComponentSpec); ComponentSpec userDropboxes = em.find(ComponentSpec.class, userDropboxesId); userDropboxes.getReferencedComponents().add(dropboxComponentSpec); mysandboxComponentSpec.getReferencedComponents().add(dropboxComponentSpec); em.persist(userDropboxes); em.persist(mysandboxComponentSpec); em.getTransaction().commit(); } finally { if(em.getTransaction().isActive()) em.getTransaction().rollback(); em.close(); } bootstrapComponentIds.refresh(); }  }
PersistenceServiceImpl implements PersistenceProvider { @Override public void addNewUser(String userId, String groupId, AbstractComponent mysandbox, AbstractComponent dropbox) { String userDropboxesId = platform.getUserDropboxes().getComponentId(); EntityManager em = entityManagerFactory.createEntityManager(); try { em.getTransaction().begin(); Disciplines group = em.find(Disciplines.class, groupId); if (group == null) { group = new Disciplines(); group.setDisciplineId(groupId); em.persist(group); } MctUsers user = new MctUsers(); user.setUserId(userId); user.setDisciplineId(group); em.persist(user); ComponentSpec mysandboxComponentSpec = new ComponentSpec(); updateComponentSpec(mysandbox, mysandboxComponentSpec, em, true); em.persist(mysandboxComponentSpec); TagAssociationPK tagAssociationPK = new TagAssociationPK(); tagAssociationPK.setComponentId(mysandbox.getComponentId()); tagAssociationPK.setTagId("bootstrap:creator"); TagAssociation tagAssociation = new TagAssociation(); tagAssociation.setTagAssociationPK(tagAssociationPK); em.persist(tagAssociation); ComponentSpec dropboxComponentSpec = new ComponentSpec(); updateComponentSpec(dropbox, dropboxComponentSpec, em, true); em.persist(dropboxComponentSpec); ComponentSpec userDropboxes = em.find(ComponentSpec.class, userDropboxesId); userDropboxes.getReferencedComponents().add(dropboxComponentSpec); mysandboxComponentSpec.getReferencedComponents().add(dropboxComponentSpec); em.persist(userDropboxes); em.persist(mysandboxComponentSpec); em.getTransaction().commit(); } finally { if(em.getTransaction().isActive()) em.getTransaction().rollback(); em.close(); } 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 addNewUser(String userId, String groupId, AbstractComponent mysandbox, AbstractComponent dropbox) { String userDropboxesId = platform.getUserDropboxes().getComponentId(); EntityManager em = entityManagerFactory.createEntityManager(); try { em.getTransaction().begin(); Disciplines group = em.find(Disciplines.class, groupId); if (group == null) { group = new Disciplines(); group.setDisciplineId(groupId); em.persist(group); } MctUsers user = new MctUsers(); user.setUserId(userId); user.setDisciplineId(group); em.persist(user); ComponentSpec mysandboxComponentSpec = new ComponentSpec(); updateComponentSpec(mysandbox, mysandboxComponentSpec, em, true); em.persist(mysandboxComponentSpec); TagAssociationPK tagAssociationPK = new TagAssociationPK(); tagAssociationPK.setComponentId(mysandbox.getComponentId()); tagAssociationPK.setTagId("bootstrap:creator"); TagAssociation tagAssociation = new TagAssociation(); tagAssociation.setTagAssociationPK(tagAssociationPK); em.persist(tagAssociation); ComponentSpec dropboxComponentSpec = new ComponentSpec(); updateComponentSpec(dropbox, dropboxComponentSpec, em, true); em.persist(dropboxComponentSpec); ComponentSpec userDropboxes = em.find(ComponentSpec.class, userDropboxesId); userDropboxes.getReferencedComponents().add(dropboxComponentSpec); mysandboxComponentSpec.getReferencedComponents().add(dropboxComponentSpec); em.persist(userDropboxes); em.persist(mysandboxComponentSpec); em.getTransaction().commit(); } finally { if(em.getTransaction().isActive()) em.getTransaction().rollback(); em.close(); } 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);  }