@Test void testCheckAndObtainConfigMissingRequiredConfigParameters() throws IOException { InputStream is = AppManagerServiceImplTest.class.getResourceAsStream("/config-missing-keys.json"); Exception exception = assertThrows( AppConfigMissingParametersException.class, () -> appManagerServiceImpl.checkAndObtainConfig("tempDir", IOUtils.toString(is, UTF_8))); assertThat(exception.getMessage()) .containsPattern( "missingConfigParameters:\\[label, description, includeMenuAndFooter, name, version\\]"); }
@Override public AppConfig checkAndObtainConfig(String tempDir, String configContent) throws IOException { if (configContent.isEmpty() || !isConfigContentValidJson(configContent)) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new InvalidAppConfigException(); } AppConfig appConfig = gson.fromJson(configContent, AppConfig.class); List<String> missingAppConfigParams = buildMissingConfigParams(appConfig); if (!missingAppConfigParams.isEmpty()) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new AppConfigMissingParametersException(missingAppConfigParams); } if (appConfig.getName().contains("/")) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new IllegalAppNameException(appConfig.getName()); } if (fileStore.getFileUnchecked(APPS_DIR + separator + appConfig.getName()).exists()) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new AppAlreadyExistsException(appConfig.getName()); } fileStore.move(tempDir, APPS_DIR + separator + appConfig.getName()); fileStore.deleteDirectory(APPS_TMP_DIR); return appConfig; }
AppManagerServiceImpl implements AppManagerService { @Override public AppConfig checkAndObtainConfig(String tempDir, String configContent) throws IOException { if (configContent.isEmpty() || !isConfigContentValidJson(configContent)) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new InvalidAppConfigException(); } AppConfig appConfig = gson.fromJson(configContent, AppConfig.class); List<String> missingAppConfigParams = buildMissingConfigParams(appConfig); if (!missingAppConfigParams.isEmpty()) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new AppConfigMissingParametersException(missingAppConfigParams); } if (appConfig.getName().contains("/")) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new IllegalAppNameException(appConfig.getName()); } if (fileStore.getFileUnchecked(APPS_DIR + separator + appConfig.getName()).exists()) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new AppAlreadyExistsException(appConfig.getName()); } fileStore.move(tempDir, APPS_DIR + separator + appConfig.getName()); fileStore.deleteDirectory(APPS_TMP_DIR); return appConfig; } }
AppManagerServiceImpl implements AppManagerService { @Override public AppConfig checkAndObtainConfig(String tempDir, String configContent) throws IOException { if (configContent.isEmpty() || !isConfigContentValidJson(configContent)) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new InvalidAppConfigException(); } AppConfig appConfig = gson.fromJson(configContent, AppConfig.class); List<String> missingAppConfigParams = buildMissingConfigParams(appConfig); if (!missingAppConfigParams.isEmpty()) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new AppConfigMissingParametersException(missingAppConfigParams); } if (appConfig.getName().contains("/")) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new IllegalAppNameException(appConfig.getName()); } if (fileStore.getFileUnchecked(APPS_DIR + separator + appConfig.getName()).exists()) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new AppAlreadyExistsException(appConfig.getName()); } fileStore.move(tempDir, APPS_DIR + separator + appConfig.getName()); fileStore.deleteDirectory(APPS_TMP_DIR); return appConfig; } AppManagerServiceImpl(
      AppFactory appFactory,
      DataService dataService,
      FileStore fileStore,
      Gson gson,
      PluginFactory pluginFactory); }
AppManagerServiceImpl implements AppManagerService { @Override public AppConfig checkAndObtainConfig(String tempDir, String configContent) throws IOException { if (configContent.isEmpty() || !isConfigContentValidJson(configContent)) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new InvalidAppConfigException(); } AppConfig appConfig = gson.fromJson(configContent, AppConfig.class); List<String> missingAppConfigParams = buildMissingConfigParams(appConfig); if (!missingAppConfigParams.isEmpty()) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new AppConfigMissingParametersException(missingAppConfigParams); } if (appConfig.getName().contains("/")) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new IllegalAppNameException(appConfig.getName()); } if (fileStore.getFileUnchecked(APPS_DIR + separator + appConfig.getName()).exists()) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new AppAlreadyExistsException(appConfig.getName()); } fileStore.move(tempDir, APPS_DIR + separator + appConfig.getName()); fileStore.deleteDirectory(APPS_TMP_DIR); return appConfig; } AppManagerServiceImpl(
      AppFactory appFactory,
      DataService dataService,
      FileStore fileStore,
      Gson gson,
      PluginFactory pluginFactory); @Override List<AppResponse> getApps(); @Override AppResponse getAppByName(String appName); @Override @Transactional void activateApp(App app); @Override @Transactional void deactivateApp(App app); @Override @Transactional void deleteApp(String id); @Override String uploadApp(InputStream zipData, String zipFileName, String formFieldName); @Override AppConfig checkAndObtainConfig(String tempDir, String configContent); @Override @Transactional void configureApp(AppConfig appConfig, String htmlTemplate); @Override String extractFileContent(String appDir, String fileName); }
AppManagerServiceImpl implements AppManagerService { @Override public AppConfig checkAndObtainConfig(String tempDir, String configContent) throws IOException { if (configContent.isEmpty() || !isConfigContentValidJson(configContent)) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new InvalidAppConfigException(); } AppConfig appConfig = gson.fromJson(configContent, AppConfig.class); List<String> missingAppConfigParams = buildMissingConfigParams(appConfig); if (!missingAppConfigParams.isEmpty()) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new AppConfigMissingParametersException(missingAppConfigParams); } if (appConfig.getName().contains("/")) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new IllegalAppNameException(appConfig.getName()); } if (fileStore.getFileUnchecked(APPS_DIR + separator + appConfig.getName()).exists()) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new AppAlreadyExistsException(appConfig.getName()); } fileStore.move(tempDir, APPS_DIR + separator + appConfig.getName()); fileStore.deleteDirectory(APPS_TMP_DIR); return appConfig; } AppManagerServiceImpl(
      AppFactory appFactory,
      DataService dataService,
      FileStore fileStore,
      Gson gson,
      PluginFactory pluginFactory); @Override List<AppResponse> getApps(); @Override AppResponse getAppByName(String appName); @Override @Transactional void activateApp(App app); @Override @Transactional void deactivateApp(App app); @Override @Transactional void deleteApp(String id); @Override String uploadApp(InputStream zipData, String zipFileName, String formFieldName); @Override AppConfig checkAndObtainConfig(String tempDir, String configContent); @Override @Transactional void configureApp(AppConfig appConfig, String htmlTemplate); @Override String extractFileContent(String appDir, String fileName); static final String APPS_DIR; static final String ZIP_INDEX_FILE; static final String ZIP_CONFIG_FILE; static final String APP_PLUGIN_ROOT; }