Search in sources :

Example 21 with SProject

use of org.bimserver.interfaces.objects.SProject in project BIMserver by opensourceBIM.

the class GetLogs method getProject.

private SProject getProject(long poid) throws ServerException, UserException, PublicInterfaceNotFoundException {
    SProject project = projects.get(poid);
    if (project == null) {
        project = client.getServiceInterface().getProjectByPoid(poid);
        projects.put(poid, project);
    }
    return project;
}
Also used : SProject(org.bimserver.interfaces.objects.SProject)

Example 22 with SProject

use of org.bimserver.interfaces.objects.SProject in project BIMserver by opensourceBIM.

the class TestBigModelEmf method test.

@Test
public void test() {
    try {
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        IfcModelInterface model = bimServerClient.newModel(newProject, true);
        RichIfcModel richIfcModel = new RichIfcModel(model);
        IfcBuilding ifcBuilding = richIfcModel.createDefaultProjectStructure();
        IfcRelAggregates buildingAggregation = richIfcModel.create(IfcRelAggregates.class);
        buildingAggregation.setRelatingObject(ifcBuilding);
        for (int i = 1; i <= 10; i++) {
            IfcBuildingStorey ifcBuildingStorey = richIfcModel.create(IfcBuildingStorey.class);
            ifcBuildingStorey.setName("Storey " + i);
            ifcBuildingStorey.setCompositionType(IfcElementCompositionEnum.ELEMENT);
            ifcBuildingStorey.setElevation(3000 * i);
            IfcLocalPlacement storeyPlacement = richIfcModel.create(IfcLocalPlacement.class);
            storeyPlacement.setRelativePlacement(richIfcModel.createBasicPosition(0, 0, i * 3000));
            ifcBuildingStorey.setObjectPlacement(storeyPlacement);
            buildingAggregation.getRelatedObjects().add(ifcBuildingStorey);
            IfcRelAggregates storeyAggregation = richIfcModel.create(IfcRelAggregates.class);
            storeyAggregation.setRelatingObject(ifcBuildingStorey);
            for (int x = 1; x <= 10; x++) {
                for (int y = 1; y <= 10; y++) {
                    createSpace(richIfcModel, richIfcModel.getDefaultRepresentationContext(), storeyPlacement, storeyAggregation, x, y);
                }
            }
        }
        long roid = model.commit("Initial model");
        SSerializerPluginConfiguration serializerByContentType = bimServerClient.getServiceInterface().getSerializerByName("Ifc2x3tc1 (Streaming)");
        bimServerClient.download(roid, serializerByContentType.getOid(), new FileOutputStream(new File("created.ifc")));
    } catch (Throwable e) {
        e.printStackTrace();
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        fail(e.getMessage());
    }
}
Also used : RichIfcModel(org.bimserver.utils.RichIfcModel) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) SProject(org.bimserver.interfaces.objects.SProject) IfcRelAggregates(org.bimserver.models.ifc2x3tc1.IfcRelAggregates) IfcLocalPlacement(org.bimserver.models.ifc2x3tc1.IfcLocalPlacement) FileOutputStream(java.io.FileOutputStream) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) IfcBuildingStorey(org.bimserver.models.ifc2x3tc1.IfcBuildingStorey) File(java.io.File) IfcBuilding(org.bimserver.models.ifc2x3tc1.IfcBuilding) Test(org.junit.Test)

Example 23 with SProject

use of org.bimserver.interfaces.objects.SProject in project BIMserver by opensourceBIM.

the class TestChangeGeometryError 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");
        // Look for a deserializer
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
        bimServerClient.checkin(newProject.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), false, true, true);
        List<IfcWall> walls = model.getAllWithSubTypes(Ifc2x3tc1Package.eINSTANCE.getIfcWall());
        IfcWall firstWall = walls.get(0);
        firstWall.getGeometry().getData().setVertices(new byte[10]);
        model.commit("Tried to change geometry, which should not be possible");
        fail("This have thrown an error");
    } catch (Throwable e) {
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        e.printStackTrace();
        assertEquals("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (GeometryData) is from the \"geometry\" package", e.getMessage());
    }
}
Also used : IfcWall(org.bimserver.models.ifc2x3tc1.IfcWall) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) Test(org.junit.Test)

Example 24 with SProject

use of org.bimserver.interfaces.objects.SProject in project BIMserver by opensourceBIM.

the class TestConstantlyDownloading method main.

public static void main(String[] args) {
    long poid = 196609;
    try {
        BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
        for (int i = 0; i < 200; i++) {
            SProject project = client.getServiceInterface().getProjectByPoid(poid);
            long roid = project.getLastRevisionId();
            SSerializerPluginConfiguration serializer = client.getPluginInterface().getSerializerByPluginClassName("org.bimserver.geometry.json.JsonGeometrySerializerPlugin");
            System.out.println(i);
            client.download(roid, serializer.getOid(), new ByteArrayOutputStream());
        }
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (BimServerClientException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ServiceException(org.bimserver.shared.exceptions.ServiceException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SProject(org.bimserver.interfaces.objects.SProject) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException)

Example 25 with SProject

use of org.bimserver.interfaces.objects.SProject in project BIMserver by opensourceBIM.

the class SyndicationServlet method writeCheckoutsFeed.

private void writeCheckoutsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws ServiceException, IOException, FeedException, PublicInterfaceNotFoundException {
    long poid = Long.parseLong(request.getParameter("poid"));
    SProject sProject = serviceMap.getServiceInterface().getProjectByPoid(poid);
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType(FEED_TYPE);
    feed.setTitle("BIMserver.org checkouts feed for project '" + sProject.getName() + "'");
    feed.setLink(request.getContextPath());
    feed.setDescription("This feed represents all the checkouts of project '" + sProject.getName() + "'");
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    try {
        List<SCheckout> allCheckoutsOfProject = serviceMap.getServiceInterface().getAllCheckoutsOfProjectAndSubProjects(poid);
        for (SCheckout sCheckout : allCheckoutsOfProject) {
            SRevision revision = serviceMap.getServiceInterface().getRevision(sCheckout.getRevision().getOid());
            SProject project = serviceMap.getServiceInterface().getProjectByPoid(sCheckout.getProjectId());
            SUser user = serviceMap.getServiceInterface().getUserByUoid(sCheckout.getUserId());
            SyndEntry entry = new SyndEntryImpl();
            entry.setTitle("Checkout on " + project.getName() + ", revision " + revision.getId());
            entry.setLink(request.getContextPath() + "/project.jsp?poid=" + sProject.getOid());
            entry.setPublishedDate(sCheckout.getDate());
            SyndContent description = new SyndContentImpl();
            description.setType("text/plain");
            description.setValue("<table><tr><td>User</td><td>" + user.getUsername() + "</td></tr><tr><td>Revision</td><td>" + sCheckout.getRevision().getOid() + "</td></tr></table>");
            entry.setDescription(description);
            entries.add(entry);
        }
    } catch (UserException e) {
        LOGGER.error("", e);
    }
    feed.setEntries(entries);
    SyndFeedOutput output = new SyndFeedOutput();
    output.output(feed, response.getWriter());
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) SUser(org.bimserver.interfaces.objects.SUser) ArrayList(java.util.ArrayList) SyndFeedOutput(com.rometools.rome.io.SyndFeedOutput) SProject(org.bimserver.interfaces.objects.SProject) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SRevision(org.bimserver.interfaces.objects.SRevision) SyndContent(com.rometools.rome.feed.synd.SyndContent) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) UserException(org.bimserver.shared.exceptions.UserException) SCheckout(org.bimserver.interfaces.objects.SCheckout)

Aggregations

SProject (org.bimserver.interfaces.objects.SProject)79 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)57 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)45 Test (org.junit.Test)39 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)37 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)24 UserException (org.bimserver.shared.exceptions.UserException)24 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)22 IOException (java.io.IOException)21 IfcModelInterface (org.bimserver.emf.IfcModelInterface)21 ServerException (org.bimserver.shared.exceptions.ServerException)20 URL (java.net.URL)19 LowLevelInterface (org.bimserver.shared.interfaces.LowLevelInterface)18 ServiceException (org.bimserver.shared.exceptions.ServiceException)16 BimServerClientException (org.bimserver.shared.exceptions.BimServerClientException)12 Path (java.nio.file.Path)10 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)9 DatabaseSession (org.bimserver.database.DatabaseSession)8 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)7 SerializerException (org.bimserver.plugins.serializers.SerializerException)7