From 7438fe5a86a9fcfaf248ee32197b24d1badaecb3 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 4 Aug 2021 10:41:51 -0400 Subject: Use lombok in apex-pdp #2 Updated context to use lombok. Issue-ID: POLICY-3391 Change-Id: I349e0202fffad161cac08cebaea4a9571db58bda Signed-off-by: Jim Hahn --- .../contextmodel/concepts/AxContextAlbum.java | 119 ++------------------- .../contextmodel/concepts/AxContextAlbums.java | 71 ++---------- .../contextmodel/concepts/AxContextModel.java | 81 ++------------ .../contextmodel/concepts/AxContextSchema.java | 47 ++------ .../contextmodel/concepts/AxContextSchemas.java | 68 ++---------- .../contextmodel/concepts/ContextAlbumsTest.java | 11 +- .../contextmodel/concepts/ContextModelTest.java | 4 +- .../contextmodel/concepts/ContextSchemasTest.java | 11 +- 8 files changed, 62 insertions(+), 350 deletions(-) (limited to 'model/context-model') diff --git a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java index 85a6ab803..b3880bd8c 100644 --- a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java +++ b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java @@ -34,6 +34,10 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; import org.onap.policy.apex.model.basicmodel.concepts.AxKey; @@ -66,6 +70,10 @@ import org.onap.policy.common.utils.validation.Assertions; @Entity @Table(name = "AxContextAlbum") +@Getter +@ToString +@EqualsAndHashCode(callSuper = false) + @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "apexContextAlbum", namespace = "http://www.onap.org/policy/apex-pdp") @XmlType(name = "AxContextAlbum", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = @@ -84,9 +92,6 @@ public class AxContextAlbum extends AxConcept { /** The value of scope for a context album for which a scope has not been specified. */ public static final String SCOPE_UNDEFINED = "UNDEFINED"; - private static final int HASH_PRIME_0 = 1231; - private static final int HASH_PRIME_1 = 1237; - @EmbeddedId @XmlElement(name = "key", required = true) private AxArtifactKey key; @@ -97,6 +102,7 @@ public class AxContextAlbum extends AxConcept { @Column(name = "isWritable") @XmlElement(name = "isWritable", required = true) + @Setter private boolean isWritable; // @formatter:off @@ -161,14 +167,6 @@ public class AxContextAlbum extends AxConcept { this.itemSchema = itemSchema; } - /** - * {@inheritDoc}. - */ - @Override - public AxArtifactKey getKey() { - return key; - } - /** * {@inheritDoc}. */ @@ -190,15 +188,6 @@ public class AxContextAlbum extends AxConcept { this.key = key; } - /** - * Gets the scope of the context album. - * - * @return the context album scope - */ - public String getScope() { - return scope; - } - /** * Sets the scope of the context album. * @@ -209,33 +198,6 @@ public class AxContextAlbum extends AxConcept { this.scope = Assertions.validateStringParameter(SCOPE_STRING, scope, SCOPE_REGEXP); } - /** - * Sets whether the album is writable or not. - * - * @param writable the writable flag value - */ - public void setWritable(final boolean writable) { - this.isWritable = writable; - } - - /** - * Checks if the album is writable. - * - * @return true, if the album is writable - */ - public boolean isWritable() { - return isWritable; - } - - /** - * Gets the artifact key of the item schema of this context album. - * - * @return the item schema key - */ - public AxArtifactKey getItemSchema() { - return itemSchema; - } - /** * Sets the artifact key of the item schema of this context album. * @@ -289,26 +251,6 @@ public class AxContextAlbum extends AxConcept { itemSchema.clean(); } - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final var builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("key="); - builder.append(key); - builder.append(",scope="); - builder.append(scope); - builder.append(",isWritable="); - builder.append(isWritable); - builder.append(",itemSchema="); - builder.append(itemSchema); - builder.append(")"); - return builder.toString(); - } - /** * {@inheritDoc}. */ @@ -328,49 +270,6 @@ public class AxContextAlbum extends AxConcept { return copy; } - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final var prime = 31; - var result = 1; - result = prime * result + key.hashCode(); - result = prime * result + scope.hashCode(); - result = prime * result + (isWritable ? HASH_PRIME_0 : HASH_PRIME_1); - result = prime * result + itemSchema.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - - if (getClass() != obj.getClass()) { - return false; - } - - final AxContextAlbum other = (AxContextAlbum) obj; - if (!key.equals(other.key)) { - return false; - } - if (!scope.equals(other.scope)) { - return false; - } - if (isWritable != other.isWritable) { - return (false); - } - return itemSchema.equals(other.itemSchema); - } - /** * {@inheritDoc}. */ diff --git a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbums.java b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbums.java index 30e021f43..aa5a89a4d 100644 --- a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbums.java +++ b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbums.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-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. @@ -39,6 +40,10 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; +import lombok.AccessLevel; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; import org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter; @@ -63,6 +68,10 @@ import org.onap.policy.common.utils.validation.Assertions; @Entity @Table(name = "AxContextAlbums") +@Getter +@ToString +@EqualsAndHashCode(callSuper = false) + @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "AxContextAlbums", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = { "key", "albums" }) @@ -79,6 +88,7 @@ public final class AxContextAlbums extends AxConcept implements AxConceptGetter< @JoinTable(joinColumns = {@JoinColumn(name = "contextName", referencedColumnName = "name"), @JoinColumn(name = "contextVersion", referencedColumnName = "version")}) @XmlElement(name = "albums", required = true) + @Getter(AccessLevel.NONE) private Map albums; // @formatter:on @@ -144,14 +154,6 @@ public final class AxContextAlbums extends AxConcept implements AxConceptGetter< albums = navigableAlbums; } - /** - * {@inheritDoc}. - */ - @Override - public AxArtifactKey getKey() { - return key; - } - /** * {@inheritDoc}. */ @@ -208,24 +210,6 @@ public final class AxContextAlbums extends AxConcept implements AxConceptGetter< } } - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final var builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("key="); - builder.append(key); - builder.append(",albums="); - builder.append(albums); - builder.append(")"); - return builder.toString(); - } - /** * {@inheritDoc}. */ @@ -295,41 +279,6 @@ public final class AxContextAlbums extends AxConcept implements AxConceptGetter< return copy; } - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final var prime = 31; - var result = 1; - result = prime * result + key.hashCode(); - result = prime * result + albums.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - - if (getClass() != obj.getClass()) { - return false; - } - - final AxContextAlbums other = (AxContextAlbums) obj; - if (!key.equals(other.key)) { - return false; - } - return albums.equals(other.albums); - } - /** * {@inheritDoc}. */ diff --git a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextModel.java b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextModel.java index c5919c030..9796fa625 100644 --- a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextModel.java +++ b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextModel.java @@ -33,6 +33,9 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; import org.onap.policy.apex.model.basicmodel.concepts.AxKey; @@ -54,6 +57,10 @@ import org.onap.policy.common.utils.validation.Assertions; @Entity @Table(name = "AxContextModel") +@Getter +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) + @XmlRootElement(name = "apexContextModel", namespace = "http://www.onap.org/policy/apex-pdp") @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "AxContextModel", namespace = "http://www.onap.org/policy/apex-pdp", @@ -159,15 +166,6 @@ public class AxContextModel extends AxModel { return keyList; } - /** - * Gets the context schemas from the model. - * - * @return the context schemas - */ - public AxContextSchemas getSchemas() { - return schemas; - } - /** * Sets the context schemas on the model. * @@ -178,15 +176,6 @@ public class AxContextModel extends AxModel { this.schemas = schemas; } - /** - * Gets the context albums from the model. - * - * @return the context albums - */ - public AxContextAlbums getAlbums() { - return albums; - } - /** * Sets the context albums on the model. * @@ -219,23 +208,6 @@ public class AxContextModel extends AxModel { albums.clean(); } - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final var builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append(super.toString()); - builder.append(",schemas="); - builder.append(schemas); - builder.append(",albums="); - builder.append(albums); - builder.append(")"); - return builder.toString(); - } - /** * {@inheritDoc}. */ @@ -254,45 +226,6 @@ public class AxContextModel extends AxModel { return copy; } - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final var prime = 31; - var result = 1; - result = prime * result + super.hashCode(); - result = prime * result + schemas.hashCode(); - result = prime * result + albums.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - throw new IllegalArgumentException("comparison object may not be null"); - } - - if (this == obj) { - return true; - } - if (getClass() != obj.getClass()) { - return false; - } - - final AxContextModel other = (AxContextModel) obj; - if (!super.equals(other)) { - return false; - } - if (!schemas.equals(other.schemas)) { - return false; - } - return albums.equals(other.albums); - } - /** * {@inheritDoc}. */ diff --git a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java index bca369157..37f44ba49 100644 --- a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java +++ b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-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. @@ -33,6 +34,9 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.ToString; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; import org.onap.policy.apex.model.basicmodel.concepts.AxKey; @@ -63,6 +67,9 @@ import org.onap.policy.common.utils.validation.Assertions; @Entity @Table(name = "AxContextSchema") +@Getter +@ToString + @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "apexContextSchema", namespace = "http://www.onap.org/policy/apex-pdp") @XmlType(name = "AxContextSchema", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = @@ -95,6 +102,7 @@ public class AxContextSchema extends AxConcept { @Convert(converter = CDataConditioner.class) @XmlJavaTypeAdapter(value = CDataConditioner.class) @XmlElement(name = "schemaDefinition", required = true) + @Getter(AccessLevel.NONE) private String schemaDefinition; /** @@ -143,14 +151,6 @@ public class AxContextSchema extends AxConcept { this.schemaDefinition = schemaDefinition.replaceAll(WHITESPACE_REGEXP, ""); } - /** - * {@inheritDoc}. - */ - @Override - public AxArtifactKey getKey() { - return key; - } - /** * {@inheritDoc}. */ @@ -169,15 +169,6 @@ public class AxContextSchema extends AxConcept { this.key = key; } - /** - * Gets the schema flavour, which defines the schema definition type being used. - * - * @return the schema flavour - */ - public String getSchemaFlavour() { - return schemaFlavour; - } - /** * Sets the schema flavour, which defines the type of schema definition being used. * @@ -251,24 +242,6 @@ public class AxContextSchema extends AxConcept { schemaDefinition = schemaDefinition.replaceAll(WHITESPACE_REGEXP, ""); } - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final var builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("key="); - builder.append(key); - builder.append(",schemaFlavour="); - builder.append(schemaFlavour); - builder.append(",schemaDefinition="); - builder.append(schemaDefinition); - builder.append(")"); - return builder.toString(); - } - /** * {@inheritDoc}. */ @@ -296,7 +269,9 @@ public class AxContextSchema extends AxConcept { var result = 1; result = prime * result + key.hashCode(); result = prime * result + schemaFlavour.hashCode(); - result = prime * result + schemaDefinition.hashCode(); + + final String thisSchema = CDataConditioner.clean(schemaDefinition).replace("\n", ""); + result = prime * result + thisSchema.hashCode(); return result; } diff --git a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchemas.java b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchemas.java index bfd1809a7..1fa0cf57a 100644 --- a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchemas.java +++ b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchemas.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-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. @@ -39,6 +40,10 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; +import lombok.AccessLevel; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; import org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter; @@ -62,6 +67,10 @@ import org.onap.policy.common.utils.validation.Assertions; @Entity @Table(name = "AxContextSchemas") +@Getter +@ToString +@EqualsAndHashCode(callSuper = false) + @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "AxContextSchemas", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = { "key", "schemas" }) @@ -81,6 +90,7 @@ public class AxContextSchemas extends AxConcept implements AxConceptGetter schemas; // @formatter:on @@ -143,14 +153,6 @@ public class AxContextSchemas extends AxConcept implements AxConceptGetter