this.conceptMap = new TreeMap<>();
for (final Entry<PfConceptKey, C> conceptMapEntry : copyConcept.conceptMap.entrySet()) {
- PfConceptKey newK = new PfConceptKey(conceptMapEntry.getKey());
- C newC = PfUtils.makeCopy(conceptMapEntry.getValue());
+ var newK = new PfConceptKey(conceptMapEntry.getKey());
+ var newC = PfUtils.makeCopy(conceptMapEntry.getValue());
this.conceptMap.put(newK, newC);
}
}
// Add the map entries one by one
for (Entry<String, A> incomingConceptEntry : incomingConceptMap.entrySet()) {
- PfConceptKey conceptKey = new PfConceptKey();
+ var conceptKey = new PfConceptKey();
if (KEY_ID_PATTERN.matches(incomingConceptEntry.getKey())) {
conceptKey = new PfConceptKey(incomingConceptEntry.getKey());
} else {
incomingConceptEntry.getValue().setVersion(findConceptField(conceptKey, conceptKey.getVersion(),
incomingConceptEntry.getValue(), PfNameVersion::getDefinedVersion));
- C jpaConcept = getConceptNewInstance();
+ var jpaConcept = getConceptNewInstance();
// This cast allows us to call the fromAuthorative method
@SuppressWarnings("unchecked")
PfAuthorative<A> authoritiveImpl = (PfAuthorative<A>) jpaConcept;
* @return the validation result
*/
private ValidationResult validateConceptMap() {
- BeanValidationResult result = new BeanValidationResult("conceptMap", conceptMap);
+ var result = new BeanValidationResult("conceptMap", conceptMap);
for (final Entry<PfConceptKey, C> conceptEntry : conceptMap.entrySet()) {
BeanValidationResult result2 = null;
return getAll(conceptKeyName, conceptKeyVersion);
} else {
final Set<C> returnSet = new TreeSet<>();
- C foundConcept = get(conceptKeyName, conceptKeyVersion);
+ var foundConcept = get(conceptKeyName, conceptKeyVersion);
if (foundConcept != null) {
returnSet.add(foundConcept);
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 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.
Assertions.argumentNotNull(conceptKeyName, "conceptKeyName may not be null");
// The very fist key that could have this name
- final PfConceptKey lowestArtifactKey = new PfConceptKey(conceptKeyName, PfKey.NULL_KEY_VERSION);
+ final var lowestArtifactKey = new PfConceptKey(conceptKeyName, PfKey.NULL_KEY_VERSION);
// Check if we found a key for our name
PfConceptKey foundKey = conceptMap.ceilingKey(lowestArtifactKey);
}
// The very fist key that could have this name
- final PfConceptKey lowestArtifactKey = new PfConceptKey(conceptKeyName, PfKey.NULL_KEY_VERSION);
+ final var lowestArtifactKey = new PfConceptKey(conceptKeyName, PfKey.NULL_KEY_VERSION);
if (conceptKeyVersion != null) {
lowestArtifactKey.setVersion(conceptKeyVersion);
}
}
final PfKeyImpl otherConceptKey = (PfKeyImpl) otherKey;
- final Compatibility compatibility = this.getCompatibility(otherConceptKey);
+ final var compatibility = this.getCompatibility(otherConceptKey);
return !(compatibility == Compatibility.DIFFERENT || compatibility == Compatibility.MAJOR);
}
validateKeyNotNull(result, KEYS_TOKEN, artifactKey);
- BeanValidationResult result2 = new BeanValidationResult(KEYS_TOKEN, artifactKey);
+ var result2 = new BeanValidationResult(KEYS_TOKEN, artifactKey);
// Null key name start check
if (artifactKey.getName().toUpperCase().startsWith(PfKey.NULL_KEY_NAME)) {
addResult(result, KEYS_TOKEN, referenceKey, IS_A_NULL_KEY);
}
- BeanValidationResult result2 = new BeanValidationResult(KEYS_TOKEN, referenceKey);
+ var result2 = new BeanValidationResult(KEYS_TOKEN, referenceKey);
// Null parent key check
if (referenceKey.getParentConceptKey().isNullKey()) {
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2021 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.
*/
@SuppressWarnings("unchecked")
public static <M extends PfConcept> M getModel(@NonNull final String modelKey) {
- final M model = (M) modelMap.get(modelKey);
+ final var model = (M) modelMap.get(modelKey);
if (model == null) {
throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR,
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019, 2021 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.
package org.onap.policy.models.base;
+import com.google.re2j.Pattern;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
-import java.util.regex.Pattern;
/**
* Interface for filtering a list of concepts.
return item -> true;
}
- Pattern pat = Pattern.compile(pattern);
+ var pat = Pattern.compile(pattern);
return item -> {
String value = extractor.apply(item);
List<T> filteredList = new ArrayList<>(originalList);
Collections.sort(filteredList, versionComparator);
- int icur = 0;
- for (int j = 1; j < filteredList.size(); j++) {
+ var icur = 0;
+ for (var j = 1; j < filteredList.size(); j++) {
// Get the current and last element
- T curElement = filteredList.get(icur);
- T lastElement = filteredList.get(j);
+ var curElement = filteredList.get(icur);
+ var lastElement = filteredList.get(j);
/*
* The list is sorted so if the last element name is the same as the current element name, the current
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019,2021 Nordix Foundation.
- * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2021 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.
* the key ID in a format that respects the KEY_ID_REGEXP
*/
public PfReferenceKey(final String id) {
- final String conditionedId = Assertions.validateStringParameter("id", id, REFERENCE_KEY_ID_REGEXP);
+ final var conditionedId = Assertions.validateStringParameter("id", id, REFERENCE_KEY_ID_REGEXP);
// Split on colon, if the id passes the regular expression test above
// it'll have just three colons separating the parent name,
@Override
public boolean isNullKey() {
- return (PfReferenceKey.NULL_KEY_NAME.equals(this.getParentKeyName()) && PfReferenceKey.NULL_KEY_VERSION
- .equals(this.getParentKeyVersion()) && PfReferenceKey.NULL_KEY_NAME.equals(this.getParentLocalName())
- && PfReferenceKey.NULL_KEY_NAME.equals(this.getLocalName()));
+ return (PfKey.NULL_KEY_NAME.equals(this.getParentKeyName()) && PfKey.NULL_KEY_VERSION
+ .equals(this.getParentKeyVersion()) && PfKey.NULL_KEY_NAME.equals(this.getParentLocalName())
+ && PfKey.NULL_KEY_NAME.equals(this.getLocalName()));
}
/**
return true;
}
- PfKey pfkey = (PfKey) value;
+ var pfkey = (PfKey) value;
if (annot.keyNotNull() && pfkey.isNullKey()) {
result.addResult(fieldName, xlate(pfkey), ValidationStatus.INVALID, Validated.IS_A_NULL_KEY);
return false;
return true;
}
- BeanValidationResult result2 = new BeanValidationResult(fieldName, value);
+ var result2 = new BeanValidationResult(fieldName, value);
PfKeyImpl keyimpl = (PfKeyImpl) pfkey;
public static void validateKeyVersionNotNull(BeanValidationResult result, @NonNull String fieldName,
PfConceptKey key) {
if (key != null && key.isNullVersion()) {
- BeanValidationResult result2 = new BeanValidationResult(fieldName, key);
+ var result2 = new BeanValidationResult(fieldName, key);
result2.addResult(makeNullResult(PfKeyImpl.VERSION_TOKEN, key.getVersion()));
result.addResult(result2);
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 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.
public String addFilter(final String inputFilterString,
final String name, final Instant startTime, final Instant endTime,
final Map<String, Object> filterMap, final String sortOrder, final int getRecordNum) {
- StringBuilder filterQueryString = new StringBuilder(inputFilterString);
+ var filterQueryString = new StringBuilder(inputFilterString);
if (filterMap != null) {
for (String key : filterMap.keySet()) {
filterQueryString.append(getKeyPrefix() + key + "= :" + key + AND);
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 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.
package org.onap.policy.models.dao;
-import java.time.Instant;
-import java.util.Map;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.dao.impl.PfNonTimestampKeyFilter;
import org.onap.policy.models.dao.impl.PfReferenceTimestampKeyFilter;
*/
private <T extends PfConcept> String getKeyName(final Class<T> someClass) {
try {
- String fullClassName = someClass.getDeclaredField("key").getType().toString();
+ var fullClassName = someClass.getDeclaredField("key").getType().toString();
return fullClassName.substring(fullClassName.lastIndexOf('.') + 1);
} catch (NoSuchFieldException e) {
LOGGER.error("Error getting the key:", e);
private static final String WHERE = " WHERE ";
private static final String AND = " AND ";
- private static final String ORDER = " ORDER BY ";
private static final String NAME_FILTER = "c.key.name = :name";
private static final String VERSION_FILTER = "c.key.version = :version";
private static final String PARENT_VERSION_FILTER = "c.key.parentKeyVersion = :parentversion";
private static final String LOCAL_NAME_FILTER = "c.key.localName = :localname";
- private static final String PARENT_NAME_REF_FILTER = "c.key.referenceKey.parentKeyName = :parentKeyName";
-
private static final String CLONE_ERR_MSG = "Could not clone object of class \"{}\"";
private static final String DELETE_BY_CONCEPT_KEY =
if (obj == null) {
return;
}
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
try {
mg.getTransaction().begin();
mg.merge(obj);
if (obj == null) {
return;
}
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
try {
mg.getTransaction().begin();
mg.remove(mg.contains(obj) ? obj : mg.merge(obj));
if (key == null) {
return;
}
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
try {
// @formatter:off
mg.getTransaction().begin();
if (key == null) {
return;
}
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
try {
// @formatter:off
mg.getTransaction().begin();
if (key == null) {
return;
}
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
try {
// @formatter:off
mg.getTransaction().begin();
if (key == null) {
return;
}
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
try {
// @formatter:off
mg.getTransaction().begin();
if (objs == null || objs.isEmpty()) {
return;
}
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
try {
mg.getTransaction().begin();
for (final T t : objs) {
if (objs == null || objs.isEmpty()) {
return;
}
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
try {
mg.getTransaction().begin();
for (final T t : objs) {
if (keys == null || keys.isEmpty()) {
return 0;
}
- int deletedCount = 0;
- final EntityManager mg = getEntityManager();
+ var deletedCount = 0;
+ final var mg = getEntityManager();
try {
// @formatter:off
mg.getTransaction().begin();
if (keys == null || keys.isEmpty()) {
return 0;
}
- int deletedCount = 0;
- final EntityManager mg = getEntityManager();
+ var deletedCount = 0;
+ final var mg = getEntityManager();
try {
// @formatter:off
mg.getTransaction().begin();
@Override
public <T extends PfConcept> void deleteAll(final Class<T> someClass) {
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
try {
mg.getTransaction().begin();
mg.createQuery(setQueryTable(DELETE_FROM_TABLE, someClass), someClass).executeUpdate();
return getAllVersions(someClass, name);
}
- T foundConcept = get(someClass, new PfConceptKey(name, version));
+ var foundConcept = get(someClass, new PfConceptKey(name, version));
return (foundConcept == null ? Collections.emptyList() : Collections.singletonList(foundConcept));
}
public <T extends PfConcept> List<T> getFiltered(final Class<T> someClass, final String name, final String version,
final Instant startTime, final Instant endTime, final Map<String, Object> filterMap, final String sortOrder,
final int getRecordNum) {
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
- String filterQueryString = SELECT_FROM_TABLE + WHERE;
+ var filterQueryString = SELECT_FROM_TABLE + WHERE;
try {
PfFilter timeStampFilter = new PfFilterFactory().createFilter(someClass);
if (someClass == null) {
return null;
}
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
try {
- final T t = mg.find(someClass, key);
+ final var t = mg.find(someClass, key);
if (t != null) {
mg.refresh(t);
}
if (someClass == null) {
return Collections.emptyList();
}
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
try {
return mg.createQuery(setQueryTable(SELECT_FROM_TABLE, someClass), someClass).getResultList();
} finally {
if (someClass == null) {
return Collections.emptyList();
}
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
try {
// @formatter:off
return mg.createQuery(setQueryTable(SELECT_ALL_FOR_PARENT, someClass), someClass)
if (someClass == null || parentKeyName == null) {
return Collections.emptyList();
}
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
try {
// @formatter:off
return mg.createQuery(setQueryTable(SELECT_ALL_VERSIONS_FOR_PARENT, someClass), someClass)
if (someClass == null || conceptName == null) {
return Collections.emptyList();
}
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
try {
// @formatter:off
return mg.createQuery(setQueryTable(SELECT_ALL_VERSIONS, someClass), someClass)
return Collections.emptyList();
}
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
try {
// @formatter:off
return mg.createQuery(setQueryTable(SELECT_BY_TIMESTAMP_NOKEY, someClass), someClass)
if (someClass == null || key == null) {
return null;
}
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
List<T> ret;
try {
// @formatter:off
if (someClass == null || key == null) {
return null;
}
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
List<T> ret;
try {
// @formatter:off
@Override
public <T extends PfConcept> T update(final T obj) {
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
T ret;
try {
mg.getTransaction().begin();
if (someClass == null) {
return 0;
}
- final EntityManager mg = getEntityManager();
+ final var mg = getEntityManager();
long size = 0;
try {
size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class)
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2021 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.
List<String> cascascadedErrorMessages = new ArrayList<>();
- for (Throwable t = throwable; t != null; t = t.getCause()) {
+ for (var t = throwable; t != null; t = t.getCause()) {
cascascadedErrorMessages.add(t.getMessage());
}
package org.onap.policy.models.tosca.utils;
-import java.util.Map;
import java.util.Map.Entry;
import javax.ws.rs.core.Response;
import lombok.NonNull;
/**
* Check entities from a fragment container can be added to an original container.
*
+ * @param <E> The type of TOSCA entity
+ * @param <J> The type of the JPA TOSCA entity
* @param <S> The type of container
*
* @param compositeContainer the original container
* @param fragmentContainer the fragment being added to the original container
* @return the composite container with the result
*/
- @SuppressWarnings("unchecked")
- // @formatter:off
- private static
- <S extends PfConceptContainer<? extends JpaToscaEntityType<? extends ToscaEntity>, ? extends ToscaEntity>>
+ private static <E extends ToscaEntity, J extends JpaToscaEntityType<E>, S extends PfConceptContainer<J, E>>
S addFragmentEntitites(final S compositeContainer, final S fragmentContainer,
final BeanValidationResult result) {
}
var result2 = new BeanValidationResult("incoming fragment", fragmentContainer);
+ var originalContainerMap = compositeContainer.getConceptMap();
+ var fragmentContainerMap = fragmentContainer.getConceptMap();
- for (Entry<PfConceptKey, ? extends JpaToscaEntityType<? extends ToscaEntity>> fragmentEntry : fragmentContainer
- .getConceptMap().entrySet()) {
- JpaToscaEntityType<? extends ToscaEntity> containerEntity =
- compositeContainer.getConceptMap().get(fragmentEntry.getKey());
+ for (Entry<PfConceptKey, J> fragmentEntry : fragmentContainerMap.entrySet()) {
+ J containerEntity = originalContainerMap.get(fragmentEntry.getKey());
if (containerEntity != null && containerEntity.compareTo(fragmentEntry.getValue()) != 0) {
- Validated.addResult(result, "entity", fragmentEntry.getKey(),
- "does not equal existing entity");
+ Validated.addResult(result, "entity", fragmentEntry.getKey(), "does not equal existing entity");
}
}
result.addResult(result2);
}
- // This use of a generic map is required to get around typing errors in directly adding the fragment map to the
- // original map
- @SuppressWarnings("rawtypes")
- Map originalContainerMap = compositeContainer.getConceptMap();
- originalContainerMap.putAll(fragmentContainer.getConceptMap());
+ originalContainerMap.putAll(fragmentContainerMap);
return compositeContainer;
}
- // @formatter:on
}