Search in sources :

Example 51 with IfcModelInterface

use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.

the class TestCreateGuid method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Create a new project
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        IfcModelInterface model = bimServerClient.newModel(newProject, true);
        IfcFurnishingElement furnishing = model.create(Ifc2x3tc1Package.eINSTANCE.getIfcFurnishingElement());
        furnishing.setGlobalId("0uyjn9Jan3nRq36Uj6gwws");
        long roid = model.commit("Initial model");
        IfcModelInterface newModel = bimServerClient.getModel(newProject, roid, true, false);
        List<IfcFurnishingElement> furnishingElements = newModel.getAllWithSubTypes(Ifc2x3tc1Package.eINSTANCE.getIfcFurnishingElement());
        assertTrue("There must be 1 furnishing element, not " + furnishingElements.size(), furnishingElements.size() == 1);
        IfcFurnishingElement newF = furnishingElements.get(0);
        assertTrue("GUID must be 0uyjn9Jan3nRq36Uj6gwws", newF.getGlobalId().equals("0uyjn9Jan3nRq36Uj6gwws"));
    } catch (Throwable e) {
        e.printStackTrace();
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        fail(e.getMessage());
    }
}
Also used : IfcFurnishingElement(org.bimserver.models.ifc2x3tc1.IfcFurnishingElement) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SProject(org.bimserver.interfaces.objects.SProject) Test(org.junit.Test)

Example 52 with IfcModelInterface

use of org.bimserver.emf.IfcModelInterface 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)

Example 53 with IfcModelInterface

use of org.bimserver.emf.IfcModelInterface 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();
    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) 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 54 with IfcModelInterface

use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.

the class ExtractFurniture method main.

public static void main(String[] args) {
    try {
        Path home = Paths.get("home");
        PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(home);
        DeserializerPlugin deserializerPlugin = pluginManager.getFirstDeserializer("ifc", Schema.IFC2X3TC1, true);
        Deserializer deserializer = deserializerPlugin.createDeserializer(null);
        MetaDataManager metaDataManager = new MetaDataManager(home.resolve("tmp"));
        PackageMetaData packageMetaData = metaDataManager.getPackageMetaData("ifc2x3tc1");
        deserializer.init(packageMetaData);
        IfcModelInterface model = DeserializerUtils.readFromFile(deserializer, Paths.get("../TestData/data/ADT-FZK-Haus-2005-2006.ifc"));
        model.fixOids(new IncrementingOidProvider());
        IfcFurnishingElement picknick = (IfcFurnishingElement) model.getByName(Ifc2x3tc1Package.eINSTANCE.getIfcFurnishingElement(), "Picknik Bank");
        IfcModelInterface newModel = new BasicIfcModel(packageMetaData, null);
        ModelHelper modelHelper = new ModelHelper(pluginManager.getMetaDataManager(), new HideAllInversesObjectIDM(CollectionUtils.singleSet(Ifc2x3tc1Package.eINSTANCE), pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1")), newModel);
        modelHelper.copy(picknick, false);
        SerializerPlugin serializerPlugin = pluginManager.getSerializerPlugin("org.bimserver.ifc.step.serializer.IfcStepSerializerPlugin", true);
        Serializer serializer = serializerPlugin.createSerializer(null);
        serializer.init(newModel, null, true);
        SerializerUtils.writeToFile(serializer, Paths.get("test.ifc"));
    } catch (PluginException e) {
        e.printStackTrace();
    } catch (DeserializeException e) {
        e.printStackTrace();
    } catch (IfcModelInterfaceException e) {
        e.printStackTrace();
    } catch (SerializerException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) ModelHelper(org.bimserver.plugins.ModelHelper) IfcFurnishingElement(org.bimserver.models.ifc2x3tc1.IfcFurnishingElement) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcModelInterface(org.bimserver.emf.IfcModelInterface) PluginException(org.bimserver.shared.exceptions.PluginException) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) FileNotFoundException(java.io.FileNotFoundException) MetaDataManager(org.bimserver.emf.MetaDataManager) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) IOException(java.io.IOException) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) SerializerException(org.bimserver.plugins.serializers.SerializerException) PluginManager(org.bimserver.plugins.PluginManager) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) Deserializer(org.bimserver.plugins.deserializers.Deserializer) HideAllInversesObjectIDM(org.bimserver.plugins.objectidms.HideAllInversesObjectIDM) IncrementingOidProvider(org.bimserver.shared.IncrementingOidProvider) Serializer(org.bimserver.plugins.serializers.Serializer)

Example 55 with IfcModelInterface

use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.

the class TestChangeDescription method start.

private void start() {
    BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
    try {
        SProject project = client.getServiceInterface().getProjectsByName("dfgfgdf").get(0);
        IfcModelInterface model = client.getModel(project, project.getLastRevisionId(), false, true);
        for (IfcWall wall : model.getAllWithSubTypes(IfcWall.class)) {
            wall.setDescription(wall.getDescription() + " Changed");
        }
        model.commit("test");
    } catch (UserException e) {
        e.printStackTrace();
    } catch (ServerException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (BimServerClientException e) {
        e.printStackTrace();
    }
}
Also used : IfcWall(org.bimserver.models.ifc2x3tc1.IfcWall) ServerException(org.bimserver.shared.exceptions.ServerException) IfcModelInterface(org.bimserver.emf.IfcModelInterface) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) UserException(org.bimserver.shared.exceptions.UserException) SProject(org.bimserver.interfaces.objects.SProject) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException)

Aggregations

IfcModelInterface (org.bimserver.emf.IfcModelInterface)58 SProject (org.bimserver.interfaces.objects.SProject)22 UserException (org.bimserver.shared.exceptions.UserException)21 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)20 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)17 Test (org.junit.Test)17 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)16 PackageMetaData (org.bimserver.emf.PackageMetaData)15 URL (java.net.URL)14 Revision (org.bimserver.models.store.Revision)14 User (org.bimserver.models.store.User)14 ModelHelper (org.bimserver.plugins.ModelHelper)13 OldQuery (org.bimserver.database.OldQuery)12 Project (org.bimserver.models.store.Project)12 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 IdEObject (org.bimserver.emf.IdEObject)11 DatabaseSession (org.bimserver.database.DatabaseSession)10 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)10 IfcModelSet (org.bimserver.plugins.IfcModelSet)10