2828import org .bimserver .ifc .BasicIfcModel ;
2929import org .bimserver .ifc .IfcModel ;
3030import 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 .*;
3632import org .bimserver .plugins .IfcModelSet ;
3733import org .bimserver .plugins .ModelHelper ;
3834import org .bimserver .plugins .modelmerger .MergeException ;
3935import org .bimserver .shared .exceptions .UserException ;
4036import 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 );
5147 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+ }
5753
5854 public Long getRoid () {
5955 return roid ;
@@ -63,34 +59,38 @@ public Long getRoid() {
6359 public Long getPoid () {
6460 return destPoid ;
6561 }
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+ }
7575 IfcModelSet ifcModelSet = new IfcModelSet ();
76- PackageMetaData lastMetaData = null ;
76+ PackageMetaData lastMetaData = null ;
7777 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 ());
8282 ifcModelSet .add (subModel );
83- lastMetaData = packageMetaData ;
84- }
83+ lastMetaData = packageMetaData ;
84+ }
8585 IfcModelInterface model = new BasicIfcModel (lastMetaData , null );
8686 try {
87- model = bimServer .getMergerFactory ().createMerger (getDatabaseSession (), authorization .getUoid ())
87+ model = bimServer .getMergerFactory ().createMerger (getDatabaseSession (), authorization .getUoid ())
8888 .merge (oldRevision .getProject (), ifcModelSet , new ModelHelper (bimServer .getMetaDataManager (), model ));
8989 } catch (MergeException e ) {
9090 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
9494 return checkinDatabaseAction .execute ();
95- }
95+ }
9696}
0 commit comments