/** * 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", ""); } }
/** * first i insert the new language in database later i create the xml file * * @param name of the new WalletLanguage * @param type of the new WalletLanguage * @param translatorPublicKey like the name says * @return WalletLanguage instance * @throws CantCreateEmptyWalletLanguageException */ @Override public WalletLanguage createEmptyLanguage(String name, Languages type, String translatorPublicKey) throws CantCreateEmptyWalletLanguageException { UUID languageId = UUID.randomUUID(); LanguageState state = LanguageState.DRAFT; Version version = new Version("1.0.0"); WalletLanguage walletLanguage = new WalletLanguageMiddlewareWalletLanguage( languageId, languageId, name, type, state, translatorPublicKey, version); try { Language language = new Language(name, type, new Version("1.0.0")); saveLanguage(language, walletLanguage); try { walletLanguageMiddlewareDao.createLanguage(walletLanguage); return walletLanguage; } catch (CantCreateEmptyWalletLanguageException e) { errorManager.reportUnexpectedPluginException( Plugins.BITDUBAI_WALLET_LANGUAGE_MIDDLEWARE, UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN, e); throw e; } } catch (CantSaveLanguageException e) { errorManager.reportUnexpectedPluginException( Plugins.BITDUBAI_WALLET_LANGUAGE_MIDDLEWARE, UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN, e); throw new CantCreateEmptyWalletLanguageException( CantCreateEmptyWalletLanguageException.DEFAULT_MESSAGE, e, "Cant create language", ""); } }
public void start() throws CantStartPluginException { this.serviceStatus = ServiceStatus.STARTED; walletLanguageMiddlewareDao = new WalletLanguageMiddlewareDao(pluginDatabaseSystem); try { walletLanguageMiddlewareDao.initializeDatabase(pluginId, pluginId.toString()); } catch (CantInitializeWalletLanguageMiddlewareDatabaseException e) { this.serviceStatus = ServiceStatus.STOPPED; throw new CantStartPluginException(CantStartPluginException.DEFAULT_MESSAGE, e, "", ""); } }
@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", ""); } }
@Override public void updateLanguage(WalletLanguage walletLanguage) throws CantUpdateLanguageException, LanguageNotFoundException { try { walletLanguageMiddlewareDao.updateLanguage(walletLanguage); } catch (CantUpdateLanguageException | LanguageNotFoundException e) { errorManager.reportUnexpectedPluginException( Plugins.BITDUBAI_WALLET_LANGUAGE_MIDDLEWARE, UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN, e); throw e; } catch (InvalidParameterException e) { // TODO METODO NO IMPLEMENTADO AUN - OJO: solo INFORMATIVO de ayuda VISUAL para DEBUG - // Eliminar si molesta e.printStackTrace(); } }
@Override public WalletLanguage getLanguageById(UUID id) throws CantGetWalletLanguageException, LanguageNotFoundException { try { return walletLanguageMiddlewareDao.findLanguageById(id); } catch (CantGetWalletLanguageException | LanguageNotFoundException e) { errorManager.reportUnexpectedPluginException( Plugins.BITDUBAI_WALLET_LANGUAGE_MIDDLEWARE, UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN, e); throw e; } catch (InvalidParameterException e) { // TODO METODO NO IMPLEMENTADO AUN - OJO: solo INFORMATIVO de ayuda VISUAL para DEBUG - // Eliminar si molesta e.printStackTrace(); } // TODO METODO CON RETURN NULL - OJO: solo INFORMATIVO de ayuda VISUAL para DEBUG - Eliminar si // molesta return null; }