http://git-wip-us.apache.org/repos/asf/atlas/blob/b0ecc36a/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositorycontentmanager/OMRSRepositoryValidator.java ---------------------------------------------------------------------- diff --git a/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositorycontentmanager/OMRSRepositoryValidator.java b/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositorycontentmanager/OMRSRepositoryValidator.java deleted file mode 100644 index 3873e39..0000000 --- a/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositorycontentmanager/OMRSRepositoryValidator.java +++ /dev/null @@ -1,3299 +0,0 @@ -/* - * 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.omrs.localrepository.repositorycontentmanager; - -import org.apache.atlas.omrs.ffdc.OMRSErrorCode; -import org.apache.atlas.omrs.ffdc.exception.*; -import org.apache.atlas.omrs.metadatacollection.properties.MatchCriteria; -import org.apache.atlas.omrs.metadatacollection.properties.instances.*; -import org.apache.atlas.omrs.metadatacollection.properties.typedefs.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Date; -import java.util.Iterator; -import java.util.List; - -/** - * OMRSRepositoryValidator provides methods to validate TypeDefs and Instances returned from - * an open metadata repository. It is typically used by OMRS repository connectors and - * repository event mappers. - */ -public class OMRSRepositoryValidator implements OMRSTypeDefValidator, OMRSInstanceValidator -{ - private static OMRSRepositoryContentManager defaultRepositoryContentManager = null; - - private OMRSRepositoryContentManager repositoryContentManager; - - private static final Logger log = LoggerFactory.getLogger(OMRSRepositoryValidator.class); - - - - /** - * Default constructor - deprecated as a repository connector should get its repository validator - * from its superclass. - */ - @Deprecated - public OMRSRepositoryValidator() - { - repositoryContentManager = defaultRepositoryContentManager; - } - - - /** - * Typical constructor used by the OMRS to create a repository validator for a repository connector. - * - * @param repositoryContentManager - holds details of valid types and provides the implementation of - * the repository validator methods - */ - public OMRSRepositoryValidator(OMRSRepositoryContentManager repositoryContentManager) - { - this.repositoryContentManager = repositoryContentManager; - } - - /** - * Set up the local repository's content manager. This maintains a cache of the local repository's type - * definitions and rules to provide helpers and validators for TypeDefs and instances that are - * exchanged amongst the open metadata repositories and open metadata access services (OMAS). - * - * @param repositoryContentManager - link to repository content manager. - */ - public static synchronized void setRepositoryContentManager(OMRSRepositoryContentManager repositoryContentManager) - { - OMRSRepositoryHelper.setRepositoryContentManager(repositoryContentManager); - } - - - /** - * Return a boolean flag indicating whether the list of TypeDefs passed are compatible with the - * all known typedefs. - * - * A valid TypeDef is one that matches name, GUID and version to the full list of TypeDefs. - * If a new TypeDef is present, it is added to the enterprise list. - * - * @param sourceName - source of the request (used for logging) - * @param typeDefs - list of TypeDefs. - * @throws RepositoryErrorException - a conflicting or invalid TypeDef has been returned - */ - public void validateEnterpriseTypeDefs(String sourceName, - List<TypeDef> typeDefs, - String methodName) throws RepositoryErrorException - { - validateRepositoryContentManager(methodName); - - repositoryContentManager.validateEnterpriseTypeDefs(sourceName, typeDefs, methodName); - } - - - /** - * Return a boolean flag indicating whether the list of TypeDefs passed are compatible with the - * all known typedefs. - * - * A valid TypeDef is one that matches name, GUID and version to the full list of TypeDefs. - * If a new TypeDef is present, it is added to the enterprise list. - * - * @param sourceName - source of the request (used for logging) - * @param attributeTypeDefs - list of AttributeTypeDefs. - * @throws RepositoryErrorException - a conflicting or invalid AttributeTypeDef has been returned - */ - public void validateEnterpriseAttributeTypeDefs(String sourceName, - List<AttributeTypeDef> attributeTypeDefs, - String methodName) throws RepositoryErrorException - { - validateRepositoryContentManager(methodName); - - repositoryContentManager.validateEnterpriseAttributeTypeDefs(sourceName, attributeTypeDefs, methodName); - } - - - /** - * Return boolean indicating whether the TypeDef/AttributeTypeDef is in use in the repository. - * - * @param sourceName - source of the request (used for logging) - * @param typeGUID - unique identifier of the type - * @param typeName - unique name of the type - * @return boolean flag - */ - public boolean isActiveType(String sourceName, String typeGUID, String typeName) - { - final String methodName = "isActiveType"; - - validateRepositoryContentManager(methodName); - - return repositoryContentManager.isActiveType(sourceName, typeGUID, typeName); - } - - - /** - * Return boolean indicating whether the TypeDef/AttributeTypeDef is in use in the repository. - * - * @param sourceName - source of the request (used for logging) - * @param typeGUID - unique identifier of the type - * @return boolean flag - */ - public boolean isActiveTypeId(String sourceName, String typeGUID) - { - final String methodName = "isActiveTypeId"; - - validateRepositoryContentManager(methodName); - - return repositoryContentManager.isActiveTypeId(sourceName, typeGUID); - } - - - /** - * Return boolean indicating whether the TypeDef is one of the open metadata types. - * - * @param sourceName - source of the request (used for logging) - * @param typeGUID - unique identifier of the type - * @param typeName - unique name of the type - * @return boolean flag - */ - public boolean isOpenType(String sourceName, String typeGUID, String typeName) - { - final String methodName = "isOpenType"; - - validateRepositoryContentManager(methodName); - - return repositoryContentManager.isOpenType(sourceName, typeGUID, typeName); - } - - - /** - * Return boolean indicating whether the TypeDef is one of the open metadata types. - * - * @param sourceName - source of the request (used for logging) - * @param typeGUID - unique identifier of the type - * @return boolean flag - */ - public boolean isOpenTypeId(String sourceName, String typeGUID) - { - final String methodName = "isOpenTypeId"; - - validateRepositoryContentManager(methodName); - - return repositoryContentManager.isOpenTypeId(sourceName, typeGUID); - } - - - /** - * Return boolean indicating whether the TypeDef/AttributeTypeDef is in use in the repository. - * - * @param sourceName - source of the request (used for logging) - * @param typeGUID - unique identifier of the type - * @param typeName - unique name of the type - * @return boolean flag - */ - public boolean isKnownType(String sourceName, String typeGUID, String typeName) - { - final String methodName = "isKnownType"; - - validateRepositoryContentManager(methodName); - - return repositoryContentManager.isKnownType(sourceName, typeGUID, typeName); - } - - - /** - * Return boolean indicating whether the TypeDef/AttributeTypeDef is in use in the repository. - * - * @param sourceName - source of the request (used for logging) - * @param typeGUID - unique identifier of the type - * @return boolean flag - */ - public boolean isKnownTypeId(String sourceName, String typeGUID) - { - final String methodName = "isKnownTypeId"; - - validateRepositoryContentManager(methodName); - - return repositoryContentManager.isKnownTypeId(sourceName, typeGUID); - } - - - /** - * Return boolean indicating whether the TypeDef identifiers are from a single known type or not. - * - * @param sourceName - source of the request (used for logging) - * @param typeGUID - unique identifier of the TypeDef - * @param typeName - unique name of the TypeDef - * @return boolean result - */ - public boolean validTypeId(String sourceName, - String typeGUID, - String typeName) - { - final String methodName = "validTypeId"; - - validateRepositoryContentManager(methodName); - - return repositoryContentManager.validTypeId(sourceName, typeGUID, typeName); - } - - - /** - * Return boolean indicating whether the TypeDef identifiers are from a single known type or not. - * - * @param sourceName - source of the request (used for logging) - * @param typeDefGUID - unique identifier of the TypeDef - * @param typeDefName - unique name of the TypeDef - * @param category - category for the TypeDef - * @return boolean result - */ - public boolean validTypeDefId(String sourceName, - String typeDefGUID, - String typeDefName, - TypeDefCategory category) - { - final String methodName = "validTypeDefId"; - - validateRepositoryContentManager(methodName); - - return repositoryContentManager.validTypeDefId(sourceName, typeDefGUID, typeDefName, category); - } - - /** - * Return boolean indicating whether the AttributeTypeDef identifiers are from a single known type or not. - * - * @param sourceName - source of the request (used for logging) - * @param attributeTypeDefGUID - unique identifier of the AttributeTypeDef - * @param attributeTypeDefName - unique name of the AttributeTypeDef - * @param category - category for the AttributeTypeDef - * @return boolean result - */ - public boolean validAttributeTypeDefId(String sourceName, - String attributeTypeDefGUID, - String attributeTypeDefName, - AttributeTypeDefCategory category) - { - final String methodName = "validAttributeTypeDefId"; - - validateRepositoryContentManager(methodName); - - return repositoryContentManager.validAttributeTypeDefId(sourceName, - attributeTypeDefGUID, - attributeTypeDefName, - category); - } - - - - /** - * Return boolean indicating whether the TypeDef identifiers are from a single known type or not. - * - * @param sourceName - source of the request (used for logging) - * @param typeDefGUID - unique identifier of the TypeDef - * @param typeDefName - unique name of the TypeDef - * @param typeDefVersion - version of the type - * @param category - category for the TypeDef - * @return boolean result - */ - public boolean validTypeDefId(String sourceName, - String typeDefGUID, - String typeDefName, - long typeDefVersion, - TypeDefCategory category) - { - final String methodName = "validTypeDefId"; - - validateRepositoryContentManager(methodName); - - return repositoryContentManager.validTypeDefId(sourceName, - typeDefGUID, - typeDefName, - typeDefVersion, - category); - } - - - /** - * Return boolean indicating whether the TypeDef identifiers are from a single known type or not. - * - * @param sourceName - source of the request (used for logging) - * @param attributeTypeDefGUID - unique identifier of the TypeDef - * @param attributeTypeDefName - unique name of the TypeDef - * @param attributeTypeDefVersion - version of the type - * @param category - category for the TypeDef - * @return boolean result - */ - public boolean validAttributeTypeDefId(String sourceName, - String attributeTypeDefGUID, - String attributeTypeDefName, - long attributeTypeDefVersion, - AttributeTypeDefCategory category) - { - final String methodName = "validAttributeTypeDefId"; - - validateRepositoryContentManager(methodName); - - return repositoryContentManager.validAttributeTypeDefId(sourceName, - attributeTypeDefGUID, - attributeTypeDefName, - attributeTypeDefVersion, - category); - } - - - - /** - * Return boolean indicating whether the supplied TypeDef is valid or not. - * - * @param sourceName - source of the TypeDef (used for logging) - * @param typeDef - TypeDef to test - * @return boolean result - */ - public boolean validTypeDef(String sourceName, - TypeDef typeDef) - { - final String methodName = "validTypeDef"; - - validateRepositoryContentManager(methodName); - - return repositoryContentManager.validTypeDef(sourceName, typeDef); - } - - - /** - * Return boolean indicating whether the supplied AttributeTypeDef is valid or not. - * - * @param sourceName - source of the request (used for logging) - * @param attributeTypeDef - TypeDef to test - * @return boolean result - */ - public boolean validAttributeTypeDef(String sourceName, - AttributeTypeDef attributeTypeDef) - { - final String methodName = "validAttributeTypeDef"; - - validateRepositoryContentManager(methodName); - - return repositoryContentManager.validAttributeTypeDef(sourceName, attributeTypeDef); - } - - - /** - * Return boolean indicating whether the supplied TypeDefSummary is valid or not. - * - * @param sourceName - source of the request (used for logging) - * @param typeDefSummary - TypeDefSummary to test. - * @return boolean result. - */ - public boolean validTypeDefSummary(String sourceName, - TypeDefSummary typeDefSummary) - { - final String methodName = "validTypeDefSummary"; - - validateRepositoryContentManager(methodName); - - return repositoryContentManager.validTypeDefSummary(sourceName, typeDefSummary); - } - - - - /* - * ===================== - * OMRSInstanceValidator - */ - - /** - * Test that the supplied entity is valid. - * - * @param sourceName - source of the request (used for logging) - * @param entity - entity to test - * @return boolean result - */ - public boolean validEntity(String sourceName, - EntitySummary entity) - { - if (entity == null) - { - log.error("Null entity from " + sourceName); - return false; - } - - InstanceType instanceType = entity.getType(); - - if (instanceType == null) - { - log.error("Null instance type in entity from " + sourceName); - return false; - } - - if (! validInstanceId(sourceName, - instanceType.getTypeDefGUID(), - instanceType.getTypeDefName(), - instanceType.getTypeDefCategory(), - entity.getGUID())) - { - log.error("Null entity guid from " + sourceName); - return false; - } - - return true; - } - - - /** - * Test that the supplied entity is valid. - * - * @param sourceName - source of the request (used for logging) - * @param entity - entity to test - * @return boolean result - */ - public boolean validEntity(String sourceName, - EntityProxy entity) - { - return this.validEntity(sourceName, (EntitySummary)entity); - } - - - /** - * Test that the supplied entity is valid. - * - * @param sourceName - source of the request (used for logging) - * @param entity - entity to test - * @return boolean result - */ - public boolean validEntity(String sourceName, - EntityDetail entity) - { - return this.validEntity(sourceName, (EntitySummary)entity); - } - - - /** - * Test that the supplied relationship is valid. - * - * @param sourceName - source of the request (used for logging) - * @param relationship - relationship to test - * @return boolean result - */ - public boolean validRelationship(String sourceName, - Relationship relationship) - { - if (relationship == null) - { - log.error("Null relationship from " + sourceName); - return false; - } - - InstanceType instanceType = relationship.getType(); - - if (instanceType == null) - { - log.error("Null instance type in relationship from " + sourceName); - return false; - } - - if (! validInstanceId(sourceName, - instanceType.getTypeDefGUID(), - instanceType.getTypeDefName(), - instanceType.getTypeDefCategory(), - relationship.getGUID())) - { - log.error("Null relationship guid from " + sourceName); - return false; - } - - String homeMetadataCollectionId = relationship.getMetadataCollectionId(); - - if (homeMetadataCollectionId == null) - { - log.error("Null home metadata collection id for relationship " + relationship.getGUID() + " from " + sourceName); - return false; - } - - return true; - } - - - /** - * Verify that the identifiers for an instance are correct. - * - * @param sourceName - source of the request (used for logging) - * @param typeDefGUID - unique identifier for the type. - * @param typeDefName - unique name for the type. - * @param category - expected category of the instance. - * @param instanceGUID - unique identifier for the instance. - * @return boolean indicating whether the identifiers are ok. - */ - public boolean validInstanceId(String sourceName, - String typeDefGUID, - String typeDefName, - TypeDefCategory category, - String instanceGUID) - { - if (instanceGUID == null) - { - log.error("Null instance guid from " + sourceName); - return false; - } - - if (! validTypeDefId(sourceName, - typeDefGUID, - typeDefName, - category)) - { - /* - * Error messages already logged - */ - return false; - } - - return true; - } - - - /* ============================================================== - * Simple parameter validation methods needed by all repositories - * ============================================================== - */ - - - /** - * Validate that the supplied user Id is not null. - * - * @param sourceName - name of source of request. - * @param userId - userId passed on call to this metadata collection. - * @param methodName - name of method requesting the validation. - * @throws UserNotAuthorizedException - the userId is invalid - */ - public void validateUserId(String sourceName, - String userId, - String methodName) throws UserNotAuthorizedException - { - if ("".equals(userId)) - { - OMRSErrorCode errorCode = OMRSErrorCode.NULL_USER_ID; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage("userId", methodName, sourceName); - - throw new UserNotAuthorizedException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - /** - * Validate that a TypeDef's identifiers are not null. - * - * @param sourceName - source of the request (used for logging) - * @param guidParameterName - name of the parameter that passed the guid. - * @param nameParameterName - name of the parameter that passed the name. - * @param guid - unique identifier for a type or an instance passed on the request - * @param name - name of TypeDef. - * @param methodName - method receiving the call - * @throws InvalidParameterException - no guid provided - */ - public void validateTypeDefIds(String sourceName, - String guidParameterName, - String nameParameterName, - String guid, - String name, - String methodName) throws InvalidParameterException - { - if (guid == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NULL_TYPEDEF_IDENTIFIER; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(guidParameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - else if (name == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NO_TYPEDEF_NAME; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(nameParameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - /** - * Validate that an AttributeTypeDef's identifiers are not null and are recognized. - * - * @param sourceName - source of the request (used for logging) - * @param guidParameterName - name of the parameter that passed the guid. - * @param nameParameterName - name of the parameter that passed the name. - * @param guid - unique identifier for a type or an instance passed on the request - * @param name - name of TypeDef. - * @param methodName - method receiving the call - * @throws InvalidParameterException - no guid, or name provided - */ - public void validateAttributeTypeDefIds(String sourceName, - String guidParameterName, - String nameParameterName, - String guid, - String name, - String methodName) throws InvalidParameterException - { - if (guid == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NULL_ATTRIBUTE_TYPEDEF_IDENTIFIER; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(guidParameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - else if (name == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NO_ATTRIBUTE_TYPEDEF_NAME; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(nameParameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - /** - * Validate that type's identifier is not null. - * - * @param sourceName - source of the request (used for logging) - * @param guidParameterName - name of the parameter that passed the guid. - * @param guid - unique identifier for a type or an instance passed on the request - * @param methodName - method receiving the call - * @throws InvalidParameterException - no guid provided - * @throws TypeErrorException - guid is not for a recognized type - */ - public void validateTypeGUID(String sourceName, - String guidParameterName, - String guid, - String methodName) throws InvalidParameterException, - TypeErrorException - { - if (guid == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NULL_TYPEDEF_IDENTIFIER; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(guidParameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - - validateOptionalTypeGUID(sourceName, guidParameterName, guid, methodName); - } - - - /** - * Validate that type's identifier is not null. - * - * @param sourceName - source of the request (used for logging) - * @param guidParameterName - name of the parameter that passed the guid. - * @param guid - unique identifier for a type or an instance passed on the request - * @param methodName - method receiving the call - * @throws TypeErrorException - unknown type guid - */ - public void validateOptionalTypeGUID(String sourceName, - String guidParameterName, - String guid, - String methodName) throws TypeErrorException - { - if (guid != null) - { - if (! isKnownTypeId(sourceName, guid)) - { - OMRSErrorCode errorCode = OMRSErrorCode.TYPEDEF_ID_NOT_KNOWN; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(guid, - guidParameterName, - methodName, - sourceName); - - throw new TypeErrorException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - } - - - /** - * Verify that a TypeDefPatch is not null. - * - * @param sourceName - source of the request (used for logging) - * @param patch - patch to test - * @param methodName - calling method - * @throws InvalidParameterException - the patch is null - * @throws PatchErrorException - the patch is invalid - */ - public void validateTypeDefPatch(String sourceName, - TypeDefPatch patch, - String methodName) throws InvalidParameterException, PatchErrorException - { - if (patch == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NULL_TYPEDEF_PATCH; - String errorMessage = errorCode.getErrorMessageId() + errorCode.getFormattedErrorMessage(methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - /** - * Validate that if a type's identifier is passed then it is valid. - * - * @param sourceName - source of the request (used for logging) - * @param guidParameterName - name of the parameter that passed the guid. - * @param guid - unique identifier for a type or an instance passed on the request - * @param methodName - method receiving the call - * @throws TypeErrorException - invalid provided - */ - public void validateInstanceTypeGUID(String sourceName, - String guidParameterName, - String guid, - String methodName) throws TypeErrorException - { - if (guid == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.BAD_TYPEDEF_ID_FOR_INSTANCE; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(guidParameterName, - methodName, - sourceName); - - throw new TypeErrorException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - /** - * Validate that type's name is not null. - * - * @param sourceName - source of the request (used for logging) - * @param nameParameterName - name of the parameter that passed the name. - * @param name - unique identifier for a type or an instance passed on the request - * @param methodName - method receiving the call - * @throws InvalidParameterException - no name provided - */ - public void validateTypeName(String sourceName, - String nameParameterName, - String name, - String methodName) throws InvalidParameterException - { - if (name == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NO_TYPEDEF_NAME; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(nameParameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - /** - * Validate that a TypeDef's category is not null. - * - * @param sourceName - source of the request (used for logging) - * @param nameParameterName - name of the parameter that passed the name. - * @param category - category of TypeDef - * @param methodName - method receiving the call - * @throws InvalidParameterException - no name provided - */ - public void validateTypeDefCategory(String sourceName, - String nameParameterName, - TypeDefCategory category, - String methodName) throws InvalidParameterException - { - if (category == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NO_TYPEDEF_CATEGORY; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(nameParameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - /** - * Validate that a AttributeTypeDef's category is not null. - * - * @param sourceName - source of the request (used for logging) - * @param nameParameterName - name of the parameter that passed the name. - * @param category - category of TypeDef - * @param methodName - method receiving the call - * @throws InvalidParameterException - no name provided - */ - public void validateAttributeTypeDefCategory(String sourceName, - String nameParameterName, - AttributeTypeDefCategory category, - String methodName) throws InvalidParameterException - { - if (category == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NO_ATTRIBUTE_TYPEDEF_CATEGORY; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(nameParameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - /** - * Validate the content of a new TypeDef is valid. - * - * @param sourceName - source of the request (used for logging) - * @param parameterName - name of the parameter that passed the typeDef. - * @param typeDef - unique identifier for a type or an instance passed on the request - * @param methodName - method receiving the call - * @throws InvalidParameterException - no typeDef provided - * @throws InvalidTypeDefException - invalid typeDef provided - */ - public void validateTypeDef(String sourceName, - String parameterName, - TypeDef typeDef, - String methodName) throws InvalidParameterException, InvalidTypeDefException - { - if (typeDef == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NULL_TYPEDEF; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(parameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - - validateTypeDefIds(sourceName, - parameterName + ".getGUID", - parameterName + ".getName", - typeDef.getGUID(), - typeDef.getName(), - methodName); - - validateTypeDefCategory(sourceName, - parameterName + ".getCategory", - typeDef.getCategory(), - methodName); - - - } - - - /** - * Validate the content of a new TypeDef is known. - * - * @param sourceName - source of the request (used for logging) - * @param parameterName - name of the parameter that passed the typeDef. - * @param typeDef - unique identifier for a type or an instance passed on the request - * @param methodName - method receiving the call - * @throws TypeDefNotKnownException - no recognized typeDef provided - */ - public void validateKnownTypeDef(String sourceName, - String parameterName, - TypeDef typeDef, - String methodName) throws TypeDefNotKnownException - { - final String thisMethodName = "validateKnownTypeDef"; - - validateRepositoryContentManager(thisMethodName); - - if (! repositoryContentManager.isKnownType(sourceName, typeDef.getGUID(), typeDef.getName())) - { - OMRSErrorCode errorCode = OMRSErrorCode.TYPEDEF_NOT_KNOWN; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(typeDef.getName(), - typeDef.getGUID(), - parameterName, - methodName, - sourceName); - - throw new TypeDefNotKnownException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - - } - } - - - /** - * Validate the content of a new TypeDef is known. - * - * @param sourceName - source of the request (used for logging) - * @param parameterName - name of the parameter that passed the typeDef. - * @param typeDef - unique identifier for a type or an instance passed on the request - * @param methodName - method receiving the call - * @throws TypeDefKnownException - the TypeDef is already defined - * @throws TypeDefConflictException - the TypeDef is already defined - but differently - */ - public void validateUnknownTypeDef(String sourceName, - String parameterName, - TypeDef typeDef, - String methodName) throws TypeDefKnownException, - TypeDefConflictException - { - final String thisMethodName = "validateUnknownTypeDef"; - - validateRepositoryContentManager(thisMethodName); - - if (repositoryContentManager.isKnownType(sourceName, typeDef.getGUID(), typeDef.getName())) - { - // todo validate that the existing typeDef matches the new one. - - OMRSErrorCode errorCode = OMRSErrorCode.TYPEDEF_ALREADY_DEFINED; - String errorMessage = errorCode.getErrorMessageId() + errorCode.getFormattedErrorMessage(typeDef.getName(), - typeDef.getGUID(), - sourceName); - - throw new TypeDefKnownException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - - } - } - - - /** - * Validate the content of a new TypeDef is known. - * - * @param sourceName - source of the request (used for logging) - * @param parameterName - name of the parameter that passed the typeDef. - * @param attributeTypeDef - unique identifier for an attribute type or an instance passed on the request - * @param methodName - method receiving the call - * @throws TypeDefKnownException - the TypeDef is already defined - * @throws TypeDefConflictException - the TypeDef is already defined - but differently - */ - public void validateUnknownAttributeTypeDef(String sourceName, - String parameterName, - AttributeTypeDef attributeTypeDef, - String methodName) throws TypeDefKnownException, - TypeDefConflictException - { - final String thisMethodName = "validateUnknownTypeDef"; - - validateRepositoryContentManager(thisMethodName); - - if (repositoryContentManager.isKnownType(sourceName, - attributeTypeDef.getGUID(), - attributeTypeDef.getName())) - { - // todo validate that the existing typeDef matches the new one. - - OMRSErrorCode errorCode = OMRSErrorCode.ATTRIBUTE_TYPEDEF_ALREADY_DEFINED; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(attributeTypeDef.getName(), - attributeTypeDef.getGUID(), - sourceName); - - throw new TypeDefKnownException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - - } - } - - - /** - * Validate the content of a TypeDef associated with a metadata instance. - * - * @param sourceName - source of the request (used for logging) - * @param parameterName - name of the parameter that passed the typeDef. - * @param typeDef - unique identifier for a type or an instance passed on the request - * @param methodName - method receiving the call - * @throws TypeErrorException - no typeDef provided - * @throws RepositoryErrorException - the TypeDef from the repository is in error. - */ - public void validateTypeDefForInstance(String sourceName, - String parameterName, - TypeDef typeDef, - String methodName) throws TypeErrorException, - RepositoryErrorException - { - if (typeDef == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NULL_TYPEDEF; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(parameterName, - methodName, - sourceName); - - throw new TypeErrorException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - - try - { - validateTypeDefIds(sourceName, - parameterName + ".getGUID", - parameterName + ".getName", - typeDef.getGUID(), - typeDef.getName(), - methodName); - - validateTypeDefCategory(sourceName, - parameterName + ".getCategory", - typeDef.getCategory(), - methodName); - } - catch (Throwable error) - { - OMRSErrorCode errorCode = OMRSErrorCode.BAD_TYPEDEF; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(parameterName, - methodName, - sourceName); - - throw new RepositoryErrorException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - /** - * Validate that the supplied TypeDef GUID and name matches the type associated with a metadata instance. - * - * @param sourceName - source of the request (used for logging) - * @param typeDefGUID - the supplied typeDef GUID. - * @param typeDefName - the supplied typeDef name. - * @param instance - instance retrieved from the store with the supplied instance guid - * @param methodName - method making this call - * @throws InvalidParameterException - incompatibility detected between the TypeDef and the instance's type - * @throws RepositoryErrorException - the instance from the repository is in error. - */ - public void validateTypeForInstanceDelete(String sourceName, - String typeDefGUID, - String typeDefName, - InstanceHeader instance, - String methodName) throws InvalidParameterException, - RepositoryErrorException - { - /* - * Just make sure the instance has a type :) - */ - this.validateInstanceType(sourceName, instance); - - - /* - * Both the GUID and the name must match - */ - if ((! typeDefGUID.equals(instance.getType().getTypeDefGUID())) || - (! typeDefName.equals(instance.getType().getTypeDefName()))) - { - OMRSErrorCode errorCode = OMRSErrorCode.BAD_TYPEDEF_IDS_FOR_DELETE; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(typeDefName, - typeDefGUID, - methodName, - instance.getGUID(), - sourceName); - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - - } - - - /** - * Validate the content of a new AttributeTypeDef. - * - * @param sourceName - source of the request (used for logging) - * @param parameterName - name of the parameter that passed the attributeTypeDef. - * @param attributeTypeDef - unique identifier for a type or an instance passed on the request - * @param methodName - method receiving the call - * @throws InvalidParameterException - no attributeTypeDef provided - * @throws InvalidTypeDefException - bad attributeTypeDef provided - */ - public void validateAttributeTypeDef(String sourceName, - String parameterName, - AttributeTypeDef attributeTypeDef, - String methodName) throws InvalidParameterException, - InvalidTypeDefException - { - if (attributeTypeDef == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NULL_ATTRIBUTE_TYPEDEF; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(parameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - - validateAttributeTypeDefIds(sourceName, - parameterName + ".getGUID", - parameterName + ".getName", - attributeTypeDef.getGUID(), - attributeTypeDef.getName(), - methodName); - - validateAttributeTypeDefCategory(sourceName, - parameterName + ".getCategory", - attributeTypeDef.getCategory(), - methodName); - } - - - /** - * Validate that type's name is not null. - * - * @param sourceName - source of the request (used for logging) - * @param parameterName - name of the parameter that passed the name. - * @param gallery - typeDef gallery - * @param methodName - method receiving the call - * @throws InvalidParameterException - no name provided - */ - public void validateTypeDefGallery(String sourceName, - String parameterName, - TypeDefGallery gallery, - String methodName) throws InvalidParameterException - { - if (gallery == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NULL_TYPEDEF_GALLERY; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(parameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - /** - * Validate that the type's name is not null. - * - * @param sourceName - source of the request (used for logging) - * @param standard - name of the standard - null means any. - * @param organization - name of the organization - null means any. - * @param identifier - identifier of the element in the standard - null means any. - * @param methodName - method receiving the call - * @throws InvalidParameterException - no name provided - */ - public void validateExternalId(String sourceName, - String standard, - String organization, - String identifier, - String methodName) throws InvalidParameterException - { - if ((standard == null) && (organization == null) || (identifier == null)) - { - OMRSErrorCode errorCode = OMRSErrorCode.NO_EXTERNAL_ID; - - String errorMessage = errorCode.getErrorMessageId() + errorCode.getFormattedErrorMessage(methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - /** - * Validate that an entity's identifier is not null. - * - * @param sourceName - source of the request (used for logging) - * @param guidParameterName - name of the parameter that passed the guid. - * @param guid - unique identifier for a type or an instance passed on the request - * @param methodName - method receiving the call - * @throws InvalidParameterException - no guid provided - */ - public void validateGUID(String sourceName, - String guidParameterName, - String guid, - String methodName) throws InvalidParameterException - { - if (guid == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NO_GUID; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(guidParameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - /** - * Validate that a home metadata collection identifier is not null. - * - * @param sourceName - source of the request (used for logging) - * @param guidParameterName - name of the parameter that passed the guid. - * @param guid - unique identifier for a type or an instance passed on the request - * @param methodName - method receiving the call - * @throws InvalidParameterException - no guid provided - */ - public void validateHomeMetadataGUID(String sourceName, - String guidParameterName, - String guid, - String methodName) throws InvalidParameterException - { - if (guid == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NULL_HOME_METADATA_COLLECTION_ID; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(guidParameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - - /** - * Validate that a home metadata collection identifier in an instance is not null. - * - * @param sourceName - source of the request (used for logging) - * @param instance - instance to test. - * @param methodName - method receiving the call - * @throws RepositoryErrorException - no guid provided - */ - public void validateHomeMetadataGUID(String sourceName, - InstanceHeader instance, - String methodName) throws RepositoryErrorException - { - final String thisMethodName = "validateHomeMetadataGUID"; - - if (instance == null) - { - this.throwValidatorLogicError(sourceName, methodName, thisMethodName); - } - - if (instance.getMetadataCollectionId() == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NULL_INSTANCE_METADATA_COLLECTION_ID; - String errorMessage = errorCode.getErrorMessageId() + errorCode.getFormattedErrorMessage(instance.getGUID(), - sourceName, - methodName, - instance.toString()); - - throw new RepositoryErrorException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - /** - * Validate that the asOfTime parameter is not for the future. - * - * @param sourceName - source of the request (used for logging) - * @param parameterName - name of the parameter that passed the guid. - * @param asOfTime - unique name for a classification type - * @param methodName - method receiving the call - * @throws InvalidParameterException - asOfTime is for the future - */ - public void validateAsOfTime(String sourceName, - String parameterName, - Date asOfTime, - String methodName) throws InvalidParameterException - { - if (asOfTime != null) - { - Date now = new Date(); - - if (asOfTime.after(now)) - { - OMRSErrorCode errorCode = OMRSErrorCode.REPOSITORY_NOT_CRYSTAL_BALL; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(asOfTime.toString(), - parameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - } - - - /** - * Validate that a page size parameter is not negative. - * - * @param sourceName - source of the request (used for logging) - * @param parameterName - name of the parameter that passed the guid. - * @param pageSize - number of elements to return on a request - * @param methodName - method receiving the call - * @throws PagingErrorException - pageSize is negative - */ - public void validatePageSize(String sourceName, - String parameterName, - int pageSize, - String methodName) throws PagingErrorException - { - if (pageSize < 0) - { - OMRSErrorCode errorCode = OMRSErrorCode.NEGATIVE_PAGE_SIZE; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(Integer.toString(pageSize), - parameterName, - methodName, - sourceName); - - throw new PagingErrorException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - - } - } - - - /** - * Validate that a classification name is not null. - * - * @param sourceName - source of the request (used for logging) - * @param parameterName - name of the parameter that passed the guid. - * @param classificationName - unique name for a classification type - * @param methodName - method receiving the call - * @throws InvalidParameterException - classification name is null - */ - public void validateClassificationName(String sourceName, - String parameterName, - String classificationName, - String methodName) throws InvalidParameterException - { - if (classificationName == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NULL_CLASSIFICATION_NAME; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(parameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - /** - * Validate that a classification is valid for the entity. - * - * @param sourceName - source of the request (used for logging) - * @param classificationName - unique name for a classification type - * @param propertiesParameterName - name of the parameter that passed the properties. - * @param classificationProperties - properties to test - * @param methodName - method receiving the call - * @throws PropertyErrorException - classification name is null - * @throws TypeErrorException - the classification is invalid for this entity - */ - public void validateClassificationProperties(String sourceName, - String classificationName, - String propertiesParameterName, - InstanceProperties classificationProperties, - String methodName) throws PropertyErrorException, - TypeErrorException - { - validateRepositoryContentManager(methodName); - - TypeDef classificationTypeDef = repositoryContentManager.getTypeDefByName(sourceName, classificationName); - - if (classificationTypeDef != null) - { - validatePropertiesForType(sourceName, propertiesParameterName, classificationTypeDef, classificationProperties, methodName); - } - else - { - /* - * Logic error as the type should be valid - */ - final String thisMethodName = "validateClassificationProperties"; - - throwValidatorLogicError(sourceName, methodName, thisMethodName); - } - } - - - /** - * Validate that a classification is valid for the entity. - * - * @param sourceName - source of the request (used for logging) - * @param classificationParameterName - name of the parameter that passed the guid. - * @param classificationName - unique name for a classification type - * @param entityTypeName - name of entity type - * @param methodName - method receiving the call - * @throws InvalidParameterException - classification name is null - * @throws ClassificationErrorException - the classification is invalid for this entity - */ - public void validateClassification(String sourceName, - String classificationParameterName, - String classificationName, - String entityTypeName, - String methodName) throws InvalidParameterException, - ClassificationErrorException - { - validateRepositoryContentManager(methodName); - - this.validateClassificationName(sourceName, classificationParameterName, classificationName, methodName); - - if (entityTypeName != null) - { - if (!repositoryContentManager.isValidClassificationForEntity(sourceName, - classificationName, - entityTypeName, - methodName)) - { - OMRSErrorCode errorCode = OMRSErrorCode.INVALID_CLASSIFICATION_FOR_ENTITY; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(sourceName, - classificationName, - entityTypeName); - - throw new ClassificationErrorException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - } - - - /** - * Validate that a classification is valid for the entity. - * - * @param sourceName - source of the request (used for logging) - * @param parameterName - name of the parameter that passed the guid. - * @param classifications - list of classifications - * @param entityTypeName - name of entity type - * @param methodName - method receiving the call - * @throws InvalidParameterException - classification name is null - * @throws ClassificationErrorException - the classification is invalid for this entity - * @throws PropertyErrorException - the classification's properties are invalid for its type - * @throws TypeErrorException - the classification's type is invalid - */ - public void validateClassificationList(String sourceName, - String parameterName, - List<Classification> classifications, - String entityTypeName, - String methodName) throws InvalidParameterException, - ClassificationErrorException, - PropertyErrorException, - TypeErrorException - { - validateRepositoryContentManager(methodName); - - if (classifications != null) - { - for (Classification classification : classifications) - { - if (classification != null) - { - - this.validateClassification(sourceName, - parameterName, - classification.getName(), - entityTypeName, - methodName); - - - this.validatePropertiesForType(sourceName, - parameterName, - repositoryContentManager.getTypeDefByName(sourceName, - classification.getName()), - classification.getProperties(), - methodName); - } - else - { - OMRSErrorCode errorCode = OMRSErrorCode.NULL_CLASSIFICATION_NAME; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(parameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - } - } - - - /** - * Validate that a TypeDef match criteria set of properties is not null. - * - * @param sourceName - source of the request (used for logging) - * @param parameterName - name of the parameter that passed the match criteria. - * @param matchCriteria - match criteria properties - * @param methodName - method receiving the call - * @throws InvalidParameterException - no guid provided - */ - public void validateMatchCriteria(String sourceName, - String parameterName, - TypeDefProperties matchCriteria, - String methodName) throws InvalidParameterException - { - if (matchCriteria == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NO_MATCH_CRITERIA; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(parameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - /** - * Validate that a metadata instance match criteria and set of properties are either both null or - * both not null. - * - * @param sourceName - source of the request (used for logging) - * @param matchCriteriaParameterName - name of the parameter that passed the match criteria. - * @param matchPropertiesParameterName - name of the parameter that passed the match criteria. - * @param matchCriteria - match criteria enum - * @param matchProperties - match properties - * @param methodName - method receiving the call - * @throws InvalidParameterException - no guid provided - */ - public void validateMatchCriteria(String sourceName, - String matchCriteriaParameterName, - String matchPropertiesParameterName, - MatchCriteria matchCriteria, - InstanceProperties matchProperties, - String methodName) throws InvalidParameterException - { - if ((matchCriteria == null) && (matchProperties == null)) - { - return; - } - - if (matchCriteria == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NO_MATCH_CRITERIA; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(matchCriteriaParameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - - if (matchProperties == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NO_MATCH_CRITERIA; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(matchPropertiesParameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - /** - * Validate that a search criteria is not null. - * - * @param sourceName - source of the request (used for logging) - * @param parameterName - name of the parameter that passed the search criteria. - * @param searchCriteria - match criteria properties - * @param methodName - method receiving the call - * @throws InvalidParameterException - no guid provided - */ - public void validateSearchCriteria(String sourceName, - String parameterName, - String searchCriteria, - String methodName) throws InvalidParameterException - { - if ((searchCriteria == null) || ("".equals(searchCriteria))) - { - OMRSErrorCode errorCode = OMRSErrorCode.NO_SEARCH_CRITERIA; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(parameterName, - methodName, - sourceName); - - throw new InvalidParameterException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - } - - - /** - * Validate that the properties for a metadata instance match its TypeDef - * - * @param sourceName - source of the request (used for logging) - * @param parameterName - name of the properties parameter. - * @param typeDef - type information to validate against. - * @param properties - proposed properties - * @param methodName - method receiving the call - * @throws PropertyErrorException - invalid property - */ - public void validatePropertiesForType(String sourceName, - String parameterName, - TypeDef typeDef, - InstanceProperties properties, - String methodName) throws PropertyErrorException - { - if (typeDef == null) - { - /* - * Logic error as the type should be valid - */ - final String thisMethodName = "validatePropertiesForType"; - - throwValidatorLogicError(sourceName, methodName, thisMethodName); - } - - if (properties == null) - { - /* - * No properties to evaluate so return - */ - return; - } - - - String typeDefCategoryName = null; - String typeDefName = typeDef.getName(); - - if (typeDef.getCategory() != null) - { - typeDefCategoryName = typeDef.getCategory().getTypeName(); - } - - List<TypeDefAttribute> typeDefAttributes = typeDef.getPropertiesDefinition(); - - if (typeDefAttributes == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NO_PROPERTIES_FOR_TYPE; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(typeDefCategoryName, - typeDefName, - sourceName); - - throw new PropertyErrorException(errorCode.getHTTPErrorCode(), - this.getClass().getName(), - methodName, - errorMessage, - errorCode.getSystemAction(), - errorCode.getUserAction()); - } - - /* - * Need to step through each of the proposed properties and validate that the name and value are - * present and they match the typeDef - */ - Iterator propertyList = properties.getPropertyNames(); - - while (propertyList.hasNext()) - { - String propertyName = propertyList.next().toString(); - - if (propertyName == null) - { - OMRSErrorCode errorCode = OMRSErrorCode.NULL_PROPERTY_NAME_FOR_INSTANCE; - String errorMessage = errorCode.getErrorMessageId() - + errorCode.getFormattedErrorMessage(parameterName, - methodName, - sourceName); - - throw new PropertyErro
<TRUNCATED>