Skip to content

Commit 52399ee

Browse files
committed
2 parents e6e391d + da1bdf0 commit 52399ee

3 files changed

Lines changed: 92 additions & 86 deletions

File tree

knowagedao/src/main/java/it/eng/spagobi/commons/dao/TenantsDAOHibImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ protected String handleThemes(SbiTenant aTenant) {
777777
aTenant.getSbiOrganizationThemes().stream().filter(y -> y.getId().getUuid() == null).forEach(x -> {
778778

779779
SbiOrganizationTheme newSbiOrganizationTheme = x;
780-
SbiOrganizationThemeId sbiOrganizationThemeId = new SbiOrganizationThemeId(uuidForLambda);
780+
SbiOrganizationThemeId sbiOrganizationThemeId = new SbiOrganizationThemeId(uuidForLambda, aTenant.getId());
781781
newSbiOrganizationTheme.setId(sbiOrganizationThemeId);
782782
newSbiOrganizationTheme.setCommonInfo(sbiCommoInfo);
783783
updateSbiCommonInfo4Insert(newSbiOrganizationTheme);

knowagedao/src/main/java/it/eng/spagobi/commons/metadata/SbiOrganizationThemeId.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public SbiOrganizationThemeId(String uuid) {
5252
this.uuid = uuid;
5353
}
5454

55+
public SbiOrganizationThemeId(String uuid, int organizationId) {
56+
this.uuid = uuid;
57+
this.organizationId = organizationId;
58+
}
59+
5560
@Column(columnDefinition = "UUID", updatable = false)
5661
public String getUuid() {
5762
return uuid;

knowageutils/src/main/java/it/eng/spagobi/commons/utilities/StringUtilities.java

Lines changed: 86 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,7 @@
3232
import java.text.DateFormat;
3333
import java.text.ParseException;
3434
import java.text.SimpleDateFormat;
35-
import java.util.ArrayList;
36-
import java.util.Arrays;
37-
import java.util.Collection;
38-
import java.util.Collections;
39-
import java.util.Comparator;
40-
import java.util.Date;
41-
import java.util.Iterator;
42-
import java.util.Map;
43-
import java.util.Random;
35+
import java.util.*;
4436
import java.util.regex.Matcher;
4537

4638
import org.apache.log4j.Logger;
@@ -398,11 +390,11 @@ private static String substituteParametersInString(String statement, Map valuesM
398390
String prefix = "";
399391
String split = "";
400392
String suffix = "";
401-
boolean attributeExcpetedToBeMultiValue = false;
393+
boolean attributeExpectedToBeMultiValue = false;
402394

403395
if (startConfigIndex != -1) {
404396
// the parameter is expected to be multivalue
405-
attributeExcpetedToBeMultiValue = true;
397+
attributeExpectedToBeMultiValue = true;
406398
int endConfigIndex = attribute.length() - 1;
407399
if (attribute.charAt(endConfigIndex) != ')')
408400
throw new Exception("Sintax error: \")\" missing. The expected sintax for "
@@ -425,83 +417,92 @@ private static String substituteParametersInString(String statement, Map valuesM
425417
LOGGER.debug("Expected single-value parameter name: '" + attributeName + "'");
426418
}
427419

428-
String value = (String) valuesMap.get(attributeName);
429-
if (value == null) {
430-
throw new Exception("Parameter '" + attributeName + "' not set.");
431-
432-
} else {
433-
434-
if (value.startsWith("' {"))
435-
value = value.substring(1);
436-
if (value.endsWith("}'"))
437-
value = value.substring(0, value.indexOf("}'") + 1);
438-
value = value.trim();
439-
LOGGER.debug("Parameter value found: " + value);
440-
String replacement = null;
441-
String newListOfValues = null;
442-
if (attributeExcpetedToBeMultiValue) {
443-
if (value.startsWith("{")) {
444-
// the parameter is multi-value
445-
String[] values = findAttributeValues(value);
446-
LOGGER.debug("N. " + values.length + " parameter values found: '" + values + "'");
447-
newListOfValues = values[0];
448-
for (int i = 1; i < values.length; i++) {
449-
newListOfValues = newListOfValues + split + values[i];
450-
}
451-
} else {
452-
LOGGER.warn(
453-
"The attribute value has not the sintax of a multi value parameter; considering it as a single value.");
454-
newListOfValues = value;
455-
}
456-
} else {
457-
if (value.startsWith("{")) {
458-
// the profile attribute is multi-value
459-
LOGGER.warn(
460-
"The attribute value seems to be a multi value parameter; trying considering it as a multi value using its own splitter and no prefix and suffix.");
461-
try {
462-
// checks the sintax
463-
String[] values = findAttributeValues(value);
464-
newListOfValues = values[0];
465-
for (int i = 1; i < values.length; i++) {
466-
newListOfValues = newListOfValues + value.charAt(1) + values[i];
467-
}
468-
} catch (Exception e) {
469-
LOGGER.error(
470-
"The attribute value does not respect the sintax of a multi value attribute; considering it as a single value.",
471-
e);
472-
newListOfValues = value;
473-
}
474-
} else {
475-
newListOfValues = value;
476-
}
477-
}
478-
479-
replacement = prefix + newListOfValues + suffix;
480-
481-
// if is specified a particular type for the parameter can add '' in case of String or Date
482-
String parType = null;
483-
if (parTypeMap != null) {
484-
parType = (String) parTypeMap.get(attributeName);
485-
}
486-
if (parType == null)
487-
parType = new String("");
488-
489-
if (surroundWithQuotes || parType.equalsIgnoreCase("STRING") || parType.equalsIgnoreCase("DATE")) {
490-
if (!replacement.startsWith("'"))
491-
replacement = "'" + replacement;
492-
if (!replacement.endsWith("'"))
493-
replacement = replacement + "'";
494-
495-
replacement = escapeInternalQuotes(replacement);
496-
}
420+
StringBuilder value = new StringBuilder((String) valuesMap.get(attributeName));
421+
List<String> singleValues = new ArrayList<>();
422+
// get all comma separated values
423+
StringTokenizer st = new StringTokenizer(value.toString(), ",");
424+
value = new StringBuilder();
425+
426+
while (st.hasMoreTokens()) {
427+
singleValues.add(st.nextToken());
428+
}
429+
for (String singleValue : singleValues) {
430+
String escapedValue = escapeInternalQuotes(singleValue);
431+
if (value.isEmpty()) {
432+
value = new StringBuilder(escapedValue);
433+
} else {
434+
value.append(",").append(escapedValue);
435+
}
436+
}
437+
438+
if (value.toString().startsWith("' {"))
439+
value = new StringBuilder(value.substring(1));
440+
if (value.toString().endsWith("}'"))
441+
value = new StringBuilder(value.substring(0, value.indexOf("}'") + 1));
442+
value = new StringBuilder(value.toString().trim());
443+
LOGGER.debug("Parameter value found: " + value);
444+
String replacement = null;
445+
String newListOfValues = null;
446+
if (attributeExpectedToBeMultiValue) {
447+
if (value.toString().startsWith("{")) {
448+
// the parameter is multi-value
449+
String[] values = findAttributeValues(value.toString());
450+
LOGGER.debug("N. " + values.length + " parameter values found: '" + values + "'");
451+
newListOfValues = values[0];
452+
for (int i = 1; i < values.length; i++) {
453+
newListOfValues = newListOfValues + split + values[i];
454+
}
455+
} else {
456+
LOGGER.warn(
457+
"The attribute value has not the sintax of a multi value parameter; considering it as a single value.");
458+
newListOfValues = value.toString();
459+
}
460+
} else {
461+
if (value.toString().startsWith("{")) {
462+
// the profile attribute is multi-value
463+
LOGGER.warn(
464+
"The attribute value seems to be a multi value parameter; trying considering it as a multi value using its own splitter and no prefix and suffix.");
465+
try {
466+
// checks the sintax
467+
String[] values = findAttributeValues(value.toString());
468+
newListOfValues = values[0];
469+
for (int i = 1; i < values.length; i++) {
470+
newListOfValues = newListOfValues + value.charAt(1) + values[i];
471+
}
472+
} catch (Exception e) {
473+
LOGGER.error(
474+
"The attribute value does not respect the sintax of a multi value attribute; considering it as a single value.",
475+
e);
476+
newListOfValues = value.toString();
477+
}
478+
} else {
479+
newListOfValues = value.toString();
480+
}
481+
}
482+
483+
replacement = prefix + newListOfValues + suffix;
484+
485+
// if is specified a particular type for the parameter can add '' in case of String or Date
486+
String parType = null;
487+
if (parTypeMap != null) {
488+
parType = (String) parTypeMap.get(attributeName);
489+
}
490+
if (parType == null)
491+
parType = new String("");
492+
493+
if (surroundWithQuotes || parType.equalsIgnoreCase("STRING") || parType.equalsIgnoreCase("DATE")) {
494+
if (!replacement.startsWith("'"))
495+
replacement = "'" + replacement;
496+
if (!replacement.endsWith("'"))
497+
replacement = replacement + "'";
498+
}
497499

498-
attribute = quote(attribute);
499-
statement = statement.replaceAll("\\$P\\{" + attribute + "\\}", replacement);
500+
attribute = quote(attribute);
501+
statement = statement.replaceAll("\\$P\\{" + attribute + "\\}", replacement);
500502

501-
LOGGER.debug("OUT");
502-
}
503+
LOGGER.debug("OUT");
503504

504-
return statement;
505+
return statement;
505506

506507
}
507508

0 commit comments

Comments
 (0)