Skip to content

Commit

Permalink
odpi#5399 delete nodes using generic handler
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 5, 2021
1 parent cc06e36 commit 33983e8
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,24 @@ public SubjectAreaOMASAPIResponse<Category> deleteCategory(String userId, String
final String methodName = "deleteCategory";
SubjectAreaOMASAPIResponse<Category> response = new SubjectAreaOMASAPIResponse<>();


try {
response = getCategoryByGuid(userId, guid);
if (response.head().isPresent()) {
Category categoryToBeDeleted = response.head().get();
checkReadOnly(methodName, categoryToBeDeleted, "delete");
}
if (isPurge) {
oMRSAPIHelper.callOMRSPurgeEntity(methodName, userId, CATEGORY_TYPE_NAME, guid);
} else {
response = getCategoryByGuid(userId, guid);
if (response.head().isPresent()) {
Category currentCategory = response.head().get();
checkReadOnly(methodName, currentCategory, "delete");
}
oMRSAPIHelper.callOMRSDeleteEntity(methodName, userId, CATEGORY_TYPE_NAME, guid);
genericHandler.deleteBeanInRepository(userId,
null,
null,
guid,
"guid",
OpenMetadataAPIMapper.GLOSSARY_CATEGORY_TYPE_GUID,
OpenMetadataAPIMapper.GLOSSARY_CATEGORY_TYPE_NAME,
null,
methodName);
}
} catch (SubjectAreaCheckedException | PropertyServerException | UserNotAuthorizedException e) {
response.setExceptionInfo(e, className);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.odpi.openmetadata.frameworks.connectors.ffdc.PropertyServerException;
import org.odpi.openmetadata.frameworks.connectors.ffdc.UserNotAuthorizedException;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityProxy;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProperties;
import org.odpi.openmetadata.commonservices.generichandlers.*;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryHelper;
Expand Down Expand Up @@ -353,28 +354,40 @@ private void updateAttributes(Glossary oldGlossary, Glossary newGlossary) {
public SubjectAreaOMASAPIResponse<Glossary> deleteGlossary(String userId, String guid, Boolean isPurge) {
final String methodName = "deleteGlossary";
SubjectAreaOMASAPIResponse<Glossary> response = new SubjectAreaOMASAPIResponse<>();
boolean issueDelete = false;
try {
response = getGlossaryByGuid(userId, guid);
Glossary currentGlossary = response.head().get();
if (response.head().isPresent()) {
checkReadOnly(methodName, currentGlossary, "delete");
}
if (isPurge) {
// TODO check whether whether the deleted glossary is not readonly prior to attempting a purge
oMRSAPIHelper.callOMRSPurgeEntity(methodName, userId, GLOSSARY_TYPE_NAME, guid);
issueDelete = true;
} else {
response = getGlossaryByGuid(userId, guid);
Glossary currentGlossary = response.head().get();
if (response.head().isPresent()) {
checkReadOnly(methodName, currentGlossary, "delete");
}
// if this is a not a purge then attempt to get terms and categories, as we should not delete if there are any
// if this is a not a purge then attempt to get all term and category relationships (these may or may not be anchored depending how they were created).
List<String> relationshipTypeNames = Arrays.asList(TERM_ANCHOR_RELATIONSHIP_NAME, CATEGORY_ANCHOR_RELATIONSHIP_NAME);
if (oMRSAPIHelper.isEmptyContent(relationshipTypeNames, userId, guid, GLOSSARY_TYPE_NAME, methodName)) {
oMRSAPIHelper.callOMRSDeleteEntity(methodName, userId, GLOSSARY_TYPE_NAME, guid);
issueDelete = true;
} else {
throw new EntityNotDeletedException(SubjectAreaErrorCode.GLOSSARY_CONTENT_PREVENTED_DELETE.getMessageDefinition(guid),
className,
methodName,
guid);
}
}
} catch (SubjectAreaCheckedException | PropertyServerException | UserNotAuthorizedException e) {
if (issueDelete) {
genericHandler.deleteBeanInRepository(userId,
null,
null,
guid,
"guid",
OpenMetadataAPIMapper.GLOSSARY_TYPE_GUID, // true for sub types
OpenMetadataAPIMapper.GLOSSARY_TYPE_NAME, // true for sub types
null,
null,
methodName);
}
} catch (SubjectAreaCheckedException | PropertyServerException | UserNotAuthorizedException | InvalidParameterException e) {
response.setExceptionInfo(e, className);
}
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ protected <T extends Node>List<T> findNodes(String userId,
}
invalidParameterHandler.validatePaging(findRequest.getStartingFrom(), findRequest.getPageSize(), methodName);
if (findRequest.getSearchCriteria() == null) {
// entityDetails = oMRSAPIHelper.getEntitiesByType(methodName, userId, typeEntityName, findRequest);
entityDetails = genericHandler.getEntitiesByType(userId,
typeEntityGuid,
typeEntityName,
Expand All @@ -207,8 +206,6 @@ protected <T extends Node>List<T> findNodes(String userId,
methodName);
} else {
FindRequest sanitisedFindRequest = sanitiseFindRequest(findRequest, exactValue, ignoreCase);
// entityDetails = oMRSAPIHelper.findEntitiesByPropertyValue(methodName, userId, typeEntityName, sanitisedFindRequest);

entityDetails = genericHandler.findEntities(userId,
sanitisedFindRequest.getSearchCriteria(),
"searchCriteria",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,17 +637,26 @@ public SubjectAreaOMASAPIResponse<Term> deleteTerm(String userId, String guid, B
final String methodName = "deleteTerm";
SubjectAreaOMASAPIResponse<Term> response = new SubjectAreaOMASAPIResponse<>();
try {
if (response.head().isPresent()) {
Term termToBeDeleted = response.head().get();
checkReadOnly(methodName, termToBeDeleted, "delete");
}
if (isPurge) {
oMRSAPIHelper.callOMRSPurgeEntity(methodName, userId, TERM_TYPE_NAME, guid);
} else {
response = getTermByGuid(userId, guid);
if (response.head().isPresent()) {
Term currentTerm = response.head().get();
checkReadOnly(methodName, currentTerm, "delete");
}
oMRSAPIHelper.callOMRSDeleteEntity(methodName, userId, TERM_TYPE_NAME, guid);
genericHandler.deleteBeanInRepository(userId,
null,
null,
guid,
"guid",
OpenMetadataAPIMapper.GLOSSARY_TERM_TYPE_GUID,
OpenMetadataAPIMapper.GLOSSARY_TERM_TYPE_NAME,
null,
null,
methodName);
}
} catch (SubjectAreaCheckedException | PropertyServerException | UserNotAuthorizedException e) {

} catch (SubjectAreaCheckedException | PropertyServerException | UserNotAuthorizedException | InvalidParameterException e ) {
response.setExceptionInfo(e, className);
}
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@ private boolean visibleToUserThroughRelationship(String userId,
* @param methodName calling method
* @return anchorGUID or null
*/
String getAnchorGUIDFromAnchorsClassification(EntityDetail connectToEntity,
public String getAnchorGUIDFromAnchorsClassification(EntityDetail connectToEntity,
String methodName)
{
/*
Expand Down Expand Up @@ -5785,7 +5785,7 @@ private void archiveBeanInRepository(String userId,


/**
* Remove any entity if it is anchored to the anchor entity
* Remove an entity if it is anchored to the anchor entity
*
* @param anchorEntity entity anchor to match against
* @param potentialAnchoredEntity entity to validate
Expand All @@ -5794,7 +5794,7 @@ private void archiveBeanInRepository(String userId,
* @throws PropertyServerException problem in the repository services
* @throws UserNotAuthorizedException calling user is not authorize to issue this request
*/
private void deleteAnchoredEntity(EntityDetail anchorEntity,
public void deleteAnchoredEntity(EntityDetail anchorEntity,
EntityProxy potentialAnchoredEntity,
String methodName) throws InvalidParameterException,
PropertyServerException,
Expand Down Expand Up @@ -6010,7 +6010,7 @@ public void deleteBeanInRepository(String userId,
* @throws PropertyServerException there is a problem removing the properties from the repository.
* @throws UserNotAuthorizedException the requesting user is not authorized to issue this request.
*/
private void deleteBeanInRepository(String userId,
public void deleteBeanInRepository(String userId,
String externalSourceGUID,
String externalSourceName,
String entityGUID,
Expand Down

0 comments on commit 33983e8

Please sign in to comment.