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.googlecode.objectify.Key;
20 import com.googlecode.objectify.annotation.Cache;
21 import com.googlecode.objectify.annotation.Entity;
22 import com.googlecode.objectify.annotation.Id;
23 import com.googlecode.objectify.annotation.Index;
24 import lombok.EqualsAndHashCode;
25 import lombok.Getter;
26 import lombok.NoArgsConstructor;
27 import lombok.Setter;
28 
29 import java.nio.file.Path;
30 import java.nio.file.Paths;
31 import java.util.Date;
32 
33 import static com.googlecode.objectify.ObjectifyService.ofy;
34 
35 /** Entity Class for Suite Test File Info */
36 @Cache
37 @Entity
38 @EqualsAndHashCode(of = "id")
39 @NoArgsConstructor
40 public class TestSuiteFileEntity implements DashboardEntity {
41 
42     /** Test Suite full file path field */
43     @Id @Getter @Setter String filePath;
44 
45     /** Test Suite year field in the filePath  */
46     @Index @Getter @Setter int year;
47 
48     /** Test Suite month field in the filePath  */
49     @Index @Getter @Setter int month;
50 
51     /** Test Suite day field in the filePath */
52     @Index @Getter @Setter int day;
53 
54     /** Test Suite file name field */
55     @Index @Getter @Setter String fileName;
56 
57     /** When this record was created or updated */
58     @Index @Getter Date updated;
59 
60     /** Construction function for TestSuiteResultEntity Class */
TestSuiteFileEntity(String filePath)61     public TestSuiteFileEntity(String filePath) {
62         this.filePath = filePath;
63         Path pathInfo = Paths.get(filePath);
64         if (pathInfo.getNameCount() > 3) {
65             this.year = Integer.valueOf(pathInfo.getName(1).toString());
66             this.month = Integer.valueOf(pathInfo.getName(2).toString());
67             this.day = Integer.valueOf(pathInfo.getName(3).toString());
68             this.fileName = pathInfo.getFileName().toString();
69         }
70     }
71 
72     /** Saving function for the instance of this class */
73     @Override
save()74     public Key<TestSuiteFileEntity> save() {
75         this.updated = new Date();
76         return ofy().save().entity(this).now();
77     }
78 }
79