/** * Copyright 2016 Hortonworks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **/ package com.hortonworks.registries.tag; import com.fasterxml.jackson.annotation.JsonIgnore; import com.hortonworks.registries.common.Schema; import com.hortonworks.registries.storage.PrimaryKey; import com.hortonworks.registries.storage.catalog.AbstractStorable; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Represents a tag that can be associated with any storable entitiy. */ public class Tag extends AbstractStorable { public static final String NAMESPACE = "tag"; public static final String ID = "id"; public static final String NAME = "name"; public static final String DESCRIPTION = "description"; public static final String TIMESTAMP = "timestamp"; private Long id; private String name; private String description = ""; private Long timestamp; // parent tags private List<Tag> tags; @JsonIgnore @Override public String getNameSpace() { return NAMESPACE; } @JsonIgnore @Override public PrimaryKey getPrimaryKey() { Map<Schema.Field, Object> fieldToObjectMap = new HashMap<>(); fieldToObjectMap.put(new Schema.Field("id", Schema.Type.LONG), this.id); return new PrimaryKey(fieldToObjectMap); } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Long getTimestamp() { return timestamp; } public void setTimestamp(Long timestamp) { this.timestamp = timestamp; } public List<Tag> getTags() { return tags; } public void setTags(List<Tag> tags) { this.tags = tags; } @JsonIgnore public Schema getSchema() { return Schema.of( new Schema.Field(ID, Schema.Type.LONG), new Schema.Field(NAME, Schema.Type.STRING), new Schema.Field(DESCRIPTION, Schema.Type.STRING), new Schema.Field(TIMESTAMP, Schema.Type.LONG) ); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Tag tag = (Tag) o; return id != null ? id.equals(tag.id) : tag.id == null; } @Override public int hashCode() { return id != null ? id.hashCode() : 0; } @Override public String toString() { return "Tag{" + "id=" + id + ", name='" + name + '\'' + ", description='" + description + '\'' + "}"; } }