summaryrefslogtreecommitdiffstats
path: root/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BaseController.java
blob: 76e6d163ff9d9971e7ef244192b3c3b35440e949 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package org.onap.sdc.dcae.composition.controller;

import com.google.gson.Gson;
import org.onap.sdc.common.onaplog.enums.LogLevel;
import org.onap.sdc.common.onaplog.OnapLoggerDebug;
import org.onap.sdc.common.onaplog.OnapLoggerError;
import org.onap.sdc.dcae.composition.impl.BaseBusinessLogic;
import org.onap.sdc.dcae.errormng.ErrConfMgr;
import org.onap.sdc.dcae.errormng.ErrConfMgr.ApiType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;

public abstract class BaseController {
	
	protected Gson gson = new Gson();

	@Autowired
	protected BaseBusinessLogic baseBusinessLogic;

	protected OnapLoggerError errLogger = OnapLoggerError.getInstance();
	protected OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();

	@ModelAttribute("requestId")
	public String getRequestId(HttpServletRequest request) {
		return request.getAttribute("requestId").toString();
	}

	ResponseEntity handleException(Exception e, ApiType apiType, String... variables){
		errLogger.log(LogLevel.ERROR, this.getClass().getName(), e.getMessage());
		return ErrConfMgr.INSTANCE.handleException(e, apiType, variables);
	}
}