Skip to content

Commit

Permalink
odpi#5399 remove purge
Browse files Browse the repository at this point in the history
Signed-off-by: David Radley <david_radley@uk.ibm.com>
  • Loading branch information
davidradl committed Jul 8, 2021
1 parent 47f6512 commit 30f9595
Show file tree
Hide file tree
Showing 40 changed files with 948 additions and 1,684 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,6 @@ public enum SubjectAreaErrorCode implements ExceptionMessageSet {
"The system is unable to process the request to change the status to deleted.",
"Correct the code in the caller to provide a valid status. Use delete call to change status to deleted."),

GUID_NOT_PURGED_ERROR(400, "OMAS-SUBJECT-AREA-400-048",
"Guid {0} was not deleted.",
"The system is unable to process to delete the userId.",
"Contact your administrator to review the audit log to find the cause of why this userId cannot be deleted."),
GLOSSARY_CREATE_WITHOUT_NAME(400, "OMAS-SUBJECT-AREA-400-049",
"Cannot create a Glossary without a name",
"The system is unable to process the Glossary create request without a name.",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ public T update(String userId, String guid, T supplied, boolean isReplace) throw
}

@Override
public void delete(String userId, String guid, boolean isPurge) throws InvalidParameterException,
public void delete(String userId, String guid) throws InvalidParameterException,
PropertyServerException,
UserNotAuthorizedException
{
final String urlTemplate = BASE_URL + "/%s?isPurge=" + Boolean.toString(isPurge);
client.deleteRESTCall(userId, guid, getMethodInfo("delete(isPurge=" + isPurge + ")"), getParameterizedType(), urlTemplate);
client.deleteRESTCall(userId, guid, getMethodInfo("delete()"), getParameterizedType(), BASE_URL);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,50 +202,15 @@ default T update(String userId, String guid, T supplied) throws InvalidParameter
*
* @param guid unique identifier of the Glossary Artifact.
* @param userId unique identifier for requesting user, under which the request is performed.
* @param isPurge true indicates a hard delete, false is a soft delete.
*
* @throws PropertyServerException something went wrong with the REST call stack.
* @throws UserNotAuthorizedException the requesting user is not authorized to issue this request.
* @throws InvalidParameterException one of the parameters is null or invalid.
*/
void delete(String userId, String guid, boolean isPurge) throws InvalidParameterException,
void delete(String userId, String guid) throws InvalidParameterException,
PropertyServerException,
UserNotAuthorizedException;

/**
* Purge a Glossary Artifact.
*
* @param guid unique identifier of the Glossary Artifact.
* @param userId unique identifier for requesting user, under which the request is performed.
*
* @throws PropertyServerException something went wrong with the REST call stack.
* @throws UserNotAuthorizedException the requesting user is not authorized to issue this request.
* @throws InvalidParameterException one of the parameters is null or invalid.
*/
default void purge(String userId, String guid) throws InvalidParameterException,
PropertyServerException,
UserNotAuthorizedException
{
delete(userId, guid, true);
}

/**
* Soft delete a Glossary Artifact.
*
* @param guid unique identifier of the Glossary Artifact.
* @param userId unique identifier for requesting user, under which the request is performed.
*
* @throws PropertyServerException something went wrong with the REST call stack.
* @throws UserNotAuthorizedException the requesting user is not authorized to issue this request.
* @throws InvalidParameterException one of the parameters is null or invalid.
*/
default void delete(String userId, String guid) throws InvalidParameterException,
PropertyServerException,
UserNotAuthorizedException
{
delete(userId, guid, false);
}

/**
* Restore of a soft deleted Glossary Artifact.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ public SubjectAreaOMASAPIResponse<Category> createCategory(String userId, Catego
} catch (SubjectAreaCheckedException | PropertyServerException | UserNotAuthorizedException | InvalidParameterException e) {
//if the entity is created, but subsequently an error occurred while creating the relationship
if (createdCategoryGuid != null) {
deleteCategory(userId, createdCategoryGuid, false);
deleteCategory(userId, createdCategoryGuid, true);
deleteCategory(userId, createdCategoryGuid);
}
response.setExceptionInfo(e, className);
}
Expand Down Expand Up @@ -400,10 +399,9 @@ private void updateAttributes(Category currentCategory, Category newTerm) {
* <li> InvalidParameterException one of the parameters is null or invalid.</li>
* <li> PropertyServerException Property server exception. </li>
* <li> EntityNotDeletedException a soft delete was issued but the category was not deleted.</li>
* <li> EntityNotPurgedException a hard delete was issued but the category was not purged</li>
* </ul>
*/
public SubjectAreaOMASAPIResponse<Category> deleteCategory(String userId, String guid, Boolean isPurge) {
public SubjectAreaOMASAPIResponse<Category> deleteCategory(String userId, String guid) {
final String methodName = "deleteCategory";
SubjectAreaOMASAPIResponse<Category> response = new SubjectAreaOMASAPIResponse<>();

Expand All @@ -413,21 +411,17 @@ public SubjectAreaOMASAPIResponse<Category> deleteCategory(String userId, String
Category categoryToBeDeleted = response.head().get();
checkReadOnly(methodName, categoryToBeDeleted, "delete");
}
if (isPurge) {
oMRSAPIHelper.callOMRSPurgeEntity(methodName, userId, CATEGORY_TYPE_NAME, guid);
} else {
genericHandler.deleteBeanInRepository(userId,
null,
null,
guid,
"guid",
OpenMetadataAPIMapper.GLOSSARY_CATEGORY_TYPE_GUID,
OpenMetadataAPIMapper.GLOSSARY_CATEGORY_TYPE_NAME,
null,
null,
methodName);
}
} catch (SubjectAreaCheckedException | PropertyServerException | UserNotAuthorizedException | InvalidParameterException e) {
genericHandler.deleteBeanInRepository(userId,
null,
null,
guid,
"guid",
OpenMetadataAPIMapper.GLOSSARY_CATEGORY_TYPE_GUID,
OpenMetadataAPIMapper.GLOSSARY_CATEGORY_TYPE_NAME,
null,
null,
methodName);
} catch (PropertyServerException | UserNotAuthorizedException | InvalidParameterException e) {
response.setExceptionInfo(e, className);
}

Expand Down Expand Up @@ -471,7 +465,6 @@ public SubjectAreaOMASAPIResponse<Category> restoreCategory(String userId, Strin
* @param searchCriteria String expression to match the categorized Term property values.
* @param exactValue a boolean, which when set means that only exact matches will be returned, otherwise matches that start with the search criteria will be returned.
* @param ignoreCase a boolean, which when set means that case will be ignored, if not set that case will be respected
* @param startingFrom the starting element number for this set of results. This is used when retrieving elements
* @param termHandler term handler
* @param startingFrom initial position in the stored list.
* @param pageSize maximum number of definitions to return on this call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,27 +323,24 @@ private void updateAttributes(Glossary oldGlossary, Glossary newGlossary) {
* The deletion of a glossary is only allowed if there is no glossary content (i.e. no terms or categories).
* <p>
* There are 2 types of deletion, a soft delete and a hard delete (also known as a purge). All repositories support hard deletes. Soft deletes support
* is optional. Soft delete is the default.
* is optional.
* <p>
* A soft delete means that the glossary instance will exist in a deleted state in the repository after the delete operation. This means
* that it is possible to undo the delete.
* A hard delete means that the glossary will not exist after the operation.
* when not successful the following Exceptions can occur
*
* @param userId unique identifier for requesting user, under which the request is performed
* @param guid guid of the glossary to be deleted.
* @param isPurge true indicates a hard delete, false is a soft delete.
* @return a void response
* when not successful the following Exception responses can occur
* <ul>
* <li> UserNotAuthorizedException the requesting user is not authorized to issue this request.</li>
* <li> InvalidParameterException one of the parameters is null or invalid.</li>
* <li> PropertyServerException Property server exception. </li>
* <li> EntityNotDeletedException a soft delete was issued but the glossary was not deleted.</li>
* <li> EntityNotPurgedException a hard delete was issued but the glossary was not purged</li>
* </ul>
*/
public SubjectAreaOMASAPIResponse<Glossary> deleteGlossary(String userId, String guid, Boolean isPurge) {
public SubjectAreaOMASAPIResponse<Glossary> deleteGlossary(String userId, String guid) {
final String methodName = "deleteGlossary";
SubjectAreaOMASAPIResponse<Glossary> response = new SubjectAreaOMASAPIResponse<>();
boolean issueDelete = false;
Expand All @@ -353,24 +350,21 @@ public SubjectAreaOMASAPIResponse<Glossary> deleteGlossary(String userId, String
if (response.head().isPresent()) {
checkReadOnly(methodName, currentGlossary, "delete");
}
if (isPurge) {
// if this is a not a purge then check there are no relationships before deleting,
// otherwise the deletion could remove all anchored entities.
if (genericHandler.isBeanIsolated(userId,
guid,
OpenMetadataAPIMapper.GLOSSARY_TYPE_NAME,
methodName)) {

issueDelete = true;
} else {
// if this is a not a purge then check there are no relationships before deleting,
// otherwise the deletion could remove all anchored entities.
if (genericHandler.isBeanIsolated(userId,
guid,
OpenMetadataAPIMapper.GLOSSARY_TYPE_NAME,
methodName)) {

issueDelete = true;
} else{
throw new EntityNotDeletedException(SubjectAreaErrorCode.GLOSSARY_CONTENT_PREVENTED_DELETE.getMessageDefinition(guid),
className,
methodName,
guid);
}
throw new EntityNotDeletedException(SubjectAreaErrorCode.GLOSSARY_CONTENT_PREVENTED_DELETE.getMessageDefinition(guid),
className,
methodName,
guid);
}

if (issueDelete) {
genericHandler.deleteBeanInRepository(userId,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,77 +473,6 @@ protected void setUniqueQualifiedNameIfBlank(Node node) {
node.setQualifiedName(node.getName() + "@" + UUID.randomUUID().toString());
}
}
/**
* return whether the Category matches the search criteria
*
* @param category category to use for match
* @param searchCriteria criteria to use for match
* @return boolean indicating whether the category matches the search criteria
*/
protected boolean categoryMatchSearchCriteria(Category category, String searchCriteria, boolean exactValue, boolean ignoreCase) {
boolean isMatch = false;
if (searchCriteria == null) return true;
final String name = category.getName();
final String description = category.getDescription();
final String qualifiedName = category.getQualifiedName();
final String sanitizedSearchCriteria = sanitiseFindRequest(searchCriteria, exactValue, ignoreCase);

if (name != null && name.matches(sanitizedSearchCriteria)) {
isMatch = true;
}
if (description != null && description.matches(sanitizedSearchCriteria)) {
isMatch = true;
}
if (qualifiedName != null && qualifiedName.matches(sanitizedSearchCriteria)) {
isMatch = true;
}
return isMatch;
}
/**
* return whether the Term matches the search criteria
*
* @param term term to use for match
* @param searchCriteria criteria to use for match
* @param exactValue a boolean, which when set means that only exact matches will be returned, otherwise matches that start with the search criteria will be returned.
* @param ignoreCase a boolean, which when set means that case will be ignored, if not set that case will be respected
* @return boolean indicating whether the term matches the search criteria
*/
protected boolean termMatchSearchCriteria(Term term, String searchCriteria, boolean exactValue, boolean ignoreCase) {
if (searchCriteria == null) return true;
boolean isMatch = false;
final String name = term.getName();
final String description = term.getDescription();
final String qualifiedName = term.getQualifiedName();
final String abbreviation = term.getAbbreviation();
final String examples = term.getExamples();
final String usage = term.getUsage();
FindRequest findRequest = new FindRequest();
findRequest.setSearchCriteria(searchCriteria);
FindRequest sanitisedFindRequest = sanitiseFindRequest(findRequest, exactValue, ignoreCase);
String sanitizedSearchCriteria = sanitisedFindRequest.getSearchCriteria();

if (name != null && name.matches(sanitizedSearchCriteria)) {
isMatch = true;
}
if (description != null && description.matches(sanitizedSearchCriteria)) {
isMatch = true;
}
if (qualifiedName != null && qualifiedName.matches(sanitizedSearchCriteria)) {
isMatch = true;
}
if (abbreviation != null && abbreviation.matches(sanitizedSearchCriteria)) {
isMatch = true;
}
if (examples != null && examples.matches(sanitizedSearchCriteria)) {
isMatch = true;
}
if (usage != null && usage.matches(sanitizedSearchCriteria)) {
isMatch = true;
}
return isMatch;
}

/**
* Check whether the node is readonly and throw and exception if it is
* @param methodName calling methodName
Expand Down
Loading

0 comments on commit 30f9595

Please sign in to comment.