陈清红
2025-04-14 880f3c0257eeb8c37761d484258fdd102a369a19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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' }
}