Skip to content

Commit ec21285

Browse files
Merge pull request #1052 from oracle/WDT-599-filters
fixing output of boolean filter fields already set
2 parents 873ad79 + 60dec97 commit ec21285

File tree

22 files changed

+166
-86
lines changed

22 files changed

+166
-86
lines changed

core/src/main/java/oracle/weblogic/deploy/json/AbstractJsonTranslator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
*/
55
package oracle.weblogic.deploy.json;
@@ -12,6 +12,7 @@
1212
import oracle.weblogic.deploy.exception.ExceptionHelper;
1313
import oracle.weblogic.deploy.logging.PlatformLogger;
1414
import oracle.weblogic.deploy.util.PyOrderedDict;
15+
import oracle.weblogic.deploy.util.PyRealBoolean;
1516
import oracle.weblogic.deploy.util.StringUtils;
1617

1718
import org.antlr.v4.runtime.CharStream;
@@ -240,7 +241,7 @@ public void exitJsonNumber(JSONParser.JsonNumberContext ctx) {
240241
*/
241242
@Override
242243
public void enterJsonTrue(JSONParser.JsonTrueContext ctx) {
243-
currentScalarValue = new PyString("true");
244+
currentScalarValue = new PyRealBoolean(true);
244245
currentValueType.push(ValueType.SCALAR);
245246
}
246247

@@ -257,7 +258,7 @@ public void exitJsonTrue(JSONParser.JsonTrueContext ctx) {
257258
*/
258259
@Override
259260
public void enterJsonFalse(JSONParser.JsonFalseContext ctx) {
260-
currentScalarValue = new PyString("false");
261+
currentScalarValue = new PyRealBoolean(false);
261262
currentValueType.push(ValueType.SCALAR);
262263
}
263264

core/src/main/java/oracle/weblogic/deploy/util/PyOrderedDict.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle Corporation and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
*/
55
package oracle.weblogic.deploy.util;
@@ -521,6 +521,8 @@ private static PyObject doDeepCopy(PyObject orig, PyObject memo) {
521521
case "NoneType":
522522
case "str":
523523
case "unicode":
524+
case "PyRealBoolean":
525+
case "oracle.weblogic.deploy.util.PyRealBoolean":
524526
result = orig;
525527
break;
526528

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates.
3+
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
*/
5+
package oracle.weblogic.deploy.util;
6+
7+
import org.python.core.Py;
8+
import org.python.core.PyObject;
9+
import org.python.core.PyString;
10+
11+
/**
12+
* A boolean value that can be passed to and from parsers, and converted to other types.
13+
* The PyBoolean type doesn't exist before Jython 2.7, so this allows
14+
* boolean values to be distinguished from other types.
15+
*/
16+
public class PyRealBoolean extends PyObject {
17+
private final boolean isTrue;
18+
19+
public PyRealBoolean(boolean isTrue) {
20+
this.isTrue = isTrue;
21+
}
22+
23+
public boolean getValue() {
24+
return isTrue;
25+
}
26+
27+
// support Python copy.deepcopy()
28+
public PyRealBoolean __deepcopy__(PyObject memo) {
29+
return new PyRealBoolean(isTrue);
30+
}
31+
32+
@Override
33+
// for Python equality checks like abc == xyz
34+
public PyObject __eq__(PyObject ob_other) {
35+
return equals(ob_other) ? Py.One : Py.Zero;
36+
}
37+
38+
@Override
39+
// for Python inequality checks like abc != xyz
40+
public PyObject __ne__(PyObject ob_other) {
41+
return equals(ob_other) ? Py.Zero : Py.One;
42+
}
43+
44+
@Override
45+
// for Python string conversion, like str(abc)
46+
public PyString __str__() {
47+
return new PyString(toString());
48+
}
49+
50+
@Override
51+
// for Python boolean check, such as bool(abc), or if abc...
52+
public boolean __nonzero__() {
53+
return isTrue;
54+
}
55+
56+
@Override
57+
public boolean equals(Object other) {
58+
if(other instanceof PyRealBoolean) {
59+
return isTrue == ((PyRealBoolean) other).isTrue;
60+
}
61+
return false;
62+
}
63+
64+
@Override
65+
public String toString() {
66+
return String.valueOf(isTrue);
67+
}
68+
}

core/src/main/java/oracle/weblogic/deploy/yaml/AbstractYamlTranslator.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
*/
55
package oracle.weblogic.deploy.yaml;
@@ -15,6 +15,7 @@
1515
import oracle.weblogic.deploy.logging.PlatformLogger;
1616
import oracle.weblogic.deploy.util.PyOrderedDict;
1717

18+
import oracle.weblogic.deploy.util.PyRealBoolean;
1819
import org.python.core.Py;
1920
import org.python.core.PyDictionary;
2021
import org.python.core.PyFloat;
@@ -233,12 +234,7 @@ private PyObject convertScalarToPythonObject(Object object) throws YamlException
233234
break;
234235

235236
case "java.lang.Boolean":
236-
boolean booleanValue = (Boolean) object;
237-
if (booleanValue) {
238-
result = new PyString("true");
239-
} else {
240-
result = new PyString("false");
241-
}
237+
result = new PyRealBoolean((Boolean) object);
242238
break;
243239

244240
case "java.lang.Integer":

core/src/main/python/wlsdeploy/aliases/alias_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2021, Oracle and/or its affiliates.
2+
Copyright (c) 2017, 2022, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
import copy
@@ -18,10 +18,12 @@
1818
from java.util import Properties
1919
from javax.management import ObjectName
2020

21+
from oracle.weblogic.deploy.util import PyRealBoolean
2122
from oracle.weblogic.deploy.aliases import TypeUtils
2223
from oracle.weblogic.deploy.aliases import VersionException
2324
from oracle.weblogic.deploy.aliases import VersionUtils
2425

26+
from wlsdeploy.aliases.alias_constants import BOOLEAN
2527
from wlsdeploy.aliases.alias_constants import ChildFoldersTypes
2628
from wlsdeploy.aliases.model_constants import MODEL_LIST_DELIMITER
2729
from wlsdeploy.exception import exception_helper
@@ -533,6 +535,8 @@ def convert_boolean(value):
533535
result = True
534536
elif value.lower() == 'false':
535537
result = False
538+
elif isinstance(value, PyRealBoolean):
539+
result = value.getValue()
536540
return result
537541

538542

@@ -845,6 +849,8 @@ def _convert_value_to_model_type(data_type, value, delimiter):
845849
try:
846850
if data_type == JAVA_LANG_BOOLEAN:
847851
converted = Boolean(converted)
852+
elif data_type == BOOLEAN:
853+
converted = PyRealBoolean('true' == converted)
848854
elif data_type == JARRAY:
849855
converted = _create_array(converted, delimiter)
850856
# elif data_type == PROPERTIES:

core/src/main/python/wlsdeploy/aliases/aliases.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2022, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
from java.lang import String
@@ -768,8 +768,8 @@ def get_model_restart_required_attribute_names(self, location):
768768

769769
for key, value in module_folder[ATTRIBUTES].iteritems():
770770
if RESTART_REQUIRED in value:
771-
restart_required_value = value[RESTART_REQUIRED]
772-
if "true" == restart_required_value.lower():
771+
restart_required = alias_utils.convert_boolean(value[RESTART_REQUIRED])
772+
if restart_required:
773773
restart_attribute_names.append(key)
774774

775775
return restart_attribute_names

core/src/main/python/wlsdeploy/json/json_translator.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2022, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
55
This model provider translation classes that convert between JSON and Python Dictionaries.
@@ -18,7 +18,6 @@
1818
import oracle.weblogic.deploy.json.JsonTranslator as JJsonTranslator
1919

2020
from wlsdeploy.logging.platform_logger import PlatformLogger
21-
from wlsdeploy.util.boolean_value import BooleanValue
2221
import wlsdeploy.exception.exception_helper as exception_helper
2322

2423
# Unlike with yaml files, JSON files do not allow comments. remove from file
@@ -240,8 +239,6 @@ def _format_json_value(value):
240239
builder = StringBuilder()
241240
if type(value) == bool:
242241
builder.append(JBoolean.toString(value))
243-
elif isinstance(value, BooleanValue):
244-
builder.append(value.get_string_value())
245242
elif isinstance(value, types.StringTypes):
246243
builder.append('"').append(_escape_text(value.strip())).append('"')
247244
else:

core/src/main/python/wlsdeploy/tool/create/domain_creator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ def __create_machines_clusters_and_servers(self, delete_now=True):
865865
# Listen Port for 7001 in order to show up in the config.xml
866866
if len(server_template_nodes) > 0:
867867
for template in server_template_nodes:
868-
listen_port = dictionary_utils.get_dictionary_element(self._topology[SERVER_TEMPLATE][template], LISTEN_PORT)
868+
listen_port = dictionary_utils.get_element(self._topology[SERVER_TEMPLATE][template], LISTEN_PORT)
869869
if listen_port is not None:
870870
temp_loc = LocationContext()
871871
temp_loc.append_location(SERVER_TEMPLATE)

core/src/main/python/wlsdeploy/tool/discover/discoverer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ def _populate_model_parameters(self, dictionary, location):
127127
# Find the attributes that are not in the LSA wlst map but are in the alias definitions with GET access
128128
get_attributes = [get_param for get_param in wlst_get_params if not get_param in wlst_did_get]
129129
for get_attribute in get_attributes:
130-
success, wlst_value = self._get_attribute_value_with_get(wlst_extra_param, wlst_path)
130+
success, wlst_value = self._get_attribute_value_with_get(get_attribute, wlst_path)
131131
if success:
132-
self._add_to_dictionary(dictionary, location, wlst_extra_param, wlst_value, wlst_path)
132+
self._add_to_dictionary(dictionary, location, get_attribute, wlst_value, wlst_path)
133133

134134
def _get_attribute_value_with_get(self, wlst_get_param, wlst_path):
135135
_method_name = '_get_attribute_value_with_get'

core/src/main/python/wlsdeploy/tool/discover/topology_discoverer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2022, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
from java.io import File
@@ -12,6 +12,7 @@
1212
from oracle.weblogic.deploy.util import StringUtils
1313
from oracle.weblogic.deploy.util import WLSDeployArchiveIOException
1414

15+
from wlsdeploy.aliases import alias_utils
1516
from wlsdeploy.aliases import model_constants
1617
from wlsdeploy.aliases.location_context import LocationContext
1718
from wlsdeploy.aliases.model_constants import MODEL_LIST_DELIMITER
@@ -588,8 +589,9 @@ def _massage_security_credential(self, result, location):
588589
short_name = self._credential_injector.get_folder_short_name(location)
589590
if model_constants.SECURITY_CONFIGURATION_PASSWORD in result:
590591
# default is false
591-
if model_constants.SECURITY_CONFIGURATION_CD_ENABLED not in result or \
592-
Boolean.valueOf(result[model_constants.SECURITY_CONFIGURATION_CD_ENABLED]) == Boolean.FALSE:
592+
cd_enabled_raw = dictionary_utils.get_element(result, model_constants.SECURITY_CONFIGURATION_CD_ENABLED)
593+
cd_enabled = alias_utils.convert_boolean(cd_enabled_raw)
594+
if not cd_enabled:
593595
# Hard code it here or hard code it later. The target code will bypass tokenize of variable
594596
cache_name = short_name + VARIABLE_SEP + model_constants.SECURITY_CONFIGURATION_PASSWORD
595597
if cache_name in pass_cache:

0 commit comments

Comments
 (0)