-
Notifications
You must be signed in to change notification settings - Fork 617
/
Copy pathLowLevelServiceImpl.java
748 lines (679 loc) · 30.4 KB
/
LowLevelServiceImpl.java
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
package org.bimserver.webservices.impl;
/******************************************************************************
* Copyright (C) 2009-2019 BIMserver.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see {@literal<http://www.gnu.org/licenses/>}.
*****************************************************************************/
import java.util.ArrayList;
import java.util.List;
import org.bimserver.BimserverDatabaseException;
import org.bimserver.changes.AddAttributeChange;
import org.bimserver.changes.AddReferenceChange;
import org.bimserver.changes.CreateObjectChange;
import org.bimserver.changes.RemoveAllReferencesChange;
import org.bimserver.changes.RemoveAttributeChange;
import org.bimserver.changes.RemoveObjectChange;
import org.bimserver.changes.RemoveReferenceChange;
import org.bimserver.changes.SetAttributeChange;
import org.bimserver.changes.SetAttributeChangeAtIndex;
import org.bimserver.changes.SetReferenceChange;
import org.bimserver.changes.SetWrappedAttributeChange;
import org.bimserver.database.Database;
import org.bimserver.database.DatabaseSession;
import org.bimserver.database.OldQuery;
import org.bimserver.database.OldQuery.Deep;
import org.bimserver.database.OperationType;
import org.bimserver.database.actions.BimDatabaseAction;
import org.bimserver.database.actions.CommitTransactionDatabaseAction;
import org.bimserver.database.actions.CountDatabaseAction;
import org.bimserver.database.actions.GetDataObjectByGuidDatabaseAction;
import org.bimserver.database.actions.GetDataObjectByOidDatabaseAction;
import org.bimserver.database.actions.GetDataObjectsByTypeDatabaseAction;
import org.bimserver.database.actions.GetDataObjectsDatabaseAction;
import org.bimserver.emf.IdEObject;
import org.bimserver.interfaces.objects.SDataObject;
import org.bimserver.models.store.ConcreteRevision;
import org.bimserver.models.store.DataObject;
import org.bimserver.models.store.Project;
import org.bimserver.models.store.Revision;
import org.bimserver.shared.exceptions.ServerException;
import org.bimserver.shared.exceptions.UserException;
import org.bimserver.shared.interfaces.LowLevelInterface;
import org.bimserver.webservices.LongTransaction;
import org.bimserver.webservices.NoTransactionException;
import org.bimserver.webservices.ServiceMap;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LowLevelServiceImpl extends GenericServiceImpl implements LowLevelInterface {
private static final Logger LOGGER = LoggerFactory.getLogger(LowLevelServiceImpl.class);
public LowLevelServiceImpl(ServiceMap serviceMap) {
super(serviceMap);
}
@Override
public Long startTransaction(Long poid) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
int pid = -1;
int rid = -1;
long roid = -1;
try {
Project project = (Project) session.get(poid, OldQuery.getDefault());
if (project == null) {
throw new UserException("No project found with poid " + poid);
}
pid = project.getId();
if (project.getLastRevision() != null) {
Revision revision = project.getLastRevision();
ConcreteRevision lastConcreteRevision = revision.getLastConcreteRevision();
rid = lastConcreteRevision.getId();
roid = revision.getOid();
}
LongTransaction longTransaction = getBimServer().getLongTransactionManager().newLongTransaction(getBimServer().getMetaDataManager().getPackageMetaData(project.getSchema()), poid, pid, rid, roid);
return longTransaction.getTid();
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
@Override
public Long commitTransaction(Long tid, String comment, Boolean regenerateAllGeometry) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
try {
LongTransaction longTransaction = getBimServer().getLongTransactionManager().get(tid);
if (longTransaction == null) {
throw new UserException("No transaction with tid " + tid + " was found");
}
CommitTransactionDatabaseAction action = new CommitTransactionDatabaseAction(getBimServer(), session, getInternalAccessMethod(), getAuthorization(), longTransaction, comment, regenerateAllGeometry);
try {
session.executeAndCommitAction(action);
return action.getRevision().getOid();
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} finally {
session.close();
}
} catch (NoTransactionException e) {
LOGGER.error("", e);
}
return -1L;
}
@Override
public void abortTransaction(Long tid) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).close();
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void addStringAttribute(Long tid, Long oid, String attributeName, String value) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new AddAttributeChange(oid, attributeName, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void addIntegerAttribute(Long tid, Long oid, String attributeName, Integer value) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new AddAttributeChange(oid, attributeName, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void addDoubleAttribute(Long tid, Long oid, String attributeName, Double value) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new AddAttributeChange(oid, attributeName, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void setDoubleAttributes(Long tid, Long oid, String attributeName, List<Double> values) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetAttributeChange(oid, attributeName, values));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void setDoubleAttributeAtIndex(Long tid, Long oid, String attributeName, Integer index, Double value) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetAttributeChangeAtIndex(oid, attributeName, index, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void setBooleanAttributeAtIndex(Long tid, Long oid, String attributeName, Integer index, Boolean value) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetAttributeChangeAtIndex(oid, attributeName, index, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void setIntegerAttributes(Long tid, Long oid, String attributeName, List<Integer> values) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetAttributeChange(oid, attributeName, values));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void setIntegerAttributeAtIndex(Long tid, Long oid, String attributeName, Integer index, Integer value) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetAttributeChangeAtIndex(oid, attributeName, index, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void setLongAttributes(Long tid, Long oid, String attributeName, List<Long> values) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetAttributeChange(oid, attributeName, values));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void setBooleanAttributes(Long tid, Long oid, String attributeName, List<Boolean> values) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetAttributeChange(oid, attributeName, values));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void addBooleanAttribute(Long tid, Long oid, String attributeName, Boolean value) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new AddAttributeChange(oid, attributeName, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void addReference(Long tid, Long oid, String referenceName, Long referenceOid) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new AddReferenceChange(oid, referenceName, referenceOid));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public Long createObject(Long tid, String className, Boolean generateGuid) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
LongTransaction longTransaction = getBimServer().getLongTransactionManager().get(tid);
if (longTransaction == null) {
throw new UserException("No transaction with tid " + tid + " was found");
}
try {
EClass eClass = ((Database) getBimServer().getDatabase()).getEClass(longTransaction.getPackageMetaData().getEPackage().getName(), className);
Long oid = getBimServer().getDatabase().newOid(eClass);
CreateObjectChange createObject = new CreateObjectChange(className, oid, eClass, generateGuid);
longTransaction.add(createObject);
return oid;
} catch (BimserverDatabaseException e) {
throw new UserException("Unknown type: \"" + className + "\"");
}
} catch (Exception e) {
return handleException(e);
}
}
@Override
public void removeAttribute(Long tid, Long oid, String attributeName, Integer index) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new RemoveAttributeChange(oid, attributeName, index));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void removeObject(Long tid, Long oid) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new RemoveObjectChange(oid, getBimServer().getDatabase().getEClassForOid(oid)));
} catch (NoTransactionException e) {
handleException(e);
} catch (BimserverDatabaseException e) {
handleException(e);
}
}
@Override
public void removeReference(Long tid, Long oid, String referenceName, Integer index) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new RemoveReferenceChange(oid, referenceName, index));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void removeReferenceByOid(Long tid, Long oid, String referenceName, Long referencedOid) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new RemoveReferenceChange(oid, referenceName, referencedOid));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void removeAllReferences(Long tid, Long oid, String referenceName) throws ServerException, UserException {
requireAdminAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new RemoveAllReferencesChange(oid, referenceName));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void setStringAttribute(Long tid, Long oid, String attributeName, String value) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetAttributeChange(oid, attributeName, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void setStringAttributeAtIndex(Long tid, Long oid, String attributeName, Integer index, String value) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetAttributeChangeAtIndex(oid, attributeName, index, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void setWrappedStringAttribute(Long tid, Long oid, String attributeName, String type, String value)
throws ServerException, UserException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetWrappedAttributeChange(oid, attributeName, type, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public String getStringAttribute(Long tid, Long oid, String attributeName) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
return (String)getAttribute(tid, oid, attributeName);
}
@Override
public void setIntegerAttribute(Long tid, Long oid, String attributeName, Integer value) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetAttributeChange(oid, attributeName, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void setWrappedIntegerAttribute(Long tid, Long oid, String attributeName, String type, Integer value) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetWrappedAttributeChange(oid, attributeName, type, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void setByteArrayAttribute(Long tid, Long oid, String attributeName, Byte[] value) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetAttributeChange(oid, attributeName, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void setLongAttribute(Long tid, Long oid, String attributeName, Long value) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetAttributeChange(oid, attributeName, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void setLongAttributeAtIndex(Long tid, Long oid, String attributeName, Integer index,Long value) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetAttributeChangeAtIndex(oid, attributeName, index, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void setWrappedLongAttribute(Long tid, Long oid, String attributeName, String type, Long value) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetWrappedAttributeChange(oid, attributeName, type, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
public Integer getIntegerAttribute(Long tid, Long oid, String attributeName) throws ServerException ,UserException {
return (Integer)getAttribute(tid, oid, attributeName);
}
public Integer getIntegerAttributeAtIndex(Long tid, Long oid, String attributeName, Integer index) throws ServerException ,UserException {
return (Integer)getAttributeAtIndex(tid, oid, attributeName, index);
}
public Long getLongAttribute(Long tid, Long oid, String attributeName) throws ServerException ,UserException {
return (Long)getAttribute(tid, oid, attributeName);
}
public Long getLongAttributeAtIndex(Long tid, Long oid, String attributeName, Integer index) throws ServerException ,UserException {
return (Long)getAttributeAtIndex(tid, oid, attributeName, index);
}
@Override
public void setBooleanAttribute(Long tid, Long oid, String attributeName, Boolean value) throws UserException, ServerException {
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetAttributeChange(oid, attributeName, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void setWrappedBooleanAttribute(Long tid, Long oid, String attributeName, String type, Boolean value) throws UserException, ServerException {
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetWrappedAttributeChange(oid, attributeName, type, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public Boolean getBooleanAttribute(Long tid, Long oid, String attributeName) throws ServerException, UserException {
return (Boolean)getAttribute(tid, oid, attributeName);
}
@Override
public Boolean getBooleanAttributeAtIndex(Long tid, Long oid, String attributeName, Integer index) throws ServerException, UserException {
return (Boolean)getAttributeAtIndex(tid, oid, attributeName, index);
}
@Override
public void setDoubleAttribute(Long tid, Long oid, String attributeName, Double value) throws UserException, ServerException {
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetAttributeChange(oid, attributeName, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void setWrappedDoubleAttribute(Long tid, Long oid, String attributeName, String type, Double value) throws UserException, ServerException {
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetWrappedAttributeChange(oid, attributeName, type, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public Double getDoubleAttribute(Long tid, Long oid, String attributeName) throws ServerException, UserException {
return (Double)getAttribute(tid, oid, attributeName);
}
@Override
public Double getDoubleAttributeAtIndex(Long tid, Long oid, String attributeName, Integer index) throws ServerException, UserException {
return (Double)getAttributeAtIndex(tid, oid, attributeName, index);
}
@SuppressWarnings("unchecked")
@Override
public List<Double> getDoubleAttributes(Long tid, Long oid, String attributeName) throws ServerException, UserException {
return (List<Double>)getAttribute(tid, oid, attributeName);
}
@SuppressWarnings("unchecked")
public List<Boolean> getBooleanAttributes(Long tid, Long oid, String attributeName) throws ServerException ,UserException {
return (List<Boolean>)getAttribute(tid, oid, attributeName);
}
@Override
public byte[] getByteArrayAttribute(Long tid, Long oid, String attributeName) throws ServerException, UserException {
return (byte[])getAttribute(tid, oid, attributeName);
}
@SuppressWarnings("unchecked")
@Override
public List<byte[]> getByteArrayAttributes(Long tid, Long oid, String attributeName) throws ServerException, UserException {
return (List<byte[]>)getAttribute(tid, oid, attributeName);
}
@SuppressWarnings("unchecked")
@Override
public List<Integer> getIntegerAttributes(Long tid, Long oid, String attributeName) throws ServerException, UserException {
return (List<Integer>)getAttribute(tid, oid, attributeName);
}
@SuppressWarnings("unchecked")
@Override
public List<String> getStringAttributes(Long tid, Long oid, String attributeName) throws ServerException, UserException {
return (List<String>)getAttribute(tid, oid, attributeName);
}
private Object getAttribute(Long tid, Long oid, String attributeName) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
try {
LongTransaction transaction = getBimServer().getLongTransactionManager().get(tid);
EClass eClass = session.getEClassForOid(oid);
IdEObject object = session.get(eClass, oid, new OldQuery(transaction.getPackageMetaData(), transaction.getPid(), transaction.getRid(), transaction.getRoid(), Deep.NO));
if (object == null) {
throw new UserException("No object of type " + eClass.getName() + " with oid " + oid + " found");
}
EStructuralFeature eStructuralFeature = object.eClass().getEStructuralFeature(attributeName);
if (eStructuralFeature == null) {
throw new UserException(eClass.getName() + " does not have a field called " + attributeName);
}
Object eGet = object.eGet(eStructuralFeature);
if (eGet instanceof IdEObject) {
IdEObject refObject = (IdEObject)eGet;
return refObject.eGet(refObject.eClass().getEStructuralFeature("wrappedValue"));
}
return eGet;
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
private Object getAttributeAtIndex(Long tid, Long oid, String attributeName, int index) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
try {
LongTransaction transaction = getBimServer().getLongTransactionManager().get(tid);
EClass eClass = session.getEClassForOid(oid);
IdEObject object = session.get(eClass, oid, new OldQuery(transaction.getPackageMetaData(), transaction.getPid(), transaction.getRid(), transaction.getRoid(), Deep.NO));
if (object == null) {
throw new UserException("No object of type " + eClass.getName() + " with oid " + oid + " found");
}
Object eGet = object.eGet(object.eClass().getEStructuralFeature(attributeName));
if (eGet instanceof List) {
List<?> list = (List<?>)eGet;
return list.get(index);
}
return eGet;
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
@Override
public void setEnumAttribute(Long tid, Long oid, String attributeName, String value) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetAttributeChange(oid, attributeName, value));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public String getEnumAttribute(Long tid, Long oid, String attributeName) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
return getAttribute(tid, oid, attributeName).toString();
}
@Override
public void setReference(Long tid, Long oid, String referenceName, Long referenceOid) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetReferenceChange(oid, referenceName, referenceOid));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public Long getReference(Long tid, Long oid, String referenceName) throws ServerException, UserException {
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
try {
LongTransaction transaction = getBimServer().getLongTransactionManager().get(tid);
EClass eClass = session.getEClassForOid(oid);
IdEObject object = session.get(eClass, oid, new OldQuery(transaction.getPackageMetaData(), transaction.getPid(), transaction.getRid(), transaction.getRoid(), Deep.NO));
if (object == null) {
throw new UserException("No object of type " + eClass.getName() + " with oid " + oid + " found");
}
EStructuralFeature eStructuralFeature = object.eClass().getEStructuralFeature(referenceName);
if (eStructuralFeature == null) {
throw new UserException("No feature with name " + referenceName + " found on class " + object.eClass().getName());
}
IdEObject ref = (IdEObject) object.eGet(eStructuralFeature);
if (ref == null) {
return -1L;
}
return ref.getOid();
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
@SuppressWarnings("unchecked")
@Override
public List<Long> getReferences(Long tid, Long oid, String referenceName) throws ServerException, UserException {
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
try {
LongTransaction transaction = getBimServer().getLongTransactionManager().get(tid);
EClass eClass = session.getEClassForOid(oid);
IdEObject object = session.get(eClass, oid, new OldQuery(transaction.getPackageMetaData(), transaction.getPid(), transaction.getRid(), transaction.getRoid(), Deep.NO));
if (object == null) {
throw new UserException("No object of type " + eClass.getName() + " with oid " + oid + " found");
}
List<IdEObject> list = (List<IdEObject>) object.eGet(object.eClass().getEStructuralFeature(referenceName));
List<Long> oidList = new ArrayList<Long>();
for (IdEObject idEObject : list) {
oidList.add(idEObject.getOid());
}
return oidList;
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
@Override
public void unsetAttribute(Long tid, Long oid, String attributeName) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetAttributeChange(oid, attributeName, null));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public void unsetReference(Long tid, Long oid, String referenceName) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
getBimServer().getLongTransactionManager().get(tid).add(new SetReferenceChange(oid, referenceName, -1));
} catch (NoTransactionException e) {
handleException(e);
}
}
@Override
public List<SDataObject> getDataObjects(Long roid) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
try {
BimDatabaseAction<List<DataObject>> action = new GetDataObjectsDatabaseAction(session, getInternalAccessMethod(), getBimServer(), roid, getAuthorization());
return getBimServer().getSConverter().convertToSListDataObject(session.executeAndCommitAction(action));
} catch (BimserverDatabaseException e) {
handleException(e);
} finally {
session.close();
}
return null;
}
@Override
public SDataObject getDataObjectByGuid(Long roid, String guid) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
try {
BimDatabaseAction<DataObject> action = new GetDataObjectByGuidDatabaseAction(getBimServer(), session, getInternalAccessMethod(), roid, guid, getAuthorization());
SDataObject dataObject = getBimServer().getSConverter().convertToSObject(session.executeAndCommitAction(action));
return dataObject;
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
@Override
public List<SDataObject> getDataObjectsByType(Long roid, String packageName, String className, Boolean flat) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
BimDatabaseAction<List<DataObject>> action = new GetDataObjectsByTypeDatabaseAction(getBimServer(), session, getInternalAccessMethod(), roid, packageName, className, getAuthorization(), flat);
try {
return getBimServer().getSConverter().convertToSListDataObject(session.executeAndCommitAction(action));
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
@Override
public SDataObject getDataObjectByOid(Long roid, Long oid) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
try {
BimDatabaseAction<DataObject> action = new GetDataObjectByOidDatabaseAction(getBimServer(), session, getInternalAccessMethod(), roid, oid, getAuthorization());
SDataObject dataObject = getBimServer().getSConverter().convertToSObject(session.executeAndCommitAction(action));
return dataObject;
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
public Integer count(Long roid, String className) throws UserException ,ServerException {
requireAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
try {
CountDatabaseAction action = new CountDatabaseAction(getBimServer(), session, getInternalAccessMethod(), roid, className, getAuthorization());
return session.executeAndCommitAction(action);
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
}