| Quintiq file version 2.0 | 
| #parent: #root | 
| Method SynchronizeEntities (Lib3DS_QueryParameters_Type type) as owning Lib3DS_Entities | 
| { | 
|   TextBody: | 
|   [* | 
|     newentities := construct( Lib3DS_Entities ); | 
|      | 
|     path := ''; | 
|     if( type.Kind() = Lib3DS_EntityKind::Object() ) | 
|     { | 
|       path := path + 'bus'; | 
|     } | 
|     else if( type.Kind() = Lib3DS_EntityKind::Relation() ) | 
|     { | 
|       path := path + 'rel'; | 
|     } | 
|      | 
|     fields := construct( Strings ); | 
|      | 
|     // Type filter | 
|     fields.Add( 'type=' + URL::Encode( type.Name() ) ); | 
|      | 
|     // Basic attributes | 
|     fields.Add( 'select=id' ); | 
|     fields.Add( 'select=physicalid' ); | 
|     fields.Add( 'select=name' ); | 
|     fields.Add( 'select=type' ); | 
|      | 
|     // Extensions | 
|     fields.Add( 'select=interface' ); | 
|      | 
|     // Paths | 
|     fields.Add( 'select=paths.path.id' ); | 
|     fields.Add( 'select=paths.path.type' ); | 
|     fields.Add( 'select=paths.path.value' ); | 
|     fields.Add( 'select=paths.path.attribute%5bRoleSemantics%5d' ); | 
|      | 
|     // PLM Name attribute is always loaded (with different attr name for Object or Relation) | 
|     plmnameattr := ifexpr( type.Kind() = Lib3DS_EntityKind::Object(), | 
|                            Lib3DS_Object::PLM_NAME_ATTRIBUTE(), | 
|                            Lib3DS_Relation::PLM_NAME_ATTRIBUTE() ); | 
|     plmnameattrUrl := URL::Encode( plmnameattr ); | 
|     fields.Add( 'select=attribute%5b' + plmnameattrUrl + '%5d.type' ); | 
|     fields.Add( 'select=attribute%5b' + plmnameattrUrl + '%5d.value' ); | 
|      | 
|     // Attributes | 
|     traverse( type, Attribute, attr ) | 
|     { | 
|       attrNameUrl := URL::Encode( attr.Name() ); | 
|       fields.Add( 'select=attribute%5b' + attrNameUrl + '%5d.type' ); | 
|       fields.Add( 'select=attribute%5b' + attrNameUrl + '%5d.value' ); | 
|     } | 
|      | 
|     // For relation objects, from and to entities | 
|     if( type.Kind() = Lib3DS_EntityKind::Relation() ) | 
|     { | 
|       fields.Add( 'select=from.id' ); | 
|       fields.Add( 'select=to.id' ); | 
|       fields.Add( 'select=torel.id' ); | 
|     } | 
|      | 
|     // Attributes specific for business objects | 
|     if( type.Kind() = Lib3DS_EntityKind::Object() ) | 
|     { | 
|       fields.Add( 'select=revision' ); | 
|     } | 
|      | 
|     querystring := fields.ToString( '&' ); | 
|     path := path + '?' + querystring; | 
|      | 
|     nvtrequest := LibInt_MessageAccessor::CreateEmptyMessage(); | 
|     LibInt_MessageAccessor::SetHeaderProperty( nvtrequest, '_QI.ContentType', 'RAW' ); | 
|     LibInt_MessageAccessor::SetHeaderProperty( nvtrequest, 'HttpEndpointMethod', 'GET' ); | 
|     LibInt_MessageAccessor::SetHeaderProperty( nvtrequest, 'HttpEndpointPath', path ); | 
|     LibInt_MessageAccessor::SetHeaderProperty( nvtrequest, 'HTTPHeader.Accept', 'application/json' ); | 
|      | 
|     nvtresponse := LibInt_IntegratorProxy::SyncNvtRequest( this.Root().IntegratorID(), '', nvtrequest ); | 
|     response := LibInt_MessageAccessor::GetBodyValueAsString( nvtresponse ); | 
|      | 
|     jsonresponse := JSON::Parse( response ); | 
|      | 
|     if( not isnull( jsonresponse ) ) | 
|     { | 
|       oldentities := selectset( Lib3DS_ClassType::FindClassType( type.Name() ), | 
|                                 AllSubTypes.SubType.Entities, | 
|                                 entity, | 
|                                 entity.Kind() = type.Kind() ); | 
|       newentities := this.Root().ParseEntityQuery( type.Kind(), jsonresponse ); | 
|       deletedentities := oldentities.Difference( newentities ); | 
|       Lib3DS_Entity::Delete( deletedentities ); | 
|     } | 
|      | 
|     return &newentities; | 
|   *] | 
|   InterfaceProperties { Accessibility: 'Module' } | 
| } |