Skip to content

Commit 1c54843

Browse files
committed
Bug #4393 :
- modifying the treatment that computing technical domain database name (replacing each sequence of special characters by one underscore and modifying the maximum length of database table/column name from 42 to 30 (due to Oracle limitations)) - fixing the non deletion of domain property file when a domain is deleted
1 parent 4c4f867 commit 1c54843

File tree

3 files changed

+69
-55
lines changed

3 files changed

+69
-55
lines changed

lib-core/src/main/java/com/stratelia/silverpeas/domains/sqldriver/SQLSettings.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
*/
3636

3737
public class SQLSettings extends DriverSettings {
38+
39+
// Definitions of max lengths due to limitations on Oracle databases
40+
public static final int DATABASE_TABLE_NAME_MAX_LENGTH = 30;
41+
public static final int DATABASE_COLUMN_NAME_MAX_LENGTH = 30;
42+
3843
// For DB Access
3944
protected String SQLClassName = "";
4045
protected String SQLJDBCUrl = "";

lib-core/src/main/java/org/silverpeas/admin/domain/SQLDomainService.java

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,31 @@
2424

2525
package org.silverpeas.admin.domain;
2626

27-
import java.io.File;
28-
import java.io.FileWriter;
29-
import java.io.IOException;
30-
import java.io.PrintWriter;
31-
32-
import javax.annotation.PostConstruct;
33-
import javax.inject.Inject;
34-
import javax.inject.Named;
35-
36-
import org.silverpeas.admin.domain.exception.DomainAuthenticationPropertiesAlreadyExistsException;
37-
import org.silverpeas.admin.domain.exception.DomainConflictException;
38-
import org.silverpeas.admin.domain.exception.DomainCreationException;
39-
import org.silverpeas.admin.domain.exception.DomainDeletionException;
40-
import org.silverpeas.admin.domain.exception.DomainPropertiesAlreadyExistsException;
41-
import org.silverpeas.admin.domain.repository.SQLDomainRepository;
42-
4327
import com.silverpeas.util.StringUtil;
4428
import com.silverpeas.util.template.SilverpeasTemplate;
4529
import com.silverpeas.util.template.SilverpeasTemplateFactory;
30+
import com.stratelia.silverpeas.domains.sqldriver.SQLSettings;
4631
import com.stratelia.silverpeas.silvertrace.SilverTrace;
4732
import com.stratelia.webactiv.beans.admin.AdminException;
4833
import com.stratelia.webactiv.beans.admin.Domain;
4934
import com.stratelia.webactiv.util.FileRepositoryManager;
5035
import com.stratelia.webactiv.util.FileServerUtils;
5136
import com.stratelia.webactiv.util.ResourceLocator;
37+
import org.silverpeas.admin.domain.exception.DomainAuthenticationPropertiesAlreadyExistsException;
38+
import org.silverpeas.admin.domain.exception.DomainConflictException;
39+
import org.silverpeas.admin.domain.exception.DomainCreationException;
40+
import org.silverpeas.admin.domain.exception.DomainDeletionException;
41+
import org.silverpeas.admin.domain.exception.DomainPropertiesAlreadyExistsException;
42+
import org.silverpeas.admin.domain.repository.SQLDomainRepository;
43+
44+
import javax.annotation.PostConstruct;
45+
import javax.inject.Inject;
46+
import javax.inject.Named;
47+
import java.io.File;
48+
import java.io.FileWriter;
49+
import java.io.IOException;
50+
import java.io.PrintWriter;
51+
import java.text.Normalizer;
5252

5353
@Named("sqlDomainService")
5454
public class SQLDomainService extends AbstractDomainService {
@@ -66,7 +66,9 @@ void init() {
6666
adminSettings = new ResourceLocator("org.silverpeas.beans.admin.admin", "");
6767
}
6868

69-
private void checkFileName(String fileDomainName) throws DomainAuthenticationPropertiesAlreadyExistsException, DomainPropertiesAlreadyExistsException {
69+
private void checkFileName(String fileDomainName)
70+
throws DomainAuthenticationPropertiesAlreadyExistsException,
71+
DomainPropertiesAlreadyExistsException {
7072
// Check properties files availability
7173
// org.silverpeas.domains.domain<domainName>.properties
7274
// org.silverpeas.authentication.autDomain<domainName>.properties
@@ -83,23 +85,25 @@ private void checkFileName(String fileDomainName) throws DomainAuthenticationPro
8385
}
8486
}
8587

86-
//transformation du nom du domaine, nécessaire pour pouvoir créer les fichiers sur le fileSystem
87-
//et créer les tables dans la BD
88+
/**
89+
* Gets a file name without special characters and without accentued characters in the aim to
90+
* create domain property files safely on file system.
91+
* @param domainName domain name with maybe some special characters and/or accentued characters
92+
* @return
93+
*/
8894
private String getCorrectDomainFileName(String domainName) {
89-
//remplace les caractères accentués non compatibles avec les fichiers fileSystem et les noms de tables BD par les caractères non accentués correspondants
95+
96+
// Normalizing (accents, puissance, ...)
9097
String fileDomainName = FileServerUtils.replaceAccentChars(domainName);
98+
fileDomainName = Normalizer.normalize(fileDomainName, Normalizer.Form.NFKD);
9199

92-
//remplace les caractères spéciaux et les espaces non compatibles avec les fichiers fileSystem et les noms de tables BD par caractère '_'
93-
fileDomainName = fileDomainName.replaceAll("[^A-Za-z0-9]", "_");
100+
// Replacing of each sequence of special characters by one underscore
101+
fileDomainName = fileDomainName.replaceAll("[^\\p{Alnum}]+", "_");
94102

95-
//tronque le nom à 42 caractères pour être compatible avec les noms de tables BD
96-
if (fileDomainName.length()>42) {
97-
fileDomainName = fileDomainName.substring(0, 42);
103+
// Limitations of some databases on length of table or column names
104+
return StringUtil.left(fileDomainName, SQLSettings.DATABASE_TABLE_NAME_MAX_LENGTH);
98105
}
99106

100-
return fileDomainName;
101-
}
102-
103107
@Override
104108
public String createDomain(Domain domainToCreate) throws DomainConflictException,
105109
DomainCreationException {
@@ -168,9 +172,16 @@ public String createDomain(Domain domainToCreate) throws DomainConflictException
168172
@Override
169173
public String deleteDomain(Domain domainToRemove) throws DomainDeletionException {
170174

171-
//set nouveau nom pour le fileSystem et la BD
172-
String domainPropertiesPath = domainToRemove.getPropFileName();
173-
String fileDomainName = domainPropertiesPath.substring(29); //supprime org.silverpeas.domains.domain
175+
// Retrieve the prefix of a domain property file name
176+
String separator = "#@#@#@#@#";
177+
String domainPropertyPrefix = new File(
178+
FileRepositoryManager.getDomainPropertiesPath(separator).replaceAll(separator + ".*$", ""))
179+
.getName();
180+
// Get the domain property file name without the package
181+
String domainPropertyFileName =
182+
domainToRemove.getPropFileName().replaceAll("[\\p{Alnum}]+\\.+", "");
183+
// Compute the common property file name by removing the prefix of a domain property file name
184+
String fileDomainName = domainPropertyFileName.replaceFirst(domainPropertyPrefix, "");
174185
domainToRemove.setName(fileDomainName);
175186

176187
// unregister new Domain dans st_domain
@@ -210,10 +221,7 @@ private void removePropertiesFiles(String domainName) {
210221
* @throws DomainCreationException
211222
*/
212223
private void generateDomainPropertiesFile(Domain domainToCreate) throws DomainCreationException {
213-
SilverTrace
214-
.info(
215-
"admin",
216-
"SQLDomainService.generateDomainPropertiesFile()",
224+
SilverTrace.info("admin", "SQLDomainService.generateDomainPropertiesFile()",
217225
"root.MSG_GEN_ENTER_METHOD");
218226

219227
String domainName = domainToCreate.getName();
@@ -252,10 +260,7 @@ private void generateDomainPropertiesFile(Domain domainToCreate) throws DomainCr
252260
*/
253261
private void generateDomainAuthenticationPropertiesFile(Domain domainToCreate)
254262
throws DomainCreationException {
255-
SilverTrace
256-
.info(
257-
"admin",
258-
"SQLDomainService.generateDomainAuthenticationPropertiesFile()",
263+
SilverTrace.info("admin", "SQLDomainService.generateDomainAuthenticationPropertiesFile()",
259264
"root.MSG_GEN_ENTER_METHOD");
260265

261266
String domainName = domainToCreate.getName();
@@ -287,20 +292,19 @@ private void generateDomainAuthenticationPropertiesFile(Domain domainToCreate)
287292
"SQLDomainService.generateDomainAuthenticationPropertiesFile()", domainToCreate
288293
.toString(), e);
289294
} finally {
295+
if (out != null) {
290296
out.close();
291297
}
292298
}
299+
}
293300

294301
/**
295302
* Remove domain authentication and settings properties file
296303
* @param domainToRemove domain to remove
297304
* @throws DomainDeletionException
298305
*/
299306
private void removeDomainPropertiesFile(Domain domainToRemove) {
300-
SilverTrace
301-
.info(
302-
"admin",
303-
"SQLDomainService.removeDomainAuthenticationPropertiesFile()",
307+
SilverTrace.info("admin", "SQLDomainService.removeDomainAuthenticationPropertiesFile()",
304308
"root.MSG_GEN_ENTER_METHOD");
305309

306310
String domainName = domainToRemove.getName();
@@ -314,11 +318,8 @@ private void removeDomainPropertiesFile(Domain domainToRemove) {
314318
boolean domainPropertiesFileDeleted = domainPropertiesFile.delete();
315319
boolean authenticationPropertiesFileDeleted = authenticationPropertiesFile.delete();
316320

317-
if ((!domainPropertiesFileDeleted) || (!authenticationPropertiesFileDeleted)) {
318-
SilverTrace
319-
.warn(
320-
"admin",
321-
"SQLDomainService.removeDomainAuthenticationPropertiesFile()",
321+
if (!(domainPropertiesFileDeleted && authenticationPropertiesFileDeleted)) {
322+
SilverTrace.warn("admin", "SQLDomainService.removeDomainAuthenticationPropertiesFile()",
322323
"admin.EX_DELETE_DOMAIN_PROPERTIES", "domainPropertiesFileDeleted:" +
323324
domainPropertiesFileDeleted + ", authenticationPropertiesFileDeleted:" +
324325
authenticationPropertiesFileDeleted);

lib-core/src/main/java/org/silverpeas/admin/domain/repository/SQLInternalDomainRepository.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,21 @@
2626

2727
import com.stratelia.webactiv.beans.admin.Domain;
2828
import com.stratelia.webactiv.util.FileRepositoryManager;
29-
import java.io.FileInputStream;
30-
import java.io.FileNotFoundException;
31-
import java.io.IOException;
32-
import java.util.Properties;
33-
import javax.inject.Named;
34-
import javax.sql.DataSource;
29+
import org.apache.commons.io.IOUtils;
3530
import org.silverpeas.admin.domain.exception.SQLDomainDAOException;
3631
import org.springframework.beans.factory.annotation.Autowired;
3732
import org.springframework.jdbc.core.JdbcTemplate;
3833
import org.springframework.stereotype.Repository;
3934
import org.springframework.transaction.annotation.Propagation;
4035
import org.springframework.transaction.annotation.Transactional;
4136

37+
import javax.inject.Named;
38+
import javax.sql.DataSource;
39+
import java.io.FileInputStream;
40+
import java.io.FileNotFoundException;
41+
import java.io.IOException;
42+
import java.util.Properties;
43+
4244
@Repository
4345
@Named("sqlInternalDomainRepository")
4446
public class SQLInternalDomainRepository implements SQLDomainRepository {
@@ -117,7 +119,13 @@ private String generateGroupTableDropStatement(String domainName) {
117119
private String generateUserTableCreateStatement(String domainName) throws FileNotFoundException,
118120
IOException {
119121
Properties props = new Properties();
120-
props.load(new FileInputStream(FileRepositoryManager.getDomainPropertiesPath(domainName)));
122+
FileInputStream fis = null;
123+
try {
124+
fis = new FileInputStream(FileRepositoryManager.getDomainPropertiesPath(domainName));
125+
props.load(fis);
126+
} finally {
127+
IOUtils.closeQuietly(fis);
128+
}
121129
int numberOfColumns = Integer.parseInt(props.getProperty("property.Number"));
122130

123131
StringBuilder createStatement = new StringBuilder();

0 commit comments

Comments
 (0)