/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 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.
*
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.models.base;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.Set;
import java.util.TreeMap;
import java.util.function.Function;
import javax.persistence.CascadeType;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.MappedSuperclass;
import javax.persistence.Table;
import javax.ws.rs.core.Response;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.lang3.StringUtils;
import org.onap.policy.models.base.PfValidationResult.ValidationResult;
// @formatter:off
/**
* This class is a concept container and holds a map of concepts. The {@link PfConceptContainer} class implements the
* helper methods of the {@link PfConceptGetter} interface to allow {@link PfConceptContainer} instances to be retrieved
* by calling methods directly on this class without referencing the contained map.
*
*
Validation checks that a container key is not null. An error is issued if no concepts are defined in a container.
* Each concept entry is checked to ensure that its key and value are not null and that the key matches the key in the
* map value. Each concept entry is then validated individually.
*
* @param C the concept being contained
*/
//@formatter:on
@MappedSuperclass
@Entity
@Table(name = "PfConceptContainer")
@Data
@EqualsAndHashCode(callSuper = false)
public class PfConceptContainer extends PfConcept
implements PfConceptGetter, PfAuthorative>> {
private static final long serialVersionUID = -324211738823208318L;
@EmbeddedId
private PfConceptKey key;
@ManyToMany(cascade = CascadeType.ALL)
// @formatter:off
@JoinTable(
joinColumns = {
@JoinColumn(name = "conceptContainerMapName", referencedColumnName = "name"),
@JoinColumn(name = "concpetContainerMapVersion", referencedColumnName = "version")
},
inverseJoinColumns = {
@JoinColumn(name = "conceptContainerName", referencedColumnName = "name"),
@JoinColumn(name = "conceptContainerVersion", referencedColumnName = "version")
}
)
// @formatter:on
private Map conceptMap;
/**
* The Default Constructor creates a {@link PfConceptContainer} object with a null artifact key and creates an empty
* concept map.
*/
public PfConceptContainer() {
this(new PfConceptKey());
}
/**
* The Key Constructor creates a {@link PfConceptContainer} object with the given artifact key and creates an empty
* concept map.
*
* @param key the concept key
*/
public PfConceptContainer(@NonNull final PfConceptKey key) {
this(key, new TreeMap());
}
/**
* This Constructor creates an concept container with all of its fields defined.
*
* @param key the concept container key
* @param conceptMap the concepts to be stored in the concept container
*/
public PfConceptContainer(@NonNull final PfConceptKey key, @NonNull final Map conceptMap) {
super();
this.key = key;
this.conceptMap = new TreeMap<>(conceptMap);
}
/**
* Copy constructor.
*
* @param copyConcept the concept to copy from
*/
public PfConceptContainer(@NonNull final PfConceptContainer copyConcept) {
super(copyConcept);
this.key = new PfConceptKey(copyConcept.key);
this.conceptMap = new TreeMap<>();
for (final Entry conceptMapEntry : copyConcept.conceptMap.entrySet()) {
PfConceptKey newK = new PfConceptKey(conceptMapEntry.getKey());
C newC = PfUtils.makeCopy(conceptMapEntry.getValue());
this.conceptMap.put(newK, newC);
}
}
@Override
public List getKeys() {
final List keyList = key.getKeys();
for (final C concept : conceptMap.values()) {
keyList.addAll(concept.getKeys());
}
return keyList;
}
@Override
public List