1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you
5  * may not use this file except in compliance with the License. You may
6  * obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13  * implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16 
17 package com.android.vts.entity;
18 
19 import static com.googlecode.objectify.ObjectifyService.ofy;
20 
21 import com.fasterxml.jackson.annotation.JsonAutoDetect;
22 import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
23 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
24 import com.googlecode.objectify.Key;
25 import com.googlecode.objectify.annotation.Cache;
26 import com.googlecode.objectify.annotation.Entity;
27 import com.googlecode.objectify.annotation.Id;
28 import com.googlecode.objectify.annotation.Index;
29 import com.googlecode.objectify.annotation.Parent;
30 import java.util.Date;
31 import java.util.List;
32 import java.util.UUID;
33 import lombok.EqualsAndHashCode;
34 import lombok.Getter;
35 import lombok.NoArgsConstructor;
36 import lombok.Setter;
37 
38 /** Entity Class for HalApiEntity */
39 @Cache
40 @Entity(name = "HalApiEntity")
41 @EqualsAndHashCode(of = "id")
42 @NoArgsConstructor
43 @JsonAutoDetect(fieldVisibility = Visibility.ANY)
44 @JsonIgnoreProperties({"id", "parent"})
45 public class HalApiEntity implements DashboardEntity {
46 
47     /** HalApiEntity id field */
48     @Id @Getter @Setter String id;
49 
50     @Parent @Getter Key<?> parent;
51 
52     /** HAL Api Release Level. e.g. */
53     @Index @Getter @Setter String halApiReleaseLevel;
54 
55     /** HAL package name. e.g. android.hardware.foo. */
56     @Index @Getter @Setter String halPackageName;
57 
58     /** HAL (major) version. e.g. 1. */
59     @Index @Getter @Setter int halMajorVersion;
60 
61     /** HAL (minor) version. e.g. 0. */
62     @Index @Getter @Setter int halMinorVersion;
63 
64     /** HAL interface name. e.g. IFoo. */
65     @Index @Getter @Setter String halInterfaceName;
66 
67     /** List of HAL API */
68     @Getter @Setter List<String> halApi;
69 
70     /** List of HAL covered API */
71     @Getter @Setter List<String> coveredHalApi;
72 
73     /** When this record was created or updated */
74     @Index Date updated;
75 
76     /** Constructor function for HalApiEntity Class */
HalApiEntity( com.googlecode.objectify.Key testRunKey, String halApiReleaseLevel, String halPackageName, int halMajorVersion, int halMinorVersion, String halInterfaceName, List<String> halApi, List<String> coveredHalApi)77     public HalApiEntity(
78             com.googlecode.objectify.Key testRunKey,
79             String halApiReleaseLevel,
80             String halPackageName,
81             int halMajorVersion,
82             int halMinorVersion,
83             String halInterfaceName,
84             List<String> halApi,
85             List<String> coveredHalApi) {
86 
87         this.id = UUID.randomUUID().toString();
88         this.parent = testRunKey;
89 
90         this.halApiReleaseLevel = halApiReleaseLevel;
91         this.halPackageName = halPackageName;
92         this.halMajorVersion = halMajorVersion;
93         this.halMinorVersion = halMinorVersion;
94         this.halInterfaceName = halInterfaceName;
95         this.halApi = halApi;
96         this.coveredHalApi = coveredHalApi;
97         this.updated = new Date();
98     }
99 
100     /** Saving function for the instance of this class */
101     @Override
save()102     public Key<HalApiEntity> save() {
103         return ofy().save().entity(this).now();
104     }
105 }
106