+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START====================================================\r
- * * org.onap.aaf\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.onap.aaf.cadi.aaf.client;\r
-\r
-import java.io.PrintStream;\r
-\r
-import org.onap.aaf.cadi.client.Future;\r
-import org.onap.aaf.cadi.util.Vars;\r
-\r
-import aaf.v2_0.Error;\r
-\r
-import org.onap.aaf.inno.env.APIException;\r
-import org.onap.aaf.inno.env.Data.TYPE;\r
-import org.onap.aaf.rosetta.env.RosettaDF;\r
-import org.onap.aaf.rosetta.env.RosettaEnv;\r
-\r
-public class ErrMessage {\r
- private RosettaDF<Error> errDF;\r
- \r
- public ErrMessage(RosettaEnv env) throws APIException {\r
- errDF = env.newDataFactory(Error.class);\r
- }\r
-\r
- /**\r
- * AT&T Requires a specific Error Format for RESTful Services, which AAF complies with.\r
- * \r
- * This code will create a meaningful string from this format. \r
- * \r
- * @param ps\r
- * @param df\r
- * @param r\r
- * @throws APIException\r
- */\r
- public void printErr(PrintStream ps, String attErrJson) throws APIException {\r
- StringBuilder sb = new StringBuilder();\r
- Error err = errDF.newData().in(TYPE.JSON).load(attErrJson).asObject();\r
- ps.println(toMsg(sb,err));\r
- }\r
- \r
- /**\r
- * AT&T Requires a specific Error Format for RESTful Services, which AAF complies with.\r
- * \r
- * This code will create a meaningful string from this format. \r
- * \r
- * @param sb\r
- * @param df\r
- * @param r\r
- * @throws APIException\r
- */\r
- public StringBuilder toMsg(StringBuilder sb, String attErrJson) throws APIException {\r
- return toMsg(sb,errDF.newData().in(TYPE.JSON).load(attErrJson).asObject());\r
- }\r
- \r
- public StringBuilder toMsg(Future<?> future) {\r
- return toMsg(new StringBuilder(),future);\r
- }\r
- \r
- public StringBuilder toMsg(StringBuilder sb, Future<?> future) {\r
- try {\r
- toMsg(sb,errDF.newData().in(TYPE.JSON).load(future.body()).asObject());\r
- } catch(Exception e) {\r
- //just print what we can\r
- sb.append(future.code());\r
- sb.append(": ");\r
- sb.append(future.body());\r
- }\r
- return sb;\r
- }\r
-\r
- public StringBuilder toMsg(StringBuilder sb, Error err) {\r
- sb.append(err.getMessageId());\r
- sb.append(' ');\r
- String[] vars = new String[err.getVariables().size()];\r
- err.getVariables().toArray(vars);\r
- Vars.convert(sb, err.getText(),vars);\r
- return sb;\r
- }\r
-}\r