diff options
Diffstat (limited to 'src/main/java')
7 files changed, 108 insertions, 99 deletions
diff --git a/src/main/java/org/onap/clamp/clds/Application.java b/src/main/java/org/onap/clamp/clds/Application.java index 63320d2fe..84232999e 100644 --- a/src/main/java/org/onap/clamp/clds/Application.java +++ b/src/main/java/org/onap/clamp/clds/Application.java @@ -65,8 +65,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.transaction.annotation.EnableTransactionManagement; @ComponentScan(basePackages = { "org.onap.clamp" }) -@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class, - UserDetailsServiceAutoConfiguration.class }) +@SpringBootApplication(exclude = { SecurityAutoConfiguration.class, UserDetailsServiceAutoConfiguration.class }) @EnableJpaRepositories(basePackages = { "org.onap.clamp" }) @EntityScan(basePackages = { "org.onap.clamp" }) @EnableTransactionManagement diff --git a/src/main/java/org/onap/clamp/clds/config/EncodedPasswordBasicDataSource.java b/src/main/java/org/onap/clamp/clds/config/EncodedPasswordBasicDataSource.java deleted file mode 100644 index 0d39cd54d..000000000 --- a/src/main/java/org/onap/clamp/clds/config/EncodedPasswordBasicDataSource.java +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.config; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -import java.security.GeneralSecurityException; - -import org.apache.commons.codec.DecoderException; -import org.apache.commons.dbcp.BasicDataSource; -import org.onap.clamp.clds.util.CryptoUtils; - -/** - * This class is an extension of the standard datasource, it will be used to - * decode the encoded password defined in the application.properties. - * - */ -public class EncodedPasswordBasicDataSource extends BasicDataSource { - protected static final EELFLogger logger = EELFManager.getInstance() - .getLogger(EncodedPasswordBasicDataSource.class); - protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); - - /** - * This method is used automatically by Spring to decode the password. - */ - @Override - public synchronized void setPassword(String encodedPassword) { - try { - this.password = CryptoUtils.decrypt(encodedPassword); - } catch (GeneralSecurityException e) { - logger.error("Unable to decrypt the DB password", e); - } catch (DecoderException e) { - logger.error("Exception caught when decoding the HEX String Key for encryption", e); - } - } -}
\ No newline at end of file diff --git a/src/main/java/org/onap/clamp/clds/config/spring/CldsConfiguration.java b/src/main/java/org/onap/clamp/clds/config/spring/CldsConfiguration.java index b2478462f..14c08c800 100644 --- a/src/main/java/org/onap/clamp/clds/config/spring/CldsConfiguration.java +++ b/src/main/java/org/onap/clamp/clds/config/spring/CldsConfiguration.java @@ -23,13 +23,9 @@ package org.onap.clamp.clds.config.spring; -import javax.sql.DataSource; - import org.onap.clamp.clds.config.ClampProperties; -import org.onap.clamp.clds.config.EncodedPasswordBasicDataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.PropertiesFactoryBean; -import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -44,16 +40,6 @@ public class CldsConfiguration { @Autowired private ClampProperties refProp; - /** - * Clds Identity database DataSource configuration. - * - * @return encoded password data source - */ - @Bean(name = "cldsDataSource") - @ConfigurationProperties(prefix = "spring.datasource.cldsdb") - public DataSource cldsDataSource() { - return new EncodedPasswordBasicDataSource(); - } /** * This loads the file system.properties. diff --git a/src/main/java/org/onap/clamp/clds/tosca/JsonEditorSchemaConstants.java b/src/main/java/org/onap/clamp/clds/tosca/JsonEditorSchemaConstants.java index fdc94231f..e3c661698 100644 --- a/src/main/java/org/onap/clamp/clds/tosca/JsonEditorSchemaConstants.java +++ b/src/main/java/org/onap/clamp/clds/tosca/JsonEditorSchemaConstants.java @@ -28,8 +28,10 @@ public class JsonEditorSchemaConstants { //Data types in JSON Schema public static final String TYPE_OBJECT = "object"; public static final String TYPE_ARRAY = "array"; + public static final String TYPE_MAP = "map"; public static final String TYPE_STRING = "string"; public static final String TYPE_INTEGER = "integer"; + public static final String TYPE_DATE_TIME = "datetime"; //Key elements in JSON Schema public static final String TYPE = "type"; @@ -43,6 +45,9 @@ public class JsonEditorSchemaConstants { public static final String ITEMS = "items"; public static final String PROPERTIES = "properties"; public static final String PROPERTY_ORDER = "propertyOrder"; + public static final String VALUES = "values"; + public static final String HEADER_TEMPLATE = "headerTemplate"; + public static final String HEADER_TEMPLATE_VALUE = "{{self.name}}"; public static final String MINIMUM = "minimum"; public static final String MAXIMUM = "maximum"; @@ -50,9 +55,13 @@ public class JsonEditorSchemaConstants { public static final String MAX_LENGTH = "maxLength"; public static final String EXCLUSIVE_MINIMUM = "exclusiveMinimum"; public static final String EXCLUSIVE_MAXIMUM = "exclusiveMaximum"; + public static final String MINITEMS = "minItems"; + public static final String MAXITEMS = "maxItems"; public static final String CUSTOM_KEY_FORMAT = "format"; public static final String CUSTOM_KEY_FORMAT_TABS_TOP = "tabs-top"; + public static final String CUSTOM_KEY_FORMAT_TABS = "tabs"; + public static final String CUSTOM_KEY_FORMAT_INPUT = "input"; public static final String FORMAT_SELECT = "select"; public static final String UNIQUE_ITEMS = "uniqueItems"; public static final String TRUE = "true"; @@ -67,5 +76,11 @@ public class JsonEditorSchemaConstants { public static final String SCHEMA = "schema"; public static final String CURRENT_VALUES = "currentValues"; + public static final String PLUGIN = "plugin"; + public static final String DATE_TIME_PICKER = "datetimepicker"; + public static final String VALIDATION = "validation"; + public static final String DATE_TIME_FORMAT = "YYYY/MM/DD HH:mm:ss"; + public static final String INPUT_EVENT = "input_event"; + public static final String DP_CHANGE = "dp.change"; } diff --git a/src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java b/src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java index 9601649c9..d00c431c8 100644 --- a/src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java +++ b/src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java @@ -30,8 +30,11 @@ public class ToscaSchemaConstants { public static final String TYPE_MAP = "map"; public static final String TYPE_STRING = "string"; public static final String TYPE_INTEGER = "integer"; + public static final String TYPE_NUMBER = "number"; + public static final String TYPE_DATE_TIME = "datetime"; public static final String TYPE_FLOAT = "float"; public static final String TYPE_BOOLEAN = "boolean"; + public static final String TYPE_USER_DEFINED = "userDefined"; // Key elements in Tosca public static final String NODE_TYPES = "policy_types"; @@ -46,6 +49,8 @@ public class ToscaSchemaConstants { public static final String METADATA = "metadata"; public static final String METADATA_POLICY_MODEL_TYPE = "policy_model_type"; public static final String METADATA_ACRONYM = "acronym"; + public static final String METADATA_ELEMENT_NAME = "element_name"; + public static final String METADATA_HEADER_TEMPLATE = "header_template"; public static final String METADATA_CLAMP_POSSIBLE_VALUES = "clamp_possible_values"; // Constraints diff --git a/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java b/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java index 666ca6702..45bb87ed8 100644 --- a/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java +++ b/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java @@ -38,6 +38,7 @@ import java.util.stream.Collectors; import org.json.JSONArray; import org.json.JSONObject; import org.onap.clamp.clds.config.ClampProperties; +import org.onap.clamp.tosca.Dictionary; import org.onap.clamp.tosca.DictionaryElement; import org.onap.clamp.tosca.DictionaryService; import org.springframework.beans.factory.annotation.Autowired; @@ -142,6 +143,13 @@ public class ToscaYamlToJsonConvertor { parseNodeAndDataType(loadedYaml, nodeTypes, dataNodes); populateJsonEditorObject(loadedYaml, nodeTypes, dataNodes, jsonParentObject, jsonTempObject, modelTypeToUse); + + String headerTemplate = getValueFromMetadata(validateAndConvertToJson(yamlString), + ToscaSchemaConstants.METADATA_HEADER_TEMPLATE); + if (headerTemplate != null) { + jsonParentObject.put(JsonEditorSchemaConstants.HEADER_TEMPLATE, + JsonEditorSchemaConstants.HEADER_TEMPLATE_VALUE); + } if (jsonTempObject.length() > 0) { jsonParentObject = jsonTempObject; } @@ -234,7 +242,7 @@ public class ToscaYamlToJsonConvertor { jsonTempObject.put(JsonEditorSchemaConstants.ITEMS, jsonParentObject); jsonTempObject.put(JsonEditorSchemaConstants.FORMAT, - JsonEditorSchemaConstants.CUSTOM_KEY_FORMAT_TABS_TOP); + JsonEditorSchemaConstants.CUSTOM_KEY_FORMAT_TABS); jsonTempObject.put(JsonEditorSchemaConstants.UNIQUE_ITEMS, JsonEditorSchemaConstants.TRUE); } @@ -652,12 +660,43 @@ public class ToscaYamlToJsonConvertor { Optional.ofNullable(cldsDictionaryElements).get().stream().forEach(c -> { JSONObject jsonObject = new JSONObject(); + if (c.getSubDictionary() != null) { + Dictionary subDictionary = + dictionaryService.getDictionary(c.getSubDictionary()); + if (subDictionary != null + && !subDictionary.getDictionaryElements().isEmpty()) { + + jsonObject.put(JsonEditorSchemaConstants.CUSTOM_KEY_FORMAT_INPUT, + JsonEditorSchemaConstants.FORMAT_SELECT); + + List<String> shortNames = new ArrayList<>(); + subDictionary.getDictionaryElements().stream().forEach(c1 -> { + shortNames.add(c1.getShortName()); + }); + jsonObject.put(JsonEditorSchemaConstants.VALUES, shortNames); + } + } jsonObject.put(JsonEditorSchemaConstants.TYPE, getJsonType(c.getType())); + if (c.getType() != null - && c.getType().equalsIgnoreCase(ToscaSchemaConstants.TYPE_STRING)) { + && (c.getType().equalsIgnoreCase(ToscaSchemaConstants.TYPE_STRING) + || c.getType().equalsIgnoreCase(ToscaSchemaConstants.TYPE_DATE_TIME) + || c.getType().equalsIgnoreCase(ToscaSchemaConstants.TYPE_MAP))) { jsonObject.put(JsonEditorSchemaConstants.MIN_LENGTH, 1); + if (c.getType().equalsIgnoreCase(ToscaSchemaConstants.TYPE_DATE_TIME)) { + jsonObject.put(JsonEditorSchemaConstants.PLUGIN, + JsonEditorSchemaConstants.DATE_TIME_PICKER); + jsonObject.put(JsonEditorSchemaConstants.INPUT_EVENT, + JsonEditorSchemaConstants.DP_CHANGE); + JSONObject formatJsonObject = new JSONObject(); + formatJsonObject.put(JsonEditorSchemaConstants.FORMAT, + JsonEditorSchemaConstants.DATE_TIME_FORMAT); + jsonObject.put(JsonEditorSchemaConstants.VALIDATION, + formatJsonObject); + } } + jsonObject.put(JsonEditorSchemaConstants.ID, c.getName()); jsonObject.put(JsonEditorSchemaConstants.LABEL, c.getShortName()); jsonObject.put(JsonEditorSchemaConstants.OPERATORS, subCldsDictionaryNames); @@ -678,32 +717,44 @@ public class ToscaYamlToJsonConvertor { String dictionaryKey = dictionaryReference.substring( dictionaryReference.indexOf(ToscaSchemaConstants.DICTIONARY) + 11, dictionaryReference.length()); + if (dictionaryKey != null) { - List<DictionaryElement> cldsDictionaryElements = - dictionaryService.getDictionary(dictionaryKey).getDictionaryElements().stream() - .collect(Collectors.toList()); - if (cldsDictionaryElements != null) { - List<String> cldsDictionaryNames = new ArrayList<>(); - List<String> cldsDictionaryFullNames = new ArrayList<>(); - cldsDictionaryElements.stream().forEach(c -> { - // Json type will be translated before Policy creation - if (c.getType() != null && !c.getType().equalsIgnoreCase("json")) { - cldsDictionaryFullNames.add(c.getName()); + if (dictionaryKey.contains(ToscaSchemaConstants.TYPE_USER_DEFINED)) { + childObject.put(JsonEditorSchemaConstants.ENUM, new ArrayList<>()); + // Add Enum titles for generated translated values during + // JSON instance generation + JSONObject enumTitles = new JSONObject(); + enumTitles.put(JsonEditorSchemaConstants.ENUM_TITLES, new ArrayList<>()); + childObject.put(JsonEditorSchemaConstants.OPTIONS, enumTitles); + } else { + List<DictionaryElement> cldsDictionaryElements = + dictionaryService.getDictionary(dictionaryKey).getDictionaryElements() + .stream().collect(Collectors.toList()); + if (cldsDictionaryElements != null) { + List<String> cldsDictionaryNames = new ArrayList<>(); + List<String> cldsDictionaryFullNames = new ArrayList<>(); + cldsDictionaryElements.stream().forEach(c -> { + // Json type will be translated before Policy creation + if (c.getType() != null && !c.getType().equalsIgnoreCase("json")) { + cldsDictionaryFullNames.add(c.getName()); + } + cldsDictionaryNames.add(c.getShortName()); + }); + + if (!cldsDictionaryFullNames.isEmpty()) { + childObject.put(JsonEditorSchemaConstants.ENUM, + cldsDictionaryFullNames); + // Add Enum titles for generated translated values during JSON instance + // generation + JSONObject enumTitles = new JSONObject(); + enumTitles.put(JsonEditorSchemaConstants.ENUM_TITLES, + cldsDictionaryNames); + childObject.put(JsonEditorSchemaConstants.OPTIONS, enumTitles); + } else { + childObject.put(JsonEditorSchemaConstants.ENUM, cldsDictionaryNames); } - cldsDictionaryNames.add(c.getShortName()); - }); - if (!cldsDictionaryFullNames.isEmpty()) { - childObject.put(JsonEditorSchemaConstants.ENUM, cldsDictionaryFullNames); - // Add Enum titles for generated translated values during JSON instance - // generation - JSONObject enumTitles = new JSONObject(); - enumTitles.put(JsonEditorSchemaConstants.ENUM_TITLES, cldsDictionaryNames); - childObject.put(JsonEditorSchemaConstants.OPTIONS, enumTitles); - } else { - childObject.put(JsonEditorSchemaConstants.ENUM, cldsDictionaryNames); } - } } } @@ -711,10 +762,15 @@ public class ToscaYamlToJsonConvertor { private String getJsonType(String toscaType) { String jsonType = null; - if (toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_INTEGER)) { + if (toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_INTEGER) + || toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_NUMBER)) { jsonType = JsonEditorSchemaConstants.TYPE_INTEGER; + } else if (toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_DATE_TIME)) { + jsonType = JsonEditorSchemaConstants.TYPE_DATE_TIME; } else if (toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_LIST)) { jsonType = JsonEditorSchemaConstants.TYPE_ARRAY; + } else if (toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_MAP)) { + jsonType = JsonEditorSchemaConstants.TYPE_MAP; } else { jsonType = JsonEditorSchemaConstants.TYPE_STRING; } diff --git a/src/main/java/org/onap/clamp/loop/LoopService.java b/src/main/java/org/onap/clamp/loop/LoopService.java index ca3681b62..3f568a331 100644 --- a/src/main/java/org/onap/clamp/loop/LoopService.java +++ b/src/main/java/org/onap/clamp/loop/LoopService.java @@ -118,6 +118,12 @@ public class LoopService { Loop addOperationalPolicy(String loopName, String policyType, String policyVersion) throws IOException { Loop loop = getLoop(loopName); PolicyModel policyModel = policyModelsService.getPolicyModel(policyType, policyVersion); + Set<OperationalPolicy> opPolicySet = loop.getOperationalPolicies(); + for (OperationalPolicy opPolicy : opPolicySet) { + if (opPolicy.getPolicyModel().equals(policyModel)) { + throw new IllegalArgumentException("This type of Operational Policy is already added to the loop. Please choose another one."); + } + } if (policyModel == null) { return null; } |