0df23d399949a7ab889a15d47a3cc3be701ed876
[policy/apex-pdp.git] / core / core-protocols / src / main / java / org / onap / policy / apex / core / protocols / engdep / messages / EngineServiceInfoResponse.java
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.core.protocols.engdep.messages;
22
23 import java.util.Arrays;
24 import java.util.Collection;
25
26 import org.onap.policy.apex.core.protocols.Message;
27 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
28
29 /**
30  * The Class Response is a message that holds the response by an Apex engine to another Actino message sent to that
31  * engine.
32  *
33  * @author Liam Fallon (liam.fallon@ericsson.com)
34  */
35 public class EngineServiceInfoResponse extends Response {
36     private static final long serialVersionUID = -7895025789667402067L;
37
38     // The engine service key
39     private AxArtifactKey engineServiceKey;
40
41     // The engines under the control of this engine service
42     private AxArtifactKey[] engineKeyArray;
43
44     // The engine service key
45     private AxArtifactKey apexModelKey;
46
47     /**
48      * Instantiates a new EngineServiceInfoResponse message.
49      *
50      * @param targetKey the target key of the entity that asked for the action that triggered this response message
51      * @param successful the successful if the action in the triggering message worked
52      * @param responseTo the message to which this message is a response
53      */
54     public EngineServiceInfoResponse(final AxArtifactKey targetKey, final boolean successful,
55             final Message responseTo) {
56         super(targetKey, successful, null, responseTo);
57     }
58
59     /**
60      * Instantiates a new EngineServiceInfoResponse message.
61      *
62      * @param targetKey the target key of the entity that asked for the action that triggered this response message
63      * @param successful the successful if the action in the triggering message worked
64      * @param messageData the message data which may indicate specific conditions for the response
65      * @param responseTo the message to which this message is a response
66      */
67     public EngineServiceInfoResponse(final AxArtifactKey targetKey, final boolean successful, final String messageData,
68             final Message responseTo) {
69         super(targetKey, successful, messageData, responseTo);
70     }
71
72     /**
73      * Gets the engine service key.
74      *
75      * @return the engine service key
76      */
77     public AxArtifactKey getEngineServiceKey() {
78         return engineServiceKey;
79     }
80
81     /**
82      * Sets the engine service key.
83      *
84      * @param engineServiceKey the engine service key
85      */
86     public void setEngineServiceKey(final AxArtifactKey engineServiceKey) {
87         this.engineServiceKey = engineServiceKey;
88     }
89
90     /**
91      * Gets the engine key array.
92      *
93      * @return the engine key array
94      */
95     public AxArtifactKey[] getEngineKeyArray() {
96         return engineKeyArray;
97     }
98
99     /**
100      * Sets the engine key array.
101      *
102      * @param engineKeyCollection the engine key array
103      */
104     public void setEngineKeyArray(final Collection<AxArtifactKey> engineKeyCollection) {
105         if (engineKeyCollection != null) {
106             engineKeyArray = engineKeyCollection.toArray(new AxArtifactKey[engineKeyCollection.size()]);
107         }
108         else {
109             engineKeyArray = null;
110         }
111     }
112
113     /**
114      * Gets the apex model key.
115      *
116      * @return the apex model key
117      */
118     public AxArtifactKey getApexModelKey() {
119         return apexModelKey;
120     }
121
122     /**
123      * Sets the apex model key.
124      *
125      * @param apexModelKey the apex model key
126      */
127     public void setApexModelKey(final AxArtifactKey apexModelKey) {
128         this.apexModelKey = apexModelKey;
129     }
130
131     /**
132      * {@inheritDoc}.
133      */
134     @Override
135     public int hashCode() {
136         final int prime = 31;
137         int result = super.hashCode();
138         result = prime * result + ((apexModelKey == null) ? 0 : apexModelKey.hashCode());
139         result = prime * result + Arrays.hashCode(engineKeyArray);
140         result = prime * result + ((engineServiceKey == null) ? 0 : engineServiceKey.hashCode());
141         return result;
142     }
143
144     /**
145      * {@inheritDoc}.
146      */
147     @Override
148     public boolean equals(Object obj) {
149         if (this == obj) {
150             return true;
151         }
152         if (!super.equals(obj)) {
153             return false;
154         }
155
156         EngineServiceInfoResponse other = (EngineServiceInfoResponse) obj;
157         if (apexModelKey == null) {
158             if (other.apexModelKey != null) {
159                 return false;
160             }
161         } else if (!apexModelKey.equals(other.apexModelKey)) {
162             return false;
163         }
164         if (!Arrays.equals(engineKeyArray, other.engineKeyArray)) {
165             return false;
166         }
167         if (engineServiceKey == null) {
168             if (other.engineServiceKey != null) {
169                 return false;
170             }
171         } else if (!engineServiceKey.equals(other.engineServiceKey)) {
172             return false;
173         }
174         return true;
175     }
176 }