--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.processor;\r
+\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import org.apache.commons.collections.CollectionUtils;\r
+import org.apache.commons.collections.MapUtils;\r
+import org.apache.commons.lang3.StringUtils;\r
+import org.onap.ccsdk.config.assignment.service.ConfigAssignmentUtils;\r
+import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService;\r
+import org.onap.ccsdk.config.model.ConfigModelConstant;\r
+import org.onap.ccsdk.config.model.ConfigModelException;\r
+import org.onap.ccsdk.config.model.ValidTypes;\r
+import org.onap.ccsdk.config.model.data.ResourceAssignment;\r
+import org.onap.ccsdk.config.model.data.dict.ResourceDefinition;\r
+import org.onap.ccsdk.config.model.data.dict.SourcesDefinition;\r
+import org.onap.ccsdk.config.model.service.ComponentNode;\r
+import org.onap.ccsdk.config.model.utils.JsonUtils;\r
+import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+import com.fasterxml.jackson.databind.node.ArrayNode;\r
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;\r
+import com.fasterxml.jackson.databind.node.ObjectNode;\r
+\r
+public class DBResourceProcessor implements ComponentNode {\r
+\r
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(DBResourceProcessor.class);\r
+ private ConfigResourceService configResourceService;\r
+ private Map<String, ResourceDefinition> dictionaries;\r
+\r
+ public DBResourceProcessor(ConfigResourceService configResourceService) {\r
+ this.configResourceService = configResourceService;\r
+ }\r
+\r
+ @Override\r
+ public Boolean preCondition(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)\r
+ throws SvcLogicException {\r
+ return Boolean.TRUE;\r
+ }\r
+\r
+ @Override\r
+ public void preProcess(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)\r
+ throws SvcLogicException {\r
+ // Auto-generated method stub\r
+ }\r
+\r
+ @Override\r
+ public void process(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {\r
+ // Auto-generated method stub\r
+ }\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public void process(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)\r
+ throws SvcLogicException {\r
+ try {\r
+ List<ResourceAssignment> batchResourceAssignment =\r
+ (List<ResourceAssignment>) componentContext.get(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS);\r
+ dictionaries =\r
+ (Map<String, ResourceDefinition>) componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARIES);\r
+\r
+ if (CollectionUtils.isNotEmpty(batchResourceAssignment)) {\r
+ for (ResourceAssignment resourceAssignment : batchResourceAssignment) {\r
+ processResourceAssignment(ctx, componentContext, resourceAssignment);\r
+ }\r
+ }\r
+ } catch (Exception e) {\r
+ throw new SvcLogicException(String.format("DBResourceProcessor Exception : (%s)", e), e);\r
+ }\r
+ }\r
+\r
+ private void processResourceAssignment(SvcLogicContext ctx, Map<String, Object> componentContext,\r
+ ResourceAssignment resourceAssignment) throws SvcLogicException, ConfigModelException {\r
+ if (resourceAssignment != null) {\r
+ try {\r
+ validate(resourceAssignment);\r
+\r
+ // Check if It has Input\r
+ Object value = ConfigAssignmentUtils.getContextKeyValue(ctx, resourceAssignment.getName());\r
+ if (value != null) {\r
+ logger.info("db source template key ({}) found from input and value is ({})",\r
+ resourceAssignment.getName(), value);\r
+ ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value);\r
+ return;\r
+ }\r
+\r
+ ResourceDefinition resourceDefinition = dictionaries.get(resourceAssignment.getDictionaryName());\r
+ SourcesDefinition sourceDb = resourceDefinition.getSources().get("db");\r
+ if (StringUtils.isBlank(sourceDb.getProperties().getQuery())) {\r
+ throw new SvcLogicException("db query property is missing");\r
+ }\r
+\r
+ String sql = sourceDb.getProperties().getQuery();\r
+ Map<String, String> inputKeyMapping = sourceDb.getProperties().getInputKeyMapping();\r
+\r
+ logger.info("Db dictionary information : ({}), ({}), ({})", sql, inputKeyMapping,\r
+ sourceDb.getProperties().getOutputKeyMapping());\r
+\r
+ Map<String, Object> namedParameters = populateNamedParameter(componentContext, inputKeyMapping);\r
+\r
+ logger.info("Parameter information : ({})", namedParameters);\r
+ List<Map<String, Object>> rows = configResourceService.query(sql, namedParameters);\r
+ if (rows != null && !rows.isEmpty()) {\r
+ processDBResults(ctx, componentContext, resourceAssignment, sourceDb, rows);\r
+ } else {\r
+ logger.warn("Failed to get db result for dictionary name ({}) the query ({})",\r
+ resourceAssignment.getDictionaryName(), sql);\r
+ }\r
+\r
+ // Check the value has populated for mandatory case\r
+ ResourceAssignmentUtils.assertTemplateKeyValueNotNull(componentContext, resourceAssignment);\r
+ } catch (Exception e) {\r
+ ResourceAssignmentUtils.setFailedResourceDataValue(componentContext, resourceAssignment,\r
+ e.getMessage());\r
+ throw new SvcLogicException(\r
+ String.format("Failed in template key (%s) assignments : (%s)", resourceAssignment, e), e);\r
+ }\r
+ } else {\r
+ // Do Nothing\r
+ }\r
+ }\r
+\r
+ private void validate(ResourceAssignment resourceAssignment) throws SvcLogicException {\r
+ if (resourceAssignment == null) {\r
+ throw new SvcLogicException("resource assignment is not defined");\r
+ }\r
+\r
+ if (StringUtils.isBlank(resourceAssignment.getName())) {\r
+ throw new SvcLogicException("resource assignment template key is not defined");\r
+ }\r
+\r
+ if (StringUtils.isBlank(resourceAssignment.getDictionaryName())) {\r
+ throw new SvcLogicException(\r
+ String.format("resource assignment dictionary name is not defined for template key (%s)",\r
+ resourceAssignment.getName()));\r
+ }\r
+\r
+ if (!ConfigModelConstant.SOURCE_DB.equalsIgnoreCase(resourceAssignment.getDictionarySource())) {\r
+ throw new SvcLogicException(String.format("resource assignment source is not db, it is (%s)",\r
+ resourceAssignment.getDictionarySource()));\r
+ }\r
+\r
+ ResourceDefinition resourceDefinition = dictionaries.get(resourceAssignment.getDictionaryName());\r
+ if (resourceDefinition == null) {\r
+ throw new SvcLogicException(String.format("missing resource dictionary definition for name (%s) ",\r
+ resourceAssignment.getDictionaryName()));\r
+ }\r
+\r
+ if (resourceDefinition.getSources() == null || resourceDefinition.getSources().get("db") == null) {\r
+ throw new SvcLogicException(String.format("missing resource dictionary db source definition for name (%s) ",\r
+ resourceAssignment.getDictionaryName()));\r
+ }\r
+\r
+ SourcesDefinition sourceDb = resourceDefinition.getSources().get("db");\r
+ if (StringUtils.isBlank(sourceDb.getProperties().getQuery())) {\r
+ throw new SvcLogicException(String.format("Failed to get request Query for dictionary (%s)",\r
+ resourceAssignment.getDictionaryName()));\r
+ }\r
+\r
+ }\r
+\r
+ private Map<String, Object> populateNamedParameter(Map<String, Object> componentContext,\r
+ Map<String, String> inputKeyMapping) {\r
+ Map<String, Object> namedParameters = new HashMap<>();\r
+ if (MapUtils.isNotEmpty(inputKeyMapping)) {\r
+\r
+ for (Map.Entry<String, String> mapping : inputKeyMapping.entrySet()) {\r
+ ResourceDefinition referenceDictionaryDefinition = dictionaries.get(mapping.getValue());\r
+ Object expressionValue =\r
+ ResourceAssignmentUtils.getDictionaryKeyValue(componentContext, referenceDictionaryDefinition);\r
+ logger.trace("Reference dictionary key ({}), value ({})", mapping.getKey(), expressionValue);\r
+ namedParameters.put(mapping.getKey(), expressionValue);\r
+ }\r
+ }\r
+ return namedParameters;\r
+ }\r
+\r
+ @SuppressWarnings("squid:S3776")\r
+ private void processDBResults(SvcLogicContext ctx, Map<String, Object> componentContext,\r
+ ResourceAssignment resourceAssignment, SourcesDefinition sourceDb, List<Map<String, Object>> rows)\r
+ throws SvcLogicException, ConfigModelException {\r
+\r
+ Map<String, String> outputKeyMapping = sourceDb.getProperties().getOutputKeyMapping();\r
+ String type = resourceAssignment.getProperty().getType();\r
+ String entrySchema = null;\r
+ logger.info("Response processing type({})", type);\r
+ // Primitive Types\r
+ if (ValidTypes.getPrimitivePropertType().contains(type)) {\r
+\r
+ Map<String, Object> row = rows.get(0);\r
+ String dbColumnName = outputKeyMapping.get(resourceAssignment.getDictionaryName());\r
+ Object dbColumnValue = row.get(dbColumnName);\r
+ ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, dbColumnValue);\r
+\r
+ } else if (ValidTypes.getListPropertType().contains(type)) {\r
+ // Array Types\r
+ if (resourceAssignment.getProperty().getEntrySchema() != null) {\r
+ entrySchema = resourceAssignment.getProperty().getEntrySchema().getType();\r
+ }\r
+\r
+ if (StringUtils.isNotBlank(entrySchema)) {\r
+ ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode();\r
+\r
+ for (Map<String, Object> row : rows) {\r
+ if (ValidTypes.getPrimitivePropertType().contains(entrySchema)) {\r
+ String dbColumnName = outputKeyMapping.get(resourceAssignment.getDictionaryName());\r
+ Object dbColumnValue = row.get(dbColumnName);\r
+ // Add Array JSON\r
+ JsonUtils.populatePrimitiveValues(dbColumnValue, entrySchema, arrayNode);\r
+ } else {\r
+ ObjectNode arrayChildNode = JsonNodeFactory.instance.objectNode();\r
+ for (Map.Entry<String, String> mapping : outputKeyMapping.entrySet()) {\r
+ Object dbColumnValue = row.get(mapping.getKey());\r
+ String propertyTypeForDataType =\r
+ ConfigAssignmentUtils.getPropertyType(ctx, entrySchema, mapping.getKey());\r
+ JsonUtils.populatePrimitiveValues(mapping.getKey(), dbColumnValue, propertyTypeForDataType,\r
+ arrayChildNode);\r
+ }\r
+ arrayNode.add(arrayChildNode);\r
+ }\r
+ }\r
+ // Set the List of Complex Values\r
+ ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, arrayNode);\r
+ } else {\r
+ throw new SvcLogicException(String.format("Entry schema is not defined for dictionary (%s) info",\r
+ resourceAssignment.getDictionaryName()));\r
+ }\r
+ } else {\r
+ // Complex Types\r
+ Map<String, Object> row = rows.get(0);\r
+ ObjectNode objectNode = JsonNodeFactory.instance.objectNode();\r
+ for (Map.Entry<String, String> mapping : outputKeyMapping.entrySet()) {\r
+ Object dbColumnValue = row.get(mapping.getKey());\r
+ String propertyTypeForDataType = ConfigAssignmentUtils.getPropertyType(ctx, type, mapping.getKey());\r
+ JsonUtils.populatePrimitiveValues(mapping.getKey(), dbColumnValue, propertyTypeForDataType, objectNode);\r
+ }\r
+ ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, objectNode);\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void postProcess(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)\r
+ throws SvcLogicException {\r
+ // Auto-generated method stub\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.processor;\r
+\r
+import static org.mockito.Matchers.any;\r
+import java.io.File;\r
+import java.nio.charset.Charset;\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import org.apache.commons.io.FileUtils;\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Matchers;\r
+import org.mockito.Mock;\r
+import org.mockito.Mockito;\r
+import org.mockito.MockitoAnnotations;\r
+import org.mockito.invocation.InvocationOnMock;\r
+import org.mockito.runners.MockitoJUnitRunner;\r
+import org.mockito.stubbing.Answer;\r
+import org.onap.ccsdk.config.assignment.service.ConfigResourceAssignmentTestUtils;\r
+import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog;\r
+import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService;\r
+import org.onap.ccsdk.config.model.ConfigModelConstant;\r
+import org.onap.ccsdk.config.model.data.ResourceAssignment;\r
+import org.onap.ccsdk.config.model.data.dict.ResourceDefinition;\r
+import org.onap.ccsdk.config.model.utils.TransformationUtils;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+\r
+@RunWith(MockitoJUnitRunner.class)\r
+public class DBResourceProcessorTest {\r
+\r
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(DBResourceProcessorTest.class);\r
+\r
+ @Mock\r
+ private ConfigResourceService configResourceService;\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Before\r
+ public void before() {\r
+ MockitoAnnotations.initMocks(this);\r
+\r
+ try {\r
+ Mockito.doAnswer(new Answer<Void>() {\r
+ @Override\r
+ public Void answer(InvocationOnMock invocationOnMock) throws Throwable {\r
+ Object[] args = invocationOnMock.getArguments();\r
+ if (args != null) {\r
+ logger.trace("Transaction info " + Arrays.asList(args));\r
+ }\r
+ return null;\r
+ }\r
+ }).when(configResourceService).save(any(TransactionLog.class));\r
+\r
+ } catch (SvcLogicException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testDbSimpleProcess() throws Exception {\r
+ logger.info(" ******************************* testDbSimpleProcess ***************************");\r
+\r
+ Mockito.doAnswer(new Answer<List<Map<String, Object>>>() {\r
+ @Override\r
+ public List<Map<String, Object>> answer(InvocationOnMock invocationOnMock) throws Throwable {\r
+ Object[] args = invocationOnMock.getArguments();\r
+ List<Map<String, Object>> results = new ArrayList<>();\r
+ if (args != null) {\r
+ logger.info("Query " + Arrays.asList(args));\r
+ Map<String, Object> record = new HashMap<>();\r
+ record.put("country", "US");\r
+ results.add(record);\r
+ }\r
+ return results;\r
+ }\r
+ }).when(configResourceService).query(Matchers.anyString(), Matchers.<Map<String, Object>>any());\r
+\r
+ String recipeName = "sample-recipe";\r
+\r
+ String resourceassignmentContent = FileUtils.readFileToString(\r
+ new File("src/test/resources/mapping/db/resource-assignments-simple.json"), Charset.defaultCharset());\r
+ List<ResourceAssignment> batchResourceAssignment =\r
+ TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class);\r
+\r
+ String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-simple.json"),\r
+ Charset.defaultCharset());\r
+ Map<String, ResourceDefinition> dictionaries =\r
+ ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent);\r
+ DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService);\r
+ Map<String, Object> componentContext = new HashMap<>();\r
+ componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template");\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries);\r
+\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample");\r
+\r
+ Map<String, String> inParams = new HashMap<>();\r
+ SvcLogicContext ctx = new SvcLogicContext();\r
+ dbResourceProcessor.process(inParams, ctx, componentContext);\r
+\r
+ logger.info(" Context " + componentContext);\r
+\r
+ }\r
+\r
+ @Test\r
+ public void testDbComplexProcess() throws Exception {\r
+ logger.info(" ******************************* testDbComplexProcess ***************************");\r
+\r
+ Mockito.doAnswer(new Answer<List<Map<String, Object>>>() {\r
+ @Override\r
+ public List<Map<String, Object>> answer(InvocationOnMock invocationOnMock) throws Throwable {\r
+ Object[] args = invocationOnMock.getArguments();\r
+ List<Map<String, Object>> results = new ArrayList<>();\r
+ if (args != null) {\r
+ logger.info("Query " + Arrays.asList(args));\r
+ Map<String, Object> record = new HashMap<>();\r
+ record.put("db-country", "US");\r
+ record.put("db-state", "NJ");\r
+ results.add(record);\r
+ }\r
+ return results;\r
+ }\r
+ }).when(configResourceService).query(Matchers.anyString(), Matchers.<Map<String, Object>>any());\r
+\r
+ String recipeName = "sample-recipe";\r
+\r
+ String resourceassignmentContent = FileUtils.readFileToString(\r
+ new File("src/test/resources/mapping/db/resource-assignments-complex.json"), Charset.defaultCharset());\r
+ List<ResourceAssignment> batchResourceAssignment =\r
+ TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class);\r
+\r
+ String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-complex.json"),\r
+ Charset.defaultCharset());\r
+ Map<String, ResourceDefinition> dictionaries =\r
+ ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent);\r
+ DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService);\r
+ Map<String, Object> componentContext = new HashMap<>();\r
+ componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template");\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample");\r
+\r
+ Map<String, String> inParams = new HashMap<>();\r
+ SvcLogicContext ctx = new SvcLogicContext();\r
+ String datatypeContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/dt-location.json"),\r
+ Charset.defaultCharset());\r
+ ctx.setAttribute("data_types.dt-location", datatypeContent);\r
+ dbResourceProcessor.process(inParams, ctx, componentContext);\r
+\r
+ }\r
+\r
+ @Test\r
+ public void testDbArrayComplexProcess() throws Exception {\r
+ logger.info(" ******************************* testDbArrayComplexProcess ***************************");\r
+ Mockito.doAnswer(new Answer<List<Map<String, Object>>>() {\r
+ @Override\r
+ public List<Map<String, Object>> answer(InvocationOnMock invocationOnMock) throws Throwable {\r
+ Object[] args = invocationOnMock.getArguments();\r
+ List<Map<String, Object>> results = new ArrayList<>();\r
+ if (args != null) {\r
+ logger.info("Query " + Arrays.asList(args));\r
+ Map<String, Object> record = new HashMap<>();\r
+ record.put("db-country", "US");\r
+ record.put("db-state", "NJ");\r
+ results.add(record);\r
+\r
+ Map<String, Object> record2 = new HashMap<>();\r
+ record2.put("db-country", "INDIA");\r
+ record2.put("db-state", "TN");\r
+ results.add(record2);\r
+ }\r
+ return results;\r
+ }\r
+ }).when(configResourceService).query(Matchers.anyString(), Matchers.<Map<String, Object>>any());\r
+\r
+ String recipeName = "sample-recipe";\r
+\r
+ String resourceassignmentContent = FileUtils.readFileToString(\r
+ new File("src/test/resources/mapping/db/resource-assignments-array.json"), Charset.defaultCharset());\r
+ List<ResourceAssignment> batchResourceAssignment =\r
+ TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class);\r
+\r
+ String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-array.json"),\r
+ Charset.defaultCharset());\r
+ Map<String, ResourceDefinition> dictionaries =\r
+ ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent);\r
+ DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService);\r
+ Map<String, Object> componentContext = new HashMap<>();\r
+ componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template");\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample");\r
+\r
+ Map<String, String> inParams = new HashMap<>();\r
+ SvcLogicContext ctx = new SvcLogicContext();\r
+ String datatypeContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/dt-location.json"),\r
+ Charset.defaultCharset());\r
+ ctx.setAttribute("data_types.dt-location", datatypeContent);\r
+ dbResourceProcessor.process(inParams, ctx, componentContext);\r
+ logger.info("Component Context = ({})", componentContext);\r
+ Assert.assertNotNull("faile dto populate Array Complex response ", componentContext);\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+{\r
+ "locations": {\r
+ "name": "locations",\r
+ "property": {\r
+ "type": "list",\r
+ "entry_schema": {\r
+ "type": "dt-location"\r
+ }\r
+ },\r
+ "sources": {\r
+ "db": {\r
+ "type": "source-sdnctl-db",\r
+ "properties": {\r
+ "query": "SELECT db-country, db-state FROM DEVICE_PROFILE WHERE profile_name = :profile_name",\r
+ "input-key-mapping": {\r
+ "profile_name": "profile_name"\r
+ },\r
+ "output-key-mapping": {\r
+ "db-country": "country",\r
+ "db-state": "state"\r
+ },\r
+ "key-dependencies": [\r
+ "profile_name"\r
+ ]\r
+ }\r
+ }\r
+ }\r
+ },\r
+ "profile_name": {\r
+ "name": "profile_name",\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "sources": {\r
+ "input": {\r
+ "type": "source-input"\r
+ }\r
+ }\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+{\r
+ "location": {\r
+ "name": "location",\r
+ "property": {\r
+ "type": "dt-location"\r
+ },\r
+ "sources": {\r
+ "db": {\r
+ "type": "source-sdnctl-db",\r
+ "properties": {\r
+ "query": "SELECT db-country, db-state FROM DEVICE_PROFILE WHERE profile_name = :profile_name",\r
+ "input-key-mapping": {\r
+ "profile_name": "profile_name"\r
+ },\r
+ "output-key-mapping": {\r
+ "db-country": "country",\r
+ "db-state": "state"\r
+ },\r
+ "key-dependencies": [\r
+ "profile_name"\r
+ ]\r
+ }\r
+ }\r
+ }\r
+ },\r
+ "profile_name": {\r
+ "name": "profile_name",\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "sources": {\r
+ "input": {\r
+ "type": "source-input"\r
+ }\r
+ }\r
+ }\r
+}\r
--- /dev/null
+{\r
+ "country": {\r
+ "name": "country",\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "sources": {\r
+ "db": {\r
+ "type": "source-sdnctl-db",\r
+ "properties": {\r
+ "query": "SELECT country FROM DEVICE_PROFILE WHERE profile_name = :profile_name",\r
+ "input-key-mapping": {\r
+ "profile_name": "profile_name"\r
+ },\r
+ "output-key-mapping": {\r
+ "country": "country"\r
+ },\r
+ "key-dependencies": [\r
+ "profile_name"\r
+ ]\r
+ }\r
+ }\r
+ }\r
+ },\r
+ "profile_name": {\r
+ "name": "profile_name",\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "sources": {\r
+ "input": {\r
+ "type": "source-input"\r
+ }\r
+ }\r
+ }\r
+}\r
--- /dev/null
+{\r
+ "version": "1.0.0",\r
+ "description": "test Data Type",\r
+ "properties": {\r
+ "country": {\r
+ "required": true,\r
+ "type": "string"\r
+ },\r
+ "state": {\r
+ "required": false,\r
+ "type": "string"\r
+ }\r
+ },\r
+ "derived_from": "tosca.datatypes.Root"\r
+}\r
--- /dev/null
+[\r
+ {\r
+ "name": "locations",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "list",\r
+ "entry_schema": {\r
+ "type": "dt-location"\r
+ }\r
+ },\r
+ "dictionary-name": "locations",\r
+ "dictionary-source": "db",\r
+ "dependencies": []\r
+ }\r
+]\r
--- /dev/null
+[\r
+ {\r
+ "name": "location",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "dt-location"\r
+ },\r
+ "dictionary-name": "location",\r
+ "dictionary-source": "db",\r
+ "dependencies": []\r
+ }\r
+]\r
--- /dev/null
+[\r
+ {\r
+ "name": "country",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "dictionary-name": "country",\r
+ "dictionary-source": "db",\r
+ "dependencies": []\r
+ }\r
+]\r