Repository: odpi/egeria-connector-ibm-information-server
Issue: NPE when trying to get EntityDetail for rid that is not present in IGC

This is uncommon scenario but if asset is removed from IGC for some reson repoistory proxy should respond with Entitiy/Detail not found message instead NPE.

`2021-02-09 17:07:02.018 ERROR [http-nio-127.0.0.1-8080-exec-7] [o.o.o.f.a.i.RepositoryRESTServices] --- igc-proxy-edl9caddd5b-637d-4cb3-a16b-20bfaa301cc3 java.lang.NullPointerException returned message of null and stacktrace of java.lang.NullPointerException
at org.odpi.egeria.connectors.ibm.igc.repositoryconnector.mapping.entities.EntityMapping.setupEntityObj(EntityMapping.java:577)
at org.odpi.egeria.connectors.ibm.igc.repositoryconnector.mapping.entities.EntityMapping.getEntityDetail(EntityMapping.java:726)
at org.odpi.egeria.connectors.ibm.igc.repositoryconnector.IGCRepositoryHelper.getEntityDetailFromMapInstance(IGCRepositoryHelper.java:1283)
at org.odpi.egeria.connectors.ibm.igc.repositoryconnector.IGCRepositoryHelper.getEntityDetail(IGCRepositoryHelper.java:1320)
at org.odpi.egeria.connectors.ibm.igc.repositoryconnector.IGCOMRSMetadataCollection.getEntityDetail(IGCOMRSMetadataCollection.java:783)
at org.odpi.openmetadata.repositoryservices.localrepository.repositoryconnector.LocalOMRSMetadataCollection.getEntityDetail(LocalOMRSMetadataCollection.java:1784)
at org.odpi.openmetadata.repositoryservices.rest.server.OMRSRepositoryRESTServices.getEntityDetail(OMRSRepositoryRESTServices.java:1893)
at org.odpi.openmetadata.repositoryservices.rest.server.spring.LocalRepositoryServicesResource.getEntityDetail(LocalRepositoryServicesResource.java:694)`


Changed files:
igc-adapter/src/main/java/org/odpi/egeria/connectors/ibm/igc/repositoryconnector/mapping/entities/EntityMapping.java

diff --git a/igc-adapter/src/main/java/org/odpi/egeria/connectors/ibm/igc/repositoryconnector/mapping/entities/EntityMapping.java b/igc-adapter/src/main/java/org/odpi/egeria/connectors/ibm/igc/repositoryconnector/mapping/entities/EntityMapping.java
index 986026c0..d7805ae4 100644
--- a/igc-adapter/src/main/java/org/odpi/egeria/connectors/ibm/igc/repositoryconnector/mapping/entities/EntityMapping.java
+++ b/igc-adapter/src/main/java/org/odpi/egeria/connectors/ibm/igc/repositoryconnector/mapping/entities/EntityMapping.java
@@ -705,6 +705,7 @@ public abstract class EntityMapping extends InstanceMapping {
      */
     public static EntityDetail getEntityDetail(ObjectCache cache, EntityMappingInstance entityMap) throws RepositoryErrorException {
 
+        final String methodName = "getEntityDetail";
         EntityMapping mapping = entityMap.getMapping();
         IGCRestClient igcRestClient = entityMap.getRepositoryConnector().getIGCRestClient();
 
@@ -721,6 +722,17 @@ public abstract class EntityMapping extends InstanceMapping {
         entityMap.initializeEntityDetail();
 
         EntityDetail preliminary = entityMap.getOmrsDetail(cache);
+
+        if(entityMap.getIgcEntity() == null) {
+            // Igc entity was not found, raise exception providing as much details as possible
+            raiseRepositoryErrorException(IGCOMRSErrorCode.ENTITY_NOT_KNOWN,
+                    methodName,
+                    null,
+                    preliminary !=null ? preliminary.getGUID() : "",
+                    entityMap.getIgcEntityRid() !=null ? entityMap.getIgcEntityRid() : "",
+                    entityMap.getRepositoryConnector().getRepositoryName());
+        }
+
         if (preliminary != null) {
             // Then handle any generic mappings and classifications
             setupEntityObj(cache, entityMap, preliminary);