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 com.fasterxml.jackson.annotation.JsonAutoDetect; 20 import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 21 import com.googlecode.objectify.Key; 22 import com.googlecode.objectify.annotation.Cache; 23 import com.googlecode.objectify.annotation.Entity; 24 import com.googlecode.objectify.annotation.Id; 25 import com.googlecode.objectify.annotation.Index; 26 import lombok.EqualsAndHashCode; 27 import lombok.Getter; 28 import lombok.NoArgsConstructor; 29 import lombok.Setter; 30 31 import java.util.Date; 32 import java.util.List; 33 34 import static com.googlecode.objectify.ObjectifyService.ofy; 35 36 /** 37 * This entity class contain the excluded API information. And this information will be used to 38 * calculate more precise the ratio of API coverage. 39 */ 40 @Cache 41 @Entity(name = "ApiCoverageExcluded") 42 @EqualsAndHashCode(of = "id") 43 @NoArgsConstructor 44 @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) 45 @JsonIgnoreProperties({"id", "parent"}) 46 public class ApiCoverageExcludedEntity implements DashboardEntity { 47 48 /** ApiCoverageEntity id field */ 49 @Id @Getter @Setter private String id; 50 51 /** Package name. e.g. android.hardware.foo. */ 52 @Index @Getter @Setter private String packageName; 53 54 /** Major Version. e.g. 1, 2. */ 55 @Getter @Setter private int majorVersion; 56 57 /** Minor Version. e.g. 0. */ 58 @Getter @Setter private int minorVersion; 59 60 /** Interface name. e.g. IFoo. */ 61 @Index @Getter @Setter private String interfaceName; 62 63 /** API Name */ 64 @Index @Getter @Setter private String apiName; 65 66 /** The reason comment for the excluded API */ 67 @Getter @Setter private String comment; 68 69 /** When this record was created or updated */ 70 @Index @Getter @Setter private Date updated; 71 72 /** Constructor function for ApiCoverageExcludedEntity Class */ ApiCoverageExcludedEntity( String packageName, String version, String interfaceName, String apiName, String comment)73 public ApiCoverageExcludedEntity( 74 String packageName, 75 String version, 76 String interfaceName, 77 String apiName, 78 String comment) { 79 this.id = this.getObjectifyId(); 80 this.packageName = packageName; 81 this.interfaceName = interfaceName; 82 this.apiName = apiName; 83 this.comment = comment; 84 this.updated = new Date(); 85 86 this.setVersions(version); 87 } 88 89 /** Setting major and minor version from version string */ setVersions(String version)90 private void setVersions(String version) { 91 String[] versionArray = version.split("[.]"); 92 if (versionArray.length == 0) { 93 this.majorVersion = 0; 94 this.minorVersion = 0; 95 } else if (versionArray.length == 1) { 96 this.majorVersion = Integer.parseInt(versionArray[0]); 97 this.minorVersion = 0; 98 } else { 99 this.majorVersion = Integer.parseInt(versionArray[0]); 100 this.minorVersion = Integer.parseInt(versionArray[1]); 101 } 102 } 103 104 /** Getting objectify ID from the entity information */ getObjectifyId()105 private String getObjectifyId() { 106 return this.packageName 107 + "." 108 + this.majorVersion 109 + "." 110 + this.minorVersion 111 + "." 112 + this.interfaceName 113 + "." 114 + this.apiName; 115 } 116 117 /** Getting key from the entity */ getKey()118 public Key<ApiCoverageExcludedEntity> getKey() { 119 return Key.create(ApiCoverageExcludedEntity.class, this.getObjectifyId()); 120 } 121 122 /** Saving function for the instance of this class */ 123 @Override save()124 public Key<ApiCoverageExcludedEntity> save() { 125 return ofy().save().entity(this).now(); 126 } 127 128 /** Get All Key List of ApiCoverageExcludedEntity */ getAllKeyList()129 public static List<Key<ApiCoverageExcludedEntity>> getAllKeyList() { 130 return ofy().load().type(ApiCoverageExcludedEntity.class).keys().list(); 131 } 132 133 } 134