Search in sources :

Example 1 with Service

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

the class AddServiceToProjectDatabaseAction method execute.

@Override
public Long 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");
        }
    }
    project.getServices().add(service);
    service.setProject(project);
    long serviceOid = getDatabaseSession().store(service);
    getDatabaseSession().store(project);
    return serviceOid;
}
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 2 with Service

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

the class CheckinDatabaseAction method execute.

@Override
public ConcreteRevision execute() throws UserException, BimserverDatabaseException {
    try {
        bimServer.getCheckinsInProgress().put(poid, getActingUid());
        if (fileSize == -1) {
            setProgress("Deserializing IFC file...", -1);
        } else {
            setProgress("Deserializing IFC file...", 0);
        }
        if (getModel().size() == 0) {
            throw new DeserializeException("Cannot checkin empty model");
        }
        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, getModel());
        }
        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(), size, project, user, comment.trim());
        concreteRevision = result.getConcreteRevision();
        IfcHeader ifcHeader = getModel().getModelMetaData().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(getModel()).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(), OldQuery.getDefault());
                revision.setService(service);
            }
        }
        newRevisionAdded.setRevision(revision);
        newRevisionAdded.setProject(project);
        newRevisionAdded.setAccessMethod(getAccessMethod());
        Revision lastRevision = project.getLastRevision();
        IfcModelInterface ifcModel = null;
        if (merge && lastRevision != null) {
            ifcModel = checkinMerge(lastRevision);
        } else {
            ifcModel = getModel();
        }
        ifcModel.fixOidsFlat(getDatabaseSession());
        if (bimServer.getServerSettingsCache().getServerSettings().isGenerateGeometryOnCheckin()) {
            setProgress("Generating Geometry...", -1);
            UserSettings userSettings = user.getUserSettings();
            RenderEnginePluginConfiguration defaultRenderEngine = userSettings.getDefaultRenderEngine();
            if (defaultRenderEngine == null) {
                throw new UserException("No default render engine has been selected for this user");
            }
            RenderEnginePool pool = bimServer.getRenderEnginePools().getRenderEnginePool(model.getPackageMetaData().getSchema(), defaultRenderEngine.getPluginDescriptor().getPluginClassName(), new PluginConfiguration(defaultRenderEngine.getSettings()));
            GenerateGeometryResult generateGeometry = new GeometryGenerator(bimServer).generateGeometry(pool, bimServer.getPluginManager(), getDatabaseSession(), ifcModel, project.getId(), concreteRevision.getId(), true, geometryCache);
            concreteRevision.setMinBounds(generateGeometry.getMinBoundsAsVector3f());
            concreteRevision.setMaxBounds(generateGeometry.getMaxBoundsAsVector3f());
            for (Revision other : concreteRevision.getRevisions()) {
                other.setHasGeometry(true);
            }
        }
        if (nrConcreteRevisionsBefore != 0 && !merge) {
            // There already was a revision, lets delete it (only when not merging)
            concreteRevision.setClear(true);
        }
        Set<EClass> eClasses = ifcModel.getUsedClasses();
        Map<EClass, Long> startOids = getDatabaseSession().getStartOids();
        if (startOids == null) {
            throw new BimserverDatabaseException("No objects changed");
        }
        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) {
            long oid = startOids.get(eClass);
            if (!DatabaseSession.perRecordVersioning(eClass)) {
                buffer.putLong(oid);
            }
        }
        concreteRevision.setOidCounters(buffer.array());
        if (ifcModel != null) {
            getDatabaseSession().store(ifcModel.getValues(), project.getId(), concreteRevision.getId());
        }
        getDatabaseSession().addPostCommitAction(new PostCommitAction() {

            @Override
            public void execute() throws UserException {
                bimServer.getCheckinsInProgress().remove(poid);
                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;
        }
        LOGGER.error("", e);
        throw new UserException(e);
    }
    return concreteRevision;
}
Also used : User(org.bimserver.models.store.User) RenderEnginePool(org.bimserver.renderengine.RenderEnginePool) IfcModelInterface(org.bimserver.emf.IfcModelInterface) ModelCheckerResult(org.bimserver.models.store.ModelCheckerResult) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) ModelChecker(org.bimserver.plugins.modelchecker.ModelChecker) EClass(org.eclipse.emf.ecore.EClass) ExplicitRightsAuthorization(org.bimserver.webservices.authorization.ExplicitRightsAuthorization) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) NewRevisionAdded(org.bimserver.models.log.NewRevisionAdded) NewService(org.bimserver.models.store.NewService) ModelCheckerInstance(org.bimserver.models.store.ModelCheckerInstance) ModelCheckerPlugin(org.bimserver.plugins.modelchecker.ModelCheckerPlugin) IdEObject(org.bimserver.emf.IdEObject) UserSettings(org.bimserver.models.store.UserSettings) PostCommitAction(org.bimserver.database.PostCommitAction) GeometryGenerator(org.bimserver.GeometryGenerator) Service(org.bimserver.models.store.Service) NewService(org.bimserver.models.store.NewService) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) IfcHeader(org.bimserver.models.store.IfcHeader) ByteBuffer(java.nio.ByteBuffer) Date(java.util.Date) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) 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)

Example 3 with Service

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

the class DeleteServiceDatabaseAction method execute.

@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Service object = getDatabaseSession().get(geteClass(), getOid(), OldQuery.getDefault());
    User user = object.getUser();
    user.getServices().remove(object);
    Project project = object.getProject();
    project.getServices().remove(object);
    getDatabaseSession().store(project);
    getDatabaseSession().store(user);
    return super.execute();
}
Also used : Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) Service(org.bimserver.models.store.Service)

Example 4 with Service

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

the class NewRevisionNotification method process.

@Override
public void process() throws BimserverDatabaseException, UserException, ServerException {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        Project project = session.get(StorePackage.eINSTANCE.getProject(), poid, OldQuery.getDefault());
        if (project == null) {
            LOGGER.error("Project with oid " + poid + " not found");
            return;
        }
        Revision revision = session.get(StorePackage.eINSTANCE.getRevision(), roid, OldQuery.getDefault());
        if (revision == null) {
            LOGGER.error("Revision with roid " + roid + " not found");
            return;
        }
        if (project.isSendEmailOnNewRevision() && sendEmail) {
            sendEmail(session, project, revision);
        }
        for (NewService newService : project.getNewServices()) {
            if (soid == -1 || newService.getOid() == soid) {
                triggerNewRevision(session, getBimServer().getNotificationsManager(), getBimServer(), getBimServer().getNotificationsManager().getSiteAddress(), project, roid, Trigger.NEW_REVISION, newService);
            }
        }
        for (Service service : project.getServices()) {
            if (soid == -1 || service.getOid() == soid) {
                triggerNewRevision(session, getBimServer().getNotificationsManager(), getBimServer(), getBimServer().getNotificationsManager().getSiteAddress(), project, roid, Trigger.NEW_REVISION, service);
            }
        }
        if (soid == -1) {
            // Only execute if we are not triggering a specific service with this notification
            NewRevisionTopic newRevisionTopic = getBimServer().getNotificationsManager().getNewRevisionTopic();
            if (newRevisionTopic != null) {
                newRevisionTopic.process(session, poid, roid, this);
            }
            NewRevisionOnSpecificProjectTopic newRevisionOnSpecificProjectTopic = getBimServer().getNotificationsManager().getNewRevisionOnSpecificProjectTopic(new NewRevisionOnSpecificProjectTopicKey(poid));
            if (newRevisionOnSpecificProjectTopic != null) {
                newRevisionOnSpecificProjectTopic.process(session, poid, roid, this);
            }
        }
    } finally {
        session.close();
    }
}
Also used : Project(org.bimserver.models.store.Project) Revision(org.bimserver.models.store.Revision) DatabaseSession(org.bimserver.database.DatabaseSession) Service(org.bimserver.models.store.Service) NewService(org.bimserver.models.store.NewService) NewService(org.bimserver.models.store.NewService)

Example 5 with Service

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

the class RemoveServiceFromProjectDatabaseAction method execute.

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

Aggregations

Service (org.bimserver.models.store.Service)8 Project (org.bimserver.models.store.Project)5 User (org.bimserver.models.store.User)5 UserException (org.bimserver.shared.exceptions.UserException)4 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)3 NewService (org.bimserver.models.store.NewService)3 Revision (org.bimserver.models.store.Revision)3 EClass (org.eclipse.emf.ecore.EClass)3 ByteBuffer (java.nio.ByteBuffer)2 Date (java.util.Date)2 GenerateGeometryResult (org.bimserver.GenerateGeometryResult)2 SummaryMap (org.bimserver.SummaryMap)2 DatabaseSession (org.bimserver.database.DatabaseSession)2 PostCommitAction (org.bimserver.database.PostCommitAction)2 NewRevisionAdded (org.bimserver.models.log.NewRevisionAdded)2 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)2 IfcHeader (org.bimserver.models.store.IfcHeader)2 NewRevisionNotification (org.bimserver.notifications.NewRevisionNotification)2 ExplicitRightsAuthorization (org.bimserver.webservices.authorization.ExplicitRightsAuthorization)2 HashMap (java.util.HashMap)1