1 /* 2 * Copyright (c) 2017 Google Inc. All Rights Reserved. 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.google.appengine.api.datastore.Entity; 20 import java.util.logging.Level; 21 import java.util.logging.Logger; 22 23 /** Entity describing test plan metadata. */ 24 public class TestPlanEntity implements DashboardEntity { 25 protected static final Logger logger = Logger.getLogger(TestPlanEntity.class.getName()); 26 27 public static final String KIND = "TestPlan"; 28 29 // Property keys 30 public static final String TEST_PLAN_NAME = "testPlanName"; 31 32 public final String testPlanName; 33 34 /** 35 * Create a TestPlanEntity object. 36 * 37 * @param testPlanName The name of the test plan. 38 */ 39 public TestPlanEntity(String testPlanName) { 40 this.testPlanName = testPlanName; 41 } 42 43 @Override 44 public Entity toEntity() { 45 Entity planEntity = new Entity(KIND, this.testPlanName); 46 return planEntity; 47 } 48 49 /** 50 * Convert an Entity object to a TestEntity. 51 * 52 * @param e The entity to process. 53 * @return TestEntity object with the properties from e processed, or null if incompatible. 54 */ 55 @SuppressWarnings("unchecked") 56 public static TestPlanEntity fromEntity(Entity e) { 57 if (!e.getKind().equals(KIND) || e.getKey().getName() == null 58 || !e.hasProperty(TEST_PLAN_NAME)) { 59 logger.log(Level.WARNING, "Missing test plan attributes in entity: " + e.toString()); 60 return null; 61 } 62 String testPlanName = e.getKey().getName(); 63 return new TestPlanEntity(testPlanName); 64 } 65 } 66