Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/odpi/egeria into code2023
Browse files Browse the repository at this point in the history
  • Loading branch information
mandy-chessell committed Feb 13, 2023
2 parents f0357c5 + 5000ea5 commit 9aa4a72
Show file tree
Hide file tree
Showing 20 changed files with 189 additions and 342 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@
import org.apache.commons.collections4.MapUtils;
import org.odpi.openmetadata.accessservices.assetcatalog.model.AssetCatalogBean;
import org.odpi.openmetadata.accessservices.assetcatalog.model.AssetCatalogItemElement;
import org.odpi.openmetadata.accessservices.assetcatalog.model.Elements;
import org.odpi.openmetadata.accessservices.assetcatalog.model.Classification;
import org.odpi.openmetadata.accessservices.assetcatalog.model.Element;
import org.odpi.openmetadata.accessservices.assetcatalog.model.ElementOrigin;
import org.odpi.openmetadata.accessservices.assetcatalog.model.Elements;
import org.odpi.openmetadata.accessservices.assetcatalog.model.Relationship;
import org.odpi.openmetadata.accessservices.assetcatalog.model.Type;
import org.odpi.openmetadata.accessservices.assetcatalog.util.Constants;
import org.odpi.openmetadata.commonservices.generichandlers.OpenMetadataAPIGenericConverter;
import org.odpi.openmetadata.frameworks.connectors.properties.beans.ElementOriginCategory;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.ArrayPropertyValue;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityProxy;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProperties;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProvenanceType;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceType;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.MapPropertyValue;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDef;
Expand Down Expand Up @@ -285,7 +283,6 @@ public Elements buildAssetElements(EntityDetail entityDetail) {
private Type convertInstanceType(InstanceType instanceType) {
Type type = new Type();
type.setName(instanceType.getTypeDefName());
type.setDescription(instanceType.getTypeDefDescription());
type.setVersion(instanceType.getTypeDefVersion());
return type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ private Elements getElementsFromEntity(EntityDetail mockedEntity) {
private Type convertInstanceType(InstanceType instanceType) {
Type type = new Type();
type.setName(instanceType.getTypeDefName());
type.setDescription(instanceType.getTypeDefDescription());
type.setVersion(instanceType.getTypeDefVersion());
return type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityProxy;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceHeader;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceType;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefLink;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefSummary;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -33,6 +35,7 @@ public class SecurityManagerOMRSTopicListener extends OMRSTopicListenerBase

private final SecurityManagerOutTopicPublisher eventPublisher;
private final UserIdentityHandler<UserIdentityElement> userIdentityHandler;
private final OMRSRepositoryHelper repositoryHelper;
private final String localServerUserId;
private final List<String> supportedZones;

Expand All @@ -56,6 +59,7 @@ public SecurityManagerOMRSTopicListener(String
super(serviceName, auditLog);

this.userIdentityHandler = userIdentityHandler;
this.repositoryHelper = userIdentityHandler.getRepositoryHelper();
this.supportedZones = supportedZones;
this.localServerUserId = localServerUserId;
this.eventPublisher = eventPublisher;
Expand Down Expand Up @@ -836,20 +840,24 @@ private boolean isTypeOfInterest(InstanceHeader entityHeader)
{
List<String> typeNames = new ArrayList<>();

typeNames.add(entityHeader.getType().getTypeDefName());
InstanceType type = entityHeader.getType();

if (entityHeader.getType().getTypeDefSuperTypes() != null)
if (type != null)
{
for (TypeDefLink superType : entityHeader.getType().getTypeDefSuperTypes())
{
if (superType != null)
{
typeNames.add(superType.getName());
typeNames.add(type.getTypeDefName());

List<TypeDefLink> superTypes = repositoryHelper.getSuperTypes(serviceName, type.getTypeDefName());

if (superTypes != null) {
for (TypeDefLink superType : superTypes) {
if (superType != null) {
typeNames.add(superType.getName());
}
}
}
}

return typeNames.contains(interestingTypeName);
return typeNames.contains(interestingTypeName);
}
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.odpi.openmetadata.repositoryservices.connectors.omrstopic.OMRSTopicConnector;
import org.odpi.openmetadata.repositoryservices.connectors.openmetadatatopic.OpenMetadataTopicConnector;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryConnector;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryHelper;
import org.odpi.openmetadata.repositoryservices.ffdc.exception.OMRSConfigErrorException;

import java.util.List;
Expand Down Expand Up @@ -57,24 +58,28 @@ public synchronized void initialize(AccessServiceConfig accessServiceConfigurati
try
{
this.auditLog = auditLog;
String accessServiceName = accessServiceConfigurationProperties.getAccessServiceName();
List<String> supportedZones = super.extractSupportedZones(accessServiceConfigurationProperties.getAccessServiceOptions(),
accessServiceConfigurationProperties.getAccessServiceName(), auditLog);
OpenMetadataTopicConnector securityOfficerOutputTopic = initializeSecurityOfficerTopicConnector(
accessServiceConfigurationProperties.getAccessServiceOutTopic());
SecurityOfficerEventProcessor securityOfficerEventProcessor = new SecurityOfficerEventProcessor(enterpriseOMRSRepositoryConnector);

securityOfficerPublisher = new SecurityOfficerPublisher(securityOfficerEventProcessor, securityOfficerOutputTopic, auditLog);
accessServiceName, auditLog);
Connection accessServiceOutTopic = accessServiceConfigurationProperties.getAccessServiceOutTopic();
OpenMetadataTopicConnector securityOfficerOutputTopic = initializeSecurityOfficerTopicConnector(accessServiceOutTopic);
SecurityOfficerEventProcessor securityOfficerEventProcessor = new SecurityOfficerEventProcessor(enterpriseOMRSRepositoryConnector,
accessServiceName);

OMRSRepositoryHelper repositoryHelper = enterpriseOMRSRepositoryConnector.getRepositoryHelper();
securityOfficerPublisher = new SecurityOfficerPublisher(securityOfficerEventProcessor, securityOfficerOutputTopic,
repositoryHelper, accessServiceName, auditLog);
this.instance = new SecurityOfficerInstance(enterpriseOMRSRepositoryConnector, supportedZones, auditLog, serverUserName,
enterpriseOMRSRepositoryConnector.getMaxPageSize(),
accessServiceConfigurationProperties.getAccessServiceOutTopic(),
accessServiceOutTopic,
securityOfficerPublisher);
this.serverName = instance.getServerName();
this.registerWithEnterpriseTopic(AccessServiceDescription.SECURITY_OFFICER_OMAS.getAccessServiceFullName(),
serverName,
enterpriseOMRSTopicConnector,
new SecurityOfficerOMRSTopicListener(
securityOfficerPublisher,
enterpriseOMRSRepositoryConnector.getRepositoryHelper(),
repositoryHelper,
enterpriseOMRSRepositoryConnector.getRepositoryValidator(),
AccessServiceDescription.SECURITY_OFFICER_OMAS.getAccessServiceFullName(),
serverName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package org.odpi.openmetadata.accessservices.securityofficer.server.handler;

import org.apache.commons.collections4.CollectionUtils;
import org.odpi.openmetadata.accessservices.securityofficer.api.ffdc.SecurityOfficerErrorCode;
import org.odpi.openmetadata.frameworks.connectors.ffdc.PropertyServerException;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.OMRSMetadataCollection;
Expand All @@ -14,6 +15,7 @@
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefLink;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryConnector;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryHelper;
import org.odpi.openmetadata.repositoryservices.ffdc.exception.EntityNotKnownException;
import org.odpi.openmetadata.repositoryservices.ffdc.exception.EntityProxyOnlyException;
import org.odpi.openmetadata.repositoryservices.ffdc.exception.FunctionNotSupportedException;
Expand All @@ -30,6 +32,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import static org.odpi.openmetadata.accessservices.securityofficer.server.utils.Constants.SCHEMA_ATTRIBUTE;
import static org.odpi.openmetadata.accessservices.securityofficer.server.utils.Constants.SECURITY_OFFICER;
Expand All @@ -39,20 +42,25 @@ public class SecurityOfficerHandler {

private static final Logger log = LoggerFactory.getLogger(SecurityOfficerHandler.class);
private OMRSMetadataCollection metadataCollection;
private OMRSRepositoryHelper repositoryHelper;
private final String sourceName;

/**
* Construct the connection handler with a link to the property handlers's connector and this access service's
* official name.
*
* @param repositoryConnector - connector to the property handlers.
* @param sourceName source name
* @throws PropertyServerException - there is a problem retrieving information from the metadata server
*/
public SecurityOfficerHandler(OMRSRepositoryConnector repositoryConnector) throws PropertyServerException {
public SecurityOfficerHandler(OMRSRepositoryConnector repositoryConnector, String sourceName) throws PropertyServerException {
final String methodName = "SecurityOfficerHandler";

this.sourceName = sourceName;
if (repositoryConnector != null) {
try {
this.metadataCollection = repositoryConnector.getMetadataCollection();
this.repositoryHelper = repositoryConnector.getRepositoryHelper();
} catch (RepositoryErrorException e) {
throw new PropertyServerException(SecurityOfficerErrorCode.NO_METADATA_COLLECTION.getMessageDefinition(repositoryConnector.getRepositoryName()),
this.getClass().getName(), methodName, e);
Expand Down Expand Up @@ -126,16 +134,22 @@ private EntityDetail getSchemaElement(String userId, String glossaryTermGUID, Re
}

private boolean isSchemaElement(InstanceType instanceType) throws UserNotAuthorizedException, RepositoryErrorException, org.odpi.openmetadata.repositoryservices.ffdc.exception.InvalidParameterException, TypeDefNotKnownException {
List<TypeDefLink> typeDefSuperTypes =instanceType.getTypeDefSuperTypes();
if (typeDefSuperTypes.stream().anyMatch(typeDefLink -> typeDefLink.getName().equals(SCHEMA_ATTRIBUTE))) {
List<TypeDefLink> typeDefSuperTypes = repositoryHelper.getSuperTypes(sourceName, instanceType.getTypeDefName());
if (CollectionUtils.isEmpty(typeDefSuperTypes)) {
return false;
}

if (typeDefSuperTypes.stream().anyMatch(typeDefLink -> Objects.equals(typeDefLink.getName(), SCHEMA_ATTRIBUTE))) {
return true;
}

for(TypeDefLink typeDefLink : typeDefSuperTypes){
if(metadataCollection.getTypeDefByName(SECURITY_OFFICER, typeDefLink.getName()).getSuperType().getName().equals(SCHEMA_ATTRIBUTE)){
for (TypeDefLink typeDefLink : typeDefSuperTypes) {
TypeDefLink superType = metadataCollection.getTypeDefByName(SECURITY_OFFICER, typeDefLink.getName()).getSuperType();
if (superType != null && Objects.equals(superType.getName(), SCHEMA_ATTRIBUTE)) {
return true;
}
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public class SecurityOfficerEventProcessor {
private SecurityOfficerHandler securityOfficerHandler;
private Builder builder = new Builder();

public SecurityOfficerEventProcessor(OMRSRepositoryConnector enterpriseOMRSRepositoryConnector) {
public SecurityOfficerEventProcessor(OMRSRepositoryConnector enterpriseOMRSRepositoryConnector, String sourceName) {
try {
securityOfficerHandler = new SecurityOfficerHandler(enterpriseOMRSRepositoryConnector);
securityOfficerHandler = new SecurityOfficerHandler(enterpriseOMRSRepositoryConnector, sourceName);
} catch (PropertyServerException e) {
log.error(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.odpi.openmetadata.accessservices.securityofficer.api.ffdc.SecurityOfficerAuditCode;
import org.odpi.openmetadata.accessservices.securityofficer.api.events.SecurityOfficerEvent;
import org.odpi.openmetadata.accessservices.securityofficer.api.events.SecurityOfficerTagEvent;
import org.odpi.openmetadata.accessservices.securityofficer.api.ffdc.SecurityOfficerAuditCode;
import org.odpi.openmetadata.accessservices.securityofficer.server.processors.SecurityOfficerEventProcessor;
import org.odpi.openmetadata.frameworks.auditlog.AuditLog;
import org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException;
Expand All @@ -20,7 +21,9 @@
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProvenanceType;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceType;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefLink;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefSummary;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryHelper;
import org.odpi.openmetadata.repositoryservices.events.OMRSInstanceEvent;
import org.odpi.openmetadata.repositoryservices.events.OMRSInstanceEventProcessor;
import org.slf4j.Logger;
Expand All @@ -39,16 +42,20 @@ public class SecurityOfficerPublisher extends OMRSInstanceEventProcessor {
private static final Logger log = LoggerFactory.getLogger(SecurityOfficerPublisher.class);
private static final String eventPublisherName = "Security Officer OMAS Event Publisher";
private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer();
private SecurityOfficerEventProcessor securityOfficerEventProcessor;
private OpenMetadataTopicConnector openMetadataTopicConnector;
private AuditLog auditLog;
private final SecurityOfficerEventProcessor securityOfficerEventProcessor;
private final OpenMetadataTopicConnector openMetadataTopicConnector;
private final OMRSRepositoryHelper repositoryHelper;
private final AuditLog auditLog;
private final String serviceName;

public SecurityOfficerPublisher(SecurityOfficerEventProcessor securityOfficerEventProcessor, OpenMetadataTopicConnector openMetadataTopicConnector, AuditLog auditLog) {
public SecurityOfficerPublisher(SecurityOfficerEventProcessor securityOfficerEventProcessor, OpenMetadataTopicConnector openMetadataTopicConnector, OMRSRepositoryHelper repositoryHelper, String serviceName, AuditLog auditLog) {
super(eventPublisherName);

this.securityOfficerEventProcessor = securityOfficerEventProcessor;
this.openMetadataTopicConnector = openMetadataTopicConnector;
this.repositoryHelper = repositoryHelper;
this.auditLog = auditLog;
this.serviceName = serviceName;
}

@Override
Expand Down Expand Up @@ -234,7 +241,8 @@ public void publishEvent(SecurityOfficerEvent securityOfficerEvent) {

private boolean isSchemaElement(InstanceType type) {
if (type != null) {
return type.getTypeDefSuperTypes().stream()
List<TypeDefLink> superTypes = repositoryHelper.getSuperTypes(serviceName, type.getTypeDefName());
return superTypes.stream()
.filter(Objects::nonNull)
.anyMatch(typeDefLink -> SCHEMA_ELEMENT.equals(typeDefLink.getName()));
} else {
Expand Down
Loading

0 comments on commit 9aa4a72

Please sign in to comment.