2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.components.impl;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.EnumMap;
26 import java.util.HashMap;
27 import java.util.HashSet;
28 import java.util.Iterator;
29 import java.util.List;
31 import java.util.Map.Entry;
33 import java.util.function.Function;
34 import java.util.regex.Pattern;
35 import java.util.stream.Collectors;
37 import javax.servlet.ServletContext;
39 import org.apache.commons.lang3.tuple.ImmutablePair;
40 import org.openecomp.sdc.be.auditing.api.IAuditingManager;
41 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
42 import org.openecomp.sdc.be.components.impl.ImportUtils.Constants;
43 import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
44 import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaTagNamesEnum;
45 import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
46 import org.openecomp.sdc.be.config.BeEcompErrorManager;
47 import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
48 import org.openecomp.sdc.be.dao.api.ActionStatus;
49 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
50 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
51 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
52 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
53 import org.openecomp.sdc.be.impl.ComponentsUtils;
54 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
55 import org.openecomp.sdc.be.model.ArtifactDefinition;
56 import org.openecomp.sdc.be.model.CapabilityDefinition;
57 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
58 import org.openecomp.sdc.be.model.InterfaceDefinition;
59 import org.openecomp.sdc.be.model.LifecycleStateEnum;
60 import org.openecomp.sdc.be.model.PropertyDefinition;
61 import org.openecomp.sdc.be.model.RequirementDefinition;
62 import org.openecomp.sdc.be.model.Resource;
63 import org.openecomp.sdc.be.model.UploadResourceInfo;
64 import org.openecomp.sdc.be.model.User;
65 import org.openecomp.sdc.be.model.category.CategoryDefinition;
66 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
67 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
68 import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
69 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
70 import org.openecomp.sdc.be.model.operations.impl.CapabilityTypeOperation;
71 import org.openecomp.sdc.be.model.operations.impl.ResourceOperation;
72 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
73 import org.openecomp.sdc.common.config.EcompErrorName;
74 import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
75 import org.openecomp.sdc.common.util.ValidationUtils;
76 import org.openecomp.sdc.exception.ResponseFormat;
77 import org.slf4j.Logger;
78 import org.slf4j.LoggerFactory;
79 import org.springframework.beans.factory.annotation.Autowired;
80 import org.springframework.stereotype.Component;
81 import org.springframework.web.context.WebApplicationContext;
82 import org.yaml.snakeyaml.Yaml;
84 import fj.data.Either;
86 @Component("resourceImportManager")
87 public class ResourceImportManager {
89 private ServletContext servletContext;
92 private IAuditingManager auditingManager;
95 private ResourceBusinessLogic resourceBusinessLogic;
98 private IGraphLockOperation graphLockOperation;
101 protected ComponentsUtils componentsUtils;
104 protected ResourceOperation resourceOperation;
106 public final static Pattern PROPERTY_NAME_PATTERN_IGNORE_LENGTH = Pattern
107 .compile("[\\w\\-\\_\\d\\:]+");
109 protected CapabilityTypeOperation capabilityTypeOperation;
111 protected ToscaOperationFacade toscaOperationFacade;
113 private ResponseFormatManager responseFormatManager;
115 private static Logger log = LoggerFactory.getLogger(ResourceImportManager.class.getName());
117 public void setToscaOperationFacade(ToscaOperationFacade toscaOperationFacade) {
118 this.toscaOperationFacade = toscaOperationFacade;
121 public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> importNormativeResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean createNewVersion, boolean needLock) {
123 LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction();
124 lifecycleChangeInfo.setUserRemarks("certification on import");
125 Function<Resource, Either<Boolean, ResponseFormat>> validator = (resource) -> resourceBusinessLogic.validatePropertiesDefaultValues(resource);
127 return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, createNewVersion, needLock, null, null, false);
130 public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> importNormativeResourceFromCsar(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean createNewVersion, boolean needLock) {
132 LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction();
133 lifecycleChangeInfo.setUserRemarks("certification on import");
134 Function<Resource, Either<Boolean, ResponseFormat>> validator = (resource) -> resourceBusinessLogic.validatePropertiesDefaultValues(resource);
136 return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, createNewVersion, needLock, null, null, false);
139 public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> importCertifiedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, Function<Resource, Either<Boolean, ResponseFormat>> validationFunction,
140 LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean isInTransaction, boolean createNewVersion, boolean needLock, Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed) {
141 Resource resource = new Resource();
142 ImmutablePair<Resource, ActionStatus> responsePair = new ImmutablePair<>(resource, ActionStatus.CREATED);
143 Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> response = Either.left(responsePair);
145 String latestCertifiedResourceId = null;
147 boolean shouldBeCertified = nodeTypeArtifactsToHandle == null || nodeTypeArtifactsToHandle.isEmpty();
148 setConstantMetaData(resource, shouldBeCertified);
149 setMetaDataFromJson(resourceMetaData, resource);
151 Either<Boolean, ResponseFormat> validateResourceFromYaml = populateResourceFromYaml(resourceYml, resource, isInTransaction);
152 if (validateResourceFromYaml.isRight()) {
153 ResponseFormat validationErrorResponse = validateResourceFromYaml.right().value();
154 auditErrorImport(resourceMetaData, creator, validationErrorResponse, true);
155 return Either.right(validationErrorResponse);
159 Either<Boolean, ResponseFormat> isValidResource = validationFunction.apply(resource);
160 if (isValidResource.isLeft()) {
161 // The flag createNewVersion if false doesn't create new version
162 if (!createNewVersion) {
163 Either<Resource, StorageOperationStatus> latestByName = toscaOperationFacade.getLatestByName(resource.getName());
164 if (latestByName.isLeft()) {
165 return Either.right(componentsUtils.getResponseFormatByResource(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, resource));
169 response = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, true, isInTransaction, needLock);
170 Either<Resource, ResponseFormat> changeStateResponse;
171 if (response.isLeft()) {
172 resource = response.left().value().left;
174 if(nodeTypeArtifactsToHandle !=null && !nodeTypeArtifactsToHandle.isEmpty()){
175 Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRes =
176 resourceBusinessLogic.handleNodeTypeArtifacts(resource, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, creator, isInTransaction);
177 if(handleNodeTypeArtifactsRes.isRight()){
178 return Either.right(handleNodeTypeArtifactsRes.right().value());
181 latestCertifiedResourceId = getLatestCertifiedResourceId(resource);
182 changeStateResponse = resourceBusinessLogic.propagateStateToCertified(creator, resource, lifecycleChangeInfo, isInTransaction, needLock, forceCertificationAllowed);
183 if (changeStateResponse.isRight()) {
184 response = Either.right(changeStateResponse.right().value());
186 responsePair = new ImmutablePair<>(changeStateResponse.left().value(), response.left().value().right);
187 response = Either.left(responsePair);
191 ResponseFormat validationErrorResponse = isValidResource.right().value();
192 auditErrorImport(resourceMetaData, creator, validationErrorResponse, true);
193 response = Either.right(validationErrorResponse);
196 } catch (RuntimeException e) {
197 ResponseFormat exceptionResponse = handleImportResourceExecption(resourceMetaData, creator, true, e);
198 response = Either.right(exceptionResponse);
200 if (latestCertifiedResourceId != null && needLock) {
201 log.debug("unlock resource {}", latestCertifiedResourceId);
202 graphLockOperation.unlockComponent(latestCertifiedResourceId, NodeTypeEnum.Resource);
209 private String getLatestCertifiedResourceId(Resource resource) {
210 Map<String, String> allVersions = resource.getAllVersions();
211 Double latestCertifiedVersion = 0.0;
212 if (allVersions != null) {
213 for (String version : allVersions.keySet()) {
214 Double dVersion = Double.valueOf(version);
215 if ((dVersion > latestCertifiedVersion) && (version.endsWith(".0"))) {
216 latestCertifiedVersion = dVersion;
219 return allVersions.get(String.valueOf(latestCertifiedVersion));
225 public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> importUserDefinedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean isReusable, boolean isInTransaction) {
227 Resource resource = new Resource();
228 ImmutablePair<Resource, ActionStatus> responsePair = new ImmutablePair<Resource, ActionStatus>(resource, ActionStatus.CREATED);
229 Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> response = Either.left(responsePair);
232 setMetaDataFromJson(resourceMetaData, resource);
234 Either<Boolean, ResponseFormat> validateResourceFromYaml = populateResourceFromYaml(resourceYml, resource, isInTransaction);
235 if (validateResourceFromYaml.isRight()) {
236 ResponseFormat validationErrorResponse = validateResourceFromYaml.right().value();
237 auditErrorImport(resourceMetaData, creator, validationErrorResponse, false);
238 return Either.right(validationErrorResponse);
242 // currently import VF isn't supported. In future will be supported
243 // import VF only with CSER file!!
244 if (ResourceTypeEnum.VF.equals(resource.getResourceType())) {
245 log.debug("Now import VF isn't supported. It will be supported in future with CSER file only");
246 return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
249 Either<Boolean, ResponseFormat> validateDerivedFromNotEmpty = resourceBusinessLogic.validateDerivedFromNotEmpty(creator, resource, AuditingActionEnum.CREATE_RESOURCE);
250 if (validateDerivedFromNotEmpty.isRight()) {
251 return Either.right(validateDerivedFromNotEmpty.right().value());
254 Either<Boolean, ResponseFormat> validatePropertiesTypes = resourceBusinessLogic.validatePropertiesDefaultValues(resource);
256 if (validatePropertiesTypes.isLeft()) {
257 response = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, false, isInTransaction, true);
259 ResponseFormat validationErrorResponse = validatePropertiesTypes.right().value();
260 auditErrorImport(resourceMetaData, creator, validationErrorResponse, false);
261 response = Either.right(validationErrorResponse);
264 } catch (RuntimeException e) {
265 ResponseFormat exceptionResponse = handleImportResourceExecption(resourceMetaData, creator, false, e);
266 response = Either.right(exceptionResponse);
273 Either<Boolean, ResponseFormat> populateResourceFromYaml(String resourceYml, Resource resource, boolean inTransaction) {
274 @SuppressWarnings("unchecked")
275 Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
276 Map<String, Object> toscaJsonAll = (Map<String, Object>) new Yaml().load(resourceYml);
277 Map<String, Object> toscaJson = toscaJsonAll;
279 // Checks if exist and builds the node_types map
280 if (toscaJsonAll.containsKey(ToscaTagNamesEnum.NODE_TYPES.getElementName()) && resource.getResourceType()!=ResourceTypeEnum.CVFC) {
281 toscaJson = new HashMap<String, Object>();
282 toscaJson.put(ToscaTagNamesEnum.NODE_TYPES.getElementName(), toscaJsonAll.get(ToscaTagNamesEnum.NODE_TYPES.getElementName()));
285 Either<Resource, ResponseFormat> setDerivedFrom = setDerivedFrom(toscaJson, resource, inTransaction);
286 if (setDerivedFrom.isRight()) {
287 return Either.right(setDerivedFrom.right().value());
289 Resource parentResource = setDerivedFrom.left().value();
290 setToscaResourceName(toscaJson, resource);
291 setAttributes(toscaJson, resource);
292 eitherResult = setCapabilities(toscaJson, resource, parentResource);
293 if (eitherResult.isRight())
295 eitherResult = setProperties(toscaJson, resource);
296 if (eitherResult.isRight())
298 eitherResult = setRequirements(toscaJson, resource, parentResource);
299 if (eitherResult.isRight())
301 setInterfaceLifecycle(toscaJson, resource);
306 private void setToscaResourceName(Map<String, Object> toscaJson, Resource resource) {
307 Either<Map<String, Object>, ResultStatusEnum> toscaElement = ImportUtils.findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.NODE_TYPES);
308 if (toscaElement.isLeft() || toscaElement.left().value().size() == 1) {
309 String toscaResourceName = toscaElement.left().value().keySet().iterator().next();
310 resource.setToscaResourceName(toscaResourceName);
314 private void setInterfaceLifecycle(Map<String, Object> toscaJson, Resource resource) {
315 Either<Map<String, Object>, ResultStatusEnum> toscaInterfaces = ImportUtils.findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.INTERFACES);
316 if (toscaInterfaces.isLeft()) {
317 Map<String, Object> jsonInterfaces = toscaInterfaces.left().value();
318 Map<String, InterfaceDefinition> moduleInterfaces = new HashMap<String, InterfaceDefinition>();
319 Iterator<Entry<String, Object>> interfacesNameValue = jsonInterfaces.entrySet().iterator();
320 while (interfacesNameValue.hasNext()) {
321 Entry<String, Object> interfaceNameValue = interfacesNameValue.next();
322 Either<InterfaceDefinition, ResultStatusEnum> eitherInterface = createModuleInterface(interfaceNameValue.getValue());
323 if (eitherInterface.isRight()) {
324 log.info("error when creating interface:{}, for resource:{}", interfaceNameValue.getKey(), resource.getName());
326 moduleInterfaces.put(interfaceNameValue.getKey(), eitherInterface.left().value());
330 if (moduleInterfaces.size() > 0) {
331 resource.setInterfaces(moduleInterfaces);
336 private Either<InterfaceDefinition, ResultStatusEnum> createModuleInterface(Object interfaceJson) {
337 InterfaceDefinition interf = new InterfaceDefinition();
338 Either<InterfaceDefinition, ResultStatusEnum> result = Either.left(interf);
341 if (interfaceJson instanceof String) {
342 String requirementJsonString = (String) interfaceJson;
343 interf.setType(requirementJsonString);
344 } else if (interfaceJson instanceof Map) {
345 Map<String, Object> requirementJsonMap = (Map<String, Object>) interfaceJson;
346 if (requirementJsonMap.containsKey(ToscaTagNamesEnum.TYPE.getElementName())) {
347 String type = (String) requirementJsonMap.get(ToscaTagNamesEnum.TYPE.getElementName());
348 interf.setType(type);
349 interf.setUniqueId(type.toLowerCase());
352 result = Either.right(ResultStatusEnum.GENERAL_ERROR);
355 } catch (Exception e) {
356 BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Import Resource- create interface");
357 BeEcompErrorManager.getInstance().logBeSystemError("Import Resource- create interface");
358 log.debug("error when creating interface, message:{}", e.getMessage(), e);
359 result = Either.right(ResultStatusEnum.GENERAL_ERROR);
365 private Either<Boolean, ResponseFormat> setRequirements(Map<String, Object> toscaJson, Resource resource, Resource parentResource) {// Note that parentResource can be null
366 Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
367 Either<List<Object>, ResultStatusEnum> toscaRequirements = ImportUtils.findFirstToscaListElement(toscaJson, ToscaTagNamesEnum.REQUIREMENTS);
368 if (toscaRequirements.isLeft()) {
369 List<Object> jsonRequirements = toscaRequirements.left().value();
370 Map<String, List<RequirementDefinition>> moduleRequirements = new HashMap<String, List<RequirementDefinition>>();
371 // Checking for name duplication
372 Set<String> reqNames = new HashSet<>();
373 // Getting flattened list of capabilities of parent node - cap name
375 Either<Map<String, String>, ResponseFormat> reqName2Type = getReqName2Type(parentResource);
376 if (reqName2Type.isRight()) {
377 ResponseFormat responseFormat = reqName2Type.right().value();
378 log.debug("Error during setting requirements of imported resource: {}", responseFormat);
379 return Either.right(responseFormat);
381 Map<String, String> reqName2TypeMap = reqName2Type.left().value();
382 for (Object jsonRequirementObj : jsonRequirements) {
384 Map<String, Object> requirementJsonWrapper = (Map<String, Object>) jsonRequirementObj;
385 String requirementName = requirementJsonWrapper.keySet().iterator().next();
386 String reqNameLowerCase = requirementName.toLowerCase();
387 if (reqNames.contains(reqNameLowerCase)) {
388 log.debug("More than one requirement with same name {} (case-insensitive) in imported TOSCA file is invalid", reqNameLowerCase);
389 return Either.right(componentsUtils.getResponseFormat(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME, "requirement", reqNameLowerCase));
391 reqNames.add(reqNameLowerCase);
392 Either<RequirementDefinition, ResponseFormat> eitherRequirement = createRequirementFromImportFile(requirementJsonWrapper.get(requirementName));
393 if (eitherRequirement.isRight()) {
394 log.info("error when creating Requirement:{}, for resource:{}", requirementName, resource.getName());
395 return Either.right(eitherRequirement.right().value());
397 RequirementDefinition requirementDef = eitherRequirement.left().value();
398 requirementDef.setName(requirementName);
399 if (moduleRequirements.containsKey(requirementDef.getCapability())) {
400 moduleRequirements.get(requirementDef.getCapability()).add(requirementDef);
402 List<RequirementDefinition> list = new ArrayList<RequirementDefinition>();
403 list.add(requirementDef);
404 moduleRequirements.put(requirementDef.getCapability(), list);
407 // Validating against req/cap of "derived from" node
408 Either<Boolean, ResponseFormat> validateVsParentCap = validateCapNameVsDerived(reqName2TypeMap, requirementDef.getCapability(), requirementDef.getName());
409 if (validateVsParentCap.isRight()) {
410 return Either.right(validateVsParentCap.right().value());
412 if (!validateVsParentCap.left().value()) {
413 log.debug("Requirement with name {} already exists in parent {}", requirementDef.getName(), parentResource.getName());
414 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, "requirement", requirementDef.getName().toLowerCase(), parentResource.getName());
415 return Either.right(responseFormat);
418 if (moduleRequirements.size() > 0) {
419 resource.setRequirements(moduleRequirements);
427 private Either<RequirementDefinition, ResponseFormat> createRequirementFromImportFile(Object requirementJson) {
428 RequirementDefinition requirement = new RequirementDefinition();
429 Either<RequirementDefinition, ResponseFormat> result = Either.left(requirement);
432 if (requirementJson instanceof String) {
433 String requirementJsonString = (String) requirementJson;
434 requirement.setCapability(requirementJsonString);
435 } else if (requirementJson instanceof Map) {
436 Map<String, Object> requirementJsonMap = (Map<String, Object>) requirementJson;
437 if (requirementJsonMap.containsKey(ToscaTagNamesEnum.CAPABILITY.getElementName())) {
438 requirement.setCapability((String) requirementJsonMap.get(ToscaTagNamesEnum.CAPABILITY.getElementName()));
441 if (requirementJsonMap.containsKey(ToscaTagNamesEnum.NODE.getElementName())) {
442 requirement.setNode((String) requirementJsonMap.get(ToscaTagNamesEnum.NODE.getElementName()));
445 if (requirementJsonMap.containsKey(ToscaTagNamesEnum.RELATIONSHIP.getElementName())) {
446 requirement.setRelationship((String) requirementJsonMap.get(ToscaTagNamesEnum.RELATIONSHIP.getElementName()));
448 if (requirementJsonMap.containsKey(ToscaTagNamesEnum.OCCURRENCES.getElementName())) {
449 List<Object> occurrencesList = (List) requirementJsonMap.get(ToscaTagNamesEnum.OCCURRENCES.getElementName());
450 Either<Boolean, ResponseFormat> validateAndSetOccurrencesStatus = validateOccurrences(occurrencesList);
451 if (validateAndSetOccurrencesStatus.isRight()) {
452 result = Either.right(validateAndSetOccurrencesStatus.right().value());
455 if (validateAndSetOccurrencesStatus.left().value() == true) {
456 requirement.setMinOccurrences(occurrencesList.get(0).toString());
457 requirement.setMaxOccurrences(occurrencesList.get(1).toString());
462 result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
465 } catch (Exception e) {
466 BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Import Resource - create Requirement");
467 BeEcompErrorManager.getInstance().logBeSystemError("Import Resource - create Requirement");
468 log.debug("error when creating requirement, message:{}", e.getMessage(), e);
469 result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
475 private Either<Boolean, ResponseFormat> setProperties(Map<String, Object> toscaJson, Resource resource) {
476 Map<String, Object> reducedToscaJson = new HashMap<>(toscaJson);
477 ImportUtils.removeElementFromJsonMap(reducedToscaJson, "capabilities");
478 Either<Boolean, ResponseFormat> result = Either.left(true);
479 Either<Map<String, PropertyDefinition>, ResultStatusEnum> properties = ImportUtils.getProperties(reducedToscaJson);
480 if (properties.isLeft()) {
481 List<PropertyDefinition> propertiesList = new ArrayList<>();
482 Map<String, PropertyDefinition> value = properties.left().value();
484 for (Entry<String, PropertyDefinition> entry : value.entrySet()) {
485 String name = entry.getKey();
486 if(!PROPERTY_NAME_PATTERN_IGNORE_LENGTH.matcher(name).matches()){
487 log.debug("The property with invalid name {} occured upon import resource {}. ", name, resource.getName());
488 result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_NAME, JsonPresentationFields.PROPERTY)));
490 PropertyDefinition propertyDefinition = entry.getValue();
491 propertyDefinition.setName(name);
492 propertiesList.add(propertyDefinition);
495 resource.setProperties(propertiesList);
496 } else if(properties.right().value() != ResultStatusEnum.ELEMENT_NOT_FOUND){
497 result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromResultStatusEnum(properties.right().value(), JsonPresentationFields.PROPERTY)));
502 private ResultStatusEnum setAttributes(Map<String, Object> toscaJson, Resource resource) {
503 ResultStatusEnum result = ResultStatusEnum.OK;
504 Either<Map<String, PropertyDefinition>, ResultStatusEnum> attributes = ImportUtils.getAttributes(toscaJson);
505 if (attributes.isLeft()) {
506 List<PropertyDefinition> attributeList = new ArrayList<>();
507 Map<String, PropertyDefinition> value = attributes.left().value();
509 for (Entry<String, PropertyDefinition> entry : value.entrySet()) {
510 String name = entry.getKey();
511 PropertyDefinition attributeDef = entry.getValue();
512 attributeDef.setName(name);
513 attributeList.add(attributeDef);
516 resource.setAttributes(attributeList);
518 result = attributes.right().value();
523 private Either<Resource, ResponseFormat> setDerivedFrom(Map<String, Object> toscaJson, Resource resource, boolean inTransaction) {
524 Either<String, ResultStatusEnum> toscaDerivedFromElement = ImportUtils.findFirstToscaStringElement(toscaJson, ToscaTagNamesEnum.DERIVED_FROM);
525 Resource derivedFromResource = null;
526 if (toscaDerivedFromElement.isLeft()) {
527 String derivedFrom = toscaDerivedFromElement.left().value();
528 log.debug("Derived from TOSCA name is {}", derivedFrom);
529 resource.setDerivedFrom(Arrays.asList(new String[] { derivedFrom }));
530 Either<Resource, StorageOperationStatus> latestByToscaResourceName = toscaOperationFacade.getLatestByToscaResourceName(derivedFrom);
532 if (latestByToscaResourceName.isRight()) {
533 StorageOperationStatus operationStatus = latestByToscaResourceName.right().value();
534 if (operationStatus.equals(StorageOperationStatus.NOT_FOUND)) {
535 operationStatus = StorageOperationStatus.PARENT_RESOURCE_NOT_FOUND;
537 log.debug("Error when fetching parent resource {}, error: {}", derivedFrom, operationStatus);
538 ActionStatus convertFromStorageResponse = componentsUtils.convertFromStorageResponse(operationStatus);
539 BeEcompErrorManager.getInstance().logBeComponentMissingError("Import TOSCA YAML", "resource", derivedFrom);
540 return Either.right(componentsUtils.getResponseFormat(convertFromStorageResponse, derivedFrom));
542 derivedFromResource = latestByToscaResourceName.left().value();
544 return Either.left(derivedFromResource);
547 private Either<Boolean, ResponseFormat> setCapabilities(Map<String, Object> toscaJson, Resource resource, Resource parentResource) {// Note that parentResource can be null
548 Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
549 Either<Map<String, Object>, ResultStatusEnum> toscaCapabilities = ImportUtils.findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.CAPABILITIES);
550 if (toscaCapabilities.isLeft()) {
551 Map<String, Object> jsonCapabilities = toscaCapabilities.left().value();
552 Map<String, List<CapabilityDefinition>> moduleCapabilities = new HashMap<String, List<CapabilityDefinition>>();
553 Iterator<Entry<String, Object>> capabilitiesNameValue = jsonCapabilities.entrySet().iterator();
554 Set<String> capNames = new HashSet<>();
555 // Getting flattened list of capabilities of parent node - cap name
557 Either<Map<String, String>, ResponseFormat> capName2Type = getCapName2Type(parentResource);
558 if (capName2Type.isRight()) {
559 ResponseFormat responseFormat = capName2Type.right().value();
560 log.debug("Error during setting capabilities of imported resource: {}", responseFormat);
561 return Either.right(responseFormat);
563 Map<String, String> capName2TypeMap = capName2Type.left().value();
564 while (capabilitiesNameValue.hasNext()) {
565 Entry<String, Object> capabilityNameValue = capabilitiesNameValue.next();
567 // Validating that no req/cap duplicates exist in imported YAML
568 String capNameLowerCase = capabilityNameValue.getKey().toLowerCase();
569 if (capNames.contains(capNameLowerCase)) {
570 log.debug("More than one capability with same name {} (case-insensitive) in imported TOSCA file is invalid", capNameLowerCase);
571 return Either.right(componentsUtils.getResponseFormat(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME, "capability", capNameLowerCase));
573 capNames.add(capNameLowerCase);
575 Either<CapabilityDefinition, ResponseFormat> eitherCapability = createCapabilityFromImportFile(capabilityNameValue.getValue());
576 if (eitherCapability.isRight()) {
577 log.debug("error when creating capability:{}, for resource:{}", capabilityNameValue.getKey(), resource.getName());
578 return Either.right(eitherCapability.right().value());
581 CapabilityDefinition capabilityDef = eitherCapability.left().value();
582 capabilityDef.setName(capabilityNameValue.getKey());
583 if (moduleCapabilities.containsKey(capabilityDef.getType())) {
584 moduleCapabilities.get(capabilityDef.getType()).add(capabilityDef);
586 List<CapabilityDefinition> list = new ArrayList<CapabilityDefinition>();
587 list.add(capabilityDef);
588 moduleCapabilities.put(capabilityDef.getType(), list);
591 // Validating against req/cap of "derived from" node
592 Either<Boolean, ResponseFormat> validateVsParentCap = validateCapNameVsDerived(capName2TypeMap, capabilityDef.getType(), capabilityDef.getName());
593 if (validateVsParentCap.isRight()) {
594 return Either.right(validateVsParentCap.right().value());
596 if (!validateVsParentCap.left().value()) {
597 // Here parentResource is for sure not null, so it's
599 log.debug("Capability with name {} already exists in parent {}", capabilityDef.getName(), parentResource.getName());
600 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, "capability", capabilityDef.getName().toLowerCase(), parentResource.getName());
601 return Either.right(responseFormat);
604 if (moduleCapabilities.size() > 0) {
605 resource.setCapabilities(moduleCapabilities);
613 private Either<Map<String, String>, ResponseFormat> getCapName2Type(Resource parentResource) {
614 Map<String, String> capName2type = new HashMap<>();
615 if (parentResource != null) {
616 Map<String, List<CapabilityDefinition>> capabilities = parentResource.getCapabilities();
617 if (capabilities != null) {
618 for (List<CapabilityDefinition> capDefinitions : capabilities.values()) {
619 for (CapabilityDefinition capDefinition : capDefinitions) {
620 String nameLowerCase = capDefinition.getName().toLowerCase();
621 if (capName2type.get(nameLowerCase) != null) {
622 String parentResourceName = parentResource.getName();
623 log.debug("Resource with name {} has more than one capability with name {}, ignoring case", parentResourceName, nameLowerCase);
624 BeEcompErrorManager.getInstance().logInternalDataError("Import resource", "Parent resource " + parentResourceName + " of imported resource has one or more capabilities with name " + nameLowerCase, ErrorSeverity.ERROR);
625 return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
627 capName2type.put(nameLowerCase, capDefinition.getType());
632 return Either.left(capName2type);
635 private Either<Map<String, String>, ResponseFormat> getReqName2Type(Resource parentResource) {
636 Map<String, String> reqName2type = new HashMap<>();
637 if (parentResource != null) {
638 Map<String, List<RequirementDefinition>> requirements = parentResource.getRequirements();
639 if (requirements != null) {
640 for (List<RequirementDefinition> reqDefinitions : requirements.values()) {
641 for (RequirementDefinition reqDefinition : reqDefinitions) {
642 String nameLowerCase = reqDefinition.getName().toLowerCase();
643 if (reqName2type.get(nameLowerCase) != null) {
644 String parentResourceName = parentResource.getName();
645 log.debug("Resource with name {} has more than one requirement with name {}, ignoring case", parentResourceName, nameLowerCase);
646 BeEcompErrorManager.getInstance().logInternalDataError("Import resource", "Parent resource " + parentResourceName + " of imported resource has one or more requirements with name " + nameLowerCase, ErrorSeverity.ERROR);
647 return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
649 reqName2type.put(nameLowerCase, reqDefinition.getCapability());
654 return Either.left(reqName2type);
657 private Either<Boolean, ResponseFormat> validateCapNameVsDerived(Map<String, String> parentCapName2Type, String childCapabilityType, String reqCapName) {
658 String capNameLowerCase = reqCapName.toLowerCase();
659 log.trace("Validating capability {} vs parent resource", capNameLowerCase);
660 String parentCapType = parentCapName2Type.get(capNameLowerCase);
661 if (parentCapType != null) {
662 if (childCapabilityType.equals(parentCapType)) {
663 log.debug("Capability with name {} is of same type {} for imported resource and its parent - this is OK", capNameLowerCase, childCapabilityType);
664 return Either.left(true);
666 Either<Boolean, StorageOperationStatus> capabilityTypeDerivedFrom = capabilityTypeOperation.isCapabilityTypeDerivedFrom(childCapabilityType, parentCapType);
667 if (capabilityTypeDerivedFrom.isRight()) {
668 log.debug("Couldn't check whether imported resource capability derives from its parent's capability");
669 ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(capabilityTypeDerivedFrom.right().value()));
670 return Either.right(responseFormat);
672 return Either.left(capabilityTypeDerivedFrom.left().value());
674 return Either.left(true);
677 private Either<CapabilityDefinition, ResponseFormat> createCapabilityFromImportFile(Object capabilityJson) {
679 CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
680 Either<CapabilityDefinition, ResponseFormat> result = Either.left(capabilityDefinition);
683 if (capabilityJson instanceof String) {
684 String capabilityJsonString = (String) capabilityJson;
685 capabilityDefinition.setType(capabilityJsonString);
686 } else if (capabilityJson instanceof Map) {
687 Map<String, Object> capabilityJsonMap = (Map<String, Object>) capabilityJson;
689 if (capabilityJsonMap.containsKey(ToscaTagNamesEnum.TYPE.getElementName())) {
690 capabilityDefinition.setType((String) capabilityJsonMap.get(ToscaTagNamesEnum.TYPE.getElementName()));
693 if (capabilityJsonMap.containsKey(ToscaTagNamesEnum.VALID_SOURCE_TYPES.getElementName())) {
694 capabilityDefinition.setValidSourceTypes((List<String>) capabilityJsonMap.get(ToscaTagNamesEnum.VALID_SOURCE_TYPES.getElementName()));
697 if (capabilityJsonMap.containsKey(ToscaTagNamesEnum.DESCRIPTION.getElementName())) {
698 capabilityDefinition.setDescription((String) capabilityJsonMap.get(ToscaTagNamesEnum.DESCRIPTION.getElementName()));
700 if (capabilityJsonMap.containsKey(ToscaTagNamesEnum.OCCURRENCES.getElementName())) {
701 List<Object> occurrencesList = (List) capabilityJsonMap.get(ToscaTagNamesEnum.OCCURRENCES.getElementName());
702 Either<Boolean, ResponseFormat> validateAndSetOccurrencesStatus = validateOccurrences(occurrencesList);
703 if (validateAndSetOccurrencesStatus.isRight()) {
704 result = Either.right(validateAndSetOccurrencesStatus.right().value());
707 if (validateAndSetOccurrencesStatus.left().value() == true) {
708 capabilityDefinition.setMinOccurrences(occurrencesList.get(0).toString());
709 capabilityDefinition.setMaxOccurrences(occurrencesList.get(1).toString());
712 if (capabilityJsonMap.containsKey(ToscaTagNamesEnum.PROPERTIES.getElementName())) {
714 Either<Map<String, PropertyDefinition>, ResultStatusEnum> propertiesRes = ImportUtils.getProperties(capabilityJsonMap);
715 if (propertiesRes.isRight()) {
716 result = Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND));
719 propertiesRes.left().value().entrySet().stream().forEach(e -> e.getValue().setName(e.getKey().toLowerCase()));
720 List<ComponentInstanceProperty> capabilityProperties = propertiesRes.left().value().values().stream().map(p -> new ComponentInstanceProperty(p, p.getDefaultValue(), null)).collect(Collectors.toList());
721 capabilityDefinition.setProperties(capabilityProperties);
724 } else if (!(capabilityJson instanceof List)) {
726 result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
729 } catch (Exception e) {
730 BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Import Resource - create capability");
731 BeEcompErrorManager.getInstance().logBeSystemError("Import Resource - create capability");
732 log.debug("error when creating capability, message:{}", e.getMessage(), e);
733 result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
739 private ResponseFormat handleImportResourceExecption(UploadResourceInfo resourceMetaData, User user, boolean isNormative, RuntimeException e) {
740 String payloadName = (resourceMetaData != null) ? resourceMetaData.getPayloadName() : "";
741 BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Import Resource " + payloadName);
742 BeEcompErrorManager.getInstance().logBeSystemError("Import Resource " + payloadName);
744 log.debug("Error when importing resource from payload:{} Exception text: {}", payloadName, e.getMessage(), e);
745 ResponseFormat errorResponseWrapper = getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR);
746 auditErrorImport(resourceMetaData, user, errorResponseWrapper, isNormative);
747 return errorResponseWrapper;
750 private void auditErrorImport(UploadResourceInfo resourceMetaData, User user, ResponseFormat errorResponseWrapper, boolean isNormative) {
751 EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<>(AuditingFieldsKeysEnum.class);
752 auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, AuditingActionEnum.IMPORT_RESOURCE.getName());
753 auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceMetaData.getName());
754 auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE, ComponentTypeEnum.RESOURCE.getValue());
755 auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_PREV_VERSION, "");
756 auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID, user.getUserId());
757 auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_PREV_STATE, "");
758 auditingFields.put(AuditingFieldsKeysEnum.AUDIT_INVARIANT_UUID, "");
759 auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, errorResponseWrapper.getStatus());
761 if (errorResponseWrapper.getMessageId() != null) {
762 message = errorResponseWrapper.getMessageId() + ": ";
764 message += errorResponseWrapper.getFormattedMessage();
765 auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, message);
766 auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_NAME, user.getFirstName() + " " + user.getLastName());
768 String version, lifeCycleState;
770 version = Constants.FIRST_CERTIFIED_VERSION_VERSION;
771 lifeCycleState = LifecycleStateEnum.CERTIFIED.name();
774 lifeCycleState = LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name();
777 auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_VERSION, version);
778 auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_STATE, lifeCycleState);
779 auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TOSCA_NODE_TYPE, "");
781 getAuditingManager().auditEvent(auditingFields);
784 private void setMetaDataFromJson(UploadResourceInfo resourceMetaData, Resource resource) {
785 resource.setTags(resourceMetaData.getTags());
786 List<CategoryDefinition> categories = resourceMetaData.getCategories();
787 resource.setCategories(categories);
788 resource.setDescription(resourceMetaData.getDescription());
789 resource.setIcon(resourceMetaData.getResourceIconPath());
790 resource.setName(resourceMetaData.getName());
791 if (categories != null && !categories.isEmpty()) {
792 CategoryDefinition categoryDef = categories.get(0);
793 resource.setAbstract(false);
794 if (categoryDef != null && categoryDef.getName() != null && categoryDef.getName().equals(Constants.ABSTRACT_CATEGORY_NAME)) {
795 SubCategoryDefinition subCategoryDef = categoryDef.getSubcategories().get(0);
796 if (subCategoryDef != null && subCategoryDef.getName().equals(Constants.ABSTRACT_SUBCATEGORY)) {
797 resource.setAbstract(true);
801 resource.setContactId(resourceMetaData.getContactId());
802 resource.setCreatorUserId(resourceMetaData.getContactId());
804 if (resourceMetaData.getVendorName() != null) {
805 resource.setVendorName(resourceMetaData.getVendorName());
808 if (resourceMetaData.getVendorRelease() != null) {
809 resource.setVendorRelease(resourceMetaData.getVendorRelease());
812 resource.setResourceType(ResourceTypeEnum.valueOf(resourceMetaData.getResourceType()));
816 private void setConstantMetaData(Resource resource, boolean shouldBeCertified) {
818 LifecycleStateEnum state;
819 if(shouldBeCertified){
820 version = ImportUtils.Constants.FIRST_CERTIFIED_VERSION_VERSION;
821 state = ImportUtils.Constants.NORMATIVE_TYPE_LIFE_CYCLE;
823 version = ImportUtils.Constants.FIRST_NON_CERTIFIED_VERSION;
824 state = ImportUtils.Constants.NORMATIVE_TYPE_LIFE_CYCLE_NOT_CERTIFIED_CHECKOUT;
826 resource.setVersion(version);
827 resource.setLifecycleState(state);
828 resource.setHighestVersion(ImportUtils.Constants.NORMATIVE_TYPE_HIGHEST_VERSION);
829 resource.setVendorName(ImportUtils.Constants.VENDOR_NAME);
830 resource.setVendorRelease(ImportUtils.Constants.VENDOR_RELEASE);
834 private Either<Boolean, ResponseFormat> validateOccurrences(List<Object> occurrensesList) {
836 if (!ValidationUtils.validateListNotEmpty(occurrensesList)) {
837 log.debug("Occurrenses list empty");
838 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
839 return Either.right(responseFormat);
842 if (occurrensesList.size() < 2) {
843 log.debug("Occurrenses list size not 2");
844 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
845 return Either.right(responseFormat);
847 Object minObj = occurrensesList.get(0);
848 Object maxObj = occurrensesList.get(1);
849 Integer minOccurrences = null;
850 Integer maxOccurrences = null;
851 if (minObj instanceof Integer)
852 minOccurrences = (Integer) minObj;
854 log.debug("Invalid occurrenses format. low_bound occurrense must be Integer {}", minObj);
855 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
856 return Either.right(responseFormat);
858 if (minOccurrences < 0) {
859 log.debug("Invalid occurrenses format.low_bound occurrense negative {}", minOccurrences);
860 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
861 return Either.right(responseFormat);
864 if (maxObj instanceof String) {
865 if (maxObj.equals("UNBOUNDED")) {
866 return Either.left(true);
868 log.debug("Invalid occurrenses format. Max occurrence is {}", maxObj);
869 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
870 return Either.right(responseFormat);
873 if (maxObj instanceof Integer)
874 maxOccurrences = (Integer) maxObj;
876 log.debug("Invalid occurrenses format. Max occurrence is {}", maxObj);
877 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
878 return Either.right(responseFormat);
881 if (maxOccurrences <= 0 || maxOccurrences < minOccurrences) {
882 log.debug("Invalid occurrenses format. min occurrence is {}, Max occurrence is {}", minOccurrences, maxOccurrences);
883 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
884 return Either.right(responseFormat);
888 return Either.left(true);
892 public void init(ServletContext servletContext) {
893 if (this.servletContext == null) {
894 synchronized (this) {
895 if (this.servletContext == null) {
896 this.servletContext = servletContext;
897 responseFormatManager = ResponseFormatManager.getInstance();
898 resourceBusinessLogic = getResourceBL(servletContext);
904 public boolean isResourceExist(String resourceName) {
905 return resourceBusinessLogic.isResourceExist(resourceName);
908 private ResourceBusinessLogic getResourceBL(ServletContext context) {
909 WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(org.openecomp.sdc.common.api.Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
910 WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
911 ResourceBusinessLogic resourceBl = webApplicationContext.getBean(ResourceBusinessLogic.class);
915 public ServletContext getServletContext() {
916 return servletContext;
919 public IAuditingManager getAuditingManager() {
920 return auditingManager;
923 public ResponseFormatManager getResponseFormatManager() {
924 return responseFormatManager;
927 public void setResponseFormatManager(ResponseFormatManager responseFormatManager) {
928 this.responseFormatManager = responseFormatManager;
931 public ResourceBusinessLogic getResourceBusinessLogic() {
932 return resourceBusinessLogic;
935 public void setResourceBusinessLogic(ResourceBusinessLogic resourceBusinessLogic) {
936 this.resourceBusinessLogic = resourceBusinessLogic;
939 public Logger getLog() {
943 public static void setLog(Logger log) {
944 ResourceImportManager.log = log;
947 public IGraphLockOperation getGraphLockOperation() {
948 return graphLockOperation;
951 public void setGraphLockOperation(IGraphLockOperation graphLockOperation) {
952 this.graphLockOperation = graphLockOperation;
955 public void setServletContext(ServletContext servletContext) {
956 this.servletContext = servletContext;
959 public void setAuditingManager(IAuditingManager auditingManager) {
960 this.auditingManager = auditingManager;
963 public void setResourceOperation(ResourceOperation resourceOperation) {
964 this.resourceOperation = resourceOperation;