Search in sources :

Example 1 with NewRevisionCallback

use of org.bimserver.shared.interfaces.async.AsyncRemoteServiceInterface.NewRevisionCallback in project BIMserver by opensourceBIM.

the class NewExtendedDataOnRevisionNotification method triggerNewExtendedData.

public void triggerNewExtendedData(DatabaseSession session, NotificationsManager notificationsManager, final BimServer bimServer, String siteAddress, Project project, final long roid, Trigger trigger, final Service service) throws UserException, ServerException {
    if (service.getTrigger() == trigger) {
        Channel channel = null;
        try {
            channel = notificationsManager.getChannel(service);
            final RemoteServiceInterface remoteServiceInterface = channel.get(RemoteServiceInterface.class);
            long writeProjectPoid = service.getWriteRevision() == null ? -1 : service.getWriteRevision().getOid();
            long writeExtendedDataRoid = service.getWriteExtendedData() != null ? roid : -1;
            long readRevisionRoid = service.isReadRevision() ? roid : -1;
            long readExtendedDataRoid = service.getReadExtendedData() != null ? roid : -1;
            final ExplicitRightsAuthorization authorization = new ExplicitRightsAuthorization(bimServer, service.getUser().getOid(), service.getOid(), new long[] { readRevisionRoid }, writeProjectPoid, readExtendedDataRoid, writeExtendedDataRoid);
            ServiceInterface newService = bimServer.getServiceFactory().get(authorization, AccessMethod.INTERNAL).get(ServiceInterface.class);
            // TODO redundant?
            ((org.bimserver.webservices.impl.ServiceImpl) newService).setAuthorization(authorization);
            AsyncRemoteServiceInterface asyncRemoteServiceInterface = new AsyncRemoteServiceInterface(remoteServiceInterface, bimServer.getExecutorService());
            asyncRemoteServiceInterface.newExtendedDataOnRevision(poid, roid, edid, soid, service.getServiceIdentifier(), service.getProfileIdentifier(), service.getToken(), authorization.asHexToken(bimServer.getEncryptionKey()), bimServer.getServerSettingsCache().getServerSettings().getSiteAddress(), new NewExtendedDataOnRevisionCallback() {

                @Override
                public void success() {
                }

                @Override
                public void error(Throwable e) {
                    LOGGER.error("", e);
                }
            });
            asyncRemoteServiceInterface.newRevision(poid, roid, service.getOid(), service.getServiceIdentifier(), service.getProfileIdentifier(), service.getToken(), authorization.asHexToken(bimServer.getEncryptionKey()), bimServer.getServerSettingsCache().getServerSettings().getSiteAddress(), new NewRevisionCallback() {

                @Override
                public void success() {
                }

                @Override
                public void error(Throwable e) {
                    LOGGER.error("", e);
                }
            });
        } catch (ChannelConnectionException e) {
            LOGGER.error("", e);
        } catch (PublicInterfaceNotFoundException e) {
            LOGGER.error("", e);
        } finally {
            if (channel != null) {
                // TODO This is interesting, when sending async, is this not going to break?
                channel.disconnect();
            }
        }
    }
}
Also used : AsyncRemoteServiceInterface(org.bimserver.shared.interfaces.async.AsyncRemoteServiceInterface) RemoteServiceInterface(org.bimserver.shared.interfaces.RemoteServiceInterface) NewRevisionCallback(org.bimserver.shared.interfaces.async.AsyncRemoteServiceInterface.NewRevisionCallback) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) Channel(org.bimserver.client.Channel) AsyncRemoteServiceInterface(org.bimserver.shared.interfaces.async.AsyncRemoteServiceInterface) ExplicitRightsAuthorization(org.bimserver.webservices.authorization.ExplicitRightsAuthorization) AsyncRemoteServiceInterface(org.bimserver.shared.interfaces.async.AsyncRemoteServiceInterface) ServiceInterface(org.bimserver.shared.interfaces.ServiceInterface) RemoteServiceInterface(org.bimserver.shared.interfaces.RemoteServiceInterface) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) NewExtendedDataOnRevisionCallback(org.bimserver.shared.interfaces.async.AsyncRemoteServiceInterface.NewExtendedDataOnRevisionCallback)

Example 2 with NewRevisionCallback

use of org.bimserver.shared.interfaces.async.AsyncRemoteServiceInterface.NewRevisionCallback in project BIMserver by opensourceBIM.

the class NewRevisionNotification method triggerNewRevision.

public void triggerNewRevision(DatabaseSession session, NotificationsManager notificationsManager, final BimServer bimServer, String siteAddress, Project project, final long roid, Trigger trigger, final Service service) throws UserException, ServerException {
    if (service.getTrigger() == trigger) {
        Channel channel = null;
        try {
            IfcModelInterface model = null;
            for (ModelCheckerInstance modelCheckerInstance : service.getModelCheckers()) {
                if (modelCheckerInstance.isValid()) {
                    ModelCheckerPlugin modelCheckerPlugin = bimServer.getPluginManager().getModelCheckerPlugin(modelCheckerInstance.getModelCheckerPluginClassName(), true);
                    if (modelCheckerPlugin != null) {
                        ModelChecker modelChecker = modelCheckerPlugin.createModelChecker(null);
                        ModelCheckerResult result;
                        try {
                            if (model == null) {
                                PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(project.getSchema());
                                model = new BasicIfcModel(packageMetaData, null);
                                Revision revision;
                                try {
                                    revision = session.get(roid, OldQuery.getDefault());
                                    session.getMap(model, new OldQuery(packageMetaData, project.getId(), revision.getId(), revision.getOid(), null, Deep.NO));
                                } catch (BimserverDatabaseException e) {
                                    LOGGER.error("", e);
                                }
                            }
                            result = modelChecker.check(model, modelCheckerInstance.getCompiled());
                            if (!result.isValid()) {
                                LOGGER.info("Not triggering");
                                return;
                            }
                        } catch (ModelCheckException e) {
                            LOGGER.info("Not triggering");
                            return;
                        }
                    }
                }
            }
            channel = notificationsManager.getChannel(service);
            final RemoteServiceInterface remoteServiceInterface = channel.get(RemoteServiceInterface.class);
            long writeProjectPoid = service.getWriteRevision() == null ? -1 : service.getWriteRevision().getOid();
            long writeExtendedDataRoid = service.getWriteExtendedData() != null ? roid : -1;
            @SuppressWarnings("unused") long readRevisionRoid = service.isReadRevision() ? roid : -1;
            long readExtendedDataRoid = service.getReadExtendedData() != null ? roid : -1;
            List<Long> roidsList = new ArrayList<>();
            Set<Project> relatedProjects = getRelatedProjects(project);
            for (Project p : relatedProjects) {
                for (Revision revision : p.getRevisions()) {
                    roidsList.add(revision.getOid());
                }
            }
            long[] roids = new long[roidsList.size()];
            for (int i = 0; i < roids.length; i++) {
                roids[i] = roidsList.get(i);
            }
            final ExplicitRightsAuthorization authorization = new ExplicitRightsAuthorization(bimServer, service.getUser().getOid(), service.getOid(), service.isReadRevision() ? roids : new long[0], writeProjectPoid, readExtendedDataRoid, writeExtendedDataRoid);
            ServiceInterface newService = bimServer.getServiceFactory().get(authorization, AccessMethod.INTERNAL).get(ServiceInterface.class);
            // TODO redundant?
            ((org.bimserver.webservices.impl.ServiceImpl) newService).setAuthorization(authorization);
            AsyncRemoteServiceInterface asyncRemoteServiceInterface = new AsyncRemoteServiceInterface(remoteServiceInterface, bimServer.getExecutorService());
            asyncRemoteServiceInterface.newRevision(poid, roid, service.getOid(), service.getServiceIdentifier(), service.getProfileIdentifier(), service.getToken(), authorization.asHexToken(bimServer.getEncryptionKey()), bimServer.getServerSettingsCache().getServerSettings().getSiteAddress(), new NewRevisionCallback() {

                @Override
                public void success() {
                }

                @Override
                public void error(Throwable e) {
                    LOGGER.error("", e);
                }
            });
        } catch (ChannelConnectionException e) {
            LOGGER.error("", e);
        } catch (PublicInterfaceNotFoundException e) {
            LOGGER.error("", e);
        } finally {
            if (channel != null) {
                // TODO This is interesting, when sending async, is this not going to break?
                channel.disconnect();
            }
        }
    }
}
Also used : RemoteServiceInterface(org.bimserver.shared.interfaces.RemoteServiceInterface) AsyncRemoteServiceInterface(org.bimserver.shared.interfaces.async.AsyncRemoteServiceInterface) NewRevisionCallback(org.bimserver.shared.interfaces.async.AsyncRemoteServiceInterface.NewRevisionCallback) IfcModelInterface(org.bimserver.emf.IfcModelInterface) ArrayList(java.util.ArrayList) AsyncRemoteServiceInterface(org.bimserver.shared.interfaces.async.AsyncRemoteServiceInterface) ModelCheckerResult(org.bimserver.models.store.ModelCheckerResult) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) ModelChecker(org.bimserver.plugins.modelchecker.ModelChecker) ExplicitRightsAuthorization(org.bimserver.webservices.authorization.ExplicitRightsAuthorization) RemoteServiceInterface(org.bimserver.shared.interfaces.RemoteServiceInterface) ServiceInterface(org.bimserver.shared.interfaces.ServiceInterface) AsyncRemoteServiceInterface(org.bimserver.shared.interfaces.async.AsyncRemoteServiceInterface) ModelCheckerInstance(org.bimserver.models.store.ModelCheckerInstance) ModelCheckerPlugin(org.bimserver.plugins.modelchecker.ModelCheckerPlugin) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) PackageMetaData(org.bimserver.emf.PackageMetaData) Channel(org.bimserver.client.Channel) ModelCheckException(org.bimserver.plugins.modelchecker.ModelCheckException) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) OldQuery(org.bimserver.database.OldQuery) Project(org.bimserver.models.store.Project) Revision(org.bimserver.models.store.Revision) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)

Aggregations

Channel (org.bimserver.client.Channel)2 ChannelConnectionException (org.bimserver.shared.ChannelConnectionException)2 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)2 RemoteServiceInterface (org.bimserver.shared.interfaces.RemoteServiceInterface)2 ServiceInterface (org.bimserver.shared.interfaces.ServiceInterface)2 AsyncRemoteServiceInterface (org.bimserver.shared.interfaces.async.AsyncRemoteServiceInterface)2 NewRevisionCallback (org.bimserver.shared.interfaces.async.AsyncRemoteServiceInterface.NewRevisionCallback)2 ExplicitRightsAuthorization (org.bimserver.webservices.authorization.ExplicitRightsAuthorization)2 ArrayList (java.util.ArrayList)1 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)1 OldQuery (org.bimserver.database.OldQuery)1 IfcModelInterface (org.bimserver.emf.IfcModelInterface)1 PackageMetaData (org.bimserver.emf.PackageMetaData)1 BasicIfcModel (org.bimserver.ifc.BasicIfcModel)1 ModelCheckerInstance (org.bimserver.models.store.ModelCheckerInstance)1 ModelCheckerResult (org.bimserver.models.store.ModelCheckerResult)1 Project (org.bimserver.models.store.Project)1 Revision (org.bimserver.models.store.Revision)1 ModelCheckException (org.bimserver.plugins.modelchecker.ModelCheckException)1 ModelChecker (org.bimserver.plugins.modelchecker.ModelChecker)1