@Override public WalletLanguage createNewVersion(WalletLanguage walletLanguage) throws CantCopyWalletLanguageException { UUID id = UUID.randomUUID(); LanguageState state = LanguageState.DRAFT; WalletLanguage newWalletLanguage = new WalletLanguageMiddlewareWalletLanguage( id, walletLanguage.getLanguageId(), walletLanguage.getName(), walletLanguage.getType(), state, walletLanguage.getTranslatorPublicKey(), walletLanguage.getVersion()); try { Language language = getLanguage(walletLanguage); saveLanguage(language, newWalletLanguage); try { walletLanguageMiddlewareDao.createLanguage(newWalletLanguage); return newWalletLanguage; } catch (CantCreateEmptyWalletLanguageException e) { errorManager.reportUnexpectedPluginException( Plugins.BITDUBAI_WALLET_LANGUAGE_MIDDLEWARE, UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN, e); throw new CantCopyWalletLanguageException( CantCopyWalletLanguageException.DEFAULT_MESSAGE, e, "Cant insert new wallet language", ""); } } catch (CantSaveLanguageException e) { errorManager.reportUnexpectedPluginException( Plugins.BITDUBAI_WALLET_LANGUAGE_MIDDLEWARE, UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN, e); throw new CantCopyWalletLanguageException( CantCopyWalletLanguageException.DEFAULT_MESSAGE, e, "Cant create language", ""); } catch (CantGetLanguageException | LanguageNotFoundException e) { errorManager.reportUnexpectedPluginException( Plugins.BITDUBAI_WALLET_LANGUAGE_MIDDLEWARE, UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN, e); throw new CantCopyWalletLanguageException( CantCopyWalletLanguageException.DEFAULT_MESSAGE, e, "Language not found", ""); } }
/** * first i delete the file later i delete the record in database * * @param walletLanguage that you're trying to delete * @throws CantDeleteWalletLanguageException * @throws LanguageNotFoundException */ @Override public void deleteLanguage(WalletLanguage walletLanguage) throws CantDeleteWalletLanguageException, LanguageNotFoundException { try { String languageFileName = getLanguageFileName(walletLanguage); PluginTextFile pluginTextFile = pluginFileSystem.getTextFile( pluginId, WALLET_LANGUAGES_PATH, languageFileName, FilePrivacy.PRIVATE, FileLifeSpan.PERMANENT); pluginTextFile.delete(); try { walletLanguageMiddlewareDao.deleteLanguage(walletLanguage.getId()); } catch (CantDeleteWalletLanguageException | LanguageNotFoundException e) { errorManager.reportUnexpectedPluginException( Plugins.BITDUBAI_WALLET_LANGUAGE_MIDDLEWARE, UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN, e); throw e; } } catch (CantCreateFileException e) { throw new CantDeleteWalletLanguageException( CantDeleteWalletLanguageException.DEFAULT_MESSAGE, e, "Cant delete language file", ""); } catch (FileNotFoundException e) { errorManager.reportUnexpectedPluginException( Plugins.BITDUBAI_WALLET_LANGUAGE_MIDDLEWARE, UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN, e); throw new LanguageNotFoundException( LanguageNotFoundException.DEFAULT_MESSAGE, e, "Language not found", ""); } }
private String getLanguageFileName(WalletLanguage walletLanguage) { return walletLanguage.getLanguageId() + WALLET_LANGUAGES_FILE_NAME_SEPARATOR + walletLanguage.getId() + WALLET_LANGUAGES_EXTENSION; }