diff options
author | ramverma <ram.krishna.verma@ericsson.com> | 2018-07-25 17:26:52 +0100 |
---|---|---|
committer | ramverma <ram.krishna.verma@ericsson.com> | 2018-07-25 17:32:29 +0100 |
commit | f8959f5c51e6338b62e23ea503eb86d9c65d7c74 (patch) | |
tree | 7a8afbbf61f7091c30aadfc1cace70fb6e65bff9 /examples/examples-myfirstpolicy/src/main/java/org | |
parent | dccf9a9e0758be0a926c94bf1599ee625066100d (diff) |
Renaming examples in apex-pdp
Renaming the examples as per what the documentation expects them.
Otherwise the documents won't work.
Change-Id: Ib9e30bf5a4cec0fec981372e1d9f3a0ee5d60f2f
Issue-ID: POLICY-861
Signed-off-by: ramverma <ram.krishna.verma@ericsson.com>
Diffstat (limited to 'examples/examples-myfirstpolicy/src/main/java/org')
3 files changed, 175 insertions, 0 deletions
diff --git a/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/MFPDomainModelFactory.java b/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/MFPDomainModelFactory.java new file mode 100644 index 000000000..9b3f6cc8a --- /dev/null +++ b/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/MFPDomainModelFactory.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.examples.myfirstpolicy.model; + +import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; +import org.onap.policy.apex.model.utilities.ResourceUtils; + +/** + * A factory for creating MFPDomainModel objects. + * + * @author John Keeney (john.keeney@ericsson.com) + */ +public class MFPDomainModelFactory { + + private static final String MFP1PATH = "examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json"; + private static final String MFP1_ALT_PATH = "examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.alt.json"; + private static final String MFP2PATH = "examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.json"; + + /** + * Gets the MyFirstPolicy#1 policy model. + * + * @return the MyFirstPolicy#1 policy model + */ + public AxPolicyModel getMFP1PolicyModel() { + java.util.TimeZone.getTimeZone("gmt"); + try { + final ApexModelReader<AxPolicyModel> reader = new ApexModelReader<>(AxPolicyModel.class); + return reader.read(ResourceUtils.getResourceAsString(MFPDomainModelFactory.MFP1PATH)); + } catch (final Exception e) { + throw new ApexRuntimeException("Failed to build MyFirstPolicy from path: " + MFPDomainModelFactory.MFP1PATH, + e); + } + } + + /** + * Gets the MyFirstPolicy#1 policy model, with alternate JavaScript task logic. + * + * @return the MyFirstPolicy#1 policy model + */ + public AxPolicyModel getMFP1AltPolicyModel() { + java.util.TimeZone.getTimeZone("gmt"); + try { + final ApexModelReader<AxPolicyModel> reader = new ApexModelReader<>(AxPolicyModel.class); + return reader.read(ResourceUtils.getResourceAsString(MFPDomainModelFactory.MFP1_ALT_PATH)); + } catch (final Exception e) { + throw new ApexRuntimeException( + "Failed to build MyFirstPolicy_ALT from path: " + MFPDomainModelFactory.MFP1_ALT_PATH, e); + } + } + + /** + * Gets the MyFirstPolicy#1 policy model. + * + * @return the MyFirstPolicy#1 policy model + */ + public AxPolicyModel getMFP2PolicyModel() { + try { + final ApexModelReader<AxPolicyModel> reader = new ApexModelReader<>(AxPolicyModel.class); + return reader.read(ResourceUtils.getResourceAsString(MFPDomainModelFactory.MFP2PATH)); + } catch (final Exception e) { + throw new ApexRuntimeException("Failed to build MyFirstPolicy from path: " + MFPDomainModelFactory.MFP2PATH, + e); + } + } + +} diff --git a/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/MFPDomainModelSaver.java b/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/MFPDomainModelSaver.java new file mode 100644 index 000000000..7343f747d --- /dev/null +++ b/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/MFPDomainModelSaver.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.examples.myfirstpolicy.model; + +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelSaver; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; + +/** + * The Class MFPDomainModelSaver. + * + * @author John Keeney (john.keeney@ericsson.com) + */ +public final class MFPDomainModelSaver { + + /** Private constructor to prevent instantiation. */ + private MFPDomainModelSaver() {} + + /** + * Write the MyFirstPolicy model to args[0]. + * + * @param args uses <code>arg[0]</code> for directory information + * @throws ApexException the apex exception + */ + public static void main(final String[] args) throws ApexException { + if (args.length != 1) { + System.err.println("usage: " + MFPDomainModelSaver.class.getCanonicalName() + " modelDirectory"); + return; + } + + // Save Java model + AxPolicyModel mfpPolicyModel = new MFPDomainModelFactory().getMFP1PolicyModel(); + ApexModelSaver<AxPolicyModel> mfpModelSaver = + new ApexModelSaver<>(AxPolicyModel.class, mfpPolicyModel, args[0] + "/1/"); + mfpModelSaver.apexModelWriteJSON(); + mfpModelSaver.apexModelWriteXML(); + + mfpPolicyModel = new MFPDomainModelFactory().getMFP2PolicyModel(); + mfpModelSaver = new ApexModelSaver<>(AxPolicyModel.class, mfpPolicyModel, args[0] + "/2/"); + mfpModelSaver.apexModelWriteJSON(); + mfpModelSaver.apexModelWriteXML(); + + } +} diff --git a/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/package-info.java b/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/package-info.java new file mode 100644 index 000000000..ed03da4ca --- /dev/null +++ b/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +/** + * Contains the model for My-First-Policy. + * + * @author John Keeney (john.keeney@ericsson.com) + */ + +package org.onap.policy.apex.examples.myfirstpolicy.model; |