f81a22ee96f80d870b046f711245fea23a32823a
[policy/apex-pdp.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.examples.myfirstpolicy.model;
22
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;
27
28 /**
29  * A factory for creating MFPDomainModel objects.
30  *
31  * @author John Keeney (john.keeney@ericsson.com)
32  */
33 public class MfpDomainModelFactory {
34
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";
38
39     /**
40      * Gets the MyFirstPolicy#1 policy model.
41      *
42      * @return the MyFirstPolicy#1 policy model
43      */
44     public AxPolicyModel getMfp1PolicyModel() {
45         java.util.TimeZone.getTimeZone("gmt");
46         try {
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,
51                     e);
52         }
53     }
54
55     /**
56      * Gets the MyFirstPolicy#1 policy model, with alternate JavaScript task logic.
57      *
58      * @return the MyFirstPolicy#1 policy model
59      */
60     public AxPolicyModel getMfp1AltPolicyModel() {
61         java.util.TimeZone.getTimeZone("gmt");
62         try {
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);
68         }
69     }
70
71     /**
72      * Gets the MyFirstPolicy#1 policy model.
73      *
74      * @return the MyFirstPolicy#1 policy model
75      */
76     public AxPolicyModel getMfp2PolicyModel() {
77         try {
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,
82                     e);
83         }
84     }
85
86 }