90f214819562a482796a469f4853ca8a314e5a7b
[sdc.git] /
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.components.impl;
22
23 import java.util.List;
24
25 import javax.servlet.ServletContext;
26
27 import org.openecomp.sdc.be.config.BeEcompErrorManager;
28 import org.openecomp.sdc.be.config.ConfigurationManager;
29 import org.openecomp.sdc.be.dao.api.ActionStatus;
30 import org.openecomp.sdc.be.dao.graph.datatype.AdditionalInformationEnum;
31 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
32 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterInfo;
33 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
34 import org.openecomp.sdc.be.impl.ComponentsUtils;
35 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
36 import org.openecomp.sdc.be.model.AdditionalInformationDefinition;
37 import org.openecomp.sdc.be.model.User;
38 import org.openecomp.sdc.be.model.operations.api.IAdditionalInformationOperation;
39 import org.openecomp.sdc.be.model.operations.api.IElementOperation;
40 import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
41 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
42 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
43 import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
44 import org.openecomp.sdc.be.model.tosca.converters.StringConvertor;
45 import org.openecomp.sdc.be.model.tosca.validators.StringValidator;
46 import org.openecomp.sdc.common.api.Constants;
47 import org.openecomp.sdc.common.util.ValidationUtils;
48 import org.openecomp.sdc.exception.ResponseFormat;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
51 import org.springframework.stereotype.Component;
52 import org.springframework.web.context.WebApplicationContext;
53
54 import fj.data.Either;
55
56 @Component("additionalInformationBusinessLogic")
57 public class AdditionalInformationBusinessLogic extends BaseBusinessLogic {
58
59     private static final String CREATE_ADDITIONAL_INFORMATION = "CreateAdditionalInformation";
60
61     private static final String UPDATE_ADDITIONAL_INFORMATION = "UpdateAdditionalInformation";
62
63     private static final String DELETE_ADDITIONAL_INFORMATION = "DeleteAdditionalInformation";
64
65     private static final String GET_ADDITIONAL_INFORMATION = "GetAdditionalInformation";
66
67     private static final Logger log = LoggerFactory.getLogger(AdditionalInformationBusinessLogic.class);
68
69     @javax.annotation.Resource
70     private IAdditionalInformationOperation additionalInformationOperation = null;
71
72     @javax.annotation.Resource
73     private IGraphLockOperation graphLockOperation;
74
75     @javax.annotation.Resource
76     private ComponentsUtils componentsUtils;
77
78     protected static IElementOperation getElementDao(Class<IElementOperation> class1, ServletContext context) {
79         WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
80
81         WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
82
83         return webApplicationContext.getBean(class1);
84     }
85
86     /**
87      * Create new additional information on resource/service on graph
88      *
89      * @param resourceId
90      * @param propertyName
91      * @param newPropertyDefinition
92      * @param userId
93      * @return Either<PropertyDefinition, ActionStatus>
94      */
95     public Either<AdditionalInfoParameterInfo, ResponseFormat> createAdditionalInformation(NodeTypeEnum nodeType, String resourceId, AdditionalInfoParameterInfo additionalInfoParameterInfo, String additionalInformationUid, String userId) {
96
97         Either<User, ResponseFormat> resp = validateUserExists(userId, "create Additional Information", false);
98         if (resp.isRight()) {
99             return Either.right(resp.right().value());
100         }
101         Either<AdditionalInfoParameterInfo, ResponseFormat> result = null;
102
103         ResponseFormat responseFormat = verifyCanWorkOnComponent(nodeType, resourceId, userId);
104         if (responseFormat != null) {
105             result = Either.right(responseFormat);
106             return result;
107         }
108
109         // lock component
110         StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceId, nodeType);
111         if (!lockResult.equals(StorageOperationStatus.OK)) {
112             BeEcompErrorManager.getInstance().logBeFailedLockObjectError(CREATE_ADDITIONAL_INFORMATION, nodeType.getName(), resourceId);
113             log.info("Failed to lock component {} error - {}", resourceId, lockResult);
114             result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
115             return result;
116         }
117         try {
118             responseFormat = validateMaxSizeNotReached(nodeType, resourceId, additionalInfoParameterInfo);
119             if (responseFormat != null) {
120                 result = Either.right(responseFormat);
121                 return result;
122             }
123
124             // validate label
125             responseFormat = validateAndConvertKey(additionalInfoParameterInfo, CREATE_ADDITIONAL_INFORMATION);
126             if (responseFormat != null) {
127                 result = Either.right(responseFormat);
128                 return result;
129             }
130
131             // validate value
132             responseFormat = validateAndConvertValue(additionalInfoParameterInfo, CREATE_ADDITIONAL_INFORMATION);
133             if (responseFormat != null) {
134                 result = Either.right(responseFormat);
135                 return result;
136             }
137
138             Either<AdditionalInformationDefinition, StorageOperationStatus> addResult = additionalInformationOperation.createAdditionalInformationParameter(nodeType, resourceId, additionalInfoParameterInfo.getKey(),
139                     additionalInfoParameterInfo.getValue(), true);
140
141             if (addResult.isRight()) {
142                 StorageOperationStatus status = addResult.right().value();
143                 BeEcompErrorManager.getInstance().logBeSystemError(CREATE_ADDITIONAL_INFORMATION);
144                 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForAdditionalInformation(status);
145                 result = Either.right(componentsUtils.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType, AdditionalInformationEnum.Label));
146                 return result;
147
148             } else {
149                 AdditionalInformationDefinition informationDefinition = addResult.left().value();
150
151                 AdditionalInfoParameterInfo createdAI = findAdditionInformationKey(informationDefinition.getParameters(), additionalInfoParameterInfo.getKey());
152                 result = Either.left(createdAI);
153                 return result;
154             }
155
156         } finally {
157             commitOrRollback(result);
158             // unlock component
159             graphLockOperation.unlockComponent(resourceId, nodeType);
160         }
161
162     }
163
164     /**
165      * Validate the value format. Format the value.
166      *
167      * @param additionalInfoParameterInfo
168      * @return null in case of success. Otherwise response format.
169      */
170     private ResponseFormat validateAndConvertValue(AdditionalInfoParameterInfo additionalInfoParameterInfo, String context) {
171         ResponseFormat result = null;
172
173         String value = additionalInfoParameterInfo.getValue();
174         log.debug("Going to validate additional information value {}", value);
175
176         Either<String, ResponseFormat> valueValidRes = validateValue(value);
177         if (valueValidRes.isRight()) {
178             BeEcompErrorManager.getInstance().logBeInvalidValueError(context, additionalInfoParameterInfo.getValue(), "additional information value", "string");
179             result = valueValidRes.right().value();
180         } else {
181             String newValue = valueValidRes.left().value();
182             if (log.isTraceEnabled()) {
183                 if (value != null && false == value.equals(newValue)) {
184                     log.trace("The additional information value was normalized from {} to {}", value, newValue);
185                 }
186             }
187             additionalInfoParameterInfo.setValue(newValue);
188         }
189         return result;
190     }
191
192     /**
193      * @param additionalInfoParameterInfo
194      * @return
195      */
196     private ResponseFormat validateAndConvertKey(AdditionalInfoParameterInfo additionalInfoParameterInfo, String context) {
197
198         String key = additionalInfoParameterInfo.getKey();
199         log.debug("Going to validate additional information key {}", key);
200
201         ResponseFormat result = null;
202         ResponseFormat responseFormat;
203         Either<String, ResponseFormat> validateKeyRes = validateAndNormalizeKey(key);
204         if (validateKeyRes.isRight()) {
205             responseFormat = validateKeyRes.right().value();
206             BeEcompErrorManager.getInstance().logBeInvalidValueError(context, additionalInfoParameterInfo.getKey(), "additional information label", "string");
207             result = responseFormat;
208
209         } else {
210             String convertedKey = validateKeyRes.left().value();
211
212             if (log.isTraceEnabled()) {
213                 if (key != null && false == key.equals(convertedKey)) {
214                     log.trace("The additional information key {} was normalized to {}", key, convertedKey);
215                 }
216             }
217             additionalInfoParameterInfo.setKey(convertedKey);
218         }
219         return result;
220     }
221
222     /**
223      * verify that the maximal number of additional information properties has not been reached.
224      *
225      * @param nodeType
226      * @param componentId
227      * @param additionalInfoParameterInfo
228      * @return response format in case the maximal number has been reached.
229      */
230     private ResponseFormat validateMaxSizeNotReached(NodeTypeEnum nodeType, String componentId, AdditionalInfoParameterInfo additionalInfoParameterInfo) {
231
232         ResponseFormat result;
233         Integer additionalInformationMaxNumberOfKeys = ConfigurationManager.getConfigurationManager().getConfiguration().getAdditionalInformationMaxNumberOfKeys();
234
235         Either<Integer, StorageOperationStatus> checkRes = additionalInformationOperation.getNumberOfAdditionalInformationParameters(nodeType, componentId, true);
236         if (checkRes.isRight()) {
237             StorageOperationStatus status = checkRes.right().value();
238
239             ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForAdditionalInformation(status);
240             result = componentsUtils.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType, AdditionalInformationEnum.None);
241             return result;
242         }
243         Integer currentNumberOfProperties = checkRes.left().value();
244         if (currentNumberOfProperties >= additionalInformationMaxNumberOfKeys) {
245             log.info("The current number of additional information properties is {}. The maximum allowed additional information properties is {}", currentNumberOfProperties, currentNumberOfProperties);
246             result = componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED, additionalInfoParameterInfo, nodeType, AdditionalInformationEnum.None);
247             return result;
248         }
249
250         return null;
251     }
252
253     /**
254      * validate additional information value
255      *
256      * @param value
257      * @return
258      */
259     private Either<String, ResponseFormat> validateValue(String value) {
260
261         boolean isNonEmptyString = ValidationUtils.validateStringNotEmpty(value);
262         if (false == isNonEmptyString) {
263             return Either.right(componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED));
264         }
265
266         boolean valid = StringValidator.getInstance().isValid(value, null);
267         if (false == valid) {
268             return Either.right(componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS, new AdditionalInfoParameterInfo(null, value), null, AdditionalInformationEnum.Value));
269         }
270
271         String converted = StringConvertor.getInstance().convert(value, null, null);
272
273         return Either.left(converted);
274     }
275
276     private AdditionalInfoParameterInfo findAdditionInformationKey(List<AdditionalInfoParameterInfo> parameters, String key) {
277
278         for (AdditionalInfoParameterInfo infoParameterInfo : parameters) {
279             if (infoParameterInfo.getKey().equals(key)) {
280                 return infoParameterInfo;
281             }
282         }
283         return null;
284     }
285
286     /**
287      * validate and normalize the key
288      *
289      * @param additionalInfoParameterInfo
290      * @return
291      */
292     private Either<String, ResponseFormat> validateAndNormalizeKey(String key) {
293
294         AdditionalInfoParameterInfo additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
295         additionalInfoParameterInfo.setKey(key);
296
297         key = ValidationUtils.normalizeAdditionalInformation(key);
298         boolean isNonEmptyString = ValidationUtils.validateStringNotEmpty(key);
299         if (false == isNonEmptyString) {
300             return Either.right(componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED, null, null, AdditionalInformationEnum.Label));
301         }
302         boolean isValidString = ValidationUtils.validateAdditionalInformationKeyName(key);
303         if (false == isValidString) {
304             if (false == ValidationUtils.validateLength(key, ValidationUtils.ADDITIONAL_INFORMATION_KEY_MAX_LENGTH)) {
305                 return Either.right(componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EXCEEDS_LIMIT, additionalInfoParameterInfo, null, AdditionalInformationEnum.Label));
306             }
307             return Either.right(componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS, additionalInfoParameterInfo, null, AdditionalInformationEnum.Label));
308         }
309
310         return Either.left(key);
311     }
312
313     /**
314      * update key and value of a given additional information.
315      *
316      * @param nodeType
317      * @param resourceId
318      * @param additionalInfoParameterInfo
319      * @param additionalInformationUid
320      *            - Future use
321      * @param userId
322      * @return
323      */
324     public Either<AdditionalInfoParameterInfo, ResponseFormat> updateAdditionalInformation(NodeTypeEnum nodeType, String resourceId, AdditionalInfoParameterInfo additionalInfoParameterInfo, String additionalInformationUid, String userId) {
325
326         Either<User, ResponseFormat> resp = validateUserExists(userId, "create Additional Information", false);
327         if (resp.isRight()) {
328             return Either.right(resp.right().value());
329         }
330         Either<AdditionalInfoParameterInfo, ResponseFormat> result = null;
331
332         ResponseFormat responseFormat = verifyCanWorkOnComponent(nodeType, resourceId, userId);
333         if (responseFormat != null) {
334             result = Either.right(responseFormat);
335             return result;
336         }
337         // lock component
338         StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceId, nodeType);
339         if (!lockResult.equals(StorageOperationStatus.OK)) {
340             BeEcompErrorManager.getInstance().logBeFailedLockObjectError(UPDATE_ADDITIONAL_INFORMATION, nodeType.getName(), resourceId);
341             log.info("Failed to lock component {} error - {}", resourceId, lockResult);
342             result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
343             return result;
344         }
345         try {
346
347             // validate input
348             responseFormat = validateAndConvertKey(additionalInfoParameterInfo, UPDATE_ADDITIONAL_INFORMATION);
349             if (responseFormat != null) {
350                 result = Either.right(responseFormat);
351                 return result;
352             }
353
354             responseFormat = validateAndConvertValue(additionalInfoParameterInfo, UPDATE_ADDITIONAL_INFORMATION);
355             if (responseFormat != null) {
356                 result = Either.right(responseFormat);
357                 return result;
358             }
359
360             Either<AdditionalInformationDefinition, StorageOperationStatus> addResult = additionalInformationOperation.updateAdditionalInformationParameter(nodeType, resourceId, additionalInfoParameterInfo.getUniqueId(),
361                     additionalInfoParameterInfo.getKey(), additionalInfoParameterInfo.getValue(), true);
362
363             if (addResult.isRight()) {
364                 StorageOperationStatus status = addResult.right().value();
365                 BeEcompErrorManager.getInstance().logBeSystemError(UPDATE_ADDITIONAL_INFORMATION);
366                 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForAdditionalInformation(status);
367                 result = Either.right(componentsUtils.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType, AdditionalInformationEnum.None));
368                 return result;
369             } else {
370                 AdditionalInformationDefinition informationDefinition = addResult.left().value();
371                 AdditionalInfoParameterInfo parameterInfo = findAdditionInformationKey(informationDefinition.getParameters(), additionalInfoParameterInfo.getKey());
372                 result = Either.left(parameterInfo);
373                 return result;
374             }
375
376         } finally {
377             commitOrRollback(result);
378             // unlock component
379             graphLockOperation.unlockComponent(resourceId, nodeType);
380         }
381
382     }
383
384     /**
385      * Delete an additional information label
386      *
387      * @param nodeType
388      * @param resourceId
389      * @param additionalInfoParameterInfo
390      * @param additionalInformationUid
391      *            - Null. Future use.
392      * @param userId
393      * @return
394      */
395     public Either<AdditionalInfoParameterInfo, ResponseFormat> deleteAdditionalInformation(NodeTypeEnum nodeType, String resourceId, AdditionalInfoParameterInfo additionalInfoParameterInfo, String additionalInformationUid, String userId) {
396
397         Either<User, ResponseFormat> resp = validateUserExists(userId, "delete Additional Information", false);
398         if (resp.isRight()) {
399             return Either.right(resp.right().value());
400         }
401         Either<AdditionalInfoParameterInfo, ResponseFormat> result = null;
402
403         ResponseFormat responseFormat = verifyCanWorkOnComponent(nodeType, resourceId, userId);
404         if (responseFormat != null) {
405             return Either.right(responseFormat);
406         }
407         // lock component
408         StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceId, nodeType);
409         if (!lockResult.equals(StorageOperationStatus.OK)) {
410             BeEcompErrorManager.getInstance().logBeFailedLockObjectError(DELETE_ADDITIONAL_INFORMATION, nodeType.getName(), resourceId);
411             log.info("Failed to lock component {} error - {}", resourceId, lockResult);
412             result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
413             return result;
414         }
415
416         try {
417
418             Either<AdditionalInfoParameterInfo, StorageOperationStatus> findIdRes = additionalInformationOperation.getAdditionalInformationParameter(nodeType, resourceId, additionalInfoParameterInfo.getUniqueId(), true);
419             if (findIdRes.isRight()) {
420                 StorageOperationStatus status = findIdRes.right().value();
421                 if (status != StorageOperationStatus.NOT_FOUND) {
422                     BeEcompErrorManager.getInstance().logBeSystemError(GET_ADDITIONAL_INFORMATION);
423                 }
424                 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForAdditionalInformation(status);
425                 result = Either.right(componentsUtils.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType, AdditionalInformationEnum.None));
426                 return result;
427             }
428
429             AdditionalInfoParameterInfo foundAdditionalInfo = findIdRes.left().value();
430
431             Either<AdditionalInformationDefinition, StorageOperationStatus> addResult = additionalInformationOperation.deleteAdditionalInformationParameter(nodeType, resourceId, additionalInfoParameterInfo.getUniqueId(), true);
432
433             if (addResult.isRight()) {
434                 StorageOperationStatus status = addResult.right().value();
435                 BeEcompErrorManager.getInstance().logBeDaoSystemError(DELETE_ADDITIONAL_INFORMATION);
436                 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForAdditionalInformation(status);
437                 result = Either.right(componentsUtils.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType, AdditionalInformationEnum.None));
438                 return result;
439             } else {
440                 result = Either.left(foundAdditionalInfo);
441                 return result;
442             }
443
444         } finally {
445             commitOrRollback(result);
446             // unlock component
447             graphLockOperation.unlockComponent(resourceId, nodeType);
448         }
449
450     }
451
452     /**
453      * @param nodeType
454      * @param resourceId
455      * @param additionalInfoParameterInfo
456      * @param additionalInformationUid
457      * @param userId
458      * @return
459      */
460     public Either<AdditionalInfoParameterInfo, ResponseFormat> getAdditionalInformation(NodeTypeEnum nodeType, String resourceId, AdditionalInfoParameterInfo additionalInfoParameterInfo, String additionalInformationUid, String userId) {
461
462         Either<User, ResponseFormat> resp = validateUserExists(userId, "get Additional Information", false);
463         if (resp.isRight()) {
464             return Either.right(resp.right().value());
465         }
466         Either<AdditionalInfoParameterInfo, ResponseFormat> result = null;
467
468         try {
469
470             Either<AdditionalInfoParameterInfo, StorageOperationStatus> findIdRes = additionalInformationOperation.getAdditionalInformationParameter(nodeType, resourceId, additionalInfoParameterInfo.getUniqueId(), true);
471
472             if (findIdRes.isRight()) {
473                 StorageOperationStatus status = findIdRes.right().value();
474                 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForAdditionalInformation(status);
475                 result = Either.right(componentsUtils.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType, AdditionalInformationEnum.None));
476             }
477
478             AdditionalInfoParameterInfo foundAdditionalInfo = findIdRes.left().value();
479
480             result = Either.left(foundAdditionalInfo);
481
482             return result;
483
484         } finally {
485             commitOrRollback(result);
486         }
487
488     }
489
490     /**
491      * Get all additional information properties of a given resource/service
492      *
493      * @param nodeType
494      * @param resourceId
495      * @param additionalInformationUid
496      *            - Future use
497      * @param userId
498      * @return
499      */
500     public Either<AdditionalInformationDefinition, ResponseFormat> getAllAdditionalInformation(NodeTypeEnum nodeType, String resourceId, String additionalInformationUid, String userId) {
501
502         Either<User, ResponseFormat> resp = validateUserExists(userId, "get All Additional Information", false);
503         if (resp.isRight()) {
504             return Either.right(resp.right().value());
505         }
506
507         Either<AdditionalInformationDefinition, ResponseFormat> result = null;
508
509         try {
510
511             Either<AdditionalInformationDefinition, TitanOperationStatus> findIdRes = additionalInformationOperation.getAllAdditionalInformationParameters(nodeType, resourceId, false);
512             if (findIdRes.isRight()) {
513                 StorageOperationStatus status = DaoStatusConverter.convertTitanStatusToStorageStatus(findIdRes.right().value());
514                 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForAdditionalInformation(status);
515                 result = Either.right(componentsUtils.getResponseFormatAdditionalProperty(actionStatus));
516             } else {
517                 AdditionalInformationDefinition informationDefinition = findIdRes.left().value();
518                 result = Either.left(informationDefinition);
519             }
520
521             return result;
522
523         } finally {
524             commitOrRollback(result);
525         }
526
527     }
528
529     private ResponseFormat verifyCanWorkOnComponent(NodeTypeEnum nodeType, String resourceId, String userId) {
530
531         switch (nodeType) {
532         case Resource:
533
534             // verify that resource is checked-out and the user is the last
535             // updater
536             if (!ComponentValidationUtils.canWorkOnComponent(resourceId, toscaOperationFacade, userId)) {
537                 return componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
538             }
539             break;
540         case Service:
541
542             // verify that resource is checked-out and the user is the last
543             // updater
544             if (!ComponentValidationUtils.canWorkOnComponent(resourceId, toscaOperationFacade, userId)) {
545                 return componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
546             }
547             break;
548         default:
549             return componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT, nodeType.getName());
550         }
551
552         return null;
553     }
554
555 }