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 com.google.appengine.api.datastore.Key; 21 import com.google.appengine.api.datastore.KeyFactory; 22 import java.util.logging.Level; 23 import java.util.logging.Logger; 24 25 /** Entity describing a build target. */ 26 public class BuildTargetEntity implements DashboardEntity { 27 protected static final Logger logger = Logger.getLogger(BuildTargetEntity.class.getName()); 28 29 public static final String KIND = "BuildTarget"; // The entity kind. 30 31 public Key key; // The key for the entity in the database. 32 33 /** 34 * Create a BuildTargetEntity object. 35 * 36 * @param targetName The name of the build target. 37 */ 38 public BuildTargetEntity(String targetName) { 39 this.key = KeyFactory.createKey(KIND, targetName); 40 } 41 42 @Override 43 public Entity toEntity() { 44 return new Entity(this.key); 45 } 46 47 /** 48 * Convert an Entity object to a BuildTargetEntity. 49 * 50 * @param e The entity to process. 51 * @return BuildTargetEntity object with the properties from e, or null if incompatible. 52 */ 53 public static BuildTargetEntity fromEntity(Entity e) { 54 if (!e.getKind().equals(KIND) || e.getKey().getName() == null) { 55 logger.log(Level.WARNING, "Missing build target attributes in entity: " + e.toString()); 56 return null; 57 } 58 String targetName = e.getKey().getName(); 59 return new BuildTargetEntity(targetName); 60 } 61 } 62