2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.examples.myfirstpolicy.model;
23 import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException;
24 import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
25 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
26 import org.onap.policy.common.utils.resources.ResourceUtils;
29 * A factory for creating MFPDomainModel objects.
31 * @author John Keeney (john.keeney@ericsson.com)
33 public class MFPDomainModelFactory {
35 private static final String MFP1PATH = "examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json";
36 private static final String MFP1_ALT_PATH = "examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.alt.json";
37 private static final String MFP2PATH = "examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.json";
40 * Gets the MyFirstPolicy#1 policy model.
42 * @return the MyFirstPolicy#1 policy model
44 public AxPolicyModel getMFP1PolicyModel() {
45 java.util.TimeZone.getTimeZone("gmt");
47 final ApexModelReader<AxPolicyModel> reader = new ApexModelReader<>(AxPolicyModel.class);
48 return reader.read(ResourceUtils.getResourceAsString(MFPDomainModelFactory.MFP1PATH));
49 } catch (final Exception e) {
50 throw new ApexRuntimeException("Failed to build MyFirstPolicy from path: " + MFPDomainModelFactory.MFP1PATH,
56 * Gets the MyFirstPolicy#1 policy model, with alternate JavaScript task logic.
58 * @return the MyFirstPolicy#1 policy model
60 public AxPolicyModel getMFP1AltPolicyModel() {
61 java.util.TimeZone.getTimeZone("gmt");
63 final ApexModelReader<AxPolicyModel> reader = new ApexModelReader<>(AxPolicyModel.class);
64 return reader.read(ResourceUtils.getResourceAsString(MFPDomainModelFactory.MFP1_ALT_PATH));
65 } catch (final Exception e) {
66 throw new ApexRuntimeException(
67 "Failed to build MyFirstPolicy_ALT from path: " + MFPDomainModelFactory.MFP1_ALT_PATH, e);
72 * Gets the MyFirstPolicy#1 policy model.
74 * @return the MyFirstPolicy#1 policy model
76 public AxPolicyModel getMFP2PolicyModel() {
78 final ApexModelReader<AxPolicyModel> reader = new ApexModelReader<>(AxPolicyModel.class);
79 return reader.read(ResourceUtils.getResourceAsString(MFPDomainModelFactory.MFP2PATH));
80 } catch (final Exception e) {
81 throw new ApexRuntimeException("Failed to build MyFirstPolicy from path: " + MFPDomainModelFactory.MFP2PATH,