Search in sources :

Example 1 with File

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

the class ServiceImpl method getFileMeta.

@Override
public SFile getFileMeta(Long fileId) throws ServerException, UserException {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        org.bimserver.models.store.File file = (org.bimserver.models.store.File) session.get(StorePackage.eINSTANCE.getFile(), fileId, OldQuery.getDefault());
        file.setData(null);
        return getBimServer().getSConverter().convertToSObject(file);
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : DatabaseSession(org.bimserver.database.DatabaseSession) File(org.bimserver.models.store.File) File(org.bimserver.models.store.File) SFile(org.bimserver.interfaces.objects.SFile) BcfFile(org.opensourcebim.bcf.BcfFile) 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 2 with File

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

the class ServiceImpl method uploadFile.

@Override
public Long uploadFile(SFile file) throws ServerException, UserException {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        File convertFromSObject = getBimServer().getSConverter().convertFromSObject(file, session.create(File.class), session);
        UploadFileDatabaseAction action = new UploadFileDatabaseAction(session, getInternalAccessMethod(), convertFromSObject);
        return session.executeAndCommitAction(action);
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : DatabaseSession(org.bimserver.database.DatabaseSession) File(org.bimserver.models.store.File) SFile(org.bimserver.interfaces.objects.SFile) BcfFile(org.opensourcebim.bcf.BcfFile) 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) UploadFileDatabaseAction(org.bimserver.database.actions.UploadFileDatabaseAction)

Example 3 with File

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

the class AddExtendedDataToRevisionDatabaseAction method execute.

@Override
public Long execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    authorization.canWriteExtendedData(roid);
    User actingUser = getUserByUoid(authorization.getUoid());
    getIdEObject().setUser(actingUser);
    getIdEObject().setAdded(new Date());
    File file = getIdEObject().getFile();
    getIdEObject().setSize(file.getData().length);
    super.execute();
    Revision revision = getRevisionByRoid(roid);
    if (revision == null) {
        throw new UserException("Revision with roid " + roid + " not found");
    }
    revision.getExtendedData().add(getIdEObject());
    getDatabaseSession().store(revision);
    getIdEObject().setProject(revision.getProject());
    getIdEObject().setRevision(revision);
    if (getIdEObject().getSchema() != null) {
        getDatabaseSession().store(getIdEObject().getSchema());
    }
    final ExtendedDataAddedToRevision extendedDataAddedToRevision = getDatabaseSession().create(ExtendedDataAddedToRevision.class);
    extendedDataAddedToRevision.setAccessMethod(getAccessMethod());
    extendedDataAddedToRevision.setDate(new Date());
    extendedDataAddedToRevision.setExecutor(actingUser);
    extendedDataAddedToRevision.setExtendedData(getIdEObject());
    extendedDataAddedToRevision.setRevision(revision);
    final long poid = revision.getProject().getOid();
    final long roid = revision.getOid();
    getDatabaseSession().addPostCommitAction(new PostCommitAction() {

        @Override
        public void execute() throws UserException {
            bimServer.getNotificationsManager().notify(new NewExtendedDataOnRevisionNotification(bimServer, getIdEObject().getOid(), poid, roid, -1));
            bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(extendedDataAddedToRevision));
        }
    });
    return null;
}
Also used : User(org.bimserver.models.store.User) ExtendedDataAddedToRevision(org.bimserver.models.log.ExtendedDataAddedToRevision) Revision(org.bimserver.models.store.Revision) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) ExtendedDataAddedToRevision(org.bimserver.models.log.ExtendedDataAddedToRevision) UserException(org.bimserver.shared.exceptions.UserException) NewExtendedDataOnRevisionNotification(org.bimserver.notifications.NewExtendedDataOnRevisionNotification) File(org.bimserver.models.store.File) Date(java.util.Date)

Example 4 with File

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

the class RegenerateGeometryDatabaseAction method execute.

@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    ProgressListener progressListener = new ProgressListener() {

        @Override
        public void updateProgress(String state, int percentage) {
            setProgress("Generating geometry...", percentage);
        }
    };
    GeometryGenerationReport report = new GeometryGenerationReport();
    report.setOriginalIfcFileName("rerun");
    report.setOriginalIfcFileSize(-1);
    report.setOriginalDeserializer("rerun");
    StreamingGeometryGenerator streamingGeometryGenerator = new StreamingGeometryGenerator(bimServer, progressListener, eoid, report);
    Revision revision = getDatabaseSession().get(roid, OldQuery.getDefault());
    ConcreteRevision concreteRevision = revision.getConcreteRevisions().get(0);
    PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
    int highestStopId = AbstractDownloadDatabaseAction.findHighestStopRid(concreteRevision.getProject(), concreteRevision);
    QueryContext queryContext = new QueryContext(getDatabaseSession(), packageMetaData, revision.getProject().getId(), revision.getId(), roid, highestStopId);
    try {
        GenerateGeometryResult generateGeometry = streamingGeometryGenerator.generateGeometry(uoid, getDatabaseSession(), queryContext);
        for (Revision other : concreteRevision.getRevisions()) {
            other.setHasGeometry(true);
        }
        concreteRevision.setMinBounds(generateGeometry.getMinBoundsAsVector3f());
        concreteRevision.setMaxBounds(generateGeometry.getMaxBoundsAsVector3f());
        ExtendedData extendedData = getDatabaseSession().create(ExtendedData.class);
        File file = getDatabaseSession().create(File.class);
        byte[] bytes = report.toHtml().getBytes(Charsets.UTF_8);
        file.setData(bytes);
        file.setFilename("geometrygenerationreport.html");
        file.setMime("text/html");
        file.setSize(bytes.length);
        User actingUser = getUserByUoid(uoid);
        extendedData.setUser(actingUser);
        extendedData.setTitle("Geometry generation report (rerun)");
        extendedData.setAdded(new Date());
        extendedData.setSize(file.getData().length);
        extendedData.setFile(file);
        revision.getExtendedData().add(extendedData);
        extendedData.setProject(revision.getProject());
        extendedData.setRevision(revision);
        getDatabaseSession().store(file);
        getDatabaseSession().store(extendedData);
        getDatabaseSession().store(revision);
        if (extendedData.getSchema() != null) {
            getDatabaseSession().store(extendedData.getSchema());
        }
        getDatabaseSession().store(concreteRevision);
        renderEngineName = streamingGeometryGenerator.getRenderEngineName();
    } catch (GeometryGeneratingException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : User(org.bimserver.models.store.User) ExtendedData(org.bimserver.models.store.ExtendedData) PackageMetaData(org.bimserver.emf.PackageMetaData) StreamingGeometryGenerator(org.bimserver.geometry.StreamingGeometryGenerator) GeometryGeneratingException(org.bimserver.GeometryGeneratingException) QueryContext(org.bimserver.shared.QueryContext) Date(java.util.Date) GeometryGenerationReport(org.bimserver.geometry.GeometryGenerationReport) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) GenerateGeometryResult(org.bimserver.GenerateGeometryResult) File(org.bimserver.models.store.File)

Example 5 with File

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

the class StreamingCheckinDatabaseAction method execute.

@Override
public ConcreteRevision execute() throws UserException, BimserverDatabaseException {
    try {
        bimServer.getCheckinsInProgress().put(poid, getActingUid());
        if (inputStream instanceof RestartableInputStream) {
            ((RestartableInputStream) inputStream).restartIfAtEnd();
        }
        getDatabaseSession().clearPostCommitActions();
        if (fileSize == -1) {
        // setProgress("Deserializing IFC file...", -1);
        } else {
            setProgress("Deserializing IFC file...", 0);
        }
        authorization.canCheckin(poid);
        project = getProjectByPoid(poid);
        int nrConcreteRevisionsBefore = project.getConcreteRevisions().size();
        User user = getUserByUoid(authorization.getUoid());
        if (project == null) {
            throw new UserException("Project with poid " + poid + " not found");
        }
        if (!authorization.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 (getModel() != null) {
        // checkCheckSum(project);
        // }
        packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(project.getSchema());
        // TODO checksum
        // TODO modelcheckers
        // TODO test ifc4
        // long size = 0;
        // if (getModel() != null) {
        // for (IdEObject idEObject : getModel().getValues()) {
        // if (idEObject.eClass().getEAnnotation("hidden") == null) {
        // size++;
        // }
        // }
        // getModel().fixInverseMismatches();
        // }
        // for (ModelCheckerInstance modelCheckerInstance : project.getModelCheckers()) {
        // if (modelCheckerInstance.isValid()) {
        // ModelCheckerPlugin modelCheckerPlugin = bimServer.getPluginManager().getModelCheckerPlugin(modelCheckerInstance.getModelCheckerPluginClassName(), true);
        // if (modelCheckerPlugin != null) {
        // ModelChecker modelChecker = modelCheckerPlugin.createModelChecker(null);
        // ModelCheckerResult result = modelChecker.check(getModel(), modelCheckerInstance.getCompiled());
        // if (!result.isValid()) {
        // throw new UserException("Model is not valid according to " + modelCheckerInstance.getName());
        // }
        // }
        // }
        // }
        CreateRevisionResult result = createNewConcreteRevision(getDatabaseSession(), -1, project, user, comment.trim());
        newRevision = result.getRevisions().get(0);
        long newRoid = newRevision.getOid();
        // TODO check
        QueryContext queryContext = new QueryContext(getDatabaseSession(), packageMetaData, result.getConcreteRevision().getProject().getId(), result.getConcreteRevision().getId(), newRoid, -1);
        AtomicLong bytesRead = new AtomicLong();
        deserializer.setProgressReporter(new ByteProgressReporter() {

            @Override
            public void progress(long byteNumber) {
                bytesRead.set(byteNumber);
                if (fileSize != -1) {
                    int perc = (int) (100.0 * byteNumber / fileSize);
                    setProgress("Deserializing...", perc);
                }
            }
        });
        // This will read the full stream of objects and write to the database directly
        long size = deserializer.read(inputStream, fileName, fileSize, queryContext);
        Set<EClass> eClasses = deserializer.getSummaryMap().keySet();
        Map<EClass, Long> startOids = getDatabaseSession().getStartOids();
        if (startOids == null) {
            throw new BimserverDatabaseException("No objects changed");
        }
        Map<EClass, Long> oidCounters = new HashMap<>();
        int s = 0;
        for (EClass eClass : eClasses) {
            if (!DatabaseSession.perRecordVersioning(eClass)) {
                s++;
            }
        }
        ByteBuffer buffer = ByteBuffer.allocate(8 * s);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        for (EClass eClass : eClasses) {
            if (!DatabaseSession.perRecordVersioning(eClass)) {
                long oid = startOids.get(eClass);
                oidCounters.put(eClass, oid);
                buffer.putLong(oid);
            }
        }
        queryContext.setOidCounters(oidCounters);
        concreteRevision = result.getConcreteRevision();
        concreteRevision.setOidCounters(buffer.array());
        setProgress("Generating inverses/opposites...", -1);
        fixInverses(packageMetaData, newRoid);
        ProgressListener progressListener = new ProgressListener() {

            @Override
            public void updateProgress(String state, int percentage) {
                setProgress("Generating geometry...", percentage);
            }
        };
        GeometryGenerationReport report = new GeometryGenerationReport();
        report.setOriginalIfcFileName(fileName);
        report.setOriginalIfcFileSize(bytesRead.get());
        report.setNumberOfObjects(size);
        report.setOriginalDeserializer(pluginBundleVersion.getGroupId() + "." + pluginBundleVersion.getArtifactId() + ":" + pluginBundleVersion.getVersion());
        StreamingGeometryGenerator geometryGenerator = new StreamingGeometryGenerator(bimServer, progressListener, -1L, report);
        setProgress("Generating geometry...", 0);
        GenerateGeometryResult generateGeometry = geometryGenerator.generateGeometry(getActingUid(), getDatabaseSession(), queryContext);
        for (Revision other : concreteRevision.getRevisions()) {
            other.setHasGeometry(true);
        }
        concreteRevision.setMinBounds(generateGeometry.getMinBoundsAsVector3f());
        concreteRevision.setMaxBounds(generateGeometry.getMaxBoundsAsVector3f());
        setProgress("Doing other stuff...", -1);
        eClasses = deserializer.getSummaryMap().keySet();
        s = (startOids.containsKey(GeometryPackage.eINSTANCE.getGeometryInfo()) && startOids.containsKey(GeometryPackage.eINSTANCE.getGeometryData())) ? 2 : 0;
        for (EClass eClass : eClasses) {
            if (!DatabaseSession.perRecordVersioning(eClass)) {
                s++;
            }
        }
        buffer = ByteBuffer.allocate(8 * s);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        for (EClass eClass : eClasses) {
            long oid = startOids.get(eClass);
            if (!DatabaseSession.perRecordVersioning(eClass)) {
                buffer.putLong(oid);
            }
        }
        if (startOids.containsKey(GeometryPackage.eINSTANCE.getGeometryInfo()) && startOids.containsKey(GeometryPackage.eINSTANCE.getGeometryData())) {
            buffer.putLong(startOids.get(GeometryPackage.eINSTANCE.getGeometryInfo()));
            buffer.putLong(startOids.get(GeometryPackage.eINSTANCE.getGeometryData()));
        }
        concreteRevision = result.getConcreteRevision();
        concreteRevision.setOidCounters(buffer.array());
        // Clear the cache, we don't want it to cache incomplete oidcounters
        ConcreteRevisionStackFrame.clearCache(concreteRevision.getOid());
        result.getConcreteRevision().setSize(size);
        for (Revision revision : result.getRevisions()) {
            revision.setSize((revision.getSize() == null ? 0 : revision.getSize()) + concreteRevision.getSize());
        }
        IfcHeader ifcHeader = deserializer.getIfcHeader();
        if (ifcHeader != null) {
            getDatabaseSession().store(ifcHeader);
            concreteRevision.setIfcHeader(ifcHeader);
        }
        project.getConcreteRevisions().add(concreteRevision);
        // if (getModel() != null) {
        // concreteRevision.setChecksum(getModel().getModelMetaData().getChecksum());
        // }
        final NewRevisionAdded newRevisionAdded = getDatabaseSession().create(NewRevisionAdded.class);
        newRevisionAdded.setDate(new Date());
        newRevisionAdded.setExecutor(user);
        final Revision revision = concreteRevision.getRevisions().get(0);
        if (newServiceId != -1) {
            NewService newService = getDatabaseSession().get(newServiceId, OldQuery.getDefault());
            revision.getServicesLinked().add(newService);
        }
        concreteRevision.setSummary(new SummaryMap(packageMetaData, deserializer.getSummaryMap()).toRevisionSummary(getDatabaseSession()));
        // If this revision is being created by an external service, store a link to the service in the revision
        if (authorization instanceof ExplicitRightsAuthorization) {
            ExplicitRightsAuthorization explicitRightsAuthorization = (ExplicitRightsAuthorization) authorization;
            if (explicitRightsAuthorization.getSoid() != -1) {
                Service service = getDatabaseSession().get(explicitRightsAuthorization.getSoid(), org.bimserver.database.OldQuery.getDefault());
                revision.setService(service);
            }
        }
        newRevisionAdded.setRevision(revision);
        newRevisionAdded.setProject(project);
        newRevisionAdded.setAccessMethod(getAccessMethod());
        if (nrConcreteRevisionsBefore != 0) {
            // There already was a revision, lets delete it (only when not merging)
            concreteRevision.setClear(true);
        }
        ExtendedData extendedData = getDatabaseSession().create(ExtendedData.class);
        File file = getDatabaseSession().create(File.class);
        byte[] bytes = report.toHtml().getBytes(Charsets.UTF_8);
        file.setData(bytes);
        file.setFilename("geometrygenerationreport.html");
        file.setMime("text/html");
        file.setSize(bytes.length);
        User actingUser = getUserByUoid(authorization.getUoid());
        extendedData.setUser(actingUser);
        extendedData.setTitle("Geometry generation report");
        extendedData.setAdded(new Date());
        extendedData.setSize(file.getData().length);
        extendedData.setFile(file);
        revision.getExtendedData().add(extendedData);
        extendedData.setProject(revision.getProject());
        extendedData.setRevision(revision);
        getDatabaseSession().store(file);
        getDatabaseSession().store(extendedData);
        if (extendedData.getSchema() != null) {
            getDatabaseSession().store(extendedData.getSchema());
        }
        getDatabaseSession().addPostCommitAction(new PostCommitAction() {

            @Override
            public void execute() throws UserException {
                bimServer.getNotificationsManager().notify(new NewRevisionNotification(bimServer, project.getOid(), revision.getOid(), authorization));
            }
        });
        getDatabaseSession().store(concreteRevision);
        getDatabaseSession().store(project);
    } catch (Throwable e) {
        if (e instanceof BimserverDatabaseException) {
            throw (BimserverDatabaseException) e;
        }
        if (e instanceof UserException) {
            throw (UserException) e;
        }
        throw new UserException(e);
    } finally {
        bimServer.getCheckinsInProgress().remove(poid);
    }
    return concreteRevision;
}
Also used : User(org.bimserver.models.store.User) HashMap(java.util.HashMap) RestartableInputStream(org.bimserver.webservices.impl.RestartableInputStream) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) GeometryGenerationReport(org.bimserver.geometry.GeometryGenerationReport) ExplicitRightsAuthorization(org.bimserver.webservices.authorization.ExplicitRightsAuthorization) UserException(org.bimserver.shared.exceptions.UserException) NewRevisionAdded(org.bimserver.models.log.NewRevisionAdded) NewService(org.bimserver.models.store.NewService) ExtendedData(org.bimserver.models.store.ExtendedData) PostCommitAction(org.bimserver.database.PostCommitAction) StreamingGeometryGenerator(org.bimserver.geometry.StreamingGeometryGenerator) Service(org.bimserver.models.store.Service) NewService(org.bimserver.models.store.NewService) QueryContext(org.bimserver.shared.QueryContext) ByteBuffer(java.nio.ByteBuffer) IfcHeader(org.bimserver.models.store.IfcHeader) Date(java.util.Date) AtomicLong(java.util.concurrent.atomic.AtomicLong) ByteProgressReporter(org.bimserver.plugins.deserializers.ByteProgressReporter) NewRevisionNotification(org.bimserver.notifications.NewRevisionNotification) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) SummaryMap(org.bimserver.SummaryMap) GenerateGeometryResult(org.bimserver.GenerateGeometryResult) AtomicLong(java.util.concurrent.atomic.AtomicLong) File(org.bimserver.models.store.File)

Aggregations

File (org.bimserver.models.store.File)5 UserException (org.bimserver.shared.exceptions.UserException)4 Date (java.util.Date)3 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)3 Revision (org.bimserver.models.store.Revision)3 User (org.bimserver.models.store.User)3 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 MessagingException (javax.mail.MessagingException)2 AddressException (javax.mail.internet.AddressException)2 GenerateGeometryResult (org.bimserver.GenerateGeometryResult)2 DatabaseSession (org.bimserver.database.DatabaseSession)2 PostCommitAction (org.bimserver.database.PostCommitAction)2 GeometryGenerationReport (org.bimserver.geometry.GeometryGenerationReport)2 StreamingGeometryGenerator (org.bimserver.geometry.StreamingGeometryGenerator)2 SFile (org.bimserver.interfaces.objects.SFile)2 CannotBeScheduledException (org.bimserver.longaction.CannotBeScheduledException)2 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)2 ExtendedData (org.bimserver.models.store.ExtendedData)2