From cfcffbce70ddc3083e337f18377c0847f7233caa Mon Sep 17 00:00:00 2001 From: liamfallon Date: Tue, 19 Mar 2019 12:52:20 +0000 Subject: Fix checkstyle/Sonar issues on juint/sonar fixes Recent changes to increase code coverage and fox Sonar bugs have introduced checkstyle and further Sonar issues. This review cleans those up. Issue-ID: POLICY-1523 Change-Id: I829217ef77d52e57f9713cfeee5b122e1f25efbc Signed-off-by: liamfallon --- .../apex/model/modelapi/impl/ApexModelImpl.java | 116 ++++------- .../model/modelapi/impl/ContextAlbumBuilder.java | 162 ++++++++-------- .../model/modelapi/impl/ContextAlbumFacade.java | 214 +++++++++------------ 3 files changed, 208 insertions(+), 284 deletions(-) (limited to 'model/model-api') diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java index 615ed2d4d..6719dea99 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -371,65 +372,39 @@ public final class ApexModelImpl implements ApexModel { return eventFacade.deleteEventPar(name, version, parName); } - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.model.modelapi.ApexEditorAPI#createContextAlbum(java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.lang.String) - */ - @Override - // CHECKSTYLE:OFF: checkstyle:parameterNumber - public ApexApiResult createContextAlbum( - final String name, - final String version, - final String scope, - final String writable, - final String contextSchemaName, - final String contextSchemaVersion, - final String uuid, - final String description) { - return contextAlbumFacade.createContextAlbum( - new ContextAlbumBuilder() - .setName(name) - .setVersion(version) - .setScope(scope) - .setWritable(writable) - .setContextSchemaName(contextSchemaName) - .setContextSchemaVersion(contextSchemaVersion) - .setUuid(uuid) - .setDescription(description)); - } - // CHECKSTYLE:ON: checkstyle:parameterNumber - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.model.modelapi.ApexEditorAPI#updateContextAlbum(java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.lang.String) - */ - // CHECKSTYLE:OFF: checkstyle:parameterNumber - @Override - public ApexApiResult updateContextAlbum( - final String name, - final String version, - final String scope, - final String writable, - final String contextSchemaName, - final String contextSchemaVersion, - final String uuid, - final String description) { - return contextAlbumFacade.updateContextAlbum( - new ContextAlbumBuilder() - .setName(name) - .setVersion(version) - .setScope(scope) - .setWritable(writable) - .setContextSchemaName(contextSchemaName) - .setContextSchemaVersion(contextSchemaVersion) - .setUuid(uuid) - .setDescription(description)); + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.model.modelapi.ApexEditorAPI#createContextAlbum(java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.lang.String) + */ + @Override + // CHECKSTYLE:OFF: checkstyle:parameterNumber + public ApexApiResult createContextAlbum(final String name, final String version, final String scope, + final String writable, final String contextSchemaName, final String contextSchemaVersion, final String uuid, + final String description) { + return contextAlbumFacade.createContextAlbum(new ContextAlbumBuilder().setName(name).setVersion(version) + .setScope(scope).setWritable(writable).setContextSchemaName(contextSchemaName) + .setContextSchemaVersion(contextSchemaVersion).setUuid(uuid).setDescription(description)); + } + // CHECKSTYLE:ON: checkstyle:parameterNumber + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.model.modelapi.ApexEditorAPI#updateContextAlbum(java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.lang.String) + */ + // CHECKSTYLE:OFF: checkstyle:parameterNumber + @Override + public ApexApiResult updateContextAlbum(final String name, final String version, final String scope, + final String writable, final String contextSchemaName, final String contextSchemaVersion, final String uuid, + final String description) { + return contextAlbumFacade.updateContextAlbum(new ContextAlbumBuilder().setName(name).setVersion(version) + .setScope(scope).setWritable(writable).setContextSchemaName(contextSchemaName) + .setContextSchemaVersion(contextSchemaVersion).setUuid(uuid).setDescription(description)); } // CHECKSTYLE:ON: checkstyle:parameterNumber @@ -970,25 +945,12 @@ public final class ApexModelImpl implements ApexModel { */ @Override // CHECKSTYLE:OFF: checkstyle:parameterNumber - public ApexApiResult createPolicyStateTaskRef( - final String name, - final String version, - final String stateName, - final String taskLocalName, - final String taskName, - final String taskVersion, - final String outputType, + public ApexApiResult createPolicyStateTaskRef(final String name, final String version, final String stateName, + final String taskLocalName, final String taskName, final String taskVersion, final String outputType, final String outputName) { - return policyFacade.createPolicyStateTaskRef( - new CreatePolicyStateTaskRefBuilder() - .setName(name) - .setVersion(version) - .setStateName(stateName) - .setTaskLocalName(taskLocalName) - .setTaskName(taskName) - .setTaskVersion(taskVersion) - .setOutputType(outputType) - .setOutputName(outputName)); + return policyFacade.createPolicyStateTaskRef(new CreatePolicyStateTaskRefBuilder().setName(name) + .setVersion(version).setStateName(stateName).setTaskLocalName(taskLocalName).setTaskName(taskName) + .setTaskVersion(taskVersion).setOutputType(outputType).setOutputName(outputName)); } // CHECKSTYLE:ON: checkstyle:parameterNumber diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumBuilder.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumBuilder.java index 88ee64822..937a16e37 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumBuilder.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumBuilder.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,87 +18,88 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ + package org.onap.policy.apex.model.modelapi.impl; public class ContextAlbumBuilder { - private String name; - private String version; - private String scope; - private String writable; - private String contextSchemaName; - private String contextSchemaVersion; - private String uuid; - private String description; - - public String getName() { - return name; - } - - public ContextAlbumBuilder setName(String name) { - this.name = name; - return this; - } - - public String getVersion() { - return version; - } - - public ContextAlbumBuilder setVersion(String version) { - this.version = version; - return this; - } - - public String getScope() { - return scope; - } - - public ContextAlbumBuilder setScope(String scope) { - this.scope = scope; - return this; - } - - public String getWritable() { - return writable; - } - - public ContextAlbumBuilder setWritable(String writable) { - this.writable = writable; - return this; - } - - public String getContextSchemaName() { - return contextSchemaName; - } - - public ContextAlbumBuilder setContextSchemaName(String contextSchemaName) { - this.contextSchemaName = contextSchemaName; - return this; - } - - public String getContextSchemaVersion() { - return contextSchemaVersion; - } - - public ContextAlbumBuilder setContextSchemaVersion(String contextSchemaVersion) { - this.contextSchemaVersion = contextSchemaVersion; - return this; - } - - public String getUuid() { - return uuid; - } - - public ContextAlbumBuilder setUuid(String uuid) { - this.uuid = uuid; - return this; - } - - public String getDescription() { - return description; - } - - public ContextAlbumBuilder setDescription(String description) { - this.description = description; - return this; - } + private String name; + private String version; + private String scope; + private String writable; + private String contextSchemaName; + private String contextSchemaVersion; + private String uuid; + private String description; + + public String getName() { + return name; + } + + public ContextAlbumBuilder setName(String name) { + this.name = name; + return this; + } + + public String getVersion() { + return version; + } + + public ContextAlbumBuilder setVersion(String version) { + this.version = version; + return this; + } + + public String getScope() { + return scope; + } + + public ContextAlbumBuilder setScope(String scope) { + this.scope = scope; + return this; + } + + public String getWritable() { + return writable; + } + + public ContextAlbumBuilder setWritable(String writable) { + this.writable = writable; + return this; + } + + public String getContextSchemaName() { + return contextSchemaName; + } + + public ContextAlbumBuilder setContextSchemaName(String contextSchemaName) { + this.contextSchemaName = contextSchemaName; + return this; + } + + public String getContextSchemaVersion() { + return contextSchemaVersion; + } + + public ContextAlbumBuilder setContextSchemaVersion(String contextSchemaVersion) { + this.contextSchemaVersion = contextSchemaVersion; + return this; + } + + public String getUuid() { + return uuid; + } + + public ContextAlbumBuilder setUuid(String uuid) { + this.uuid = uuid; + return this; + } + + public String getDescription() { + return description; + } + + public ContextAlbumBuilder setDescription(String description) { + this.description = description; + return this; + } } diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumFacade.java index 920dc5eba..dfc29b302 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumFacade.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumFacade.java @@ -2,19 +2,20 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * 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========================================================= */ @@ -61,7 +62,8 @@ public class ContextAlbumFacade { * @param apexModel the apex model * @param apexProperties Properties for the model * @param jsonMode set to true to return JSON strings in list and delete operations, otherwise - * set to false + * set to false * Modifications Copyright (C) 2019 Nordix Foundation. + */ public ContextAlbumFacade(final ApexModel apexModel, final Properties apexProperties, final boolean jsonMode) { this.apexModel = apexModel; @@ -71,140 +73,98 @@ public class ContextAlbumFacade { keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties, jsonMode); } - /** - * Create a context album. - * - * @param name name of the context album - * @param version version of the context album, set to null to use the default version - * @param scope of the context album - * @param writable "true" or "t" if the context album is writable, set to null or any other value - * for a read-only album - * @param contextSchemaName name of the parameter context schema - * @param contextSchemaVersion version of the parameter context schema, set to null to use the - * latest version - * @param uuid context album UUID, set to null to generate a UUID - * @param description context album description, set to null to generate a description - * @return result of the operation - */ - // CHECKSTYLE:OFF: checkstyle:parameterNumber - public ApexApiResult createContextAlbum(ContextAlbumBuilder builder) { - try { - final AxArtifactKey key = new AxArtifactKey(); - key.setName(builder.getName()); - if (builder.getVersion() != null) { - key.setVersion(builder.getVersion()); - } else { - key.setVersion(apexProperties.getProperty("DEFAULT_CONCEPT_VERSION")); - } + /** + * Create a context album. + * + * @param builder the builder for the context album parameters + * @return result of the operation + */ + // CHECKSTYLE:OFF: checkstyle:parameterNumber + public ApexApiResult createContextAlbum(ContextAlbumBuilder builder) { + try { + final AxArtifactKey key = new AxArtifactKey(); + key.setName(builder.getName()); + if (builder.getVersion() != null) { + key.setVersion(builder.getVersion()); + } else { + key.setVersion(apexProperties.getProperty("DEFAULT_CONCEPT_VERSION")); + } - if (apexModel.getPolicyModel().getAlbums().getAlbumsMap().containsKey(key)) { - return new ApexApiResult( - ApexApiResult.Result.CONCEPT_EXISTS, CONCEPT + key.getId() + " already exists"); - } + if (apexModel.getPolicyModel().getAlbums().getAlbumsMap().containsKey(key)) { + return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS, + CONCEPT + key.getId() + " already exists"); + } - final AxContextSchema schema = - apexModel - .getPolicyModel() - .getSchemas() - .get(builder.getContextSchemaName(), builder.getContextSchemaVersion()); - if (schema == null) { - return new ApexApiResult( - ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT - + builder.getContextSchemaName() - + ':' - + builder.getContextSchemaVersion() - + DOES_NOT_EXIST); - } + final AxContextSchema schema = apexModel.getPolicyModel().getSchemas().get(builder.getContextSchemaName(), + builder.getContextSchemaVersion()); + if (schema == null) { + return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, CONCEPT + + builder.getContextSchemaName() + ':' + builder.getContextSchemaVersion() + DOES_NOT_EXIST); + } - final AxContextAlbum contextAlbum = new AxContextAlbum(key); - contextAlbum.setScope(builder.getScope()); - contextAlbum.setItemSchema(schema.getKey()); + final AxContextAlbum contextAlbum = new AxContextAlbum(key); + contextAlbum.setScope(builder.getScope()); + contextAlbum.setItemSchema(schema.getKey()); - if (builder.getWritable() != null - && ("true".equalsIgnoreCase(builder.getWritable().trim()) - || "t".equalsIgnoreCase(builder.getWritable().trim()))) { - contextAlbum.setWritable(true); - } else { - contextAlbum.setWritable(false); - } + contextAlbum + .setWritable(builder.getWritable() != null && ("true".equalsIgnoreCase(builder.getWritable().trim()) + || "t".equalsIgnoreCase(builder.getWritable().trim()))); - apexModel.getPolicyModel().getAlbums().getAlbumsMap().put(key, contextAlbum); + apexModel.getPolicyModel().getAlbums().getAlbumsMap().put(key, contextAlbum); - if (apexModel.getPolicyModel().getKeyInformation().getKeyInfoMap().containsKey(key)) { - return keyInformationFacade.updateKeyInformation( - builder.getName(), builder.getVersion(), builder.getUuid(), builder.getDescription()); - } else { - return keyInformationFacade.createKeyInformation( - builder.getName(), builder.getVersion(), builder.getUuid(), builder.getDescription()); - } - } catch (final Exception e) { - return new ApexApiResult(ApexApiResult.Result.FAILED, e); - } + if (apexModel.getPolicyModel().getKeyInformation().getKeyInfoMap().containsKey(key)) { + return keyInformationFacade.updateKeyInformation(builder.getName(), builder.getVersion(), + builder.getUuid(), builder.getDescription()); + } else { + return keyInformationFacade.createKeyInformation(builder.getName(), builder.getVersion(), + builder.getUuid(), builder.getDescription()); + } + } catch (final Exception e) { + return new ApexApiResult(ApexApiResult.Result.FAILED, e); + } } - // CHECKSTYLE:ON: checkstyle:parameterNumber + // CHECKSTYLE:ON: checkstyle:parameterNumber - /** - * Update a context album. - * - * @param name name of the context album - * @param version version of the context album, set to null to use the default version - * @param scope of the context album - * @param writable "true" or "t" if the context album is writable, set to null or any other value - * for a read-only album - * @param contextSchemaName name of the parameter context schema - * @param contextSchemaVersion version of the parameter context schema, set to null to use the - * latest version - * @param uuid context album UUID, set to null to generate a UUID - * @param description context album description, set to null to generate a description - * @return result of the operation - */ - // CHECKSTYLE:OFF: checkstyle:parameterNumber - public ApexApiResult updateContextAlbum(ContextAlbumBuilder builder) { - try { - final AxContextAlbum contextAlbum = - apexModel.getPolicyModel().getAlbums().get(builder.getName(), builder.getVersion()); - if (contextAlbum == null) { - return new ApexApiResult( - ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + builder.getName() + ':' + builder.getVersion() + DOES_NOT_EXIST); - } + /** + * Update a context album. + * + * @param builder the builder for the context album parameters + * @return result of the operation + */ + // CHECKSTYLE:OFF: checkstyle:parameterNumber + public ApexApiResult updateContextAlbum(ContextAlbumBuilder builder) { + try { + final AxContextAlbum contextAlbum = + apexModel.getPolicyModel().getAlbums().get(builder.getName(), builder.getVersion()); + if (contextAlbum == null) { + return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, + CONCEPT + builder.getName() + ':' + builder.getVersion() + DOES_NOT_EXIST); + } - if (builder.getScope() != null) { - contextAlbum.setScope(builder.getScope()); - } - if (builder.getWritable() != null) { - if ("true".equalsIgnoreCase(builder.getWritable().trim()) - || "t".equalsIgnoreCase(builder.getWritable().trim())) { - contextAlbum.setWritable(true); - } else { - contextAlbum.setWritable(false); - } - } + if (builder.getScope() != null) { + contextAlbum.setScope(builder.getScope()); + } - if (builder.getContextSchemaName() != null) { - final AxContextSchema schema = - apexModel - .getPolicyModel() - .getSchemas() - .get(builder.getContextSchemaName(), builder.getContextSchemaVersion()); - if (schema == null) { - return new ApexApiResult( - ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT - + builder.getContextSchemaName() - + ':' - + builder.getContextSchemaVersion() - + DOES_NOT_EXIST); - } - contextAlbum.setItemSchema(schema.getKey()); - } + contextAlbum + .setWritable(builder.getWritable() != null && ("true".equalsIgnoreCase(builder.getWritable().trim()) + || "t".equalsIgnoreCase(builder.getWritable().trim()))); - return keyInformationFacade.updateKeyInformation( - builder.getName(), builder.getVersion(), builder.getUuid(), builder.getDescription()); - } catch (final Exception e) { - return new ApexApiResult(ApexApiResult.Result.FAILED, e); - } + if (builder.getContextSchemaName() != null) { + final AxContextSchema schema = apexModel.getPolicyModel().getSchemas() + .get(builder.getContextSchemaName(), builder.getContextSchemaVersion()); + if (schema == null) { + return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, + CONCEPT + builder.getContextSchemaName() + ':' + builder.getContextSchemaVersion() + + DOES_NOT_EXIST); + } + contextAlbum.setItemSchema(schema.getKey()); + } + + return keyInformationFacade.updateKeyInformation(builder.getName(), builder.getVersion(), builder.getUuid(), + builder.getDescription()); + } catch (final Exception e) { + return new ApexApiResult(ApexApiResult.Result.FAILED, e); + } } // CHECKSTYLE:ON: checkstyle:parameterNumber -- cgit 1.2.3-korg