Search in sources :

Example 6 with Project

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

the class ServiceImpl method addProjectAsSubProject.

@Override
public SProject addProjectAsSubProject(String projectName, Long parentPoid, String schema) throws ServerException, UserException {
    requireRealUserAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        BimDatabaseAction<Project> action = new AddProjectDatabaseAction(getBimServer(), session, getInternalAccessMethod(), projectName, parentPoid, schema, getAuthorization());
        return getBimServer().getSConverter().convertToSObject(session.executeAndCommitAction(action));
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : Project(org.bimserver.models.store.Project) SProject(org.bimserver.interfaces.objects.SProject) DatabaseSession(org.bimserver.database.DatabaseSession) AddProjectDatabaseAction(org.bimserver.database.actions.AddProjectDatabaseAction) 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) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException)

Example 7 with Project

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

the class ServiceImpl method getSuggestedDeserializerForExtension.

@Override
public SDeserializerPluginConfiguration getSuggestedDeserializerForExtension(String extension, Long poid) throws ServerException, UserException {
    // Token authenticated users should also be able to call this method
    try {
        requireAuthenticationAndRunningServer();
        DatabaseSession session = getBimServer().getDatabase().createSession();
        List<DeserializerPluginConfiguration> list = new ArrayList<>();
        try {
            Project project = session.get(poid, OldQuery.getDefault());
            UserSettings userSettings = getUserSettings(session);
            for (DeserializerPluginConfiguration deserializer : userSettings.getDeserializers()) {
                Plugin plugin = getBimServer().getPluginManager().getPlugin(deserializer.getPluginDescriptor().getIdentifier(), true);
                if (plugin instanceof DeserializerPlugin) {
                    DeserializerPlugin deserializerPlugin = (DeserializerPlugin) plugin;
                    if (deserializerPlugin.getSupportedSchemas().contains(Schema.valueOf(project.getSchema().toUpperCase()))) {
                        if (deserializerPlugin.canHandleExtension(extension)) {
                            list.add(deserializer);
                        }
                    }
                } else if (plugin instanceof StreamingDeserializerPlugin) {
                    StreamingDeserializerPlugin streamingDeserializerPlugin = (StreamingDeserializerPlugin) plugin;
                    if (streamingDeserializerPlugin.getSupportedSchemas().contains(Schema.valueOf(project.getSchema().toUpperCase()))) {
                        if (streamingDeserializerPlugin.canHandleExtension(extension)) {
                            list.add(deserializer);
                        }
                    }
                }
            }
        } finally {
            session.close();
        }
        if (list.size() == 1) {
            return getBimServer().getSConverter().convertToSObject(list.get(0));
        } else if (list.size() > 1) {
            for (DeserializerPluginConfiguration deserializerPluginConfiguration : list) {
                Plugin plugin = getBimServer().getPluginManager().getPlugin(deserializerPluginConfiguration.getPluginDescriptor().getIdentifier(), true);
                // Prefer the streaming version
                if (plugin instanceof StreamingDeserializerPlugin) {
                    return getBimServer().getSConverter().convertToSObject(deserializerPluginConfiguration);
                }
            }
            // Just return the first one
            return getBimServer().getSConverter().convertToSObject(list.get(0));
        }
    } catch (Exception e) {
        return handleException(e);
    }
    return null;
}
Also used : Project(org.bimserver.models.store.Project) SProject(org.bimserver.interfaces.objects.SProject) DatabaseSession(org.bimserver.database.DatabaseSession) UserSettings(org.bimserver.models.store.UserSettings) SUserSettings(org.bimserver.interfaces.objects.SUserSettings) StreamingDeserializerPlugin(org.bimserver.plugins.deserializers.StreamingDeserializerPlugin) ArrayList(java.util.ArrayList) StreamingDeserializerPlugin(org.bimserver.plugins.deserializers.StreamingDeserializerPlugin) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) DeserializerPluginConfiguration(org.bimserver.models.store.DeserializerPluginConfiguration) 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) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) QueryEnginePlugin(org.bimserver.plugins.queryengine.QueryEnginePlugin) MessagingSerializerPlugin(org.bimserver.plugins.serializers.MessagingSerializerPlugin) StreamingDeserializerPlugin(org.bimserver.plugins.deserializers.StreamingDeserializerPlugin) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) MessagingStreamingSerializerPlugin(org.bimserver.plugins.serializers.MessagingStreamingSerializerPlugin) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) Plugin(org.bimserver.plugins.Plugin)

Example 8 with Project

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

the class ServiceImpl method checkinInitiatedInternal.

public Long checkinInitiatedInternal(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();
    String username = "Unknown";
    String userUsername = "Unknown";
    try {
        if (getBimServer().getCheckinsInProgress().containsKey(poid)) {
            Thread.sleep(1000);
            throw new UserException("Checkin in progress on this project, please try again later");
        }
        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 homeDirIncoming = getBimServer().getHomeDir().resolve("incoming");
        Path userDirIncoming = homeDirIncoming.resolve(userUsername);
        if (!Files.exists(userDirIncoming)) {
            Files.createDirectories(userDirIncoming);
        }
        if (fileName.contains("/")) {
            fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
        }
        if (fileName.contains("\\")) {
            fileName = fileName.substring(fileName.lastIndexOf("\\") + 1);
        }
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
        String cacheFileName = dateFormat.format(new Date()) + "-" + fileName;
        Path file = userDirIncoming.resolve(cacheFileName);
        return checkinInternal(topicId, poid, comment, deserializerOid, fileSize, fileName, dataHandler.getInputStream(), merge, sync, session, username, userUsername, project, file, newServiceId);
    } catch (UserException e) {
        throw e;
    } catch (Throwable e) {
        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) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) UserException(org.bimserver.shared.exceptions.UserException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 9 with Project

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

the class ServiceImpl method getProjectSmallByPoid.

@Override
public SProjectSmall getProjectSmallByPoid(Long poid) throws ServerException, UserException {
    requireAuthenticationAndRunningServer();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        GetProjectByPoidDatabaseAction action = new GetProjectByPoidDatabaseAction(session, getInternalAccessMethod(), poid, getAuthorization());
        Project project = session.executeAndCommitAction(action);
        User user = session.get(getAuthorization().getUoid(), OldQuery.getDefault());
        return GetAllProjectsSmallDatabaseAction.createSmallProject(getAuthorization(), getBimServer(), project, user);
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : GetProjectByPoidDatabaseAction(org.bimserver.database.actions.GetProjectByPoidDatabaseAction) Project(org.bimserver.models.store.Project) SProject(org.bimserver.interfaces.objects.SProject) SUser(org.bimserver.interfaces.objects.SUser) User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) 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) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException)

Example 10 with Project

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

the class AddExtendedDataToProjectDatabaseAction method execute.

@Override
public Long execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    super.execute();
    User actingUser = getUserByUoid(authorization.getUoid());
    Project project = getProjectByPoid(poid);
    if (project == null) {
        throw new UserException("Project with poid " + poid + " not found");
    }
    project.getExtendedData().add(getIdEObject());
    getDatabaseSession().store(project);
    final ExtendedDataAddedToProject extendedDataAddedToProject = getDatabaseSession().create(ExtendedDataAddedToProject.class);
    extendedDataAddedToProject.setAccessMethod(getAccessMethod());
    extendedDataAddedToProject.setDate(new Date());
    extendedDataAddedToProject.setExecutor(actingUser);
    extendedDataAddedToProject.setExtendedData(getIdEObject());
    extendedDataAddedToProject.setProject(project);
    getDatabaseSession().addPostCommitAction(new PostCommitAction() {

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

Aggregations

Project (org.bimserver.models.store.Project)80 UserException (org.bimserver.shared.exceptions.UserException)48 User (org.bimserver.models.store.User)46 DatabaseSession (org.bimserver.database.DatabaseSession)25 Revision (org.bimserver.models.store.Revision)23 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)22 ServerException (org.bimserver.shared.exceptions.ServerException)20 Date (java.util.Date)18 ArrayList (java.util.ArrayList)14 SProject (org.bimserver.interfaces.objects.SProject)14 IOException (java.io.IOException)13 PackageMetaData (org.bimserver.emf.PackageMetaData)13 HashSet (java.util.HashSet)12 IfcModelInterface (org.bimserver.emf.IfcModelInterface)12 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)11 OldQuery (org.bimserver.database.OldQuery)10 PostCommitAction (org.bimserver.database.PostCommitAction)10 SConverter (org.bimserver.interfaces.SConverter)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 MalformedURLException (java.net.MalformedURLException)8