From 59b90519eda3b95b0cfc49b6349a591c7d0c78e2 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Mon, 7 Feb 2022 17:56:44 +0000 Subject: Remove JAXB and XML, use GSON for JSON This review converst apex-pdp to use GSON for JSON handling. In order to preserve backward compatibility with the JAXB format of JSON, custom handling of maps was required. Therefore, the policy-common StandardCoder could not be used. There are a lot of small changes, removing annotations from concepts and tweaking of test data. However, this cleans up the code base so it is worth doing. Issue-ID: POLICY-1820 Change-Id: I213fa64f6d7f3f1df8d10f111d9fbedbe80f9fe0 Signed-off-by: liamfallon --- .../policy/apex/model/modelapi/ApexApiResult.java | 17 +- .../onap/policy/apex/model/modelapi/ApexModel.java | 6 +- .../apex/model/modelapi/ApexModelFactory.java | 13 +- .../apex/model/modelapi/impl/ApexModelImpl.java | 55 ++-- .../model/modelapi/impl/ContextAlbumFacade.java | 62 ++-- .../model/modelapi/impl/ContextSchemaFacade.java | 47 ++- .../apex/model/modelapi/impl/EventFacade.java | 78 ++--- .../model/modelapi/impl/KeyInformationFacade.java | 34 +- .../apex/model/modelapi/impl/ModelFacade.java | 29 +- .../model/modelapi/impl/ModelHandlerFacade.java | 34 +- .../apex/model/modelapi/impl/PolicyFacade.java | 353 ++++++++++----------- .../apex/model/modelapi/impl/TaskFacade.java | 126 ++++---- 12 files changed, 372 insertions(+), 482 deletions(-) (limited to 'model/model-api/src/main/java') diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexApiResult.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexApiResult.java index d05d410f8..83e3b5370 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexApiResult.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexApiResult.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020,2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,13 +25,6 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlEnum; -import javax.xml.bind.annotation.XmlRootElement; import lombok.Setter; /** @@ -39,14 +32,11 @@ import lombok.Setter; * {@link ApexModel} API. */ @Setter -@XmlRootElement -@XmlAccessorType(XmlAccessType.NONE) public class ApexApiResult { /** * This enumeration is used to represent the result status of a call on the {@link ApexModel} API. */ - @XmlEnum(value = String.class) public enum Result { /** The method call succeeded. */ SUCCESS, @@ -155,7 +145,6 @@ public class ApexApiResult { * * @return true, if the result indicates the API operation succeeded */ - @XmlAttribute(required = true) public boolean isOk() { return Result.isOk(result); } @@ -174,7 +163,6 @@ public class ApexApiResult { * * @return the result status */ - @XmlAttribute(required = true) public Result getResult() { return result; } @@ -184,8 +172,6 @@ public class ApexApiResult { * * @return the list of messages returned by an API operation */ - @XmlElementWrapper(required = false, nillable = true) - @XmlElement(nillable = true, name = "message") public List getMessages() { return messages; } @@ -195,7 +181,6 @@ public class ApexApiResult { * * @return the messages returned by an API operation as a single string */ - @XmlElement(required = true, name = "content") public String getMessage() { final StringBuilder builder = new StringBuilder(); for (final String message : messages) { diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModel.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModel.java index d721e33fd..3c6e4c063 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModel.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModel.java @@ -56,10 +56,9 @@ public interface ApexModel extends ApexEditorApi { * Save an Apex model to a file. * * @param fileName the file name - * @param xmlFlag if true, save the file in XML format, otherwise save the file in the default JSON format * @return the result of the operation */ - ApexApiResult saveToFile(String fileName, boolean xmlFlag); + ApexApiResult saveToFile(String fileName); /** * Read an APEX model from a location identified by a URL. @@ -73,10 +72,9 @@ public interface ApexModel extends ApexEditorApi { * Write an APEX model to a location identified by a URL. * * @param urlString the URL to read the model from - * @param xmlFlag if true, save the file in XML format, otherwise save the file in the default JSON format * @return the result of the operation */ - ApexApiResult writeToUrl(String urlString, boolean xmlFlag); + ApexApiResult writeToUrl(String urlString); /** * Analyse an Apex model that shows the concept usage references of a policy model. diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModelFactory.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModelFactory.java index 5be8b02b8..908f562d2 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModelFactory.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModelFactory.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2022 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========================================================= */ @@ -34,12 +35,10 @@ public class ApexModelFactory { * Creates a new ApexModel object from its implementation. * * @param apexProperties default values and other configuration information for the apex model - * @param jsonMode set to true to return JSON strings in list and delete operations, otherwise - * set to false * @return the apex model */ - public ApexModel createApexModel(final Properties apexProperties, final boolean jsonMode) { - return new ApexModelImpl(setDefaultPropertyValues(apexProperties), jsonMode); + public ApexModel createApexModel(final Properties apexProperties) { + return new ApexModelImpl(setDefaultPropertyValues(apexProperties)); } /** 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 944d95f2b..54b94d0e7 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 @@ -54,9 +54,6 @@ public final class ApexModelImpl implements ApexModel { @Setter private AxPolicyModel policyModel = new AxPolicyModel(); - // The file name for the loaded file - private String fileName = null; - // @formatter:off private ModelFacade modelFacade; private KeyInformationFacade keyInformationFacade; @@ -69,27 +66,24 @@ public final class ApexModelImpl implements ApexModel { // @formatter:on private Properties apexProperties; - private boolean jsonMode; /** * Create an implementation of the Apex editor and model APIs. * * @param apexProperties The properties to use for the model - * @param jsonMode set to true to return JSON strings in list and delete operations, otherwise set to false */ - public ApexModelImpl(final Properties apexProperties, final boolean jsonMode) { + public ApexModelImpl(final Properties apexProperties) { this.apexProperties = apexProperties; - this.jsonMode = jsonMode; // @formatter:off - this.modelFacade = new ModelFacade(this, apexProperties, jsonMode); - this.keyInformationFacade = new KeyInformationFacade(this, apexProperties, jsonMode); - this.contextSchemaFacade = new ContextSchemaFacade(this, apexProperties, jsonMode); - this.eventFacade = new EventFacade(this, apexProperties, jsonMode); - this.contextAlbumFacade = new ContextAlbumFacade(this, apexProperties, jsonMode); - this.taskFacade = new TaskFacade(this, apexProperties, jsonMode); - this.policyFacade = new PolicyFacade(this, apexProperties, jsonMode); - this.modelHandlerFacade = new ModelHandlerFacade(this, apexProperties, jsonMode); + this.modelFacade = new ModelFacade(this, apexProperties); + this.keyInformationFacade = new KeyInformationFacade(this, apexProperties); + this.contextSchemaFacade = new ContextSchemaFacade(this, apexProperties); + this.eventFacade = new EventFacade(this, apexProperties); + this.contextAlbumFacade = new ContextAlbumFacade(this, apexProperties); + this.taskFacade = new TaskFacade(this, apexProperties); + this.policyFacade = new PolicyFacade(this, apexProperties); + this.modelHandlerFacade = new ModelHandlerFacade(this, apexProperties); // @formatter:on } @@ -101,17 +95,15 @@ public final class ApexModelImpl implements ApexModel { ApexModelImpl ret = new ApexModelImpl(); // @formatter:off ret.policyModel = new AxPolicyModel(policyModel); - ret.fileName = this.fileName; ret.apexProperties = this.apexProperties; - ret.jsonMode = this.jsonMode; - ret.modelFacade = new ModelFacade(ret, this.apexProperties, this.jsonMode); - ret.keyInformationFacade = new KeyInformationFacade(ret, this.apexProperties, this.jsonMode); - ret.contextSchemaFacade = new ContextSchemaFacade(ret, this.apexProperties, this.jsonMode); - ret.eventFacade = new EventFacade(ret, this.apexProperties, this.jsonMode); - ret.contextAlbumFacade = new ContextAlbumFacade(ret, this.apexProperties, this.jsonMode); - ret.taskFacade = new TaskFacade(ret, this.apexProperties, this.jsonMode); - ret.policyFacade = new PolicyFacade(ret, this.apexProperties, this.jsonMode); - ret.modelHandlerFacade = new ModelHandlerFacade(ret, this.apexProperties, this.jsonMode); + ret.modelFacade = new ModelFacade(ret, this.apexProperties); + ret.keyInformationFacade = new KeyInformationFacade(ret, this.apexProperties); + ret.contextSchemaFacade = new ContextSchemaFacade(ret, this.apexProperties); + ret.eventFacade = new EventFacade(ret, this.apexProperties); + ret.contextAlbumFacade = new ContextAlbumFacade(ret, this.apexProperties); + ret.taskFacade = new TaskFacade(ret, this.apexProperties); + ret.policyFacade = new PolicyFacade(ret, this.apexProperties); + ret.modelHandlerFacade = new ModelHandlerFacade(ret, this.apexProperties); // @formatter:on return ret; @@ -770,7 +762,6 @@ public final class ApexModelImpl implements ApexModel { @Override // CHECKSTYLE:OFF: checkstyle:HiddenField public ApexApiResult loadFromFile(final String fileName) { - this.fileName = fileName; return modelHandlerFacade.loadFromFile(fileName); } // CHECKSTYLE:ON: checkstyle:HiddenField @@ -779,12 +770,8 @@ public final class ApexModelImpl implements ApexModel { * {@inheritDoc}. */ @Override - public ApexApiResult saveToFile(final String saveFileName, final boolean xmlFlag) { - if (saveFileName == null) { - return modelHandlerFacade.saveToFile(fileName, xmlFlag); - } else { - return modelHandlerFacade.saveToFile(saveFileName, xmlFlag); - } + public ApexApiResult saveToFile(final String fileName) { + return modelHandlerFacade.saveToFile(fileName); } /** @@ -799,8 +786,8 @@ public final class ApexModelImpl implements ApexModel { * {@inheritDoc}. */ @Override - public ApexApiResult writeToUrl(final String urlString, final boolean xmlFlag) { - return modelHandlerFacade.writeToUrl(urlString, xmlFlag); + public ApexApiResult writeToUrl(final String urlString) { + return modelHandlerFacade.writeToUrl(urlString); } /** 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 a78444da6..d29f32ea0 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,7 +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. + * Modifications Copyright (C) 2019,2022 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -53,24 +53,17 @@ public class ContextAlbumFacade { // Facade classes for working towards the real Apex model private final KeyInformationFacade keyInformationFacade; - // JSON output on list/delete if set - private final boolean jsonMode; - /** * Constructor that creates a context album facade for the Apex Model API. * * @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 * Modifications Copyright (C) 2019 Nordix Foundation. - */ - public ContextAlbumFacade(final ApexModel apexModel, final Properties apexProperties, final boolean jsonMode) { + public ContextAlbumFacade(final ApexModel apexModel, final Properties apexProperties) { this.apexModel = apexModel; this.apexProperties = apexProperties; - this.jsonMode = jsonMode; - keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties, jsonMode); + keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties); } /** @@ -92,14 +85,14 @@ public class ContextAlbumFacade { if (apexModel.getPolicyModel().getAlbums().getAlbumsMap().containsKey(key)) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS, - CONCEPT + key.getId() + " already exists"); + CONCEPT + key.getId() + " already exists"); } final AxContextSchema schema = apexModel.getPolicyModel().getSchemas().get(builder.getContextSchemaName(), - builder.getContextSchemaVersion()); + builder.getContextSchemaVersion()); if (schema == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, CONCEPT - + builder.getContextSchemaName() + ':' + builder.getContextSchemaVersion() + DOES_NOT_EXIST); + + builder.getContextSchemaName() + ':' + builder.getContextSchemaVersion() + DOES_NOT_EXIST); } final AxContextAlbum contextAlbum = new AxContextAlbum(key); @@ -107,17 +100,17 @@ public class ContextAlbumFacade { contextAlbum.setItemSchema(schema.getKey()); contextAlbum - .setWritable(builder.getWritable() != null && ("true".equalsIgnoreCase(builder.getWritable().trim()) - || "t".equalsIgnoreCase(builder.getWritable().trim()))); + .setWritable(builder.getWritable() != null && ("true".equalsIgnoreCase(builder.getWritable().trim()) + || "t".equalsIgnoreCase(builder.getWritable().trim()))); 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()); + builder.getUuid(), builder.getDescription()); } else { return keyInformationFacade.createKeyInformation(builder.getName(), builder.getVersion(), - builder.getUuid(), builder.getDescription()); + builder.getUuid(), builder.getDescription()); } } catch (final Exception e) { return new ApexApiResult(ApexApiResult.Result.FAILED, e); @@ -135,10 +128,10 @@ public class ContextAlbumFacade { public ApexApiResult updateContextAlbum(ContextAlbum builder) { try { final AxContextAlbum contextAlbum = - apexModel.getPolicyModel().getAlbums().get(builder.getName(), builder.getVersion()); + 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); + CONCEPT + builder.getName() + ':' + builder.getVersion() + DOES_NOT_EXIST); } if (builder.getScope() != null) { @@ -146,22 +139,21 @@ public class ContextAlbumFacade { } contextAlbum - .setWritable(builder.getWritable() != null && ("true".equalsIgnoreCase(builder.getWritable().trim()) - || "t".equalsIgnoreCase(builder.getWritable().trim()))); + .setWritable(builder.getWritable() != null && ("true".equalsIgnoreCase(builder.getWritable().trim()) + || "t".equalsIgnoreCase(builder.getWritable().trim()))); if (builder.getContextSchemaName() != null) { final AxContextSchema schema = apexModel.getPolicyModel().getSchemas() - .get(builder.getContextSchemaName(), builder.getContextSchemaVersion()); + .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); + 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()); + builder.getDescription()); } catch (final Exception e) { return new ApexApiResult(ApexApiResult.Result.FAILED, e); } @@ -180,13 +172,13 @@ public class ContextAlbumFacade { final Set contextAlbumSet = apexModel.getPolicyModel().getAlbums().getAll(name, version); if (name != null && contextAlbumSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxContextAlbum contextAlbum : contextAlbumSet) { - result.addMessage(new ApexModelStringWriter(false).writeString(contextAlbum, - AxContextAlbum.class, jsonMode)); + result.addMessage( + new ApexModelStringWriter(false).writeString(contextAlbum, AxContextAlbum.class)); } return result; } catch (final Exception e) { @@ -209,20 +201,20 @@ public class ContextAlbumFacade { return new ApexApiResult(); } else { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + key.getId() + DOES_NOT_EXIST); + CONCEPT + key.getId() + DOES_NOT_EXIST); } } final Set contextAlbumSet = apexModel.getPolicyModel().getAlbums().getAll(name, version); if (contextAlbumSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxContextAlbum contextAlbum : contextAlbumSet) { - result.addMessage(new ApexModelStringWriter(false).writeString(contextAlbum, - AxContextAlbum.class, jsonMode)); + result.addMessage( + new ApexModelStringWriter(false).writeString(contextAlbum, AxContextAlbum.class)); apexModel.getPolicyModel().getAlbums().getAlbumsMap().remove(contextAlbum.getKey()); keyInformationFacade.deleteKeyInformation(name, version); } @@ -244,14 +236,14 @@ public class ContextAlbumFacade { final Set contextAlbumSet = apexModel.getPolicyModel().getAlbums().getAll(name, version); if (contextAlbumSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxContextAlbum contextAlbum : contextAlbumSet) { final AxValidationResult validationResult = contextAlbum.validate(new AxValidationResult()); result.addMessage(new ApexModelStringWriter(false).writeString(contextAlbum.getKey(), - AxArtifactKey.class, jsonMode)); + AxArtifactKey.class)); result.addMessage(validationResult.toString()); } return result; diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextSchemaFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextSchemaFacade.java index 00156c5bd..83bca5a01 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextSchemaFacade.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextSchemaFacade.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019,2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,22 +52,17 @@ public class ContextSchemaFacade { // Facade classes for working towards the real Apex model private final KeyInformationFacade keyInformationFacade; - // JSON output on list/delete if set - private final boolean jsonMode; - /** * Constructor to create the context schema facade for the Model API. * * @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 */ - public ContextSchemaFacade(final ApexModel apexModel, final Properties apexProperties, final boolean jsonMode) { + public ContextSchemaFacade(final ApexModel apexModel, final Properties apexProperties) { this.apexModel = apexModel; this.apexProperties = apexProperties; - this.jsonMode = jsonMode; - keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties, jsonMode); + keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties); } /** @@ -82,7 +77,7 @@ public class ContextSchemaFacade { * @return result of the operation */ public ApexApiResult createContextSchema(final String name, final String version, final String schemaFlavour, - final String schemaDefinition, final String uuid, final String description) { + final String schemaDefinition, final String uuid, final String description) { try { Assertions.argumentNotNull(schemaFlavour, "schemaFlavour may not be null"); @@ -99,7 +94,7 @@ public class ContextSchemaFacade { } apexModel.getPolicyModel().getSchemas().getSchemasMap().put(key, - new AxContextSchema(key, schemaFlavour, schemaDefinition)); + new AxContextSchema(key, schemaFlavour, schemaDefinition)); if (apexModel.getPolicyModel().getKeyInformation().getKeyInfoMap().containsKey(key)) { return keyInformationFacade.updateKeyInformation(name, version, uuid, description); @@ -123,12 +118,12 @@ public class ContextSchemaFacade { * @return result of the operation */ public ApexApiResult updateContextSchema(final String name, final String version, final String schemaFlavour, - final String schemaDefinition, final String uuid, final String description) { + final String schemaDefinition, final String uuid, final String description) { try { final AxContextSchema schema = apexModel.getPolicyModel().getSchemas().get(name, version); if (schema == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } if (schemaFlavour != null) { @@ -157,13 +152,13 @@ public class ContextSchemaFacade { final Set schemaSet = apexModel.getPolicyModel().getSchemas().getAll(name, version); if (name != null && schemaSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxContextSchema schema : schemaSet) { - result.addMessage(new ApexModelStringWriter(false).writeString(schema, - AxContextSchema.class, jsonMode)); + result.addMessage( + new ApexModelStringWriter(false).writeString(schema, AxContextSchema.class)); } return result; } catch (final Exception e) { @@ -182,28 +177,28 @@ public class ContextSchemaFacade { try { if (version != null) { final AxArtifactKey key = new AxArtifactKey(name, version); - final AxContextSchema removedSchema = apexModel.getPolicyModel().getSchemas().getSchemasMap() - .remove(key); + final AxContextSchema removedSchema = + apexModel.getPolicyModel().getSchemas().getSchemasMap().remove(key); if (removedSchema != null) { return new ApexApiResult(ApexApiResult.Result.SUCCESS, - new ApexModelStringWriter(false).writeString(removedSchema, - AxContextSchema.class, jsonMode)); + new ApexModelStringWriter(false).writeString(removedSchema, + AxContextSchema.class)); } else { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + key.getId() + DOES_NOT_EXIST); + CONCEPT + key.getId() + DOES_NOT_EXIST); } } final Set schemaSet = apexModel.getPolicyModel().getSchemas().getAll(name, version); if (schemaSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxContextSchema schema : schemaSet) { - result.addMessage(new ApexModelStringWriter(false).writeString(schema, - AxContextSchema.class, jsonMode)); + result.addMessage( + new ApexModelStringWriter(false).writeString(schema, AxContextSchema.class)); apexModel.getPolicyModel().getSchemas().getSchemasMap().remove(schema.getKey()); keyInformationFacade.deleteKeyInformation(name, version); } @@ -225,14 +220,14 @@ public class ContextSchemaFacade { final Set schemaSet = apexModel.getPolicyModel().getSchemas().getAll(name, version); if (schemaSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxContextSchema schema : schemaSet) { final AxValidationResult validationResult = schema.validate(new AxValidationResult()); - result.addMessage(new ApexModelStringWriter(false).writeString(schema.getKey(), - AxArtifactKey.class, jsonMode)); + result.addMessage( + new ApexModelStringWriter(false).writeString(schema.getKey(), AxArtifactKey.class)); result.addMessage(validationResult.toString()); } return result; diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/EventFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/EventFacade.java index f1f939397..336f27b5d 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/EventFacade.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/EventFacade.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019,2022 Nordix Foundation. * Modifications Copyright (C) 2022 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -57,23 +57,17 @@ public class EventFacade { // Facade classes for working towards the real Apex model private final KeyInformationFacade keyInformationFacade; - // JSON output on list/delete if set - private final boolean jsonMode; - /** * Constructor to create an event facade for the Model API. * * @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 */ - public EventFacade(final ApexModel apexModel, final Properties apexProperties, final boolean jsonMode) { + public EventFacade(final ApexModel apexModel, final Properties apexProperties) { this.apexModel = apexModel; this.apexProperties = apexProperties; - this.jsonMode = jsonMode; - keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties, jsonMode); + keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties); } /** @@ -90,8 +84,8 @@ public class EventFacade { * @return result of the operation */ public ApexApiResult createEvent(final String name, final String version, final String nameSpace, - final String source, final String target, final String uuid, final String description, - final String toscaPolicyState) { + final String source, final String target, final String uuid, final String description, + final String toscaPolicyState) { try { final AxArtifactKey key = new AxArtifactKey(); key.setName(name); @@ -140,13 +134,13 @@ public class EventFacade { * @return result of the operation */ public ApexApiResult updateEvent(final String name, final String version, final String nameSpace, - final String source, final String target, final String uuid, final String description, - final String toscaPolicyState) { + final String source, final String target, final String uuid, final String description, + final String toscaPolicyState) { try { final AxEvent event = apexModel.getPolicyModel().getEvents().get(name, version); if (event == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } if (nameSpace != null) { @@ -180,13 +174,12 @@ public class EventFacade { final Set eventSet = apexModel.getPolicyModel().getEvents().getAll(name, version); if (name != null && eventSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxEvent event : eventSet) { - result.addMessage( - new ApexModelStringWriter(false).writeString(event, AxEvent.class, jsonMode)); + result.addMessage(new ApexModelStringWriter(false).writeString(event, AxEvent.class)); } return result; } catch (final Exception e) { @@ -207,24 +200,23 @@ public class EventFacade { final AxArtifactKey key = new AxArtifactKey(name, version); final AxEvent removedEvent = apexModel.getPolicyModel().getEvents().getEventMap().remove(key); if (removedEvent != null) { - return new ApexApiResult(ApexApiResult.Result.SUCCESS, new ApexModelStringWriter(false) - .writeString(removedEvent, AxEvent.class, jsonMode)); + return new ApexApiResult(ApexApiResult.Result.SUCCESS, + new ApexModelStringWriter(false).writeString(removedEvent, AxEvent.class)); } else { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + key.getId() + DOES_NOT_EXIST); + CONCEPT + key.getId() + DOES_NOT_EXIST); } } final Set eventSet = apexModel.getPolicyModel().getEvents().getAll(name, version); if (eventSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxEvent event : eventSet) { - result.addMessage( - new ApexModelStringWriter(false).writeString(event, AxEvent.class, jsonMode)); + result.addMessage(new ApexModelStringWriter(false).writeString(event, AxEvent.class)); apexModel.getPolicyModel().getEvents().getEventMap().remove(event.getKey()); keyInformationFacade.deleteKeyInformation(name, version); } @@ -246,14 +238,14 @@ public class EventFacade { final Set eventSet = apexModel.getPolicyModel().getEvents().getAll(name, version); if (eventSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxEvent event : eventSet) { final AxValidationResult validationResult = event.validate(new AxValidationResult()); - result.addMessage(new ApexModelStringWriter(false).writeString(event.getKey(), - AxArtifactKey.class, jsonMode)); + result.addMessage( + new ApexModelStringWriter(false).writeString(event.getKey(), AxArtifactKey.class)); result.addMessage(validationResult.toString()); } return result; @@ -275,28 +267,28 @@ public class EventFacade { * @return result of the operation */ public ApexApiResult createEventPar(final String name, final String version, final String parName, - final String contextSchemaName, final String contextSchemaVersion, final boolean optional) { + final String contextSchemaName, final String contextSchemaVersion, final boolean optional) { try { Assertions.argumentNotNull(parName, "parName may not be null"); final AxEvent event = apexModel.getPolicyModel().getEvents().get(name, version); if (event == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxReferenceKey refKey = new AxReferenceKey(event.getKey(), parName); if (event.getParameterMap().containsKey(refKey.getLocalName())) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS, - CONCEPT + refKey.getId() + ALREADY_EXISTS); + CONCEPT + refKey.getId() + ALREADY_EXISTS); } final AxContextSchema schema = - apexModel.getPolicyModel().getSchemas().get(contextSchemaName, contextSchemaVersion); + apexModel.getPolicyModel().getSchemas().get(contextSchemaName, contextSchemaVersion); if (schema == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + contextSchemaName + ':' + contextSchemaVersion + DOES_NOT_EXIST); + CONCEPT + contextSchemaName + ':' + contextSchemaVersion + DOES_NOT_EXIST); } event.getParameterMap().put(refKey.getLocalName(), new AxField(refKey, schema.getKey(), optional)); @@ -319,28 +311,27 @@ public class EventFacade { final AxEvent event = apexModel.getPolicyModel().getEvents().get(name, version); if (event == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } if (parName != null) { final AxField eventField = event.getParameterMap().get(parName); if (eventField != null) { return new ApexApiResult(ApexApiResult.Result.SUCCESS, - new ApexModelStringWriter(false).writeString(eventField, AxField.class, jsonMode)); + new ApexModelStringWriter(false).writeString(eventField, AxField.class)); } else { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + ':' + parName + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + ':' + parName + DOES_NOT_EXIST); } } else { if (event.getParameterMap().size() == 0) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "no parameters defined on event " + event.getKey().getId()); + "no parameters defined on event " + event.getKey().getId()); } final ApexApiResult result = new ApexApiResult(); for (final AxField eventPar : event.getParameterMap().values()) { - result.addMessage( - new ApexModelStringWriter(false).writeString(eventPar, AxField.class, jsonMode)); + result.addMessage(new ApexModelStringWriter(false).writeString(eventPar, AxField.class)); } return result; } @@ -362,29 +353,28 @@ public class EventFacade { final AxEvent event = apexModel.getPolicyModel().getEvents().get(name, version); if (event == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); if (parName != null) { if (event.getParameterMap().containsKey(parName)) { result.addMessage(new ApexModelStringWriter(false) - .writeString(event.getParameterMap().get(parName), AxField.class, jsonMode)); + .writeString(event.getParameterMap().get(parName), AxField.class)); event.getParameterMap().remove(parName); return result; } else { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + ':' + parName + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + ':' + parName + DOES_NOT_EXIST); } } else { if (event.getParameterMap().size() == 0) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "no parameters defined on event " + event.getKey().getId()); + "no parameters defined on event " + event.getKey().getId()); } for (final AxField eventPar : event.getParameterMap().values()) { - result.addMessage( - new ApexModelStringWriter(false).writeString(eventPar, AxField.class, jsonMode)); + result.addMessage(new ApexModelStringWriter(false).writeString(eventPar, AxField.class)); } event.getParameterMap().clear(); return result; @@ -393,4 +383,4 @@ public class EventFacade { return new ApexApiResult(ApexApiResult.Result.FAILED, e); } } -} \ No newline at end of file +} diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/KeyInformationFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/KeyInformationFacade.java index b76bfdc06..6875a4c20 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/KeyInformationFacade.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/KeyInformationFacade.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,9 +52,6 @@ public class KeyInformationFacade { // Properties to use for the model private final Properties apexProperties; - // JSON output on list/delete if set - private final boolean jsonMode; - /** * Create key information. * @@ -65,7 +63,7 @@ public class KeyInformationFacade { * @return result of the operation */ public ApexApiResult createKeyInformation(final String name, final String version, final String uuid, - final String description) { + final String description) { try { final AxArtifactKey key = new AxArtifactKey(); key.setName(name); @@ -107,12 +105,12 @@ public class KeyInformationFacade { * @return result of the operation */ public ApexApiResult updateKeyInformation(final String name, final String version, final String uuid, - final String description) { + final String description) { try { final AxKeyInfo keyInfo = apexModel.getPolicyModel().getKeyInformation().get(name, version); if (keyInfo == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ":" + version + DOES_NOT_EXIST); + CONCEPT + name + ":" + version + DOES_NOT_EXIST); } if (description != null) { @@ -145,13 +143,12 @@ public class KeyInformationFacade { final Set keyInfoSet = apexModel.getPolicyModel().getKeyInformation().getAll(name, version); if (name != null && keyInfoSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxKeyInfo keyInfo : keyInfoSet) { - result.addMessage( - new ApexModelStringWriter(false).writeString(keyInfo, AxKeyInfo.class, jsonMode)); + result.addMessage(new ApexModelStringWriter(false).writeString(keyInfo, AxKeyInfo.class)); } return result; } catch (final Exception e) { @@ -172,26 +169,25 @@ public class KeyInformationFacade { if (version != null) { final AxArtifactKey key = new AxArtifactKey(name, version); final AxKeyInfo removedKeyInfo = - apexModel.getPolicyModel().getKeyInformation().getKeyInfoMap().remove(key); + apexModel.getPolicyModel().getKeyInformation().getKeyInfoMap().remove(key); if (removedKeyInfo != null) { - return new ApexApiResult(ApexApiResult.Result.SUCCESS, new ApexModelStringWriter(false) - .writeString(removedKeyInfo, AxKeyInfo.class, jsonMode)); + return new ApexApiResult(ApexApiResult.Result.SUCCESS, + new ApexModelStringWriter(false).writeString(removedKeyInfo, AxKeyInfo.class)); } else { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + key.getId() + DOES_NOT_EXIST); + CONCEPT + key.getId() + DOES_NOT_EXIST); } } final Set keyInfoSet = apexModel.getPolicyModel().getKeyInformation().getAll(name, version); if (keyInfoSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxKeyInfo keyInfo : keyInfoSet) { - result.addMessage( - new ApexModelStringWriter(false).writeString(keyInfo, AxKeyInfo.class, jsonMode)); + result.addMessage(new ApexModelStringWriter(false).writeString(keyInfo, AxKeyInfo.class)); apexModel.getPolicyModel().getKeyInformation().getKeyInfoMap().remove(keyInfo.getKey()); } return result; @@ -213,14 +209,14 @@ public class KeyInformationFacade { final Set keyInfoSet = apexModel.getPolicyModel().getKeyInformation().getAll(name, version); if (keyInfoSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxKeyInfo keyInfo : keyInfoSet) { final AxValidationResult validationResult = keyInfo.validate(new AxValidationResult()); - result.addMessage(new ApexModelStringWriter(false).writeString(keyInfo.getKey(), - AxArtifactKey.class, jsonMode)); + result.addMessage( + new ApexModelStringWriter(false).writeString(keyInfo.getKey(), AxArtifactKey.class)); result.addMessage(validationResult.toString()); } return result; diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelFacade.java index 2adf99050..1030a5bf5 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelFacade.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelFacade.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019,2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,26 +49,20 @@ public class ModelFacade { // Facade classes for working towards the real Apex model private final KeyInformationFacade keyInformationFacade; - // JSON output on list/delete if set - private final boolean jsonMode; - /** * Constructor to create a model facade for the Apex model. * * @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 */ - public ModelFacade(final ApexModel apexModel, final Properties apexProperties, final boolean jsonMode) { + public ModelFacade(final ApexModel apexModel, final Properties apexProperties) { Assertions.argumentNotNull(apexModel, "apexModel may not be null"); Assertions.argumentNotNull(apexProperties, "apexProperties may not be null"); this.apexModel = apexModel; this.apexProperties = apexProperties; - this.jsonMode = jsonMode; - keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties, jsonMode); + keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties); } /** @@ -81,7 +75,7 @@ public class ModelFacade { * @return result of the operation */ public ApexApiResult createModel(final String name, final String version, final String uuid, - final String description) { + final String description) { try { final AxArtifactKey key = new AxArtifactKey(); key.setName(name); @@ -98,7 +92,7 @@ public class ModelFacade { if (!apexModel.getPolicyModel().getKey().equals(AxArtifactKey.getNullKey())) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS, - CONCEPT + apexModel.getPolicyModel().getKey().getId() + ALREADY_CREATED); + CONCEPT + apexModel.getPolicyModel().getKey().getId() + ALREADY_CREATED); } apexModel.setPolicyModel(new AxPolicyModel(key)); @@ -107,6 +101,7 @@ public class ModelFacade { result = keyInformationFacade.createKeyInformation(name, version, uuid, description); if (result.getResult().equals(ApexApiResult.Result.SUCCESS)) { + apexModel.getPolicyModel().buildReferences(); apexModel.getPolicyModel().getKeyInformation().generateKeyInfo(apexModel.getPolicyModel()); } return result; @@ -125,7 +120,7 @@ public class ModelFacade { * @return result of the operation */ public ApexApiResult updateModel(final String name, final String version, final String uuid, - final String description) { + final String description) { try { final AxArtifactKey key = new AxArtifactKey(); key.setName(name); @@ -137,13 +132,13 @@ public class ModelFacade { key.setVersion(defaultVersion); } else { return new ApexApiResult(ApexApiResult.Result.FAILED, - CONCEPT + apexModel.getPolicyModel().getKey().getId() + NO_VERSION_SPECIFIED); + CONCEPT + apexModel.getPolicyModel().getKey().getId() + NO_VERSION_SPECIFIED); } } if (apexModel.getPolicyModel().getKey().equals(AxArtifactKey.getNullKey())) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + apexModel.getPolicyModel().getKey().getId() + DOES_NOT_EXIST); + CONCEPT + apexModel.getPolicyModel().getKey().getId() + DOES_NOT_EXIST); } return keyInformationFacade.updateKeyInformation(name, version, uuid, description); @@ -161,8 +156,8 @@ public class ModelFacade { try { final ApexApiResult result = new ApexApiResult(); final AxArtifactKey modelkey = apexModel.getPolicyModel().getKey(); - result.addMessage(new ApexModelStringWriter(false).writeString(modelkey, AxArtifactKey.class, - jsonMode)); + result + .addMessage(new ApexModelStringWriter(false).writeString(modelkey, AxArtifactKey.class)); return result; } catch (final Exception e) { return new ApexApiResult(ApexApiResult.Result.FAILED, e); @@ -178,7 +173,7 @@ public class ModelFacade { try { final ApexApiResult result = new ApexApiResult(); result.addMessage(new ApexModelStringWriter(false).writeString(apexModel.getPolicyModel(), - AxPolicyModel.class, jsonMode)); + AxPolicyModel.class)); return result; } catch (final Exception e) { return new ApexApiResult(ApexApiResult.Result.FAILED, e); diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java index 9d03ba1e0..fecf92e1f 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java @@ -70,22 +70,17 @@ public class ModelHandlerFacade { // Apex model we're working towards private final ApexModel apexModel; - // JSON output on list/delete if set - private final boolean jsonMode; - /** * This Constructor creates a model handling facade for the given {@link ApexModel}. * * @param apexModel the apex model to manipulate * @param apexProperties properties for the model - * @param jsonMode set to true to return JSON strings in list and delete operations, otherwise set to false */ - public ModelHandlerFacade(final ApexModel apexModel, final Properties apexProperties, final boolean jsonMode) { + public ModelHandlerFacade(final ApexModel apexModel, final Properties apexProperties) { Assertions.argumentNotNull(apexModel, "apexModel may not be null"); Assertions.argumentNotNull(apexProperties, "apexProperties may not be null"); this.apexModel = apexModel; - this.jsonMode = jsonMode; } /** @@ -134,20 +129,15 @@ public class ModelHandlerFacade { * Save an Apex model to a file. * * @param fileName the file name - * @param xmlFlag if true, save the file in XML format, otherwise save the file in the default JSON format * @return the result of the operation */ - public ApexApiResult saveToFile(final String fileName, final boolean xmlFlag) { + public ApexApiResult saveToFile(final String fileName) { Assertions.argumentNotNull(fileName, FILE_NAME_MAY_NOT_BE_NULL); ApexModelFileWriter apexModelFileWriter = new ApexModelFileWriter<>(false); try { - if (xmlFlag) { - apexModelFileWriter.apexModelWriteXmlFile(apexModel.getPolicyModel(), AxPolicyModel.class, fileName); - } else { - apexModelFileWriter.apexModelWriteJsonFile(apexModel.getPolicyModel(), AxPolicyModel.class, fileName); - } + apexModelFileWriter.apexModelWriteJsonFile(apexModel.getPolicyModel(), AxPolicyModel.class, fileName); return new ApexApiResult(); } catch (ApexException e) { return new ApexApiResult(ApexApiResult.Result.FAILED, e); @@ -180,7 +170,7 @@ public class ModelHandlerFacade { try { ApexModelReader apexModelReader = new ApexModelReader<>(AxPolicyModel.class); - apexModelReader.setValidateFlag(false); + apexModelReader.setValidate(false); AxPolicyModel newPolicyModel = apexModelReader.read(apexModelUrl.openStream()); apexModel.setPolicyModel(newPolicyModel != null ? newPolicyModel : new AxPolicyModel()); return new ApexApiResult(); @@ -194,10 +184,9 @@ public class ModelHandlerFacade { * Write an APEX model to a location identified by a URL. * * @param urlString the URL to read the model from - * @param xmlFlag if true, save the file in XML format, otherwise save the file in the default JSON format * @return the result of the operation */ - public ApexApiResult writeToUrl(final String urlString, final boolean xmlFlag) { + public ApexApiResult writeToUrl(final String urlString) { Assertions.argumentNotNull(urlString, "urlString may not be null"); URL apexModelUrl; @@ -212,8 +201,7 @@ public class ModelHandlerFacade { try { ApexModelWriter apexModelWriter = new ApexModelWriter<>(AxPolicyModel.class); - apexModelWriter.setValidateFlag(false); - apexModelWriter.setJsonOutput(!xmlFlag); + apexModelWriter.setValidate(false); // Open the URL for output and write the model URLConnection urlConnection = apexModelUrl.openConnection(); @@ -250,7 +238,7 @@ public class ModelHandlerFacade { result.setResult(ApexApiResult.Result.FAILED); } result.addMessage(new ApexModelStringWriter(false) - .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class, jsonMode)); + .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class)); result.addMessage(validationResult.toString()); return result; } catch (Exception e) { @@ -277,7 +265,7 @@ public class ModelHandlerFacade { PolicyModelComparer policyModelComparer = new PolicyModelComparer(apexModel.getPolicyModel(), otherPolicyModel); result.addMessage(new ApexModelStringWriter(false) - .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class, jsonMode)); + .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class)); result.addMessage(policyModelComparer.toString()); return result; @@ -306,7 +294,7 @@ public class ModelHandlerFacade { PolicyModelComparer policyModelComparer = new PolicyModelComparer(apexModel.getPolicyModel(), otherPolicyModel); result.addMessage(new ApexModelStringWriter(false) - .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class, jsonMode)); + .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class)); result.addMessage(policyModelComparer.toString()); return result; @@ -470,7 +458,7 @@ public class ModelHandlerFacade { try { ApexModelReader apexModelReader = new ApexModelReader<>(AxPolicyModel.class); - apexModelReader.setValidateFlag(false); + apexModelReader.setValidate(false); readModel = apexModelReader.read(apexModelUrl.openStream()); result.setResult(ApexApiResult.Result.SUCCESS); return readModel; @@ -497,7 +485,7 @@ public class ModelHandlerFacade { try { ApexModelReader apexModelReader = new ApexModelReader<>(AxPolicyModel.class); - apexModelReader.setValidateFlag(false); + apexModelReader.setValidate(false); readModel = apexModelReader.read(modelStringStream); result.setResult(ApexApiResult.Result.SUCCESS); return readModel; diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java index 4d0999ab1..408f0913f 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019,2022 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -72,23 +72,17 @@ public class PolicyFacade { // Facade classes for working towards the real Apex model private final KeyInformationFacade keyInformationFacade; - // JSON output on list/delete if set - private final boolean jsonMode; - /** * Constructor that creates a policy facade for the Apex Model API. * * @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 */ - public PolicyFacade(final ApexModel apexModel, final Properties apexProperties, final boolean jsonMode) { + public PolicyFacade(final ApexModel apexModel, final Properties apexProperties) { this.apexModel = apexModel; this.apexProperties = apexProperties; - this.jsonMode = jsonMode; - keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties, jsonMode); + keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties); } /** @@ -103,7 +97,7 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult createPolicy(final String name, final String version, final String template, - final String firstState, final String uuid, final String description) { + final String firstState, final String uuid, final String description) { try { final AxArtifactKey key = new AxArtifactKey(); key.setName(name); @@ -150,12 +144,12 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult updatePolicy(final String name, final String version, final String template, - final String firstState, final String uuid, final String description) { + final String firstState, final String uuid, final String description) { try { final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } if (template != null) { @@ -183,13 +177,12 @@ public class PolicyFacade { final Set policySet = apexModel.getPolicyModel().getPolicies().getAll(name, version); if (name != null && policySet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxPolicy policy : policySet) { - result.addMessage( - new ApexModelStringWriter(false).writeString(policy, AxPolicy.class, jsonMode)); + result.addMessage(new ApexModelStringWriter(false).writeString(policy, AxPolicy.class)); } return result; } catch (final Exception e) { @@ -210,24 +203,23 @@ public class PolicyFacade { final AxArtifactKey key = new AxArtifactKey(name, version); final AxPolicy removedPolicy = apexModel.getPolicyModel().getPolicies().getPolicyMap().remove(key); if (removedPolicy != null) { - return new ApexApiResult(ApexApiResult.Result.SUCCESS, new ApexModelStringWriter(false) - .writeString(removedPolicy, AxPolicy.class, jsonMode)); + return new ApexApiResult(ApexApiResult.Result.SUCCESS, + new ApexModelStringWriter(false).writeString(removedPolicy, AxPolicy.class)); } else { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + key.getId() + DOES_NOT_EXIST); + CONCEPT + key.getId() + DOES_NOT_EXIST); } } final Set policySet = apexModel.getPolicyModel().getPolicies().getAll(name, version); if (policySet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxPolicy policy : policySet) { - result.addMessage( - new ApexModelStringWriter(false).writeString(policy, AxPolicy.class, jsonMode)); + result.addMessage(new ApexModelStringWriter(false).writeString(policy, AxPolicy.class)); apexModel.getPolicyModel().getPolicies().getPolicyMap().remove(policy.getKey()); keyInformationFacade.deleteKeyInformation(name, version); } @@ -249,14 +241,14 @@ public class PolicyFacade { final Set policySet = apexModel.getPolicyModel().getPolicies().getAll(name, version); if (policySet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxPolicy policy : policySet) { final AxValidationResult validationResult = policy.validate(new AxValidationResult()); - result.addMessage(new ApexModelStringWriter(false).writeString(policy.getKey(), - AxArtifactKey.class, jsonMode)); + result.addMessage( + new ApexModelStringWriter(false).writeString(policy.getKey(), AxArtifactKey.class)); result.addMessage(validationResult.toString()); } return result; @@ -279,34 +271,34 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult createPolicyState(final String name, final String version, final String stateName, - final String triggerName, final String triggerVersion, final String defaultTaskName, - final String defaltTaskVersion) { + final String triggerName, final String triggerVersion, final String defaultTaskName, + final String defaltTaskVersion) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxReferenceKey refKey = new AxReferenceKey(policy.getKey(), stateName); if (policy.getStateMap().containsKey(refKey.getLocalName())) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS, - CONCEPT + refKey.getId() + ALREADY_EXISTS); + CONCEPT + refKey.getId() + ALREADY_EXISTS); } final AxEvent triggerEvent = apexModel.getPolicyModel().getEvents().get(triggerName, triggerVersion); if (triggerEvent == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + triggerName + ':' + triggerVersion + DOES_NOT_EXIST); + CONCEPT + triggerName + ':' + triggerVersion + DOES_NOT_EXIST); } final AxTask defaultTask = apexModel.getPolicyModel().getTasks().get(defaultTaskName, defaltTaskVersion); if (defaultTask == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + defaultTaskName + ':' + defaltTaskVersion + DOES_NOT_EXIST); + CONCEPT + defaultTaskName + ':' + defaltTaskVersion + DOES_NOT_EXIST); } final AxState state = new AxState(refKey); @@ -334,38 +326,38 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult updatePolicyState(final String name, final String version, final String stateName, - final String triggerName, final String triggerVersion, final String defaultTaskName, - final String defaltTaskVersion) { + final String triggerName, final String triggerVersion, final String defaultTaskName, + final String defaltTaskVersion) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(stateName); if (state == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); + CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); } if (triggerName != null) { final AxEvent triggerEvent = apexModel.getPolicyModel().getEvents().get(triggerName, triggerVersion); if (triggerEvent == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + triggerName + ':' + triggerVersion + DOES_NOT_EXIST); + CONCEPT + triggerName + ':' + triggerVersion + DOES_NOT_EXIST); } state.setTrigger(triggerEvent.getKey()); } if (defaultTaskName != null) { final AxTask defaultTask = - apexModel.getPolicyModel().getTasks().get(defaultTaskName, defaltTaskVersion); + apexModel.getPolicyModel().getTasks().get(defaultTaskName, defaltTaskVersion); if (defaultTask == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + defaultTaskName + ':' + defaltTaskVersion + DOES_NOT_EXIST); + CONCEPT + defaultTaskName + ':' + defaltTaskVersion + DOES_NOT_EXIST); } state.setDefaultTask(defaultTask.getKey()); } @@ -389,27 +381,26 @@ public class PolicyFacade { final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } if (stateName != null) { final AxState state = policy.getStateMap().get(stateName); if (state != null) { return new ApexApiResult(ApexApiResult.Result.SUCCESS, - new ApexModelStringWriter(false).writeString(state, AxState.class, jsonMode)); + new ApexModelStringWriter(false).writeString(state, AxState.class)); } else { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + ':' + state + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + ':' + state + DOES_NOT_EXIST); } } else { if (policy.getStateMap().size() == 0) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "no states defined on policy " + policy.getKey().getId()); + "no states defined on policy " + policy.getKey().getId()); } final ApexApiResult result = new ApexApiResult(); for (final AxState state : policy.getStateMap().values()) { - result.addMessage( - new ApexModelStringWriter(false).writeString(state, AxState.class, jsonMode)); + result.addMessage(new ApexModelStringWriter(false).writeString(state, AxState.class)); } return result; } @@ -431,28 +422,27 @@ public class PolicyFacade { final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); if (stateName != null) { if (policy.getStateMap().containsKey(stateName)) { result.addMessage(new ApexModelStringWriter(false) - .writeString(policy.getStateMap().get(stateName), AxState.class, jsonMode)); + .writeString(policy.getStateMap().get(stateName), AxState.class)); policy.getStateMap().remove(stateName); return result; } else { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + ':' + stateName + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + ':' + stateName + DOES_NOT_EXIST); } } else { if (policy.getStateMap().size() == 0) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "no states defined on policy " + policy.getKey().getId()); + "no states defined on policy " + policy.getKey().getId()); } for (final AxState state : policy.getStateMap().values()) { - result.addMessage( - new ApexModelStringWriter(false).writeString(state, AxState.class, jsonMode)); + result.addMessage(new ApexModelStringWriter(false).writeString(state, AxState.class)); } policy.getStateMap().clear(); return result; @@ -474,20 +464,20 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult createPolicyStateTaskSelectionLogic(final String name, final String version, - final String stateName, final String logicFlavour, final String logic) { + final String stateName, final String logicFlavour, final String logic) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(stateName); if (state == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); + CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); } // There is only one logic item associated with a state so we use a hard coded logic @@ -496,7 +486,7 @@ public class PolicyFacade { if (!state.getTaskSelectionLogic().getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS, - CONCEPT + refKey.getId() + ALREADY_EXISTS); + CONCEPT + refKey.getId() + ALREADY_EXISTS); } state.setTaskSelectionLogic(new AxTaskSelectionLogic(refKey, logicFlavour, logic)); @@ -517,25 +507,25 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult updatePolicyStateTaskSelectionLogic(final String name, final String version, - final String stateName, final String logicFlavour, final String logic) { + final String stateName, final String logicFlavour, final String logic) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(stateName); if (state == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); + CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); } if (state.getTaskSelectionLogic().getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + state.getTaskSelectionLogic().getKey().getId() + DOES_NOT_EXIST); + CONCEPT + state.getTaskSelectionLogic().getKey().getId() + DOES_NOT_EXIST); } final AxTaskSelectionLogic taskSelectionLogic = state.getTaskSelectionLogic(); @@ -561,25 +551,25 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult listPolicyStateTaskSelectionLogic(final String name, final String version, - final String stateName) { + final String stateName) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(stateName); if (state == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); + CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); } return new ApexApiResult(ApexApiResult.Result.SUCCESS, - new ApexModelStringWriter(false).writeString(state.getTaskSelectionLogic(), - AxTaskSelectionLogic.class, jsonMode)); + new ApexModelStringWriter(false).writeString(state.getTaskSelectionLogic(), + AxTaskSelectionLogic.class)); } catch (final Exception e) { return new ApexApiResult(ApexApiResult.Result.FAILED, e); } @@ -594,30 +584,30 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult deletePolicyStateTaskSelectionLogic(final String name, final String version, - final String stateName) { + final String stateName) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(stateName); if (state == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); + CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); } if (state.getTaskSelectionLogic().getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + state.getTaskSelectionLogic().getKey().getId() + DOES_NOT_EXIST); + CONCEPT + state.getTaskSelectionLogic().getKey().getId() + DOES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); result.addMessage(new ApexModelStringWriter(false) - .writeString(state.getTaskSelectionLogic(), AxTaskSelectionLogic.class, jsonMode)); + .writeString(state.getTaskSelectionLogic(), AxTaskSelectionLogic.class)); state.setTaskSelectionLogic(new AxTaskSelectionLogic()); return result; } catch (final Exception e) { @@ -640,7 +630,7 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult createPolicyStateOutput(final String name, final String version, final String stateName, - final String outputName, final String eventName, final String eventVersion, final String nextState) { + final String outputName, final String eventName, final String eventVersion, final String nextState) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); Assertions.argumentNotNull(outputName, "outputName may not be null"); @@ -648,13 +638,13 @@ public class PolicyFacade { final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "Policy concept " + name + ':' + version + DOES_NOT_EXIST); + "Policy concept " + name + ':' + version + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(stateName); if (state == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "State concept " + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); + "State concept " + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); } final AxReferenceKey refKey = new AxReferenceKey(state.getKey(), outputName); @@ -668,20 +658,20 @@ public class PolicyFacade { final AxEvent event = apexModel.getPolicyModel().getEvents().get(eventName, eventVersion); if (event == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "Event concept " + eventName + ':' + eventVersion + DOES_NOT_EXIST); + "Event concept " + eventName + ':' + eventVersion + DOES_NOT_EXIST); } AxReferenceKey nextStateKey = AxReferenceKey.getNullKey(); if (nextState != null && !(AxReferenceKey.getNullKey().getLocalName().equals(nextState))) { if (state.getKey().getLocalName().equals(nextState)) { return new ApexApiResult(ApexApiResult.Result.FAILED, - "next state " + nextState + " of a state cannot be the state itself"); + "next state " + nextState + " of a state cannot be the state itself"); } nextStateKey = new AxReferenceKey(state.getKey().getParentArtifactKey(), nextState); if (!policy.getStateMap().containsKey(nextState)) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "Next state concept " + nextStateKey.getId() + DOES_NOT_EXIST); + "Next state concept " + nextStateKey.getId() + DOES_NOT_EXIST); } } @@ -724,43 +714,42 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult listPolicyStateOutput(final String name, final String version, final String stateName, - final String outputName) { + final String outputName) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(stateName); if (state == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); + CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); } if (outputName != null) { final AxStateOutput stateOutput = state.getStateOutputs().get(outputName); if (stateOutput != null) { return new ApexApiResult(ApexApiResult.Result.SUCCESS, - new ApexModelStringWriter(false).writeString(stateOutput, - AxStateOutput.class, jsonMode)); + new ApexModelStringWriter(false).writeString(stateOutput, AxStateOutput.class)); } else { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + state.getKey().getId() + ':' + outputName + DOES_NOT_EXIST); + CONCEPT + state.getKey().getId() + ':' + outputName + DOES_NOT_EXIST); } } else { if (state.getStateOutputs().size() == 0) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "no state output concepts exist for state " + state.getKey().getId()); + "no state output concepts exist for state " + state.getKey().getId()); } final ApexApiResult result = new ApexApiResult(); for (final AxStateOutput stateOutput : state.getStateOutputs().values()) { - result.addMessage(new ApexModelStringWriter(false).writeString(stateOutput, - AxStateOutput.class, jsonMode)); + result.addMessage( + new ApexModelStringWriter(false).writeString(stateOutput, AxStateOutput.class)); } return result; } @@ -779,45 +768,44 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult deletePolicyStateOutput(final String name, final String version, final String stateName, - final String outputName) { + final String outputName) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(stateName); if (state == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); + CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); } if (outputName != null) { final AxStateOutput stateOutput = state.getStateOutputs().get(outputName); if (stateOutput != null) { final ApexApiResult result = new ApexApiResult(ApexApiResult.Result.SUCCESS, - new ApexModelStringWriter(false).writeString(stateOutput, - AxStateOutput.class, jsonMode)); + new ApexModelStringWriter(false).writeString(stateOutput, AxStateOutput.class)); state.getStateOutputs().remove(outputName); return result; } else { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + state.getKey().getId() + ':' + outputName + DOES_NOT_EXIST); + CONCEPT + state.getKey().getId() + ':' + outputName + DOES_NOT_EXIST); } } else { if (state.getStateOutputs().size() == 0) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "no state output concepts exist for state " + state.getKey().getId()); + "no state output concepts exist for state " + state.getKey().getId()); } final ApexApiResult result = new ApexApiResult(); for (final Entry stateOutputEntry : state.getStateOutputs().entrySet()) { result.addMessage(new ApexModelStringWriter(false) - .writeString(stateOutputEntry.getValue(), AxStateOutput.class, jsonMode)); + .writeString(stateOutputEntry.getValue(), AxStateOutput.class)); } state.getStateOutputs().clear(); return result; @@ -840,7 +828,7 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult createPolicyStateFinalizerLogic(final String name, final String version, - final String stateName, final String finalizerLogicName, final String logicFlavour, final String logic) { + final String stateName, final String finalizerLogicName, final String logicFlavour, final String logic) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); Assertions.argumentNotNull(finalizerLogicName, "finalizerlogicName may not be null"); @@ -848,24 +836,24 @@ public class PolicyFacade { final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(stateName); if (state == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); + CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); } final AxReferenceKey refKey = new AxReferenceKey(state.getKey(), finalizerLogicName); if (state.getStateFinalizerLogicMap().containsKey(refKey.getLocalName())) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS, - CONCEPT + refKey.getId() + ALREADY_EXISTS); + CONCEPT + refKey.getId() + ALREADY_EXISTS); } state.getStateFinalizerLogicMap().put(finalizerLogicName, - new AxStateFinalizerLogic(refKey, logicFlavour, logic)); + new AxStateFinalizerLogic(refKey, logicFlavour, logic)); return new ApexApiResult(); } catch (final Exception e) { return new ApexApiResult(ApexApiResult.Result.FAILED, e); @@ -885,7 +873,7 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult updatePolicyStateFinalizerLogic(final String name, final String version, - final String stateName, final String finalizerLogicName, final String logicFlavour, final String logic) { + final String stateName, final String finalizerLogicName, final String logicFlavour, final String logic) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); Assertions.argumentNotNull(finalizerLogicName, "finalizerLogicName may not be null"); @@ -893,21 +881,21 @@ public class PolicyFacade { final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(stateName); if (state == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); + CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); } final AxReferenceKey refKey = new AxReferenceKey(state.getKey(), finalizerLogicName); final AxStateFinalizerLogic stateFinalizerLogic = - state.getStateFinalizerLogicMap().get(refKey.getKey().getLocalName()); + state.getStateFinalizerLogicMap().get(refKey.getKey().getLocalName()); if (stateFinalizerLogic == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - STATE_FINALIZER_LOGIC + refKey.getId() + DOES_NOT_EXIST); + STATE_FINALIZER_LOGIC + refKey.getId() + DOES_NOT_EXIST); } if (logicFlavour != null) { @@ -933,43 +921,43 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult listPolicyStateFinalizerLogic(final String name, final String version, final String stateName, - final String finalizerLogicName) { + final String finalizerLogicName) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(stateName); if (state == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); + CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); } if (finalizerLogicName != null) { final AxReferenceKey refKey = new AxReferenceKey(state.getKey(), finalizerLogicName); final AxStateFinalizerLogic stateFinalizerLogic = - state.getStateFinalizerLogicMap().get(refKey.getKey().getLocalName()); + state.getStateFinalizerLogicMap().get(refKey.getKey().getLocalName()); if (stateFinalizerLogic == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - STATE_FINALIZER_LOGIC + refKey.getId() + DOES_NOT_EXIST); + STATE_FINALIZER_LOGIC + refKey.getId() + DOES_NOT_EXIST); } return new ApexApiResult(ApexApiResult.Result.SUCCESS, - new ApexModelStringWriter(false).writeString(stateFinalizerLogic, - AxStateFinalizerLogic.class, jsonMode)); + new ApexModelStringWriter(false).writeString(stateFinalizerLogic, + AxStateFinalizerLogic.class)); } else { if (state.getStateFinalizerLogicMap().size() == 0) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "no state finalizer logic defined on state " + state.getKey().getId()); + "no state finalizer logic defined on state " + state.getKey().getId()); } final ApexApiResult result = new ApexApiResult(); for (final AxStateFinalizerLogic stateFinalizerLogic : state.getStateFinalizerLogicMap().values()) { result.addMessage(new ApexModelStringWriter(false) - .writeString(stateFinalizerLogic, AxStateFinalizerLogic.class, jsonMode)); + .writeString(stateFinalizerLogic, AxStateFinalizerLogic.class)); } return result; } @@ -988,46 +976,46 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult deletePolicyStateFinalizerLogic(final String name, final String version, - final String stateName, final String finalizerLogicName) { + final String stateName, final String finalizerLogicName) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(stateName); if (state == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); + CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); } if (finalizerLogicName != null) { final AxReferenceKey refKey = new AxReferenceKey(state.getKey(), finalizerLogicName); final AxStateFinalizerLogic stateFinalizerLogic = - state.getStateFinalizerLogicMap().get(refKey.getKey().getLocalName()); + state.getStateFinalizerLogicMap().get(refKey.getKey().getLocalName()); if (stateFinalizerLogic == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - STATE_FINALIZER_LOGIC + refKey.getId() + DOES_NOT_EXIST); + STATE_FINALIZER_LOGIC + refKey.getId() + DOES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); result.addMessage(new ApexModelStringWriter(false) - .writeString(stateFinalizerLogic, AxStateFinalizerLogic.class, jsonMode)); + .writeString(stateFinalizerLogic, AxStateFinalizerLogic.class)); state.getStateFinalizerLogicMap().remove(refKey.getLocalName()); return result; } else { if (state.getStateFinalizerLogicMap().size() == 0) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "no state finalizer logic defined on state " + state.getKey().getId()); + "no state finalizer logic defined on state " + state.getKey().getId()); } final ApexApiResult result = new ApexApiResult(); for (final AxStateFinalizerLogic stateFinalizerLogic : state.getStateFinalizerLogicMap().values()) { result.addMessage(new ApexModelStringWriter(false) - .writeString(stateFinalizerLogic, AxStateFinalizerLogic.class, jsonMode)); + .writeString(stateFinalizerLogic, AxStateFinalizerLogic.class)); } state.getStateFinalizerLogicMap().clear(); return result; @@ -1049,38 +1037,28 @@ public class PolicyFacade { Assertions.argumentNotNull(builder.getOutputName(), "outputName may not be null"); final AxPolicy policy = - apexModel.getPolicyModel().getPolicies().get(builder.getName(), builder.getVersion()); + apexModel.getPolicyModel().getPolicies().get(builder.getName(), builder.getVersion()); if (policy == null) { - return new ApexApiResult( - ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + builder.getName() + ':' + builder.getVersion() + DOES_NOT_EXIST); + return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, + CONCEPT + builder.getName() + ':' + builder.getVersion() + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(builder.getStateName()); if (state == null) { - return new ApexApiResult( - ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + builder.getStateName() + DOES_NOT_EXIST); + return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, + CONCEPT + policy.getKey().getId() + ':' + builder.getStateName() + DOES_NOT_EXIST); } final AxTask task = - apexModel - .getPolicyModel() - .getTasks() - .get(builder.getTaskName(), builder.getTaskVersion()); + apexModel.getPolicyModel().getTasks().get(builder.getTaskName(), builder.getTaskVersion()); if (task == null) { - return new ApexApiResult( - ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + builder.getTaskName() + ':' + builder.getTaskVersion() + DOES_NOT_EXIST); + return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, + CONCEPT + builder.getTaskName() + ':' + builder.getTaskVersion() + DOES_NOT_EXIST); } if (state.getTaskReferences().containsKey(task.getKey())) { - return new ApexApiResult( - ApexApiResult.Result.CONCEPT_EXISTS, - "task " - + task.getKey().getId() - + " already has reference with output " - + state.getTaskReferences().get(task.getKey())); + return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS, "task " + task.getKey().getId() + + " already has reference with output " + state.getTaskReferences().get(task.getKey())); } AxReferenceKey refKey; @@ -1091,26 +1069,22 @@ public class PolicyFacade { } // The reference to the output we're using here - final AxReferenceKey outputRefKey = - new AxReferenceKey(state.getKey(), builder.getOutputName()); + final AxReferenceKey outputRefKey = new AxReferenceKey(state.getKey(), builder.getOutputName()); - final AxStateTaskOutputType stateTaskOutputType = - AxStateTaskOutputType.valueOf(builder.getOutputType()); + final AxStateTaskOutputType stateTaskOutputType = AxStateTaskOutputType.valueOf(builder.getOutputType()); if (stateTaskOutputType.equals(AxStateTaskOutputType.DIRECT)) { if (!state.getStateOutputs().containsKey(outputRefKey.getLocalName())) { - return new ApexApiResult( - ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "state output concept " + outputRefKey.getId() + DOES_NOT_EXIST); + return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, + "state output concept " + outputRefKey.getId() + DOES_NOT_EXIST); } } else if (stateTaskOutputType.equals(AxStateTaskOutputType.LOGIC)) { if (!state.getStateFinalizerLogicMap().containsKey(outputRefKey.getLocalName())) { - return new ApexApiResult( - ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "state finalizer logic concept " + outputRefKey.getId() + DOES_NOT_EXIST); + return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, + "state finalizer logic concept " + outputRefKey.getId() + DOES_NOT_EXIST); } } else { - return new ApexApiResult( - ApexApiResult.Result.FAILED, "output type " + builder.getOutputType() + " invalid"); + return new ApexApiResult(ApexApiResult.Result.FAILED, + "output type " + builder.getOutputType() + " invalid"); } String outputRefName = outputRefKey.getLocalName(); @@ -1138,14 +1112,11 @@ public class PolicyFacade { Map outputEvents = new TreeMap<>(); if (state.getNextStateSet().isEmpty() || state.getNextStateSet().contains(AxReferenceKey.getNullKey().getLocalName())) { - state.getStateOutputs().get(outputRefName).getOutgoingEventSet() - .forEach(outgoingEventKey -> outputEvents.put(outgoingEventKey.getName(), - apexModel.getPolicyModel().getEvents().get(outgoingEventKey))); + state.getStateOutputs().get(outputRefName).getOutgoingEventSet().forEach(outgoingEventKey -> outputEvents + .put(outgoingEventKey.getName(), apexModel.getPolicyModel().getEvents().get(outgoingEventKey))); } else { - AxArtifactKey outgoingEventKey = - state.getStateOutputs().get(outputRefName).getOutgoingEvent(); - outputEvents.put(outgoingEventKey.getName(), - apexModel.getPolicyModel().getEvents().get(outgoingEventKey)); + AxArtifactKey outgoingEventKey = state.getStateOutputs().get(outputRefName).getOutgoingEvent(); + outputEvents.put(outgoingEventKey.getName(), apexModel.getPolicyModel().getEvents().get(outgoingEventKey)); } task.setOutputEvents(outputEvents); } @@ -1161,20 +1132,20 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult listPolicyStateTaskRef(final String name, final String version, final String stateName, - final String taskName, final String taskVersion) { + final String taskName, final String taskVersion) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(stateName); if (state == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); + CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); @@ -1184,21 +1155,21 @@ public class PolicyFacade { final AxArtifactKey key = taskReferenceEntry.getKey(); final AxStateTaskReference value = taskReferenceEntry.getValue(); if ((taskName != null && !key.getName().equals(taskName)) - || (taskVersion != null && !key.getVersion().equals(taskVersion))) { + || (taskVersion != null && !key.getVersion().equals(taskVersion))) { continue; } found = true; - result.addMessage(new ApexModelStringWriter(false).writeString(key, AxArtifactKey.class, - jsonMode)); + result + .addMessage(new ApexModelStringWriter(false).writeString(key, AxArtifactKey.class)); result.addMessage(new ApexModelStringWriter(false).writeString(value, - AxStateTaskReference.class, jsonMode)); + AxStateTaskReference.class)); } if (found) { return result; } else { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "no task references found for state " + state.getKey().getId()); + "no task references found for state " + state.getKey().getId()); } } catch (final Exception e) { return new ApexApiResult(ApexApiResult.Result.FAILED, e); @@ -1216,41 +1187,41 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult deletePolicyStateTaskRef(final String name, final String version, final String stateName, - final String taskName, final String taskVersion) { + final String taskName, final String taskVersion) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(stateName); if (state == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); + CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); } final Set deleteSet = new TreeSet<>(); for (final AxArtifactKey taskReferenceKey : state.getTaskReferences().keySet()) { if ((taskName != null && !taskReferenceKey.getName().equals(taskName)) - || (taskVersion != null && !taskReferenceKey.getVersion().equals(taskVersion))) { + || (taskVersion != null && !taskReferenceKey.getVersion().equals(taskVersion))) { continue; } deleteSet.add(taskReferenceKey); } if (deleteSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + taskName + ':' + taskVersion + DOES_NOT_EXIST_ON_STATE + state.getKey().getId()); + CONCEPT + taskName + ':' + taskVersion + DOES_NOT_EXIST_ON_STATE + state.getKey().getId()); } final ApexApiResult result = new ApexApiResult(); for (final AxArtifactKey keyToDelete : deleteSet) { state.getTaskReferences().remove(keyToDelete); - result.addMessage(new ApexModelStringWriter(false).writeString(keyToDelete, - AxArtifactKey.class, jsonMode)); + result.addMessage( + new ApexModelStringWriter(false).writeString(keyToDelete, AxArtifactKey.class)); } return result; } catch (final Exception e) { @@ -1270,32 +1241,32 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult createPolicyStateContextRef(final String name, final String version, final String stateName, - final String contextAlbumName, final String contextAlbumVersion) { + final String contextAlbumName, final String contextAlbumVersion) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(stateName); if (state == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); + CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); } final AxContextAlbum contextAlbum = - apexModel.getPolicyModel().getAlbums().get(contextAlbumName, contextAlbumVersion); + apexModel.getPolicyModel().getAlbums().get(contextAlbumName, contextAlbumVersion); if (contextAlbum == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + contextAlbumName + ':' + contextAlbumVersion + DOES_NOT_EXIST); + CONCEPT + contextAlbumName + ':' + contextAlbumVersion + DOES_NOT_EXIST); } if (state.getContextAlbumReferences().contains(contextAlbum.getKey())) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS, "concept album reference for concept " - + contextAlbum.getKey().getId() + " already exists in state"); + + contextAlbum.getKey().getId() + " already exists in state"); } state.getContextAlbumReferences().add(contextAlbum.getKey()); @@ -1318,36 +1289,36 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult listPolicyStateContextRef(final String name, final String version, final String stateName, - final String contextAlbumName, final String contextAlbumVersion) { + final String contextAlbumName, final String contextAlbumVersion) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(stateName); if (state == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); + CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); boolean found = false; for (final AxArtifactKey albumKey : state.getContextAlbumReferences()) { if ((contextAlbumName != null && !albumKey.getName().equals(contextAlbumName)) - || (contextAlbumVersion != null && !albumKey.getVersion().equals(contextAlbumVersion))) { + || (contextAlbumVersion != null && !albumKey.getVersion().equals(contextAlbumVersion))) { continue; } - result.addMessage(new ApexModelStringWriter(false).writeString(albumKey, - AxArtifactKey.class, jsonMode)); + result.addMessage( + new ApexModelStringWriter(false).writeString(albumKey, AxArtifactKey.class)); found = true; } if (!found) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, CONCEPT + contextAlbumName + ':' - + contextAlbumVersion + DOES_NOT_EXIST_ON_STATE + state.getKey().getId()); + + contextAlbumVersion + DOES_NOT_EXIST_ON_STATE + state.getKey().getId()); } return result; } catch (final Exception e) { @@ -1368,20 +1339,20 @@ public class PolicyFacade { * @return result of the operation */ public ApexApiResult deletePolicyStateContextRef(final String name, final String version, final String stateName, - final String contextAlbumName, final String contextAlbumVersion) { + final String contextAlbumName, final String contextAlbumVersion) { try { Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL); final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version); if (policy == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxState state = policy.getStateMap().get(stateName); if (state == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); + CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST); } final Set deleteSet = new TreeSet<>(); @@ -1389,7 +1360,7 @@ public class PolicyFacade { for (final AxArtifactKey albumKey : state.getContextAlbumReferences()) { if ((contextAlbumName != null && !albumKey.getName().equals(contextAlbumName)) - || (contextAlbumVersion != null && !albumKey.getVersion().equals(contextAlbumVersion))) { + || (contextAlbumVersion != null && !albumKey.getVersion().equals(contextAlbumVersion))) { continue; } @@ -1397,14 +1368,14 @@ public class PolicyFacade { } if (deleteSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, CONCEPT + contextAlbumName + ':' - + contextAlbumVersion + DOES_NOT_EXIST_ON_STATE + state.getKey().getId()); + + contextAlbumVersion + DOES_NOT_EXIST_ON_STATE + state.getKey().getId()); } final ApexApiResult result = new ApexApiResult(); for (final AxArtifactKey keyToDelete : deleteSet) { state.getContextAlbumReferences().remove(keyToDelete); - result.addMessage(new ApexModelStringWriter(false).writeString(keyToDelete, - AxArtifactKey.class, jsonMode)); + result.addMessage( + new ApexModelStringWriter(false).writeString(keyToDelete, AxArtifactKey.class)); } return result; } catch (final Exception e) { diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/TaskFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/TaskFacade.java index ad1edd72e..6a2ded3e2 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/TaskFacade.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/TaskFacade.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019,2022 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -59,23 +59,17 @@ public class TaskFacade { // Facade classes for working towards the real Apex model private final KeyInformationFacade keyInformationFacade; - // JSON output on list/delete if set - private final boolean jsonMode; - /** * Constructor that creates a task facade for the Apex Model API. * * @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 */ - public TaskFacade(final ApexModel apexModel, final Properties apexProperties, final boolean jsonMode) { + public TaskFacade(final ApexModel apexModel, final Properties apexProperties) { this.apexModel = apexModel; this.apexProperties = apexProperties; - this.jsonMode = jsonMode; - keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties, jsonMode); + keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties); } /** @@ -88,7 +82,7 @@ public class TaskFacade { * @return result of the operation */ public ApexApiResult createTask(final String name, final String version, final String uuid, - final String description) { + final String description) { try { final AxArtifactKey key = new AxArtifactKey(); key.setName(name); @@ -124,12 +118,12 @@ public class TaskFacade { * @return result of the operation */ public ApexApiResult updateTask(final String name, final String version, final String uuid, - final String description) { + final String description) { try { final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version); if (task == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } return keyInformationFacade.updateKeyInformation(name, version, uuid, description); @@ -150,12 +144,12 @@ public class TaskFacade { final Set taskSet = apexModel.getPolicyModel().getTasks().getAll(name, version); if (name != null && taskSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxTask task : taskSet) { - result.addMessage(new ApexModelStringWriter(false).writeString(task, AxTask.class, jsonMode)); + result.addMessage(new ApexModelStringWriter(false).writeString(task, AxTask.class)); } return result; } catch (final Exception e) { @@ -177,22 +171,22 @@ public class TaskFacade { final AxTask removedTask = apexModel.getPolicyModel().getTasks().getTaskMap().remove(key); if (removedTask != null) { return new ApexApiResult(ApexApiResult.Result.SUCCESS, - new ApexModelStringWriter(false).writeString(removedTask, AxTask.class, jsonMode)); + new ApexModelStringWriter(false).writeString(removedTask, AxTask.class)); } else { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + key.getId() + DOES_NOT_EXIST); + CONCEPT + key.getId() + DOES_NOT_EXIST); } } final Set taskSet = apexModel.getPolicyModel().getTasks().getAll(name, version); if (taskSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxTask task : taskSet) { - result.addMessage(new ApexModelStringWriter(false).writeString(task, AxTask.class, jsonMode)); + result.addMessage(new ApexModelStringWriter(false).writeString(task, AxTask.class)); apexModel.getPolicyModel().getTasks().getTaskMap().remove(task.getKey()); keyInformationFacade.deleteKeyInformation(name, version); } @@ -214,14 +208,14 @@ public class TaskFacade { final Set taskSet = apexModel.getPolicyModel().getTasks().getAll(name, version); if (taskSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); + CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxTask task : taskSet) { final AxValidationResult validationResult = task.validate(new AxValidationResult()); - result.addMessage(new ApexModelStringWriter(false).writeString(task.getKey(), - AxArtifactKey.class, jsonMode)); + result.addMessage( + new ApexModelStringWriter(false).writeString(task.getKey(), AxArtifactKey.class)); result.addMessage(validationResult.toString()); } return result; @@ -241,12 +235,12 @@ public class TaskFacade { * @return result of the operation */ public ApexApiResult createTaskLogic(final String name, final String version, final String logicFlavour, - final String logic) { + final String logic) { try { final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version); if (task == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } // There is only one logic item associated with a task so we use a hard coded logic name @@ -254,7 +248,7 @@ public class TaskFacade { if (!task.getTaskLogic().getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS, - CONCEPT + refKey.getId() + ALREADY_EXISTS); + CONCEPT + refKey.getId() + ALREADY_EXISTS); } task.setTaskLogic(new AxTaskLogic(refKey, logicFlavour, logic)); @@ -274,17 +268,17 @@ public class TaskFacade { * @return result of the operation */ public ApexApiResult updateTaskLogic(final String name, final String version, final String logicFlavour, - final String logic) { + final String logic) { try { final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version); if (task == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } if (task.getTaskLogic().getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + task.getTaskLogic().getKey().getId() + DOES_NOT_EXIST); + CONCEPT + task.getTaskLogic().getKey().getId() + DOES_NOT_EXIST); } final AxTaskLogic taskLogic = task.getTaskLogic(); @@ -313,11 +307,11 @@ public class TaskFacade { final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version); if (task == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } - return new ApexApiResult(ApexApiResult.Result.SUCCESS, new ApexModelStringWriter(false) - .writeString(task.getTaskLogic(), AxTaskLogic.class, jsonMode)); + return new ApexApiResult(ApexApiResult.Result.SUCCESS, + new ApexModelStringWriter(false).writeString(task.getTaskLogic(), AxTaskLogic.class)); } catch (final Exception e) { return new ApexApiResult(ApexApiResult.Result.FAILED, e); } @@ -335,17 +329,17 @@ public class TaskFacade { final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version); if (task == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } if (task.getTaskLogic().getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + task.getTaskLogic().getKey().getId() + DOES_NOT_EXIST); + CONCEPT + task.getTaskLogic().getKey().getId() + DOES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); - result.addMessage(new ApexModelStringWriter(false).writeString(task.getTaskLogic(), - AxTaskLogic.class, jsonMode)); + result.addMessage( + new ApexModelStringWriter(false).writeString(task.getTaskLogic(), AxTaskLogic.class)); task.setTaskLogic(new AxTaskLogic()); return result; } catch (final Exception e) { @@ -363,21 +357,21 @@ public class TaskFacade { * @return result of the operation */ public ApexApiResult createTaskParameter(final String name, final String version, final String parName, - final String defaultValue) { + final String defaultValue) { try { Assertions.argumentNotNull(parName, "parName may not be null"); final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version); if (task == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxReferenceKey refKey = new AxReferenceKey(task.getKey(), parName); if (task.getTaskParameters().containsKey(refKey.getLocalName())) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS, - CONCEPT + refKey.getId() + ALREADY_EXISTS); + CONCEPT + refKey.getId() + ALREADY_EXISTS); } task.getTaskParameters().put(refKey.getLocalName(), new AxTaskParameter(refKey, defaultValue)); @@ -400,29 +394,29 @@ public class TaskFacade { final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version); if (task == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } if (parName != null) { final AxTaskParameter taskParameter = task.getTaskParameters().get(parName); if (taskParameter != null) { return new ApexApiResult(ApexApiResult.Result.SUCCESS, - new ApexModelStringWriter(false).writeString(taskParameter, - AxTaskParameter.class, jsonMode)); + new ApexModelStringWriter(false).writeString(taskParameter, + AxTaskParameter.class)); } else { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + ':' + taskParameter + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + ':' + taskParameter + DOES_NOT_EXIST); } } else { if (task.getTaskParameters().size() == 0) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "no task parameters defined on task " + task.getKey().getId()); + "no task parameters defined on task " + task.getKey().getId()); } final ApexApiResult result = new ApexApiResult(); for (final AxTaskParameter parameter : task.getTaskParameters().values()) { result.addMessage(new ApexModelStringWriter(false).writeString(parameter, - AxTaskParameter.class, jsonMode)); + AxTaskParameter.class)); } return result; } @@ -444,29 +438,29 @@ public class TaskFacade { final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version); if (task == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); if (parName != null) { if (task.getTaskParameters().containsKey(parName)) { result.addMessage(new ApexModelStringWriter(false) - .writeString(task.getTaskParameters().get(parName), AxTaskParameter.class, jsonMode)); + .writeString(task.getTaskParameters().get(parName), AxTaskParameter.class)); task.getTaskParameters().remove(parName); return result; } else { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + ':' + parName + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + ':' + parName + DOES_NOT_EXIST); } } else { if (task.getTaskParameters().size() == 0) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - "no task parameters defined on task " + task.getKey().getId()); + "no task parameters defined on task " + task.getKey().getId()); } for (final AxTaskParameter parameter : task.getTaskParameters().values()) { result.addMessage(new ApexModelStringWriter(false).writeString(parameter, - AxTaskParameter.class, jsonMode)); + AxTaskParameter.class)); } task.getTaskParameters().clear(); return result; @@ -487,24 +481,24 @@ public class TaskFacade { * @return result of the operation */ public ApexApiResult createTaskContextRef(final String name, final String version, final String contextAlbumName, - final String contextAlbumVersion) { + final String contextAlbumVersion) { try { final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version); if (task == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final AxContextAlbum contextAlbum = - apexModel.getPolicyModel().getAlbums().get(contextAlbumName, contextAlbumVersion); + apexModel.getPolicyModel().getAlbums().get(contextAlbumName, contextAlbumVersion); if (contextAlbum == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + contextAlbumName + ':' + contextAlbumVersion + DOES_NOT_EXIST); + CONCEPT + contextAlbumName + ':' + contextAlbumVersion + DOES_NOT_EXIST); } if (task.getContextAlbumReferences().contains(contextAlbum.getKey())) { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS, "context album reference for concept " - + contextAlbum.getKey().getId() + " already exists in task"); + return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS, + "context album reference for concept " + contextAlbum.getKey().getId() + " already exists in task"); } task.getContextAlbumReferences().add(contextAlbum.getKey()); @@ -526,28 +520,28 @@ public class TaskFacade { * @return result of the operation */ public ApexApiResult listTaskContextRef(final String name, final String version, final String contextAlbumName, - final String contextAlbumVersion) { + final String contextAlbumVersion) { try { final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version); if (task == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); boolean found = false; for (final AxArtifactKey albumKey : task.getContextAlbumReferences()) { if ((contextAlbumName != null && !albumKey.getName().equals(contextAlbumName)) - || (contextAlbumVersion != null && !albumKey.getVersion().equals(contextAlbumVersion))) { + || (contextAlbumVersion != null && !albumKey.getVersion().equals(contextAlbumVersion))) { continue; } - result.addMessage(new ApexModelStringWriter(false).writeString(albumKey, - AxArtifactKey.class, jsonMode)); + result.addMessage( + new ApexModelStringWriter(false).writeString(albumKey, AxArtifactKey.class)); found = true; } if (!found) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + contextAlbumName + ':' + contextAlbumVersion + DOES_NOT_EXIST); + CONCEPT + contextAlbumName + ':' + contextAlbumVersion + DOES_NOT_EXIST); } return result; } catch (final Exception e) { @@ -567,19 +561,19 @@ public class TaskFacade { * @return result of the operation */ public ApexApiResult deleteTaskContextRef(final String name, final String version, final String contextAlbumName, - final String contextAlbumVersion) { + final String contextAlbumVersion) { try { final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version); if (task == null) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + name + ':' + version + DOES_NOT_EXIST); + CONCEPT + name + ':' + version + DOES_NOT_EXIST); } final Set deleteSet = new TreeSet<>(); for (final AxArtifactKey albumKey : task.getContextAlbumReferences()) { if ((contextAlbumName != null && !albumKey.getName().equals(contextAlbumName)) - || (contextAlbumVersion != null && !albumKey.getVersion().equals(contextAlbumVersion))) { + || (contextAlbumVersion != null && !albumKey.getVersion().equals(contextAlbumVersion))) { continue; } deleteSet.add(albumKey); @@ -587,13 +581,13 @@ public class TaskFacade { if (deleteSet.isEmpty()) { return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + contextAlbumName + ':' + contextAlbumVersion + DOES_NOT_EXIST); + CONCEPT + contextAlbumName + ':' + contextAlbumVersion + DOES_NOT_EXIST); } final ApexApiResult result = new ApexApiResult(); for (final AxArtifactKey keyToDelete : deleteSet) { task.getContextAlbumReferences().remove(keyToDelete); - result.addMessage(new ApexModelStringWriter(false).writeString(keyToDelete, - AxArtifactKey.class, jsonMode)); + result.addMessage( + new ApexModelStringWriter(false).writeString(keyToDelete, AxArtifactKey.class)); } return result; } catch (final Exception e) { -- cgit 1.2.3-korg