/**
* ============LICENSE_START=======================================================
- * Gizmo
+ * org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property.
- * Copyright © 2017 Amdocs
- * All rights reserved.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.crud.dao.champ;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
import org.eclipse.jetty.util.security.Password;
+import org.onap.aai.cl.mdc.MdcContext;
import org.onap.aai.logging.LoggingContext;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
} else {
// We didn't find a vertex with the supplied id, so just throw an
// exception.
- throw new CrudException("No vertex with id " + id + " found in graph",
- javax.ws.rs.core.Response.Status.NOT_FOUND);
+ throw createErrorException(getResult, javax.ws.rs.core.Response.Status.NOT_FOUND, "No vertex with id " + id + " found in graph");
}
}
} else {
// We didn't find a vertex with the supplied id, so just throw an
// exception.
- throw new CrudException("No vertex with id " + id + " found in graph",
- javax.ws.rs.core.Response.Status.NOT_FOUND);
+ throw createErrorException(getResult, javax.ws.rs.core.Response.Status.NOT_FOUND, "No vertex with id " + id + " found in graph");
}
}
} else {
// We didn't find a vertex with the supplied id, so just throw an
// exception.
- throw new CrudException("No vertex with id " + id + " found in graph",
- javax.ws.rs.core.Response.Status.NOT_FOUND);
+ throw createErrorException(getResult, javax.ws.rs.core.Response.Status.NOT_FOUND, "No vertex with id " + id + " found in graph");
}
}
} else {
// We didn't find a vertex with the supplied id, so just throw an
// exception.
- throw new CrudException("No vertices found in graph for given filters",
- javax.ws.rs.core.Response.Status.NOT_FOUND);
+ throw createErrorException(getResult, javax.ws.rs.core.Response.Status.NOT_FOUND, "No vertices found in graph for given filters");
}
}
} else {
// We didn't find a edge with the supplied type, so just throw an
// exception.
- throw new CrudException("No edge with id " + id + " found in graph", javax.ws.rs.core.Response.Status.NOT_FOUND);
+ throw createErrorException(getResult, javax.ws.rs.core.Response.Status.NOT_FOUND, "No edge with id " + id + " found in graph");
}
}
} else {
// We didn't find a vertex with the supplied id, so just throw an
// exception.
- throw new CrudException("No edges found in graph for given filters", javax.ws.rs.core.Response.Status.NOT_FOUND);
+ throw createErrorException(getResult, javax.ws.rs.core.Response.Status.NOT_FOUND, "No edges found in graph for given filters");
}
}
if (getResult.getResultCode() != 200) {
// We didn't find an edge with the supplied type, so just throw an
// exception.
- throw new CrudException("No edge with id " + id + " found in graph", javax.ws.rs.core.Response.Status.NOT_FOUND);
+ throw createErrorException(getResult, javax.ws.rs.core.Response.Status.NOT_FOUND, "No edge with id " + id + " found in graph");
}
}
if (getResult.getResultCode() != 200) {
// We didn't find an edge with the supplied type, so just throw an
// exception.
- throw new CrudException("No edge with id " + id + " found in graph", javax.ws.rs.core.Response.Status.NOT_FOUND);
+ throw createErrorException(getResult, javax.ws.rs.core.Response.Status.NOT_FOUND, "No edge with id " + id + " found in graph");
}
}
} else {
// We didn't find an edge with the supplied id, so just throw an
// exception.
- throw new CrudException("No edge with id " + id + " found in graph", javax.ws.rs.core.Response.Status.NOT_FOUND);
+ throw createErrorException(getResult, javax.ws.rs.core.Response.Status.NOT_FOUND, "No edge with id " + id + " found in graph");
}
}
} else {
// We didn't find a vertex with the supplied id, so just throw an
// exception.
- throw new CrudException("No vertex with id " + id + " found in graph",
- javax.ws.rs.core.Response.Status.NOT_FOUND);
+ throw createErrorException(getResult, javax.ws.rs.core.Response.Status.NOT_FOUND, "No vertex with id " + id + " found in graph");
}
}
private Map<String, List<String>> createHeader() {
Map<String, List<String>> headers = new HashMap<>();
headers.put(HEADER_FROM_APP, Arrays.asList(FROM_APP_NAME));
- headers.put(HEADER_TRANS_ID, Arrays.asList(MDC.get(LoggingContext.LoggingField.REQUEST_ID.toString())));
+ headers.put(HEADER_TRANS_ID, Arrays.asList(MDC.get(MdcContext.MDC_REQUEST_ID)));
return headers;
}
+
+ private CrudException createErrorException(OperationResult result, javax.ws.rs.core.Response.Status defaultErrorCode , String defaultErrorMsg)
+ {
+ CrudException ce = null;
+ if(result != null)
+ ce = new CrudException(result.getFailureCause(), Response.Status.fromStatusCode(result.getResultCode()));
+ else
+ ce = new CrudException(defaultErrorMsg, defaultErrorCode);
+ return ce;
+ }
+
}