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=========================================================
21 package org.openecomp.sdc.be.model.operations.impl;
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;
29 import javax.validation.constraints.NotNull;
32 public class AnnotationTypeOperations implements TypeOperations<AnnotationTypeDefinition> {
34 private final CommonTypeOperations commonTypeOperations;
36 public AnnotationTypeOperations(CommonTypeOperations commonTypeOperations) {
37 this.commonTypeOperations = commonTypeOperations;
41 public AnnotationTypeDefinition addType(AnnotationTypeDefinition newTypeDefinition) {
42 AnnotationTypeData annotationTypeData = new AnnotationTypeData(newTypeDefinition);
43 String uniqueId = UniqueIdBuilder.buildTypeUid(newTypeDefinition.getType(), newTypeDefinition.getVersion(), "annotationtype");
44 annotationTypeData.setInitialCreationProperties(uniqueId);
45 commonTypeOperations.addType(annotationTypeData, AnnotationTypeData.class);
46 commonTypeOperations.addProperties(uniqueId, NodeTypeEnum.AnnotationType, newTypeDefinition.getProperties());
47 return getType(uniqueId);
51 public AnnotationTypeDefinition getType(String uniqueId) {
52 return commonTypeOperations.getType(uniqueId, AnnotationTypeData.class, NodeTypeEnum.AnnotationType)
53 .map(this::populateTypeDefinition)
57 private AnnotationTypeDefinition populateTypeDefinition(@NotNull AnnotationTypeData annotationTypeData) {
58 AnnotationTypeDefinition annotationTypeDefinition = new AnnotationTypeDefinition(annotationTypeData.getAnnotationTypeDataDefinition());
59 commonTypeOperations.fillProperties(annotationTypeDefinition.getUniqueId(), NodeTypeEnum.AnnotationType, annotationTypeDefinition::setProperties);
60 return annotationTypeDefinition;
64 public AnnotationTypeDefinition getLatestType(String type) {
65 return commonTypeOperations.getLatestType(type, AnnotationTypeData.class, NodeTypeEnum.AnnotationType)
66 .map(this::populateTypeDefinition)
71 public boolean isSameType(AnnotationTypeDefinition type1, AnnotationTypeDefinition type2) {
72 return type1.isSameDefinition(type2);
76 public AnnotationTypeDefinition updateType(AnnotationTypeDefinition currentTypeDefinition,
77 AnnotationTypeDefinition updatedTypeDefinition) {
78 AnnotationTypeData updatedTypeData = new AnnotationTypeData(updatedTypeDefinition);
79 updatedTypeData.setUpdateProperties(currentTypeDefinition);
80 commonTypeOperations.updateType(updatedTypeData, updatedTypeDefinition.getProperties(), AnnotationTypeData.class, NodeTypeEnum.AnnotationType);
81 return getType(updatedTypeData.getUniqueId());