Search in sources :

Example 51 with Project

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

the class ServiceImpl method initiateCheckin.

@Override
public Long initiateCheckin(Long poid, Long deserializerOid) throws ServerException, UserException {
    requireAuthenticationAndRunningServer();
    ProgressOnProjectTopic progressTopic = getBimServer().getNotificationsManager().createProgressOnProjectTopic(getAuthorization().getUoid(), poid, SProgressTopicType.UPLOAD, "Checkin");
    long topicId = progressTopic.getKey().getId();
    try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
        Project tmpProject = tmpSession.get(poid, OldQuery.getDefault());
        if (tmpProject.getCheckinInProgress() != topicId && tmpProject.getCheckinInProgress() != 0) {
            Thread.sleep(1000);
            throw new UserException("Checkin in progress on this project (topicId: " + tmpProject.getCheckinInProgress() + "), please try again later");
        }
        tmpProject.setCheckinInProgress(topicId);
        tmpSession.store(tmpProject);
        tmpSession.commit();
    } catch (BimserverDatabaseException e) {
        // TODO
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ServiceException e) {
        if (e instanceof UserException) {
            throw (UserException) e;
        }
        e.printStackTrace();
    }
    final DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
    try {
        User user = (User) session.get(StorePackage.eINSTANCE.getUser(), getAuthorization().getUoid(), OldQuery.getDefault());
        Project project = session.get(poid, OldQuery.getDefault());
        if (!getAuthorization().hasRightsOnProjectOrSuperProjects(user, project)) {
            throw new UserException("User has no rights to checkin models to this project");
        }
        if (!MailSystem.isValidEmailAddress(user.getUsername())) {
            throw new UserException("Users must have a valid e-mail address to checkin");
        }
        if (project == null) {
            throw new UserException("No project found with poid " + poid);
        }
        return progressTopic.getKey().getId();
    } catch (UserException e) {
        throw e;
    } catch (Throwable e) {
        LOGGER.error("", e);
        throw new ServerException(e);
    } finally {
        session.close();
    }
}
Also used : Project(org.bimserver.models.store.Project) SProject(org.bimserver.interfaces.objects.SProject) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) ProgressOnProjectTopic(org.bimserver.notifications.ProgressOnProjectTopic) SUser(org.bimserver.interfaces.objects.SUser) User(org.bimserver.models.store.User) ServerException(org.bimserver.shared.exceptions.ServerException) ServiceException(org.bimserver.shared.exceptions.ServiceException) DatabaseSession(org.bimserver.database.DatabaseSession) UserException(org.bimserver.shared.exceptions.UserException)

Example 52 with Project

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

the class NotificationRegistryServiceImpl method getProgressTopicsOnProject.

@Override
public List<Long> getProgressTopicsOnProject(Long poid) throws ServerException, UserException {
    DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
    try {
        List<Long> list = new ArrayList<Long>();
        Project project = session.get(StorePackage.eINSTANCE.getProject(), poid, OldQuery.getDefault());
        List<Long> revisionOids = new ArrayList<Long>();
        for (Revision revision : project.getRevisions()) {
            revisionOids.add(revision.getOid());
        }
        Set<ProgressTopic> progressOnProjectTopics = getBimServer().getNotificationsManager().getProgressOnProjectTopics(poid, revisionOids);
        if (progressOnProjectTopics != null) {
            for (ProgressTopic topic : progressOnProjectTopics) {
                list.add(topic.getKey().getId());
            }
        }
        return list;
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : Project(org.bimserver.models.store.Project) ProgressTopic(org.bimserver.notifications.ProgressTopic) Revision(org.bimserver.models.store.Revision) DatabaseSession(org.bimserver.database.DatabaseSession) ArrayList(java.util.ArrayList) TopicRegisterException(org.bimserver.notifications.TopicRegisterException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 53 with Project

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

the class BimServer method cleanupStaleData.

private void cleanupStaleData() throws BimserverDatabaseException {
    LOGGER.info("Checking for stale records, this can take some time...");
    long s = System.nanoTime();
    try (DatabaseSession session = bimDatabase.createSession(OperationType.POSSIBLY_WRITE)) {
        for (Project project : session.getAll(Project.class)) {
            if (project.getCheckinInProgress() == 0) {
                continue;
            }
            if (project.getName().equals("INT-Store")) {
                continue;
            }
            int recordsRemoved = 0;
            if (project.getRevisions().size() == 0) {
                recordsRemoved += checkPidRid(session, project, project.getId(), 0);
            } else {
                ConcreteRevision lastConcreteRevision = project.getLastConcreteRevision();
                if (lastConcreteRevision != null) {
                    recordsRemoved += checkPidRid(session, project, project.getId(), lastConcreteRevision.getId());
                }
            }
            if (recordsRemoved > 0) {
                LOGGER.info("Removed " + recordsRemoved + " stale records for project " + project.getName());
            }
            project.setCheckinInProgress(0);
            session.store(project);
        }
        session.commit();
    } catch (ServiceException e1) {
        LOGGER.error("", e1);
    }
    long e = System.nanoTime();
    LOGGER.info("Done checking for stale records (" + ((e - s) / 1000000) + " ms)");
}
Also used : Project(org.bimserver.models.store.Project) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ServiceException(org.bimserver.shared.exceptions.ServiceException) DatabaseSession(org.bimserver.database.DatabaseSession)

Example 54 with Project

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

the class ServiceImpl method getUserRelatedLogs.

@Override
public List<SLogAction> getUserRelatedLogs(Long uoid) throws ServerException, UserException {
    DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
    try {
        List<LogAction> logActions = new ArrayList<LogAction>();
        User user = session.get(getAuthorization().getUoid(), OldQuery.getDefault());
        IfcModelInterface projectsModel = session.getAllOfType(StorePackage.eINSTANCE.getProject(), OldQuery.getDefault());
        logActions.addAll(user.getLogs());
        for (IdEObject idEObject : projectsModel.getValues()) {
            if (idEObject instanceof Project) {
                Project project = (Project) idEObject;
                if ((user.getUserType() == UserType.ADMIN || (project.getState() == ObjectState.ACTIVE) && getAuthorization().hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project))) {
                    logActions.addAll(project.getLogs());
                }
            }
        }
        Collections.sort(logActions, new Comparator<LogAction>() {

            @Override
            public int compare(LogAction o1, LogAction o2) {
                return o1.getDate().compareTo(o2.getDate());
            }
        });
        return getBimServer().getSConverter().convertToSListLogAction(logActions);
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : Project(org.bimserver.models.store.Project) SProject(org.bimserver.interfaces.objects.SProject) LogAction(org.bimserver.models.log.LogAction) SLogAction(org.bimserver.interfaces.objects.SLogAction) SUser(org.bimserver.interfaces.objects.SUser) User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) IdEObject(org.bimserver.emf.IdEObject) IfcModelInterface(org.bimserver.emf.IfcModelInterface) ArrayList(java.util.ArrayList) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerException(org.bimserver.plugins.serializers.SerializerException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) PluginException(org.bimserver.shared.exceptions.PluginException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException)

Example 55 with Project

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

the class ServiceImpl method checkinInitiatedInternalSync.

public SLongActionState checkinInitiatedInternalSync(Long topicId, final Long poid, final String comment, Long deserializerOid, Long fileSize, String fileName, DataHandler dataHandler, Boolean merge, Boolean sync, long newServiceId) throws ServerException, UserException {
    requireAuthenticationAndRunningServer();
    final DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
    String username = "Unknown";
    String userUsername = "Unknown";
    try {
        User user = (User) session.get(StorePackage.eINSTANCE.getUser(), getAuthorization().getUoid(), OldQuery.getDefault());
        Project project = session.get(poid, OldQuery.getDefault());
        if (project == null) {
            throw new UserException("No project found with poid " + poid);
        }
        username = user.getName();
        userUsername = user.getUsername();
        Path incomingFile = getIncomingFileName(fileName, null, userUsername);
        return checkinInternal(topicId, poid, comment, deserializerOid, fileSize, fileName, dataHandler.getInputStream(), merge, sync, session, username, userUsername, project, incomingFile, newServiceId);
    } catch (UserException e) {
        try {
            clearCheckinInProgress(poid);
        } catch (BimserverDatabaseException | ServiceException e1) {
            LOGGER.error("", e1);
        }
        throw e;
    } catch (Throwable e) {
        try {
            clearCheckinInProgress(poid);
        } catch (BimserverDatabaseException | ServiceException e1) {
            LOGGER.error("", e1);
        }
        LOGGER.error("", e);
        throw new ServerException(e);
    } finally {
        session.close();
    }
}
Also used : Path(java.nio.file.Path) Project(org.bimserver.models.store.Project) SProject(org.bimserver.interfaces.objects.SProject) SUser(org.bimserver.interfaces.objects.SUser) User(org.bimserver.models.store.User) ServerException(org.bimserver.shared.exceptions.ServerException) DatabaseSession(org.bimserver.database.DatabaseSession) 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