All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.usergrid.persistence.schema.EntityInfo Maven / Gradle / Ivy

There is a newer version: 0.0.27.1
Show newest version
/*******************************************************************************
 * Copyright 2012 Apigee Corporation
 * 
 * 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 org.usergrid.persistence.schema;

import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

import org.usergrid.persistence.Schema;

public class EntityInfo {

	private String type;

	private String aliasProperty;

	private Map properties = new TreeMap(
			String.CASE_INSENSITIVE_ORDER);
	private final Set indexed = new TreeSet(
			String.CASE_INSENSITIVE_ORDER);
	private final Set basic = new TreeSet(
			String.CASE_INSENSITIVE_ORDER);
	private final Set required = new TreeSet(
			String.CASE_INSENSITIVE_ORDER);
	private final Set indexedInConnections = new TreeSet(
			String.CASE_INSENSITIVE_ORDER);
	private Map dictionaries = new TreeMap(
			String.CASE_INSENSITIVE_ORDER);
	private Map collections = new TreeMap(
			String.CASE_INSENSITIVE_ORDER);
	private final Set fulltextIndexed = new TreeSet(
			String.CASE_INSENSITIVE_ORDER);

	private boolean publicVisible = true;

	private boolean includedInExport = true;;

	public EntityInfo() {
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public boolean hasProperty(String propertyName) {
		return properties.containsKey(propertyName);
	}

	public PropertyInfo getProperty(String propertyName) {
		return properties.get(propertyName);
	}

	public boolean hasProperties() {
		return !properties.isEmpty();
	}

	public Map getProperties() {
		return properties;
	}

	public void setProperties(Map properties) {
		this.properties = new TreeMap(
				String.CASE_INSENSITIVE_ORDER);
		this.properties.putAll(properties);
		for (String key : properties.keySet()) {
			PropertyInfo property = properties.get(key);
			property.setName(key);

			if (property.isIndexed()) {
				indexed.add(key);
			}

			if (property.isRequired()) {
				required.add(key);
				// logger.info("property " + key + " is required");
			}

			if (property.isBasic()) {
				basic.add(key);
			}

			if (property.isIndexedInConnections()) {
				indexedInConnections.add(key);
			}

			if (property.isFulltextIndexed()) {
				fulltextIndexed.add(key);
			}

			if (property.isAliasProperty()) {
				aliasProperty = property.getName();
			}
		}
	}

	public boolean isPropertyMutable(String propertyName) {
		PropertyInfo property = properties.get(propertyName);
		if (property == null) {
			return false;
		}
		return property.isMutable();
	}

	public boolean isPropertyUnique(String propertyName) {
		PropertyInfo property = properties.get(propertyName);
		if (property == null) {
			return false;
		}
		return property.isUnique();
	}

	public boolean isPropertyTimestamp(String propertyName) {
		PropertyInfo property = properties.get(propertyName);
		if (property == null) {
			return false;
		}
		return property.isTimestamp();
	}

	public boolean isPropertyRequired(String propertyName) {
		return required.contains(propertyName);
	}

	public Set getIndexedProperties() {
		return indexed;
	}

	public boolean isPropertyIndexed(String propertyName) {
		return indexed.contains(propertyName);
	}

	public boolean isPropertyFulltextIndexed(String propertyName) {
		return fulltextIndexed.contains(propertyName);
	}

	public Set getRequiredProperties() {
		return required;
	}

	public boolean isPropertyIndexedInConnections(String propertyName) {
		return indexedInConnections.contains(propertyName);
	}

	public Set getPropertiesIndexedInConnections() {
		return indexedInConnections;
	}

	public boolean isPropertyBasic(String propertyName) {
		return basic.contains(propertyName);
	}

	public Set getBasicProperties() {
		return basic;
	}

	public boolean hasDictionary(String dictionaryName) {
		return dictionaries.containsKey(dictionaryName);
	}

	public DictionaryInfo getDictionary(String dictionaryName) {
		return dictionaries.get(dictionaryName);
	}

	public boolean hasDictionaries() {
		return !dictionaries.isEmpty();
	}

	public Map getDictionaries() {
		return dictionaries;
	}

	public void setDictionaries(Map dictionaries) {
		this.dictionaries = new TreeMap(
				String.CASE_INSENSITIVE_ORDER);
		this.dictionaries.putAll(dictionaries);
		for (String key : dictionaries.keySet()) {
			DictionaryInfo dictionary = dictionaries.get(key);
			dictionary.setName(key);
		}

		for (@SuppressWarnings("rawtypes")
		Entry dictionaryEntry : Schema.DEFAULT_DICTIONARIES
				.entrySet()) {
			String dictionaryName = dictionaryEntry.getKey();
			if (!this.dictionaries.containsKey(dictionaryName)) {
				DictionaryInfo dictionary = new DictionaryInfo();
				dictionary.setName(dictionaryName);
				dictionary.setKeyType(String.class);
				dictionary.setValueType(dictionaryEntry.getValue());
				this.dictionaries.put(dictionaryName, dictionary);
			}
		}
	}

	public boolean hasCollection(String collectionName) {
		return collections.containsKey(collectionName);
	}

	public CollectionInfo getCollection(String collectionName) {
		return collections.get(collectionName);
	}

	public Map getCollections() {
		return collections;
	}

	public void setCollections(Map collections) {
		this.collections = new TreeMap(
				String.CASE_INSENSITIVE_ORDER);
		this.collections.putAll(collections);
	}

	public void mapCollectors(Schema schema, String entityType) {

		setType(entityType);

		for (String collectionName : collections.keySet()) {
			CollectionInfo collection = collections.get(collectionName);
			collection.setContainer(this);
			collection.setName(collectionName);
			schema.mapCollector(collection.getType(), entityType,
					collectionName, collection);
		}
	}

	public String getAliasProperty() {
		return aliasProperty;
	}

	public void setAliasProperty(String nameProperty) {
		aliasProperty = nameProperty;
	}

	public PropertyInfo getAliasPropertyObject() {
		if (aliasProperty == null) {
			return null;
		}
		return getProperty(aliasProperty);
	}

	public boolean isPublic() {
		return publicVisible;
	}

	public void setPublic(boolean publicVisible) {
		this.publicVisible = publicVisible;
	}

	public void setIncludedInExport(boolean includedInExport) {
		this.includedInExport = includedInExport;
	}

	public boolean isIncludedInExport() {
		return includedInExport;
	}

	@Override
	public String toString() {
		return "Entity [type=" + type + ", aliasProperty=" + aliasProperty
				+ ", properties=" + properties + ", indexed=" + indexed
				+ ", required=" + required + ", indexedInConnections="
				+ indexedInConnections + ", sets=" + dictionaries
				+ ", collections=" + collections + ", fulltextIndexed="
				+ fulltextIndexed + ", publicVisible=" + publicVisible + "]";
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy