2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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=========================================================
20 package org.openecomp.sdc.be.model.operations.impl;
22 import javax.validation.constraints.NotNull;
23 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
24 import org.openecomp.sdc.be.model.AnnotationTypeDefinition;
25 import org.openecomp.sdc.be.model.operations.api.TypeOperations;
26 import org.openecomp.sdc.be.resources.data.AnnotationTypeData;
27 import org.springframework.stereotype.Component;
30 public class AnnotationTypeOperations implements TypeOperations<AnnotationTypeDefinition> {
32 private final CommonTypeOperations commonTypeOperations;
34 public AnnotationTypeOperations(CommonTypeOperations commonTypeOperations) {
35 this.commonTypeOperations = commonTypeOperations;
39 public AnnotationTypeDefinition addType(AnnotationTypeDefinition newTypeDefinition) {
40 AnnotationTypeData annotationTypeData = new AnnotationTypeData(newTypeDefinition);
41 String uniqueId = UniqueIdBuilder.buildTypeUid(newTypeDefinition.getType(), newTypeDefinition.getVersion(), "annotationtype");
42 annotationTypeData.setInitialCreationProperties(uniqueId);
43 commonTypeOperations.addType(annotationTypeData, AnnotationTypeData.class);
44 commonTypeOperations.addProperties(uniqueId, NodeTypeEnum.AnnotationType, newTypeDefinition.getProperties());
45 return getType(uniqueId);
49 public AnnotationTypeDefinition getType(String uniqueId) {
50 return commonTypeOperations.getType(uniqueId, AnnotationTypeData.class, NodeTypeEnum.AnnotationType).map(this::populateTypeDefinition)
54 private AnnotationTypeDefinition populateTypeDefinition(@NotNull AnnotationTypeData annotationTypeData) {
55 AnnotationTypeDefinition annotationTypeDefinition = new AnnotationTypeDefinition(annotationTypeData.getAnnotationTypeDataDefinition());
57 .fillProperties(annotationTypeDefinition.getUniqueId(), NodeTypeEnum.AnnotationType, annotationTypeDefinition::setProperties);
58 return annotationTypeDefinition;
62 public AnnotationTypeDefinition getLatestType(String type) {
63 return commonTypeOperations.getLatestType(type, AnnotationTypeData.class, NodeTypeEnum.AnnotationType).map(this::populateTypeDefinition)
68 public boolean isSameType(AnnotationTypeDefinition type1, AnnotationTypeDefinition type2) {
69 return type1.isSameDefinition(type2);
73 public AnnotationTypeDefinition updateType(AnnotationTypeDefinition currentTypeDefinition, AnnotationTypeDefinition updatedTypeDefinition) {
74 AnnotationTypeData updatedTypeData = new AnnotationTypeData(updatedTypeDefinition);
75 updatedTypeData.setUpdateProperties(currentTypeDefinition);
77 .updateType(updatedTypeData, updatedTypeDefinition.getProperties(), AnnotationTypeData.class, NodeTypeEnum.AnnotationType);
78 return getType(updatedTypeData.getUniqueId());