Search in sources :

Example 61 with Project

use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.

the class AddUserToProjectDatabaseAction method execute.

@Override
public Boolean execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
    final Project project = getProjectByPoid(poid);
    User actingUser = getUserByUoid(authorization.getUoid());
    if (authorization.hasRightsOnProject(actingUser, project)) {
        User user = getUserByUoid(uoid);
        project.getHasAuthorizedUsers().add(user);
        user.getHasRightsOn().add(project);
        final UserAddedToProject userAddedToProject = getDatabaseSession().create(UserAddedToProject.class);
        userAddedToProject.setExecutor(actingUser);
        userAddedToProject.setDate(new Date());
        userAddedToProject.setAccessMethod(getAccessMethod());
        userAddedToProject.setUser(user);
        userAddedToProject.setProject(project);
        getDatabaseSession().addPostCommitAction(new PostCommitAction() {

            @Override
            public void execute() throws UserException {
                bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(userAddedToProject));
            }
        });
        getDatabaseSession().store(user);
        getDatabaseSession().store(project);
        return true;
    } else {
        throw new UserException("User has no rights to grant permission on '" + project.getName() + "'");
    }
}
Also used : UserAddedToProject(org.bimserver.models.log.UserAddedToProject) Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) UserAddedToProject(org.bimserver.models.log.UserAddedToProject) UserException(org.bimserver.shared.exceptions.UserException) Date(java.util.Date)

Example 62 with Project

use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.

the class CheckinDatabaseAction method clearCheckinInProgress.

private void clearCheckinInProgress() throws BimserverDatabaseException, ServiceException {
    try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.READ_WRITE)) {
        Project project = tmpSession.get(poid, OldQuery.getDefault());
        project.setCheckinInProgress(0);
        tmpSession.store(project);
        tmpSession.commit();
    }
}
Also used : Project(org.bimserver.models.store.Project) DatabaseSession(org.bimserver.database.DatabaseSession)

Example 63 with Project

use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.

the class CreateBaseProjectDatabaseAction method execute.

@Override
public Project execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
    final Project project = getDatabaseSession().create(Project.class);
    project.setName(Database.STORE_PROJECT_NAME);
    project.setCreatedDate(new Date());
    getDatabaseSession().store(project);
    return project;
}
Also used : Project(org.bimserver.models.store.Project) Date(java.util.Date)

Example 64 with Project

use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.

the class AddLocalServiceToProjectDatabaseAction method execute.

@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Project project = getDatabaseSession().get(StorePackage.eINSTANCE.getProject(), poid, OldQuery.getDefault());
    User user = getDatabaseSession().get(StorePackage.eINSTANCE.getUser(), authorization.getUoid(), OldQuery.getDefault());
    service.setUser(user);
    for (org.bimserver.models.store.Service existing : project.getServices()) {
        if (existing.getName().equals(service.getName())) {
            throw new UserException("Service name \"" + service.getName() + "\" already used in this project");
        }
    }
    service.setInternalService((InternalServicePluginConfiguration) getDatabaseSession().get(StorePackage.eINSTANCE.getInternalServicePluginConfiguration(), internalServiceOid, OldQuery.getDefault()));
    project.getServices().add(service);
    service.setProject(project);
    getDatabaseSession().store(service);
    service.setProfileIdentifier("" + service.getOid());
    getDatabaseSession().store(project);
    return null;
}
Also used : Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) Service(org.bimserver.models.store.Service) UserException(org.bimserver.shared.exceptions.UserException)

Example 65 with Project

use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.

the class LongStreamingCheckinAction method execute.

public void execute() {
    DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
    try {
        checkinDatabaseAction.setDatabaseSession(session);
        session.executeAndCommitAction(checkinDatabaseAction, new ProgressHandler() {

            private int count;

            @Override
            public void progress(int current, int max) {
                if (count == 0) {
                    updateProgress("Saving to database (" + fileName + ")", current * 100 / max);
                } else {
                    updateProgress("Saving to database (" + fileName + ", " + count + " try)", current * 100 / max);
                }
            }

            @Override
            public void retry(int count) {
                this.count = count;
            }
        }, new RollbackListener() {

            @Override
            public void rollback() {
                try {
                    checkinDatabaseAction.rollback();
                } catch (BimserverDatabaseException e) {
                    LOGGER.error("", e);
                }
            }
        });
        this.roid = checkinDatabaseAction.getRevision().getOid();
    } catch (Exception e) {
        try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.READ_WRITE)) {
            Project project = tmpSession.get(checkinDatabaseAction.getPoid(), OldQuery.getDefault());
            project.setCheckinInProgress(0);
            tmpSession.store(project);
            try {
                tmpSession.commit();
            } catch (ServiceException e2) {
                LOGGER.error("", e2);
            }
        } catch (BimserverDatabaseException e1) {
            LOGGER.error("", e1);
        }
        if (e instanceof UserException) {
            if (e.getCause() instanceof DeserializeException) {
                this.deserializerException = (DeserializeException) e.getCause();
            }
        } else if (e instanceof BimserverConcurrentModificationDatabaseException) {
        // Ignore
        } else {
            LOGGER.error("", e);
        }
        error(e);
    } finally {
        try {
            checkinDatabaseAction.close();
        } catch (IOException e) {
            LOGGER.error("", e);
        }
        session.close();
        if (getActionState() != ActionState.AS_ERROR) {
            changeActionState(ActionState.FINISHED, "Checkin of " + fileName, 100);
        }
        done();
    }
}
Also used : DatabaseSession(org.bimserver.database.DatabaseSession) ProgressHandler(org.bimserver.database.ProgressHandler) BimserverConcurrentModificationDatabaseException(org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) IOException(java.io.IOException) RollbackListener(org.bimserver.database.RollbackListener) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) BimserverConcurrentModificationDatabaseException(org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) UserException(org.bimserver.shared.exceptions.UserException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) Project(org.bimserver.models.store.Project) ServiceException(org.bimserver.shared.exceptions.ServiceException) UserException(org.bimserver.shared.exceptions.UserException)

Aggregations

Project (org.bimserver.models.store.Project)87 UserException (org.bimserver.shared.exceptions.UserException)53 User (org.bimserver.models.store.User)51 DatabaseSession (org.bimserver.database.DatabaseSession)33 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)25 Revision (org.bimserver.models.store.Revision)25 ServerException (org.bimserver.shared.exceptions.ServerException)23 Date (java.util.Date)19 ServiceException (org.bimserver.shared.exceptions.ServiceException)19 SProject (org.bimserver.interfaces.objects.SProject)18 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)15 PackageMetaData (org.bimserver.emf.PackageMetaData)14 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)12 HashSet (java.util.HashSet)12 IfcModelInterface (org.bimserver.emf.IfcModelInterface)12 OldQuery (org.bimserver.database.OldQuery)11 PostCommitAction (org.bimserver.database.PostCommitAction)11 SConverter (org.bimserver.interfaces.SConverter)9 SUser (org.bimserver.interfaces.objects.SUser)9