org.odpi.openmetadata.commonservices.generichandlers.SecurityGroupConverter 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.connectors.ffdc.PropertyServerException;
import org.odpi.openmetadata.frameworks.openmetadata.metadataelements.SecurityGroupElement;
import org.odpi.openmetadata.frameworks.openmetadata.properties.security.SecurityGroupProperties;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProperties;
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;
/**
* GovernanceDefinitionConverter provides common methods for transferring relevant properties from an Open Metadata Repository Services (OMRS)
* EntityDetail object into a bean that inherits from GovernanceDefinition.
*/
public class SecurityGroupConverter extends OMFConverter
{
/**
* Constructor
*
* @param repositoryHelper helper object to parse entity
* @param serviceName name of this component
* @param serverName local server name
*/
public SecurityGroupConverter(OMRSRepositoryHelper repositoryHelper,
String serviceName,
String serverName)
{
super(repositoryHelper, serviceName, serverName);
}
/**
* Using the supplied instances, return a new instance of the bean. It is used for beans such as
* an Annotation or DataField bean which combine knowledge from the entity and its linked relationships.
*
* @param beanClass name of the class to create
* @param primaryEntity entity that is the root of the collection of entities that make up the
* content of the bean
* @param relationships relationships linking the entities
* @param methodName calling method
* @return bean populated with properties from the instances supplied
* @throws PropertyServerException there is a problem instantiating the bean
*/
@SuppressWarnings(value = "unused")
@Override
public B getNewComplexBean(Class beanClass,
EntityDetail primaryEntity,
List relationships,
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 SecurityGroupElement bean)
{
if (primaryEntity != null)
{
bean.setElementHeader(this.getMetadataElementHeader(beanClass, primaryEntity, methodName));
/*
* The initial set of values come from the entity.
*/
InstanceProperties instanceProperties = new InstanceProperties(primaryEntity.getProperties());
String typeName = primaryEntity.getType().getTypeDefName();
SecurityGroupProperties securityGroupProperties = new SecurityGroupProperties();
securityGroupProperties.setDocumentIdentifier(this.removeQualifiedName(instanceProperties));
securityGroupProperties.setAdditionalProperties(this.removeAdditionalProperties(instanceProperties));
securityGroupProperties.setTitle(this.removeTitle(instanceProperties));
securityGroupProperties.setScope(this.removeScope(instanceProperties));
securityGroupProperties.setDomainIdentifier(this.removeDomainIdentifier(instanceProperties));
securityGroupProperties.setPriority(this.removePriority(instanceProperties));
securityGroupProperties.setOutcomes(this.removeOutcomes(instanceProperties));
securityGroupProperties.setResults(this.removeResults(instanceProperties));
securityGroupProperties.setDistinguishedName(this.removeDistinguishedName(instanceProperties));
/*
* Any remaining properties are returned in the extended properties. They are
* assumed to be defined in a subtype.
*/
securityGroupProperties.setTypeName(bean.getElementHeader().getType().getTypeName());
securityGroupProperties.setExtendedProperties(this.getRemainingExtendedProperties(instanceProperties));
bean.setProperties(securityGroupProperties);
}
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;
}
/**
* Using the supplied instances, return a new instance of the bean. This is used for beans that
* contain a combination of the properties from an entity and that of a connected relationship.
*
* @param beanClass name of the class to create
* @param entity entity containing the properties
* @param relationship relationship containing the properties
* @param methodName calling method
* @return bean populated with properties from the instances supplied
* @throws PropertyServerException there is a problem instantiating the bean
*/
@Override
public B getNewBean(Class beanClass,
EntityDetail entity,
Relationship relationship,
String methodName) throws PropertyServerException
{
B returnBean = this.getNewBean(beanClass, entity, methodName);
if (returnBean instanceof SecurityGroupElement bean)
{
bean.setRelatedElement(super.getRelatedElement(beanClass, entity, relationship, methodName));
}
return returnBean;
}
}