summaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp/action-library-rest/action-library-rest-services/src/main/java/org/openecomp/sdcrests/action/rest/services/ActionsImpl.java
blob: 14c9782fac796876d8cf41b24c27d7b4e4305f29 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
='n399' href='#n399'>399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * 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
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdcrests.action.rest.services;

import static org.openecomp.sdc.action.ActionConstants.ACTION_REQUEST_PARAM_NAME;
import static org.openecomp.sdc.action.ActionConstants.ACTION_REQUEST_PARAM_SUPPORTED_MODELS;
import static org.openecomp.sdc.action.ActionConstants.ARTIFACT_FILE;
import static org.openecomp.sdc.action.ActionConstants.ARTIFACT_NAME;
import static org.openecomp.sdc.action.ActionConstants.BE_FQDN;
import static org.openecomp.sdc.action.ActionConstants.CATEGORY_LOG_LEVEL;
import static org.openecomp.sdc.action.ActionConstants.CLIENT_IP;
import static org.openecomp.sdc.action.ActionConstants.ERROR_DESCRIPTION;
import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_CATEGORY;
import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_MODEL;
import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_NAME;
import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_NONE;
import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_OPEN_ECOMP_COMPONENT;
import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_VENDOR;
import static org.openecomp.sdc.action.ActionConstants.INSTANCE_UUID;
import static org.openecomp.sdc.action.ActionConstants.LOCAL_ADDR;
import static org.openecomp.sdc.action.ActionConstants.MAX_ACTION_ARTIFACT_SIZE;
import static org.openecomp.sdc.action.ActionConstants.MDC_ASDC_INSTANCE_UUID;
import static org.openecomp.sdc.action.ActionConstants.PARTNER_NAME;
import static org.openecomp.sdc.action.ActionConstants.REMOTE_HOST;
import static org.openecomp.sdc.action.ActionConstants.REQUEST_EMPTY_BODY;
import static org.openecomp.sdc.action.ActionConstants.REQUEST_ID;
import static org.openecomp.sdc.action.ActionConstants.REQUEST_TYPE_CREATE_ACTION;
import static org.openecomp.sdc.action.ActionConstants.REQUEST_TYPE_UPDATE_ACTION;
import static org.openecomp.sdc.action.ActionConstants.REQUEST_TYPE_VERSION_ACTION;
import static org.openecomp.sdc.action.ActionConstants.SERVICE_INSTANCE_ID;
import static org.openecomp.sdc.action.ActionConstants.SERVICE_METRIC_BEGIN_TIMESTAMP;
import static org.openecomp.sdc.action.ActionConstants.SERVICE_NAME;
import static org.openecomp.sdc.action.ActionConstants.STATUS;
import static org.openecomp.sdc.action.ActionConstants.STATUS_CODE;
import static org.openecomp.sdc.action.ActionConstants.SUPPORTED_COMPONENTS_ID;
import static org.openecomp.sdc.action.ActionConstants.SUPPORTED_MODELS_VERSION_ID;
import static org.openecomp.sdc.action.ActionConstants.TIMESTAMP;
import static org.openecomp.sdc.action.ActionConstants.UPDATED_BY;
import static org.openecomp.sdc.action.ActionConstants.X_OPEN_ECOMP_INSTANCE_ID_HEADER_PARAM;
import static org.openecomp.sdc.action.ActionConstants.X_OPEN_ECOMP_REQUEST_ID_HEADER_PARAM;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_CHECKSUM_ERROR_CODE;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_INVALID_NAME;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_INVALID_NAME_CODE;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_INVALID_PROTECTION_CODE;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_READ_FILE_ERROR;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_TOO_BIG_ERROR;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_TOO_BIG_ERROR_CODE;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ENTITY_NOT_EXIST;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ENTITY_NOT_EXIST_CODE;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_FILTER_MULTIPLE_QUERY_PARAM_NOT_SUPPORTED;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_INVALID_INSTANCE_ID_CODE;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_INVALID_PARAM_CODE;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_INVALID_REQUEST_BODY_CODE;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_INVALID_REQUEST_ID_CODE;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_INVALID_SEARCH_CRITERIA;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_MULT_SEARCH_CRITERIA;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_REQUEST_ARTIFACT_CHECKSUM_ERROR;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_REQUEST_ARTIFACT_INVALID_PROTECTION_VALUE;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_REQUEST_ARTIFACT_OPERATION_ALLOWED;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_REQUEST_BODY_EMPTY;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_REQUEST_CONTENT_TYPE_INVALID;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_REQUEST_FILTER_PARAM_INVALID;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_REQUEST_INVALID_GENERIC_CODE;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_REQUEST_INVALID_NAME;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_REQUEST_MISSING_MANDATORY_PARAM;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_REQUEST_OPEN_ECOMP_INSTANCE_ID_INVALID;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_REQUEST_OPEN_ECOMP_REQUEST_ID_INVALID;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_UNSUPPORTED_OPERATION;
import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_UPDATE_NOT_ALLOWED_CODE;
import static org.openecomp.sdc.action.util.ActionUtil.actionErrorLogProcessor;
import static org.openecomp.sdc.action.util.ActionUtil.actionLogPostProcessor;
import static org.openecomp.sdc.action.util.ActionUtil.getUtcDateStringFromTimestamp;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Response;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.core.utilities.json.JsonUtil;
import org.openecomp.sdc.action.ActionConstants;
import org.openecomp.sdc.action.ActionManager;
import org.openecomp.sdc.action.errors.ActionErrorConstants;
import org.openecomp.sdc.action.errors.ActionException;
import org.openecomp.sdc.action.logging.CategoryLogLevel;
import org.openecomp.sdc.action.logging.StatusCode;
import org.openecomp.sdc.action.types.Action;
import org.openecomp.sdc.action.types.ActionArtifact;
import org.openecomp.sdc.action.types.ActionArtifactProtection;
import org.openecomp.sdc.action.types.ActionRequest;
import org.openecomp.sdc.action.types.OpenEcompComponent;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdcrests.action.rest.Actions;
import org.openecomp.sdcrests.action.rest.mapping.MapActionToActionResponseDto;
import org.openecomp.sdcrests.action.types.ActionResponseDto;
import org.openecomp.sdcrests.action.types.ActionVersionDto;
import org.openecomp.sdcrests.action.types.ListResponseWrapper;
import org.openecomp.sdcrests.wrappers.StringWrapperResponse;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

/**
 * Implements various CRUD API that can be performed on Action
 */
@SuppressWarnings("ALL")
@Named
@Service("actions")
@Scope(value = "prototype")
@Validated
public class ActionsImpl implements Actions {

  private static final Logger LOGGER = LoggerFactory.getLogger(ActionsImpl.class);
  @Autowired
  private ActionManager actionManager;
  private String whitespaceCharacters = "\\s"       /* dummy empty string for homogeneity */
      + "\\u0009" // CHARACTER TABULATION
      + "\\u000A" // LINE FEED (LF)
      + "\\u000B" // LINE TABULATION
      + "\\u000C" // FORM FEED (FF)
      + "\\u000D" // CARRIAGE RETURN (CR)
      + "\\u0020" // SPACE
      + "\\u0085" // NEXT LINE (NEL)
      + "\\u00A0" // NO-BREAK SPACE
      + "\\u1680" // OGHAM SPACE MARK
      + "\\u180E" // MONGOLIAN VOWEL SEPARATOR
      + "\\u2000" // EN QUAD
      + "\\u2001" // EM QUAD
      + "\\u2002" // EN SPACE
      + "\\u2003" // EM SPACE
      + "\\u2004" // THREE-PER-EM SPACE
      + "\\u2005" // FOUR-PER-EM SPACE
      + "\\u2006" // SIX-PER-EM SPACE
      + "\\u2007" // FIGURE SPACE
      + "\\u2008" // PUNCTUATION SPACE
      + "\\u2009" // THIN SPACE
      + "\\u200A" // HAIR SPACE
      + "\\u2028" // LINE SEPARATOR
      + "\\u2029" // PARAGRAPH SEPARATOR
      + "\\u202F" // NARROW NO-BREAK SPACE
      + "\\u205F" // MEDIUM MATHEMATICAL SPACE
      + "\\u3000" // IDEOGRAPHIC SPACE
      ;
  private String invalidFilenameChars = "#<>$+%!`&*'|{}?\"=/:@\\\\";
  private String whitespaceRegex = ".*[" + whitespaceCharacters + "].*";
  private String invalidFilenameRegex = ".*[" + whitespaceCharacters + invalidFilenameChars + "].*";

  /**
   * Calculate the checksum for a given input
   *
   * @param input Byte array for which the checksum has to be calculated
   * @return Calculated checksum of the input byte array
   */
  private static String calculateCheckSum(byte[] input) {
    String checksum = null;
    if (input != null) {
      checksum = DigestUtils.md5Hex(input);
    }
    return checksum;
  }

  @Override
  public Response getActionsByActionInvariantUuId(String invariantID, String actionUUID,
                                                  HttpServletRequest servletRequest) {
    ListResponseWrapper responseList = new ListResponseWrapper();

    try {
      LOGGER.debug(" entering getActionsByActionInvariantUuId ");
      initializeRequestMDC(servletRequest, invariantID, ActionRequest.GET_ACTIONS_INVARIANT_ID);
      MDC.put(SERVICE_INSTANCE_ID, invariantID);

      if (StringUtils.isEmpty(servletRequest.getQueryString())) {
        responseList = getActionsByInvId(servletRequest, invariantID);
      } else {
        Response response = getActionByUUID(servletRequest, invariantID, actionUUID);
        actionLogPostProcessor(StatusCode.COMPLETE, true);
        return response;
      }
    } catch (ActionException exception) {
      actionLogPostProcessor(StatusCode.ERROR, exception.getErrorCode(), exception.getDescription(), true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, exception.getErrorCode(), exception.getDescription());
      LOGGER.error("");
      throw exception;
    } catch (Exception exception) {
      actionLogPostProcessor(StatusCode.ERROR, true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, ACTION_INTERNAL_SERVER_ERR_CODE,
          ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
      LOGGER.error("");
      throw exception;
    }

    LOGGER.debug(" exit getActionsByActionInvariantUuId ");
    actionLogPostProcessor(StatusCode.COMPLETE, true);
    return Response.ok(responseList).build();
  }

  private ListResponseWrapper getActionsByInvId(HttpServletRequest servletRequest,
                                                String invariantID) {
    LOGGER.debug(" entering getActionsByInvId with invariantID= " + invariantID);
    ListResponseWrapper responseList = new ListResponseWrapper();
    if (StringUtils.isEmpty(servletRequest.getQueryString())) {
      Map<String, String> errorMap = validateRequestHeaders(servletRequest);
      Map<String, String> queryParamErrors = validateQueryParam(invariantID);
      errorMap.putAll(queryParamErrors);
      if (errorMap.isEmpty()) {
        List<Action> actions = actionManager.getActionsByActionInvariantUuId(invariantID);
        List<ActionResponseDto> versionList = new ArrayList<>();
        for (Action action : actions) {
          ActionResponseDto responseDTO = createResponseDTO(action);
          versionList.add(responseDTO);
        }
        responseList.setVersions(versionList);
        responseList.setActionList(null);

      } else {
        checkAndThrowError(errorMap);
      }
    }
    LOGGER.debug(" exit getActionsByInvId with invariantID= " + invariantID);
    return responseList;
  }

  private Response getActionByUUID(HttpServletRequest servletRequest, String invariantID,
                                   String actionUUID) throws ActionException {
    int noOfFilterParams = 0;
    Response response = null;
    LOGGER.debug(" entering getActionByUUID with invariantID= " + invariantID + " and actionUUID= " +
        actionUUID);
    if (!StringUtils.isEmpty(actionUUID)) {
      noOfFilterParams++;
      response = getActionsByUniqueID(actionUUID, servletRequest, invariantID);
    }
    if (noOfFilterParams == 0) {
      throw new ActionException(ACTION_INVALID_SEARCH_CRITERIA,
          ACTION_REQUEST_FILTER_PARAM_INVALID);
    }

    LOGGER.debug(" exit getActionByUUID with invariantID= " + invariantID + " and actionUUID= " +
        actionUUID);
    return response;
  }

  @Override
  public Response getOpenEcompComponents(HttpServletRequest servletRequest) {
    try {
      LOGGER.debug(" entering getEcompComponents ");
      initializeRequestMDC(servletRequest, "", ActionRequest.GET_OPEN_ECOMP_COMPONENTS);
      //Validate request syntax before passing to the manager
      Map<String, String> errorMap = validateRequestHeaders(servletRequest);
      checkAndThrowError(errorMap);
      ListResponseWrapper response = new ListResponseWrapper();
      List<OpenEcompComponent> openEcompComponents = actionManager.getOpenEcompComponents();
      response.setActionList(null);
      response.setComponentList(openEcompComponents);
      LOGGER.debug(" exit getEcompComponents ");
      actionLogPostProcessor(StatusCode.COMPLETE, true);
      return Response.ok(response).build();
    } catch (ActionException exception) {
      actionLogPostProcessor(StatusCode.ERROR, exception.getErrorCode(), exception.getDescription(), true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, exception.getErrorCode(), exception.getDescription());
      LOGGER.error("");
      throw exception;
    } catch (Exception exception) {
      actionLogPostProcessor(StatusCode.ERROR, true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, ACTION_INTERNAL_SERVER_ERR_CODE,
          ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
      LOGGER.error("");
      throw exception;
    }
  }

  @Override
  public Response getFilteredActions(String vendor, String category, String name, String modelID,
                                     String componentID, HttpServletRequest servletRequest) {
    try {
      LOGGER.debug(" entering getFilteredActions ");
      Response response;
      initializeRequestMDC(servletRequest, "", ActionRequest.GET_FILTERED_ACTIONS);
      int noOfFilterParams = getNoOfFilterParams(vendor, category, name, modelID, componentID);
      if (StringUtils.isEmpty(servletRequest.getQueryString())) {
        response = getAllActions(servletRequest);
        LOGGER.debug(" exit getFilteredActions ");
        actionLogPostProcessor(StatusCode.COMPLETE, true);
        return response;
      }
      validateNoOfFilterParamsExactly1(noOfFilterParams);
      if (!StringUtils.isEmpty(vendor)) {
        response = getActionsByVendor(vendor, servletRequest);
      } else if (!StringUtils.isEmpty(category)) {
        response = getActionsByCategory(category, servletRequest);
      } else if (!StringUtils.isEmpty(name)) {
        response = getActionsByName(name, servletRequest);
      } else if (!StringUtils.isEmpty(modelID)) {
        response = getActionsByModel(modelID, servletRequest);
      } else if (!StringUtils.isEmpty(componentID)) {
        response = getActionsByOpenEcompComponents(componentID, servletRequest);
      } else {
        throw new ActionException(ACTION_INVALID_PARAM_CODE, ACTION_REQUEST_FILTER_PARAM_INVALID);
      }

      LOGGER.debug(" exit getFilteredActions ");
      actionLogPostProcessor(StatusCode.COMPLETE, true);
      return response;
    } catch (ActionException exception) {
      actionLogPostProcessor(StatusCode.ERROR, exception.getErrorCode(), exception.getDescription(), true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, exception.getErrorCode(), exception.getDescription());
      LOGGER.error("");
      throw exception;
    } catch (Exception exception) {
      actionLogPostProcessor(StatusCode.ERROR, true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, ACTION_INTERNAL_SERVER_ERR_CODE,
          ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
      LOGGER.error("");
      throw exception;
    }
  }

  private void validateNoOfFilterParamsExactly1(int noOfFilterParams) {
    if (noOfFilterParams > 1) {
      throw new ActionException(ACTION_MULT_SEARCH_CRITERIA,
          ACTION_FILTER_MULTIPLE_QUERY_PARAM_NOT_SUPPORTED);
    }
    if (noOfFilterParams == 0) {
      throw new ActionException(ACTION_INVALID_SEARCH_CRITERIA,
          ACTION_REQUEST_FILTER_PARAM_INVALID);
    }
  }

  private int getNoOfFilterParams(String vendor, String category, String name, String modelID, String componentID) {
    int noOfFilterParams = 0;
    if (!StringUtils.isEmpty(vendor)) {
      noOfFilterParams++;
    }
    if (!StringUtils.isEmpty(category)) {
      noOfFilterParams++;
    }
    if (!StringUtils.isEmpty(name)) {
      noOfFilterParams++;
    }
    if (!StringUtils.isEmpty(modelID)) {
      noOfFilterParams++;
    }
    if (!StringUtils.isEmpty(componentID)) {
      noOfFilterParams++;
    }
    return noOfFilterParams;
  }

  @Override
  public Response createAction(String requestJSON, HttpServletRequest servletRequest) {
    try {
      initializeRequestMDC(servletRequest, null, ActionRequest.CREATE_ACTION);
      LOGGER.debug(" entering API createAction ");
      Map<String, String> errorMap = validateRequestHeaders(servletRequest);
      Map<String, String> requestBodyErrors =
          validateRequestBody(REQUEST_TYPE_CREATE_ACTION, requestJSON);
      errorMap.putAll(requestBodyErrors);
      ActionResponseDto actionResponseDTO = new ActionResponseDto();
      if (errorMap.isEmpty()) {
        String user = servletRequest.getRemoteUser();
        Action action = JsonUtil.json2Object(requestJSON, Action.class);
        action.setData(requestJSON);
        Action responseAction = actionManager.createAction(action, user);
        MDC.put(SERVICE_INSTANCE_ID, responseAction.getActionInvariantUuId());
        new MapActionToActionResponseDto().doMapping(responseAction, actionResponseDTO);
      } else {
        checkAndThrowError(errorMap);
      }
      actionLogPostProcessor(StatusCode.COMPLETE, true);
      LOGGER.debug(" exit API createAction with ActionInvariantUUID= " + MDC.get(SERVICE_INSTANCE_ID));
      return Response.ok(actionResponseDTO).build();
    } catch (ActionException exception) {
      actionLogPostProcessor(StatusCode.ERROR, exception.getErrorCode(), exception.getDescription(), true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, exception.getErrorCode(), exception.getDescription());
      LOGGER.error("");
      throw exception;
    } catch (Exception exception) {
      actionLogPostProcessor(StatusCode.ERROR, true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, ACTION_INTERNAL_SERVER_ERR_CODE,
          ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
      LOGGER.error(exception.getMessage());
      throw exception;
    }

  }

  @Override
  public Response updateAction(String invariantUUID, String requestJSON,
                               HttpServletRequest servletRequest) {
    ActionResponseDto actionResponseDTO = null;
    try {
      initializeRequestMDC(servletRequest, invariantUUID, ActionRequest.UPDATE_ACTION);
      Map<String, String> errorMap = validateRequestHeaders(servletRequest);
      Map<String, String> requestBodyErrors =
          validateRequestBody(REQUEST_TYPE_UPDATE_ACTION, requestJSON);
      errorMap.putAll(requestBodyErrors);
      actionResponseDTO = new ActionResponseDto();
      if (errorMap.isEmpty()) {
        String user = servletRequest.getRemoteUser();
        Action action = JsonUtil.json2Object(requestJSON, Action.class);
        action.setActionInvariantUuId(invariantUUID);
        action.setData(requestJSON);
        Action updatedAction = actionManager.updateAction(action, user);
        new MapActionToActionResponseDto().doMapping(updatedAction, actionResponseDTO);
      } else {
        checkAndThrowError(errorMap);
      }
      actionLogPostProcessor(StatusCode.COMPLETE, true);
    } catch (ActionException exception) {
      actionLogPostProcessor(StatusCode.ERROR, exception.getErrorCode(), exception.getDescription(), true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, exception.getErrorCode(), exception.getDescription());
      LOGGER.error("");
      throw exception;
    } catch (Exception exception) {
      actionLogPostProcessor(StatusCode.ERROR, true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, ACTION_INTERNAL_SERVER_ERR_CODE,
          ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
      LOGGER.error(exception.getMessage());
      throw exception;
    }

    return Response.ok(actionResponseDTO).build();
  }

  @Override
  public Response deleteAction(String actionInvariantUUID, HttpServletRequest servletRequest) {
    try {
      initializeRequestMDC(servletRequest, actionInvariantUUID, ActionRequest.DELETE_ACTION);
      Map<String, String> errorMap = validateRequestHeaders(servletRequest);
      if (errorMap.isEmpty()) {
        String user = servletRequest.getRemoteUser();
        actionManager.deleteAction(actionInvariantUUID, user);
      } else {
        checkAndThrowError(errorMap);
      }

      actionLogPostProcessor(StatusCode.COMPLETE, true);
      return Response.ok(new ActionResponseDto()).build();
    } catch (ActionException exception) {
      actionLogPostProcessor(StatusCode.ERROR, exception.getErrorCode(), exception.getDescription(), true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, exception.getErrorCode(), exception.getDescription());
      LOGGER.error(MDC.get(ERROR_DESCRIPTION));
      throw exception;
    } catch (Exception exception) {
      actionLogPostProcessor(StatusCode.ERROR, true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, ACTION_INTERNAL_SERVER_ERR_CODE,
          ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
      LOGGER.error(exception.getMessage());
      throw exception;
    }
  }

  @Override
  public Response actOnAction(String invariantUUID, String requestJSON,
                              HttpServletRequest servletRequest) {
    Response response = null;
    try {
      initializeRequestMDC(servletRequest, invariantUUID, ActionRequest.ACTION_VERSIONING);
      LOGGER.debug("entering actOnAction with invariantUUID= " + invariantUUID + " and requestJSON= " +
          requestJSON);
      Map<String, String> errorMap = validateRequestHeaders(servletRequest);
      Map<String, String> requestBodyErrors =
          validateRequestBody(REQUEST_TYPE_VERSION_ACTION, requestJSON);
      errorMap.putAll(requestBodyErrors);

      ActionVersionDto versionDTO = JsonUtil.json2Object(requestJSON, ActionVersionDto.class);
      checkAndThrowError(errorMap);

      String status = versionDTO.getStatus();
      Action action = new Action();
      String user = servletRequest.getRemoteUser();
      switch (status) {
        case "Checkout":
          action = actionManager.checkout(invariantUUID, user);
          break;
        case "Undo_Checkout":
          actionManager.undoCheckout(invariantUUID, user);
          StringWrapperResponse responseText = new StringWrapperResponse();
          responseText.setValue(ActionConstants.UNDO_CHECKOUT_RESPONSE_TEXT);
          response = Response
              .status(Response.Status.OK)
              .entity(responseText)
              .build();
          return response;
        case "Checkin":
          action = actionManager.checkin(invariantUUID, user);
          break;
        case "Submit":
          action = actionManager.submit(invariantUUID, user);
          break;
        default:
          throw new ActionException(ACTION_INVALID_PARAM_CODE,
              String.format(ACTION_UNSUPPORTED_OPERATION, status));
      }

      ActionResponseDto actionResponseDTO = new ActionResponseDto();
      new MapActionToActionResponseDto().doMapping(action, actionResponseDTO);
      response = Response.ok(actionResponseDTO).build();
      actionLogPostProcessor(StatusCode.COMPLETE, true);
    } catch (ActionException exception) {
      actionLogPostProcessor(StatusCode.ERROR, exception.getErrorCode(), exception.getDescription(), true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, exception.getErrorCode(), exception.getDescription());
      LOGGER.error(MDC.get(ERROR_DESCRIPTION));
      throw exception;
    } catch (Exception exception) {
      actionLogPostProcessor(StatusCode.ERROR, true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, ACTION_INTERNAL_SERVER_ERR_CODE,
          ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
      LOGGER.error(exception.getMessage());
      throw exception;
    } finally {
      LOGGER.debug("exit actOnAction with invariantUUID= " + invariantUUID + " and requestJSON= " +
          requestJSON);
    }
    return response;
  }

  @Override
  public Response uploadArtifact(String actionInvariantUUID,
                                 String artifactName,
                                 String artifactLabel,
                                 String artifactCategory,
                                 String artifactDescription,
                                 String artifactProtection,
                                 String checksum,
                                 Attachment artifactToUpload,
                                 HttpServletRequest servletRequest) {
    Response response = null;
    try {
      initializeRequestMDC(servletRequest, actionInvariantUUID, ActionRequest.UPLOAD_ARTIFACT);
      LOGGER.debug("entering uploadArtifact with actionInvariantUuId= " + actionInvariantUUID +
          "artifactName= " + artifactName);
      response =
          uploadArtifactInternal(actionInvariantUUID, artifactName, artifactLabel, artifactCategory,
              artifactDescription, artifactProtection, checksum, artifactToUpload, servletRequest);
      actionLogPostProcessor(StatusCode.COMPLETE, true);
      LOGGER.debug("exiting uploadArtifact with actionInvariantUuId= " + actionInvariantUUID +
          "artifactName= " + artifactName);
    } catch (ActionException exception) {
      actionLogPostProcessor(StatusCode.ERROR, exception.getErrorCode(), exception.getDescription(), true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, exception.getErrorCode(), exception.getDescription());
      LOGGER.error(MDC.get(ERROR_DESCRIPTION));
      throw exception;
    } catch (Exception exception) {
      actionLogPostProcessor(StatusCode.ERROR, true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, ACTION_INTERNAL_SERVER_ERR_CODE,
          ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
      LOGGER.error(exception.getMessage());
      throw exception;
    }

    LOGGER.debug("exiting uploadArtifact with actionInvariantUuId= " + actionInvariantUUID +
        "artifactName= " + artifactName);
    return response;
  }

  private Response uploadArtifactInternal(String actionInvariantUUID, String artifactName,
                                          String artifactLabel, String artifactCategory,
                                          String artifactDescription, String artifactProtection,
                                          String checksum, Attachment artifactToUpload,
                                          HttpServletRequest servletRequest) {
    byte[] payload = null;
    Map<String, String> errorMap = validateRequestHeaders(servletRequest);
    //Artifact name empty validation
    if (StringUtils.isEmpty(artifactName)) {
      errorMap.put(ACTION_REQUEST_INVALID_GENERIC_CODE,
          ACTION_REQUEST_MISSING_MANDATORY_PARAM + ARTIFACT_NAME);
    } else {
      //Artifact name syntax check for whitespaces and invalid characters
      if (artifactName.matches(invalidFilenameRegex)) {
        errorMap.put(ACTION_ARTIFACT_INVALID_NAME_CODE, ACTION_ARTIFACT_INVALID_NAME);
      }
    }

    //Content-Type Header Validation
    String contentType = servletRequest.getContentType();
    if (StringUtils.isEmpty(contentType)) {
      errorMap.put(ACTION_REQUEST_INVALID_GENERIC_CODE, ACTION_REQUEST_CONTENT_TYPE_INVALID);
    }

    if (artifactToUpload == null) {
      throw new ActionException(ACTION_REQUEST_INVALID_GENERIC_CODE,
          ACTION_REQUEST_MISSING_MANDATORY_PARAM + ARTIFACT_FILE);
    }

    try (InputStream artifactInputStream = artifactToUpload.getDataHandler().getInputStream()) {
      payload = FileUtils.toByteArray(artifactInputStream);
    } catch (IOException exception) {
      LOGGER.error(ACTION_ARTIFACT_READ_FILE_ERROR, exception);
      throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE, ACTION_ARTIFACT_READ_FILE_ERROR);
    }

    //Validate Artifact size
    if (payload != null && payload.length > MAX_ACTION_ARTIFACT_SIZE) {
      throw new ActionException(ACTION_ARTIFACT_TOO_BIG_ERROR_CODE, ACTION_ARTIFACT_TOO_BIG_ERROR);
    }

    //Validate Checksum
    if (StringUtils.isEmpty(checksum) || !checksum.equalsIgnoreCase(calculateCheckSum(payload))) {
      errorMap.put(ACTION_ARTIFACT_CHECKSUM_ERROR_CODE, ACTION_REQUEST_ARTIFACT_CHECKSUM_ERROR);
    }

    //Validate artifact protection values
    if (StringUtils.isEmpty(artifactProtection)) {
      artifactProtection = ActionArtifactProtection.readWrite.name();
    }

    if (!artifactProtection.equals(ActionArtifactProtection.readOnly.name()) &&
        !artifactProtection.equals(ActionArtifactProtection.readWrite.name())) {
      errorMap.put(ACTION_ARTIFACT_INVALID_PROTECTION_CODE,
          ACTION_REQUEST_ARTIFACT_INVALID_PROTECTION_VALUE);
    }

    ActionArtifact uploadedArtifact = new ActionArtifact();
    if (errorMap.isEmpty()) {
      String user = servletRequest.getRemoteUser();
      ActionArtifact upload = new ActionArtifact();
      upload.setArtifactName(artifactName);
      upload.setArtifactLabel(artifactLabel);
      upload.setArtifactDescription(artifactDescription);
      upload.setArtifact(payload);
      upload.setArtifactCategory(artifactCategory);
      upload.setArtifactProtection(artifactProtection);
      uploadedArtifact = actionManager.uploadArtifact(upload, actionInvariantUUID, user);
    } else {
      checkAndThrowError(errorMap);
    }
    return Response.ok(uploadedArtifact).build();
  }

  @Override
  public Response downloadArtifact(String actionUUID, String artifactUUID,
                                   HttpServletRequest servletRequest) {
    Response response = null;
    try {
      initializeRequestMDC(servletRequest, "", ActionRequest.DOWNLOAD_ARTIFACT);
      LOGGER.debug(
          " entering downloadArtifact with actionUUID= " + actionUUID + " and artifactUUID= " +
              artifactUUID);
      response = downloadArtifactInternal(actionUUID, artifactUUID, servletRequest);
      actionLogPostProcessor(StatusCode.COMPLETE, true);
    } catch (ActionException exception) {
      actionLogPostProcessor(StatusCode.ERROR, exception.getErrorCode(), exception.getDescription(), true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, exception.getErrorCode(), exception.getDescription());
      LOGGER.error(MDC.get(ERROR_DESCRIPTION));
      throw exception;
    } catch (Exception exception) {
      actionLogPostProcessor(StatusCode.ERROR, true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, ACTION_INTERNAL_SERVER_ERR_CODE,
          ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
      LOGGER.error(exception.getMessage());
      throw exception;
    }

    LOGGER.debug(" exit downloadArtifact with actionUUID= " + actionUUID + " and artifactUUID= " +
        artifactUUID);
    return response;
  }

  private Response downloadArtifactInternal(String actionUUID, String artifactUUID,
                                            HttpServletRequest servletRequest) {
    Response response;
    ActionArtifact actionartifact = null;
    Map<String, String> errorMap = validateRequestHeaders(servletRequest);
    Map<String, String> queryParamErrors = validateQueryParam(actionUUID);
    errorMap.putAll(queryParamErrors);
    queryParamErrors = validateQueryParam(artifactUUID);
    errorMap.putAll(queryParamErrors);
    if (errorMap.isEmpty()) {
      actionartifact = actionManager.downloadArtifact(actionUUID, artifactUUID);
    } else {
      checkAndThrowError(errorMap);
    }
    response = createArtifactDownloadResponse(actionartifact);
    return response;
  }

  @Override
  public Response deleteArtifact(String actionInvariantUUID, String artifactUUID,
                                 HttpServletRequest servletRequest) {
    Response response = null;
    try {
      initializeRequestMDC(servletRequest, actionInvariantUUID, ActionRequest.DELETE_ARTIFACT);
      LOGGER.debug(" entering deleteArtifact with actionInvariantUuId= " + actionInvariantUUID +
          " and artifactUUID= " + artifactUUID);
      response = deleteArtifactInternal(actionInvariantUUID, artifactUUID, servletRequest);
      LOGGER.debug(" exit deleteArtifact with actionInvariantUuId= " + actionInvariantUUID +
          " and artifactUUID= " + artifactUUID);
      actionLogPostProcessor(StatusCode.COMPLETE, true);
    } catch (ActionException exception) {
      actionLogPostProcessor(StatusCode.ERROR, exception.getErrorCode(), exception.getDescription(), true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, exception.getErrorCode(), exception.getDescription());
      LOGGER.error(MDC.get(ERROR_DESCRIPTION));
      throw exception;
    } catch (Exception exception) {
      actionLogPostProcessor(StatusCode.ERROR, true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, ACTION_INTERNAL_SERVER_ERR_CODE,
          ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
      LOGGER.error(exception.getMessage());
      throw exception;
    }

    return response;
  }

  private Response deleteArtifactInternal(String actionInvariantUUID, String artifactUUID,
                                          HttpServletRequest servletRequest) {
    Map<String, String> errorMap = validateRequestHeaders(servletRequest);
    Map<String, String> queryParamErrors = validateQueryParam(actionInvariantUUID);
    errorMap.putAll(queryParamErrors);
    queryParamErrors = validateQueryParam(artifactUUID);
    errorMap.putAll(queryParamErrors);
    if (errorMap.isEmpty()) {
      actionManager
          .deleteArtifact(actionInvariantUUID, artifactUUID, servletRequest.getRemoteUser());
    } else {
      checkAndThrowError(errorMap);
    }
    return Response.ok().build();
  }

  @Override
  public Response updateArtifact(String actionInvariantUUID, String artifactUUID,
                                 String artifactName, String artifactLabel, String artifactCategory,
                                 String artifactDescription, String artifactProtection,
                                 String checksum, Attachment artifactToUpdate,
                                 HttpServletRequest servletRequest) {
    Response response = null;
    LOGGER.debug(" entering updateArtifact with actionInvariantUuId= " + actionInvariantUUID +
        " and artifactUUID= " + artifactUUID + " and artifactName= " + artifactName +
        " and artifactLabel= " + artifactLabel + " and artifactCategory= " + artifactCategory +
        " and artifactDescription= " + artifactDescription + " and artifactProtection= " +
        artifactProtection + " and checksum= " + checksum);
    try {
      initializeRequestMDC(servletRequest, actionInvariantUUID, ActionRequest.UPDATE_ARTIFACT);
      response =
          updateArtifactInternal(actionInvariantUUID, artifactUUID, artifactName, artifactLabel,
              artifactCategory, artifactDescription, artifactProtection, checksum, artifactToUpdate,
              servletRequest);
      actionLogPostProcessor(StatusCode.COMPLETE, true);
    } catch (ActionException exception) {
      actionLogPostProcessor(StatusCode.ERROR, exception.getErrorCode(), exception.getDescription(), true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, exception.getErrorCode(), exception.getDescription());
      LOGGER.error(MDC.get(ERROR_DESCRIPTION));
      throw exception;
    } catch (Exception exception) {
      actionLogPostProcessor(StatusCode.ERROR, true);
      actionErrorLogProcessor(CategoryLogLevel.ERROR, ACTION_INTERNAL_SERVER_ERR_CODE,
          ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
      LOGGER.error(exception.getMessage());
      throw exception;
    }

    LOGGER.debug(" exit updateArtifact with actionInvariantUuId= " + actionInvariantUUID +
        " and artifactUUID= " + artifactUUID + " and artifactName= " + artifactName +
        " and artifactLabel= " + artifactLabel + " and artifactCategory= " + artifactCategory +
        " and artifactDescription= " + artifactDescription + " and artifactProtection= " +
        artifactProtection + " and checksum= " + checksum);
    return response;
  }

  private Response updateArtifactInternal(String actionInvariantUUID, String artifactUUID,
                                          String artifactName, String artifactLabel,
                                          String artifactCategory, String artifactDescription,
                                          String artifactProtection, String checksum,
                                          Attachment artifactToUpdate,
                                          HttpServletRequest servletRequest) {
    byte[] payload = null;
    Map<String, String> errorMap = validateRequestHeaders(servletRequest);

    //Content-Type Header Validation
    String contentType = servletRequest.getContentType();
    if (StringUtils.isEmpty(contentType)) {
      errorMap.put(ACTION_REQUEST_INVALID_GENERIC_CODE, ACTION_REQUEST_CONTENT_TYPE_INVALID);
    }

    if (artifactToUpdate != null) {

      try (InputStream artifactInputStream = artifactToUpdate.getDataHandler().getInputStream()) {
        payload = FileUtils.toByteArray(artifactInputStream);
      } catch (IOException exception) {
        LOGGER.error(ACTION_ARTIFACT_READ_FILE_ERROR, exception);
        throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE, ACTION_ARTIFACT_READ_FILE_ERROR);
      }

      //Validate Artifact size
      if (payload != null && payload.length > MAX_ACTION_ARTIFACT_SIZE) {
        throw new ActionException(ACTION_ARTIFACT_TOO_BIG_ERROR_CODE,
            ACTION_ARTIFACT_TOO_BIG_ERROR);
      }

      //Validate Checksum
      if (StringUtils.isEmpty(checksum) || !checksum.equalsIgnoreCase(calculateCheckSum(payload))) {
        errorMap.put(ACTION_ARTIFACT_CHECKSUM_ERROR_CODE, ACTION_REQUEST_ARTIFACT_CHECKSUM_ERROR);
      }
    }

    if (artifactProtection != null && (artifactProtection.isEmpty() ||
        (!artifactProtection.equals(ActionArtifactProtection.readOnly.name()) &&
            !artifactProtection.equals(ActionArtifactProtection.readWrite.name())))) {
      errorMap.put(ACTION_ARTIFACT_INVALID_PROTECTION_CODE,
          ACTION_REQUEST_ARTIFACT_INVALID_PROTECTION_VALUE);
    }

    ActionArtifact updateArtifact = new ActionArtifact();
    if (errorMap.isEmpty()) {
      String user = servletRequest.getRemoteUser();
      ActionArtifact update = new ActionArtifact();
      update.setArtifactUuId(artifactUUID);
      update.setArtifactName(artifactName);
      update.setArtifactLabel(artifactLabel);
      update.setArtifactDescription(artifactDescription);
      update.setArtifact(payload);
      update.setArtifactCategory(artifactCategory);
      update.setArtifactProtection(artifactProtection);
      actionManager.updateArtifact(update, actionInvariantUUID, user);
    } else {
      checkAndThrowError(errorMap);
    }
    return Response.ok().build();
  }

  /**
   * Get List of all actions
   */
  private Response getAllActions(HttpServletRequest servletRequest) {
    ListResponseWrapper responseList = null;
    Map<String, String> errorMap = validateRequestHeaders(servletRequest);
    if (errorMap.isEmpty()) {
      List<Action> actions = actionManager.getFilteredActions(FILTER_TYPE_NONE, null);
      responseList = createResponse(actions);
    } else {
      checkAndThrowError(errorMap);
    }

    return Response.ok(responseList).build();
  }

  /**
   * Get Actions by OPENECOMP component ID
   */
  private Response getActionsByOpenEcompComponents(String componentID,
                                                   HttpServletRequest servletRequest) {
    ListResponseWrapper responseList = null;
    Map<String, String> errorMap = validateRequestHeaders(servletRequest);
    Map<String, String> queryParamErrors = validateQueryParam(componentID);
    errorMap.putAll(queryParamErrors);
    if (errorMap.isEmpty()) {
      List<Action> actions =
          actionManager.getFilteredActions(FILTER_TYPE_OPEN_ECOMP_COMPONENT, componentID);
      responseList = createResponse(actions);
    } else {
      checkAndThrowError(errorMap);
    }
    return Response.ok(responseList).build();
  }

  /**
   * Get Actions by Model ID
   */
  private Response getActionsByModel(String modelId, HttpServletRequest servletRequest) {
    ListResponseWrapper responseList = null;
    Map<String, String> errorMap = validateRequestHeaders(servletRequest);
    Map<String, String> queryParamErrors = validateQueryParam(modelId);
    errorMap.putAll(queryParamErrors);
    if (errorMap.isEmpty()) {
      List<Action> actions = actionManager.getFilteredActions(FILTER_TYPE_MODEL, modelId);
      responseList = createResponse(actions);
    } else {
      checkAndThrowError(errorMap);
    }
    return Response.ok(responseList).build();
  }

  /**
   * Get all actions with given action name
   */
  private Response getActionsByName(String name, HttpServletRequest servletRequest) {
    ListResponseWrapper responseList = null;
    Map<String, String> errorMap = validateRequestHeaders(servletRequest);
    Map<String, String> queryParamErrors = validateQueryParam(name);
    errorMap.putAll(queryParamErrors);
    if (errorMap.isEmpty()) {
      List<Action> actions = actionManager.getFilteredActions(FILTER_TYPE_NAME, name);
      responseList = createResponse(actions);
    } else {
      checkAndThrowError(errorMap);
    }
    return Response.ok(responseList).build();
  }

  /**
   * Get an action with given ActionUUID
   */
  private Response getActionsByUniqueID(String actionUUID, HttpServletRequest servletRequest,
                                        String actionInvariantUUID) {
    LOGGER.debug(
        " entering getActionByUUID with invariantID= " + actionInvariantUUID + " and actionUUID= " +
            actionUUID);
    Map<String, Object> responseDTO = new LinkedHashMap<>();
    Map<String, String> errorMap = validateRequestHeaders(servletRequest);
    Map<String, String> queryParamErrors = validateQueryParam(actionUUID);
    errorMap.putAll(queryParamErrors);
    if (errorMap.isEmpty()) {
      Action action = actionManager.getActionsByActionUuId(actionUUID);
      if (action.getActionInvariantUuId() != null &&
          action.getActionInvariantUuId().equalsIgnoreCase(actionInvariantUUID)) {
        responseDTO = JsonUtil.json2Object(action.getData(), LinkedHashMap.class);
        responseDTO.put(STATUS, action.getStatus().name());
        responseDTO.put(TIMESTAMP, getUtcDateStringFromTimestamp(action.getTimestamp()));
        responseDTO.put(UPDATED_BY, action.getUser());
      } else {
        throw new ActionException(ACTION_ENTITY_NOT_EXIST_CODE, ACTION_ENTITY_NOT_EXIST);
      }
    } else {
      checkAndThrowError(errorMap);
    }
    LOGGER.debug(
        " exit getActionByUUID with invariantID= " + actionInvariantUUID + " and actionUUID= " +
            actionUUID);
    return Response.ok(responseDTO).build();
  }

  /**
   * Get all actions with given Vendor Name
   */
  private Response getActionsByVendor(String vendor, HttpServletRequest servletRequest) {
    //Validate request syntax before passing to the manager
    ListResponseWrapper responseList = null;
    Map<String, String> errorMap = validateRequestHeaders(servletRequest);
    Map<String, String> queryParamErrors = validateQueryParam(vendor);
    errorMap.putAll(queryParamErrors);
    if (errorMap.isEmpty()) {
      List<Action> actions = actionManager.getFilteredActions(FILTER_TYPE_VENDOR, vendor);
      responseList = createResponse(actions);
    } else {
      checkAndThrowError(errorMap);
    }
    return Response.ok(responseList).build();
  }

  /**
   * Get all actions with given Category Name
   */
  private Response getActionsByCategory(String category, HttpServletRequest servletRequest) {
    //Validate request syntax before passing to the manager
    ListResponseWrapper responseList = null;
    Map<String, String> errorMap = validateRequestHeaders(servletRequest);
    Map<String, String> queryParamErrors = validateQueryParam(category);
    errorMap.putAll(queryParamErrors);
    if (errorMap.isEmpty()) {
      List<Action> actions = actionManager.getFilteredActions(FILTER_TYPE_CATEGORY, category);
      responseList = createResponse(actions);
    } else {
      checkAndThrowError(errorMap);
    }
    return Response.ok(responseList).build();
  }

  /**
   * Validates mandatory headers in the request
   *
   * @param servletRequest Servlet Request object
   * @return Map of error codes and description found in the request headers
   */
  private Map<String, String> validateRequestHeaders(HttpServletRequest servletRequest) {
    Map<String, String> errorMap = new LinkedHashMap<>();
    //Syntactic generic request parameter validations
    String openEcompRequestId = servletRequest.getHeader(X_OPEN_ECOMP_REQUEST_ID_HEADER_PARAM);
    if (StringUtils.isEmpty(openEcompRequestId)) {
      errorMap.put(ACTION_INVALID_REQUEST_ID_CODE, ACTION_REQUEST_OPEN_ECOMP_REQUEST_ID_INVALID);
    }

    String opemnEcompInstanceId = servletRequest.getHeader(X_OPEN_ECOMP_INSTANCE_ID_HEADER_PARAM);
    if (StringUtils.isEmpty(opemnEcompInstanceId)) {
      errorMap.put(ACTION_INVALID_INSTANCE_ID_CODE, ACTION_REQUEST_OPEN_ECOMP_INSTANCE_ID_INVALID);
    }
    return errorMap;
  }

  /**
   * Validates query parameter in the request
   *
   * @param queryParam Query Parameter to be validated
   * @return Map of error codes and description found in the query parameter
   */
  private Map<String, String> validateQueryParam(String queryParam) {
    Map<String, String> queryParamErrors = new LinkedHashMap<>();
    if (StringUtils.isEmpty(queryParam)) {
      queryParamErrors
          .put(ACTION_INVALID_PARAM_CODE, ACTION_REQUEST_MISSING_MANDATORY_PARAM + queryParam);
    }
    return queryParamErrors;
  }

  /**
   * Validate request body based on request type
   *
   * @param requestJSON Raw request json body as string
   * @return Map of error codes and description found in the request body
   */
  private Map<String, String> validateRequestBody(String requestType, String requestJSON) {
    Map<String, String> requestBodyErrorMap = new LinkedHashMap<>();
    if (StringUtils.isEmpty(requestJSON) || requestJSON.equals(REQUEST_EMPTY_BODY)) {
      requestBodyErrorMap.put(ACTION_INVALID_REQUEST_BODY_CODE, ACTION_REQUEST_BODY_EMPTY);
    } else {
      if(requestType == ActionConstants.REQUEST_TYPE_CREATE_ACTION){
        //placeholder for future implementation
      }
      if(requestType == ActionConstants.REQUEST_TYPE_UPDATE_ACTION){
        //Semantic request specific validations
        Action action = JsonUtil.json2Object(requestJSON, Action.class);
        if(StringUtils.isEmpty(action.getName())){
          setErrorValue(ACTION_REQUEST_INVALID_GENERIC_CODE, ACTION_REQUEST_PARAM_NAME,
              requestBodyErrorMap);
        } else {
          //Added check for action names not allowing whitespaces
          if (action.getName().matches(whitespaceRegex)){
            requestBodyErrorMap.put(ACTION_ARTIFACT_INVALID_NAME_CODE, ACTION_REQUEST_INVALID_NAME);
          }
        }

        if(action.getSupportedModels() != null && !isIDPresentInMap(action.getSupportedModels(),
            SUPPORTED_MODELS_VERSION_ID)){
          setErrorValue(ACTION_REQUEST_INVALID_GENERIC_CODE,
              ACTION_REQUEST_PARAM_SUPPORTED_MODELS, requestBodyErrorMap);
        }
        if(action.getSupportedComponents() != null && !isIDPresentInMap(action
            .getSupportedComponents(), SUPPORTED_COMPONENTS_ID)){
          setErrorValue(ACTION_REQUEST_INVALID_GENERIC_CODE,
              ACTION_REQUEST_PARAM_SUPPORTED_MODELS, requestBodyErrorMap);
        }
        if(action.getArtifacts() != null){
          setErrorValue(ACTION_UPDATE_NOT_ALLOWED_CODE,
              ACTION_REQUEST_ARTIFACT_OPERATION_ALLOWED, requestBodyErrorMap);
        }
      }

    }
    return requestBodyErrorMap;
  }

  /**
   * Populates Given Error Map with Given Error Code and Error MEssage
   */
  private void setErrorValue(String key, String message, Map<String, String> errorMap) {
    String errorMessage = errorMap.get(key);
    if (errorMessage != null) {
      message = errorMessage + ", " + message;
    } else {
      if(key == ACTION_REQUEST_INVALID_GENERIC_CODE)
        message = ACTION_REQUEST_MISSING_MANDATORY_PARAM + message;
    }
    errorMap.put(key, message);
  }

  /**
   * Returns true if given key exists in List of HashMap
   */
  private boolean isIDPresentInMap(List<HashMap<String, String>> map, String idName) {
    if (map != null && !map.isEmpty()) {
      for (HashMap<String, String> entry : map) {
        if (StringUtils.isEmpty(entry.get(idName))) {
          return false;
        }
      }
    }
    return true;
  }

  /**
   * @throws ActionException if given ErrorMap is not empty. All error messages at given time are
   *                         thrown in one single exception
   */
  private void checkAndThrowError(Map<String, String> errorMap) {
    if (errorMap.size() > 1) {
      //Multiple errors detected .. Send the response with a common error code for multiple errors
      throw new ActionException(ACTION_REQUEST_INVALID_GENERIC_CODE,
          StringUtils.join(errorMap.values(), ", "));
    } else if (errorMap.size() == 1) {
      String svcPolicyExceptionCode = errorMap.entrySet().iterator().next().getKey();
      throw new ActionException(svcPolicyExceptionCode,
          errorMap.get(svcPolicyExceptionCode));
    }
  }

  /**
   * Populates ActionResponseDto based on given Action
   */
  private ActionResponseDto createResponseDTO(Action action) {
    String data = action.getData();
    ActionResponseDto responseDTO = JsonUtil.json2Object(data, ActionResponseDto.class);
    responseDTO.setStatus(action.getStatus().name());
    responseDTO.setTimestamp(getUtcDateStringFromTimestamp(action.getTimestamp()));
    //if(!action.getUser().equals(DELETE_ACTION_USER))
    responseDTO.setUpdatedBy(action.getUser());
    return responseDTO;
  }

  /**
   * Creates response based on given list of actions
   */
  private ListResponseWrapper createResponse(List<Action> actions) {
    ListResponseWrapper responseList = new ListResponseWrapper();
    for (Action action : actions) {
      ActionResponseDto responseDTO = createResponseDTO(action);
      responseList.add(responseDTO);
    }
    return responseList;
  }


  private Response createArtifactDownloadResponse(ActionArtifact actionartifact) {
    if (actionartifact != null && actionartifact.getArtifact() != null) {
      byte[] artifactsBytes = actionartifact.getArtifact();
      File artifactFile = new File(actionartifact.getArtifactName());
      try (FileOutputStream fos = new FileOutputStream(artifactFile)) {
        fos.write(artifactsBytes);
      } catch (IOException exception) {
        LOGGER.error(ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG, exception);
        throw new ActionException(ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE,
            ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
      }
      Response.ResponseBuilder responseBuilder = Response.ok(artifactFile);
      responseBuilder.header("Content-Disposition",
          "attachment; filename=" + actionartifact.getArtifactName());
      responseBuilder.header("Content-MD5", CalcMD5CheckSum(artifactsBytes));
      responseBuilder.header("Content-Length", artifactFile.length());
      return responseBuilder.build();
    } else {
      throw new ActionException(ActionErrorConstants.ACTION_ARTIFACT_ENTITY_NOT_EXIST_CODE,
          ActionErrorConstants.ACTION_ARTIFACT_ENTITY_NOT_EXIST);
    }
  }

  /**
   * Initialize MDC for logging the current request
   *
   * @param actionInvariantId Action Invariant Id if available (null otherwise)
   * @param servletRequest    Request Contecxt object
   * @param requestType       Current action request (CRUD of Action, Artifact, Version operations)
   */
  private void initializeRequestMDC(HttpServletRequest servletRequest, String actionInvariantId,
                                    ActionRequest requestType) {
    MDC.put(REQUEST_ID, servletRequest.getHeader(X_OPEN_ECOMP_REQUEST_ID_HEADER_PARAM));
    MDC.put(PARTNER_NAME, servletRequest.getRemoteUser());
    MDC.put(INSTANCE_UUID, MDC_ASDC_INSTANCE_UUID);
    MDC.put(SERVICE_METRIC_BEGIN_TIMESTAMP, String.valueOf(System.currentTimeMillis()));
    MDC.put(STATUS_CODE, StatusCode.COMPLETE.name());
    MDC.put(SERVICE_NAME, requestType.name());
    MDC.put(CLIENT_IP, MDC.get(REMOTE_HOST));
    MDC.put(SERVICE_INSTANCE_ID, actionInvariantId);
    MDC.put(LOCAL_ADDR, MDC.get("ServerIPAddress"));
    MDC.put(BE_FQDN, MDC.get("ServerFQDN"));

    if (LOGGER.isDebugEnabled()) {
      MDC.put(CATEGORY_LOG_LEVEL, CategoryLogLevel.DEBUG.name());
    } else if (LOGGER.isInfoEnabled()) {
      MDC.put(CATEGORY_LOG_LEVEL, CategoryLogLevel.INFO.name());
    } else if (LOGGER.isWarnEnabled()) {
      MDC.put(CATEGORY_LOG_LEVEL, CategoryLogLevel.WARN.name());
    } else if (LOGGER.isErrorEnabled()) {
      MDC.put(CATEGORY_LOG_LEVEL, CategoryLogLevel.ERROR.name());
    }
  }

  private String CalcMD5CheckSum(byte[] input) {
    String checksum = null;
    if (input != null) {
      checksum = DigestUtils.md5Hex(input).toUpperCase();
      System.out.println("checksum : " + checksum);
    }
    return checksum;
  }
}