http://git-wip-us.apache.org/repos/asf/atlas/blob/f57fd7f0/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/ErrorHandler.java ---------------------------------------------------------------------- diff --git a/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/ErrorHandler.java b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/ErrorHandler.java new file mode 100644 index 0000000..cfde2cc --- /dev/null +++ b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/ErrorHandler.java @@ -0,0 +1,333 @@ +/* + * 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.server; + +import org.apache.atlas.omas.assetconsumer.ffdc.AssetConsumerErrorCode; +import org.apache.atlas.omas.assetconsumer.ffdc.exceptions.InvalidParameterException; +import org.apache.atlas.omas.assetconsumer.ffdc.exceptions.PropertyServerException; +import org.apache.atlas.omas.assetconsumer.ffdc.exceptions.UserNotAuthorizedException; +import org.apache.atlas.omrs.metadatacollection.OMRSMetadataCollection; +import org.apache.atlas.omrs.metadatacollection.repositoryconnector.OMRSRepositoryConnector; + +/** + * ErrorHandler provides common validation routines for the other handler classes + */ +public class ErrorHandler +{ + private OMRSRepositoryConnector repositoryConnector; + + + /** + * Typical constructor providing access to the repository connector for this access service. + * + * @param repositoryConnector - connector object + */ + public ErrorHandler(OMRSRepositoryConnector repositoryConnector) + { + this.repositoryConnector = repositoryConnector; + } + + + /** + * Throw an exception if the supplied userId is null + * + * @param userId - user name to validate + * @param methodName - name of the method making the call. + * @throws InvalidParameterException - the userId is null + */ + public void validateUserId(String userId, + String methodName) throws InvalidParameterException + { + if (userId == null) + { + AssetConsumerErrorCode errorCode = AssetConsumerErrorCode.NULL_USER_ID; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(methodName); + + throw new InvalidParameterException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + } + + + /** + * Throw an exception if the supplied unique identifier is null + * + * @param guid - unique identifier to validate + * @param parameterName - name of the parameter that passed the guid. + * @param methodName - name of the method making the call. + * @throws InvalidParameterException - the guid is null + */ + public void validateGUID(String guid, + String parameterName, + String methodName) throws InvalidParameterException + { + if (guid == null) + { + AssetConsumerErrorCode errorCode = AssetConsumerErrorCode.NULL_GUID; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(parameterName, methodName); + + throw new InvalidParameterException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + } + + + /** + * Throw an exception if the supplied enum is null + * + * @param enumValue - enum value to validate + * @param parameterName - name of the parameter that passed the enum. + * @param methodName - name of the method making the call. + * @throws InvalidParameterException - the enum is null + */ + public void validateEnum(Object enumValue, + String parameterName, + String methodName) throws InvalidParameterException + { + if (enumValue == null) + { + AssetConsumerErrorCode errorCode = AssetConsumerErrorCode.NULL_ENUM; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(parameterName, methodName); + + throw new InvalidParameterException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + } + + + /** + * Throw an exception if the supplied name is null + * + * @param name - unique name to validate + * @param parameterName - name of the parameter that passed the name. + * @param methodName - name of the method making the call. + * @throws InvalidParameterException - the guid is null + */ + public void validateName(String name, + String parameterName, + String methodName) throws InvalidParameterException + { + if (name == null) + { + AssetConsumerErrorCode errorCode = AssetConsumerErrorCode.NULL_NAME; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(parameterName, methodName); + + throw new InvalidParameterException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + } + + + /** + * Throw an exception if the supplied text field is null + * + * @param text - unique name to validate + * @param parameterName - name of the parameter that passed the name. + * @param methodName - name of the method making the call. + * @throws InvalidParameterException - the guid is null + */ + public void validateText(String text, + String parameterName, + String methodName) throws InvalidParameterException + { + if (text == null) + { + AssetConsumerErrorCode errorCode = AssetConsumerErrorCode.NULL_TEXT; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(parameterName, methodName); + + throw new InvalidParameterException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + } + + + /** + * Check that there is a repository connector. + * + * @param methodName - name of the method being called + * @return metadata collection that provides access to the properties in the property server + * @throws PropertyServerException - exception thrown if the repository connector + */ + public OMRSMetadataCollection validateRepositoryConnector(String methodName) throws PropertyServerException + { + if (this.repositoryConnector == null) + { + AssetConsumerErrorCode errorCode = AssetConsumerErrorCode.OMRS_NOT_INITIALIZED; + String errorMessage = errorCode.getErrorMessageId() + errorCode.getFormattedErrorMessage(methodName); + + throw new PropertyServerException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + + } + + if (! this.repositoryConnector.isActive()) + { + AssetConsumerErrorCode errorCode = AssetConsumerErrorCode.OMRS_NOT_AVAILABLE; + String errorMessage = errorCode.getErrorMessageId() + errorCode.getFormattedErrorMessage(methodName); + + throw new PropertyServerException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + try + { + return repositoryConnector.getMetadataCollection(); + } + catch (Throwable error) + { + AssetConsumerErrorCode errorCode = AssetConsumerErrorCode.NO_METADATA_COLLECTION; + String errorMessage = errorCode.getErrorMessageId() + errorCode.getFormattedErrorMessage(methodName); + + throw new PropertyServerException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + } + + + /** + * Throw an exception if the supplied userId is not authorized to perform a request + * + * @param userId - user name to validate + * @param methodName - name of the method making the call. + * @param serverName - name of this server + * @param serviceName - name of this access service + * @throws UserNotAuthorizedException - the userId is unauthorised for the request + */ + public void handleUnauthorizedUser(String userId, + String methodName, + String serverName, + String serviceName) throws UserNotAuthorizedException + { + AssetConsumerErrorCode errorCode = AssetConsumerErrorCode.USER_NOT_AUTHORIZED; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(userId, + methodName, + serviceName, + serverName); + + throw new UserNotAuthorizedException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + + } + + + /** + * Throw an exception if the supplied userId is not authorized to perform a request + * + * @param error - caught exception + * @param methodName - name of the method making the call. + * @param serverName - name of this server + * @param serviceName - name of this access service + * @throws PropertyServerException - unexpected exception from property server + */ + public void handleRepositoryError(Throwable error, + String methodName, + String serverName, + String serviceName) throws PropertyServerException + { + AssetConsumerErrorCode errorCode = AssetConsumerErrorCode.PROPERTY_SERVER_ERROR; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(error.getMessage(), + methodName, + serviceName, + serverName); + + throw new PropertyServerException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + + } + + + /** + * Throw an exception if the supplied userId is not authorized to perform a request + * + * @param error - caught exception + * @param assetGUID - unique identifier for the requested asset + * @param methodName - name of the method making the call + * @param serverName - name of this server + * @param serviceName - name of this access service + * @throws InvalidParameterException - unexpected exception from property server + */ + public void handleUnknownAsset(Throwable error, + String assetGUID, + String methodName, + String serverName, + String serviceName) throws InvalidParameterException + { + AssetConsumerErrorCode errorCode = AssetConsumerErrorCode.UNKNOWN_ASSET; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(assetGUID, + methodName, + serviceName, + serverName, + error.getMessage()); + + throw new InvalidParameterException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + + } +}
http://git-wip-us.apache.org/repos/asf/atlas/blob/f57fd7f0/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/FeedbackHandler.java ---------------------------------------------------------------------- diff --git a/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/FeedbackHandler.java b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/FeedbackHandler.java new file mode 100644 index 0000000..bd2e448 --- /dev/null +++ b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/FeedbackHandler.java @@ -0,0 +1,1013 @@ +/* + * 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.server; + +import org.apache.atlas.ocf.properties.CommentType; +import org.apache.atlas.ocf.properties.StarRating; +import org.apache.atlas.omas.assetconsumer.ffdc.exceptions.InvalidParameterException; +import org.apache.atlas.omas.assetconsumer.ffdc.exceptions.PropertyServerException; +import org.apache.atlas.omas.assetconsumer.ffdc.exceptions.UserNotAuthorizedException; +import org.apache.atlas.omrs.localrepository.repositorycontentmanager.OMRSRepositoryHelper; +import org.apache.atlas.omrs.metadatacollection.OMRSMetadataCollection; +import org.apache.atlas.omrs.metadatacollection.properties.instances.*; +import org.apache.atlas.omrs.metadatacollection.repositoryconnector.OMRSRepositoryConnector; + +import java.util.Date; + +/** + * FeedbackHandler manages the creation of asset feedback (likes, ratings, comments and tags) in the + * property server. + */ +public class FeedbackHandler +{ + private static final String informalTagTypeName = "InformalTag"; + private static final String informalTagTypeGUID = "ba846a7b-2955-40bf-952b-2793ceca090a"; + private static final String privateTagTypeName = "PrivateTag"; + private static final String privateTagTypeGUID = "9b3f5443-2475-4522-bfda-8f1f17e9a6c3"; + private static final String tagNamePropertyName = "TagName"; + private static final String tagDescriptionPropertyName = "TagDescription"; + private static final String attachedTagTypeGUID = "4b1641c4-3d1a-4213-86b2-d6968b6c65ab"; + + private static final String likeTypeName = "Like"; + private static final String likeTypeGUID = "deaa5ca0-47a0-483d-b943-d91c76744e01"; + private static final String attachedLikeTypeGUID = "e2509715-a606-415d-a995-61d00503dad4"; + + private static final String ratingTypeName = "Rating"; + private static final String ratingTypeGUID = "7299d721-d17f-4562-8286-bcd451814478"; + private static final String starsPropertyName = "stars"; + private static final String reviewPropertyName = "review"; + private static final String attachedRatingTypeGUID = "0aaad9e9-9cc5-4ad8-bc2e-c1099bab6344"; + + private static final String commentTypeName = "Comment"; + private static final String commentTypeGUID = "1a226073-9c84-40e4-a422-fbddb9b84278"; + private static final String qualifiedNamePropertyName = "qualifiedName"; + private static final String commentPropertyName = "comment"; + private static final String commentTypePropertyName = "commentType"; + private static final String attachedCommentTypeGUID = "0d90501b-bf29-4621-a207-0c8c953bdac9"; + + + + + private String serviceName; + + private String serverName = null; + private OMRSRepositoryHelper repositoryHelper = null; + private ErrorHandler errorHandler = null; + + + /** + * Construct the feedback handler with a link to the property server's connector and this access service's + * official name. + * + * @param serviceName - name of this service + * @param repositoryConnector - connector to the property server. + */ + public FeedbackHandler(String serviceName, + OMRSRepositoryConnector repositoryConnector) + { + this.serviceName = serviceName; + + if (repositoryConnector != null) + { + this.repositoryHelper = repositoryConnector.getRepositoryHelper(); + this.serverName = repositoryConnector.getServerName(); + errorHandler = new ErrorHandler(repositoryConnector); + } + } + + + /** + * 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. + */ + public String addTagToAsset(String userId, + String assetGUID, + String tagName, + String tagDescription) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException + { + final String methodName = "addTagToAsset"; + + return this.addTagToAsset(informalTagTypeGUID, + userId, + assetGUID, + tagName, + tagDescription, + methodName); + } + + + /** + * 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. + */ + public String addPrivateTagToAsset(String userId, + String assetGUID, + String tagName, + String tagDescription) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException + { + final String methodName = "addPrivateTagToAsset"; + + return this.addTagToAsset(privateTagTypeGUID, + userId, + assetGUID, + tagName, + tagDescription, + methodName); + } + + + /** + * 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. + */ + private String addTagToAsset(String tagTypeGUID, + String userId, + String assetGUID, + String tagName, + String tagDescription, + String methodName) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException + { + final String guidParameter = "assetGUID"; + final String nameParameter = "tagName"; + + errorHandler.validateUserId(userId, methodName); + errorHandler.validateGUID(assetGUID, guidParameter, methodName); + errorHandler.validateName(tagName, nameParameter, methodName); + + OMRSMetadataCollection metadataCollection = errorHandler.validateRepositoryConnector(methodName); + + this.validateEntity(userId, assetGUID, metadataCollection, methodName); + + try + { + /* + * Create the Tag Entity + */ + InstanceProperties properties; + + properties = repositoryHelper.addStringPropertyToInstance(serviceName, + null, + tagNamePropertyName, + tagName, + methodName); + properties = repositoryHelper.addStringPropertyToInstance(serviceName, + properties, + tagDescriptionPropertyName, + tagDescription, + methodName); + EntityDetail feedbackEntity = metadataCollection.addEntity(userId, + tagTypeGUID, + properties, + null, + InstanceStatus.ACTIVE); + + /* + * Link the tag to the asset + */ + metadataCollection.addRelationship(userId, + attachedTagTypeGUID, + null, + assetGUID, + feedbackEntity.getGUID(), + InstanceStatus.ACTIVE); + + /* + * Return the guid of the feedback entity + */ + if (feedbackEntity != null) + { + return feedbackEntity.getGUID(); + } + } + catch (org.apache.atlas.omrs.ffdc.exception.UserNotAuthorizedException error) + { + errorHandler.handleUnauthorizedUser(userId, + methodName, + serverName, + serviceName); + } + catch (Throwable error) + { + errorHandler.handleRepositoryError(error, + methodName, + serverName, + serviceName); + } + + return null; + } + + /** + * 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. + */ + public String addRatingToAsset(String userId, + String assetGUID, + StarRating starRating, + String review) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException + { + final String methodName = "addRatingToAsset"; + final String guidParameter = "assetGUID"; + final String ratingParameter = "starRating"; + + errorHandler.validateUserId(userId, methodName); + errorHandler.validateGUID(assetGUID, guidParameter, methodName); + errorHandler.validateEnum(starRating, ratingParameter, methodName); + + OMRSMetadataCollection metadataCollection = errorHandler.validateRepositoryConnector(methodName); + + this.validateEntity(userId, assetGUID, metadataCollection, methodName); + + try + { + /* + * Create the Rating Entity + */ + InstanceProperties properties = null; + + properties = this.addStarRatingPropertyToInstance(properties, + starRating, + methodName); + properties = repositoryHelper.addStringPropertyToInstance(serviceName, + properties, + reviewPropertyName, + review, + methodName); + EntityDetail feedbackEntity = metadataCollection.addEntity(userId, + ratingTypeGUID, + properties, + null, + InstanceStatus.ACTIVE); + + /* + * Link the Rating to the asset + */ + metadataCollection.addRelationship(userId, + attachedRatingTypeGUID, + null, + assetGUID, + feedbackEntity.getGUID(), + InstanceStatus.ACTIVE); + + /* + * Return the guid of the feedback entity + */ + if (feedbackEntity != null) + { + return feedbackEntity.getGUID(); + } + } + catch (org.apache.atlas.omrs.ffdc.exception.UserNotAuthorizedException error) + { + errorHandler.handleUnauthorizedUser(userId, + methodName, + serverName, + serviceName); + } + catch (Throwable error) + { + errorHandler.handleRepositoryError(error, + methodName, + serverName, + serviceName); + } + + return null; + } + + + /** + * Set up a property value for the StartRating enum property. + * + * @param properties - current properties + * @param starRating - enum value + * @param methodName - calling method + * @return - InstanceProperties object with the enum value added + */ + private InstanceProperties addStarRatingPropertyToInstance(InstanceProperties properties, + StarRating starRating, + String methodName) + { + int ordinal = 99; + String symbolicName = null; + String description = null; + + final int element1Ordinal = 0; + final String element1Value = "NotRecommended"; + final String element1Description = "This content is not recommended."; + + final int element2Ordinal = 1; + final String element2Value = "OneStar"; + final String element2Description = "One star rating."; + + final int element3Ordinal = 2; + final String element3Value = "TwoStar"; + final String element3Description = "Two star rating."; + + final int element4Ordinal = 3; + final String element4Value = "ThreeStar"; + final String element4Description = "Three star rating."; + + final int element5Ordinal = 4; + final String element5Value = "FourStar"; + final String element5Description = "Four star rating."; + + final int element6Ordinal = 5; + final String element6Value = "FiveStar"; + final String element6Description = "Five star rating."; + + switch (starRating) + { + case NOT_RECOMMENDED: + ordinal = element1Ordinal; + symbolicName = element1Value; + description = element1Description; + break; + + case ONE_STAR: + ordinal = element2Ordinal; + symbolicName = element2Value; + description = element2Description; + break; + + case TWO_STARS: + ordinal = element3Ordinal; + symbolicName = element3Value; + description = element3Description; + break; + + case THREE_STARS: + ordinal = element4Ordinal; + symbolicName = element4Value; + description = element4Description; + break; + + case FOUR_STARS: + ordinal = element5Ordinal; + symbolicName = element5Value; + description = element5Description; + break; + + case FIVE_STARS: + ordinal = element6Ordinal; + symbolicName = element6Value; + description = element6Description; + break; + } + + return repositoryHelper.addEnumPropertyToInstance(serviceName, + properties, + starsPropertyName, + ordinal, + symbolicName, + description, + methodName); + } + + + /** + * 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. + */ + public String addLikeToAsset(String userId, + String assetGUID) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException + { + final String methodName = "addLikeToAsset"; + final String guidParameter = "assetGUID"; + + errorHandler.validateUserId(userId, methodName); + errorHandler.validateGUID(assetGUID, guidParameter, methodName); + + OMRSMetadataCollection metadataCollection = errorHandler.validateRepositoryConnector(methodName); + + this.validateEntity(userId, assetGUID, metadataCollection, methodName); + + try + { + /* + * Create the Like Entity + */ + EntityDetail feedbackEntity = metadataCollection.addEntity(userId, + likeTypeGUID, + null, + null, + InstanceStatus.ACTIVE); + + /* + * Link the Like to the asset + */ + metadataCollection.addRelationship(userId, + attachedLikeTypeGUID, + null, + assetGUID, + feedbackEntity.getGUID(), + InstanceStatus.ACTIVE); + + /* + * Return the guid of the feedback entity + */ + if (feedbackEntity != null) + { + return feedbackEntity.getGUID(); + } + } + catch (org.apache.atlas.omrs.ffdc.exception.UserNotAuthorizedException error) + { + errorHandler.handleUnauthorizedUser(userId, + methodName, + serverName, + serviceName); + } + catch (Throwable error) + { + errorHandler.handleRepositoryError(error, + methodName, + serverName, + serviceName); + } + + return null; + } + + + /** + * 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. + */ + public String addCommentToAsset(String userId, + String assetGUID, + CommentType commentType, + String commentText) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException + { + final String methodName = "addCommentToAsset"; + final String guidParameter = "assetGUID"; + + return this.addCommentToEntity(userId, assetGUID, guidParameter, commentType, commentText, methodName); + } + + /** + * 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. + */ + public String addCommentReply(String userId, + String commentGUID, + CommentType commentType, + String commentText) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException + { + final String methodName = "addCommentReply"; + final String guidParameter = "assetGUID"; + + + return this.addCommentToEntity(userId, commentGUID, guidParameter, commentType, commentText, methodName); + } + + + /** + * Set up a property value for the CommentType enum property. + * + * @param properties - current properties + * @param commentType - enum value + * @param methodName - calling method + * @return - InstanceProperties object with the enum value added + */ + private InstanceProperties addCommentTypePropertyToInstance(InstanceProperties properties, + CommentType commentType, + String methodName) + { + int ordinal = 99; + String symbolicName = null; + String description = null; + + final int element1Ordinal = 0; + final String element1Value = "GeneralComment"; + final String element1Description = "General comment."; + + final int element2Ordinal = 1; + final String element2Value = "Question"; + final String element2Description = "A question."; + + final int element3Ordinal = 2; + final String element3Value = "Answer"; + final String element3Description = "An answer to a previously asked question."; + + final int element4Ordinal = 3; + final String element4Value = "Suggestion"; + final String element4Description = "A suggestion for improvement."; + + final int element5Ordinal = 3; + final String element5Value = "Experience"; + final String element5Description = "An account of an experience."; + + switch (commentType) + { + case STANDARD_COMMENT: + ordinal = element1Ordinal; + symbolicName = element1Value; + description = element1Description; + break; + + case QUESTION: + ordinal = element2Ordinal; + symbolicName = element2Value; + description = element2Description; + break; + + case ANSWER: + ordinal = element3Ordinal; + symbolicName = element3Value; + description = element3Description; + break; + + case SUGGESTION: + ordinal = element4Ordinal; + symbolicName = element4Value; + description = element4Description; + break; + + case USAGE_EXPERIENCE: + ordinal = element5Ordinal; + symbolicName = element5Value; + description = element5Description; + break; + } + + return repositoryHelper.addEnumPropertyToInstance(serviceName, + properties, + commentTypePropertyName, + ordinal, + symbolicName, + description, + methodName); + } + + + /** + * Adds a comment and links it to the supplied entity. + * + * @param userId - String - userId of user making request. + * @param entityGUID - String - unique id for an existing comment. Used to add a reply to a comment. + * @param guidParameter - name of parameter that supplied the entity'ss unique identifier. + * @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. + */ + private String addCommentToEntity(String userId, + String entityGUID, + String guidParameter, + CommentType commentType, + String commentText, + String methodName) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException + { + final String typeParameter = "commentType"; + final String textParameter = "commentText"; + + errorHandler.validateUserId(userId, methodName); + errorHandler.validateGUID(entityGUID, guidParameter, methodName); + errorHandler.validateEnum(commentType, typeParameter, methodName); + errorHandler.validateText(commentText, textParameter, methodName); + + OMRSMetadataCollection metadataCollection = errorHandler.validateRepositoryConnector(methodName); + + this.validateEntity(userId, entityGUID, metadataCollection, methodName); + + try + { + /* + * Create the Comment Entity + */ + InstanceProperties properties = null; + + properties = this.addCommentTypePropertyToInstance(properties, + commentType, + methodName); + properties = repositoryHelper.addStringPropertyToInstance(serviceName, + properties, + qualifiedNamePropertyName, + "Comment:" + userId + ":" + new Date().toString(), + methodName); + properties = repositoryHelper.addStringPropertyToInstance(serviceName, + properties, + commentPropertyName, + commentText, + methodName); + EntityDetail feedbackEntity = metadataCollection.addEntity(userId, + commentTypeGUID, + properties, + null, + InstanceStatus.ACTIVE); + + /* + * Link the comment reply to the supplied entity + */ + metadataCollection.addRelationship(userId, + attachedCommentTypeGUID, + null, + entityGUID, + feedbackEntity.getGUID(), + InstanceStatus.ACTIVE); + + /* + * Return the guid of the feedback entity + */ + if (feedbackEntity != null) + { + return feedbackEntity.getGUID(); + } + } + catch (org.apache.atlas.omrs.ffdc.exception.UserNotAuthorizedException error) + { + errorHandler.handleUnauthorizedUser(userId, + methodName, + serverName, + serviceName); + } + catch (Throwable error) + { + errorHandler.handleRepositoryError(error, + methodName, + serverName, + serviceName); + } + + return null; + } + + + /** + * 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. + */ + public void removeTagFromAsset(String userId, + String tagGUID) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException + { + final String methodName = "removeTagFromAsset"; + final String guidParameter = "tagGUID"; + + errorHandler.validateUserId(userId, methodName); + errorHandler.validateGUID(tagGUID, guidParameter, methodName); + + OMRSMetadataCollection metadataCollection = errorHandler.validateRepositoryConnector(methodName); + + try + { + metadataCollection.deleteEntity(userId, informalTagTypeGUID, informalTagTypeName, tagGUID); + } + catch (org.apache.atlas.omrs.ffdc.exception.UserNotAuthorizedException error) + { + errorHandler.handleUnauthorizedUser(userId, + methodName, + serverName, + serviceName); } + catch (Throwable error) + { + errorHandler.handleRepositoryError(error, + methodName, + serverName, + serviceName); + } + } + + + /** + * 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. + */ + public void removePrivateTagFromAsset(String userId, + String tagGUID) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException + { + final String methodName = "removePrivateTagFromAsset"; + final String guidParameter = "tagGUID"; + + errorHandler.validateUserId(userId, methodName); + errorHandler.validateGUID(tagGUID, guidParameter, methodName); + + OMRSMetadataCollection metadataCollection = errorHandler.validateRepositoryConnector(methodName); + + try + { + metadataCollection.deleteEntity(userId, privateTagTypeGUID, privateTagTypeName, tagGUID); + } + catch (org.apache.atlas.omrs.ffdc.exception.UserNotAuthorizedException error) + { + errorHandler.handleUnauthorizedUser(userId, + methodName, + serverName, + serviceName); } + catch (Throwable error) + { + errorHandler.handleRepositoryError(error, + methodName, + serverName, + serviceName); + } + } + + + /** + * 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. + */ + public void removeRatingFromAsset(String userId, + String ratingGUID) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException + { + final String methodName = "removeRatingFromAsset"; + final String guidParameter = "ratingGUID"; + + errorHandler.validateUserId(userId, methodName); + errorHandler.validateGUID(ratingGUID, guidParameter, methodName); + + OMRSMetadataCollection metadataCollection = errorHandler.validateRepositoryConnector(methodName); + + try + { + metadataCollection.deleteEntity(userId, ratingTypeGUID, ratingTypeName, ratingGUID); + } + catch (org.apache.atlas.omrs.ffdc.exception.UserNotAuthorizedException error) + { + errorHandler.handleUnauthorizedUser(userId, + methodName, + serverName, + serviceName); } + catch (Throwable error) + { + errorHandler.handleRepositoryError(error, + methodName, + serverName, + serviceName); + } + } + + + /** + * 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. + */ + public void removeLikeFromAsset(String userId, + String likeGUID) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException + { + final String methodName = "removeLikeFromAsset"; + final String guidParameter = "likeGUID"; + + errorHandler.validateUserId(userId, methodName); + errorHandler.validateGUID(likeGUID, guidParameter, methodName); + + OMRSMetadataCollection metadataCollection = errorHandler.validateRepositoryConnector(methodName); + + try + { + metadataCollection.deleteEntity(userId, likeTypeGUID, likeTypeName, likeGUID); + } + catch (org.apache.atlas.omrs.ffdc.exception.UserNotAuthorizedException error) + { + errorHandler.handleUnauthorizedUser(userId, + methodName, + serverName, + serviceName); } + catch (Throwable error) + { + errorHandler.handleRepositoryError(error, + methodName, + serverName, + serviceName); + } + } + + + /** + * 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. + */ + public void removeCommentFromAsset(String userId, + String commentGUID) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException + { + final String methodName = "removeCommentFromAsset"; + final String guidParameter = "commentGUID"; + + errorHandler.validateUserId(userId, methodName); + errorHandler.validateGUID(commentGUID, guidParameter, methodName); + + OMRSMetadataCollection metadataCollection = errorHandler.validateRepositoryConnector(methodName); + + try + { + metadataCollection.deleteEntity(userId, commentTypeGUID, commentTypeName, commentGUID); + } + catch (org.apache.atlas.omrs.ffdc.exception.UserNotAuthorizedException error) + { + errorHandler.handleUnauthorizedUser(userId, + methodName, + serverName, + serviceName); } + catch (Throwable error) + { + errorHandler.handleRepositoryError(error, + methodName, + serverName, + serviceName); + } + } + + + /** + * Validate that the supplied GUID is for a real entity. + * + * @param userId - user making the request. + * @param assetGUID - unique identifier of the asset. + * @param metadataCollection - repository's metadata collection + * @param methodName - name of method called. + * @throws InvalidParameterException - entity not known + * @throws PropertyServerException - problem accessing property server + * @throws UserNotAuthorizedException - security access problem + */ + private void validateEntity(String userId, + String assetGUID, + OMRSMetadataCollection metadataCollection, + String methodName) throws InvalidParameterException, + PropertyServerException, + UserNotAuthorizedException + { + try + { + metadataCollection.getEntitySummary(userId, assetGUID); + } + catch (org.apache.atlas.omrs.ffdc.exception.EntityNotKnownException error) + { + errorHandler.handleUnknownAsset(error, + assetGUID, + methodName, + serverName, + serviceName); + } + catch (org.apache.atlas.omrs.ffdc.exception.UserNotAuthorizedException error) + { + errorHandler.handleUnauthorizedUser(userId, + methodName, + serverName, + serviceName); + } + catch (Throwable error) + { + errorHandler.handleRepositoryError(error, + methodName, + serverName, + serviceName); + } + } +} http://git-wip-us.apache.org/repos/asf/atlas/blob/f57fd7f0/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/properties/AssetConsumerOMASAPIResponse.java ---------------------------------------------------------------------- diff --git a/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/properties/AssetConsumerOMASAPIResponse.java b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/properties/AssetConsumerOMASAPIResponse.java new file mode 100644 index 0000000..011963a --- /dev/null +++ b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/properties/AssetConsumerOMASAPIResponse.java @@ -0,0 +1,172 @@ +/* + * 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.server.properties; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +/** + * AssetConsumerOMASAPIResponse provides a common header for Asset Consumer OMAS managed responses to its REST API. + * It manages information about exceptions. If no exception has been raised exceptionClassName is null. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +public abstract class AssetConsumerOMASAPIResponse +{ + protected int relatedHTTPCode = 200; + protected String exceptionClassName = null; + protected String exceptionErrorMessage = null; + protected String exceptionSystemAction = null; + protected String exceptionUserAction = null; + + + /** + * Default constructor + */ + public AssetConsumerOMASAPIResponse() + { + } + + + /** + * Return the HTTP Code to use if forwarding response to HTTP client. + * + * @return integer HTTP status code + */ + public int getRelatedHTTPCode() + { + return relatedHTTPCode; + } + + + /** + * Set up the HTTP Code to use if forwarding response to HTTP client. + * + * @param relatedHTTPCode - integer HTTP status code + */ + public void setRelatedHTTPCode(int relatedHTTPCode) + { + this.relatedHTTPCode = relatedHTTPCode; + } + + + /** + * Return the name of the Java class name to use to recreate the exception. + * + * @return String name of the fully-qualified java class name + */ + public String getExceptionClassName() + { + return exceptionClassName; + } + + + /** + * Set up the name of the Java class name to use to recreate the exception. + * + * @param exceptionClassName - String name of the fully-qualified java class name + */ + public void setExceptionClassName(String exceptionClassName) + { + this.exceptionClassName = exceptionClassName; + } + + + /** + * Return the error message associated with the exception. + * + * @return string error message + */ + public String getExceptionErrorMessage() + { + return exceptionErrorMessage; + } + + + /** + * Set up the error message associated with the exception. + * + * @param exceptionErrorMessage - string error message + */ + public void setExceptionErrorMessage(String exceptionErrorMessage) + { + this.exceptionErrorMessage = exceptionErrorMessage; + } + + + /** + * Return the description of the action taken by the system as a result of the exception. + * + * @return - string description of the action taken + */ + public String getExceptionSystemAction() + { + return exceptionSystemAction; + } + + + /** + * Set up the description of the action taken by the system as a result of the exception. + * + * @param exceptionSystemAction - string description of the action taken + */ + public void setExceptionSystemAction(String exceptionSystemAction) + { + this.exceptionSystemAction = exceptionSystemAction; + } + + + /** + * Return the action that a user should take to resolve the problem. + * + * @return string instructions + */ + public String getExceptionUserAction() + { + return exceptionUserAction; + } + + + /** + * Set up the action that a user should take to resolve the problem. + * + * @param exceptionUserAction - string instructions + */ + public void setExceptionUserAction(String exceptionUserAction) + { + this.exceptionUserAction = exceptionUserAction; + } + + + @Override + public String toString() + { + return "AssetConsumerOMASAPIResponse{" + + "relatedHTTPCode=" + relatedHTTPCode + + ", exceptionClassName='" + exceptionClassName + '\'' + + ", exceptionErrorMessage='" + exceptionErrorMessage + '\'' + + ", exceptionSystemAction='" + exceptionSystemAction + '\'' + + ", exceptionUserAction='" + exceptionUserAction + '\'' + + '}'; + } +} http://git-wip-us.apache.org/repos/asf/atlas/blob/f57fd7f0/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/properties/ConnectionResponse.java ---------------------------------------------------------------------- diff --git a/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/properties/ConnectionResponse.java b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/properties/ConnectionResponse.java new file mode 100644 index 0000000..4ac72d2 --- /dev/null +++ b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/properties/ConnectionResponse.java @@ -0,0 +1,81 @@ +/* + * 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.server.properties; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import org.apache.atlas.ocf.properties.beans.Connection; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + + +/** + * ConnectionResponse is the response structure used on the Asset Consumer OMAS REST API calls that returns a + * Connection object as a response. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +public class ConnectionResponse extends AssetConsumerOMASAPIResponse +{ + private Connection connection = null; + + /** + * Default constructor + */ + public ConnectionResponse() + { + } + + + /** + * Return the Connection object. + * + * @return connection + */ + public Connection getConnection() + { + return connection; + } + + /** + * Set up the Connection object. + * + * @param connection - connection object + */ + public void setConnection(Connection connection) + { + this.connection = connection; + } + + + @Override + public String toString() + { + return "ConnectionResponse{" + + "connection=" + connection + + ", relatedHTTPCode=" + relatedHTTPCode + + ", exceptionClassName='" + exceptionClassName + '\'' + + ", exceptionErrorMessage='" + exceptionErrorMessage + '\'' + + ", exceptionSystemAction='" + exceptionSystemAction + '\'' + + ", exceptionUserAction='" + exceptionUserAction + '\'' + + '}'; + } +} http://git-wip-us.apache.org/repos/asf/atlas/blob/f57fd7f0/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/properties/GUIDResponse.java ---------------------------------------------------------------------- diff --git a/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/properties/GUIDResponse.java b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/properties/GUIDResponse.java new file mode 100644 index 0000000..506878f --- /dev/null +++ b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/properties/GUIDResponse.java @@ -0,0 +1,81 @@ +/* + * 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.server.properties; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + + +/** + * GUIDResponse is the response structure used on the Asset Consumer OMAS REST API calls that return a + * unique identifier (guid) object as a response. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +public class GUIDResponse extends AssetConsumerOMASAPIResponse +{ + private String guid = null; + + + /** + * Default constructor + */ + public GUIDResponse() + { + } + + + /** + * Return the guid result. + * + * @return unique identifier + */ + public String getGUID() + { + return guid; + } + + /** + * Set up the guid result. + * + * @param guid - unique identifier + */ + public void setGUID(String guid) + { + this.guid = guid; + } + + + @Override + public String toString() + { + return "GUIDResponse{" + + "guid='" + guid + '\'' + + ", relatedHTTPCode=" + relatedHTTPCode + + ", exceptionClassName='" + exceptionClassName + '\'' + + ", exceptionErrorMessage='" + exceptionErrorMessage + '\'' + + ", exceptionSystemAction='" + exceptionSystemAction + '\'' + + ", exceptionUserAction='" + exceptionUserAction + '\'' + + '}'; + } +} http://git-wip-us.apache.org/repos/asf/atlas/blob/f57fd7f0/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/properties/VoidResponse.java ---------------------------------------------------------------------- diff --git a/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/properties/VoidResponse.java b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/properties/VoidResponse.java new file mode 100644 index 0000000..66a4592 --- /dev/null +++ b/omas-assetconsumer/src/main/java/org/apache/atlas/omas/assetconsumer/server/properties/VoidResponse.java @@ -0,0 +1,54 @@ +/* + * 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.server.properties; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +/** + * VoidResponse defines the response structure for the Asset Consumer OMAS REST API calls that returns a + * void as a response. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +public class VoidResponse extends AssetConsumerOMASAPIResponse +{ + /** + * Default constructor + */ + public VoidResponse() + { + } + + @Override + public String toString() + { + return "VoidResponse{" + + "relatedHTTPCode=" + relatedHTTPCode + + ", exceptionClassName='" + exceptionClassName + '\'' + + ", exceptionErrorMessage='" + exceptionErrorMessage + '\'' + + ", exceptionSystemAction='" + exceptionSystemAction + '\'' + + ", exceptionUserAction='" + exceptionUserAction + '\'' + + '}'; + } +} http://git-wip-us.apache.org/repos/asf/atlas/blob/f57fd7f0/omas-connectedasset/README.md ---------------------------------------------------------------------- diff --git a/omas-connectedasset/README.md b/omas-connectedasset/README.md new file mode 100644 index 0000000..2f431df --- /dev/null +++ b/omas-connectedasset/README.md @@ -0,0 +1,42 @@ +<!-- + ~ 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. + --> + +# Connected Asset Open Metadata Access Service (OMAS) + +The Connected Asset OMAS implements the ConnectedAssetProperties API that is +available on every **OCF connector**. + +An OCF connector is a connector that supports the open connector framework (OCF). +It has 3 sets of APIs: +* An API to return properties about the connector and its connection +* An API to access the asset it connects to +* An API to access the metadata about the asset the connector is used to access + +The Connected Asset OMAS is the third API on an OCF connector - the one for the metadata about the asset. +It is a generic API for all types of open metadata assets. However, it assumes the +asset's metadata model inherits from **Asset** (see model 0010 in Area 0). + +The Connected Asset OMAS returns metadata about the asset at three levels of detail: + +* getAssetSummary - returns the summary information organized in the assetSummary structure. +* getAssetDetail - returns detailed information about the asset organized in the assetDetail structure. +* getAssetUniverse - returns all of the common metadata properties connected to the asset such as its schma, meanings +and platform. + +These structures are defined in the OCF module as POJO property objects. + http://git-wip-us.apache.org/repos/asf/atlas/blob/f57fd7f0/omas-connectedasset/pom.xml ---------------------------------------------------------------------- diff --git a/omas-connectedasset/pom.xml b/omas-connectedasset/pom.xml new file mode 100644 index 0000000..219c972 --- /dev/null +++ b/omas-connectedasset/pom.xml @@ -0,0 +1,111 @@ +<?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-connectedasset</artifactId> + + <name>Connected Asset Open Metadata Access Service (OMAS)</name> + <description>Connected Asset OMAS Module covering client, REST API, Event Listener and Event Publisher</description> + + <packaging>jar</packaging> + + <dependencies> + + <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>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + </dependency> + + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </dependency> + + <dependency> + <groupId>com.fasterxml.jackson.jaxrs</groupId> + <artifactId>jackson-jaxrs-base</artifactId> + <version>${jackson.version}</version> + </dependency> + + <dependency> + <groupId>com.fasterxml.jackson.jaxrs</groupId> + <artifactId>jackson-jaxrs-json-provider</artifactId> + <version>${jackson.version}</version> + </dependency> + + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <version>${javax-inject.version}</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>
