1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cadi.aaf.client;
\r
25 import java.io.PrintStream;
\r
27 import org.onap.aaf.cadi.client.Future;
\r
28 import org.onap.aaf.cadi.util.Vars;
\r
30 import aaf.v2_0.Error;
\r
32 import org.onap.aaf.inno.env.APIException;
\r
33 import org.onap.aaf.inno.env.Data.TYPE;
\r
34 import org.onap.aaf.rosetta.env.RosettaDF;
\r
35 import org.onap.aaf.rosetta.env.RosettaEnv;
\r
37 public class ErrMessage {
\r
38 private RosettaDF<Error> errDF;
\r
40 public ErrMessage(RosettaEnv env) throws APIException {
\r
41 errDF = env.newDataFactory(Error.class);
\r
45 * AT&T Requires a specific Error Format for RESTful Services, which AAF complies with.
\r
47 * This code will create a meaningful string from this format.
\r
52 * @throws APIException
\r
54 public void printErr(PrintStream ps, String attErrJson) throws APIException {
\r
55 StringBuilder sb = new StringBuilder();
\r
56 Error err = errDF.newData().in(TYPE.JSON).load(attErrJson).asObject();
\r
57 ps.println(toMsg(sb,err));
\r
61 * AT&T Requires a specific Error Format for RESTful Services, which AAF complies with.
\r
63 * This code will create a meaningful string from this format.
\r
68 * @throws APIException
\r
70 public StringBuilder toMsg(StringBuilder sb, String attErrJson) throws APIException {
\r
71 return toMsg(sb,errDF.newData().in(TYPE.JSON).load(attErrJson).asObject());
\r
74 public StringBuilder toMsg(Future<?> future) {
\r
75 return toMsg(new StringBuilder(),future);
\r
78 public StringBuilder toMsg(StringBuilder sb, Future<?> future) {
\r
80 toMsg(sb,errDF.newData().in(TYPE.JSON).load(future.body()).asObject());
\r
81 } catch(Exception e) {
\r
82 //just print what we can
\r
83 sb.append(future.code());
\r
85 sb.append(future.body());
\r
90 public StringBuilder toMsg(StringBuilder sb, Error err) {
\r
91 sb.append(err.getMessageId());
\r
93 String[] vars = new String[err.getVariables().size()];
\r
94 err.getVariables().toArray(vars);
\r
95 Vars.convert(sb, err.getText(),vars);
\r