2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
3 * Modifications Copyright © 2018 IBM.
\r
5 * Licensed under the Apache License, Version 2.0 (the "License");
\r
6 * you may not use this file except in compliance with the License.
\r
7 * You may obtain a copy of the License at
\r
9 * http://www.apache.org/licenses/LICENSE-2.0
\r
11 * Unless required by applicable law or agreed to in writing, software
\r
12 * distributed under the License is distributed on an "AS IS" BASIS,
\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 * See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
18 package org.onap.ccsdk.config.assignment.processor;
\r
20 import java.util.List;
\r
21 import java.util.Map;
\r
22 import org.apache.commons.lang3.StringUtils;
\r
23 import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService;
\r
24 import org.onap.ccsdk.config.model.ConfigModelConstant;
\r
25 import org.onap.ccsdk.config.model.ConfigModelException;
\r
26 import org.onap.ccsdk.config.model.data.ResourceAssignment;
\r
27 import org.onap.ccsdk.config.model.service.ComponentNode;
\r
28 import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils;
\r
29 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
\r
30 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
\r
32 public class InputResourceProcessor implements ComponentNode {
\r
34 public InputResourceProcessor(ConfigResourceService configResourceService) {}
\r
37 public Boolean preCondition(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
\r
38 throws SvcLogicException {
\r
39 return Boolean.TRUE;
\r
43 public void preProcess(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
\r
44 throws SvcLogicException {
\r
45 // Auto-generated method stub
\r
49 public void process(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
\r
50 // Auto-generated method stub
\r
53 @SuppressWarnings("unchecked")
\r
55 public void process(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
\r
56 throws SvcLogicException {
\r
58 List<ResourceAssignment> batchResourceAssignment =
\r
59 (List<ResourceAssignment>) componentContext.get(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS);
\r
60 if (batchResourceAssignment != null && !batchResourceAssignment.isEmpty()) {
\r
61 for (ResourceAssignment resourceAssignment : batchResourceAssignment) {
\r
62 processResourceAssignment(ctx, componentContext, resourceAssignment);
\r
65 } catch (Exception e) {
\r
66 throw new SvcLogicException(String.format("InputResourceProcessor Exception : (%s)", e), e);
\r
70 private void processResourceAssignment(SvcLogicContext ctx, Map<String, Object> componentContext,
\r
71 ResourceAssignment resourceAssignment) throws ConfigModelException, SvcLogicException {
\r
73 if (StringUtils.isNotBlank(resourceAssignment.getName())) {
\r
74 String value = ctx.getAttribute(resourceAssignment.getName());
\r
75 // if value is null don't call setResourceDataValue to populate the value
\r
76 if (StringUtils.isNotBlank(value)) {
\r
77 ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value);
\r
81 // Check the value has populated for mandatory case
\r
82 ResourceAssignmentUtils.assertTemplateKeyValueNotNull(componentContext, resourceAssignment);
\r
83 } catch (Exception e) {
\r
84 ResourceAssignmentUtils.setFailedResourceDataValue(componentContext, resourceAssignment, e.getMessage());
\r
85 throw new SvcLogicException(
\r
86 String.format("Failed in template key (%s) assignments with : (%s)", resourceAssignment, e), e);
\r
91 public void postProcess(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
\r
92 throws SvcLogicException {
\r
93 // Auto-generated method stub
\r