Search in sources :

Example 71 with Project

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

the class UndeleteProjectDatabaseAction method execute.

@Override
public Boolean execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
    User actingUser = getUserByUoid(authorization.getUoid());
    final Project project = getProjectByPoid(poid);
    if (project == null) {
        throw new UserException("No Project with oid " + poid + " found");
    }
    if (actingUser.getUserType() == UserType.ADMIN || actingUser.getHasRightsOn().contains(project)) {
        project.setState(ObjectState.ACTIVE);
        final ProjectUndeleted projectUndeleted = getDatabaseSession().create(ProjectUndeleted.class);
        projectUndeleted.setAccessMethod(getAccessMethod());
        projectUndeleted.setDate(new Date());
        projectUndeleted.setExecutor(actingUser);
        projectUndeleted.setProject(project);
        getDatabaseSession().addPostCommitAction(new PostCommitAction() {

            @Override
            public void execute() throws UserException {
                bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(projectUndeleted));
            }
        });
        getDatabaseSession().store(project);
        return true;
    } else {
        throw new UserException("No rights to undelete this project");
    }
}
Also used : Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) UserException(org.bimserver.shared.exceptions.UserException) Date(java.util.Date) ProjectUndeleted(org.bimserver.models.log.ProjectUndeleted)

Example 72 with Project

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

the class RemoveModelCheckerFromProjectDatabaseAction method execute.

@Override
public Boolean execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
    ModelCheckerInstance modelCheckerInstance = getDatabaseSession().get(mcoid, OldQuery.getDefault());
    Project project = getDatabaseSession().get(poid, OldQuery.getDefault());
    project.getModelCheckers().remove(modelCheckerInstance);
    getDatabaseSession().store(project);
    return true;
}
Also used : Project(org.bimserver.models.store.Project) ModelCheckerInstance(org.bimserver.models.store.ModelCheckerInstance)

Example 73 with Project

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

the class UpdateProjectDatabaseAction method execute.

@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User actingUser = getUserByUoid(authorization.getUoid());
    final Project project = getProjectByPoid(sProject.getOid());
    if (project == null) {
        throw new UserException("Project with pid " + sProject.getOid() + " not found");
    }
    if (sProject.getName().trim().equals("")) {
        throw new UserException("Project name cannot be empty");
    }
    if (!authorization.hasRightsOnProjectOrSuperProjects(actingUser, project)) {
        throw new UserException("User has no rights to update project properties");
    }
    if (project.getParent() == null) {
        if (!sProject.getName().equals(project.getName())) {
            for (Project p : getProjectsByName(sProject.getName())) {
                if (p.getParent() == null) {
                    throw new UserException("Project name must be unique");
                }
            }
        }
    } else {
        Project parent = project.getParent();
        for (Project subProject : parent.getSubProjects()) {
            if (subProject.getName().equals(sProject.getName()) && subProject != project) {
                throw new UserException("Project name must be unique within parent project (" + parent.getName() + ")");
            }
        }
    }
    project.setSendEmailOnNewRevision(sProject.isSendEmailOnNewRevision());
    project.setName(sProject.getName());
    project.setDescription(sProject.getDescription());
    project.setExportLengthMeasurePrefix(SIPrefix.get(sProject.getExportLengthMeasurePrefix().getOrdinal()));
    final ProjectUpdated projectUpdated = getDatabaseSession().create(ProjectUpdated.class);
    projectUpdated.setAccessMethod(getAccessMethod());
    projectUpdated.setDate(new Date());
    projectUpdated.setExecutor(actingUser);
    projectUpdated.setProject(project);
    getDatabaseSession().addPostCommitAction(new PostCommitAction() {

        @Override
        public void execute() throws UserException {
            bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(projectUpdated));
        }
    });
    getDatabaseSession().store(project);
    return null;
}
Also used : SProject(org.bimserver.interfaces.objects.SProject) Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) ProjectUpdated(org.bimserver.models.log.ProjectUpdated) UserException(org.bimserver.shared.exceptions.UserException) Date(java.util.Date)

Example 74 with Project

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

the class GenericCheckinDatabaseAction method createNewConcreteRevision.

public CreateRevisionResult createNewConcreteRevision(DatabaseSession session, long size, Project project, User user, String comment) throws BimserverDatabaseException, BimserverLockConflictException {
    CreateRevisionResult result = new CreateRevisionResult();
    ConcreteRevision concreteRevision = getDatabaseSession().create(ConcreteRevision.class);
    concreteRevision.setSize(size);
    Date date = new Date();
    concreteRevision.setDate(date);
    concreteRevision.setId(project.getConcreteRevisions().size() + 1);
    concreteRevision.setUser(user);
    concreteRevision.setProject(project);
    project.setLastConcreteRevision(concreteRevision);
    Revision newRevision = createNewVirtualRevision(session, project, concreteRevision, comment, date, user, size);
    for (Checkout checkout : project.getCheckouts()) {
        if (checkout.getUser() == user) {
            checkout.setActive(false);
            session.store(checkout);
        }
    }
    project.setLastRevision(newRevision);
    Project parent = project.getParent();
    result.addRevision(newRevision);
    while (parent != null) {
        Revision revision = getDatabaseSession().create(Revision.class);
        result.addRevision(revision);
        revision.setComment("generated for subproject " + project.getName() + ", revision " + concreteRevision.getId() + ", by " + user.getName());
        revision.setDate(date);
        revision.setUser(getSystemUser());
        revision.setProject(parent);
        if (parent.getLastRevision() != null) {
            Revision lastRevision = parent.getLastRevision();
            for (ConcreteRevision oldRevision : lastRevision.getConcreteRevisions()) {
                if (oldRevision.getProject() != project && oldRevision.getProject() != parent) {
                    revision.getConcreteRevisions().add(oldRevision);
                    revision.setSize(((revision.getSize() == null || revision.getSize() == -1) ? 0 : revision.getSize()) + oldRevision.getSize());
                    session.store(revision);
                    session.store(oldRevision);
                }
            }
        }
        revision.getConcreteRevisions().add(concreteRevision);
        revision.setSize((revision.getSize() == null ? 0 : revision.getSize()) + concreteRevision.getSize());
        revision.setLastConcreteRevision(concreteRevision);
        if (parent.getLastRevision() == null) {
            revision.setId(1);
        } else {
            revision.setId(parent.getLastRevision().getId() + 1);
        }
        parent.setLastRevision(revision);
        session.store(revision);
        session.store(parent);
        parent = parent.getParent();
    }
    session.store(project);
    session.store(concreteRevision);
    result.setConcreteRevision(concreteRevision);
    return result;
}
Also used : Project(org.bimserver.models.store.Project) Checkout(org.bimserver.models.store.Checkout) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) Date(java.util.Date)

Example 75 with Project

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

the class GetCheckinWarningsDatabaseAction method execute.

@Override
public Set<String> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Project project = getProjectByPoid(poid);
    User user = getUserByUoid(authorization.getUoid());
    Set<String> warnings = new HashSet<String>();
    checkInterleavingCommits(project, user, warnings);
    new GetCheckoutWarningsDatabaseAction(getDatabaseSession(), getAccessMethod(), poid, authorization).checkOtherUsersCheckouts(project, user, warnings);
    return warnings;
}
Also used : Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) HashSet(java.util.HashSet)

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