org.odpi.openmetadata.commonservices.generichandlers.TabularColumnConverter Maven / Gradle / Ivy
The newest version!
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright Contributors to the ODPi Egeria project. */
package org.odpi.openmetadata.commonservices.generichandlers;
import org.odpi.openmetadata.frameworks.openmetadata.metadataelements.SchemaTypeElement;
import org.odpi.openmetadata.frameworks.openmetadata.metadataelements.TabularColumnElement;
import org.odpi.openmetadata.frameworks.openmetadata.properties.schema.tabular.TabularColumnProperties;
import org.odpi.openmetadata.frameworks.connectors.ffdc.PropertyServerException;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefCategory;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryHelper;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
/**
* TabularColumnConverter transfers the relevant properties from an Open Metadata Repository Services (OMRS)
* EntityDetail object into a TabularColumnElement bean.
*/
public class TabularColumnConverter extends OMFConverter
{
/**
* Constructor
*
* @param repositoryHelper helper object to parse entity
* @param serviceName name of this component
* @param serverName local server name
*/
public TabularColumnConverter(OMRSRepositoryHelper repositoryHelper,
String serviceName,
String serverName)
{
super(repositoryHelper, serviceName, serverName);
}
/**
* Extract the properties from the schema attribute entity. Each API creates a specialization of this method for its beans.
*
* @param beanClass name of the class to create
* @param schemaAttributeEntity entity containing the properties for the main schema attribute
* @param typeClass name of type used to describe the schema type
* @param schemaType bean containing the properties of the schema type - this is filled out by the schema type converter
* @param schemaAttributeRelationships relationships containing the links to other schema attributes
* @param methodName calling method
* @param bean type used to create the schema type
* @return bean populated with properties from the instances supplied
* @throws PropertyServerException there is a problem instantiating the bean
*/
@Override
public B getNewSchemaAttributeBean(Class beanClass,
EntityDetail schemaAttributeEntity,
Class typeClass,
T schemaType,
List schemaAttributeRelationships,
String methodName) throws PropertyServerException
{
try
{
/*
* This is initial confirmation that the generic converter has been initialized with an appropriate bean class.
*/
B returnBean = beanClass.getDeclaredConstructor().newInstance();
if (returnBean instanceof TabularColumnElement bean)
{
TabularColumnProperties properties = new TabularColumnProperties();
if (schemaAttributeEntity != null)
{
SchemaTypeElement schemaTypeElement = null;
if (schemaType instanceof SchemaTypeElement)
{
schemaTypeElement = (SchemaTypeElement) schemaType;
}
bean.setElementHeader(this.getMetadataElementHeader(beanClass, schemaAttributeEntity, methodName));
super.setUpSchemaAttribute(schemaAttributeEntity, schemaTypeElement, properties);
properties.setTypeName(bean.getElementHeader().getType().getTypeName());
bean.setTabularColumnProperties(properties);
}
else
{
handleMissingMetadataInstance(beanClass.getName(), TypeDefCategory.ENTITY_DEF, methodName);
}
}
return returnBean;
}
catch (IllegalAccessException | InstantiationException | ClassCastException | NoSuchMethodException | InvocationTargetException error)
{
super.handleInvalidBeanClass(beanClass.getName(), error, methodName);
}
return null;
}
}