Catalog alignment
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / BeGenericServlet.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.servlets;
22
23 import com.fasterxml.jackson.databind.DeserializationFeature;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import com.fasterxml.jackson.databind.module.SimpleModule;
26 import com.google.common.annotations.VisibleForTesting;
27 import com.google.gson.Gson;
28 import com.google.gson.GsonBuilder;
29 import com.google.gson.reflect.TypeToken;
30 import fj.data.Either;
31 import org.json.simple.JSONArray;
32 import org.json.simple.JSONObject;
33 import org.json.simple.parser.JSONParser;
34 import org.json.simple.parser.ParseException;
35 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
36 import org.openecomp.sdc.be.components.impl.BaseBusinessLogic;
37 import org.openecomp.sdc.be.components.impl.CapabilitiesBusinessLogic;
38 import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
39 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
40 import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
41 import org.openecomp.sdc.be.components.impl.GenericArtifactBrowserBusinessLogic;
42 import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
43 import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
44 import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic;
45 import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic;
46 import org.openecomp.sdc.be.components.impl.ProductBusinessLogic;
47 import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
48 import org.openecomp.sdc.be.components.impl.RelationshipTypeBusinessLogic;
49 import org.openecomp.sdc.be.components.impl.RequirementBusinessLogic;
50 import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
51 import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
52 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
53 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
54 import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
55 import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic;
56 import org.openecomp.sdc.be.components.upgrade.UpgradeBusinessLogic;
57 import org.openecomp.sdc.be.config.BeEcompErrorManager;
58 import org.openecomp.sdc.be.dao.api.ActionStatus;
59 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
60 import org.openecomp.sdc.be.datatypes.enums.DeclarationTypeEnum;
61 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
62 import org.openecomp.sdc.be.ecomp.converters.AssetMetadataConverter;
63 import org.openecomp.sdc.be.impl.ComponentsUtils;
64 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
65 import org.openecomp.sdc.be.model.ComponentInstInputsMap;
66 import org.openecomp.sdc.be.model.PropertyConstraint;
67 import org.openecomp.sdc.be.model.PropertyDefinition;
68 import org.openecomp.sdc.be.model.User;
69 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
70 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintJacksonDeserializer;
71 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
72 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
73 import org.openecomp.sdc.be.user.UserBusinessLogic;
74 import org.openecomp.sdc.common.api.Constants;
75 import org.openecomp.sdc.common.log.wrappers.Logger;
76 import org.openecomp.sdc.common.servlets.BasicServlet;
77 import org.openecomp.sdc.exception.ResponseFormat;
78 import org.springframework.web.context.WebApplicationContext;
79
80 import javax.servlet.ServletContext;
81 import javax.servlet.http.HttpServletRequest;
82 import javax.ws.rs.core.Context;
83 import javax.ws.rs.core.Response;
84 import javax.ws.rs.core.Response.ResponseBuilder;
85 import java.io.IOException;
86 import java.lang.reflect.Type;
87 import java.util.HashMap;
88 import java.util.Iterator;
89 import java.util.List;
90 import java.util.Map;
91 import java.util.Map.Entry;
92 import java.util.Objects;
93 import java.util.Set;
94 import java.util.function.Supplier;
95
96 public class BeGenericServlet extends BasicServlet {
97
98     public BeGenericServlet(UserBusinessLogic userAdminManager,
99         ComponentsUtils componentsUtils) {
100         this.userAdminManager = userAdminManager;
101         this.componentsUtils = componentsUtils;
102     }
103
104     @Context
105     protected HttpServletRequest servletRequest;
106
107     private static final Logger log = Logger.getLogger(BeGenericServlet.class);
108
109     private static final String PROPERTY_NAME_REGEX = "[\\w,\\d,_]+";
110
111     private UserBusinessLogic userAdminManager;
112     protected ComponentsUtils componentsUtils;
113
114     /******************** New error response mechanism
115      * @param requestErrorWrapper **************/
116
117     protected Response buildErrorResponse(ResponseFormat requestErrorWrapper) {
118         return Response.status(requestErrorWrapper.getStatus()).entity(gson.toJson(requestErrorWrapper.getRequestError())).build();
119     }
120
121     protected Response buildGeneralErrorResponse() {
122         return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
123     }
124
125     protected Response buildOkResponse(Object entity) {
126         return buildOkResponseStatic(entity);
127     }
128
129     private static Response buildOkResponseStatic(Object entity) {
130         return Response.status(Response.Status.OK)
131             .entity(entity)
132             .build();
133     }
134
135     public HttpServletRequest getServletRequest() {
136         return servletRequest;
137     }
138
139     @VisibleForTesting
140     public void setRequestServlet(HttpServletRequest request) {this.servletRequest = request;}
141
142     protected Response buildOkResponse(ResponseFormat errorResponseWrapper, Object entity) {
143         return buildOkResponse(errorResponseWrapper, entity, null);
144     }
145
146     protected Response buildOkResponse(ResponseFormat errorResponseWrapper, Object entity, Map<String, String> additionalHeaders) {
147         int status = errorResponseWrapper.getStatus();
148         ResponseBuilder responseBuilder = Response.status(status);
149         if (entity != null) {
150             if (log.isTraceEnabled())
151                 log.trace("returned entity is {}", entity.toString());
152             responseBuilder = responseBuilder.entity(entity);
153         }
154         if (additionalHeaders != null) {
155             for (Entry<String, String> additionalHeader : additionalHeaders.entrySet()) {
156                 String headerName = additionalHeader.getKey();
157                 String headerValue = additionalHeader.getValue();
158                 if (log.isTraceEnabled())
159                     log.trace("Adding header {} with value {} to the response", headerName, headerValue);
160                 responseBuilder.header(headerName, headerValue);
161             }
162         }
163         return responseBuilder.build();
164     }
165
166     /*******************************************************************************************************/
167     protected Either<User, ResponseFormat> getUser(final HttpServletRequest request, String userId) {
168         User user;
169         try {
170             user = getUserAdminManager(request.getSession().getServletContext()).getUser(userId, false);
171             return Either.left(user);
172         } catch (ComponentException ce) {
173             log.info("createResource method - user is not listed. userId= {}", userId);
174             ResponseFormat errorResponse = getComponentsUtils().getResponseFormat(ce);
175             user = new User("", "", userId, "", null, null);
176             getComponentsUtils().auditResource(errorResponse, user, "", AuditingActionEnum.CHECKOUT_RESOURCE);
177             return Either.right(errorResponse);
178         }
179     }
180
181     UserBusinessLogic getUserAdminManager(ServletContext context) {
182         return getClassFromWebAppContext(context, () -> UserBusinessLogic.class);
183     }
184
185     protected GenericArtifactBrowserBusinessLogic getGenericArtifactBrowserBL(ServletContext context) {
186         return getClassFromWebAppContext(context, () -> GenericArtifactBrowserBusinessLogic.class);
187     }
188
189     protected ResourceBusinessLogic getResourceBL(ServletContext context) {
190         return getClassFromWebAppContext(context, () -> ResourceBusinessLogic.class);
191     }
192
193     InterfaceOperationBusinessLogic getInterfaceOperationBL(ServletContext context) {
194         return getClassFromWebAppContext(context, () -> InterfaceOperationBusinessLogic.class);
195     }
196
197     protected CapabilitiesBusinessLogic getCapabilitiesBL(ServletContext context) {
198         return getClassFromWebAppContext(context, () -> CapabilitiesBusinessLogic.class);
199     }
200
201     protected RelationshipTypeBusinessLogic getRelationshipTypeBL(ServletContext context) {
202         return getClassFromWebAppContext(context, () -> RelationshipTypeBusinessLogic.class);
203     }
204     protected RequirementBusinessLogic getRequirementBL(ServletContext context) {
205         return getClassFromWebAppContext(context, () -> RequirementBusinessLogic.class);
206     }
207     ComponentsCleanBusinessLogic getComponentCleanerBL(ServletContext context) {
208         return getClassFromWebAppContext(context, () -> ComponentsCleanBusinessLogic.class);
209     }
210
211     protected ServiceBusinessLogic getServiceBL(ServletContext context) {
212         return getClassFromWebAppContext(context, () -> ServiceBusinessLogic.class);
213     }
214
215     ProductBusinessLogic getProductBL(ServletContext context) {
216         return getClassFromWebAppContext(context, () -> ProductBusinessLogic.class);
217     }
218
219     protected ArtifactsBusinessLogic getArtifactBL(ServletContext context) {
220         return getClassFromWebAppContext(context, () -> ArtifactsBusinessLogic.class);
221     }
222     protected UpgradeBusinessLogic getUpgradeBL(ServletContext context) {
223         return getClassFromWebAppContext(context, () -> UpgradeBusinessLogic.class);
224     }
225
226     protected ElementBusinessLogic getElementBL(ServletContext context) {
227         return getClassFromWebAppContext(context, () -> ElementBusinessLogic.class);
228     }
229
230     protected AssetMetadataConverter getAssetUtils(ServletContext context) {
231         return getClassFromWebAppContext(context, () -> AssetMetadataConverter.class);
232     }
233
234     protected LifecycleBusinessLogic getLifecycleBL(ServletContext context) {
235         return getClassFromWebAppContext(context, () -> LifecycleBusinessLogic.class);
236     }
237
238     <T> T getClassFromWebAppContext(ServletContext context, Supplier<Class<T>> businessLogicClassGen) {
239         WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
240         WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
241         return webApplicationContext.getBean(businessLogicClassGen.get());
242     }
243
244     GroupBusinessLogic getGroupBL(ServletContext context) {
245
246         WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
247         WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
248         return webApplicationContext.getBean(GroupBusinessLogic.class);
249     }
250
251     protected ComponentInstanceBusinessLogic getComponentInstanceBL(ServletContext context) {
252         WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
253         WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
254         return webApplicationContext.getBean(ComponentInstanceBusinessLogic.class);
255     }
256
257     protected ComponentsUtils getComponentsUtils() {
258         ServletContext context = this.servletRequest.getSession().getServletContext();
259
260         WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
261         WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
262         return webApplicationContext.getBean(ComponentsUtils.class);
263     }
264
265     /**
266      * Used to support Unit Test.<br>
267      * Header Params are not supported in Unit Tests
268      *
269      * @return
270      */
271     String initHeaderParam(String headerValue, HttpServletRequest request, String headerName) {
272         String retValue;
273         if (headerValue != null) {
274             retValue = headerValue;
275         } else {
276             retValue = request.getHeader(headerName);
277         }
278         return retValue;
279     }
280
281     protected String getContentDispositionValue(String artifactFileName) {
282         return new StringBuilder().append("attachment; filename=\"").append(artifactFileName).append("\"").toString();
283     }
284
285
286
287     protected ComponentBusinessLogic getComponentBL(ComponentTypeEnum componentTypeEnum, ServletContext context) {
288         ComponentBusinessLogic businessLogic;
289         switch (componentTypeEnum) {
290             case RESOURCE:
291                 businessLogic = getResourceBL(context);
292                 break;
293             case SERVICE:
294                 businessLogic = getServiceBL(context);
295                 break;
296             case PRODUCT:
297                 businessLogic = getProductBL(context);
298                 break;
299             case RESOURCE_INSTANCE:
300                 businessLogic = getResourceBL(context);
301                 break;
302             default:
303                 BeEcompErrorManager.getInstance().logBeSystemError("getComponentBL");
304                 throw new IllegalArgumentException("Illegal component type:" + componentTypeEnum.getValue());
305         }
306         return businessLogic;
307     }
308
309     <T> T convertJsonToObjectOfClass(String json, Class<T> clazz) {
310         T object = null;
311         ObjectMapper mapper = new ObjectMapper()
312             .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
313             .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
314         try {
315             log.trace("Starting to convert json to object. Json=\n{}", json);
316
317             SimpleModule module = new SimpleModule("customDeserializationModule");
318             module.addDeserializer(PropertyConstraint.class, new PropertyConstraintJacksonDeserializer());
319             mapper.registerModule(module);
320
321             object = mapper.readValue(json, clazz);
322             if (object != null) {
323                 return object;
324             } else {
325                 BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
326                 log.debug("The object of class {} is null after converting from json. ", clazz);
327                 throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
328             }
329         } catch (IOException e) {
330             BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
331             log.debug("The exception {} occurred upon json to object convertation. Json=\n{}", e, json);
332             throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
333         }
334     }
335
336     protected Either<Map<String, PropertyDefinition>, ActionStatus> getPropertyModel(String componentId, String data) {
337         JSONParser parser = new JSONParser();
338         JSONObject root;
339         try {
340             Map<String, PropertyDefinition> properties = new HashMap<>();
341             root = (JSONObject) parser.parse(data);
342
343             Set entrySet = root.entrySet();
344             Iterator iterator = entrySet.iterator();
345             while (iterator.hasNext()) {
346                 Entry next = (Entry) iterator.next();
347                 String propertyName = (String) next.getKey();
348
349                 if(!isPropertyNameValid(propertyName)) {
350                     return Either.right(ActionStatus.INVALID_PROPERTY_NAME);
351                 }
352
353                 JSONObject value = (JSONObject) next.getValue();
354                 Either<PropertyDefinition, ActionStatus> propertyDefinitionEither =
355                         getPropertyDefinitionFromJson(componentId, propertyName, value);
356
357                 if(propertyDefinitionEither.isRight()) {
358                     return Either.right(propertyDefinitionEither.right().value());
359                 }
360
361                 properties.put(propertyName, propertyDefinitionEither.left().value());
362             }
363
364             return Either.left(properties);
365         } catch (ParseException e) {
366             log.info("Property conetnt is invalid - {}", data);
367             return Either.right(ActionStatus.INVALID_CONTENT);
368         }
369     }
370
371     protected boolean isPropertyNameValid(String propertyName) {
372         return Objects.nonNull(propertyName)
373                        && propertyName.matches(PROPERTY_NAME_REGEX);
374
375     }
376
377     private Either<PropertyDefinition, ActionStatus> getPropertyDefinitionFromJson(String componentId, String propertyName, JSONObject value) {
378         String jsonString = value.toJSONString();
379         Either<PropertyDefinition, ActionStatus> convertJsonToObject = convertJsonToObject(jsonString, PropertyDefinition.class);
380         if (convertJsonToObject.isRight()) {
381             return Either.right(convertJsonToObject.right().value());
382         }
383         PropertyDefinition propertyDefinition = convertJsonToObject.left().value();
384         String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(componentId, propertyName);
385         propertyDefinition.setUniqueId(uniqueId);
386
387         return Either.left(propertyDefinition);
388     }
389
390     protected Either<Map<String, PropertyDefinition>, ActionStatus> getPropertiesListForUpdate(String data) {
391
392         Map<String, PropertyDefinition> properties = new HashMap<>();
393         JSONParser parser = new JSONParser();
394         JSONArray jsonArray;
395
396         try {
397             jsonArray = (JSONArray) parser.parse(data);
398             for (Object jsonElement : jsonArray) {
399                 String propertyAsString = jsonElement.toString();
400                 Either<PropertyDefinition, ActionStatus> convertJsonToObject = convertJsonToObject(propertyAsString, PropertyDefinition.class);
401
402                 if (convertJsonToObject.isRight()) {
403                     return Either.right(convertJsonToObject.right().value());
404                 }
405
406                 PropertyDefinition propertyDefinition = convertJsonToObject.left().value();
407                 properties.put(propertyDefinition.getName(), propertyDefinition);
408             }
409
410             return Either.left(properties);
411         } catch (Exception e) {
412             log.info("Property content is invalid - {}", data);
413             return Either.right(ActionStatus.INVALID_CONTENT);
414         }
415
416     }
417
418
419     protected String propertyToJson(Map.Entry<String, PropertyDefinition> property) {
420         JSONObject root = new JSONObject();
421         String propertyName = property.getKey();
422         PropertyDefinition propertyDefinition = property.getValue();
423         JSONObject propertyDefinitionO = getPropertyDefinitionJSONObject(propertyDefinition);
424         root.put(propertyName, propertyDefinitionO);
425         propertyDefinition.getType();
426         return root.toString();
427     }
428
429     private JSONObject getPropertyDefinitionJSONObject(PropertyDefinition propertyDefinition) {
430
431         Either<String, ActionStatus> either = convertObjectToJson(propertyDefinition);
432         if (either.isRight()) {
433             return new JSONObject();
434         }
435         String value = either.left().value();
436         try {
437             JSONObject root = (JSONObject) new JSONParser().parse(value);
438             return root;
439         } catch (ParseException e) {
440             log.info("failed to convert input to json");
441             log.error("failed to convert to json", e);
442             return new JSONObject();
443         }
444
445     }
446
447     protected  <T> Either<T, ActionStatus> convertJsonToObject(String data, Class<T> clazz) {
448         T t = null;
449         Type constraintType = new TypeToken<PropertyConstraint>() {
450         }.getType();
451         Gson
452             gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyOperation.PropertyConstraintDeserialiser()).create();
453         try {
454             log.trace("convert json to object. json=\n {}", data);
455             t = gson.fromJson(data, clazz);
456             if (t == null) {
457                 log.info("object is null after converting from json");
458                 return Either.right(ActionStatus.INVALID_CONTENT);
459             }
460         } catch (Exception e) {
461             // INVALID JSON
462             log.info("failed to convert from json");
463             log.error("failed to convert from json", e);
464             return Either.right(ActionStatus.INVALID_CONTENT);
465         }
466         return Either.left(t);
467     }
468
469     private Either<String, ActionStatus> convertObjectToJson(PropertyDefinition propertyDefinition) {
470         Type constraintType = new TypeToken<PropertyConstraint>() {
471         }.getType();
472         Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyOperation.PropertyConstraintSerialiser()).create();
473         try {
474             log.trace("convert object to json. propertyDefinition= {}", propertyDefinition);
475             String json = gson.toJson(propertyDefinition);
476             if (json == null) {
477                 log.info("object is null after converting to json");
478                 return Either.right(ActionStatus.INVALID_CONTENT);
479             }
480             return Either.left(json);
481         } catch (Exception e) {
482             // INVALID JSON
483             log.info("failed to convert to json");
484             log.debug("failed to convert fto json", e);
485             return Either.right(ActionStatus.INVALID_CONTENT);
486         }
487
488     }
489
490     protected PropertyBusinessLogic getPropertyBL(ServletContext context) {
491         WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
492         WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
493         PropertyBusinessLogic propertytBl = webApplicationContext.getBean(PropertyBusinessLogic.class);
494         return propertytBl;
495     }
496
497     protected InputsBusinessLogic getInputBL(ServletContext context) {
498         WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
499         WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
500         return webApplicationContext.getBean(InputsBusinessLogic.class);
501     }
502
503     protected PolicyBusinessLogic getPolicyBL(ServletContext context) {
504         WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
505         WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
506         return webApplicationContext.getBean(PolicyBusinessLogic.class);
507     }
508
509     protected Either<ComponentInstInputsMap, ResponseFormat> parseToComponentInstanceMap(String componentJson, User user, ComponentTypeEnum componentType) {
510         return getComponentsUtils().convertJsonToObjectUsingObjectMapper(componentJson, user, ComponentInstInputsMap.class, AuditingActionEnum.CREATE_RESOURCE, componentType);
511     }
512
513     protected Response declareProperties(String userId, String componentId, String componentType,
514             String componentInstInputsMapObj, DeclarationTypeEnum typeEnum, HttpServletRequest request) {
515         ServletContext context = request.getSession().getServletContext();
516         String url = request.getMethod() + " " + request.getRequestURI();
517         log.debug("(get) Start handle request of {}", url);
518         Response response = null;
519
520         try {
521             BaseBusinessLogic businessLogic = getBlForPropertyDeclaration(typeEnum, context);
522
523             // get modifier id
524             User modifier = new User();
525             modifier.setUserId(userId);
526             log.debug("modifier id is {}", userId);
527             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
528             Either<ComponentInstInputsMap, ResponseFormat> componentInstInputsMapRes = parseToComponentInstanceMap(componentInstInputsMapObj, modifier, componentTypeEnum);
529             if (componentInstInputsMapRes.isRight()) {
530                 log.debug("failed to parse componentInstInputsMap");
531                 response = buildErrorResponse(componentInstInputsMapRes.right().value());
532                 return response;
533             }
534
535             Either<List<ToscaDataDefinition>, ResponseFormat> propertiesAfterDeclaration = businessLogic
536                                                                                .declareProperties(userId, componentId,
537                                                                                        componentTypeEnum,
538                                                                                        componentInstInputsMapRes.left().value());
539             if (propertiesAfterDeclaration.isRight()) {
540                 log.debug("failed to create inputs  for service: {}", componentId);
541                 return buildErrorResponse(propertiesAfterDeclaration.right().value());
542             }
543             Object properties = RepresentationUtils.toRepresentation(propertiesAfterDeclaration.left().value());
544             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
545
546         } catch (Exception e) {
547             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create inputs for service with id: " + componentId);
548             log.debug("Properties declaration failed with exception", e);
549             response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
550             return response;
551         }
552     }
553
554     public BaseBusinessLogic getBlForPropertyDeclaration(DeclarationTypeEnum typeEnum,
555                                                           ServletContext context) {
556         if(typeEnum.equals(DeclarationTypeEnum.POLICY)) {
557             return getPolicyBL(context);
558         }
559
560         return getInputBL(context);
561     }
562 }