EntityManagerService { public EntityModel saveEntity(EntityModel entity) throws IOException { JsonNode node = entity.toJson(); String fullpath = entity.getFilename(); HubEntity hubEntity = HubEntity.fromJson(fullpath, node); if (fullpath == null) { String entityFileName = entity.getName() + ENTITY_FILE_EXTENSION; File entityFile = hubConfig.getHubEntitiesDir().resolve(entityFileName).toFile(); String canonicalFileName = Paths.get(entityFile.getCanonicalPath()).getFileName().toString(); if (entityFile.exists() && !entityFileName.equals(canonicalFileName)) { throw new DataHubProjectException("An entity with this name already exists."); } em.saveEntity(hubEntity, false); } else { HubEntity renamedEntity = em.saveEntity(hubEntity, true); entity.setFilename(renamedEntity.getFilename()); } return entity; }  List<EntityModel> getLegacyEntities(); List<EntityModel> getEntities(); EntityModel createEntity(EntityModel newEntity); EntityModel saveEntity(EntityModel entity); void deleteEntity(String entity); void deploySearchOptions(); void saveDbIndexes(); void savePii(); void saveAllUiData(List<EntityModel> entities); void saveEntityUiData(EntityModel entity); EntityModel getEntity(String entityName); EntityModel getEntity(String entityName, Boolean extendSubEntities); FlowModel getFlow(String entityName, FlowType flowType, String flowName); FlowModel createFlow(String entityName, FlowType flowType, FlowModel newFlow); void deleteFlow(String entityName, String flowName, FlowType flowType); JsonNode validatePlugin(
        HubConfig config,
        String entityName,
        String flowName,
        PluginModel plugin
    ); void saveFlowPlugin(
        PluginModel plugin
    ); static final String ENTITY_FILE_EXTENSION; }
@Test public void saveEntity() throws IOException { Path entityDir = projectDir.resolve("entities"); String entityFilename = ENTITY2 + EntityManagerService.ENTITY_FILE_EXTENSION; JsonNode node = getJsonFromResource(entityFilename); EntityModel entity = EntityModel.fromJson(entityFilename, node); entity.setFilename(entityDir.resolve(entityFilename).toString()); entityMgrService.saveEntity(entity); List<EntityModel> entities = entityMgrService.getEntities(); assertEquals(2, entities.size()); List<String> expected = Arrays.asList(ENTITY, ENTITY2); List<String> actual = Arrays.asList(entities.get(0).getName(), entities.get(1).getName()); assertTrue(expected.containsAll(actual)); }