2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.requestsdb;
23 import java.sql.Timestamp;
25 import org.onap.so.db.request.beans.InfraActiveRequests;
26 import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository;
27 import org.onap.so.logger.MsoLogger;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Component;
32 public class RequestsDBHelper {
34 private static final String UNKNOWN = "UNKNOWN";
35 private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH, RequestsDBHelper.class);
36 private String className = this.getClass().getSimpleName() +" class\'s ";
37 private String methodName = "";
38 private String classMethodMessage = "";
40 private InfraActiveRequestsRepository infraActiveRequestsRepository;
42 * This util method is to update the InfraRequest table to Complete
43 * @param msg - string, unique message for each caller
44 * @param requestId - string
45 * @param operationalEnvironmentId - string
46 * @return void - nothing
49 public void updateInfraSuccessCompletion(String msg, String requestId, String operationalEnvironmentId) {
50 methodName = "updateInfraSuccessCompletion() method.";
51 classMethodMessage = className + " " + methodName;
52 msoLogger.debug("Begin of " + classMethodMessage);
54 InfraActiveRequests request = infraActiveRequestsRepository.findOneByRequestId(requestId);
56 request.setRequestStatus("COMPLETE");
57 request.setStatusMessage("SUCCESSFUL, operationalEnvironmentId - " + operationalEnvironmentId + "; Success Message: " + msg);
58 request.setProgress(100L);
59 request.setLastModifiedBy("APIH");
60 request.setOperationalEnvId(operationalEnvironmentId);
61 if(request.getAction() == null){
62 request.setRequestAction(UNKNOWN);
64 if(request.getRequestScope() == null){
65 request.setRequestScope(UNKNOWN);
67 Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis());
68 request.setEndTime(endTimeStamp);
69 infraActiveRequestsRepository.save(request);
71 msoLogger.debug("End of " + classMethodMessage);
76 * This util method is to update the InfraRequest table to Failure
77 * @param msg - string, unique message for each caller
78 * @param requestId - string
79 * @param operationalEnvironmentId - string
80 * @return void - nothing
83 public void updateInfraFailureCompletion(String msg, String requestId, String operationalEnvironmentId) {
84 methodName = "updateInfraFailureCompletion() method.";
85 classMethodMessage = className + " " + methodName;
86 msoLogger.debug("Begin of " + classMethodMessage);
88 InfraActiveRequests request = infraActiveRequestsRepository.findOneByRequestId(requestId);
89 request.setRequestStatus("FAILED");
90 request.setStatusMessage("FAILURE, operationalEnvironmentId - " + operationalEnvironmentId + "; Error message: " + msg);
91 request.setProgress(100L);
92 request.setLastModifiedBy("APIH");
93 request.setOperationalEnvId(operationalEnvironmentId);
94 if(request.getAction() == null){
95 request.setRequestAction(UNKNOWN);
97 if(request.getRequestScope() == null){
98 request.setRequestScope(UNKNOWN);
100 Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis());
101 request.setEndTime(endTimeStamp);
102 infraActiveRequestsRepository.save(request);
104 msoLogger.debug("End of " + classMethodMessage);