use of org.compiere.model.MLanguage in project adempiere by adempiere.
the class Translation method validateLanguage.
// getTrlColumns
/**************************************************************************
* Validate Language.
* - Check if AD_Language record exists
* - Check Trl table records
* @param AD_Language language
* @return "" if validated - or error message
*/
public String validateLanguage(String AD_Language) {
String sql = "SELECT * " + "FROM AD_Language " + "WHERE AD_Language=?";
MLanguage language = null;
try {
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setString(1, AD_Language);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
language = new MLanguage(m_ctx, rs, null);
rs.close();
pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
return e.toString();
}
// No AD_Language Record
if (language == null) {
log.log(Level.SEVERE, "Language does not exist: " + AD_Language);
return "Language does not exist: " + AD_Language;
}
// Language exists
if (language.isActive()) {
if (language.isBaseLanguage())
return "";
} else {
log.log(Level.SEVERE, "Language not active or not system language: " + AD_Language);
return "Language not active or not system language: " + AD_Language;
}
// Validate Translation
log.info("Start Validating ... " + language);
language.maintain(true);
return "";
}
use of org.compiere.model.MLanguage in project adempiere by adempiere.
the class InitialClientSetup method doIt.
/**
* Process
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("InitialClientSetup" + ": ClientName=" + getClientName() + ", OrgValue=" + getOrgKey() + ", OrgName=" + getOrganizationName() + ", AdminUserName=" + getAdministrativeUserName() + ", NormalUserName=" + getNormalUserName() + ", C_Currency_ID=" + getCurrencyId() + ", C_Country_ID=" + getCountryId() + ", C_Region_ID=" + getRegionId() + ", CityName=" + getCityName() + ", C_City_ID=" + getCityId() + ", IsUseBPDimension=" + isBPAccounting() + ", IsUseProductDimension=" + isProductAccounting() + ", IsUseProjectDimension=" + isProjectAccounting() + ", IsUseCampaignDimension=" + isCampaignAccounting() + ", IsUseSalesRegionDimension=" + isSalesRegionAccounting() + ", ChartofAccountsFile=" + getChartofAccountsFile());
// Validate Mandatory parameters
if (getClientName() == null || getClientName().length() == 0 || getOrganizationName() == null || getOrganizationName().length() == 0 || getCurrencyId() <= 0 || getCountryId() <= 0 || getChartofAccountsFile() == null || getChartofAccountsFile().length() == 0)
throw new IllegalArgumentException("Missing required parameters");
// Unique Client Name
if (DB.executeUpdate("UPDATE AD_Client SET CreatedBy=0 WHERE Name=?", new Object[] { getClientName() }, false, null) != 0)
throw new AdempiereException("@NotUnique@ " + getClientName());
// Unique User Names
if (DB.executeUpdate("UPDATE AD_User SET CreatedBy=0 WHERE Name=?", new Object[] { getAdministrativeUserName() }, false, null) != 0)
throw new AdempiereException("@NotUnique@ " + getAdministrativeUserName());
if (DB.executeUpdate("UPDATE AD_User SET CreatedBy=0 WHERE Name=?", new Object[] { getNormalUserName() }, false, null) != 0)
throw new AdempiereException("@NotUnique@ " + getNormalUserName());
// City_ID overrides CityName if both used
if (getCityId() > 0) {
MCity city = MCity.get(getCtx(), getCityId());
if (!city.getName().equals(getCityName())) {
log.info("City name changed from " + getCityName() + " to " + city.getName());
setCityName(city.getName());
}
}
// Validate existence and read permissions on CoA file
File chartofAccountsFile = new File(getChartofAccountsFile());
if (!chartofAccountsFile.exists())
throw new AdempiereException("CoaFile " + getChartofAccountsFile() + " does not exist");
if (!chartofAccountsFile.canRead())
throw new AdempiereException("Cannot read CoaFile " + getChartofAccountsFile());
if (!chartofAccountsFile.isFile())
throw new AdempiereException("CoaFile " + getChartofAccountsFile() + " is not a file");
if (chartofAccountsFile.length() <= 0L)
throw new AdempiereException("CoaFile " + getChartofAccountsFile() + " is empty");
// Process
MSetup setup = null;
MCountry country = MCountry.get(getCtx(), getCountryId());
try {
Class<?> ppClass = Class.forName("org.compiere.model.MSetup_" + country.getCountryCode());
if (ppClass != null)
setup = (MSetup) ppClass.newInstance();
} catch (// NoClassDefFound
Exception e) {
// ignore as country specific setup class may not exist
}
if (setup == null)
setup = new MSetup();
setup.initialize(Env.getCtx(), WINDOW_THIS_PROCESS);
if (!setup.createClient(getClientName(), getOrgKey(), getOrganizationName(), getAdministrativeUserName(), getNormalUserName(), getPhone(), getPhone2(), getFax(), getEMailAddress(), getTaxID(), getDUNS(), getLogo(), getCountryId())) {
setup.rollback();
throw new AdempiereException("Create client failed");
}
addLog(setup.getInfo());
// Generate Accounting
MCurrency currency = MCurrency.get(getCtx(), getCurrencyId());
KeyNamePair currencyKeyNamePair = new KeyNamePair(getCurrencyId(), currency.getDescription());
if (!setup.createAccounting(currencyKeyNamePair, isProductAccounting(), isBPAccounting(), isProjectAccounting(), isCampaignAccounting(), isSalesRegionAccounting(), getStartDate(), getHistoryYears(), chartofAccountsFile)) {
setup.rollback();
throw new AdempiereException("@AccountSetupError@");
}
// Generate Entities
if (!setup.createEntities(getCountryId(), getCityName(), getRegionId(), getCurrencyId(), getZIP(), getAddress1())) {
setup.rollback();
throw new AdempiereException("@AccountSetupError@");
}
// Create Bank
if (!Util.isEmpty(getBankName()) && !Util.isEmpty(getRoutingNo()) && !Util.isEmpty(getAccountNo())) {
setup.createBank(getBankName(), getRoutingNo(), getAccountNo(), getCurrencyId());
}
// load chart of accounts
if (!setup.importChart(chartofAccountsFile)) {
setup.rollback();
throw new AdempiereException("@AccountSetupError@");
}
addLog(setup.getInfo());
// Create Print Documents
PrintUtil.setupPrintForm(setup.getAD_Client_ID());
// Update translation after create a new tenant
//Adempiere-53 Changes
String whereClause = MLanguage.COLUMNNAME_IsSystemLanguage + "='Y' AND " + MLanguage.COLUMNNAME_IsActive + "='Y'";
List<MLanguage> list = new Query(Env.getCtx(), MLanguage.Table_Name, whereClause, get_TrxName()).list();
for (MLanguage lang : list) {
log.fine("Updating Translation - " + lang);
lang.maintain(true);
}
return "@OK@";
}
use of org.compiere.model.MLanguage in project adempiere by adempiere.
the class LanguageMaintenance method doIt.
// prepare
/**
* Perform process.
* @return Message (clear text)
* @throws Exception if not successful
*/
protected String doIt() throws Exception {
m_language = new MLanguage(getCtx(), p_AD_Language_ID, get_TrxName());
log.info("Mode=" + p_MaintenanceMode + ", ID=" + p_AD_Language_ID + " - " + m_language);
if (m_language.isBaseLanguage())
throw new Exception("Base Language has no Translations");
int deleteNo = 0;
int insertNo = 0;
// Delete
if (MAINTENANCEMODE_Delete.equals(p_MaintenanceMode) || MAINTENANCEMODE_ReCreate.equals(p_MaintenanceMode)) {
deleteNo = m_language.maintain(false);
}
// Add
if (MAINTENANCEMODE_Add.equals(p_MaintenanceMode) || MAINTENANCEMODE_ReCreate.equals(p_MaintenanceMode)) {
if (m_language.isActive() && m_language.isSystemLanguage()) {
insertNo = m_language.maintain(true);
} else
throw new Exception("Language not active System Language");
}
// Delete
if (MAINTENANCEMODE_Delete.equals(p_MaintenanceMode)) {
if (m_language.isSystemLanguage()) {
m_language.setIsSystemLanguage(false);
m_language.saveEx();
}
}
return "@Deleted@=" + deleteNo + " - @Inserted@=" + insertNo;
}
Aggregations