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

org.molgenis.data.semanticsearch.explain.bean.ExplainedAttribute Maven / Gradle / Ivy

There is a newer version: 4.1.0
Show newest version
package org.molgenis.data.semanticsearch.explain.bean;

import com.google.auto.value.AutoValue;
import com.google.common.collect.Sets;
import org.molgenis.data.meta.model.Attribute;
import org.molgenis.data.meta.model.AttributeMetadata;
import org.molgenis.gson.AutoGson;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@AutoValue
@AutoGson(autoValueClass = AutoValue_ExplainedAttribute.class)
public abstract class ExplainedAttribute
{
	public static ExplainedAttribute create(Attribute attribute)
	{
		return new AutoValue_ExplainedAttribute(attributeToMap(attribute), Collections.emptySet(),
				false);
	}

	public static ExplainedAttribute create(Attribute attribute,
			Iterable explainedQueryStrings, boolean highQuality)
	{
		return new AutoValue_ExplainedAttribute(attributeToMap(attribute),
				Sets.newHashSet(explainedQueryStrings), highQuality);
	}

	public abstract Map getAttribute();

	public abstract Set getExplainedQueryStrings();

	public abstract boolean isHighQuality();

	private static Map attributeToMap(Attribute attribute)
	{
		Map map = new HashMap();
		map.put(AttributeMetadata.NAME, attribute.getName());
		map.put(AttributeMetadata.LABEL, attribute.getLabel());
		map.put(AttributeMetadata.DESCRIPTION, attribute.getDescription());
		map.put(AttributeMetadata.TYPE, attribute.getDataType().toString());
		map.put(AttributeMetadata.IS_NULLABLE, attribute.isNillable());
		map.put(AttributeMetadata.IS_UNIQUE, attribute.isUnique());
		if (attribute.getRefEntity() != null)
		{
			map.put(AttributeMetadata.REF_ENTITY_TYPE, attribute.getRefEntity().getName());
		}
		return map;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy