2 * Copyright (c) 2015 Intel Corporation All rights reserved.
3 * Copyright (c) 2015 Isaku Yamahata All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.neutron.spi;
12 import com.fasterxml.jackson.annotation.JsonIgnore;
13 import java.io.Serializable;
14 import java.util.List;
15 import javax.xml.bind.annotation.XmlAccessType;
16 import javax.xml.bind.annotation.XmlAccessorType;
17 import javax.xml.bind.annotation.XmlElement;
18 import javax.xml.bind.annotation.XmlRootElement;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
22 @XmlAccessorType(XmlAccessType.NONE)
23 public abstract class NeutronObject<T extends NeutronObject> extends NeutronID
24 implements Serializable, INeutronObject<T> {
25 private static final long serialVersionUID = 1L;
27 @XmlElement(name = "tenant_id")
30 @XmlElement(name = "project_id")
33 @XmlElement(name = "revision_number")
36 public NeutronObject() {
41 public String getTenantID() {
42 if (tenantID != null && tenantID.isEmpty()) {
43 // Bug 4775 - Treat empty string tenantId as null, so no attempt is made
44 // to turn it into a uuid.
51 public void setTenantID(String tenantID) {
52 this.tenantID = tenantID;
57 public void setTenantID(Uuid tenantID) {
58 this.tenantID = tenantID.getValue().replace("-", "");
62 public String toString() {
63 return "NeutronObject [id=" + uuid + ", tenantID=" + tenantID + "]";
67 public void setProjectID(String projectID) {
68 this.projectID = projectID;
72 public String getProjectID() {
73 return this.projectID;
77 public Long getRevisionNumber() {
78 return revisionNumber;
82 public void setRevisionNumber(Long revisionNumber) {
83 this.revisionNumber = revisionNumber;
87 public void initDefaults() {
88 if (projectID != null && tenantID == null) {
91 if (projectID == null && tenantID != null) {
97 public abstract T extractFields(List<String> fields);
99 protected void extractField(String field, T ans) {
100 if (field.equals("id")) {
101 ans.setID(this.getID());
103 if (field.equals("tenant_id")) {
104 ans.setTenantID(this.getTenantID());
106 if (field.equals("project_id")) {
107 ans.setProjectID(this.getProjectID());
109 if (field.equals("revision_number")) {
110 ans.setRevisionNumber(this.getRevisionNumber());