* ============LICENSE_START=======================================================
* Integrity Audit
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-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.
// Clean up the DB
try (EntityTransCloser etc = new EntityTransCloser(em.getTransaction())) {
- EntityTransaction et = etc.getTransation();
+ EntityTransaction et = etc.getTransaction();
em.createQuery("Delete from IntegrityAuditEntity").executeUpdate();
EntityTransCloser etc = new EntityTransCloser(emc.getManager().getTransaction())) {
EntityManager entmgr = emc.getManager();
- EntityTransaction entrans = etc.getTransation();
+ EntityTransaction entrans = etc.getTransaction();
// Clean up the DB
entmgr.createQuery("Delete from " + tableName).executeUpdate();
@Override
public void commit() {
synchronized (FLUSHLOCK) {
- if (getTransation().isActive()) {
+ if (getTransaction().isActive()) {
super.commit();
}
}
@Override
public void rollback() {
synchronized (FLUSHLOCK) {
- if (getTransation().isActive()) {
+ if (getTransaction().isActive()) {
super.rollback();
}
}
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
import org.onap.policy.common.gson.DoubleConverter;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
/**
* JSON encoder and decoder using the "standard" mechanism, which is currently gson.
*/
+@AllArgsConstructor(access = AccessLevel.PROTECTED)
public class StandardCoder implements Coder {
/**
this(GSON_STD, GSON_STD_PRETTY);
}
- /**
- * Constructs the object.
- */
- protected StandardCoder(Gson gson, Gson gsonPretty) {
- this.gson = gson;
- this.gsonPretty = gsonPretty;
- }
-
@Override
public <S, T> T convert(S source, Class<T> clazz) throws CoderException {
if (source == null) {
/**
* Adapter for standard objects.
*/
+ @AllArgsConstructor
protected static class StandardTypeAdapter extends TypeAdapter<StandardCoderObject> {
/**
*/
private static TypeAdapter<JsonElement> elementAdapter = new Gson().getAdapter(JsonElement.class);
- /**
- * Constructs the object.
- */
- public StandardTypeAdapter() {
- super();
- }
-
@Override
public void write(JsonWriter out, StandardCoderObject value) throws IOException {
elementAdapter.write(out, value.getData());
import com.google.gson.JsonElement;
import java.io.Serializable;
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
/**
* Object type used by the {@link StandardCoder}. Different serialization tools have
* different "standard objects". For instance, GSON uses {@link JsonElement}. This class
* wraps that object so that it can be used without exposing the object, itself.
*/
+@AllArgsConstructor(access = AccessLevel.PROTECTED)
public class StandardCoderObject implements Serializable {
private static final long serialVersionUID = 1L;
* this should not be transient, but since it isn't serializable, we're stuck with it
* until there's time to address the issue
*/
+ @Getter(AccessLevel.PROTECTED)
private final transient JsonElement data;
/**
data = null;
}
- /**
- * Constructs the object.
- *
- * @param data data wrapped by this object.
- */
- protected StandardCoderObject(JsonElement data) {
- this.data = data;
- }
-
- /**
- * Gets the data wrapped by this.
- *
- * @return the data wrapped by this
- */
- protected JsonElement getData() {
- return data;
- }
-
/**
* Gets a field's value from this object, traversing the object hierarchy.
*
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
+import lombok.AllArgsConstructor;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.emitter.Emitter;
* translation. In addition, the {@link #convertFromDouble(Class, Object)} method should
* be overridden with an appropriate conversion method.
*/
+@AllArgsConstructor
public class YamlJsonTranslator {
/**
this(new Gson());
}
- /**
- * Constructs the object.
- *
- * @param gson the Gson object to be used to serialize and de-serialize
- */
- public YamlJsonTranslator(Gson gson) {
- this.gson = gson;
- }
-
/**
* Translates a POJO into a YAML String.
*
* ============LICENSE_START=======================================================
* Common Utils
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 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.
* 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.
package org.onap.policy.common.utils.jpa;
import javax.persistence.EntityManager;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
/**
* Wrapper for an <i>EntityManager</i>, providing auto-close functionality. This is useful in
* try-with-resources statements.
*/
+@AllArgsConstructor
public class EntityMgrCloser implements AutoCloseable {
/**
* The wrapped manager.
*/
- private final EntityManager em;
-
- /**
- * Construct an instance with the EntityManager.
- *
- * @param em manager to be auto-closed
- */
- public EntityMgrCloser(EntityManager em) {
- this.em = em;
- }
-
- /**
- * Gets the EntityManager wrapped within this object.
- *
- * @return the associated EntityManager
- */
- public EntityManager getManager() {
- return em;
- }
+ @Getter
+ private final EntityManager manager;
@Override
public void close() {
- em.close();
+ manager.close();
}
}
* ============LICENSE_START=======================================================
* Common Utils
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 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.
* 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.
package org.onap.policy.common.utils.jpa;
import javax.persistence.EntityManagerFactory;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
/**
* Wrapper for an <i>EntityManagerFactory</i>, providing auto-close functionality. This is useful in
* try-with-resources statements.
*/
+@AllArgsConstructor
public class EntityMgrFactoryCloser implements AutoCloseable {
/**
* The wrapped factory.
*/
- private final EntityManagerFactory emf;
-
- /**
- * Construct an instance with the given EntityManagerFactory.
- *
- * @param emf manager to be auto-closed
- */
- public EntityMgrFactoryCloser(EntityManagerFactory emf) {
- this.emf = emf;
- }
-
- /**
- * Gets the EntityManagerFactory wrapped within this object.
- *
- * @return the associated EntityManagerFactory
- */
- public EntityManagerFactory getFactory() {
- return emf;
- }
+ @Getter
+ private final EntityManagerFactory factory;
@Override
public void close() {
- emf.close();
+ factory.close();
}
}
* ============LICENSE_START=======================================================
* Common Utils
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 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.
* 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.
package org.onap.policy.common.utils.jpa;
import javax.persistence.EntityTransaction;
+import lombok.Getter;
/**
* Wrapper for an <i>EntityTransaction</i> that is auto-rolled back when closed. This is useful in
/**
* Transaction to be rolled back.
*/
- private final EntityTransaction trans;
+ @Getter
+ private final EntityTransaction transaction;
/**
* Begins a transaction.
- *
+ *
* @param et transaction to wrap/begin
*/
public EntityTransCloser(EntityTransaction et) {
- trans = et;
- trans.begin();
- }
-
- /**
- * Gets the wrapped transaction.
- *
- * @return the transaction
- */
- public EntityTransaction getTransation() {
- return trans;
+ transaction = et;
+ transaction.begin();
}
/**
* Commits the transaction.
*/
public void commit() {
- trans.commit();
+ transaction.commit();
}
/**
* Rolls back the transaction.
*/
public void rollback() {
- trans.rollback();
+ transaction.rollback();
}
@Override
public void close() {
- if (trans.isActive()) {
- trans.rollback();
+ if (transaction.isActive()) {
+ transaction.rollback();
}
}
-
}
import java.net.Socket;
import java.net.UnknownHostException;
import javax.net.ssl.TrustManager;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.apache.commons.net.util.TrustManagerUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Network Utilities.
*/
-public class NetworkUtil {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class NetworkUtil {
public static final Logger logger = LoggerFactory.getLogger(NetworkUtil.class.getName());
*/
private static final TrustManager[] ALWAYS_TRUST_MANAGER = { TrustManagerUtils.getAcceptAllTrustManager() };
- private NetworkUtil() {
- // Empty constructor
- }
-
/**
* Allocates an available port on which a server may listen.
*
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Utilities for generating POJOs from Properties.
*/
-public class PropertyObjectUtils {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class PropertyObjectUtils {
public static final Logger logger = LoggerFactory.getLogger(PropertyObjectUtils.class);
private static final Pattern NAME_PAT = Pattern.compile("\\[(\\d{1,3})\\]$");
private static final Pattern DOT_PAT = Pattern.compile("[.]");
- private PropertyObjectUtils() {
- // do nothing
- }
-
/**
* Converts a set of properties to a Map. Supports json-path style property names with
* "." separating components, where components may have an optional subscript.
package org.onap.policy.common.utils.properties;
import java.util.Properties;
+import lombok.AccessLevel;
+import lombok.Getter;
/**
* Properties with an optional specialization (e.g., session name, controller name).
*/
+@Getter(AccessLevel.PROTECTED)
public class SpecProperties extends Properties {
private static final long serialVersionUID = 1L;
return super.getProperty(key);
}
- protected String getPrefix() {
- return prefix;
- }
-
- protected String getSpecPrefix() {
- return specPrefix;
- }
-
@Override
public final synchronized int hashCode() {
throw new UnsupportedOperationException("SpecProperties cannot be hashed");
package org.onap.policy.common.utils.properties.exception;
+import lombok.Getter;
+
/**
* Exception associated with a Property.
*/
+@Getter
public class PropertyException extends Exception {
private static final long serialVersionUID = 1L;
this.fieldName = fieldName;
}
- /**
- * Get the property name.
- *
- * @return name of the property for which the exception was thrown, or {@code null} if
- * no name was provided
- */
- public String getPropertyName() {
- return propertyName;
- }
-
- /**
- * Get the field name.
- *
- * @return name of the field for which the exception was thrown, or {@code null} if no
- * field was provided
- */
- public String getFieldName() {
- return fieldName;
- }
-
/**
* Make the message.
*
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Bell Canada. All rights reserved.
+ * 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.common.utils.resources;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
/**
* Common messages to be used by all components.
*/
-public class MessageConstants {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class MessageConstants {
public static final String POLICY_API = "policy-api";
public static final String POLICY_PAP = "policy-pap";
public static final String START_SUCCESS_MSG = "Started %s service successfully.";
public static final String START_FAILURE_MSG = "Start of %s service failed.";
-
- private MessageConstants() {
- super();
- }
}
import java.util.TreeSet;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* This is common utility class with static methods for handling Java resources on the class path. It is an abstract
* class to prevent any direct instantiation and private constructor to prevent extending this class.
*/
-public abstract class ResourceUtils {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ResourceUtils {
// Get a reference to the logger
private static final Logger LOGGER = LoggerFactory.getLogger(ResourceUtils.class);
private static final String FILE_PROTOCOL = "file";
private static final String JAR_PROTOCOL = "jar";
- /**
- * Private constructor used to prevent sub class instantiation.
- */
- private ResourceUtils() {
- // Prevent construction of this class
- }
-
/**
* Method to resolve a resource; the local file system is checked first and then the class path is checked.
*
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.apache.commons.io.IOUtils;
/**
*
* @author Liam Fallon (liam.fallon@est.tech)
*/
-public class TextFileUtils {
-
- private TextFileUtils() {
- // This class cannot be initialized
- }
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class TextFileUtils {
/**
* Method to return the contents of a text file as a string.
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * 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.
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
/**
* Utilities for use with "feature APIs".
*/
-public class FeatureApiUtils {
-
- private FeatureApiUtils() {
- // do nothing
- }
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class FeatureApiUtils {
/**
* Applies a function on each feature provider, stopping as soon as one returns true.
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * 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.
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* This is a simple object registry, similar in spirit to JNDI, but suitable for use in a
* stand-alone JVM.
*/
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class Registry {
private static final Logger logger = LoggerFactory.getLogger(Registry.class);
*/
private Map<String, Object> name2object = new ConcurrentHashMap<>();
- /**
- * Constructs the object.
- */
- private Registry() {
- super();
- }
-
/**
* Registers an object.
*
* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * 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.
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
import org.onap.policy.common.capabilities.Startable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Manager name.
*/
+ @Getter
private final String name;
/**
this.name = name;
}
- public String getName() {
- return name;
- }
-
/**
* Adds a pair of service actions to the manager.
*
/**
* Service information.
*/
+ @AllArgsConstructor
private static class Service {
private String stepName;
private RunnableWithEx starter;
private RunnableWithEx stopper;
-
- public Service(String stepName, RunnableWithEx starter, RunnableWithEx stopper) {
- this.stepName = stepName;
- this.starter = starter;
- this.stopper = stopper;
- }
}
/*
* ============LICENSE_START=======================================================
* Common Utils
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 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.
* 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.
package org.onap.policy.common.utils.time;
import java.util.Date;
+import lombok.NoArgsConstructor;
/**
* Methods to access the current time. Classes can use objects of this type to get current
* time information, while allowing the objects to be overridden by junit tests.
*/
+@NoArgsConstructor
public class CurrentTime {
- /**
- * Constructor.
- *
- */
- public CurrentTime() {
- super();
- }
-
/**
* Get the millisecond time.
- *
+ *
* @return the current time, in milliseconds
*/
public long getMillis() {
/**
* Get the current date.
- *
+ *
* @return the current Date
*/
public Date getDate() {
/**
* Sleeps for a period of time.
- *
+ *
* @param sleepMs amount of time to sleep, in milliseconds
* @throws InterruptedException can be interrupted
*/
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019 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.common.utils.validation;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* The Class Assertions is a static class that is used as a shorthand for assertions in the source code.
* It throws runtime exceptions on assertion fails.
*/
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class Assertions {
// Logger for this class
private static final Logger LOGGER = LoggerFactory.getLogger(Assertions.class);
- /**
- * Private constructor used to prevent sub class instantiation.
- */
- private Assertions() {
- }
-
/**
* Gets the validation message for a string parameter.
*
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * 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.common.utils.validation;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
/**
* Class to provide utility methods for common parameter validations.
*
* @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
*/
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ParameterValidationUtils {
- private ParameterValidationUtils() {
-
- }
-
/**
* Validates the given string input.
*
* ============LICENSE_START=======================================================
* Common Utils
* ================================================================================
- * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-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 void testEntityTransCloser() {
EntityTransCloser entityTransCloser = new EntityTransCloser(trans);
- assertEquals(trans, entityTransCloser.getTransation());
+ assertEquals(trans, entityTransCloser.getTransaction());
// verify that transaction was started
verify(trans).begin();
@Test
public void testGetTransation() {
try (EntityTransCloser t = new EntityTransCloser(trans)) {
- assertEquals(trans, t.getTransation());
+ assertEquals(trans, t.getTransaction());
}
}