http://git-wip-us.apache.org/repos/asf/atlas/blob/f57fd7f0/omas-assetconsumer/pom.xml ---------------------------------------------------------------------- diff --git a/omas-assetconsumer/pom.xml b/omas-assetconsumer/pom.xml new file mode 100644 index 0000000..29935e7 --- /dev/null +++ b/omas-assetconsumer/pom.xml @@ -0,0 +1,107 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you 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. + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <artifactId>apache-atlas</artifactId> + <groupId>org.apache.atlas</groupId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>omas-assetconsumer</artifactId> + + <name>Asset Consumer Open Metadata Access Service (OMAS)</name> + <description>APIs for tools and applications wishing to access data assets through Open Connector Framework (OCF) connectors.</description> + + <packaging>jar</packaging> + + <dependencies> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + <version>1.5.7.RELEASE</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <version>1.5.7.RELEASE</version> + </dependency> + + <dependency> + <groupId>org.apache.atlas</groupId> + <artifactId>om-fwk-ocf</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.atlas</groupId> + <artifactId>omrs</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.atlas</groupId> + <artifactId>omag-api</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.atlas</groupId> + <artifactId>omas-connectedasset</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + <version>3.2.2</version> + </dependency> + + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <scope>test</scope> + </dependency> + + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>2.4</version> + <executions> + <execution> + <goals> + <goal>test-jar</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/atlas/blob/f57fd7f0/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/AssetConsumerInterface.java ---------------------------------------------------------------------- diff --git a/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/AssetConsumerInterface.java b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/AssetConsumerInterface.java new file mode 100644 index 0000000..2118568 --- /dev/null +++ b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/AssetConsumerInterface.java @@ -0,0 +1,388 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.apache.atlas.omas.assetconsumer; + + +import org.apache.atlas.ocf.Connector; +import org.apache.atlas.ocf.ffdc.ConnectionCheckedException; +import org.apache.atlas.ocf.ffdc.ConnectorCheckedException; +import org.apache.atlas.ocf.properties.CommentType; +import org.apache.atlas.omas.connectedasset.properties.AssetUniverse; +import org.apache.atlas.ocf.properties.beans.Connection; +import org.apache.atlas.ocf.properties.StarRating; +import org.apache.atlas.omas.assetconsumer.ffdc.exceptions.*; + +/** + * The AssetConsumer Open Metadata Access Service (OMAS) is used by applications and tools as a factory for Open + * Connector Framework (OCF) connectors. The configuration for the connectors is managed as open metadata in + * a Connection definition. The caller to the AssetConsumer OMAS passes either the name, GUID or URL for the + * connection to the appropriate method to retrieve a connector. The AssetConsumer OMAS retrieves the connection + * from the metadata repository and creates an appropriate connector as described the connection and + * returns it to the caller. + * + * Each connection has a unique guid and a name. An application can request a connector instance + * from the OCF's Connector Broker using the guid, name or URL of a connection, or by passing a fully + * populated connection object. If the connection guid, name or URL is used, AssetConsumer OMAS + * looks up the connection properties in the metadata repository before calling the OCF ConnectorBroker to create the + * connector + * + * In addition it is possible to maintain feedback for the asset through the AssetConsumer OMAS. + * This is in terms of tags, star ratings, likes and comments. There is also the ability to add audit log records + * related to the use of the asset through the AssetConsumerInterface OMAS. + */ +public interface AssetConsumerInterface +{ + /** + * Returns the connector corresponding to the supplied connection name. + * + * @param userId - String - userId of user making request. + * @param connectionName - this may be the qualifiedName or displayName of the connection. + * + * @return Connector - connector instance. + * @throws InvalidParameterException - one of the parameters is null or invalid. + * @throws UnrecognizedConnectionNameException - there is no connection defined for this name. + * @throws AmbiguousConnectionNameException - there is more than one connection defined for this name. + * @throws ConnectionCheckedException - there are errors in the configuration of the connection which is preventing + * the creation of a connector. + * @throws ConnectorCheckedException - there are errors in the initialization of the connector. + * @throws PropertyServerException - there is a problem retrieving information from the property (metadata) server. + * @throws UserNotAuthorizedException - the requesting user is not authorized to issue this request. + */ + Connector getConnectorByName(String userId, + String connectionName) throws InvalidParameterException, + UnrecognizedConnectionNameException, + AmbiguousConnectionNameException, + ConnectionCheckedException, + ConnectorCheckedException, + PropertyServerException, + UserNotAuthorizedException; + + + /** + * Returns the connector corresponding to the supplied connection GUID. + * + * @param userId - String - userId of user making request. + * @param connectionGUID - the unique id for the connection within the metadata repository. + * + * @return Connector - connector instance. + * + * @throws InvalidParameterException - one of the parameters is null or invalid. + * @throws UnrecognizedConnectionGUIDException - the supplied GUID is not recognized by the property server. + * @throws ConnectionCheckedException - there are errors in the configuration of the connection which is preventing + * the creation of a connector. + * @throws ConnectorCheckedException - there are errors in the initialization of the connector. + * @throws PropertyServerException - there is a problem retrieving information from the property (metadata) server. + * @throws UserNotAuthorizedException - the requesting user is not authorized to issue this request. + */ + Connector getConnectorByGUID(String userId, + String connectionGUID) throws InvalidParameterException, + UnrecognizedConnectionGUIDException, + ConnectionCheckedException, + ConnectorCheckedException, + PropertyServerException, + UserNotAuthorizedException; + + + /** + * Returns the connector corresponding to the supplied connection. + * + * @param userId - String - userId of user making request. + * @param connection - the connection object that contains the properties needed to create the connection. + * + * @return Connector - connector instance + * + * @throws InvalidParameterException - one of the parameters is null or invalid. + * @throws ConnectionCheckedException - there are errors in the configuration of the connection which is preventing + * the creation of a connector. + * @throws ConnectorCheckedException - there are errors in the initialization of the connector. + * @throws PropertyServerException - there is a problem retrieving information from the property server. + * @throws UserNotAuthorizedException - the requesting user is not authorized to issue this request. + */ + Connector getConnectorByConnection(String userId, + Connection connection) throws InvalidParameterException, + ConnectionCheckedException, + ConnectorCheckedException, + PropertyServerException, + UserNotAuthorizedException; + + + /** + * Returns a comprehensive collection of properties about the requested asset. + * + * @param userId - String - userId of user making request. + * @param assetGUID - String - unique id for asset. + * + * @return AssetUniverse - a comprehensive collection of properties about the asset. + + * @throws InvalidParameterException - one of the parameters is null or invalid. + * @throws PropertyServerException - There is a problem retrieving the asset properties from + * the property server. + * @throws UserNotAuthorizedException - the requesting user is not authorized to issue this request. + */ + AssetUniverse getAssetProperties(String userId, + String assetGUID) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException; + + + /** + * Creates an Audit log record for the asset. This log record is stored in the Asset's Audit Log. + * + * @param userId - String - userId of user making request. + * @param assetGUID - String - unique id for the asset. + * @param connectorInstanceId - String - (optional) id of connector in use (if any). + * @param connectionName - String - (optional) name of the connection (extracted from the connector). + * @param connectorType - String - (optional) type of connector in use (if any). + * @param contextId - String - (optional) function name, or processId of the activity that the caller is performing. + * @param message - log record content. + * + * @throws InvalidParameterException - one of the parameters is null or invalid. + * @throws PropertyServerException - There is a problem adding the asset properties to + * the property server. + * @throws UserNotAuthorizedException - the requesting user is not authorized to issue this request. + */ + void addLogMessageToAsset(String userId, + String assetGUID, + String connectorInstanceId, + String connectionName, + String connectorType, + String contextId, + String message) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException; + + + + /** + * Adds a new public tag to the asset's properties. + * + * @param userId - String - userId of user making request. + * @param assetGUID - String - unique id for the asset. + * @param tagName - String - name of the tag. + * @param tagDescription - String - (optional) description of the tag. Setting a description, particularly in + * a public tag makes the tag more valuable to other users and can act as an embryonic + * glossary term. + * @return String - GUID for new tag. + * @throws InvalidParameterException - one of the parameters is null or invalid. + * @throws PropertyServerException - There is a problem adding the asset properties to + * the property server. + * @throws UserNotAuthorizedException - the requesting user is not authorized to issue this request. + */ + String addTagToAsset(String userId, + String assetGUID, + String tagName, + String tagDescription) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException; + + + /** + * Adds a new private tag to the asset's properties. + * + * @param userId - String - userId of user making request. + * @param assetGUID - String - unique id for the asset. + * @param tagName - String - name of the tag. + * @param tagDescription - String - (optional) description of the tag. Setting a description, particularly in + * a public tag makes the tag more valuable to other users and can act as an embryonic + * glossary term. + * @return String - GUID for new tag. + * @throws InvalidParameterException - one of the parameters is null or invalid. + * @throws PropertyServerException - There is a problem adding the asset properties to + * the property server. + * @throws UserNotAuthorizedException - the requesting user is not authorized to issue this request. + */ + String addPrivateTagToAsset(String userId, + String assetGUID, + String tagName, + String tagDescription) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException; + + + + /** + * Adds a rating to the asset. + * + * @param userId - String - userId of user making request. + * @param assetGUID - String - unique id for the asset. + * @param starRating - StarRating - enumeration for none, one to five stars. + * @param review - String - user review of asset. + * + * @return guid of new rating object. + * + * @throws InvalidParameterException - one of the parameters is null or invalid. + * @throws PropertyServerException - There is a problem adding the asset properties to + * the property server. + * @throws UserNotAuthorizedException - the requesting user is not authorized to issue this request. + */ + String addRatingToAsset(String userId, + String assetGUID, + StarRating starRating, + String review) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException; + + /** + * Adds a "Like" to the asset. + * + * @param userId - String - userId of user making request. + * @param assetGUID - String - unique id for the asset + * + * @return guid of new like object. + * + * @throws InvalidParameterException - one of the parameters is null or invalid. + * @throws PropertyServerException - There is a problem adding the asset properties to + * the property server. + * @throws UserNotAuthorizedException - the requesting user is not authorized to issue this request. + */ + String addLikeToAsset(String userId, + String assetGUID) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException; + + + /** + * Adds a comment to the asset. + * + * @param userId - String - userId of user making request. + * @param assetGUID - String - unique id for the asset. + * @param commentType - type of comment enum. + * @param commentText - String - the text of the comment. + * + * @return guid of new comment. + * + * @throws InvalidParameterException - one of the parameters is null or invalid. + * @throws PropertyServerException - There is a problem adding the asset properties to + * the property server. + * @throws UserNotAuthorizedException - the requesting user is not authorized to issue this request. + */ + String addCommentToAsset(String userId, + String assetGUID, + CommentType commentType, + String commentText) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException; + + + /** + * Adds a comment to the asset. + * + * @param userId - String - userId of user making request. + * @param commentGUID - String - unique id for an existing comment. Used to add a reply to a comment. + * @param commentType - type of comment enum. + * @param commentText - String - the text of the comment. + * + * @return guid of new comment. + * + * @throws InvalidParameterException - one of the parameters is null or invalid. + * @throws PropertyServerException - There is a problem adding the asset properties to + * the property server. + * @throws UserNotAuthorizedException - the requesting user is not authorized to issue this request. + */ + String addCommentReply(String userId, + String commentGUID, + CommentType commentType, + String commentText) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException; + + + /** + * Removes a tag from the asset that was added by this user. + * + * @param userId - String - userId of user making request. + * @param tagGUID - String - unique id for the tag. + * + * @throws InvalidParameterException - one of the parameters is null or invalid. + * @throws PropertyServerException - There is a problem updating the asset properties in + * the property server. + * @throws UserNotAuthorizedException - the requesting user is not authorized to issue this request. + */ + void removeTag(String userId, + String tagGUID) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException; + + + /** + * Removes a tag from the asset that was added by this user. + * + * @param userId - String - userId of user making request. + * @param tagGUID - String - unique id for the tag. + * + * @throws InvalidParameterException - one of the parameters is null or invalid. + * @throws PropertyServerException - There is a problem updating the asset properties in + * the property server. + * @throws UserNotAuthorizedException - the requesting user is not authorized to issue this request. + */ + void removePrivateTag(String userId, + String tagGUID) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException; + + + /** + * Removes of a star rating that was added to the asset by this user. + * + * @param userId - String - userId of user making request. + * @param ratingGUID - String - unique id for the rating object + * + * @throws InvalidParameterException - one of the parameters is null or invalid. + * @throws PropertyServerException - There is a problem updating the asset properties in + * the property server. + * @throws UserNotAuthorizedException - the requesting user is not authorized to issue this request. + */ + void removeRating(String userId, + String ratingGUID) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException; + + + /** + * Removes a "Like" added to the asset by this user. + * + * @param userId - String - userId of user making request. + * @param likeGUID - String - unique id for the like object + * + * @throws InvalidParameterException - one of the parameters is null or invalid. + * @throws PropertyServerException - There is a problem updating the asset properties in + * the property server. + * @throws UserNotAuthorizedException - the requesting user is not authorized to issue this request. + */ + void removeLike(String userId, + String likeGUID) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException; + + + /** + * Removes a comment added to the asset by this user. + * + * @param userId - String - userId of user making request. + * @param commentGUID - String - unique id for the comment object + * + * @throws InvalidParameterException - one of the parameters is null or invalid. + * @throws PropertyServerException - There is a problem updating the asset properties in + * the property server. + * @throws UserNotAuthorizedException - the user does not have permission to perform this request. + */ + void removeComment(String userId, + String commentGUID) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException; +} http://git-wip-us.apache.org/repos/asf/atlas/blob/f57fd7f0/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/admin/AssetConsumerAdmin.java ---------------------------------------------------------------------- diff --git a/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/admin/AssetConsumerAdmin.java b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/admin/AssetConsumerAdmin.java new file mode 100644 index 0000000..c3d4b75 --- /dev/null +++ b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/admin/AssetConsumerAdmin.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.apache.atlas.omas.assetconsumer.admin; + +import org.apache.atlas.omag.configuration.properties.AccessServiceConfig; +import org.apache.atlas.omag.configuration.registration.AccessServiceAdmin; +import org.apache.atlas.omag.ffdc.exception.OMAGConfigurationErrorException; +import org.apache.atlas.omas.assetconsumer.auditlog.AssetConsumerAuditCode; +import org.apache.atlas.omas.assetconsumer.listener.AssetConsumerOMRSTopicListener; +import org.apache.atlas.omas.assetconsumer.server.AssetConsumerRESTServices; +import org.apache.atlas.omrs.auditlog.OMRSAuditLog; +import org.apache.atlas.omrs.metadatacollection.repositoryconnector.OMRSRepositoryConnector; +import org.apache.atlas.omrs.topicconnectors.OMRSTopicConnector; + +public class AssetConsumerAdmin implements AccessServiceAdmin +{ + private OMRSRepositoryConnector repositoryConnector = null; + private OMRSTopicConnector omrsTopicConnector = null; + private AccessServiceConfig accessServiceConfig = null; + private OMRSAuditLog auditLog = null; + private String serverUserName = null; + + private AssetConsumerOMRSTopicListener omrsTopicListener = null; + + /** + * Default constructor + */ + public AssetConsumerAdmin() + { + } + + + /** + * Initialize the access service. + * + * @param accessServiceConfigurationProperties - specific configuration properties for this access service. + * @param enterpriseOMRSTopicConnector - connector for receiving OMRS Events from the cohorts + * @param enterpriseOMRSRepositoryConnector - connector for querying the cohort repositories + * @param auditLog - audit log component for logging messages. + * @param serverUserName - user id to use on OMRS calls where there is no end user. + * @throws OMAGConfigurationErrorException - invalid parameters in the configuration properties. + */ + public void initialize(AccessServiceConfig accessServiceConfigurationProperties, + OMRSTopicConnector enterpriseOMRSTopicConnector, + OMRSRepositoryConnector enterpriseOMRSRepositoryConnector, + OMRSAuditLog auditLog, + String serverUserName) throws OMAGConfigurationErrorException + { + final String actionDescription = "initialize"; + AssetConsumerAuditCode auditCode; + + auditCode = AssetConsumerAuditCode.SERVICE_INITIALIZING; + auditLog.logRecord(actionDescription, + auditCode.getLogMessageId(), + auditCode.getSeverity(), + auditCode.getFormattedLogMessage(), + null, + auditCode.getSystemAction(), + auditCode.getUserAction()); + + this.repositoryConnector = enterpriseOMRSRepositoryConnector; + AssetConsumerRESTServices.setRepositoryConnector(accessServiceConfigurationProperties.getAccessServiceName(), + repositoryConnector); + + this.accessServiceConfig = accessServiceConfigurationProperties; + this.omrsTopicConnector = enterpriseOMRSTopicConnector; + + if (omrsTopicConnector != null) + { + auditCode = AssetConsumerAuditCode.SERVICE_REGISTERED_WITH_TOPIC; + auditLog.logRecord(actionDescription, + auditCode.getLogMessageId(), + auditCode.getSeverity(), + auditCode.getFormattedLogMessage(), + null, + auditCode.getSystemAction(), + auditCode.getUserAction()); + + omrsTopicListener = new AssetConsumerOMRSTopicListener(accessServiceConfig.getAccessServiceOutTopic(), + repositoryConnector.getRepositoryHelper(), + repositoryConnector.getRepositoryValidator(), + accessServiceConfig.getAccessServiceName()); + + omrsTopicConnector.registerListener(omrsTopicListener); + } + + this.auditLog = auditLog; + this.serverUserName = serverUserName; + + auditCode = AssetConsumerAuditCode.SERVICE_INITIALIZED; + auditLog.logRecord(actionDescription, + auditCode.getLogMessageId(), + auditCode.getSeverity(), + auditCode.getFormattedLogMessage(), + null, + auditCode.getSystemAction(), + auditCode.getUserAction()); + } + + + /** + * Shutdown the access service. + */ + public void shutdown() + { + final String actionDescription = "shutdown"; + AssetConsumerAuditCode auditCode; + + auditCode = AssetConsumerAuditCode.SERVICE_SHUTDOWN; + auditLog.logRecord(actionDescription, + auditCode.getLogMessageId(), + auditCode.getSeverity(), + auditCode.getFormattedLogMessage(), + null, + auditCode.getSystemAction(), + auditCode.getUserAction()); + } +} http://git-wip-us.apache.org/repos/asf/atlas/blob/f57fd7f0/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/auditlog/AssetConsumerAuditCode.java ---------------------------------------------------------------------- diff --git a/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/auditlog/AssetConsumerAuditCode.java b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/auditlog/AssetConsumerAuditCode.java new file mode 100644 index 0000000..1d76880 --- /dev/null +++ b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/auditlog/AssetConsumerAuditCode.java @@ -0,0 +1,174 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.apache.atlas.omas.assetconsumer.auditlog; + +import org.apache.atlas.omrs.auditlog.OMRSAuditLogRecordSeverity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.text.MessageFormat; +import java.util.Arrays; + +/** + * The AssetConsumerAuditCode is used to define the message content for the OMRS Audit Log. + * + * The 5 fields in the enum are: + * <ul> + * <li>Log Message Id - to uniquely identify the message</li> + * <li>Severity - is this an event, decision, action, error or exception</li> + * <li>Log Message Text - includes placeholder to allow additional values to be captured</li> + * <li>Additional Information - further parameters and data relating to the audit message (optional)</li> + * <li>SystemAction - describes the result of the situation</li> + * <li>UserAction - describes how a user should correct the situation</li> + * </ul> + */ +public enum AssetConsumerAuditCode +{ + SERVICE_INITIALIZING("OMAS-ASSET-CONSUMER-0001", + OMRSAuditLogRecordSeverity.INFO, + "The Asset Consumer Open Metadata Access Service (OMAS) is initializing", + "The local server has started up the Asset Consumer OMAS.", + "No action is required. This is part of the normal operation of the server."), + + SERVICE_REGISTERED_WITH_TOPIC("OMAS-ASSET-CONSUMER-0002", + OMRSAuditLogRecordSeverity.INFO, + "The Asset Consumer Open Metadata Access Service (OMAS) is registering a listener with the OMRS Topic", + "The Asset Consumer OMAS is registering to receive events from the connected open metadata repositories.", + "No action is required. This is part of the normal operation of the server."), + + SERVICE_INITIALIZED("OMAS-ASSET-CONSUMER-0003", + OMRSAuditLogRecordSeverity.INFO, + "The Asset Consumer Open Metadata Access Service (OMAS) is initialized", + "The Asset Consumer OMAS has completed initialization.", + "No action is required. This is part of the normal operation of the server."), + + SERVICE_SHUTDOWN("OMAS-ASSET-CONSUMER-0004", + OMRSAuditLogRecordSeverity.INFO, + "The Asset Consumer Open Metadata Access Service (OMAS) is shutting down", + "The local server has requested shut down of the Asset Consumer OMAS.", + "No action is required. This is part of the normal operation of the server."), + + + ; + + private String logMessageId; + private OMRSAuditLogRecordSeverity severity; + private String logMessage; + private String systemAction; + private String userAction; + + private static final Logger log = LoggerFactory.getLogger(AssetConsumerAuditCode.class); + + + /** + * The constructor for OMRSAuditCode expects to be passed one of the enumeration rows defined in + * OMRSAuditCode above. For example: + * + * OMRSAuditCode auditCode = OMRSAuditCode.SERVER_NOT_AVAILABLE; + * + * This will expand out to the 4 parameters shown below. + * + * @param messageId - unique Id for the message + * @param severity - severity of the message + * @param message - text for the message + * @param systemAction - description of the action taken by the system when the condition happened + * @param userAction - instructions for resolving the situation, if any + */ + AssetConsumerAuditCode(String messageId, + OMRSAuditLogRecordSeverity severity, + String message, + String systemAction, + String userAction) + { + this.logMessageId = messageId; + this.severity = severity; + this.logMessage = message; + this.systemAction = systemAction; + this.userAction = userAction; + } + + + /** + * Returns the unique identifier for the error message. + * + * @return logMessageId + */ + public String getLogMessageId() + { + return logMessageId; + } + + + /** + * Return the severity of the audit log record. + * + * @return OMRSAuditLogRecordSeverity enum + */ + public OMRSAuditLogRecordSeverity getSeverity() + { + return severity; + } + + /** + * Returns the log message with the placeholders filled out with the supplied parameters. + * + * @param params - strings that plug into the placeholders in the logMessage + * @return logMessage (formatted with supplied parameters) + */ + public String getFormattedLogMessage(String... params) + { + if (log.isDebugEnabled()) + { + log.debug(String.format("<== OMRS Audit Code.getMessage(%s)", Arrays.toString(params))); + } + + MessageFormat mf = new MessageFormat(logMessage); + String result = mf.format(params); + + if (log.isDebugEnabled()) + { + log.debug(String.format("==> OMRS Audit Code.getMessage(%s): %s", Arrays.toString(params), result)); + } + + return result; + } + + + + /** + * Returns a description of the action taken by the system when the condition that caused this exception was + * detected. + * + * @return systemAction String + */ + public String getSystemAction() + { + return systemAction; + } + + + /** + * Returns instructions of how to resolve the issue reported in this exception. + * + * @return userAction String + */ + public String getUserAction() + { + return userAction; + } +}
