Search in sources :

Example 11 with ServiceException

use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.

the class SyndicationServlet method writeProjectsFeed.

private void writeProjectsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws UserException, IOException, FeedException, PublicInterfaceNotFoundException {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType(FEED_TYPE);
    feed.setTitle("BIMserver.org projects feed");
    feed.setLink(request.getContextPath());
    feed.setDescription("This feed represents all your available projects within this BIMserver");
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    try {
        List<SProject> allProjects = serviceMap.getServiceInterface().getAllProjects(false, true);
        for (SProject sProject : allProjects) {
            SyndEntry entry = new SyndEntryImpl();
            entry.setAuthor(serviceMap.getServiceInterface().getUserByUoid(sProject.getCreatedById()).getName());
            entry.setTitle(sProject.getName());
            entry.setLink(request.getContextPath() + "/project.jsp?poid=" + sProject.getOid());
            entry.setPublishedDate(sProject.getCreatedDate());
            SyndContent description = new SyndContentImpl();
            description.setType("text/plain");
            description.setValue(sProject.getDescription());
            entry.setDescription(description);
            entries.add(entry);
        }
        if (allProjects.size() == 0) {
            SyndEntry entry = new SyndEntryImpl();
            entry.setTitle("No projects found");
            entry.setLink(request.getContextPath() + "/main.jsp");
            entry.setPublishedDate(new Date());
            SyndContent description = new SyndContentImpl();
            description.setType("text/plain");
            description.setValue("No projects found");
            entry.setDescription(description);
            entries.add(entry);
        }
    } catch (ServiceException 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) ArrayList(java.util.ArrayList) SyndFeedOutput(com.rometools.rome.io.SyndFeedOutput) SProject(org.bimserver.interfaces.objects.SProject) Date(java.util.Date) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndContent(com.rometools.rome.feed.synd.SyndContent) ServiceException(org.bimserver.shared.exceptions.ServiceException) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl)

Example 12 with ServiceException

use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.

the class SyndicationServlet method service.

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (request.getHeader("Origin") != null && !getBimServer().getServerSettingsCache().isHostAllowed(request.getHeader("Origin"))) {
        response.setStatus(403);
        return;
    }
    if (request.getHeader("Authorization") != null) {
        String authorization = request.getHeader("Authorization");
        String usernamePasswordEncoded = authorization.substring(6);
        String decodeBase64 = new String(Base64.decodeBase64(usernamePasswordEncoded.getBytes(Charsets.UTF_8)), Charsets.UTF_8);
        if (decodeBase64.equals(":")) {
            response.getWriter().print("Not authenticated");
            return;
        }
        String[] split = decodeBase64.split(":");
        String username = split[0];
        String password = split[1];
        String token = (String) getServletContext().getAttribute("token");
        ServiceMap serviceMap = null;
        try {
            if (token == null) {
                serviceMap = getBimServer().getServiceFactory().get(AccessMethod.SYNDICATION);
            } else {
                serviceMap = getBimServer().getServiceFactory().get(token, AccessMethod.SYNDICATION);
            }
            if (serviceMap.getAuthInterface().login(username, password) != null) {
                String requestURI = request.getRequestURI();
                response.setContentType("application/atom+xml");
                try {
                    if (requestURI.endsWith("/projects")) {
                        writeProjectsFeed(request, response, serviceMap);
                    } else if (requestURI.contains("/revisions")) {
                        writeRevisionsFeed(request, response, serviceMap);
                    } else if (requestURI.contains("/checkouts")) {
                        writeCheckoutsFeed(request, response, serviceMap);
                    }
                } catch (ServiceException e) {
                    response.setContentType("text/html");
                    response.getWriter().println(e.getUserMessage());
                } catch (FeedException e) {
                    LOGGER.error("", e);
                }
            } else {
                response.setStatus(401);
                response.setHeader("WWW-Authenticate", "Basic realm=\"Secure Area\"");
            }
        } catch (ServiceException e) {
            LOGGER.error("", e);
        } catch (PublicInterfaceNotFoundException e) {
            LOGGER.error("", e);
        }
    } else {
        response.setStatus(401);
        response.setHeader("WWW-Authenticate", "Basic realm=\"Secure Area\"");
    }
}
Also used : ServiceMap(org.bimserver.webservices.ServiceMap) ServiceException(org.bimserver.shared.exceptions.ServiceException) FeedException(com.rometools.rome.io.FeedException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)

Example 13 with ServiceException

use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.

the class LongCheckinAction method execute.

public void execute() {
    DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
    try {
        checkinDatabaseAction.setDatabaseSession(session);
        session.setCleanupListener(new CleanupListener() {

            @Override
            public void cleanup() {
                try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.READ_WRITE)) {
                    Project project = tmpSession.get(checkinDatabaseAction.getPoid(), OldQuery.getDefault());
                    project.setCheckinInProgress(0);
                    tmpSession.store(project);
                    try {
                        tmpSession.commit();
                    } catch (ServiceException e2) {
                        LOGGER.error("", e2);
                    }
                } catch (BimserverDatabaseException e1) {
                    LOGGER.error("", e1);
                }
            }
        });
        session.executeAndCommitAction(checkinDatabaseAction, new ProgressHandler() {

            private int count;

            @Override
            public void progress(int current, int max) {
                if (count == 0) {
                    updateProgress("Saving to database (" + fileName + ")", current * 100 / max);
                } else {
                    updateProgress("Saving to database (" + fileName + ", " + count + " try)", current * 100 / max);
                }
            }

            @Override
            public void retry(int count) {
                this.count = count;
            }
        });
    } catch (Exception e) {
        if (e instanceof UserException) {
        } else if (e instanceof BimserverConcurrentModificationDatabaseException) {
        // Ignore
        } else {
            LOGGER.error("", e);
        }
        error(e);
    } finally {
        session.close();
        if (getActionState() != ActionState.AS_ERROR) {
            changeActionState(ActionState.FINISHED, "Checkin of " + fileName, 100);
        }
        done();
    }
}
Also used : Project(org.bimserver.models.store.Project) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) CleanupListener(org.bimserver.database.CleanupListener) ServiceException(org.bimserver.shared.exceptions.ServiceException) DatabaseSession(org.bimserver.database.DatabaseSession) ProgressHandler(org.bimserver.database.ProgressHandler) BimserverConcurrentModificationDatabaseException(org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException) UserException(org.bimserver.shared.exceptions.UserException) ServiceException(org.bimserver.shared.exceptions.ServiceException) BimserverConcurrentModificationDatabaseException(org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException) UserException(org.bimserver.shared.exceptions.UserException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 14 with ServiceException

use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.

the class ImportLargeProject method main.

public static void main(String[] args) {
    BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
    try {
        Path baseFolder = Paths.get("C:\\Users\\Ruben de Laat\\Documents\\ttt");
        ServiceInterface serviceInterface = client.getServiceInterface();
        SProject mainProject = serviceInterface.addProject("Tekla Demo Model", "ifc2x3tc1");
        SProject architectural = serviceInterface.addProjectAsSubProject("Architectural", mainProject.getOid(), "ifc2x3tc1");
        SProject teklaHouseArchitectural = serviceInterface.addProjectAsSubProject("Tekla House Architectural", architectural.getOid(), "ifc2x3tc1");
        SProject structuralSteal = serviceInterface.addProjectAsSubProject("Structural Steal", mainProject.getOid(), "ifc2x3tc1");
        SProject teklaHouseStructural = serviceInterface.addProjectAsSubProject("Tekla House Structural", structuralSteal.getOid(), "ifc2x3tc1");
        SProject foundation = serviceInterface.addProjectAsSubProject("Foundation", mainProject.getOid(), "ifc2x3tc1");
        SProject teklaHouseFoundationFootings = serviceInterface.addProjectAsSubProject("Tekla Hose Foundation Footings", foundation.getOid(), "ifc2x3tc1");
        SProject teklaHouseFoundationPiles = serviceInterface.addProjectAsSubProject("Tekla Hose Foundation Piles", foundation.getOid(), "ifc2x3tc1");
        SProject teklaHouseFoundationRebars = serviceInterface.addProjectAsSubProject("Tekla Hose Foundation Rebars", foundation.getOid(), "ifc2x3tc1");
        SProject teklaHouseFoundationEmbedments = serviceInterface.addProjectAsSubProject("Tekla Hose Foundation Embedments", foundation.getOid(), "ifc2x3tc1");
        SProject cipConcreteContractor = serviceInterface.addProjectAsSubProject("CIP Concrete Contractor", mainProject.getOid(), "ifc2x3tc1");
        serviceInterface.addProjectAsSubProject("Tekla House CIP Pours", cipConcreteContractor.getOid(), "ifc2x3tc1");
        SProject teklaHouseCIPRebars = serviceInterface.addProjectAsSubProject("Tekla House CIP Rebars", cipConcreteContractor.getOid(), "ifc2x3tc1");
        SProject teklaHouseCIPColumns = serviceInterface.addProjectAsSubProject("Tekla House CIP Columns", cipConcreteContractor.getOid(), "ifc2x3tc1");
        SProject formWork = serviceInterface.addProjectAsSubProject("Formwork", mainProject.getOid(), "ifc2x3tc1");
        serviceInterface.addProjectAsSubProject("Column Formwork", formWork.getOid(), "ifc2x3tc1");
        SProject precast = serviceInterface.addProjectAsSubProject("Precast", mainProject.getOid(), "ifc2x3tc1");
        SProject teklaHousePrecastRebars = serviceInterface.addProjectAsSubProject("Tekla House Precast Rebars", precast.getOid(), "ifc2x3tc1");
        SProject teklaHousePrecastConcrete = serviceInterface.addProjectAsSubProject("Tekla House Precast Concrete", precast.getOid(), "ifc2x3tc1");
        SProject mep = serviceInterface.addProjectAsSubProject("MEP", mainProject.getOid(), "ifc2x3tc1");
        SProject teklaHouseMEPGround = serviceInterface.addProjectAsSubProject("Teklas House MEP, Ground", mep.getOid(), "ifc2x3tc1");
        SProject teklaHouseMEP1 = serviceInterface.addProjectAsSubProject("Tekla House MEP, 1st", mep.getOid(), "ifc2x3tc1");
        SProject teklaHouseMEP2 = serviceInterface.addProjectAsSubProject("Tekla House MEP, 2nd", mep.getOid(), "ifc2x3tc1");
        SProject teklaHouseMEP3 = serviceInterface.addProjectAsSubProject("Tekla House MEP, 3rd", mep.getOid(), "ifc2x3tc1");
        SProject teklaHouseMEPRoof = serviceInterface.addProjectAsSubProject("Tekla House MEP, Roof", mep.getOid(), "ifc2x3tc1");
        SProject site = serviceInterface.addProjectAsSubProject("Site", mainProject.getOid(), "ifc2x3tc1");
        serviceInterface.addProjectAsSubProject("Site.skp", site.getOid(), "ifc2x3tc1");
        serviceInterface.addProjectAsSubProject("Tower crane", site.getOid(), "ifc2x3tc1");
        serviceInterface.addProjectAsSubProject("Caterpillar", site.getOid(), "ifc2x3tc1");
        serviceInterface.addProjectAsSubProject("Excavator", site.getOid(), "ifc2x3tc1");
        SProject grid = serviceInterface.addProjectAsSubProject("Grid", mainProject.getOid(), "ifc2x3tc1");
        SProject teklaHouseGrids = serviceInterface.addProjectAsSubProject("Tekla House Grids", grid.getOid(), "ifc2x3tc1");
        SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", grid.getOid());
        client.checkinSync(teklaHouseStructural.getOid(), "Initial", deserializer.getOid(), false, baseFolder.resolve("Tekla House Structural.ifcZIP"));
        client.checkinSync(teklaHouseGrids.getOid(), "Initial", deserializer.getOid(), false, baseFolder.resolve("Tekla House Grids.ifc"));
        client.checkinSync(teklaHouseFoundationFootings.getOid(), "Initial", deserializer.getOid(), false, baseFolder.resolve("Tekla House Foundation Footings.ifcZIP"));
        client.checkinSync(teklaHouseFoundationPiles.getOid(), "Initial", deserializer.getOid(), false, baseFolder.resolve("Tekla House Foundation Piles.ifcZIP"));
        client.checkinSync(teklaHouseFoundationRebars.getOid(), "Initial", deserializer.getOid(), false, baseFolder.resolve("Tekla House Foundation Rebars.ifcZIP"));
        client.checkinSync(teklaHouseFoundationEmbedments.getOid(), "Initial", deserializer.getOid(), false, baseFolder.resolve("Tekla House Foundation Embedments.ifcZIP"));
        client.checkinSync(teklaHousePrecastRebars.getOid(), "Initial", deserializer.getOid(), false, baseFolder.resolve("Tekla House Precast Rebars.ifcZIP"));
        client.checkinSync(teklaHousePrecastConcrete.getOid(), "Initial", deserializer.getOid(), false, baseFolder.resolve("Tekla House Precast Concrete.ifcZIP"));
        // client.checkinSync(teklaHouseCIPPours.getOid(), "Initial", deserializer.getOid(), false, true, baseFolder, "Tekla House CIP Pours.ifc"));
        client.checkinSync(teklaHouseCIPRebars.getOid(), "Initial", deserializer.getOid(), false, baseFolder.resolve("Tekla House CIP Rebars.ifcZIP"));
        client.checkinSync(teklaHouseCIPColumns.getOid(), "Initial", deserializer.getOid(), false, baseFolder.resolve("Tekla House CIP Columns.ifcZIP"));
        client.checkinSync(teklaHouseArchitectural.getOid(), "Initial", deserializer.getOid(), false, baseFolder.resolve("Tekla House Architectural.ifczip"));
        client.checkinSync(teklaHouseMEPGround.getOid(), "Initial", deserializer.getOid(), false, baseFolder.resolve("Tekla House MEP, Ground.ifc"));
        client.checkinSync(teklaHouseMEP1.getOid(), "Initial", deserializer.getOid(), false, baseFolder.resolve("Tekla House MEP, 1st.ifc"));
        client.checkinSync(teklaHouseMEP2.getOid(), "Initial", deserializer.getOid(), false, baseFolder.resolve("Tekla House MEP, 2nd.ifc"));
        client.checkinSync(teklaHouseMEP3.getOid(), "Initial", deserializer.getOid(), false, baseFolder.resolve("Tekla House MEP, 3rd.ifc"));
        client.checkinSync(teklaHouseMEPRoof.getOid(), "Initial", deserializer.getOid(), false, baseFolder.resolve("Tekla House MEP, Roof.ifc"));
        mainProject = serviceInterface.getProjectByPoid(mainProject.getOid());
        SSerializerPluginConfiguration serializer = client.getServiceInterface().getSerializerByContentType("application/ifc");
        client.download(mainProject.getLastRevisionId(), serializer.getOid(), Paths.get("output.ifc"));
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (BimServerClientException e) {
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) ServiceException(org.bimserver.shared.exceptions.ServiceException) ServiceInterface(org.bimserver.shared.interfaces.ServiceInterface) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) IOException(java.io.IOException) SProject(org.bimserver.interfaces.objects.SProject) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException)

Example 15 with ServiceException

use of org.bimserver.shared.exceptions.ServiceException 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)

Aggregations

ServiceException (org.bimserver.shared.exceptions.ServiceException)53 IOException (java.io.IOException)21 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)21 SProject (org.bimserver.interfaces.objects.SProject)19 DatabaseSession (org.bimserver.database.DatabaseSession)18 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)17 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)16 User (org.bimserver.models.store.User)13 Project (org.bimserver.models.store.Project)11 BimServerClientException (org.bimserver.shared.exceptions.BimServerClientException)11 UserException (org.bimserver.shared.exceptions.UserException)11 Date (java.util.Date)10 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)9 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)9 ChannelConnectionException (org.bimserver.shared.ChannelConnectionException)9 Path (java.nio.file.Path)8 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)8 ServerException (org.bimserver.shared.exceptions.ServerException)8 ArrayList (java.util.ArrayList)6 BimServerClientFactory (org.bimserver.shared.BimServerClientFactory)6