28
28
import org .bimserver .ifc .BasicIfcModel ;
29
29
import org .bimserver .ifc .IfcModel ;
30
30
import org .bimserver .models .log .AccessMethod ;
31
- import org .bimserver .models .store .ConcreteRevision ;
32
- import org .bimserver .models .store .Project ;
33
- import org .bimserver .models .store .Revision ;
34
- import org .bimserver .models .store .StorePackage ;
35
- import org .bimserver .models .store .User ;
31
+ import org .bimserver .models .store .*;
36
32
import org .bimserver .plugins .IfcModelSet ;
37
33
import org .bimserver .plugins .ModelHelper ;
38
34
import org .bimserver .plugins .modelmerger .MergeException ;
39
35
import org .bimserver .shared .exceptions .UserException ;
40
36
import org .bimserver .webservices .authorization .Authorization ;
41
-
42
- public class BranchToExistingProjectDatabaseAction extends AbstractBranchDatabaseAction {
43
- private final Long roid ;
44
- private final Long destPoid ;
45
- private final String comment ;
46
- private final BimServer bimServer ;
47
- private Authorization authorization ;
48
-
49
- public BranchToExistingProjectDatabaseAction (DatabaseSession databaseSession , AccessMethod accessMethod , BimServer bimServer , Authorization authorization , Long roid , Long destPoid , String comment ) {
50
- super (databaseSession , accessMethod );
37
+
38
+ public class BranchToExistingProjectDatabaseAction extends AbstractBranchDatabaseAction {
39
+ private final Long roid ;
40
+ private final Long destPoid ;
41
+ private final String comment ;
42
+ private final BimServer bimServer ;
43
+ private Authorization authorization ;
44
+
45
+ public BranchToExistingProjectDatabaseAction (DatabaseSession databaseSession , AccessMethod accessMethod , BimServer bimServer , Authorization authorization , Long roid , Long destPoid , String comment ) {
46
+ super (databaseSession , accessMethod );
51
47
this .bimServer = bimServer ;
52
- this .authorization = authorization ;
53
- this .roid = roid ;
54
- this .destPoid = destPoid ;
55
- this .comment = comment ;
56
- }
48
+ this .authorization = authorization ;
49
+ this .roid = roid ;
50
+ this .destPoid = destPoid ;
51
+ this .comment = comment ;
52
+ }
57
53
58
54
public Long getRoid () {
59
55
return roid ;
@@ -63,34 +59,38 @@ public Long getRoid() {
63
59
public Long getPoid () {
64
60
return destPoid ;
65
61
}
66
-
67
- @ Override
68
- public ConcreteRevision execute () throws UserException , BimserverLockConflictException , BimserverDatabaseException {
69
- Revision oldRevision = getDatabaseSession ().get (StorePackage .eINSTANCE .getRevision (), roid , OldQuery .getDefault ());
70
- Project oldProject = oldRevision .getProject ();
71
- User user = getDatabaseSession ().get (StorePackage .eINSTANCE .getUser (), authorization .getUoid (), OldQuery .getDefault ());
72
- if (!authorization .hasRightsOnProjectOrSuperProjectsOrSubProjects (user , oldProject )) {
73
- throw new UserException ("User has insufficient rights to download revisions from this project" );
74
- }
62
+
63
+ @ Override
64
+ public ConcreteRevision execute () throws UserException , BimserverLockConflictException , BimserverDatabaseException {
65
+ Revision oldRevision = getDatabaseSession ().get (StorePackage .eINSTANCE .getRevision (), roid , OldQuery .getDefault ());
66
+ Project oldProject = oldRevision .getProject ();
67
+ User user = getDatabaseSession ().get (StorePackage .eINSTANCE .getUser (), authorization .getUoid (), OldQuery .getDefault ());
68
+ User actingUser = getUserByUoid (authorization .getUoid ());
69
+ if (actingUser .getUserType () == UserType .READ_ONLY ) {
70
+ throw new UserException ("User '" + actingUser .getName () + "' is read only and cannot branch projects" );
71
+ }
72
+ if (!authorization .hasRightsOnProjectOrSuperProjectsOrSubProjects (user , oldProject )) {
73
+ throw new UserException ("User has insufficient rights to download revisions from this project" );
74
+ }
75
75
IfcModelSet ifcModelSet = new IfcModelSet ();
76
- PackageMetaData lastMetaData = null ;
76
+ PackageMetaData lastMetaData = null ;
77
77
for (ConcreteRevision subRevision : oldRevision .getConcreteRevisions ()) {
78
- PackageMetaData packageMetaData = bimServer .getMetaDataManager ().getPackageMetaData (subRevision .getProject ().getSchema ());
79
- IfcModel subModel = new BasicIfcModel (packageMetaData , null );
80
- getDatabaseSession ().getMap (subModel , new OldQuery (packageMetaData , subRevision .getProject ().getId (), subRevision .getId (), -1 , Deep .YES ));
81
- subModel .getModelMetaData ().setDate (subRevision .getDate ());
78
+ PackageMetaData packageMetaData = bimServer .getMetaDataManager ().getPackageMetaData (subRevision .getProject ().getSchema ());
79
+ IfcModel subModel = new BasicIfcModel (packageMetaData , null );
80
+ getDatabaseSession ().getMap (subModel , new OldQuery (packageMetaData , subRevision .getProject ().getId (), subRevision .getId (), -1 , Deep .YES ));
81
+ subModel .getModelMetaData ().setDate (subRevision .getDate ());
82
82
ifcModelSet .add (subModel );
83
- lastMetaData = packageMetaData ;
84
- }
83
+ lastMetaData = packageMetaData ;
84
+ }
85
85
IfcModelInterface model = new BasicIfcModel (lastMetaData , null );
86
86
try {
87
- model = bimServer .getMergerFactory ().createMerger (getDatabaseSession (), authorization .getUoid ())
87
+ model = bimServer .getMergerFactory ().createMerger (getDatabaseSession (), authorization .getUoid ())
88
88
.merge (oldRevision .getProject (), ifcModelSet , new ModelHelper (bimServer .getMetaDataManager (), model ));
89
89
} catch (MergeException e ) {
90
90
throw new UserException (e );
91
- }
92
- model .resetOids ();
93
- CheckinDatabaseAction checkinDatabaseAction = new CheckinDatabaseAction (bimServer , getDatabaseSession (), getAccessMethod (), destPoid , authorization , model , comment , comment , false , -1 , -1 ); // TODO
91
+ }
92
+ model .resetOids ();
93
+ CheckinDatabaseAction checkinDatabaseAction = new CheckinDatabaseAction (bimServer , getDatabaseSession (), getAccessMethod (), destPoid , authorization , model , comment , comment , false , -1 , -1 ); // TODO
94
94
return checkinDatabaseAction .execute ();
95
- }
95
+ }
96
96
}
0 commit comments