+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * 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.openecomp.sdc.be.components.property;
-import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
+import fj.data.Either;
import org.apache.commons.collections.CollectionUtils;
-import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.jsontitan.operations.PolicyOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.openecomp.sdc.common.log.wrappers.Logger;
-import fj.data.Either;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput;
@org.springframework.stereotype.Component
-public class PolicyPropertyDecelerator extends DefaultPropertyDecelerator<PolicyDefinition, PropertyDataDefinition> {
+public class PolicyPropertyDeclarator extends DefaultPropertyDeclarator<PolicyDefinition, PropertyDataDefinition> {
- private static final Logger log = LoggerFactory.getLogger(PolicyPropertyDecelerator.class);
+ private static final Logger log = Logger.getLogger(PolicyPropertyDeclarator.class);
private PolicyOperation policyOperation;
- public PolicyPropertyDecelerator(ComponentsUtils componentsUtils, PropertyOperation propertyOperation, PolicyOperation policyOperation) {
+ public PolicyPropertyDeclarator(ComponentsUtils componentsUtils, PropertyOperation propertyOperation, PolicyOperation policyOperation) {
super(componentsUtils, propertyOperation);
this.policyOperation = policyOperation;
}
}
@Override
- void addPropertiesListToInput(PropertyDataDefinition declaredProp, PropertyDataDefinition originalProp, InputDefinition input) {
+ void addPropertiesListToInput(PropertyDataDefinition declaredProp, InputDefinition input) {
List<ComponentInstanceProperty> propertiesList = input.getProperties();
if(propertiesList == null) {
propertiesList = new ArrayList<>(); // adding the property with the new value for UI
if (container.getPolicies() == null) {
return Optional.empty();
}
- return container.getPolicies().values()
+ return container.getPolicies()
+ .values()
.stream()
.filter(policy -> Objects.nonNull(policy.getProperties()))
- .collect(Collectors.toMap(PolicyDataDefinition::getUniqueId,
- p -> getPolicyPropertiesDeclaredAsInput(p, inputId)))
- .entrySet()
- .stream()
- .filter(entry -> !entry.getValue().isEmpty())
- .map(entry -> new PolicyProperties(entry.getKey(), entry.getValue()))
+ .map(policy -> getPolicyPropertiesDeclaredAsInput(policy, inputId))
+ .filter(PolicyProperties::isNotEmpty)
.findFirst();
}
.anyMatch(getInputVal -> isGetInputValueForInput(getInputVal, inputId));
}
- private List<PropertyDataDefinition> getPolicyPropertiesDeclaredAsInput(PolicyDefinition policy, String inputId) {
- return policy.getProperties()
+ private PolicyProperties getPolicyPropertiesDeclaredAsInput(PolicyDefinition policy, String inputId) {
+ List<PropertyDataDefinition> collect = policy.getProperties()
.stream()
.filter(prop -> isPropertyDeclaredAsInputByInputId(prop, inputId))
.collect(Collectors.toList());
+ return new PolicyProperties(policy.getUniqueId(), collect);
+
}
private class PolicyProperties {
PolicyProperties(String policyId, List<PropertyDataDefinition> properties) {
this.policyId = policyId;
- this.properties = properties;
+ this.properties = (properties == null)? null : new ArrayList<>(properties);
}
String getPolicyId() {
}
public List<PropertyDataDefinition> getProperties() {
- return properties;
+ return new ArrayList<>(properties);
+ }
+
+ boolean isNotEmpty() {
+ return CollectionUtils.isNotEmpty(properties);
}
}
}