CMDBuild Forum

Unable to deactivate attribute in inherited class through REST API

Hi there,

I’m preparing CMDBuild deployment and I would like to use REST API to configure all changes/customizations in default Ready2Use model - so I need to prepare script which can be replayed any time, easily maintained, useful for documentation, … I’ve started to play with REST API v3 but I found strange thing, probably issue, when I’m trying to deactivate inherited attribute in child class. Through CMDBuild Admin module it is possible. But with REST I’m getting error:

“cannot alter type of attr “TestClass2”.TestAttribute1: attribute is inherited from parent class”

My scenario:

  • new class TestClass1 created as Superclass
  • new string attribute TestAttribute1 created for TestClass1
  • new class TestClass2 created as child of TestClass1

As this is working through CMDBuild Admin module I would expect that it should work also through REST. Is this an issue? Or am I doing something wrong?

Below are more details.

Thanks

Rasto

Through PowerShell two classes prepared with attribute in parent class:

$RootUrl = "http://hostname:port/cmdbuild/services/rest/v3"

$RESTResult = Invoke-RestMethod `
    -Headers @{ "CMDBuild-Authorization" = "$SessionID" } `
    -ContentType "application/json" `
    -Uri "$RootUrl/classes?scope=service" `
    -Method Post `
    -Body (@{
        name = "TestClass1"
        type = "standard"
        prototype = $true
    } | ConvertTo-Json)

$RESTResult = Invoke-RestMethod `
    -Headers @{ "CMDBuild-Authorization" = "$SessionID" } `
    -ContentType "application/json" `
    -Uri "$RootUrl/classes/TestClass1/attributes" `
    -Method Post `
    -Body (@{
        name = "TestAttribute1"
        description = "TestAttribute1"
        mode = "write"
        type = "string"
        maxLength = 50
    } | ConvertTo-Json)

$RESTResult = Invoke-RestMethod `
    -Headers @{ "CMDBuild-Authorization" = "$SessionID" } `
    -ContentType "application/json" `
    -Uri "$RootUrl/classes?scope=service" `
    -Method Post `
    -Body (@{
        name = "TestClass2"
        type = "standard"
        parent = "TestClass1"
    } | ConvertTo-Json)

When I try to disable TestAttribute1 in TestClass2

$RESTResult = Invoke-RestMethod `
    -Headers @{ "CMDBuild-Authorization" = "$SessionID" } `
    -ContentType "application/json" `
    -Uri "$RootUrl/classes/TestClass2/attributes/TestAttribute1" `
    -Method Put `
    -Body (@{
        name = "TestAttribute1"
        type = "string"
        active = $false
    } | ConvertTo-Json)

I’m getting error:
{
“success”: false,
“messages”: [
{
“level”: “ERROR”,
“show_user”: true,
“message”: “cannot alter type of attr “TestClass2”.TestAttribute1: attribute is inherited from parent class”,
“_message_translation”: “cannot alter type of attr “TestClass2”.TestAttribute1: attribute is inherited from parent class”
},
{
“level”: “ERROR”,
“show_user”: false,
“message”: “org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [SELECT _cm3_attribute_modify(?::regclass,?,?,?::jsonb)]; SQL state [P0001]; error code [0]; ERROR: CM: cannot alter type of attr “TestClass2”.TestAttribute1: attribute is inherited from parent class\n Where: PL/pgSQL function _cm3_attribute_modify(regclass,character varying,character varying,jsonb) line 27 at RAISE; nested exception is org.postgresql.util.PSQLException: ERROR: CM: cannot alter type of attr “TestClass2”.TestAttribute1: attribute is inherited from parent class\n Where: PL/pgSQL function _cm3_attribute_modify(regclass,character varying,character varying,jsonb) line 27 at RAISE, caused by: org.postgresql.util.PSQLException: ERROR: CM: cannot alter type of attr “TestClass2”.TestAttribute1: attribute is inherited from parent class\n Where: PL/pgSQL function _cm3_attribute_modify(regclass,character varying,character varying,jsonb) line 27 at RAISE”,
“_message_translation”: “org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [SELECT _cm3_attribute_modify(?::regclass,?,?,?::jsonb)]; SQL state [P0001]; error code [0]; ERROR: CM: cannot alter type of attr “TestClass2”.TestAttribute1: attribute is inherited from parent class\n Where: PL/pgSQL function _cm3_attribute_modify(regclass,character varying,character varying,jsonb) line 27 at RAISE; nested exception is org.postgresql.util.PSQLException: ERROR: CM: cannot alter type of attr “TestClass2”.TestAttribute1: attribute is inherited from parent class\n Where: PL/pgSQL function _cm3_attribute_modify(regclass,character varying,character varying,jsonb) line 27 at RAISE, caused by: org.postgresql.util.PSQLException: ERROR: CM: cannot alter type of attr “TestClass2”.TestAttribute1: attribute is inherited from parent class\n Where: PL/pgSQL function _cm3_attribute_modify(regclass,character varying,character varying,jsonb) line 27 at RAISE”
}
]
}