odpi / egeria

Egeria core
https://egeria-project.org
Apache License 2.0
806 stars 260 forks source link

Failed to create Classification and map it to EntityDetail #4352

Closed Mirovan closed 3 years ago

Mirovan commented 3 years ago

I am try create some EntityDetail by my custom EntityDef and map to Classification.

There are my code:

        EntityDetail entityDetail = new EntityDetail();
        InstanceType instanceType = new InstanceType();
        instanceType.setTypeDefName("test_entitydef_type");
        entityDetail.setType(instanceType);

        //set classificationDef
        List<Classification> classifications = new ArrayList<>();
        Classification c = new Classification();
        c.setClassificationOriginGUID("uad00000-0000-00pa-rent-groupclass0");
        c.setName("ParentGroupClassification");
        classifications.add(c);

        entityDetail.setClassifications(classifications);
        //call to GraphRepository and create EntityDetail
        EntityDetail term = entityDetailService.create(entityDetail);

My ClassificationDef:

{
  "class": "ClassificationDef",
  "headerVersion": 1,
  "guid": "uad00000-0000-00pa-rent-groupclass0",
  "name": "ParentGroupClassification",
  "status": "ACTIVE_TYPEDEF",
  "version": 1,
  "versionName": "1.0",
  "category": "CLASSIFICATION_DEF",
  "description": "test descr",
  "origin": "bce3b0a0-662a-4f87-b8dc-844078a11a6e",
  "createdBy": "UADSYSTEM",
  "createTime": 1577886131090,
  "validInstanceStatusList": [
    "ACTIVE",
    "DELETED"
  ],
  "initialStatus": "ACTIVE",
  "validEntityDefs": [],
  "propagatable": false
}

If I create EntityDetail it is work perfectly, but if I set some ClassificationDef, I get this bug:

18:36:15.847 [https-jsse-nio-9443-exec-2] ERROR o.o.o.a.r.g.r.GraphOMRSClassificationMapper - mapInstanceAuditHeaderToVertex entity is missing a core attribute type or typeName
18:36:15.849 [https-jsse-nio-9443-exec-2] ERROR o.o.o.a.r.g.r.GraphOMRSMetadataStore - createEntityInStore Caught exception from entity mapper OMRS-GRAPH-REPOSITORY-400-014 The attempt to map a vertex and a classification failed because the properties could not be mapped for classification with name ParentGroupClassification in mapInstanceAuditHeaderToVertex method of class org.odpi.openmetadata.adapters.repositoryservices.graphrepository.repositoryconnector.GraphOMRSClassificationMapper to open metadata repository uad1

We are using Egeria 2.3. How I can solve this mistake?

Mirovan commented 3 years ago

When I try using default Egeria TypeDef I have same error:

        EntityDetail entityDetail = new EntityDetail();
        InstanceType instanceType = new InstanceType();
        instanceType.setTypeDefName("SoftwareServer");
        entityDetail.setType(instanceType);

        List<Classification> classifications = new ArrayList<>();
        Classification c = new Classification();
        c.setName("ApplicationServer");
        classifications.add(c);

        entityDetail.setClassifications(classifications);
        EntityDetail term = entityDetailService.create(entityDetail);
Mirovan commented 3 years ago

My entityDetailService:

    public EntityDetail create(EntityDetail entityDetail) {
        //get typedef
        TypeDef typeDef = typeDefService.getTypeDefByName(entityDetail.getType().getTypeDefName());
        String typeDefGUID = typeDef.getGUID();

        EntityCreateRequest createRequest = new EntityCreateRequest();
        createRequest.setEntityTypeGUID(typeDefGUID);
        createRequest.setInitialStatus(InstanceStatus.ACTIVE);
        createRequest.setInitialProperties(entityDetail.getProperties());
        createRequest.setInitialClassifications(entityDetail.getClassifications());
        EntityDetailResponse responseEntityDetail = null;

        try {
            //Call request
            responseEntityDetail = clientConnector.callPostRESTCall(
                    "addEntity",
                    EntityDetailResponse.class,
                    egeriaHelper.buildURL("/entity"),
                    createRequest
            );

        } catch (RESTServerException e) {
            log.warn(e.toString());
        }

        return Optional.ofNullable(responseEntityDetail.getEntity())
                .orElseThrow(() -> new RuntimeException(String.format("Ошибка создания сущности '%s'", entityDetail.toString())));
    }
grahamwallis commented 3 years ago

Hi @Mirovan - I think the problem is that although you are creating a Classification object it is not fully initialised with core properties.

I wasn't sure quite what you meant by 'create some EntityDetail ... and map to Classification'. The normally expected behaviour would, I think, be to create an entity and then associate it with a classification. There are a couple of things that I would recommend looking at:

1) When you create an entity in the repository (using metadataCollection.addEntity) you can supply the entity type GUID and a set of initial entity properties and initial entity classifications. That would save you having to create and initialise the entity and classification objects yourself.

2) The repository content helper provides helper methods, like getSkeletonClassification, which will do a lot of initialisation for you. The helper method will set up things like the type information (which from the error message you posted is why your classification is rejected by the repository), as well as the other core properties.

3) If you need to associate a classification with an existing entity, you could use the metadataCollection's classifyEntity method.

I hope this helps. All the best, Graham

Mirovan commented 3 years ago

@grahamwallis thank you!

I solve it with new request for Egeria API, I call method - /servers/{serverName}/open-metadata/repository-services/users/{userId}/instances/entity/{entityGUID}/classification/{classificationName}.

But now I have to request:

  1. create entity request
  2. create classification request

If it possible, I want make only one request, when I call GraphOMRSClassificationMapper method mapClassificationToVertex - there is some error. What wrong, I can't understand (

grahamwallis commented 3 years ago

Hi @Mirovan - Is there a reason that you cannot use either addEntity (with an initial classification) or for an existing entity, use classifyEntity?

Mirovan commented 3 years ago

Hi @grahamwallis ! Now my problem was solved.