CMDBuild Forum

REST API update relation failed

Hello, I am trying update relation by REST v1, but failed.

I have a relation like this:

GET /cmdbuild/services/rest/v1/domains/UpdateTest/relations

{"data":[{"_destinationDescription":"C002","_sourceId":12557,"_type":"UpdateTest","_destinationId":12559,"_id":12615,"_destinationType":"LinkTest","_sourceType":"LinkTest","_sourceDescription":"C001"}],"meta":{"total":1}}

 

So I put one, API returns 500 Internal Server Error (Stack trace is attached below)

PUT /cmdbuild/services/rest/v1/domains/UpdateTest/relations/12615

{"_sourceId":12557,"_type":"UpdateTest","_destinationId":12559,"_id":12615,"_destinationType":"LinkTest","_sourceType":"LinkTest"}

 

I trace programs  commit b890716 on 2.3 branch, 

at org.cmdbuild.service.rest.v1.cxf.CxfRelations#update copying Relation instance to RelationDTO, it missed to copy relation Id but at DefaultDataAccessLogic#updateRelation, it uses dto's relationId, so it seems query is always failed.

 
Is this bugs? or something I missed?
 
Thank you for your help.
 

----

Error logs in tomcat:

WARN  2015-04-13 02:56:39 [org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper] javax.ws.rs.WebApplicationException: java.util.NoSuchElementException

    at org.cmdbuild.service.rest.v1.cxf.WebApplicationExceptionErrorHandler.propagate(WebApplicationExceptionErrorHandler.java:145)

    at org.cmdbuild.service.rest.v1.cxf.CxfRelations.update(CxfRelations.java:280)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at org.cmdbuild.common.reflect.AnnouncingInvocationHandler.invoke(AnnouncingInvocationHandler.java:31)

    at com.sun.proxy.$Proxy164.update(Unknown Source)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)

    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:132)

    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:120)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)

    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)

    at com.sun.proxy.$Proxy22.update(Unknown Source)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

        (snip)

    at java.lang.Thread.run(Thread.java:662)

Caused by: java.util.NoSuchElementException

    at java.util.AbstractList$Itr.next(AbstractList.java:350)

    at org.cmdbuild.dao.query.DBQueryResult.getOnlyRow(DBQueryResult.java:55)

    at org.cmdbuild.dao.query.ForwardingQueryResult.getOnlyRow(ForwardingQueryResult.java:38)

    at org.cmdbuild.services.localization.LocalizedQueryResult.getOnlyRow(LocalizedQueryResult.java:57)

    at org.cmdbuild.dao.view.user.UserQueryResult.getOnlyRow(UserQueryResult.java:86)

    at org.cmdbuild.logic.data.access.DefaultDataAccessLogic.updateRelation(DefaultDataAccessLogic.java:1057)

    at org.cmdbuild.service.rest.v1.cxf.CxfRelations.update(CxfRelations.java:278)

 

    ... 78 more

 

-----

org.cmdbuild.service.rest.v1.cxf.CxfRelations

public void update(final String domainId, final Long relationId, final Relation relation) {

        final CMDomain targetDomain = dataAccessLogic.findDomain(domainId);

        if (targetDomain == null) {

                errorHandler.domainNotFound(domainId);

        }

        try {

                final RelationDTO relationDTO = relationDto(targetDomain, relation);

                System.out.println("domainId = " + domainId); // DEBUG

                System.out.println("relationId = " + relationId); // DEBUG -> 12615 OK

                System.out.println("relationDTO =" + relationDTO.relationId); // DEBUG -> null NG?

                        

                dataAccessLogic.updateRelation(relationDTO);

        } catch (final Exception e) {

                errorHandler.propagate(e);

        }

}

private RelationDTO relationDto(final CMDomain domain, final Relation relation) {

        final RelationDTO relationDTO = new RelationDTO();

        relationDTO.domainName = domain.getName();

        relationDTO.master = "_1";

        relationDTO.addSourceCard(relation.getSource().getId(), relation.getSource().getType());

        relationDTO.addDestinationCard(relation.getDestination().getId(), relation.getDestination().getType());

        relationDTO.relationAttributeToValue = relation.getValues();

        return relationDTO;

 

}

-----

org.cmdbuild.logic.data.access.DefaultDataAccessLogic#updateRelation

 

(snip)

condition(attribute(domainAlias, ID_ATTRIBUTE), eq(relationDTO.relationId)), // <- relationDTO.relationId Always NULL

(snip)

 

I dumped DB query logs, 

2015-04-13 02:56:39 JST [3105-50] postgres@cmdbuild LOG:  execute <unnamed>: SELECT * FROM ( 

        SELECT

        "LinkTest"."Code" AS "LinkTest#Code", "LinkTest"."Description" AS "LinkTest#Description", "LinkTest"."Notes" AS "LinkTest#Notes", "LinkTest"."IdClass"::oid AS "_LinkTest_IdClass", "LinkTest"."Id" AS "_LinkTest_Id", "LinkTest"."User" AS "_LinkTest_User", "LinkTest"."BeginDate" AS "_LinkTest_BeginDate", "DST"."IdClass"::oid AS "_DST_IdClass", "DST"."Id" AS "_DST_Id", "DST"."User" AS "_DST_User", "DST"."BeginDate" AS "_DST_BeginDate", "DOM"."IdDomain"::oid AS "_DOM_IdDomain", "DOM"."_Src" AS "_DOM__Src", "DOM"."Id" AS "_DOM_Id", "DOM"."User" AS "_DOM_User", "DOM"."BeginDate" AS "_DOM_BeginDate", "DOM"."EndDate" AS "_DOM_EndDate", "DOM"."IdObj1" AS "_DOM_IdObj1", "DOM"."IdObj2" AS "_DOM_IdObj2" 

        FROM "LinkTest" AS "LinkTest" 

        JOIN (SELECT "Id", "IdDomain", $1 AS "_Src", "IdObj1", "IdObj2", "User", "BeginDate", NULL AS "EndDate" FROM ONLY "Map_UpdateTest" WHERE "Map_UpdateTest"."Status" = $2 UNION ALL SELECT "Id", "IdDomain", $3 AS "_Src", "IdObj2" AS "IdObj1", "IdObj1" AS "IdObj2", "User", "BeginDate", NULL AS "EndDate" FROM ONLY "Map_UpdateTest" WHERE "Map_UpdateTest"."Status" = $4) AS "DOM" ON "LinkTest"."Id"="DOM"."IdObj1" JOIN (SELECT "Id", "IdClass", "User", "BeginDate", NULL AS "EndDate", NULL AS "CurrentId" FROM ONLY "LinkTest" WHERE "LinkTest"."Status" = $5) AS "DST" ON "DOM"."IdObj2"="DST"."Id" 

        WHERE ( "LinkTest"."Id" = $6 AND   ( "DOM"."Id" = $7 AND   "DOM"."_Src" = $8 ) ) AND "LinkTest"."Status" = $9) AS main

        ORDER BY "_LinkTest_Id" 

        LIMIT ALL 

        OFFSET 0

 

2015-04-13 02:56:39 JST [3105-51] postgres@cmdbuild DETAIL:  parameters: $1 = '_1', $2 = 'A', $3 = '_2', $4 = 'A', $5 = 'A', $6 = '12557', $7 = NULL, $8 = '_1', $9 = 'A'

Dear Tomohisa,
 
we've investigated, found the issue and fix it. The fix will be availabe in the upcoming release.
 
Best regards.
 
-- CMDBuild Team
 
Previously Tomohisa wrote:

Hello, I am trying update relation by REST v1, but failed.

I have a relation like this:

GET /cmdbuild/services/rest/v1/domains/UpdateTest/relations

{"data":[{"_destinationDescription":"C002","_sourceId":12557,"_type":"UpdateTest","_destinationId":12559,"_id":12615,"_destinationType":"LinkTest","_sourceType":"LinkTest","_sourceDescription":"C001"}],"meta":{"total":1}}

 

So I put one, API returns 500 Internal Server Error (Stack trace is attached below)

PUT /cmdbuild/services/rest/v1/domains/UpdateTest/relations/12615

{"_sourceId":12557,"_type":"UpdateTest","_destinationId":12559,"_id":12615,"_destinationType":"LinkTest","_sourceType":"LinkTest"}

 

I trace programs  commit b890716 on 2.3 branch, 

at org.cmdbuild.service.rest.v1.cxf.CxfRelations#update copying Relation instance to RelationDTO, it missed to copy relation Id but at DefaultDataAccessLogic#updateRelation, it uses dto's relationId, so it seems query is always failed.

 
Is this bugs? or something I missed?
 
Thank you for your help.
 

----

Error logs in tomcat:

WARN  2015-04-13 02:56:39 [org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper] javax.ws.rs.WebApplicationException: java.util.NoSuchElementException

    at org.cmdbuild.service.rest.v1.cxf.WebApplicationExceptionErrorHandler.propagate(WebApplicationExceptionErrorHandler.java:145)

    at org.cmdbuild.service.rest.v1.cxf.CxfRelations.update(CxfRelations.java:280)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at org.cmdbuild.common.reflect.AnnouncingInvocationHandler.invoke(AnnouncingInvocationHandler.java:31)

    at com.sun.proxy.$Proxy164.update(Unknown Source)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)

    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:132)

    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:120)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)

    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)

    at com.sun.proxy.$Proxy22.update(Unknown Source)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

        (snip)

    at java.lang.Thread.run(Thread.java:662)

Caused by: java.util.NoSuchElementException

    at java.util.AbstractList$Itr.next(AbstractList.java:350)

    at org.cmdbuild.dao.query.DBQueryResult.getOnlyRow(DBQueryResult.java:55)

    at org.cmdbuild.dao.query.ForwardingQueryResult.getOnlyRow(ForwardingQueryResult.java:38)

    at org.cmdbuild.services.localization.LocalizedQueryResult.getOnlyRow(LocalizedQueryResult.java:57)

    at org.cmdbuild.dao.view.user.UserQueryResult.getOnlyRow(UserQueryResult.java:86)

    at org.cmdbuild.logic.data.access.DefaultDataAccessLogic.updateRelation(DefaultDataAccessLogic.java:1057)

    at org.cmdbuild.service.rest.v1.cxf.CxfRelations.update(CxfRelations.java:278)

 

    ... 78 more

 

-----

org.cmdbuild.service.rest.v1.cxf.CxfRelations

public void update(final String domainId, final Long relationId, final Relation relation) {

        final CMDomain targetDomain = dataAccessLogic.findDomain(domainId);

        if (targetDomain == null) {

                errorHandler.domainNotFound(domainId);

        }

        try {

                final RelationDTO relationDTO = relationDto(targetDomain, relation);

                System.out.println("domainId = " + domainId); // DEBUG

                System.out.println("relationId = " + relationId); // DEBUG -> 12615 OK

                System.out.println("relationDTO =" + relationDTO.relationId); // DEBUG -> null NG?

                        

                dataAccessLogic.updateRelation(relationDTO);

        } catch (final Exception e) {

                errorHandler.propagate(e);

        }

}

private RelationDTO relationDto(final CMDomain domain, final Relation relation) {

        final RelationDTO relationDTO = new RelationDTO();

        relationDTO.domainName = domain.getName();

        relationDTO.master = "_1";

        relationDTO.addSourceCard(relation.getSource().getId(), relation.getSource().getType());

        relationDTO.addDestinationCard(relation.getDestination().getId(), relation.getDestination().getType());

        relationDTO.relationAttributeToValue = relation.getValues();

        return relationDTO;

 

}

-----

org.cmdbuild.logic.data.access.DefaultDataAccessLogic#updateRelation

 

(snip)

condition(attribute(domainAlias, ID_ATTRIBUTE), eq(relationDTO.relationId)), // <- relationDTO.relationId Always NULL

(snip)

 

I dumped DB query logs, 

2015-04-13 02:56:39 JST [3105-50] postgres@cmdbuild LOG:  execute <unnamed>: SELECT * FROM ( 

        SELECT

        "LinkTest"."Code" AS "LinkTest#Code", "LinkTest"."Description" AS "LinkTest#Description", "LinkTest"."Notes" AS "LinkTest#Notes", "LinkTest"."IdClass"::oid AS "_LinkTest_IdClass", "LinkTest"."Id" AS "_LinkTest_Id", "LinkTest"."User" AS "_LinkTest_User", "LinkTest"."BeginDate" AS "_LinkTest_BeginDate", "DST"."IdClass"::oid AS "_DST_IdClass", "DST"."Id" AS "_DST_Id", "DST"."User" AS "_DST_User", "DST"."BeginDate" AS "_DST_BeginDate", "DOM"."IdDomain"::oid AS "_DOM_IdDomain", "DOM"."_Src" AS "_DOM__Src", "DOM"."Id" AS "_DOM_Id", "DOM"."User" AS "_DOM_User", "DOM"."BeginDate" AS "_DOM_BeginDate", "DOM"."EndDate" AS "_DOM_EndDate", "DOM"."IdObj1" AS "_DOM_IdObj1", "DOM"."IdObj2" AS "_DOM_IdObj2" 

        FROM "LinkTest" AS "LinkTest" 

        JOIN (SELECT "Id", "IdDomain", $1 AS "_Src", "IdObj1", "IdObj2", "User", "BeginDate", NULL AS "EndDate" FROM ONLY "Map_UpdateTest" WHERE "Map_UpdateTest"."Status" = $2 UNION ALL SELECT "Id", "IdDomain", $3 AS "_Src", "IdObj2" AS "IdObj1", "IdObj1" AS "IdObj2", "User", "BeginDate", NULL AS "EndDate" FROM ONLY "Map_UpdateTest" WHERE "Map_UpdateTest"."Status" = $4) AS "DOM" ON "LinkTest"."Id"="DOM"."IdObj1" JOIN (SELECT "Id", "IdClass", "User", "BeginDate", NULL AS "EndDate", NULL AS "CurrentId" FROM ONLY "LinkTest" WHERE "LinkTest"."Status" = $5) AS "DST" ON "DOM"."IdObj2"="DST"."Id" 

        WHERE ( "LinkTest"."Id" = $6 AND   ( "DOM"."Id" = $7 AND   "DOM"."_Src" = $8 ) ) AND "LinkTest"."Status" = $9) AS main

        ORDER BY "_LinkTest_Id" 

        LIMIT ALL 

        OFFSET 0

 

2015-04-13 02:56:39 JST [3105-51] postgres@cmdbuild DETAIL:  parameters: $1 = '_1', $2 = 'A', $3 = '_2', $4 = 'A', $5 = 'A', $6 = '12557', $7 = NULL, $8 = '_1', $9 = 'A'

 

Hi,

 

This issue is already fixed? I'm using cmdbuild-2.4.1

 

I have the same problem described.

 

Thanks,

David Santos

 

Previously Tecnoteca wrote:
Dear Tomohisa,
 
we've investigated, found the issue and fix it. The fix will be availabe in the upcoming release.
 
Best regards.
 
-- CMDBuild Team
 
Previously Tomohisa wrote:

Hello, I am trying update relation by REST v1, but failed.

I have a relation like this:

GET /cmdbuild/services/rest/v1/domains/UpdateTest/relations

{"data":[{"_destinationDescription":"C002","_sourceId":12557,"_type":"UpdateTest","_destinationId":12559,"_id":12615,"_destinationType":"LinkTest","_sourceType":"LinkTest","_sourceDescription":"C001"}],"meta":{"total":1}}

 

So I put one, API returns 500 Internal Server Error (Stack trace is attached below)

PUT /cmdbuild/services/rest/v1/domains/UpdateTest/relations/12615

{"_sourceId":12557,"_type":"UpdateTest","_destinationId":12559,"_id":12615,"_destinationType":"LinkTest","_sourceType":"LinkTest"}

 

I trace programs  commit b890716 on 2.3 branch, 

at org.cmdbuild.service.rest.v1.cxf.CxfRelations#update copying Relation instance to RelationDTO, it missed to copy relation Id but at DefaultDataAccessLogic#updateRelation, it uses dto's relationId, so it seems query is always failed.

 
Is this bugs? or something I missed?
 
Thank you for your help.
 

----

Error logs in tomcat:

WARN  2015-04-13 02:56:39 [org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper] javax.ws.rs.WebApplicationException: java.util.NoSuchElementException

    at org.cmdbuild.service.rest.v1.cxf.WebApplicationExceptionErrorHandler.propagate(WebApplicationExceptionErrorHandler.java:145)

    at org.cmdbuild.service.rest.v1.cxf.CxfRelations.update(CxfRelations.java:280)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at org.cmdbuild.common.reflect.AnnouncingInvocationHandler.invoke(AnnouncingInvocationHandler.java:31)

    at com.sun.proxy.$Proxy164.update(Unknown Source)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)

    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:132)

    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:120)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)

    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)

    at com.sun.proxy.$Proxy22.update(Unknown Source)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

        (snip)

    at java.lang.Thread.run(Thread.java:662)

Caused by: java.util.NoSuchElementException

    at java.util.AbstractList$Itr.next(AbstractList.java:350)

    at org.cmdbuild.dao.query.DBQueryResult.getOnlyRow(DBQueryResult.java:55)

    at org.cmdbuild.dao.query.ForwardingQueryResult.getOnlyRow(ForwardingQueryResult.java:38)

    at org.cmdbuild.services.localization.LocalizedQueryResult.getOnlyRow(LocalizedQueryResult.java:57)

    at org.cmdbuild.dao.view.user.UserQueryResult.getOnlyRow(UserQueryResult.java:86)

    at org.cmdbuild.logic.data.access.DefaultDataAccessLogic.updateRelation(DefaultDataAccessLogic.java:1057)

    at org.cmdbuild.service.rest.v1.cxf.CxfRelations.update(CxfRelations.java:278)

 

    ... 78 more

 

-----

org.cmdbuild.service.rest.v1.cxf.CxfRelations

public void update(final String domainId, final Long relationId, final Relation relation) {

        final CMDomain targetDomain = dataAccessLogic.findDomain(domainId);

        if (targetDomain == null) {

                errorHandler.domainNotFound(domainId);

        }

        try {

                final RelationDTO relationDTO = relationDto(targetDomain, relation);

                System.out.println("domainId = " + domainId); // DEBUG

                System.out.println("relationId = " + relationId); // DEBUG -> 12615 OK

                System.out.println("relationDTO =" + relationDTO.relationId); // DEBUG -> null NG?

                        

                dataAccessLogic.updateRelation(relationDTO);

        } catch (final Exception e) {

                errorHandler.propagate(e);

        }

}

private RelationDTO relationDto(final CMDomain domain, final Relation relation) {

        final RelationDTO relationDTO = new RelationDTO();

        relationDTO.domainName = domain.getName();

        relationDTO.master = "_1";

        relationDTO.addSourceCard(relation.getSource().getId(), relation.getSource().getType());

        relationDTO.addDestinationCard(relation.getDestination().getId(), relation.getDestination().getType());

        relationDTO.relationAttributeToValue = relation.getValues();

        return relationDTO;

 

}

-----

org.cmdbuild.logic.data.access.DefaultDataAccessLogic#updateRelation

 

(snip)

condition(attribute(domainAlias, ID_ATTRIBUTE), eq(relationDTO.relationId)), // <- relationDTO.relationId Always NULL

(snip)

 

I dumped DB query logs, 

2015-04-13 02:56:39 JST [3105-50] postgres@cmdbuild LOG:  execute <unnamed>: SELECT * FROM ( 

        SELECT

        "LinkTest"."Code" AS "LinkTest#Code", "LinkTest"."Description" AS "LinkTest#Description", "LinkTest"."Notes" AS "LinkTest#Notes", "LinkTest"."IdClass"::oid AS "_LinkTest_IdClass", "LinkTest"."Id" AS "_LinkTest_Id", "LinkTest"."User" AS "_LinkTest_User", "LinkTest"."BeginDate" AS "_LinkTest_BeginDate", "DST"."IdClass"::oid AS "_DST_IdClass", "DST"."Id" AS "_DST_Id", "DST"."User" AS "_DST_User", "DST"."BeginDate" AS "_DST_BeginDate", "DOM"."IdDomain"::oid AS "_DOM_IdDomain", "DOM"."_Src" AS "_DOM__Src", "DOM"."Id" AS "_DOM_Id", "DOM"."User" AS "_DOM_User", "DOM"."BeginDate" AS "_DOM_BeginDate", "DOM"."EndDate" AS "_DOM_EndDate", "DOM"."IdObj1" AS "_DOM_IdObj1", "DOM"."IdObj2" AS "_DOM_IdObj2" 

        FROM "LinkTest" AS "LinkTest" 

        JOIN (SELECT "Id", "IdDomain", $1 AS "_Src", "IdObj1", "IdObj2", "User", "BeginDate", NULL AS "EndDate" FROM ONLY "Map_UpdateTest" WHERE "Map_UpdateTest"."Status" = $2 UNION ALL SELECT "Id", "IdDomain", $3 AS "_Src", "IdObj2" AS "IdObj1", "IdObj1" AS "IdObj2", "User", "BeginDate", NULL AS "EndDate" FROM ONLY "Map_UpdateTest" WHERE "Map_UpdateTest"."Status" = $4) AS "DOM" ON "LinkTest"."Id"="DOM"."IdObj1" JOIN (SELECT "Id", "IdClass", "User", "BeginDate", NULL AS "EndDate", NULL AS "CurrentId" FROM ONLY "LinkTest" WHERE "LinkTest"."Status" = $5) AS "DST" ON "DOM"."IdObj2"="DST"."Id" 

        WHERE ( "LinkTest"."Id" = $6 AND   ( "DOM"."Id" = $7 AND   "DOM"."_Src" = $8 ) ) AND "LinkTest"."Status" = $9) AS main

        ORDER BY "_LinkTest_Id" 

        LIMIT ALL 

        OFFSET 0

 

2015-04-13 02:56:39 JST [3105-51] postgres@cmdbuild DETAIL:  parameters: $1 = '_1', $2 = 'A', $3 = '_2', $4 = 'A', $5 = 'A', $6 = '12557', $7 = NULL, $8 = '_1', $9 = 'A'

 

 

Hi,

 

I was trying to update one relation but i always get an error via Rest and i notice that via SOAP this operation isn't provided. This indicates that even via Rest we are not able to perform this kind of operation?

 

Thanks,

David Santos

 

Previously Tecnoteca wrote:
Dear Tomohisa,
 
we've investigated, found the issue and fix it. The fix will be availabe in the upcoming release.
 
Best regards.
 
-- CMDBuild Team
 
Previously Tomohisa wrote:

Hello, I am trying update relation by REST v1, but failed.

I have a relation like this:

GET /cmdbuild/services/rest/v1/domains/UpdateTest/relations

{"data":[{"_destinationDescription":"C002","_sourceId":12557,"_type":"UpdateTest","_destinationId":12559,"_id":12615,"_destinationType":"LinkTest","_sourceType":"LinkTest","_sourceDescription":"C001"}],"meta":{"total":1}}

 

So I put one, API returns 500 Internal Server Error (Stack trace is attached below)

PUT /cmdbuild/services/rest/v1/domains/UpdateTest/relations/12615

{"_sourceId":12557,"_type":"UpdateTest","_destinationId":12559,"_id":12615,"_destinationType":"LinkTest","_sourceType":"LinkTest"}

 

I trace programs  commit b890716 on 2.3 branch, 

at org.cmdbuild.service.rest.v1.cxf.CxfRelations#update copying Relation instance to RelationDTO, it missed to copy relation Id but at DefaultDataAccessLogic#updateRelation, it uses dto's relationId, so it seems query is always failed.

 
Is this bugs? or something I missed?
 
Thank you for your help.
 

----

Error logs in tomcat:

WARN  2015-04-13 02:56:39 [org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper] javax.ws.rs.WebApplicationException: java.util.NoSuchElementException

    at org.cmdbuild.service.rest.v1.cxf.WebApplicationExceptionErrorHandler.propagate(WebApplicationExceptionErrorHandler.java:145)

    at org.cmdbuild.service.rest.v1.cxf.CxfRelations.update(CxfRelations.java:280)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at org.cmdbuild.common.reflect.AnnouncingInvocationHandler.invoke(AnnouncingInvocationHandler.java:31)

    at com.sun.proxy.$Proxy164.update(Unknown Source)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)

    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:132)

    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:120)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)

    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)

    at com.sun.proxy.$Proxy22.update(Unknown Source)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

        (snip)

    at java.lang.Thread.run(Thread.java:662)

Caused by: java.util.NoSuchElementException

    at java.util.AbstractList$Itr.next(AbstractList.java:350)

    at org.cmdbuild.dao.query.DBQueryResult.getOnlyRow(DBQueryResult.java:55)

    at org.cmdbuild.dao.query.ForwardingQueryResult.getOnlyRow(ForwardingQueryResult.java:38)

    at org.cmdbuild.services.localization.LocalizedQueryResult.getOnlyRow(LocalizedQueryResult.java:57)

    at org.cmdbuild.dao.view.user.UserQueryResult.getOnlyRow(UserQueryResult.java:86)

    at org.cmdbuild.logic.data.access.DefaultDataAccessLogic.updateRelation(DefaultDataAccessLogic.java:1057)

    at org.cmdbuild.service.rest.v1.cxf.CxfRelations.update(CxfRelations.java:278)

 

    ... 78 more

 

-----

org.cmdbuild.service.rest.v1.cxf.CxfRelations

public void update(final String domainId, final Long relationId, final Relation relation) {

        final CMDomain targetDomain = dataAccessLogic.findDomain(domainId);

        if (targetDomain == null) {

                errorHandler.domainNotFound(domainId);

        }

        try {

                final RelationDTO relationDTO = relationDto(targetDomain, relation);

                System.out.println("domainId = " + domainId); // DEBUG

                System.out.println("relationId = " + relationId); // DEBUG -> 12615 OK

                System.out.println("relationDTO =" + relationDTO.relationId); // DEBUG -> null NG?

                        

                dataAccessLogic.updateRelation(relationDTO);

        } catch (final Exception e) {

                errorHandler.propagate(e);

        }

}

private RelationDTO relationDto(final CMDomain domain, final Relation relation) {

        final RelationDTO relationDTO = new RelationDTO();

        relationDTO.domainName = domain.getName();

        relationDTO.master = "_1";

        relationDTO.addSourceCard(relation.getSource().getId(), relation.getSource().getType());

        relationDTO.addDestinationCard(relation.getDestination().getId(), relation.getDestination().getType());

        relationDTO.relationAttributeToValue = relation.getValues();

        return relationDTO;

 

}

-----

org.cmdbuild.logic.data.access.DefaultDataAccessLogic#updateRelation

 

(snip)

condition(attribute(domainAlias, ID_ATTRIBUTE), eq(relationDTO.relationId)), // <- relationDTO.relationId Always NULL

(snip)

 

I dumped DB query logs, 

2015-04-13 02:56:39 JST [3105-50] postgres@cmdbuild LOG:  execute <unnamed>: SELECT * FROM ( 

        SELECT

        "LinkTest"."Code" AS "LinkTest#Code", "LinkTest"."Description" AS "LinkTest#Description", "LinkTest"."Notes" AS "LinkTest#Notes", "LinkTest"."IdClass"::oid AS "_LinkTest_IdClass", "LinkTest"."Id" AS "_LinkTest_Id", "LinkTest"."User" AS "_LinkTest_User", "LinkTest"."BeginDate" AS "_LinkTest_BeginDate", "DST"."IdClass"::oid AS "_DST_IdClass", "DST"."Id" AS "_DST_Id", "DST"."User" AS "_DST_User", "DST"."BeginDate" AS "_DST_BeginDate", "DOM"."IdDomain"::oid AS "_DOM_IdDomain", "DOM"."_Src" AS "_DOM__Src", "DOM"."Id" AS "_DOM_Id", "DOM"."User" AS "_DOM_User", "DOM"."BeginDate" AS "_DOM_BeginDate", "DOM"."EndDate" AS "_DOM_EndDate", "DOM"."IdObj1" AS "_DOM_IdObj1", "DOM"."IdObj2" AS "_DOM_IdObj2" 

        FROM "LinkTest" AS "LinkTest" 

        JOIN (SELECT "Id", "IdDomain", $1 AS "_Src", "IdObj1", "IdObj2", "User", "BeginDate", NULL AS "EndDate" FROM ONLY "Map_UpdateTest" WHERE "Map_UpdateTest"."Status" = $2 UNION ALL SELECT "Id", "IdDomain", $3 AS "_Src", "IdObj2" AS "IdObj1", "IdObj1" AS "IdObj2", "User", "BeginDate", NULL AS "EndDate" FROM ONLY "Map_UpdateTest" WHERE "Map_UpdateTest"."Status" = $4) AS "DOM" ON "LinkTest"."Id"="DOM"."IdObj1" JOIN (SELECT "Id", "IdClass", "User", "BeginDate", NULL AS "EndDate", NULL AS "CurrentId" FROM ONLY "LinkTest" WHERE "LinkTest"."Status" = $5) AS "DST" ON "DOM"."IdObj2"="DST"."Id" 

        WHERE ( "LinkTest"."Id" = $6 AND   ( "DOM"."Id" = $7 AND   "DOM"."_Src" = $8 ) ) AND "LinkTest"."Status" = $9) AS main

        ORDER BY "_LinkTest_Id" 

        LIMIT ALL 

        OFFSET 0

 

2015-04-13 02:56:39 JST [3105-51] postgres@cmdbuild DETAIL:  parameters: $1 = '_1', $2 = 'A', $3 = '_2', $4 = 'A', $5 = 'A', $6 = '12557', $7 = NULL, $8 = '_1', $9 = 'A'

 

 

Dear David,
 
we are trying using the demo database without encountering the error. This is what we are doing:
 
$ curl "http://localhost:8080/cmdbuild/services/rest/v1/domains/Members/relations/?limit=1" -H "Content-Type: application/json" -H "CMDBuild-Authorization: $REST_SESSION_ID" | json_pp   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   258    0   258    0     0  10114      0 --:--:-- --:--:-- --:--:-- 10320
{
   "meta" : {
      "total" : 10,
      "positions" : {}
   },
   "data" : [
      {
         "_destinationDescription" : "Brown Robert",
         "_destinationType" : "Employee",
         "_sourceDescription" : "Office 03 - Legal Department",
         "_id" : 176,
         "_sourceType" : "Office",
         "_destinationId" : 124,
         "_sourceId" : 110,
         "_type" : "Members"
      }
   ]
}
 
and then
 
$ curl "http://localhost:8080/cmdbuild/services/rest/v1/domains/Members/relations/176" -H "Content-Type: application/json" -H "CMDBuild-Authorization: $REST_SESSION_ID" --data-binary '{"_sourceId":110,"_type":"Members","_destinationId":124,"_id":176,"_destinationType":"Employee","_sourceType":"Office"}' -X PUT -v
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> PUT /cmdbuild/services/rest/v1/domains/Members/relations/176 HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:8080
> Accept: */*
> Content-Type: application/json
> CMDBuild-Authorization: beidanmbup7srt7djv01sci3f5
> Content-Length: 119
* upload completely sent off: 119 out of 119 bytes
< HTTP/1.1 204 No Content
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< Date: Fri, 09 Sep 2016 07:55:35 GMT
* Connection #0 to host localhost left intact
 
As you can see we are trying with v1 but we have the same result (no error) on version v2. What are we doing different from you?
 
Best regards.
 
-- CMDBuild Team
 
Previously David wrote:

Hi,

 

This issue is already fixed? I'm using cmdbuild-2.4.1

 

I have the same problem described.

 

Thanks,

David Santos

 

Previously Tecnoteca wrote:
Dear Tomohisa,
 
we've investigated, found the issue and fix it. The fix will be availabe in the upcoming release.
 
Best regards.
 
-- CMDBuild Team
 
Previously Tomohisa wrote:

Hello, I am trying update relation by REST v1, but failed.

I have a relation like this:

GET /cmdbuild/services/rest/v1/domains/UpdateTest/relations

{"data":[{"_destinationDescription":"C002","_sourceId":12557,"_type":"UpdateTest","_destinationId":12559,"_id":12615,"_destinationType":"LinkTest","_sourceType":"LinkTest","_sourceDescription":"C001"}],"meta":{"total":1}}

 

So I put one, API returns 500 Internal Server Error (Stack trace is attached below)

PUT /cmdbuild/services/rest/v1/domains/UpdateTest/relations/12615

{"_sourceId":12557,"_type":"UpdateTest","_destinationId":12559,"_id":12615,"_destinationType":"LinkTest","_sourceType":"LinkTest"}

 

I trace programs  commit b890716 on 2.3 branch, 

at org.cmdbuild.service.rest.v1.cxf.CxfRelations#update copying Relation instance to RelationDTO, it missed to copy relation Id but at DefaultDataAccessLogic#updateRelation, it uses dto's relationId, so it seems query is always failed.

 
Is this bugs? or something I missed?
 
Thank you for your help.
 

----

Error logs in tomcat:

WARN  2015-04-13 02:56:39 [org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper] javax.ws.rs.WebApplicationException: java.util.NoSuchElementException

    at org.cmdbuild.service.rest.v1.cxf.WebApplicationExceptionErrorHandler.propagate(WebApplicationExceptionErrorHandler.java:145)

    at org.cmdbuild.service.rest.v1.cxf.CxfRelations.update(CxfRelations.java:280)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at org.cmdbuild.common.reflect.AnnouncingInvocationHandler.invoke(AnnouncingInvocationHandler.java:31)

    at com.sun.proxy.$Proxy164.update(Unknown Source)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)

    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:132)

    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:120)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)

    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)

    at com.sun.proxy.$Proxy22.update(Unknown Source)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

        (snip)

    at java.lang.Thread.run(Thread.java:662)

Caused by: java.util.NoSuchElementException

    at java.util.AbstractList$Itr.next(AbstractList.java:350)

    at org.cmdbuild.dao.query.DBQueryResult.getOnlyRow(DBQueryResult.java:55)

    at org.cmdbuild.dao.query.ForwardingQueryResult.getOnlyRow(ForwardingQueryResult.java:38)

    at org.cmdbuild.services.localization.LocalizedQueryResult.getOnlyRow(LocalizedQueryResult.java:57)

    at org.cmdbuild.dao.view.user.UserQueryResult.getOnlyRow(UserQueryResult.java:86)

    at org.cmdbuild.logic.data.access.DefaultDataAccessLogic.updateRelation(DefaultDataAccessLogic.java:1057)

    at org.cmdbuild.service.rest.v1.cxf.CxfRelations.update(CxfRelations.java:278)

 

    ... 78 more

 

-----

org.cmdbuild.service.rest.v1.cxf.CxfRelations

public void update(final String domainId, final Long relationId, final Relation relation) {

        final CMDomain targetDomain = dataAccessLogic.findDomain(domainId);

        if (targetDomain == null) {

                errorHandler.domainNotFound(domainId);

        }

        try {

                final RelationDTO relationDTO = relationDto(targetDomain, relation);

                System.out.println("domainId = " + domainId); // DEBUG

                System.out.println("relationId = " + relationId); // DEBUG -> 12615 OK

                System.out.println("relationDTO =" + relationDTO.relationId); // DEBUG -> null NG?

                        

                dataAccessLogic.updateRelation(relationDTO);

        } catch (final Exception e) {

                errorHandler.propagate(e);

        }

}

private RelationDTO relationDto(final CMDomain domain, final Relation relation) {

        final RelationDTO relationDTO = new RelationDTO();

        relationDTO.domainName = domain.getName();

        relationDTO.master = "_1";

        relationDTO.addSourceCard(relation.getSource().getId(), relation.getSource().getType());

        relationDTO.addDestinationCard(relation.getDestination().getId(), relation.getDestination().getType());

        relationDTO.relationAttributeToValue = relation.getValues();

        return relationDTO;

 

}

-----

org.cmdbuild.logic.data.access.DefaultDataAccessLogic#updateRelation

 

(snip)

condition(attribute(domainAlias, ID_ATTRIBUTE), eq(relationDTO.relationId)), // <- relationDTO.relationId Always NULL

(snip)

 

I dumped DB query logs, 

2015-04-13 02:56:39 JST [3105-50] postgres@cmdbuild LOG:  execute <unnamed>: SELECT * FROM ( 

        SELECT

        "LinkTest"."Code" AS "LinkTest#Code", "LinkTest"."Description" AS "LinkTest#Description", "LinkTest"."Notes" AS "LinkTest#Notes", "LinkTest"."IdClass"::oid AS "_LinkTest_IdClass", "LinkTest"."Id" AS "_LinkTest_Id", "LinkTest"."User" AS "_LinkTest_User", "LinkTest"."BeginDate" AS "_LinkTest_BeginDate", "DST"."IdClass"::oid AS "_DST_IdClass", "DST"."Id" AS "_DST_Id", "DST"."User" AS "_DST_User", "DST"."BeginDate" AS "_DST_BeginDate", "DOM"."IdDomain"::oid AS "_DOM_IdDomain", "DOM"."_Src" AS "_DOM__Src", "DOM"."Id" AS "_DOM_Id", "DOM"."User" AS "_DOM_User", "DOM"."BeginDate" AS "_DOM_BeginDate", "DOM"."EndDate" AS "_DOM_EndDate", "DOM"."IdObj1" AS "_DOM_IdObj1", "DOM"."IdObj2" AS "_DOM_IdObj2" 

        FROM "LinkTest" AS "LinkTest" 

        JOIN (SELECT "Id", "IdDomain", $1 AS "_Src", "IdObj1", "IdObj2", "User", "BeginDate", NULL AS "EndDate" FROM ONLY "Map_UpdateTest" WHERE "Map_UpdateTest"."Status" = $2 UNION ALL SELECT "Id", "IdDomain", $3 AS "_Src", "IdObj2" AS "IdObj1", "IdObj1" AS "IdObj2", "User", "BeginDate", NULL AS "EndDate" FROM ONLY "Map_UpdateTest" WHERE "Map_UpdateTest"."Status" = $4) AS "DOM" ON "LinkTest"."Id"="DOM"."IdObj1" JOIN (SELECT "Id", "IdClass", "User", "BeginDate", NULL AS "EndDate", NULL AS "CurrentId" FROM ONLY "LinkTest" WHERE "LinkTest"."Status" = $5) AS "DST" ON "DOM"."IdObj2"="DST"."Id" 

        WHERE ( "LinkTest"."Id" = $6 AND   ( "DOM"."Id" = $7 AND   "DOM"."_Src" = $8 ) ) AND "LinkTest"."Status" = $9) AS main

        ORDER BY "_LinkTest_Id" 

        LIMIT ALL 

        OFFSET 0

 

2015-04-13 02:56:39 JST [3105-51] postgres@cmdbuild DETAIL:  parameters: $1 = '_1', $2 = 'A', $3 = '_2', $4 = 'A', $5 = 'A', $6 = '12557', $7 = NULL, $8 = '_1', $9 = 'A'