public static SpaceConfig getSpaceConfig(Space space) { SpaceConfig config = new SpaceConfig(); config.setName(space.getName()); config.setId(new EntityId(space.getId())); if (space.getTag() != null) { config.setTag(space.getTag()); } config.setCtime(space.getCreatedAt()); return config; }
public static SpaceConfig addOrUpdateSpace(NamespaceService service, SpacePath spacePath, Space space) throws NamespaceException, UserNotFoundException { SpaceConfig spaceConfig = new SpaceConfig() .setId(space.getId() != null ? new EntityId(space.getId()) : null) .setName(space.getName()) .setDescription(space.getDescription()) .setTag(space.getVersion()); service.addOrUpdateSpace(spacePath.toNamespaceKey(), spaceConfig); return service.getSpace(spacePath.toNamespaceKey()); }
@Test public void testGetSpaceCatalogEntityById() throws Exception { SpaceConfig spaceConfig = new SpaceConfig(); spaceConfig.setId(new EntityId("space-id")); spaceConfig.setName("mySpace"); NameSpaceContainer namespaceContainer = new NameSpaceContainer(); namespaceContainer.setType(NameSpaceContainer.Type.SPACE); namespaceContainer.setSpace(spaceConfig); when(namespaceService.getEntityById(spaceConfig.getId().getId())).thenReturn(namespaceContainer); when(namespaceService.getEntities(Collections.singletonList(new NamespaceKey(spaceConfig.getName())))).thenReturn(Collections.singletonList(namespaceContainer)); // for children listing, we just send the space back to keep it simple when(namespaceService.list(new NamespaceKey(spaceConfig.getName()))).thenReturn(Collections.singletonList(namespaceContainer)); Optional<CatalogEntity> catalogEntityById = catalogServiceHelper.getCatalogEntityById(spaceConfig.getId().getId()); assertTrue(catalogEntityById.isPresent()); CatalogEntity catalogEntity = catalogEntityById.get(); assertTrue(catalogEntity instanceof Space); Space space = (Space) catalogEntity; assertEquals(space.getId(), spaceConfig.getId().getId()); assertEquals(space.getChildren().size(), 1); }
/** helper method that sets the given id in given container */ static void setId(NameSpaceContainer container, String id) { switch (container.getType()) { case SOURCE: container.getSource().setId(new EntityId(id)); return; case SPACE: container.getSpace().setId(new EntityId(id)); return; case HOME: container.getHome().setId(new EntityId(id)); return; case FOLDER: container.getFolder().setId(new EntityId(id)); return; case DATASET: container.getDataset().setId(new EntityId(id)); return; default: throw new RuntimeException("Invalid container type"); } }
spaceConfig.setId(new EntityId("space-id")); when(namespaceService.getSpaces()).thenReturn(Arrays.asList(spaceConfig));