public static Space newInstance(SpaceConfig spaceConfig, NamespaceTree contents, int datasetCount) { String id = spaceConfig.getId() != null ? spaceConfig.getId().getId() : null; return new Space(id, spaceConfig.getName(), spaceConfig.getDescription(), spaceConfig.getTag(), contents, datasetCount, spaceConfig.getCtime()); } }
protected Space getSpaceFromConfig(SpaceConfig config, List<CatalogItem> children) { return new Space( config.getId().getId(), config.getName(), String.valueOf(config.getTag()), config.getCtime(), children ); }
private static CatalogItem fromSpaceConfig(SpaceConfig spaceConfig, CollaborationTag tags) { return new Builder() .setId(spaceConfig.getId().getId()) .setPath(Lists.newArrayList(spaceConfig.getName())) .setTag(String.valueOf(spaceConfig.getTag())) .setType(CatalogItemType.CONTAINER) .setContainerType(ContainerSubType.SPACE) .setTags(tags) .build(); }
@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 returns the id of the entity in given container */ public static String getId(NameSpaceContainer container) { EntityId entityId; switch (container.getType()) { case SOURCE: entityId = container.getSource().getId(); break; case SPACE: entityId = container.getSpace().getId(); break; case HOME: entityId = container.getHome().getId(); break; case FOLDER: entityId = container.getFolder().getId(); break; case DATASET: entityId = container.getDataset().getId(); break; default: throw new RuntimeException("Invalid container type"); } return entityId != null ? entityId.getId() : null; }
@Test public void testSpace() throws Exception { // create a new space Space newSpace = new Space(null, "final frontier", null, null, null); Space space = expectSuccess(getBuilder(getPublicAPI(3).path(CATALOG_PATH)).buildPost(Entity.json(newSpace)), new GenericType<Space>() {}); SpaceConfig spaceConfig = newNamespaceService().getSpace(new NamespaceKey(newSpace.getName())); assertEquals(space.getId(), spaceConfig.getId().getId()); assertEquals(space.getName(), spaceConfig.getName()); // make sure that trying to create the space again fails expectStatus(Response.Status.CONFLICT, getBuilder(getPublicAPI(3).path(CATALOG_PATH)).buildPost(Entity.json(newSpace))); // delete the space expectSuccess(getBuilder(getPublicAPI(3).path(CATALOG_PATH).path(spaceConfig.getId().getId())).buildDelete()); thrown.expect(NamespaceException.class); newNamespaceService().getSpace(new NamespaceKey(spaceConfig.getName())); }
assertEquals(item.getId(), spaceConfig.getId().getId());
writer.write(NamespaceIndexKeys.SPACE_ID, spaceConfig.getId().getId()); writer.write(NamespaceIndexKeys.LAST_MODIFIED, spaceConfig.getCtime()); break;