49f2f84641fd26ea751c9739fcb089a8d7ed4c67
[aaf/authz.git] / authz-gw / src / main / java / com / att / authz / gw / mapper / Mapper_1_0.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aai\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * Copyright © 2017 Amdocs\r
7  * * ===========================================================================\r
8  * * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * * you may not use this file except in compliance with the License.\r
10  * * You may obtain a copy of the License at\r
11  * * \r
12  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
13  * * \r
14  *  * Unless required by applicable law or agreed to in writing, software\r
15  * * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * * See the License for the specific language governing permissions and\r
18  * * limitations under the License.\r
19  * * ============LICENSE_END====================================================\r
20  * *\r
21  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  * *\r
23  ******************************************************************************/\r
24 package com.att.authz.gw.mapper;\r
25 \r
26 import com.att.cadi.util.Vars;\r
27 \r
28 import gw.v1_0.Error;\r
29 import gw.v1_0.InRequest;\r
30 import gw.v1_0.Out;\r
31 \r
32 public class Mapper_1_0 implements Mapper<InRequest,Out,Error> {\r
33         \r
34         @Override\r
35         public Class<?> getClass(API api) {\r
36                 switch(api) {\r
37                         case IN_REQ: return InRequest.class;\r
38                         case OUT: return Out.class;\r
39                         case ERROR: return Error.class;\r
40                         case VOID: return Void.class;\r
41                 }\r
42                 return null;\r
43         }\r
44 \r
45         @SuppressWarnings("unchecked")\r
46         @Override\r
47         public <A> A newInstance(API api) {\r
48                 switch(api) {\r
49                         case IN_REQ: return (A) new InRequest();\r
50                         case OUT: return (A) new Out();\r
51                         case ERROR: return (A)new Error();\r
52                         case VOID: return null;\r
53                 }\r
54                 return null;\r
55         }\r
56 \r
57         //////////////  Mapping Functions /////////////\r
58         @Override\r
59         public gw.v1_0.Error errorFromMessage(StringBuilder holder, String msgID, String text,String... var) {\r
60                 Error err = new Error();\r
61                 err.setMessageId(msgID);\r
62                 // AT&T Restful Error Format requires numbers "%" placements\r
63                 err.setText(Vars.convert(holder, text, var));\r
64                 for(String s : var) {\r
65                         err.getVariables().add(s);\r
66                 }\r
67                 return err;\r
68         }\r
69 \r
70 }\r