154bc40dadbf6feb9298a601df7b175131e99afe
[sdc.git] /
1 /*
2  *
3  *  Copyright © 2017-2018 European Support Limited
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  * Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  */
18 package org.openecomp.sdc.versioning.types;
19
20 import lombok.Getter;
21 import lombok.Setter;
22 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
23
24 import java.util.Date;
25 import java.util.EnumMap;
26 import java.util.HashMap;
27 import java.util.Map;
28
29 @Getter
30 @Setter
31 public class Item {
32   private String id;
33   private String type;
34   private String name;
35   private String owner;
36   private ItemStatus status;
37   private String description;
38   private Map<String, Object> properties = new HashMap<>();
39   private Map<VersionStatus, Integer> versionStatusCounters = new EnumMap<>(VersionStatus.class);
40   private Date creationTime;
41   private Date modificationTime;
42
43   public void addProperty(String key, Object value) {
44     properties.put(key, value);
45   }
46
47   public void addVersionStatus(VersionStatus versionStatus) {
48     Integer counter = versionStatusCounters.get(versionStatus);
49     versionStatusCounters
50         .put(versionStatus, counter == null ? 1 : counter + 1);
51   }
52
53   public void removeVersionStatus(VersionStatus versionStatus) {
54     Integer counter = versionStatusCounters.get(versionStatus);
55     if (counter != null) {
56       if (counter == 1) {
57         versionStatusCounters.remove(versionStatus);
58       } else {
59         versionStatusCounters.put(versionStatus, counter - 1);
60       }
61     }
62   }
63 }